Make the patch apply cleanly
[linux-2.6.git] / patch-2.6.22.14-vs2.3.0.32.diff
1 diff -NurpP --minimal linux-2.6.22.10/Documentation/vserver/debug.txt linux-2.6.22.10-vs2.3.0.29/Documentation/vserver/debug.txt
2 --- linux-2.6.22.10/Documentation/vserver/debug.txt     1970-01-01 01:00:00 +0100
3 +++ linux-2.6.22.10-vs2.3.0.29/Documentation/vserver/debug.txt  2007-08-05 20:53:12 +0200
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.22.10/Makefile linux-2.6.22.10-vs2.3.0.29/Makefile
160 --- linux-2.6.22.10/Makefile    2007-10-30 01:57:11 +0100
161 +++ linux-2.6.22.10-vs2.3.0.29/Makefile 2007-10-30 02:41:27 +0100
162 @@ -1,7 +1,7 @@
163  VERSION = 2
164  PATCHLEVEL = 6
165  SUBLEVEL = 22
166 -EXTRAVERSION = .14
167 +EXTRAVERSION = .14-vs2.3.0.32
168  NAME = Holy Dancing Manatees, Batman!
169  
170  # *DOCUMENTATION*
171 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/alpha/Kconfig
172 --- linux-2.6.22.10/arch/alpha/Kconfig  2007-07-09 13:17:31 +0200
173 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/Kconfig       2007-08-05 20:53:12 +0200
174 @@ -662,6 +662,8 @@ config DUMMY_CONSOLE
175         depends on VGA_HOSE
176         default y
177  
178 +source "kernel/vserver/Kconfig"
179 +
180  source "security/Kconfig"
181  
182  source "crypto/Kconfig"
183 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/kernel/asm-offsets.c linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/asm-offsets.c
184 --- linux-2.6.22.10/arch/alpha/kernel/asm-offsets.c     2006-02-15 13:54:10 +0100
185 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/asm-offsets.c  2007-08-05 20:53:12 +0200
186 @@ -36,6 +36,7 @@ void foo(void)
187         DEFINE(PT_PTRACED, PT_PTRACED);
188         DEFINE(CLONE_VM, CLONE_VM);
189         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
190 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
191         DEFINE(SIGCHLD, SIGCHLD);
192         BLANK();
193  
194 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/kernel/entry.S linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/entry.S
195 --- linux-2.6.22.10/arch/alpha/kernel/entry.S   2007-07-09 13:17:31 +0200
196 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/entry.S        2007-08-05 20:53:12 +0200
197 @@ -643,7 +643,7 @@ kernel_thread:
198         stq     $2, 152($sp)            /* HAE */
199  
200         /* Shuffle FLAGS to the front; add CLONE_VM.  */
201 -       ldi     $1, CLONE_VM|CLONE_UNTRACED
202 +       ldi     $1, CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD;
203         or      $18, $1, $16
204         bsr     $26, sys_clone
205  
206 @@ -872,24 +872,15 @@ sys_getxgid:
207         .globl  sys_getxpid
208         .ent    sys_getxpid
209  sys_getxpid:
210 +       lda     $sp, -16($sp)
211 +       stq     $26, 0($sp)
212         .prologue 0
213 -       ldq     $2, TI_TASK($8)
214  
215 -       /* See linux/kernel/timer.c sys_getppid for discussion
216 -          about this loop.  */
217 -       ldq     $3, TASK_GROUP_LEADER($2)
218 -       ldq     $4, TASK_REAL_PARENT($3)
219 -       ldl     $0, TASK_TGID($2)
220 -1:     ldl     $1, TASK_TGID($4)
221 -#ifdef CONFIG_SMP
222 -       mov     $4, $5
223 -       mb
224 -       ldq     $3, TASK_GROUP_LEADER($2)
225 -       ldq     $4, TASK_REAL_PARENT($3)
226 -       cmpeq   $4, $5, $5
227 -       beq     $5, 1b
228 -#endif
229 -       stq     $1, 80($sp)
230 +       lda     $16, 96($sp)
231 +       jsr     $26, do_getxpid
232 +       ldq     $26, 0($sp)
233 +
234 +       lda     $sp, 16($sp)
235         ret
236  .end sys_getxpid
237  
238 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/kernel/osf_sys.c linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/osf_sys.c
239 --- linux-2.6.22.10/arch/alpha/kernel/osf_sys.c 2007-07-09 13:17:31 +0200
240 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/osf_sys.c      2007-08-05 20:53:12 +0200
241 @@ -883,7 +883,7 @@ osf_gettimeofday(struct timeval32 __user
242  {
243         if (tv) {
244                 struct timeval ktv;
245 -               do_gettimeofday(&ktv);
246 +               vx_gettimeofday(&ktv);
247                 if (put_tv32(tv, &ktv))
248                         return -EFAULT;
249         }
250 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/ptrace.c
251 --- linux-2.6.22.10/arch/alpha/kernel/ptrace.c  2006-04-09 13:49:39 +0200
252 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/ptrace.c       2007-08-05 20:53:12 +0200
253 @@ -15,6 +15,7 @@
254  #include <linux/slab.h>
255  #include <linux/security.h>
256  #include <linux/signal.h>
257 +#include <linux/vs_base.h>
258  
259  #include <asm/uaccess.h>
260  #include <asm/pgtable.h>
261 @@ -283,6 +284,11 @@ do_sys_ptrace(long request, long pid, lo
262                 goto out_notsk;
263         }
264  
265 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
266 +               ret = -EPERM;
267 +               goto out;
268 +       }
269 +
270         if (request == PTRACE_ATTACH) {
271                 ret = ptrace_attach(child);
272                 goto out;
273 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/kernel/semaphore.c linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/semaphore.c
274 --- linux-2.6.22.10/arch/alpha/kernel/semaphore.c       2004-08-14 12:55:32 +0200
275 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/semaphore.c    2007-08-05 20:53:12 +0200
276 @@ -68,8 +68,8 @@ __down_failed(struct semaphore *sem)
277         DECLARE_WAITQUEUE(wait, tsk);
278  
279  #ifdef CONFIG_DEBUG_SEMAPHORE
280 -       printk("%s(%d): down failed(%p)\n",
281 -              tsk->comm, tsk->pid, sem);
282 +       printk("%s(%d:#%u): down failed(%p)\n",
283 +              tsk->comm, tsk->pid, tsk->xid, sem);
284  #endif
285  
286         tsk->state = TASK_UNINTERRUPTIBLE;
287 @@ -97,8 +97,8 @@ __down_failed(struct semaphore *sem)
288         wake_up(&sem->wait);
289  
290  #ifdef CONFIG_DEBUG_SEMAPHORE
291 -       printk("%s(%d): down acquired(%p)\n",
292 -              tsk->comm, tsk->pid, sem);
293 +       printk("%s(%d:#%u): down acquired(%p)\n",
294 +              tsk->comm, tsk->pid, tsk->xid, sem);
295  #endif
296  }
297  
298 @@ -110,8 +110,8 @@ __down_failed_interruptible(struct semap
299         long ret = 0;
300  
301  #ifdef CONFIG_DEBUG_SEMAPHORE
302 -       printk("%s(%d): down failed(%p)\n",
303 -              tsk->comm, tsk->pid, sem);
304 +       printk("%s(%d:#%u): down failed(%p)\n",
305 +              tsk->comm, tsk->pid, tsk->xid, sem);
306  #endif
307  
308         tsk->state = TASK_INTERRUPTIBLE;
309 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/kernel/systbls.S linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/systbls.S
310 --- linux-2.6.22.10/arch/alpha/kernel/systbls.S 2007-07-09 13:17:31 +0200
311 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/systbls.S      2007-08-05 20:53:12 +0200
312 @@ -446,7 +446,7 @@ sys_call_table:
313         .quad sys_stat64                        /* 425 */
314         .quad sys_lstat64
315         .quad sys_fstat64
316 -       .quad sys_ni_syscall                    /* sys_vserver */
317 +       .quad sys_vserver                       /* sys_vserver */
318         .quad sys_ni_syscall                    /* sys_mbind */
319         .quad sys_ni_syscall                    /* sys_get_mempolicy */
320         .quad sys_ni_syscall                    /* sys_set_mempolicy */
321 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/traps.c
322 --- linux-2.6.22.10/arch/alpha/kernel/traps.c   2006-09-20 16:57:57 +0200
323 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/kernel/traps.c        2007-08-05 20:53:12 +0200
324 @@ -182,7 +182,8 @@ die_if_kernel(char * str, struct pt_regs
325  #ifdef CONFIG_SMP
326         printk("CPU %d ", hard_smp_processor_id());
327  #endif
328 -       printk("%s(%d): %s %ld\n", current->comm, current->pid, str, err);
329 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
330 +               current->pid, current->xid, str, err);
331         dik_show_regs(regs, r9_15);
332         dik_show_trace((unsigned long *)(regs+1));
333         dik_show_code((unsigned int *)regs->pc);
334 diff -NurpP --minimal linux-2.6.22.10/arch/alpha/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/alpha/mm/fault.c
335 --- linux-2.6.22.10/arch/alpha/mm/fault.c       2007-07-09 13:17:32 +0200
336 +++ linux-2.6.22.10-vs2.3.0.29/arch/alpha/mm/fault.c    2007-08-05 20:53:12 +0200
337 @@ -197,8 +197,8 @@ do_page_fault(unsigned long address, uns
338                 down_read(&mm->mmap_sem);
339                 goto survive;
340         }
341 -       printk(KERN_ALERT "VM: killing process %s(%d)\n",
342 -              current->comm, current->pid);
343 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
344 +              current->comm, current->pid, current->xid);
345         if (!user_mode(regs))
346                 goto no_context;
347         do_exit(SIGKILL);
348 diff -NurpP --minimal linux-2.6.22.10/arch/arm/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/arm/Kconfig
349 --- linux-2.6.22.10/arch/arm/Kconfig    2007-07-09 13:17:32 +0200
350 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm/Kconfig 2007-08-05 20:53:12 +0200
351 @@ -1042,6 +1042,8 @@ source "arch/arm/oprofile/Kconfig"
352  
353  source "arch/arm/Kconfig.debug"
354  
355 +source "kernel/vserver/Kconfig"
356 +
357  source "security/Kconfig"
358  
359  source "crypto/Kconfig"
360 diff -NurpP --minimal linux-2.6.22.10/arch/arm/kernel/calls.S linux-2.6.22.10-vs2.3.0.29/arch/arm/kernel/calls.S
361 --- linux-2.6.22.10/arch/arm/kernel/calls.S     2007-07-09 13:17:32 +0200
362 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm/kernel/calls.S  2007-08-05 20:53:12 +0200
363 @@ -322,7 +322,7 @@
364  /* 310 */      CALL(sys_request_key)
365                 CALL(sys_keyctl)
366                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
367 -/* vserver */  CALL(sys_ni_syscall)
368 +               CALL(sys_vserver)
369                 CALL(sys_ioprio_set)
370  /* 315 */      CALL(sys_ioprio_get)
371                 CALL(sys_inotify_init)
372 diff -NurpP --minimal linux-2.6.22.10/arch/arm/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/arm/kernel/process.c
373 --- linux-2.6.22.10/arch/arm/kernel/process.c   2007-07-09 13:17:32 +0200
374 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm/kernel/process.c        2007-08-05 20:53:12 +0200
375 @@ -261,7 +261,8 @@ void __show_regs(struct pt_regs *regs)
376  void show_regs(struct pt_regs * regs)
377  {
378         printk("\n");
379 -       printk("Pid: %d, comm: %20s\n", current->pid, current->comm);
380 +       printk("Pid: %d[#%u], comm: %20s\n",
381 +               current->pid, current->xid, current->comm);
382         __show_regs(regs);
383         __backtrace();
384  }
385 @@ -423,7 +424,8 @@ pid_t kernel_thread(int (*fn)(void *), v
386         regs.ARM_pc = (unsigned long)kernel_thread_helper;
387         regs.ARM_cpsr = SVC_MODE;
388  
389 -       return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
390 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
391 +               0, &regs, 0, NULL, NULL);
392  }
393  EXPORT_SYMBOL(kernel_thread);
394  
395 diff -NurpP --minimal linux-2.6.22.10/arch/arm/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/arm/kernel/traps.c
396 --- linux-2.6.22.10/arch/arm/kernel/traps.c     2007-07-09 13:17:32 +0200
397 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm/kernel/traps.c  2007-08-05 20:53:12 +0200
398 @@ -222,8 +222,8 @@ static void __die(const char *str, int e
399                str, err, ++die_counter);
400         print_modules();
401         __show_regs(regs);
402 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
403 -               tsk->comm, tsk->pid, thread + 1);
404 +       printk("Process %s (pid: %d:#%u, stack limit = 0x%p)\n",
405 +               tsk->comm, tsk->pid, tsk->xid, thread + 1);
406  
407         if (!user_mode(regs) || in_interrupt()) {
408                 dump_mem("Stack: ", regs->ARM_sp,
409 diff -NurpP --minimal linux-2.6.22.10/arch/arm/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/arm/mm/fault.c
410 --- linux-2.6.22.10/arch/arm/mm/fault.c 2007-07-09 13:17:39 +0200
411 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm/mm/fault.c      2007-08-05 20:53:12 +0200
412 @@ -266,7 +266,8 @@ do_page_fault(unsigned long addr, unsign
413                  * happened to us that made us unable to handle
414                  * the page fault gracefully.
415                  */
416 -               printk("VM: killing process %s\n", tsk->comm);
417 +               printk("VM: killing process %s(%d:#%u)\n",
418 +                       tsk->comm, tsk->pid, tsk->xid);
419                 do_exit(SIGKILL);
420                 return 0;
421  
422 diff -NurpP --minimal linux-2.6.22.10/arch/arm26/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/arm26/Kconfig
423 --- linux-2.6.22.10/arch/arm26/Kconfig  2007-07-09 13:17:40 +0200
424 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm26/Kconfig       2007-08-05 20:53:12 +0200
425 @@ -243,6 +243,8 @@ source "drivers/usb/Kconfig"
426  
427  source "arch/arm26/Kconfig.debug"
428  
429 +source "kernel/vserver/Kconfig"
430 +
431  source "security/Kconfig"
432  
433  source "crypto/Kconfig"
434 diff -NurpP --minimal linux-2.6.22.10/arch/arm26/kernel/calls.S linux-2.6.22.10-vs2.3.0.29/arch/arm26/kernel/calls.S
435 --- linux-2.6.22.10/arch/arm26/kernel/calls.S   2005-03-02 12:38:19 +0100
436 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm26/kernel/calls.S        2007-08-05 20:53:12 +0200
437 @@ -257,6 +257,11 @@ __syscall_start:
438                 .long   sys_lremovexattr
439                 .long   sys_fremovexattr
440                 .long   sys_tkill
441 +
442 +               .rept   313 - (. - __syscall_start) / 4
443 +                       .long   sys_ni_syscall
444 +               .endr
445 +               .long   sys_vserver     /* 313 */
446  __syscall_end:
447  
448                 .rept   NR_syscalls - (__syscall_end - __syscall_start) / 4
449 diff -NurpP --minimal linux-2.6.22.10/arch/arm26/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/arm26/kernel/process.c
450 --- linux-2.6.22.10/arch/arm26/kernel/process.c 2006-09-20 16:57:57 +0200
451 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm26/kernel/process.c      2007-08-05 20:53:12 +0200
452 @@ -365,7 +365,8 @@ pid_t kernel_thread(int (*fn)(void *), v
453          regs.ARM_r3 = (unsigned long)do_exit;
454          regs.ARM_pc = (unsigned long)kernel_thread_helper | MODE_SVC26;
455  
456 -        return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
457 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
458 +               0, &regs, 0, NULL, NULL);
459  }
460  EXPORT_SYMBOL(kernel_thread);
461  
462 diff -NurpP --minimal linux-2.6.22.10/arch/arm26/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/arm26/kernel/traps.c
463 --- linux-2.6.22.10/arch/arm26/kernel/traps.c   2006-09-20 16:57:57 +0200
464 +++ linux-2.6.22.10-vs2.3.0.29/arch/arm26/kernel/traps.c        2007-08-05 20:53:12 +0200
465 @@ -185,8 +185,9 @@ NORET_TYPE void die(const char *str, str
466         printk("Internal error: %s: %x\n", str, err);
467         printk("CPU: %d\n", smp_processor_id());
468         show_regs(regs);
469 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
470 -               current->comm, current->pid, end_of_stack(tsk));
471 +       printk("Process %s (pid: %d[#%u], stack limit = 0x%p)\n",
472 +               current->comm, current->pid,
473 +               current->xid, end_of_stack(tsk));
474  
475         if (!user_mode(regs) || in_interrupt()) {
476                 __dump_stack(tsk, (unsigned long)(regs + 1));
477 diff -NurpP --minimal linux-2.6.22.10/arch/cris/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/cris/Kconfig
478 --- linux-2.6.22.10/arch/cris/Kconfig   2007-05-02 19:24:19 +0200
479 +++ linux-2.6.22.10-vs2.3.0.29/arch/cris/Kconfig        2007-08-05 20:53:12 +0200
480 @@ -200,6 +200,8 @@ source "drivers/usb/Kconfig"
481  
482  source "arch/cris/Kconfig.debug"
483  
484 +source "kernel/vserver/Kconfig"
485 +
486  source "security/Kconfig"
487  
488  source "crypto/Kconfig"
489 diff -NurpP --minimal linux-2.6.22.10/arch/cris/arch-v10/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/cris/arch-v10/kernel/process.c
490 --- linux-2.6.22.10/arch/cris/arch-v10/kernel/process.c 2006-09-20 16:57:57 +0200
491 +++ linux-2.6.22.10-vs2.3.0.29/arch/cris/arch-v10/kernel/process.c      2007-08-05 20:53:12 +0200
492 @@ -103,7 +103,8 @@ int kernel_thread(int (*fn)(void *), voi
493         regs.dccr = 1 << I_DCCR_BITNR;
494  
495         /* Ok, create the new process.. */
496 -        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
497 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
498 +               0, &regs, 0, NULL, NULL);
499  }
500  
501  /* setup the child's kernel stack with a pt_regs and switch_stack on it.
502 diff -NurpP --minimal linux-2.6.22.10/arch/cris/arch-v32/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/cris/arch-v32/kernel/process.c
503 --- linux-2.6.22.10/arch/cris/arch-v32/kernel/process.c 2006-09-20 16:57:57 +0200
504 +++ linux-2.6.22.10-vs2.3.0.29/arch/cris/arch-v32/kernel/process.c      2007-08-05 20:53:12 +0200
505 @@ -120,7 +120,8 @@ kernel_thread(int (*fn)(void *), void * 
506         regs.ccs = 1 << (I_CCS_BITNR + CCS_SHIFT);
507  
508         /* Create the new process. */
509 -        return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
510 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
511 +               0, &regs, 0, NULL, NULL);
512  }
513  
514  /*
515 diff -NurpP --minimal linux-2.6.22.10/arch/frv/kernel/kernel_thread.S linux-2.6.22.10-vs2.3.0.29/arch/frv/kernel/kernel_thread.S
516 --- linux-2.6.22.10/arch/frv/kernel/kernel_thread.S     2005-03-02 12:38:20 +0100
517 +++ linux-2.6.22.10-vs2.3.0.29/arch/frv/kernel/kernel_thread.S  2007-08-05 20:53:12 +0200
518 @@ -13,6 +13,8 @@
519  #include <asm/unistd.h>
520  
521  #define CLONE_VM       0x00000100      /* set if VM shared between processes */
522 +#define CLONE_KTHREAD  0x10000000      /* kernel thread */
523 +#define CLONE_KT       (CLONE_VM | CLONE_KTHREAD)      /* kernel thread flags */
524  #define        KERN_ERR        "<3>"
525  
526         .section .rodata
527 @@ -37,7 +39,7 @@ kernel_thread:
528  
529         # start by forking the current process, but with shared VM
530         setlos.p        #__NR_clone,gr7         ; syscall number
531 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
532 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
533         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
534         setlo           #0xe4e4,gr9
535         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
536 diff -NurpP --minimal linux-2.6.22.10/arch/h8300/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/h8300/Kconfig
537 --- linux-2.6.22.10/arch/h8300/Kconfig  2007-07-09 13:17:41 +0200
538 +++ linux-2.6.22.10-vs2.3.0.29/arch/h8300/Kconfig       2007-08-05 20:53:12 +0200
539 @@ -222,6 +222,8 @@ source "fs/Kconfig"
540  
541  source "arch/h8300/Kconfig.debug"
542  
543 +source "kernel/vserver/Kconfig"
544 +
545  source "security/Kconfig"
546  
547  source "crypto/Kconfig"
548 diff -NurpP --minimal linux-2.6.22.10/arch/h8300/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/h8300/kernel/process.c
549 --- linux-2.6.22.10/arch/h8300/kernel/process.c 2006-09-20 16:57:58 +0200
550 +++ linux-2.6.22.10-vs2.3.0.29/arch/h8300/kernel/process.c      2007-08-05 20:53:12 +0200
551 @@ -134,7 +134,7 @@ int kernel_thread(int (*fn)(void *), voi
552  
553         fs = get_fs();
554         set_fs (KERNEL_DS);
555 -       clone_arg = flags | CLONE_VM;
556 +       clone_arg = flags | CLONE_VM | CLONE_KTHREAD;
557         __asm__("mov.l sp,er3\n\t"
558                 "sub.l er2,er2\n\t"
559                 "mov.l %2,er1\n\t"
560 diff -NurpP --minimal linux-2.6.22.10/arch/i386/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/i386/Kconfig
561 --- linux-2.6.22.10/arch/i386/Kconfig   2007-07-09 13:17:41 +0200
562 +++ linux-2.6.22.10-vs2.3.0.29/arch/i386/Kconfig        2007-08-05 20:53:12 +0200
563 @@ -1230,6 +1230,8 @@ endmenu
564  
565  source "arch/i386/Kconfig.debug"
566  
567 +source "kernel/vserver/Kconfig"
568 +
569  source "security/Kconfig"
570  
571  source "crypto/Kconfig"
572 diff -NurpP --minimal linux-2.6.22.10/arch/i386/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/i386/kernel/process.c
573 --- linux-2.6.22.10/arch/i386/kernel/process.c  2007-07-09 13:17:42 +0200
574 +++ linux-2.6.22.10-vs2.3.0.29/arch/i386/kernel/process.c       2007-08-05 20:53:12 +0200
575 @@ -302,8 +302,10 @@ void show_regs(struct pt_regs * regs)
576         unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
577  
578         printk("\n");
579 -       printk("Pid: %d, comm: %20s\n", current->pid, current->comm);
580 -       printk("EIP: %04x:[<%08lx>] CPU: %d\n",0xffff & regs->xcs,regs->eip, smp_processor_id());
581 +       printk("Pid: %d[#%u], comm: %20s\n",
582 +               current->pid, current->xid, current->comm);
583 +       printk("EIP: %04x:[<%08lx>] CPU: %d\n",
584 +               0xffff & regs->xcs,regs->eip, smp_processor_id());
585         print_symbol("EIP is at %s\n", regs->eip);
586  
587         if (user_mode_vm(regs))
588 @@ -355,7 +357,8 @@ int kernel_thread(int (*fn)(void *), voi
589         regs.eflags = X86_EFLAGS_IF | X86_EFLAGS_SF | X86_EFLAGS_PF | 0x2;
590  
591         /* Ok, create the new process.. */
592 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
593 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
594 +               0, &regs, 0, NULL, NULL);
595  }
596  EXPORT_SYMBOL(kernel_thread);
597  
598 diff -NurpP --minimal linux-2.6.22.10/arch/i386/kernel/syscall_table.S linux-2.6.22.10-vs2.3.0.29/arch/i386/kernel/syscall_table.S
599 --- linux-2.6.22.10/arch/i386/kernel/syscall_table.S    2007-07-09 13:17:42 +0200
600 +++ linux-2.6.22.10-vs2.3.0.29/arch/i386/kernel/syscall_table.S 2007-08-05 20:53:12 +0200
601 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
602         .long sys_tgkill        /* 270 */
603         .long sys_utimes
604         .long sys_fadvise64_64
605 -       .long sys_ni_syscall    /* sys_vserver */
606 +       .long sys_vserver
607         .long sys_mbind
608         .long sys_get_mempolicy
609         .long sys_set_mempolicy
610 diff -NurpP --minimal linux-2.6.22.10/arch/i386/kernel/sysenter.c linux-2.6.22.10-vs2.3.0.29/arch/i386/kernel/sysenter.c
611 --- linux-2.6.22.10/arch/i386/kernel/sysenter.c 2007-10-30 01:57:12 +0100
612 +++ linux-2.6.22.10-vs2.3.0.29/arch/i386/kernel/sysenter.c      2007-09-05 03:06:10 +0200
613 @@ -17,6 +17,7 @@
614  #include <linux/elf.h>
615  #include <linux/mm.h>
616  #include <linux/module.h>
617 +#include <linux/vs_memory.h>
618  
619  #include <asm/cpufeature.h>
620  #include <asm/msr.h>
621 diff -NurpP --minimal linux-2.6.22.10/arch/i386/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/i386/kernel/traps.c
622 --- linux-2.6.22.10/arch/i386/kernel/traps.c    2007-07-09 13:17:42 +0200
623 +++ linux-2.6.22.10-vs2.3.0.29/arch/i386/kernel/traps.c 2007-08-05 20:53:12 +0200
624 @@ -56,6 +56,8 @@
625  #include <asm/stacktrace.h>
626  
627  #include <linux/module.h>
628 +#include <linux/vs_context.h>
629 +#include <linux/vserver/history.h>
630  
631  #include "mach_traps.h"
632  
633 @@ -303,8 +305,8 @@ void show_registers(struct pt_regs *regs
634                 regs->esi, regs->edi, regs->ebp, esp);
635         printk(KERN_EMERG "ds: %04x   es: %04x   fs: %04x  gs: %04x  ss: %04x\n",
636                regs->xds & 0xffff, regs->xes & 0xffff, regs->xfs & 0xffff, gs, ss);
637 -       printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)",
638 -               TASK_COMM_LEN, current->comm, current->pid,
639 +       printk(KERN_EMERG "Process %.*s (pid: %d[#%u], ti=%p task=%p task.ti=%p)",
640 +               TASK_COMM_LEN, current->comm, current->pid, current->xid,
641                 current_thread_info(), current, task_thread_info(current));
642         /*
643          * When in-kernel, we also print out the stack and code at the
644 @@ -375,6 +377,8 @@ void die(const char * str, struct pt_reg
645  
646         oops_enter();
647  
648 +       vxh_throw_oops();
649 +
650         if (die.lock_owner != raw_smp_processor_id()) {
651                 console_verbose();
652                 spin_lock_irqsave(&die.lock, flags);
653 @@ -412,9 +416,9 @@ void die(const char * str, struct pt_reg
654                 if (nl)
655                         printk("\n");
656                 if (notify_die(DIE_OOPS, str, regs, err,
657 -                                       current->thread.trap_no, SIGSEGV) !=
658 -                               NOTIFY_STOP) {
659 +                       current->thread.trap_no, SIGSEGV) != NOTIFY_STOP) {
660                         show_registers(regs);
661 +                       vxh_dump_history();
662                         /* Executive summary in case the oops scrolled away */
663                         esp = (unsigned long) (&regs->esp);
664                         savesegment(ss, ss);
665 diff -NurpP --minimal linux-2.6.22.10/arch/i386/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/i386/mm/fault.c
666 --- linux-2.6.22.10/arch/i386/mm/fault.c        2007-10-30 01:57:12 +0100
667 +++ linux-2.6.22.10-vs2.3.0.29/arch/i386/mm/fault.c     2007-09-05 03:06:10 +0200
668 @@ -587,7 +587,8 @@ out_of_memory:
669                 down_read(&mm->mmap_sem);
670                 goto survive;
671         }
672 -       printk("VM: killing process %s\n", tsk->comm);
673 +       printk("VM: killing process %s(%d:#%u)\n",
674 +               tsk->comm, tsk->pid, tsk->xid);
675         if (error_code & 4)
676                 do_exit(SIGKILL);
677         goto no_context;
678 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/ia64/Kconfig
679 --- linux-2.6.22.10/arch/ia64/Kconfig   2007-07-09 13:17:43 +0200
680 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/Kconfig        2007-08-05 20:53:12 +0200
681 @@ -592,6 +592,8 @@ endmenu
682  
683  source "arch/ia64/Kconfig.debug"
684  
685 +source "kernel/vserver/Kconfig"
686 +
687  source "security/Kconfig"
688  
689  source "crypto/Kconfig"
690 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/ia32/binfmt_elf32.c linux-2.6.22.10-vs2.3.0.29/arch/ia64/ia32/binfmt_elf32.c
691 --- linux-2.6.22.10/arch/ia64/ia32/binfmt_elf32.c       2007-05-02 19:24:20 +0200
692 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/ia32/binfmt_elf32.c    2007-08-05 20:53:12 +0200
693 @@ -233,7 +233,8 @@ ia32_setup_arg_pages (struct linux_binpr
694                         kmem_cache_free(vm_area_cachep, mpnt);
695                         return ret;
696                 }
697 -               current->mm->stack_vm = current->mm->total_vm = vma_pages(mpnt);
698 +               vx_vmpages_sub(current->mm, current->mm->total_vm - vma_pages(mpnt));
699 +               current->mm->stack_vm = current->mm->total_vm;
700         }
701  
702         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
703 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/ia32/ia32_entry.S linux-2.6.22.10-vs2.3.0.29/arch/ia64/ia32/ia32_entry.S
704 --- linux-2.6.22.10/arch/ia64/ia32/ia32_entry.S 2007-07-09 13:17:43 +0200
705 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/ia32/ia32_entry.S      2007-08-05 20:53:12 +0200
706 @@ -446,7 +446,7 @@ ia32_syscall_table:
707         data8 sys_tgkill        /* 270 */
708         data8 compat_sys_utimes
709         data8 sys32_fadvise64_64
710 -       data8 sys_ni_syscall
711 +       data8 sys32_vserver
712         data8 sys_ni_syscall
713         data8 sys_ni_syscall    /* 275 */
714         data8 sys_ni_syscall
715 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/ia32/sys_ia32.c linux-2.6.22.10-vs2.3.0.29/arch/ia64/ia32/sys_ia32.c
716 --- linux-2.6.22.10/arch/ia64/ia32/sys_ia32.c   2007-05-02 19:24:20 +0200
717 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/ia32/sys_ia32.c        2007-08-05 20:53:12 +0200
718 @@ -1182,7 +1182,7 @@ sys32_gettimeofday (struct compat_timeva
719  {
720         if (tv) {
721                 struct timeval ktv;
722 -               do_gettimeofday(&ktv);
723 +               vx_gettimeofday(&ktv);
724                 if (put_tv32(tv, &ktv))
725                         return -EFAULT;
726         }
727 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/kernel/asm-offsets.c linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/asm-offsets.c
728 --- linux-2.6.22.10/arch/ia64/kernel/asm-offsets.c      2007-05-02 19:24:20 +0200
729 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/asm-offsets.c   2007-08-05 20:53:12 +0200
730 @@ -192,6 +192,7 @@ void foo(void)
731      /* for assembly files which can't include sched.h: */
732         DEFINE(IA64_CLONE_VFORK, CLONE_VFORK);
733         DEFINE(IA64_CLONE_VM, CLONE_VM);
734 +       DEFINE(IA64_CLONE_KTHREAD, CLONE_KTHREAD);
735  
736         BLANK();
737         DEFINE(IA64_CPUINFO_NSEC_PER_CYC_OFFSET,
738 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/kernel/entry.S linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/entry.S
739 --- linux-2.6.22.10/arch/ia64/kernel/entry.S    2007-07-09 13:17:43 +0200
740 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/entry.S 2007-08-05 20:53:12 +0200
741 @@ -1547,7 +1547,7 @@ sys_call_table:
742         data8 sys_mq_notify
743         data8 sys_mq_getsetattr
744         data8 sys_kexec_load
745 -       data8 sys_ni_syscall                    // reserved for vserver
746 +       data8 sys_vserver
747         data8 sys_waitid                        // 1270
748         data8 sys_add_key
749         data8 sys_request_key
750 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/kernel/perfmon.c linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/perfmon.c
751 --- linux-2.6.22.10/arch/ia64/kernel/perfmon.c  2007-07-09 13:17:43 +0200
752 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/perfmon.c       2007-08-05 20:53:12 +0200
753 @@ -40,6 +40,7 @@
754  #include <linux/capability.h>
755  #include <linux/rcupdate.h>
756  #include <linux/completion.h>
757 +#include <linux/vs_memory.h>
758  
759  #include <asm/errno.h>
760  #include <asm/intrinsics.h>
761 @@ -2395,7 +2396,7 @@ pfm_smpl_buffer_alloc(struct task_struct
762          */
763         insert_vm_struct(mm, vma);
764  
765 -       mm->total_vm  += size >> PAGE_SHIFT;
766 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
767         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
768                                                         vma_pages(vma));
769         up_write(&task->mm->mmap_sem);
770 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/process.c
771 --- linux-2.6.22.10/arch/ia64/kernel/process.c  2007-07-09 13:17:43 +0200
772 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/process.c       2007-08-05 20:53:12 +0200
773 @@ -105,7 +105,8 @@ show_regs (struct pt_regs *regs)
774         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
775  
776         print_modules();
777 -       printk("\nPid: %d, CPU %d, comm: %20s\n", current->pid, smp_processor_id(), current->comm);
778 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n",
779 +               current->pid, current->xid, smp_processor_id(), current->comm);
780         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s\n",
781                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted());
782         print_symbol("ip is at %s\n", ip);
783 @@ -696,7 +697,8 @@ kernel_thread (int (*fn)(void *), void *
784         regs.sw.ar_fpsr = regs.pt.ar_fpsr = ia64_getreg(_IA64_REG_AR_FPSR);
785         regs.sw.ar_bspstore = (unsigned long) current + IA64_RBS_OFFSET;
786         regs.sw.pr = (1 << PRED_KERNEL_STACK);
787 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs.pt, 0, NULL, NULL);
788 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
789 +               0, &regs.pt, 0, NULL, NULL);
790  }
791  EXPORT_SYMBOL(kernel_thread);
792  
793 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/ptrace.c
794 --- linux-2.6.22.10/arch/ia64/kernel/ptrace.c   2007-05-02 19:24:20 +0200
795 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/ptrace.c        2007-08-05 20:53:12 +0200
796 @@ -17,6 +17,7 @@
797  #include <linux/security.h>
798  #include <linux/audit.h>
799  #include <linux/signal.h>
800 +#include <linux/vs_base.h>
801  
802  #include <asm/pgtable.h>
803  #include <asm/processor.h>
804 @@ -1443,6 +1444,9 @@ sys_ptrace (long request, pid_t pid, uns
805         read_unlock(&tasklist_lock);
806         if (!child)
807                 goto out;
808 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
809 +               goto out_tsk;
810 +
811         ret = -EPERM;
812         if (pid == 1)           /* no messing around with init! */
813                 goto out_tsk;
814 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/traps.c
815 --- linux-2.6.22.10/arch/ia64/kernel/traps.c    2007-07-09 13:17:43 +0200
816 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/kernel/traps.c 2007-08-05 20:53:12 +0200
817 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
818         put_cpu();
819  
820         if (++die.lock_owner_depth < 3) {
821 -               printk("%s[%d]: %s %ld [%d]\n",
822 -                       current->comm, current->pid, str, err, ++die_counter);
823 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
824 +                       current->comm, current->pid, current->xid,
825 +                       str, err, ++die_counter);
826                 (void) notify_die(DIE_OOPS, (char *)str, regs, err, 255, SIGSEGV);
827                 show_regs(regs);
828         } else
829 @@ -313,8 +314,9 @@ handle_fpu_swa (int fp_fault, struct pt_
830                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
831                                 last.time = current_jiffies + 5 * HZ;
832                                 printk(KERN_WARNING
833 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
834 -                                       current->comm, current->pid, regs->cr_iip + ia64_psr(regs)->ri, isr);
835 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
836 +                                       current->comm, current->pid, current->xid,
837 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
838                         }
839                 }
840         }
841 diff -NurpP --minimal linux-2.6.22.10/arch/ia64/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/ia64/mm/fault.c
842 --- linux-2.6.22.10/arch/ia64/mm/fault.c        2007-07-09 13:17:43 +0200
843 +++ linux-2.6.22.10-vs2.3.0.29/arch/ia64/mm/fault.c     2007-08-05 20:53:12 +0200
844 @@ -10,6 +10,7 @@
845  #include <linux/interrupt.h>
846  #include <linux/kprobes.h>
847  #include <linux/kdebug.h>
848 +#include <linux/vs_memory.h>
849  
850  #include <asm/pgtable.h>
851  #include <asm/processor.h>
852 diff -NurpP --minimal linux-2.6.22.10/arch/m32r/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/m32r/kernel/process.c
853 --- linux-2.6.22.10/arch/m32r/kernel/process.c  2007-05-02 19:24:21 +0200
854 +++ linux-2.6.22.10-vs2.3.0.29/arch/m32r/kernel/process.c       2007-08-05 20:53:12 +0200
855 @@ -211,8 +211,8 @@ int kernel_thread(int (*fn)(void *), voi
856         regs.psw = M32R_PSW_BIE;
857  
858         /* Ok, create the new process. */
859 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL,
860 -               NULL);
861 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
862 +               0, &regs, 0, NULL, NULL);
863  }
864  
865  /*
866 diff -NurpP --minimal linux-2.6.22.10/arch/m32r/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/m32r/kernel/traps.c
867 --- linux-2.6.22.10/arch/m32r/kernel/traps.c    2006-11-30 21:18:28 +0100
868 +++ linux-2.6.22.10-vs2.3.0.29/arch/m32r/kernel/traps.c 2007-08-05 20:53:12 +0200
869 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
870         } else {
871                 printk("SPI: %08lx\n", sp);
872         }
873 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
874 -               current->comm, current->pid, 0xffff & i, 4096+(unsigned long)current);
875 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
876 +               current->comm, current->pid, current->xid,
877 +               0xffff & i, 4096+(unsigned long)current);
878  
879         /*
880          * When in-kernel, we also print out the stack and code at the
881 diff -NurpP --minimal linux-2.6.22.10/arch/m68k/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/m68k/Kconfig
882 --- linux-2.6.22.10/arch/m68k/Kconfig   2007-07-09 13:17:47 +0200
883 +++ linux-2.6.22.10-vs2.3.0.29/arch/m68k/Kconfig        2007-08-05 20:53:12 +0200
884 @@ -678,6 +678,8 @@ source "fs/Kconfig"
885  
886  source "arch/m68k/Kconfig.debug"
887  
888 +source "kernel/vserver/Kconfig"
889 +
890  source "security/Kconfig"
891  
892  source "crypto/Kconfig"
893 diff -NurpP --minimal linux-2.6.22.10/arch/m68k/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/m68k/kernel/process.c
894 --- linux-2.6.22.10/arch/m68k/kernel/process.c  2006-11-30 21:18:28 +0100
895 +++ linux-2.6.22.10-vs2.3.0.29/arch/m68k/kernel/process.c       2007-08-05 20:53:12 +0200
896 @@ -159,7 +159,8 @@ int kernel_thread(int (*fn)(void *), voi
897  
898         {
899         register long retval __asm__ ("d0");
900 -       register long clone_arg __asm__ ("d1") = flags | CLONE_VM | CLONE_UNTRACED;
901 +       register long clone_arg __asm__ ("d1") =
902 +               flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD;
903  
904         retval = __NR_clone;
905         __asm__ __volatile__
906 diff -NurpP --minimal linux-2.6.22.10/arch/m68k/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/arch/m68k/kernel/ptrace.c
907 --- linux-2.6.22.10/arch/m68k/kernel/ptrace.c   2007-07-09 13:17:47 +0200
908 +++ linux-2.6.22.10-vs2.3.0.29/arch/m68k/kernel/ptrace.c        2007-08-05 20:53:12 +0200
909 @@ -18,6 +18,7 @@
910  #include <linux/ptrace.h>
911  #include <linux/user.h>
912  #include <linux/signal.h>
913 +#include <linux/vs_base.h>
914  
915  #include <asm/uaccess.h>
916  #include <asm/page.h>
917 @@ -278,6 +279,8 @@ long arch_ptrace(struct task_struct *chi
918                 ret = ptrace_request(child, request, addr, data);
919                 break;
920         }
921 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
922 +               goto out_tsk;
923  
924         return ret;
925  out_eio:
926 diff -NurpP --minimal linux-2.6.22.10/arch/m68k/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/m68k/kernel/traps.c
927 --- linux-2.6.22.10/arch/m68k/kernel/traps.c    2007-05-02 19:24:21 +0200
928 +++ linux-2.6.22.10-vs2.3.0.29/arch/m68k/kernel/traps.c 2007-08-05 20:53:12 +0200
929 @@ -899,8 +899,8 @@ void show_registers(struct pt_regs *regs
930         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
931                regs->d4, regs->d5, regs->a0, regs->a1);
932  
933 -       printk("Process %s (pid: %d, task=%p)\n",
934 -               current->comm, current->pid, current);
935 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
936 +               current->comm, current->pid, current->xid, current);
937         addr = (unsigned long)&fp->un;
938         printk("Frame format=%X ", regs->format);
939         switch (regs->format) {
940 diff -NurpP --minimal linux-2.6.22.10/arch/m68knommu/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/m68knommu/Kconfig
941 --- linux-2.6.22.10/arch/m68knommu/Kconfig      2007-07-09 13:17:47 +0200
942 +++ linux-2.6.22.10-vs2.3.0.29/arch/m68knommu/Kconfig   2007-08-05 20:53:12 +0200
943 @@ -670,6 +670,8 @@ source "fs/Kconfig"
944  
945  source "arch/m68knommu/Kconfig.debug"
946  
947 +source "kernel/vserver/Kconfig"
948 +
949  source "security/Kconfig"
950  
951  source "crypto/Kconfig"
952 diff -NurpP --minimal linux-2.6.22.10/arch/m68knommu/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/m68knommu/kernel/process.c
953 --- linux-2.6.22.10/arch/m68knommu/kernel/process.c     2007-02-06 03:00:08 +0100
954 +++ linux-2.6.22.10-vs2.3.0.29/arch/m68knommu/kernel/process.c  2007-08-05 20:53:12 +0200
955 @@ -122,7 +122,7 @@ void show_regs(struct pt_regs * regs)
956  int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
957  {
958         int retval;
959 -       long clone_arg = flags | CLONE_VM;
960 +       long clone_arg = flags | CLONE_VM | CLONE_KTHREAD;
961         mm_segment_t fs;
962  
963         fs = get_fs();
964 diff -NurpP --minimal linux-2.6.22.10/arch/m68knommu/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/m68knommu/kernel/traps.c
965 --- linux-2.6.22.10/arch/m68knommu/kernel/traps.c       2007-05-02 19:24:21 +0200
966 +++ linux-2.6.22.10-vs2.3.0.29/arch/m68knommu/kernel/traps.c    2007-08-05 20:53:12 +0200
967 @@ -80,8 +80,9 @@ void die_if_kernel(char *str, struct pt_
968         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
969                fp->d4, fp->d5, fp->a0, fp->a1);
970  
971 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
972 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
973 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
974 +               current->comm, current->pid, current->xid,
975 +               PAGE_SIZE+(unsigned long)current);
976         show_stack(NULL, (unsigned long *)fp);
977         do_exit(SIGSEGV);
978  }
979 diff -NurpP --minimal linux-2.6.22.10/arch/mips/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/mips/Kconfig
980 --- linux-2.6.22.10/arch/mips/Kconfig   2007-07-09 13:17:47 +0200
981 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/Kconfig        2007-08-05 20:53:12 +0200
982 @@ -1959,6 +1959,8 @@ source "arch/mips/oprofile/Kconfig"
983  
984  source "arch/mips/Kconfig.debug"
985  
986 +source "kernel/vserver/Kconfig"
987 +
988  source "security/Kconfig"
989  
990  source "crypto/Kconfig"
991 diff -NurpP --minimal linux-2.6.22.10/arch/mips/kernel/linux32.c linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/linux32.c
992 --- linux-2.6.22.10/arch/mips/kernel/linux32.c  2007-07-09 13:17:48 +0200
993 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/linux32.c       2007-08-05 20:53:12 +0200
994 @@ -229,7 +229,7 @@ sys32_gettimeofday(struct compat_timeval
995  {
996         if (tv) {
997                 struct timeval ktv;
998 -               do_gettimeofday(&ktv);
999 +               vx_gettimeofday(&ktv);
1000                 if (put_tv32(tv, &ktv))
1001                         return -EFAULT;
1002         }
1003 diff -NurpP --minimal linux-2.6.22.10/arch/mips/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/process.c
1004 --- linux-2.6.22.10/arch/mips/kernel/process.c  2007-05-02 19:24:23 +0200
1005 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/process.c       2007-08-05 20:53:12 +0200
1006 @@ -236,7 +236,8 @@ long kernel_thread(int (*fn)(void *), vo
1007  #endif
1008  
1009         /* Ok, create the new process.. */
1010 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0, NULL, NULL);
1011 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
1012 +               0, &regs, 0, NULL, NULL);
1013  }
1014  
1015  /*
1016 diff -NurpP --minimal linux-2.6.22.10/arch/mips/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/ptrace.c
1017 --- linux-2.6.22.10/arch/mips/kernel/ptrace.c   2007-07-09 13:17:48 +0200
1018 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/ptrace.c        2007-08-05 20:53:12 +0200
1019 @@ -25,6 +25,7 @@
1020  #include <linux/user.h>
1021  #include <linux/security.h>
1022  #include <linux/signal.h>
1023 +#include <linux/vs_base.h>
1024  
1025  #include <asm/byteorder.h>
1026  #include <asm/cpu.h>
1027 @@ -171,6 +172,9 @@ long arch_ptrace(struct task_struct *chi
1028  {
1029         int ret;
1030  
1031 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
1032 +               goto out;
1033 +
1034         switch (request) {
1035         /* when I and D space are separate, these will need to be fixed. */
1036         case PTRACE_PEEKTEXT: /* read word at location addr. */
1037 diff -NurpP --minimal linux-2.6.22.10/arch/mips/kernel/scall32-o32.S linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/scall32-o32.S
1038 --- linux-2.6.22.10/arch/mips/kernel/scall32-o32.S      2007-07-09 13:17:48 +0200
1039 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/scall32-o32.S   2007-08-05 20:53:12 +0200
1040 @@ -619,7 +619,7 @@ einval:     li      v0, -EINVAL
1041         sys     sys_mq_timedreceive     5
1042         sys     sys_mq_notify           2       /* 4275 */
1043         sys     sys_mq_getsetattr       3
1044 -       sys     sys_ni_syscall          0       /* sys_vserver */
1045 +       sys     sys_vserver             3
1046         sys     sys_waitid              5
1047         sys     sys_ni_syscall          0       /* available, was setaltroot */
1048         sys     sys_add_key             5       /* 4280 */
1049 diff -NurpP --minimal linux-2.6.22.10/arch/mips/kernel/scall64-64.S linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/scall64-64.S
1050 --- linux-2.6.22.10/arch/mips/kernel/scall64-64.S       2007-07-09 13:17:48 +0200
1051 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/scall64-64.S    2007-08-05 20:53:12 +0200
1052 @@ -434,7 +434,7 @@ sys_call_table:
1053         PTR     sys_mq_timedreceive
1054         PTR     sys_mq_notify
1055         PTR     sys_mq_getsetattr               /* 5235 */
1056 -       PTR     sys_ni_syscall                  /* sys_vserver */
1057 +       PTR     sys_vserver
1058         PTR     sys_waitid
1059         PTR     sys_ni_syscall                  /* available, was setaltroot */
1060         PTR     sys_add_key
1061 diff -NurpP --minimal linux-2.6.22.10/arch/mips/kernel/scall64-n32.S linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/scall64-n32.S
1062 --- linux-2.6.22.10/arch/mips/kernel/scall64-n32.S      2007-07-09 13:17:48 +0200
1063 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/scall64-n32.S   2007-08-05 20:53:12 +0200
1064 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
1065         PTR     compat_sys_mq_timedreceive
1066         PTR     compat_sys_mq_notify
1067         PTR     compat_sys_mq_getsetattr
1068 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
1069 +       PTR     sys32_vserver                   /* 6240 */
1070         PTR     compat_sys_waitid
1071         PTR     sys_ni_syscall                  /* available, was setaltroot */
1072         PTR     sys_add_key
1073 diff -NurpP --minimal linux-2.6.22.10/arch/mips/kernel/scall64-o32.S linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/scall64-o32.S
1074 --- linux-2.6.22.10/arch/mips/kernel/scall64-o32.S      2007-07-09 13:17:48 +0200
1075 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/scall64-o32.S   2007-08-05 20:53:12 +0200
1076 @@ -482,7 +482,7 @@ sys_call_table:
1077         PTR     compat_sys_mq_timedreceive
1078         PTR     compat_sys_mq_notify            /* 4275 */
1079         PTR     compat_sys_mq_getsetattr
1080 -       PTR     sys_ni_syscall                  /* sys_vserver */
1081 +       PTR     sys32_vserver
1082         PTR     sys32_waitid
1083         PTR     sys_ni_syscall                  /* available, was setaltroot */
1084         PTR     sys_add_key                     /* 4280 */
1085 diff -NurpP --minimal linux-2.6.22.10/arch/mips/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/traps.c
1086 --- linux-2.6.22.10/arch/mips/kernel/traps.c    2007-07-09 13:17:48 +0200
1087 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/kernel/traps.c 2007-08-05 20:53:12 +0200
1088 @@ -302,8 +302,9 @@ void show_registers(struct pt_regs *regs
1089  {
1090         show_regs(regs);
1091         print_modules();
1092 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p)\n",
1093 -               current->comm, current->pid, current_thread_info(), current);
1094 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p)\n",
1095 +               current->comm, current->pid, current->xid,
1096 +               current_thread_info(), current);
1097         show_stacktrace(current, regs);
1098         show_code((unsigned int *) regs->cp0_epc);
1099         printk("\n");
1100 diff -NurpP --minimal linux-2.6.22.10/arch/mips/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/mips/mm/fault.c
1101 --- linux-2.6.22.10/arch/mips/mm/fault.c        2007-07-09 13:17:48 +0200
1102 +++ linux-2.6.22.10-vs2.3.0.29/arch/mips/mm/fault.c     2007-08-05 20:53:12 +0200
1103 @@ -179,7 +179,8 @@ out_of_memory:
1104                 down_read(&mm->mmap_sem);
1105                 goto survive;
1106         }
1107 -       printk("VM: killing process %s\n", tsk->comm);
1108 +       printk("VM: killing process %s(%d:#%u)\n",
1109 +               tsk->comm, tsk->pid, tsk->xid);
1110         if (user_mode(regs))
1111                 do_exit(SIGKILL);
1112         goto no_context;
1113 diff -NurpP --minimal linux-2.6.22.10/arch/parisc/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/parisc/Kconfig
1114 --- linux-2.6.22.10/arch/parisc/Kconfig 2007-05-02 19:24:26 +0200
1115 +++ linux-2.6.22.10-vs2.3.0.29/arch/parisc/Kconfig      2007-08-05 20:53:12 +0200
1116 @@ -271,6 +271,8 @@ source "arch/parisc/oprofile/Kconfig"
1117  
1118  source "arch/parisc/Kconfig.debug"
1119  
1120 +source "kernel/vserver/Kconfig"
1121 +
1122  source "security/Kconfig"
1123  
1124  source "crypto/Kconfig"
1125 diff -NurpP --minimal linux-2.6.22.10/arch/parisc/kernel/entry.S linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/entry.S
1126 --- linux-2.6.22.10/arch/parisc/kernel/entry.S  2007-07-09 13:17:50 +0200
1127 +++ linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/entry.S       2007-08-05 20:53:12 +0200
1128 @@ -761,6 +761,7 @@ END(fault_vector_11)
1129  
1130  #define CLONE_VM 0x100 /* Must agree with <linux/sched.h> */
1131  #define CLONE_UNTRACED 0x00800000
1132 +#define CLONE_KTHREAD 0x10000000
1133  
1134         .import do_fork
1135  ENTRY(__kernel_thread)
1136 diff -NurpP --minimal linux-2.6.22.10/arch/parisc/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/process.c
1137 --- linux-2.6.22.10/arch/parisc/kernel/process.c        2007-07-09 13:17:50 +0200
1138 +++ linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/process.c     2007-08-05 20:53:12 +0200
1139 @@ -173,7 +173,7 @@ pid_t kernel_thread(int (*fn)(void *), v
1140          *        kernel_thread can become a #define.
1141          */
1142  
1143 -       return __kernel_thread(fn, arg, flags);
1144 +       return __kernel_thread(fn, arg, flags | CLONE_KTHREAD);
1145  }
1146  EXPORT_SYMBOL(kernel_thread);
1147  
1148 diff -NurpP --minimal linux-2.6.22.10/arch/parisc/kernel/sys_parisc32.c linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/sys_parisc32.c
1149 --- linux-2.6.22.10/arch/parisc/kernel/sys_parisc32.c   2007-07-09 13:17:50 +0200
1150 +++ linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/sys_parisc32.c        2007-08-05 20:53:12 +0200
1151 @@ -204,11 +204,11 @@ static inline long get_ts32(struct times
1152  asmlinkage int
1153  sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
1154  {
1155 -    extern void do_gettimeofday(struct timeval *tv);
1156 +    extern void vx_gettimeofday(struct timeval *tv);
1157  
1158      if (tv) {
1159             struct timeval ktv;
1160 -           do_gettimeofday(&ktv);
1161 +           vx_gettimeofday(&ktv);
1162             if (put_compat_timeval(tv, &ktv))
1163                     return -EFAULT;
1164      }
1165 diff -NurpP --minimal linux-2.6.22.10/arch/parisc/kernel/syscall_table.S linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/syscall_table.S
1166 --- linux-2.6.22.10/arch/parisc/kernel/syscall_table.S  2007-07-09 13:17:50 +0200
1167 +++ linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/syscall_table.S       2007-08-05 20:53:12 +0200
1168 @@ -363,7 +363,7 @@
1169         ENTRY_COMP(mbind)               /* 260 */
1170         ENTRY_COMP(get_mempolicy)
1171         ENTRY_COMP(set_mempolicy)
1172 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
1173 +       ENTRY_DIFF(vserver)
1174         ENTRY_SAME(add_key)
1175         ENTRY_SAME(request_key)         /* 265 */
1176         ENTRY_SAME(keyctl)
1177 diff -NurpP --minimal linux-2.6.22.10/arch/parisc/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/traps.c
1178 --- linux-2.6.22.10/arch/parisc/kernel/traps.c  2007-07-09 13:17:50 +0200
1179 +++ linux-2.6.22.10-vs2.3.0.29/arch/parisc/kernel/traps.c       2007-08-05 20:53:12 +0200
1180 @@ -218,8 +218,9 @@ void die_if_kernel(char *str, struct pt_
1181                 if (err == 0)
1182                         return; /* STFU */
1183  
1184 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
1185 -                       current->comm, current->pid, str, err, regs->iaoq[0]);
1186 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
1187 +                       current->comm, current->pid, current->xid,
1188 +                       str, err, regs->iaoq[0]);
1189  #ifdef PRINT_USER_FAULTS
1190                 /* XXX for debugging only */
1191                 show_regs(regs);
1192 @@ -251,8 +252,8 @@ KERN_CRIT "                     ||     |
1193                 pdc_console_restart();
1194         
1195         if (err)
1196 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
1197 -                       current->comm, current->pid, str, err);
1198 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
1199 +                       current->comm, current->pid, current->xid, str, err);
1200  
1201         /* Wot's wrong wif bein' racy? */
1202         if (current->thread.flags & PARISC_KERNEL_DEATH) {
1203 diff -NurpP --minimal linux-2.6.22.10/arch/parisc/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/parisc/mm/fault.c
1204 --- linux-2.6.22.10/arch/parisc/mm/fault.c      2007-05-02 19:24:26 +0200
1205 +++ linux-2.6.22.10-vs2.3.0.29/arch/parisc/mm/fault.c   2007-08-05 20:53:12 +0200
1206 @@ -209,8 +209,9 @@ bad_area:
1207  
1208  #ifdef PRINT_USER_FAULTS
1209                 printk(KERN_DEBUG "\n");
1210 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
1211 -                   tsk->pid, tsk->comm, code, address);
1212 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
1213 +                   "command='%s' type=%lu address=0x%08lx\n",
1214 +                   tsk->pid, tsk->xid, tsk->comm, code, address);
1215                 if (vma) {
1216                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
1217                                         vma->vm_start, vma->vm_end);
1218 @@ -260,7 +261,8 @@ no_context:
1219  
1220    out_of_memory:
1221         up_read(&mm->mmap_sem);
1222 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
1223 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
1224 +               current->comm, current->pid, current->xid);
1225         if (user_mode(regs))
1226                 do_exit(SIGKILL);
1227         goto no_context;
1228 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/powerpc/Kconfig
1229 --- linux-2.6.22.10/arch/powerpc/Kconfig        2007-07-09 13:17:50 +0200
1230 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/Kconfig     2007-08-05 20:53:12 +0200
1231 @@ -906,6 +906,8 @@ endmenu
1232  
1233  source "arch/powerpc/Kconfig.debug"
1234  
1235 +source "kernel/vserver/Kconfig"
1236 +
1237  source "security/Kconfig"
1238  
1239  config KEYS_COMPAT
1240 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/kernel/asm-offsets.c linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/asm-offsets.c
1241 --- linux-2.6.22.10/arch/powerpc/kernel/asm-offsets.c   2007-07-09 13:17:51 +0200
1242 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/asm-offsets.c        2007-08-05 20:53:12 +0200
1243 @@ -250,6 +250,7 @@ int main(void)
1244  
1245         DEFINE(CLONE_VM, CLONE_VM);
1246         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
1247 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
1248  
1249  #ifndef CONFIG_PPC64
1250         DEFINE(MM_PGD, offsetof(struct mm_struct, pgd));
1251 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/kernel/irq.c linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/irq.c
1252 --- linux-2.6.22.10/arch/powerpc/kernel/irq.c   2007-07-09 13:17:51 +0200
1253 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/irq.c        2007-08-05 20:53:12 +0200
1254 @@ -53,6 +53,7 @@
1255  #include <linux/mutex.h>
1256  #include <linux/bootmem.h>
1257  #include <linux/pci.h>
1258 +#include <linux/vs_context.h>
1259  
1260  #include <asm/uaccess.h>
1261  #include <asm/system.h>
1262 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/kernel/misc_32.S linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/misc_32.S
1263 --- linux-2.6.22.10/arch/powerpc/kernel/misc_32.S       2007-07-09 13:17:51 +0200
1264 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/misc_32.S    2007-08-05 20:53:12 +0200
1265 @@ -745,7 +745,7 @@ _GLOBAL(kernel_thread)
1266         mr      r30,r3          /* function */
1267         mr      r31,r4          /* argument */
1268         ori     r3,r5,CLONE_VM  /* flags */
1269 -       oris    r3,r3,CLONE_UNTRACED>>16
1270 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1271         li      r4,0            /* new sp (unused) */
1272         li      r0,__NR_clone
1273         sc
1274 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/kernel/misc_64.S linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/misc_64.S
1275 --- linux-2.6.22.10/arch/powerpc/kernel/misc_64.S       2007-05-02 19:24:27 +0200
1276 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/misc_64.S    2007-08-05 20:53:12 +0200
1277 @@ -434,7 +434,7 @@ _GLOBAL(kernel_thread)
1278         mr      r29,r3
1279         mr      r30,r4
1280         ori     r3,r5,CLONE_VM  /* flags */
1281 -       oris    r3,r3,(CLONE_UNTRACED>>16)
1282 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1283         li      r4,0            /* new sp (unused) */
1284         li      r0,__NR_clone
1285         sc
1286 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/process.c
1287 --- linux-2.6.22.10/arch/powerpc/kernel/process.c       2007-10-30 01:57:12 +0100
1288 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/process.c    2007-09-30 14:57:55 +0200
1289 @@ -422,8 +422,9 @@ void show_regs(struct pt_regs * regs)
1290         trap = TRAP(regs);
1291         if (trap == 0x300 || trap == 0x600)
1292                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
1293 -       printk("TASK = %p[%d] '%s' THREAD: %p",
1294 -              current, current->pid, current->comm, task_thread_info(current));
1295 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
1296 +              current, current->pid, current->xid,
1297 +              current->comm, task_thread_info(current));
1298  
1299  #ifdef CONFIG_SMP
1300         printk(" CPU: %d", smp_processor_id());
1301 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/kernel/sys_ppc32.c linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/sys_ppc32.c
1302 --- linux-2.6.22.10/arch/powerpc/kernel/sys_ppc32.c     2007-07-09 13:17:51 +0200
1303 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/sys_ppc32.c  2007-08-05 20:53:12 +0200
1304 @@ -205,7 +205,7 @@ asmlinkage long compat_sys_gettimeofday(
1305  {
1306         if (tv) {
1307                 struct timeval ktv;
1308 -               do_gettimeofday(&ktv);
1309 +               vx_gettimeofday(&ktv);
1310                 if (put_tv32(tv, &ktv))
1311                         return -EFAULT;
1312         }
1313 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/traps.c
1314 --- linux-2.6.22.10/arch/powerpc/kernel/traps.c 2007-07-09 13:17:51 +0200
1315 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/traps.c      2007-08-05 20:53:12 +0200
1316 @@ -878,8 +878,9 @@ void nonrecoverable_exception(struct pt_
1317  
1318  void trace_syscall(struct pt_regs *regs)
1319  {
1320 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1321 -              current, current->pid, regs->nip, regs->link, regs->gpr[0],
1322 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1323 +              current, current->pid, current->xid,
1324 +              regs->nip, regs->link, regs->gpr[0],
1325                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
1326  }
1327  
1328 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/kernel/vdso.c linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/vdso.c
1329 --- linux-2.6.22.10/arch/powerpc/kernel/vdso.c  2007-07-09 13:17:51 +0200
1330 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/kernel/vdso.c       2007-08-05 20:53:12 +0200
1331 @@ -21,6 +21,7 @@
1332  #include <linux/elf.h>
1333  #include <linux/security.h>
1334  #include <linux/bootmem.h>
1335 +#include <linux/vs_memory.h>
1336  
1337  #include <asm/pgtable.h>
1338  #include <asm/system.h>
1339 diff -NurpP --minimal linux-2.6.22.10/arch/powerpc/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/powerpc/mm/fault.c
1340 --- linux-2.6.22.10/arch/powerpc/mm/fault.c     2007-07-09 13:17:51 +0200
1341 +++ linux-2.6.22.10-vs2.3.0.29/arch/powerpc/mm/fault.c  2007-08-05 20:53:12 +0200
1342 @@ -378,7 +378,8 @@ out_of_memory:
1343                 down_read(&mm->mmap_sem);
1344                 goto survive;
1345         }
1346 -       printk("VM: killing process %s\n", current->comm);
1347 +       printk("VM: killing process %s(%d:#%u)\n",
1348 +               current->comm, current->pid, current->xid);
1349         if (user_mode(regs))
1350                 do_exit(SIGKILL);
1351         return SIGKILL;
1352 diff -NurpP --minimal linux-2.6.22.10/arch/ppc/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/ppc/Kconfig
1353 --- linux-2.6.22.10/arch/ppc/Kconfig    2007-05-02 19:24:28 +0200
1354 +++ linux-2.6.22.10-vs2.3.0.29/arch/ppc/Kconfig 2007-08-05 20:53:12 +0200
1355 @@ -1455,6 +1455,8 @@ source "arch/powerpc/oprofile/Kconfig"
1356  
1357  source "arch/ppc/Kconfig.debug"
1358  
1359 +source "kernel/vserver/Kconfig"
1360 +
1361  source "security/Kconfig"
1362  
1363  source "crypto/Kconfig"
1364 diff -NurpP --minimal linux-2.6.22.10/arch/ppc/kernel/asm-offsets.c linux-2.6.22.10-vs2.3.0.29/arch/ppc/kernel/asm-offsets.c
1365 --- linux-2.6.22.10/arch/ppc/kernel/asm-offsets.c       2007-07-09 13:18:01 +0200
1366 +++ linux-2.6.22.10-vs2.3.0.29/arch/ppc/kernel/asm-offsets.c    2007-08-05 20:53:12 +0200
1367 @@ -120,6 +120,7 @@ main(void)
1368         DEFINE(TRAP, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, trap));
1369         DEFINE(CLONE_VM, CLONE_VM);
1370         DEFINE(CLONE_UNTRACED, CLONE_UNTRACED);
1371 +       DEFINE(CLONE_KTHREAD, CLONE_KTHREAD);
1372         DEFINE(MM_PGD, offsetof(struct mm_struct, pgd));
1373  
1374         /* About the CPU features table */
1375 diff -NurpP --minimal linux-2.6.22.10/arch/ppc/kernel/misc.S linux-2.6.22.10-vs2.3.0.29/arch/ppc/kernel/misc.S
1376 --- linux-2.6.22.10/arch/ppc/kernel/misc.S      2006-11-30 21:18:32 +0100
1377 +++ linux-2.6.22.10-vs2.3.0.29/arch/ppc/kernel/misc.S   2007-08-05 20:53:12 +0200
1378 @@ -848,7 +848,7 @@ _GLOBAL(kernel_thread)
1379         mr      r30,r3          /* function */
1380         mr      r31,r4          /* argument */
1381         ori     r3,r5,CLONE_VM  /* flags */
1382 -       oris    r3,r3,CLONE_UNTRACED>>16
1383 +       oris    r3,r3,(CLONE_UNTRACED|CLONE_KTHREAD)>>16
1384         li      r4,0            /* new sp (unused) */
1385         li      r0,__NR_clone
1386         sc
1387 diff -NurpP --minimal linux-2.6.22.10/arch/ppc/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/ppc/kernel/traps.c
1388 --- linux-2.6.22.10/arch/ppc/kernel/traps.c     2007-07-09 13:18:01 +0200
1389 +++ linux-2.6.22.10-vs2.3.0.29/arch/ppc/kernel/traps.c  2007-08-05 20:53:12 +0200
1390 @@ -696,8 +696,9 @@ void nonrecoverable_exception(struct pt_
1391  
1392  void trace_syscall(struct pt_regs *regs)
1393  {
1394 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1395 -              current, current->pid, regs->nip, regs->link, regs->gpr[0],
1396 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
1397 +              current, current->pid, current->xid,
1398 +              regs->nip, regs->link, regs->gpr[0],
1399                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
1400  }
1401  
1402 diff -NurpP --minimal linux-2.6.22.10/arch/ppc/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/ppc/mm/fault.c
1403 --- linux-2.6.22.10/arch/ppc/mm/fault.c 2006-11-30 21:18:32 +0100
1404 +++ linux-2.6.22.10-vs2.3.0.29/arch/ppc/mm/fault.c      2007-08-05 20:53:12 +0200
1405 @@ -296,7 +296,8 @@ out_of_memory:
1406                 down_read(&mm->mmap_sem);
1407                 goto survive;
1408         }
1409 -       printk("VM: killing process %s\n", current->comm);
1410 +       printk("VM: killing process %s(%d:#%u)\n",
1411 +               current->comm, current->pid, current->xid);
1412         if (user_mode(regs))
1413                 do_exit(SIGKILL);
1414         return SIGKILL;
1415 diff -NurpP --minimal linux-2.6.22.10/arch/s390/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/s390/Kconfig
1416 --- linux-2.6.22.10/arch/s390/Kconfig   2007-07-09 13:18:02 +0200
1417 +++ linux-2.6.22.10-vs2.3.0.29/arch/s390/Kconfig        2007-08-05 20:53:12 +0200
1418 @@ -551,6 +551,8 @@ endmenu
1419  
1420  source "arch/s390/Kconfig.debug"
1421  
1422 +source "kernel/vserver/Kconfig"
1423 +
1424  source "security/Kconfig"
1425  
1426  source "crypto/Kconfig"
1427 diff -NurpP --minimal linux-2.6.22.10/arch/s390/kernel/compat_linux.c linux-2.6.22.10-vs2.3.0.29/arch/s390/kernel/compat_linux.c
1428 --- linux-2.6.22.10/arch/s390/kernel/compat_linux.c     2007-07-09 13:18:02 +0200
1429 +++ linux-2.6.22.10-vs2.3.0.29/arch/s390/kernel/compat_linux.c  2007-08-05 20:53:12 +0200
1430 @@ -567,7 +567,7 @@ asmlinkage long sys32_gettimeofday(struc
1431  {
1432         if (tv) {
1433                 struct timeval ktv;
1434 -               do_gettimeofday(&ktv);
1435 +               vx_gettimeofday(&ktv);
1436                 if (put_tv32(tv, &ktv))
1437                         return -EFAULT;
1438         }
1439 diff -NurpP --minimal linux-2.6.22.10/arch/s390/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/s390/kernel/process.c
1440 --- linux-2.6.22.10/arch/s390/kernel/process.c  2007-07-09 13:18:02 +0200
1441 +++ linux-2.6.22.10-vs2.3.0.29/arch/s390/kernel/process.c       2007-08-05 20:53:12 +0200
1442 @@ -164,9 +164,9 @@ void show_regs(struct pt_regs *regs)
1443         struct task_struct *tsk = current;
1444  
1445          printk("CPU:    %d    %s\n", task_thread_info(tsk)->cpu, print_tainted());
1446 -        printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
1447 -              current->comm, current->pid, (void *) tsk,
1448 -              (void *) tsk->thread.ksp);
1449 +       printk("Process %s (pid: %d[#%u], task: %p, ksp: %p)\n",
1450 +              current->comm, current->pid, current->xid,
1451 +              (void *) tsk, (void *) tsk->thread.ksp);
1452  
1453         show_registers(regs);
1454         /* Show stack backtrace if pt_regs is from kernel mode */
1455 @@ -197,7 +197,7 @@ int kernel_thread(int (*fn)(void *), voi
1456         regs.orig_gpr2 = -1;
1457  
1458         /* Ok, create the new process.. */
1459 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED,
1460 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
1461                        0, &regs, 0, NULL, NULL);
1462  }
1463  
1464 diff -NurpP --minimal linux-2.6.22.10/arch/s390/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/arch/s390/kernel/ptrace.c
1465 --- linux-2.6.22.10/arch/s390/kernel/ptrace.c   2007-05-02 19:24:29 +0200
1466 +++ linux-2.6.22.10-vs2.3.0.29/arch/s390/kernel/ptrace.c        2007-08-05 20:53:12 +0200
1467 @@ -33,6 +33,7 @@
1468  #include <linux/security.h>
1469  #include <linux/audit.h>
1470  #include <linux/signal.h>
1471 +#include <linux/vs_base.h>
1472  
1473  #include <asm/segment.h>
1474  #include <asm/page.h>
1475 @@ -725,7 +726,13 @@ sys_ptrace(long request, long pid, long 
1476                 goto out;
1477         }
1478  
1479 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1480 +               ret = -EPERM;
1481 +               goto out_tsk;
1482 +       }
1483 +
1484         ret = do_ptrace(child, request, addr, data);
1485 +out_tsk:
1486         put_task_struct(child);
1487  out:
1488         unlock_kernel();
1489 diff -NurpP --minimal linux-2.6.22.10/arch/s390/kernel/syscalls.S linux-2.6.22.10-vs2.3.0.29/arch/s390/kernel/syscalls.S
1490 --- linux-2.6.22.10/arch/s390/kernel/syscalls.S 2007-07-09 13:18:02 +0200
1491 +++ linux-2.6.22.10-vs2.3.0.29/arch/s390/kernel/syscalls.S      2007-08-05 20:53:12 +0200
1492 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
1493  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
1494  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
1495  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
1496 -NI_SYSCALL                                                     /* reserved for vserver */
1497 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
1498  SYSCALL(s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
1499  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
1500  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
1501 diff -NurpP --minimal linux-2.6.22.10/arch/s390/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/s390/mm/fault.c
1502 --- linux-2.6.22.10/arch/s390/mm/fault.c        2007-07-09 13:18:02 +0200
1503 +++ linux-2.6.22.10-vs2.3.0.29/arch/s390/mm/fault.c     2007-08-05 20:53:12 +0200
1504 @@ -216,7 +216,8 @@ static int do_out_of_memory(struct pt_re
1505                 down_read(&mm->mmap_sem);
1506                 return 1;
1507         }
1508 -       printk("VM: killing process %s\n", tsk->comm);
1509 +       printk("VM: killing process %s(%d:#%u)\n",
1510 +               tsk->comm, tsk->pid, tsk->xid);
1511         if (regs->psw.mask & PSW_MASK_PSTATE)
1512                 do_exit(SIGKILL);
1513         do_no_context(regs, error_code, address);
1514 diff -NurpP --minimal linux-2.6.22.10/arch/sh/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/sh/Kconfig
1515 --- linux-2.6.22.10/arch/sh/Kconfig     2007-07-09 13:18:02 +0200
1516 +++ linux-2.6.22.10-vs2.3.0.29/arch/sh/Kconfig  2007-08-05 20:53:12 +0200
1517 @@ -723,6 +723,8 @@ source "arch/sh/oprofile/Kconfig"
1518  
1519  source "arch/sh/Kconfig.debug"
1520  
1521 +source "kernel/vserver/Kconfig"
1522 +
1523  source "security/Kconfig"
1524  
1525  source "crypto/Kconfig"
1526 diff -NurpP --minimal linux-2.6.22.10/arch/sh/kernel/irq.c linux-2.6.22.10-vs2.3.0.29/arch/sh/kernel/irq.c
1527 --- linux-2.6.22.10/arch/sh/kernel/irq.c        2007-07-09 13:18:03 +0200
1528 +++ linux-2.6.22.10-vs2.3.0.29/arch/sh/kernel/irq.c     2007-08-05 20:53:12 +0200
1529 @@ -12,6 +12,7 @@
1530  #include <linux/kernel_stat.h>
1531  #include <linux/seq_file.h>
1532  #include <linux/irq.h>
1533 +#include <linux/vs_context.h>
1534  #include <asm/processor.h>
1535  #include <asm/machvec.h>
1536  #include <asm/uaccess.h>
1537 diff -NurpP --minimal linux-2.6.22.10/arch/sh/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/sh/kernel/process.c
1538 --- linux-2.6.22.10/arch/sh/kernel/process.c    2007-07-09 13:18:03 +0200
1539 +++ linux-2.6.22.10-vs2.3.0.29/arch/sh/kernel/process.c 2007-08-05 20:53:12 +0200
1540 @@ -118,7 +118,8 @@ void machine_power_off(void)
1541  void show_regs(struct pt_regs * regs)
1542  {
1543         printk("\n");
1544 -       printk("Pid : %d, Comm: %20s\n", current->pid, current->comm);
1545 +       printk("Pid : %d:#%u, Comm: %20s\n",
1546 +               current->pid, current->xid, current->comm);
1547         print_symbol("PC is at %s\n", instruction_pointer(regs));
1548         printk("PC  : %08lx SP  : %08lx SR  : %08lx ",
1549                regs->pc, regs->regs[15], regs->sr);
1550 @@ -179,7 +180,7 @@ int kernel_thread(int (*fn)(void *), voi
1551         regs.sr = (1 << 30);
1552  
1553         /* Ok, create the new process.. */
1554 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
1555 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD, 0,
1556                        &regs, 0, NULL, NULL);
1557  }
1558  
1559 diff -NurpP --minimal linux-2.6.22.10/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.22.10-vs2.3.0.29/arch/sh/kernel/vsyscall/vsyscall.c
1560 --- linux-2.6.22.10/arch/sh/kernel/vsyscall/vsyscall.c  2007-07-09 13:18:03 +0200
1561 +++ linux-2.6.22.10-vs2.3.0.29/arch/sh/kernel/vsyscall/vsyscall.c       2007-08-05 20:53:12 +0200
1562 @@ -18,6 +18,7 @@
1563  #include <linux/module.h>
1564  #include <linux/elf.h>
1565  #include <linux/sched.h>
1566 +#include <linux/vs_memory.h>
1567  
1568  /*
1569   * Should the kernel map a VDSO page into processes and pass its
1570 diff -NurpP --minimal linux-2.6.22.10/arch/sh/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/sh/mm/fault.c
1571 --- linux-2.6.22.10/arch/sh/mm/fault.c  2007-07-09 13:18:03 +0200
1572 +++ linux-2.6.22.10-vs2.3.0.29/arch/sh/mm/fault.c       2007-08-05 20:53:12 +0200
1573 @@ -201,7 +201,8 @@ out_of_memory:
1574                 down_read(&mm->mmap_sem);
1575                 goto survive;
1576         }
1577 -       printk("VM: killing process %s\n", tsk->comm);
1578 +       printk("VM: killing process %s(%d:#%u)\n",
1579 +               tsk->comm, tsk->pid, tsk->xid);
1580         if (user_mode(regs))
1581                 do_exit(SIGKILL);
1582         goto no_context;
1583 diff -NurpP --minimal linux-2.6.22.10/arch/sh64/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/sh64/kernel/process.c
1584 --- linux-2.6.22.10/arch/sh64/kernel/process.c  2007-07-09 13:18:03 +0200
1585 +++ linux-2.6.22.10-vs2.3.0.29/arch/sh64/kernel/process.c       2007-08-05 20:53:12 +0200
1586 @@ -400,8 +400,8 @@ int kernel_thread(int (*fn)(void *), voi
1587         regs.pc = (unsigned long)kernel_thread_helper;
1588         regs.sr = (1 << 30);
1589  
1590 -       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0,
1591 -                      &regs, 0, NULL, NULL);
1592 +       return do_fork(flags | CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD,
1593 +               0, &regs, 0, NULL, NULL);
1594  }
1595  
1596  /*
1597 diff -NurpP --minimal linux-2.6.22.10/arch/sh64/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/sh64/mm/fault.c
1598 --- linux-2.6.22.10/arch/sh64/mm/fault.c        2007-07-09 13:18:04 +0200
1599 +++ linux-2.6.22.10-vs2.3.0.29/arch/sh64/mm/fault.c     2007-08-05 20:53:12 +0200
1600 @@ -81,7 +81,7 @@ static inline void print_vma(struct vm_a
1601  
1602  static inline void print_task(struct task_struct *tsk)
1603  {
1604 -       printk("Task pid %d\n", tsk->pid);
1605 +       printk("Task pid %d:#%u\n", tsk->pid, tsk->xid);
1606  }
1607  
1608  static pte_t *lookup_pte(struct mm_struct *mm, unsigned long address)
1609 @@ -330,7 +330,8 @@ out_of_memory:
1610                 down_read(&mm->mmap_sem);
1611                 goto survive;
1612         }
1613 -       printk("VM: killing process %s\n", tsk->comm);
1614 +       printk("VM: killing process %s(%d:#%u)\n",
1615 +               tsk->comm, tsk->pid, tsk->xid);
1616         if (user_mode(regs))
1617                 do_exit(SIGKILL);
1618         goto no_context;
1619 diff -NurpP --minimal linux-2.6.22.10/arch/sparc/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/sparc/Kconfig
1620 --- linux-2.6.22.10/arch/sparc/Kconfig  2007-07-09 13:18:04 +0200
1621 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc/Kconfig       2007-08-05 20:53:12 +0200
1622 @@ -317,6 +317,8 @@ endmenu
1623  
1624  source "arch/sparc/Kconfig.debug"
1625  
1626 +source "kernel/vserver/Kconfig"
1627 +
1628  source "security/Kconfig"
1629  
1630  source "crypto/Kconfig"
1631 diff -NurpP --minimal linux-2.6.22.10/arch/sparc/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/sparc/kernel/process.c
1632 --- linux-2.6.22.10/arch/sparc/kernel/process.c 2007-07-09 13:18:04 +0200
1633 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc/kernel/process.c      2007-08-05 20:53:12 +0200
1634 @@ -705,7 +705,8 @@ pid_t kernel_thread(int (*fn)(void *), v
1635                              /* Notreached by child. */
1636                              "1: mov %%o0, %0\n\t" :
1637                              "=r" (retval) :
1638 -                            "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
1639 +                            "i" (__NR_clone), "r" (flags |
1640 +                                       CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD),
1641                              "i" (__NR_exit),  "r" (fn), "r" (arg) :
1642                              "g1", "g2", "g3", "o0", "o1", "memory", "cc");
1643         return retval;
1644 diff -NurpP --minimal linux-2.6.22.10/arch/sparc/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/arch/sparc/kernel/ptrace.c
1645 --- linux-2.6.22.10/arch/sparc/kernel/ptrace.c  2007-02-06 03:00:18 +0100
1646 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc/kernel/ptrace.c       2007-08-05 20:53:12 +0200
1647 @@ -19,6 +19,7 @@
1648  #include <linux/smp_lock.h>
1649  #include <linux/security.h>
1650  #include <linux/signal.h>
1651 +#include <linux/vs_base.h>
1652  
1653  #include <asm/pgtable.h>
1654  #include <asm/system.h>
1655 @@ -302,6 +303,10 @@ asmlinkage void do_ptrace(struct pt_regs
1656                 pt_error_return(regs, -ret);
1657                 goto out;
1658         }
1659 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1660 +               pt_error_return(regs, ESRCH);
1661 +               goto out_tsk;
1662 +       }
1663  
1664         if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
1665             || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
1666 diff -NurpP --minimal linux-2.6.22.10/arch/sparc/kernel/systbls.S linux-2.6.22.10-vs2.3.0.29/arch/sparc/kernel/systbls.S
1667 --- linux-2.6.22.10/arch/sparc/kernel/systbls.S 2007-07-09 13:18:04 +0200
1668 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc/kernel/systbls.S      2007-08-05 20:53:12 +0200
1669 @@ -71,7 +71,7 @@ sys_call_table:
1670  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1671  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1672  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1673 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
1674 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1675  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1676  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1677  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1678 diff -NurpP --minimal linux-2.6.22.10/arch/sparc/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/sparc/kernel/traps.c
1679 --- linux-2.6.22.10/arch/sparc/kernel/traps.c   2007-07-09 13:18:05 +0200
1680 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc/kernel/traps.c        2007-08-05 20:53:12 +0200
1681 @@ -99,7 +99,8 @@ void die_if_kernel(char *str, struct pt_
1682  "              /_| \\__/ |_\\\n"
1683  "                 \\__U_/\n");
1684  
1685 -       printk("%s(%d): %s [#%d]\n", current->comm, current->pid, str, ++die_counter);
1686 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
1687 +               current->pid, current->xid, str, ++die_counter);
1688         show_regs(regs);
1689  
1690         __SAVE; __SAVE; __SAVE; __SAVE;
1691 diff -NurpP --minimal linux-2.6.22.10/arch/sparc/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/sparc/mm/fault.c
1692 --- linux-2.6.22.10/arch/sparc/mm/fault.c       2007-07-09 13:18:05 +0200
1693 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc/mm/fault.c    2007-08-05 20:53:12 +0200
1694 @@ -367,7 +367,8 @@ no_context:
1695   */
1696  out_of_memory:
1697         up_read(&mm->mmap_sem);
1698 -       printk("VM: killing process %s\n", tsk->comm);
1699 +       printk("VM: killing process %s(%d:#%u)\n",
1700 +               tsk->comm, tsk->pid, tsk->xid);
1701         if (from_user)
1702                 do_exit(SIGKILL);
1703         goto no_context;
1704 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/sparc64/Kconfig
1705 --- linux-2.6.22.10/arch/sparc64/Kconfig        2007-07-09 13:18:06 +0200
1706 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/Kconfig     2007-08-05 20:53:12 +0200
1707 @@ -451,6 +451,8 @@ endmenu
1708  
1709  source "arch/sparc64/Kconfig.debug"
1710  
1711 +source "kernel/vserver/Kconfig"
1712 +
1713  source "security/Kconfig"
1714  
1715  source "crypto/Kconfig"
1716 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/kernel/binfmt_aout32.c linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/binfmt_aout32.c
1717 --- linux-2.6.22.10/arch/sparc64/kernel/binfmt_aout32.c 2007-02-06 03:00:18 +0100
1718 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/binfmt_aout32.c      2007-08-05 20:53:12 +0200
1719 @@ -27,6 +27,7 @@
1720  #include <linux/binfmts.h>
1721  #include <linux/personality.h>
1722  #include <linux/init.h>
1723 +#include <linux/vs_memory.h>
1724  
1725  #include <asm/system.h>
1726  #include <asm/uaccess.h>
1727 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/process.c
1728 --- linux-2.6.22.10/arch/sparc64/kernel/process.c       2007-07-09 13:18:06 +0200
1729 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/process.c    2007-08-05 20:53:12 +0200
1730 @@ -707,7 +707,8 @@ pid_t kernel_thread(int (*fn)(void *), v
1731                              /* Notreached by child. */
1732                              "1:" :
1733                              "=r" (retval) :
1734 -                            "i" (__NR_clone), "r" (flags | CLONE_VM | CLONE_UNTRACED),
1735 +                            "i" (__NR_clone), "r" (flags |
1736 +                               CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD),
1737                              "i" (__NR_exit),  "r" (fn), "r" (arg) :
1738                              "g1", "g2", "g3", "o0", "o1", "memory", "cc");
1739         return retval;
1740 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/ptrace.c
1741 --- linux-2.6.22.10/arch/sparc64/kernel/ptrace.c        2007-02-06 03:00:18 +0100
1742 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/ptrace.c     2007-08-05 20:53:12 +0200
1743 @@ -22,6 +22,7 @@
1744  #include <linux/seccomp.h>
1745  #include <linux/audit.h>
1746  #include <linux/signal.h>
1747 +#include <linux/vs_base.h>
1748  
1749  #include <asm/asi.h>
1750  #include <asm/pgtable.h>
1751 @@ -215,6 +216,10 @@ asmlinkage void do_ptrace(struct pt_regs
1752                 pt_error_return(regs, -ret);
1753                 goto out;
1754         }
1755 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT)) {
1756 +               pt_error_return(regs, ESRCH);
1757 +               goto out_tsk;
1758 +       }
1759  
1760         if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
1761             || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
1762 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/kernel/sys_sparc32.c linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/sys_sparc32.c
1763 --- linux-2.6.22.10/arch/sparc64/kernel/sys_sparc32.c   2007-07-09 13:18:06 +0200
1764 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/sys_sparc32.c        2007-08-05 20:53:12 +0200
1765 @@ -729,7 +729,7 @@ asmlinkage long sys32_gettimeofday(struc
1766  {
1767         if (tv) {
1768                 struct timeval ktv;
1769 -               do_gettimeofday(&ktv);
1770 +               vx_gettimeofday(&ktv);
1771                 if (put_tv32(tv, &ktv))
1772                         return -EFAULT;
1773         }
1774 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/kernel/systbls.S linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/systbls.S
1775 --- linux-2.6.22.10/arch/sparc64/kernel/systbls.S       2007-07-09 13:18:06 +0200
1776 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/systbls.S    2007-08-05 20:53:12 +0200
1777 @@ -72,7 +72,7 @@ sys_call_table32:
1778  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
1779         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
1780  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
1781 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
1782 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
1783  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
1784         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
1785  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
1786 @@ -144,7 +144,7 @@ sys_call_table:
1787  /*250*/        .word sys64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1788         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1789  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1790 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
1791 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1792  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1793         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1794  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1795 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/traps.c
1796 --- linux-2.6.22.10/arch/sparc64/kernel/traps.c 2007-10-30 01:57:12 +0100
1797 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/kernel/traps.c      2007-09-05 03:06:11 +0200
1798 @@ -2225,7 +2225,8 @@ void die_if_kernel(char *str, struct pt_
1799  "              /_| \\__/ |_\\\n"
1800  "                 \\__U_/\n");
1801  
1802 -       printk("%s(%d): %s [#%d]\n", current->comm, current->pid, str, ++die_counter);
1803 +       printk("%s(%d[#%u]): %s [#%d]\n", current->comm,
1804 +               current->pid, current->xid, str, ++die_counter);
1805         notify_die(DIE_OOPS, str, regs, 0, 255, SIGSEGV);
1806         __asm__ __volatile__("flushw");
1807         __show_regs(regs);
1808 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/sparc64/mm/fault.c
1809 --- linux-2.6.22.10/arch/sparc64/mm/fault.c     2007-10-30 01:57:12 +0100
1810 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/mm/fault.c  2007-09-05 03:06:11 +0200
1811 @@ -463,7 +463,8 @@ handle_kernel_fault:
1812  out_of_memory:
1813         insn = get_fault_insn(regs, insn);
1814         up_read(&mm->mmap_sem);
1815 -       printk("VM: killing process %s\n", current->comm);
1816 +       printk("VM: killing process %s(%d:#%u)\n",
1817 +               current->comm, current->pid, current->xid);
1818         if (!(regs->tstate & TSTATE_PRIV))
1819                 do_exit(SIGKILL);
1820         goto handle_kernel_fault;
1821 diff -NurpP --minimal linux-2.6.22.10/arch/sparc64/solaris/fs.c linux-2.6.22.10-vs2.3.0.29/arch/sparc64/solaris/fs.c
1822 --- linux-2.6.22.10/arch/sparc64/solaris/fs.c   2007-02-06 03:00:21 +0100
1823 +++ linux-2.6.22.10-vs2.3.0.29/arch/sparc64/solaris/fs.c        2007-08-05 20:53:12 +0200
1824 @@ -368,7 +368,7 @@ static int report_statvfs(struct vfsmoun
1825                 int j = strlen (p);
1826                 
1827                 if (j > 15) j = 15;
1828 -               if (IS_RDONLY(inode)) i = 1;
1829 +               if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt)) i = 1;
1830                 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
1831                 if (!sysv_valid_dev(inode->i_sb->s_dev))
1832                         return -EOVERFLOW;
1833 @@ -404,7 +404,7 @@ static int report_statvfs64(struct vfsmo
1834                 int j = strlen (p);
1835                 
1836                 if (j > 15) j = 15;
1837 -               if (IS_RDONLY(inode)) i = 1;
1838 +               if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt)) i = 1;
1839                 if (mnt->mnt_flags & MNT_NOSUID) i |= 2;
1840                 if (!sysv_valid_dev(inode->i_sb->s_dev))
1841                         return -EOVERFLOW;
1842 diff -NurpP --minimal linux-2.6.22.10/arch/um/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/um/Kconfig
1843 --- linux-2.6.22.10/arch/um/Kconfig     2007-07-09 13:18:07 +0200
1844 +++ linux-2.6.22.10-vs2.3.0.29/arch/um/Kconfig  2007-08-05 20:53:12 +0200
1845 @@ -316,6 +316,8 @@ source "drivers/connector/Kconfig"
1846  
1847  source "fs/Kconfig"
1848  
1849 +source "kernel/vserver/Kconfig"
1850 +
1851  source "security/Kconfig"
1852  
1853  source "crypto/Kconfig"
1854 diff -NurpP --minimal linux-2.6.22.10/arch/um/kernel/trap.c linux-2.6.22.10-vs2.3.0.29/arch/um/kernel/trap.c
1855 --- linux-2.6.22.10/arch/um/kernel/trap.c       2007-07-09 13:18:07 +0200
1856 +++ linux-2.6.22.10-vs2.3.0.29/arch/um/kernel/trap.c    2007-08-05 20:53:12 +0200
1857 @@ -210,7 +210,8 @@ unsigned long segv(struct faultinfo fi, 
1858                 current->thread.arch.faultinfo = fi;
1859                 force_sig_info(SIGBUS, &si, current);
1860         } else if (err == -ENOMEM) {
1861 -               printk("VM: killing process %s\n", current->comm);
1862 +               printk("VM: killing process %s(%d:#%u)\n",
1863 +                       current->comm, current->pid, current->xid);
1864                 do_exit(SIGKILL);
1865         } else {
1866                 BUG_ON(err != -EFAULT);
1867 diff -NurpP --minimal linux-2.6.22.10/arch/v850/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/v850/Kconfig
1868 --- linux-2.6.22.10/arch/v850/Kconfig   2007-07-09 13:18:08 +0200
1869 +++ linux-2.6.22.10-vs2.3.0.29/arch/v850/Kconfig        2007-08-05 20:53:12 +0200
1870 @@ -333,6 +333,8 @@ source "drivers/usb/Kconfig"
1871  
1872  source "arch/v850/Kconfig.debug"
1873  
1874 +source "kernel/vserver/Kconfig"
1875 +
1876  source "security/Kconfig"
1877  
1878  source "crypto/Kconfig"
1879 diff -NurpP --minimal linux-2.6.22.10/arch/v850/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/v850/kernel/process.c
1880 --- linux-2.6.22.10/arch/v850/kernel/process.c  2007-07-09 13:18:08 +0200
1881 +++ linux-2.6.22.10-vs2.3.0.29/arch/v850/kernel/process.c       2007-08-05 20:53:12 +0200
1882 @@ -82,7 +82,7 @@ int kernel_thread (int (*fn)(void *), vo
1883         /* Clone this thread.  Note that we don't pass the clone syscall's
1884            second argument -- it's ignored for calls from kernel mode (the
1885            child's SP is always set to the top of the kernel stack).  */
1886 -       arg0 = flags | CLONE_VM;
1887 +       arg0 = flags | CLONE_VM | CLONE_KTHREAD;
1888         syscall = __NR_clone;
1889         asm volatile ("trap " SYSCALL_SHORT_TRAP
1890                       : "=r" (ret), "=r" (syscall)
1891 diff -NurpP --minimal linux-2.6.22.10/arch/v850/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/arch/v850/kernel/ptrace.c
1892 --- linux-2.6.22.10/arch/v850/kernel/ptrace.c   2007-07-09 13:18:08 +0200
1893 +++ linux-2.6.22.10-vs2.3.0.29/arch/v850/kernel/ptrace.c        2007-08-05 20:53:12 +0200
1894 @@ -23,6 +23,7 @@
1895  #include <linux/sched.h>
1896  #include <linux/ptrace.h>
1897  #include <linux/signal.h>
1898 +#include <linux/vs_base.h>
1899  
1900  #include <asm/errno.h>
1901  #include <asm/ptrace.h>
1902 @@ -116,6 +117,9 @@ long arch_ptrace(struct task_struct *chi
1903  {
1904         int rval;
1905  
1906 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
1907 +               goto out;
1908 +
1909         switch (request) {
1910                 unsigned long val, copied;
1911  
1912 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/Kconfig linux-2.6.22.10-vs2.3.0.29/arch/x86_64/Kconfig
1913 --- linux-2.6.22.10/arch/x86_64/Kconfig 2007-07-09 13:18:08 +0200
1914 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/Kconfig      2007-08-05 20:53:12 +0200
1915 @@ -782,6 +782,8 @@ endmenu
1916  
1917  source "arch/x86_64/Kconfig.debug"
1918  
1919 +source "kernel/vserver/Kconfig"
1920 +
1921  source "security/Kconfig"
1922  
1923  source "crypto/Kconfig"
1924 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/ia32/ia32_aout.c linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/ia32_aout.c
1925 --- linux-2.6.22.10/arch/x86_64/ia32/ia32_aout.c        2007-02-06 03:00:21 +0100
1926 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/ia32_aout.c     2007-08-05 20:53:12 +0200
1927 @@ -25,6 +25,7 @@
1928  #include <linux/binfmts.h>
1929  #include <linux/personality.h>
1930  #include <linux/init.h>
1931 +#include <linux/vs_memory.h>
1932  
1933  #include <asm/system.h>
1934  #include <asm/uaccess.h>
1935 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/ia32/ia32_binfmt.c linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/ia32_binfmt.c
1936 --- linux-2.6.22.10/arch/x86_64/ia32/ia32_binfmt.c      2007-07-09 13:18:08 +0200
1937 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/ia32_binfmt.c   2007-08-05 20:53:12 +0200
1938 @@ -324,7 +324,8 @@ int ia32_setup_arg_pages(struct linux_bi
1939                         kmem_cache_free(vm_area_cachep, mpnt);
1940                         return ret;
1941                 }
1942 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
1943 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
1944 +               mm->stack_vm = mm->total_vm;
1945         } 
1946  
1947         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
1948 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/ia32/ia32entry.S linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/ia32entry.S
1949 --- linux-2.6.22.10/arch/x86_64/ia32/ia32entry.S        2007-10-30 01:57:12 +0100
1950 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/ia32entry.S     2007-09-30 14:57:59 +0200
1951 @@ -680,7 +680,7 @@ ia32_sys_call_table:
1952         .quad sys_tgkill                /* 270 */
1953         .quad compat_sys_utimes
1954         .quad sys32_fadvise64_64
1955 -       .quad quiet_ni_syscall  /* sys_vserver */
1956 +       .quad sys32_vserver
1957         .quad sys_mbind
1958         .quad compat_sys_get_mempolicy  /* 275 */
1959         .quad sys_set_mempolicy
1960 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/ia32/sys_ia32.c linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/sys_ia32.c
1961 --- linux-2.6.22.10/arch/x86_64/ia32/sys_ia32.c 2007-07-09 13:18:08 +0200
1962 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/sys_ia32.c      2007-08-05 20:53:12 +0200
1963 @@ -454,7 +454,7 @@ sys32_gettimeofday(struct compat_timeval
1964  {
1965         if (tv) {
1966                 struct timeval ktv;
1967 -               do_gettimeofday(&ktv);
1968 +               vx_gettimeofday(&ktv);
1969                 if (put_tv32(tv, &ktv))
1970                         return -EFAULT;
1971         }
1972 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/ia32/syscall32.c linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/syscall32.c
1973 --- linux-2.6.22.10/arch/x86_64/ia32/syscall32.c        2007-07-09 13:18:08 +0200
1974 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/ia32/syscall32.c     2007-08-05 20:53:12 +0200
1975 @@ -10,6 +10,7 @@
1976  #include <linux/init.h>
1977  #include <linux/stringify.h>
1978  #include <linux/security.h>
1979 +#include <linux/vs_memory.h>
1980  #include <asm/proto.h>
1981  #include <asm/tlbflush.h>
1982  #include <asm/ia32_unistd.h>
1983 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/kernel/process.c linux-2.6.22.10-vs2.3.0.29/arch/x86_64/kernel/process.c
1984 --- linux-2.6.22.10/arch/x86_64/kernel/process.c        2007-07-09 13:18:08 +0200
1985 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/kernel/process.c     2007-08-05 20:53:12 +0200
1986 @@ -54,7 +54,8 @@
1987  
1988  asmlinkage extern void ret_from_fork(void);
1989  
1990 -unsigned long kernel_thread_flags = CLONE_VM | CLONE_UNTRACED;
1991 +unsigned long kernel_thread_flags =
1992 +       CLONE_VM | CLONE_UNTRACED | CLONE_KTHREAD;
1993  
1994  unsigned long boot_option_idle_override = 0;
1995  EXPORT_SYMBOL(boot_option_idle_override);
1996 @@ -310,8 +311,8 @@ void __show_regs(struct pt_regs * regs)
1997  
1998         printk("\n");
1999         print_modules();
2000 -       printk("Pid: %d, comm: %.20s %s %s %.*s\n",
2001 -               current->pid, current->comm, print_tainted(),
2002 +       printk("Pid: %d:#%u, comm: %.20s %s %s %.*s\n",
2003 +               current->pid, current->xid, current->comm, print_tainted(),
2004                 init_utsname()->release,
2005                 (int)strcspn(init_utsname()->version, " "),
2006                 init_utsname()->version);
2007 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/kernel/traps.c linux-2.6.22.10-vs2.3.0.29/arch/x86_64/kernel/traps.c
2008 --- linux-2.6.22.10/arch/x86_64/kernel/traps.c  2007-07-09 13:18:08 +0200
2009 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/kernel/traps.c       2007-09-30 17:11:18 +0200
2010 @@ -33,6 +33,8 @@
2011  #include <linux/uaccess.h>
2012  #include <linux/bug.h>
2013  #include <linux/kdebug.h>
2014 +#include <linux/vs_context.h>
2015 +#include <linux/vserver/history.h>
2016  
2017  #include <asm/system.h>
2018  #include <asm/io.h>
2019 @@ -413,8 +415,9 @@ void show_registers(struct pt_regs *regs
2020         rsp = regs->rsp;
2021         printk("CPU %d ", cpu);
2022         __show_regs(regs);
2023 -       printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
2024 -               cur->comm, cur->pid, task_thread_info(cur), cur);
2025 +       printk("Process %s (pid: %d[#%u], threadinfo %p, task %p)\n",
2026 +               cur->comm, cur->pid, cur->xid,
2027 +               task_thread_info(cur), cur);
2028  
2029         /*
2030          * When in-kernel, we also print out the stack and code at the
2031 @@ -518,6 +521,7 @@ void __kprobes __die(const char * str, s
2032         printk("\n");
2033         notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV);
2034         show_registers(regs);
2035 +       vxh_dump_history();
2036         /* Executive summary in case the oops scrolled away */
2037         printk(KERN_ALERT "RIP ");
2038         printk_address(regs->rip); 
2039 @@ -530,6 +534,7 @@ void die(const char * str, struct pt_reg
2040  {
2041         unsigned long flags = oops_begin();
2042  
2043 +       vxh_throw_oops();
2044         if (!user_mode(regs))
2045                 report_bug(regs->rip);
2046  
2047 @@ -542,12 +547,14 @@ void __kprobes die_nmi(char *str, struct
2048  {
2049         unsigned long flags = oops_begin();
2050  
2051 +       vxh_throw_oops();
2052         /*
2053          * We are in trouble anyway, lets at least try
2054          * to get a message out.
2055          */
2056         printk(str, smp_processor_id());
2057         show_registers(regs);
2058 +       vxh_dump_history();
2059         if (kexec_should_crash(current))
2060                 crash_kexec(regs);
2061         if (do_panic || panic_on_oops)
2062 @@ -580,8 +587,8 @@ static void __kprobes do_trap(int trapnr
2063  
2064                 if (exception_trace && unhandled_signal(tsk, signr))
2065                         printk(KERN_INFO
2066 -                              "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n",
2067 -                              tsk->comm, tsk->pid, str,
2068 +                              "%s[%d:#%u] trap %s rip:%lx rsp:%lx error:%lx\n",
2069 +                              tsk->comm, tsk->pid, tsk->xid, str,
2070                                regs->rip, regs->rsp, error_code); 
2071  
2072                 if (info)
2073 @@ -684,8 +691,8 @@ asmlinkage void __kprobes do_general_pro
2074  
2075                 if (exception_trace && unhandled_signal(tsk, SIGSEGV))
2076                         printk(KERN_INFO
2077 -                      "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n",
2078 -                              tsk->comm, tsk->pid,
2079 +                      "%s[%d:#%u] general protection rip:%lx rsp:%lx error:%lx\n",
2080 +                              tsk->comm, tsk->pid, tsk->xid,
2081                                regs->rip, regs->rsp, error_code); 
2082  
2083                 force_sig(SIGSEGV, tsk);
2084 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/mm/fault.c linux-2.6.22.10-vs2.3.0.29/arch/x86_64/mm/fault.c
2085 --- linux-2.6.22.10/arch/x86_64/mm/fault.c      2007-07-09 13:18:08 +0200
2086 +++ linux-2.6.22.10-vs2.3.0.29/arch/x86_64/mm/fault.c   2007-08-05 20:53:12 +0200
2087 @@ -497,10 +497,10 @@ bad_area_nosemaphore:
2088  
2089                 if (exception_trace && unhandled_signal(tsk, SIGSEGV)) {
2090                         printk(
2091 -                      "%s%s[%d]: segfault at %016lx rip %016lx rsp %016lx error %lx\n",
2092 +                      "%s%s[%d:#%u]: segfault at %016lx rip %016lx rsp %016lx error %lx\n",
2093                                         tsk->pid > 1 ? KERN_INFO : KERN_EMERG,
2094 -                                       tsk->comm, tsk->pid, address, regs->rip,
2095 -                                       regs->rsp, error_code);
2096 +                                       tsk->comm, tsk->pid, tsk->xid, address,
2097 +                                       regs->rip, regs->rsp, error_code);
2098                 }
2099         
2100                 tsk->thread.cr2 = address;
2101 @@ -567,7 +567,8 @@ out_of_memory:
2102                 yield();
2103                 goto again;
2104         }
2105 -       printk("VM: killing process %s\n", tsk->comm);
2106 +       printk("VM: killing process %s(%d:#%u)\n",
2107 +               tsk->comm, tsk->pid, tsk->xid);
2108         if (error_code & 4)
2109                 do_exit(SIGKILL);
2110         goto no_context;
2111 Files linux-2.6.22.10/core and linux-2.6.22.10-vs2.3.0.29/core differ
2112 diff -NurpP --minimal linux-2.6.22.10/drivers/block/Kconfig linux-2.6.22.10-vs2.3.0.29/drivers/block/Kconfig
2113 --- linux-2.6.22.10/drivers/block/Kconfig       2007-07-09 13:18:16 +0200
2114 +++ linux-2.6.22.10-vs2.3.0.29/drivers/block/Kconfig    2007-08-05 20:53:12 +0200
2115 @@ -311,6 +311,13 @@ config BLK_DEV_CRYPTOLOOP
2116           instead, which can be configured to be on-disk compatible with the
2117           cryptoloop device.
2118  
2119 +config BLK_DEV_VROOT
2120 +       tristate "Virtual Root device support"
2121 +       depends on QUOTACTL
2122 +       ---help---
2123 +         Saying Y here will allow you to use quota/fs ioctls on a shared
2124 +         partition within a virtual server without compromising security.
2125 +
2126  config BLK_DEV_NBD
2127         tristate "Network block device support"
2128         depends on NET
2129 diff -NurpP --minimal linux-2.6.22.10/drivers/block/Makefile linux-2.6.22.10-vs2.3.0.29/drivers/block/Makefile
2130 --- linux-2.6.22.10/drivers/block/Makefile      2007-02-06 03:00:26 +0100
2131 +++ linux-2.6.22.10-vs2.3.0.29/drivers/block/Makefile   2007-08-05 20:53:12 +0200
2132 @@ -28,4 +28,5 @@ obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryp
2133  obj-$(CONFIG_VIODASD)          += viodasd.o
2134  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
2135  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
2136 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
2137  
2138 diff -NurpP --minimal linux-2.6.22.10/drivers/block/loop.c linux-2.6.22.10-vs2.3.0.29/drivers/block/loop.c
2139 --- linux-2.6.22.10/drivers/block/loop.c        2007-07-09 13:18:16 +0200
2140 +++ linux-2.6.22.10-vs2.3.0.29/drivers/block/loop.c     2007-08-16 04:06:51 +0200
2141 @@ -74,6 +74,7 @@
2142  #include <linux/highmem.h>
2143  #include <linux/gfp.h>
2144  #include <linux/kthread.h>
2145 +#include <linux/vs_context.h>
2146  
2147  #include <asm/uaccess.h>
2148  
2149 @@ -790,6 +791,7 @@ static int loop_set_fd(struct loop_devic
2150         lo->lo_blocksize = lo_blocksize;
2151         lo->lo_device = bdev;
2152         lo->lo_flags = lo_flags;
2153 +       lo->lo_xid = vx_current_xid();
2154         lo->lo_backing_file = file;
2155         lo->transfer = transfer_none;
2156         lo->ioctl = NULL;
2157 @@ -909,6 +911,7 @@ static int loop_clr_fd(struct loop_devic
2158         lo->lo_encrypt_key_size = 0;
2159         lo->lo_flags = 0;
2160         lo->lo_thread = NULL;
2161 +       lo->lo_xid = 0;
2162         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
2163         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
2164         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
2165 @@ -930,7 +933,7 @@ loop_set_status(struct loop_device *lo, 
2166         struct loop_func_table *xfer;
2167  
2168         if (lo->lo_encrypt_key_size && lo->lo_key_owner != current->uid &&
2169 -           !capable(CAP_SYS_ADMIN))
2170 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
2171                 return -EPERM;
2172         if (lo->lo_state != Lo_bound)
2173                 return -ENXIO;
2174 @@ -1010,7 +1013,8 @@ loop_get_status(struct loop_device *lo, 
2175         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
2176         info->lo_encrypt_type =
2177                 lo->lo_encryption ? lo->lo_encryption->number : 0;
2178 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
2179 +       if (lo->lo_encrypt_key_size &&
2180 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
2181                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
2182                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
2183                        lo->lo_encrypt_key_size);
2184 @@ -1321,6 +1325,9 @@ static int lo_open(struct inode *inode, 
2185  {
2186         struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
2187  
2188 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID))
2189 +               return -EACCES;
2190 +
2191         mutex_lock(&lo->lo_ctl_mutex);
2192         lo->lo_refcnt++;
2193         mutex_unlock(&lo->lo_ctl_mutex);
2194 diff -NurpP --minimal linux-2.6.22.10/drivers/block/vroot.c linux-2.6.22.10-vs2.3.0.29/drivers/block/vroot.c
2195 --- linux-2.6.22.10/drivers/block/vroot.c       1970-01-01 01:00:00 +0100
2196 +++ linux-2.6.22.10-vs2.3.0.29/drivers/block/vroot.c    2007-08-05 20:53:12 +0200
2197 @@ -0,0 +1,281 @@
2198 +/*
2199 + *  linux/drivers/block/vroot.c
2200 + *
2201 + *  written by Herbert Pötzl, 9/11/2002
2202 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
2203 + *
2204 + *  based on the loop.c code by Theodore Ts'o.
2205 + *
2206 + * Copyright (C) 2002-2007 by Herbert Pötzl.
2207 + * Redistribution of this file is permitted under the
2208 + * GNU General Public License.
2209 + *
2210 + */
2211 +
2212 +#include <linux/module.h>
2213 +#include <linux/moduleparam.h>
2214 +#include <linux/file.h>
2215 +#include <linux/major.h>
2216 +#include <linux/blkdev.h>
2217 +
2218 +#include <linux/vroot.h>
2219 +#include <linux/vs_context.h>
2220 +
2221 +
2222 +static int max_vroot = 8;
2223 +
2224 +static struct vroot_device *vroot_dev;
2225 +static struct gendisk **disks;
2226 +
2227 +
2228 +static int vroot_set_dev(
2229 +       struct vroot_device *vr,
2230 +       struct file *vr_file,
2231 +       struct block_device *bdev,
2232 +       unsigned int arg)
2233 +{
2234 +       struct block_device *real_bdev;
2235 +       struct file *file;
2236 +       struct inode *inode;
2237 +       int error;
2238 +
2239 +       error = -EBUSY;
2240 +       if (vr->vr_state != Vr_unbound)
2241 +               goto out;
2242 +
2243 +       error = -EBADF;
2244 +       file = fget(arg);
2245 +       if (!file)
2246 +               goto out;
2247 +
2248 +       error = -EINVAL;
2249 +       inode = file->f_dentry->d_inode;
2250 +
2251 +
2252 +       if (S_ISBLK(inode->i_mode)) {
2253 +               real_bdev = inode->i_bdev;
2254 +               vr->vr_device = real_bdev;
2255 +               __iget(real_bdev->bd_inode);
2256 +       } else
2257 +               goto out_fput;
2258 +
2259 +       vxdprintk(VXD_CBIT(misc, 0),
2260 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
2261 +               vr->vr_number, VXD_DEV(real_bdev));
2262 +
2263 +       vr->vr_state = Vr_bound;
2264 +       error = 0;
2265 +
2266 + out_fput:
2267 +       fput(file);
2268 + out:
2269 +       return error;
2270 +}
2271 +
2272 +static int vroot_clr_dev(
2273 +       struct vroot_device *vr,
2274 +       struct file *vr_file,
2275 +       struct block_device *bdev)
2276 +{
2277 +       struct block_device *real_bdev;
2278 +
2279 +       if (vr->vr_state != Vr_bound)
2280 +               return -ENXIO;
2281 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
2282 +               return -EBUSY;
2283 +
2284 +       real_bdev = vr->vr_device;
2285 +
2286 +       vxdprintk(VXD_CBIT(misc, 0),
2287 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
2288 +               vr->vr_number, VXD_DEV(real_bdev));
2289 +
2290 +       bdput(real_bdev);
2291 +       vr->vr_state = Vr_unbound;
2292 +       vr->vr_device = NULL;
2293 +       return 0;
2294 +}
2295 +
2296 +
2297 +static int vr_ioctl(struct inode *inode, struct file *file,
2298 +       unsigned int cmd, unsigned long arg)
2299 +{
2300 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2301 +       int err;
2302 +
2303 +       down(&vr->vr_ctl_mutex);
2304 +       switch (cmd) {
2305 +       case VROOT_SET_DEV:
2306 +               err = vroot_set_dev(vr, file, inode->i_bdev, arg);
2307 +               break;
2308 +       case VROOT_CLR_DEV:
2309 +               err = vroot_clr_dev(vr, file, inode->i_bdev);
2310 +               break;
2311 +       default:
2312 +               err = -EINVAL;
2313 +               break;
2314 +       }
2315 +       up(&vr->vr_ctl_mutex);
2316 +       return err;
2317 +}
2318 +
2319 +static int vr_open(struct inode *inode, struct file *file)
2320 +{
2321 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2322 +
2323 +       down(&vr->vr_ctl_mutex);
2324 +       vr->vr_refcnt++;
2325 +       up(&vr->vr_ctl_mutex);
2326 +       return 0;
2327 +}
2328 +
2329 +static int vr_release(struct inode *inode, struct file *file)
2330 +{
2331 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2332 +
2333 +       down(&vr->vr_ctl_mutex);
2334 +       --vr->vr_refcnt;
2335 +       up(&vr->vr_ctl_mutex);
2336 +       return 0;
2337 +}
2338 +
2339 +static struct block_device_operations vr_fops = {
2340 +       .owner =        THIS_MODULE,
2341 +       .open =         vr_open,
2342 +       .release =      vr_release,
2343 +       .ioctl =        vr_ioctl,
2344 +};
2345 +
2346 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
2347 +{
2348 +       struct inode *inode = bdev->bd_inode;
2349 +       struct vroot_device *vr;
2350 +       struct block_device *real_bdev;
2351 +       int minor = iminor(inode);
2352 +
2353 +       vr = &vroot_dev[minor];
2354 +       real_bdev = vr->vr_device;
2355 +
2356 +       vxdprintk(VXD_CBIT(misc, 0),
2357 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
2358 +               vr->vr_number, VXD_DEV(real_bdev));
2359 +
2360 +       if (vr->vr_state != Vr_bound)
2361 +               return ERR_PTR(-ENXIO);
2362 +
2363 +       __iget(real_bdev->bd_inode);
2364 +       return real_bdev;
2365 +}
2366 +
2367 +/*
2368 + * And now the modules code and kernel interface.
2369 + */
2370 +
2371 +module_param(max_vroot, int, 0);
2372 +
2373 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
2374 +MODULE_LICENSE("GPL");
2375 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
2376 +
2377 +MODULE_AUTHOR ("Herbert Pötzl");
2378 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
2379 +
2380 +
2381 +int __init vroot_init(void)
2382 +{
2383 +       int err, i;
2384 +
2385 +       if (max_vroot < 1 || max_vroot > 256) {
2386 +               max_vroot = MAX_VROOT_DEFAULT;
2387 +               printk(KERN_WARNING "vroot: invalid max_vroot "
2388 +                       "(must be between 1 and 256), "
2389 +                       "using default (%d)\n", max_vroot);
2390 +       }
2391 +
2392 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
2393 +               return -EIO;
2394 +
2395 +       err = -ENOMEM;
2396 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
2397 +       if (!vroot_dev)
2398 +               goto out_mem1;
2399 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
2400 +
2401 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
2402 +       if (!disks)
2403 +               goto out_mem2;
2404 +
2405 +       for (i = 0; i < max_vroot; i++) {
2406 +               disks[i] = alloc_disk(1);
2407 +               if (!disks[i])
2408 +                       goto out_mem3;
2409 +       }
2410 +
2411 +       for (i = 0; i < max_vroot; i++) {
2412 +               struct vroot_device *vr = &vroot_dev[i];
2413 +               struct gendisk *disk = disks[i];
2414 +
2415 +               memset(vr, 0, sizeof(*vr));
2416 +               init_MUTEX(&vr->vr_ctl_mutex);
2417 +               vr->vr_number = i;
2418 +               disk->major = VROOT_MAJOR;
2419 +               disk->first_minor = i;
2420 +               disk->fops = &vr_fops;
2421 +               sprintf(disk->disk_name, "vroot%d", i);
2422 +               disk->private_data = vr;
2423 +       }
2424 +
2425 +       err = register_vroot_grb(&__vroot_get_real_bdev);
2426 +       if (err)
2427 +               goto out_mem3;
2428 +
2429 +       for (i = 0; i < max_vroot; i++)
2430 +               add_disk(disks[i]);
2431 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
2432 +       return 0;
2433 +
2434 +out_mem3:
2435 +       while (i--)
2436 +               put_disk(disks[i]);
2437 +       kfree(disks);
2438 +out_mem2:
2439 +       kfree(vroot_dev);
2440 +out_mem1:
2441 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2442 +       printk(KERN_ERR "vroot: ran out of memory\n");
2443 +       return err;
2444 +}
2445 +
2446 +void vroot_exit(void)
2447 +{
2448 +       int i;
2449 +
2450 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
2451 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
2452 +
2453 +       for (i = 0; i < max_vroot; i++) {
2454 +               del_gendisk(disks[i]);
2455 +               put_disk(disks[i]);
2456 +       }
2457 +       if (unregister_blkdev(VROOT_MAJOR, "vroot"))
2458 +               printk(KERN_WARNING "vroot: cannot unregister blkdev\n");
2459 +
2460 +       kfree(disks);
2461 +       kfree(vroot_dev);
2462 +}
2463 +
2464 +module_init(vroot_init);
2465 +module_exit(vroot_exit);
2466 +
2467 +#ifndef MODULE
2468 +
2469 +static int __init max_vroot_setup(char *str)
2470 +{
2471 +       max_vroot = simple_strtol(str, NULL, 0);
2472 +       return 1;
2473 +}
2474 +
2475 +__setup("max_vroot=", max_vroot_setup);
2476 +
2477 +#endif
2478 +
2479 diff -NurpP --minimal linux-2.6.22.10/drivers/char/sysrq.c linux-2.6.22.10-vs2.3.0.29/drivers/char/sysrq.c
2480 --- linux-2.6.22.10/drivers/char/sysrq.c        2007-07-09 13:18:20 +0200
2481 +++ linux-2.6.22.10-vs2.3.0.29/drivers/char/sysrq.c     2007-08-05 20:53:12 +0200
2482 @@ -36,6 +36,7 @@
2483  #include <linux/kexec.h>
2484  #include <linux/irq.h>
2485  #include <linux/hrtimer.h>
2486 +#include <linux/vserver/debug.h>
2487  
2488  #include <asm/ptrace.h>
2489  #include <asm/irq_regs.h>
2490 @@ -309,6 +310,21 @@ static struct sysrq_key_op sysrq_unrt_op
2491         .enable_mask    = SYSRQ_ENABLE_RTNICE,
2492  };
2493  
2494 +
2495 +#ifdef CONFIG_VSERVER_DEBUG
2496 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
2497 +{
2498 +       dump_vx_info_inactive((key == 'x')?0:1);
2499 +}
2500 +
2501 +static struct sysrq_key_op sysrq_showvxinfo_op = {
2502 +       .handler        = sysrq_handle_vxinfo,
2503 +       .help_msg       = "conteXt",
2504 +       .action_msg     = "Show Context Info",
2505 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
2506 +};
2507 +#endif
2508 +
2509  /* Key Operations table and lock */
2510  static DEFINE_SPINLOCK(sysrq_key_table_lock);
2511  
2512 @@ -357,7 +373,11 @@ static struct sysrq_key_op *sysrq_key_ta
2513         /* x: May be registered on ppc/powerpc for xmon */
2514         NULL,                           /* x */
2515         NULL,                           /* y */
2516 -       NULL                            /* z */
2517 +#ifdef CONFIG_VSERVER_DEBUG
2518 +       &sysrq_showvxinfo_op,           /* z */
2519 +#else
2520 +       NULL,                           /* z */
2521 +#endif
2522  };
2523  
2524  /* key2index calculation, -1 on invalid index */
2525 @@ -369,6 +389,8 @@ static int sysrq_key_table_key2index(int
2526                 retval = key - '0';
2527         else if ((key >= 'a') && (key <= 'z'))
2528                 retval = key + 10 - 'a';
2529 +       else if ((key >= 'A') && (key <= 'Z'))
2530 +               retval = key + 10 - 'A';
2531         else
2532                 retval = -1;
2533         return retval;
2534 diff -NurpP --minimal linux-2.6.22.10/drivers/char/tty_io.c linux-2.6.22.10-vs2.3.0.29/drivers/char/tty_io.c
2535 --- linux-2.6.22.10/drivers/char/tty_io.c       2007-07-09 13:18:20 +0200
2536 +++ linux-2.6.22.10-vs2.3.0.29/drivers/char/tty_io.c    2007-08-05 20:53:12 +0200
2537 @@ -103,6 +103,7 @@
2538  #include <linux/selection.h>
2539  
2540  #include <linux/kmod.h>
2541 +#include <linux/vs_pid.h>
2542  
2543  #undef TTY_DEBUG_HANGUP
2544  
2545 @@ -3049,13 +3050,15 @@ unlock:
2546  
2547  static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
2548  {
2549 +       pid_t pgrp;
2550         /*
2551          * (tty == real_tty) is a cheap way of
2552          * testing if the tty is NOT a master pty.
2553          */
2554         if (tty == real_tty && current->signal->tty != real_tty)
2555                 return -ENOTTY;
2556 -       return put_user(pid_nr(real_tty->pgrp), p);
2557 +       pgrp = vx_map_pid(pid_nr(real_tty->pgrp));
2558 +       return put_user(pgrp, p);
2559  }
2560  
2561  /**
2562 @@ -3086,6 +3089,7 @@ static int tiocspgrp(struct tty_struct *
2563                 return -ENOTTY;
2564         if (get_user(pgrp_nr, p))
2565                 return -EFAULT;
2566 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2567         if (pgrp_nr < 0)
2568                 return -EINVAL;
2569         rcu_read_lock();
2570 diff -NurpP --minimal linux-2.6.22.10/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.22.10-vs2.3.0.29/drivers/infiniband/hw/ipath/ipath_user_pages.c
2571 --- linux-2.6.22.10/drivers/infiniband/hw/ipath/ipath_user_pages.c      2007-02-06 03:00:37 +0100
2572 +++ linux-2.6.22.10-vs2.3.0.29/drivers/infiniband/hw/ipath/ipath_user_pages.c   2007-08-05 20:53:12 +0200
2573 @@ -33,6 +33,7 @@
2574  
2575  #include <linux/mm.h>
2576  #include <linux/device.h>
2577 +#include <linux/vs_memory.h>
2578  
2579  #include "ipath_kernel.h"
2580  
2581 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
2582         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
2583                 PAGE_SHIFT;
2584  
2585 -       if (num_pages > lock_limit) {
2586 +       if (num_pages > lock_limit ||
2587 +               !vx_vmlocked_avail(current->mm, num_pages)) {
2588                 ret = -ENOMEM;
2589                 goto bail;
2590         }
2591 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
2592                         goto bail_release;
2593         }
2594  
2595 -       current->mm->locked_vm += num_pages;
2596 +       vx_vmlocked_add(current->mm, num_pages);
2597  
2598         ret = 0;
2599         goto bail;
2600 @@ -203,7 +205,7 @@ void ipath_release_user_pages(struct pag
2601  
2602         __ipath_release_user_pages(p, num_pages, 1);
2603  
2604 -       current->mm->locked_vm -= num_pages;
2605 +       vx_vmlocked_sub(current->mm, num_pages);
2606  
2607         up_write(&current->mm->mmap_sem);
2608  }
2609 @@ -220,7 +222,7 @@ static void user_pages_account(struct wo
2610                 container_of(_work, struct ipath_user_pages_work, work);
2611  
2612         down_write(&work->mm->mmap_sem);
2613 -       work->mm->locked_vm -= work->num_pages;
2614 +       vx_vmlocked_sub(work->mm, work->num_pages);
2615         up_write(&work->mm->mmap_sem);
2616         mmput(work->mm);
2617         kfree(work);
2618 diff -NurpP --minimal linux-2.6.22.10/drivers/md/dm-ioctl.c linux-2.6.22.10-vs2.3.0.29/drivers/md/dm-ioctl.c
2619 --- linux-2.6.22.10/drivers/md/dm-ioctl.c       2007-05-02 19:24:50 +0200
2620 +++ linux-2.6.22.10-vs2.3.0.29/drivers/md/dm-ioctl.c    2007-08-05 20:53:12 +0200
2621 @@ -15,6 +15,7 @@
2622  #include <linux/slab.h>
2623  #include <linux/dm-ioctl.h>
2624  #include <linux/hdreg.h>
2625 +#include <linux/vs_context.h>
2626  
2627  #include <asm/uaccess.h>
2628  
2629 @@ -100,7 +101,8 @@ static struct hash_cell *__get_name_cell
2630         unsigned int h = hash_str(str);
2631  
2632         list_for_each_entry (hc, _name_buckets + h, name_list)
2633 -               if (!strcmp(hc->name, str)) {
2634 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2635 +                       !strcmp(hc->name, str)) {
2636                         dm_get(hc->md);
2637                         return hc;
2638                 }
2639 @@ -114,7 +116,8 @@ static struct hash_cell *__get_uuid_cell
2640         unsigned int h = hash_str(str);
2641  
2642         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
2643 -               if (!strcmp(hc->uuid, str)) {
2644 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2645 +                       !strcmp(hc->uuid, str)) {
2646                         dm_get(hc->md);
2647                         return hc;
2648                 }
2649 @@ -349,6 +352,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
2650  
2651  static int remove_all(struct dm_ioctl *param, size_t param_size)
2652  {
2653 +       if (!vx_check(0, VS_ADMIN))
2654 +               return -EPERM;
2655 +
2656         dm_hash_remove_all(1);
2657         param->data_size = 0;
2658         return 0;
2659 @@ -396,6 +402,8 @@ static int list_devices(struct dm_ioctl 
2660          */
2661         for (i = 0; i < NUM_BUCKETS; i++) {
2662                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2663 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2664 +                               continue;
2665                         needed += sizeof(struct dm_name_list);
2666                         needed += strlen(hc->name) + 1;
2667                         needed += ALIGN_MASK;
2668 @@ -419,6 +427,8 @@ static int list_devices(struct dm_ioctl 
2669          */
2670         for (i = 0; i < NUM_BUCKETS; i++) {
2671                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2672 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2673 +                               continue;
2674                         if (old_nl)
2675                                 old_nl->next = (uint32_t) ((void *) nl -
2676                                                            (void *) old_nl);
2677 @@ -609,10 +619,11 @@ static struct hash_cell *__find_device_h
2678         if (!md)
2679                 goto out;
2680  
2681 -       mdptr = dm_get_mdptr(md);
2682 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
2683 +               mdptr = dm_get_mdptr(md);
2684 +
2685         if (!mdptr)
2686                 dm_put(md);
2687 -
2688  out:
2689         return mdptr;
2690  }
2691 @@ -1409,8 +1420,8 @@ static int ctl_ioctl(struct inode *inode
2692         ioctl_fn fn = NULL;
2693         size_t param_size;
2694  
2695 -       /* only root can play with this */
2696 -       if (!capable(CAP_SYS_ADMIN))
2697 +       /* only root and certain contexts can play with this */
2698 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
2699                 return -EACCES;
2700  
2701         if (_IOC_TYPE(command) != DM_IOCTL)
2702 diff -NurpP --minimal linux-2.6.22.10/drivers/md/dm.c linux-2.6.22.10-vs2.3.0.29/drivers/md/dm.c
2703 --- linux-2.6.22.10/drivers/md/dm.c     2007-10-30 01:57:13 +0100
2704 +++ linux-2.6.22.10-vs2.3.0.29/drivers/md/dm.c  2007-08-11 22:41:50 +0200
2705 @@ -21,6 +21,7 @@
2706  #include <linux/hdreg.h>
2707  #include <linux/blktrace_api.h>
2708  #include <linux/smp_lock.h>
2709 +#include <linux/vs_base.h>
2710  
2711  #define DM_MSG_PREFIX "core"
2712  
2713 @@ -77,6 +78,7 @@ struct mapped_device {
2714         rwlock_t map_lock;
2715         atomic_t holders;
2716         atomic_t open_count;
2717 +       xid_t xid;
2718  
2719         unsigned long flags;
2720  
2721 @@ -223,6 +225,7 @@ static void __exit dm_exit(void)
2722  static int dm_blk_open(struct inode *inode, struct file *file)
2723  {
2724         struct mapped_device *md;
2725 +       int ret = -ENXIO;
2726  
2727         spin_lock(&_minor_lock);
2728  
2729 @@ -231,18 +234,19 @@ static int dm_blk_open(struct inode *ino
2730                 goto out;
2731  
2732         if (test_bit(DMF_FREEING, &md->flags) ||
2733 -           test_bit(DMF_DELETING, &md->flags)) {
2734 -               md = NULL;
2735 +           test_bit(DMF_DELETING, &md->flags))
2736 +               goto out;
2737 +
2738 +       ret = -EACCES;
2739 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
2740                 goto out;
2741 -       }
2742  
2743         dm_get(md);
2744         atomic_inc(&md->open_count);
2745 -
2746 +       ret = 0;
2747  out:
2748         spin_unlock(&_minor_lock);
2749 -
2750 -       return md ? 0 : -ENXIO;
2751 +       return ret;
2752  }
2753  
2754  static int dm_blk_close(struct inode *inode, struct file *file)
2755 @@ -438,6 +442,14 @@ int dm_set_geometry(struct mapped_device
2756         return 0;
2757  }
2758  
2759 +/*
2760 + * Get the xid associated with a dm device
2761 + */
2762 +xid_t dm_get_xid(struct mapped_device *md)
2763 +{
2764 +       return md->xid;
2765 +}
2766 +
2767  /*-----------------------------------------------------------------
2768   * CRUD START:
2769   *   A more elegant soln is in the works that uses the queue
2770 @@ -1000,6 +1012,7 @@ static struct mapped_device *alloc_dev(i
2771         atomic_set(&md->holders, 1);
2772         atomic_set(&md->open_count, 0);
2773         atomic_set(&md->event_nr, 0);
2774 +       md->xid = vx_current_xid();
2775  
2776         md->queue = blk_alloc_queue(GFP_KERNEL);
2777         if (!md->queue)
2778 diff -NurpP --minimal linux-2.6.22.10/drivers/md/dm.h linux-2.6.22.10-vs2.3.0.29/drivers/md/dm.h
2779 --- linux-2.6.22.10/drivers/md/dm.h     2007-02-06 03:00:41 +0100
2780 +++ linux-2.6.22.10-vs2.3.0.29/drivers/md/dm.h  2007-08-05 20:53:12 +0200
2781 @@ -91,6 +91,8 @@ void dm_put_target_type(struct target_ty
2782  int dm_target_iterate(void (*iter_func)(struct target_type *tt,
2783                                         void *param), void *param);
2784  
2785 +xid_t dm_get_xid(struct mapped_device *md);
2786 +
2787  /*-----------------------------------------------------------------
2788   * Useful inlines.
2789   *---------------------------------------------------------------*/
2790 diff -NurpP --minimal linux-2.6.22.16/fs/Kconfig linux-2.6.22.16-vs2.3.0.32/fs/Kconfig
2791 --- linux-2.6.22.16/fs/Kconfig  2007-07-09 13:19:22 +0200
2792 +++ linux-2.6.22.16-vs2.3.0.32/fs/Kconfig       2008-01-18 14:44:53 +0100
2793 @@ -2026,7 +2026,7 @@ config CODA_FS_OLD_API
2794  
2795  config AFS_FS
2796         tristate "Andrew File System support (AFS) (EXPERIMENTAL)"
2797 -       depends on INET && EXPERIMENTAL
2798 +       depends on INET && EXPERIMENTAL && !VSERVER_SECURITY
2799         select AF_RXRPC
2800         help
2801           If you say Y here, you will get an experimental Andrew File System
2802 diff -NurpP --minimal linux-2.6.22.10/fs/attr.c linux-2.6.22.10-vs2.3.0.29/fs/attr.c
2803 --- linux-2.6.22.10/fs/attr.c   2007-07-09 13:19:22 +0200
2804 +++ linux-2.6.22.10-vs2.3.0.29/fs/attr.c        2007-10-25 17:05:55 +0200
2805 @@ -14,6 +14,9 @@
2806  #include <linux/fcntl.h>
2807  #include <linux/quotaops.h>
2808  #include <linux/security.h>
2809 +#include <linux/proc_fs.h>
2810 +#include <linux/devpts_fs.h>
2811 +#include <linux/vs_base.h>
2812  
2813  /* Taken over from the old code... */
2814  
2815 @@ -55,6 +58,27 @@ int inode_change_ok(struct inode *inode,
2816                 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
2817                         goto error;
2818         }
2819 +
2820 +       /* Check for evil vserver activity */
2821 +       if (vx_check(0, VS_ADMIN))
2822 +               goto fine;
2823 +
2824 +       if (IS_BARRIER(inode)) {
2825 +               vxwprintk_task(1, "messing with the barrier.");
2826 +               goto error;
2827 +       }
2828 +       switch (inode->i_sb->s_magic) {
2829 +               case PROC_SUPER_MAGIC:
2830 +                       /* maybe allow that in the future? */
2831 +                       vxwprintk_task(1, "messing with the procfs.");
2832 +                       goto error;
2833 +               case DEVPTS_SUPER_MAGIC:
2834 +                       /* devpts is xid tagged */
2835 +                       if (vx_check((xid_t)inode->i_tag, VS_IDENT))
2836 +                               goto fine;
2837 +                       vxwprintk_task(1, "messing with the devpts.");
2838 +                       goto error;
2839 +       }
2840  fine:
2841         retval = 0;
2842  error:
2843 @@ -78,6 +102,8 @@ int inode_setattr(struct inode * inode, 
2844                 inode->i_uid = attr->ia_uid;
2845         if (ia_valid & ATTR_GID)
2846                 inode->i_gid = attr->ia_gid;
2847 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2848 +               inode->i_tag = attr->ia_tag;
2849         if (ia_valid & ATTR_ATIME)
2850                 inode->i_atime = timespec_trunc(attr->ia_atime,
2851                                                 inode->i_sb->s_time_gran);
2852 @@ -152,7 +178,8 @@ int notify_change(struct dentry * dentry
2853                         error = security_inode_setattr(dentry, attr);
2854                 if (!error) {
2855                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2856 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2857 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2858 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2859                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2860                         if (!error)
2861                                 error = inode_setattr(inode, attr);
2862 diff -NurpP --minimal linux-2.6.22.10/fs/binfmt_aout.c linux-2.6.22.10-vs2.3.0.29/fs/binfmt_aout.c
2863 --- linux-2.6.22.10/fs/binfmt_aout.c    2007-02-06 03:01:16 +0100
2864 +++ linux-2.6.22.10-vs2.3.0.29/fs/binfmt_aout.c 2007-08-05 20:53:12 +0200
2865 @@ -24,6 +24,7 @@
2866  #include <linux/binfmts.h>
2867  #include <linux/personality.h>
2868  #include <linux/init.h>
2869 +#include <linux/vs_memory.h>
2870  
2871  #include <asm/system.h>
2872  #include <asm/uaccess.h>
2873 diff -NurpP --minimal linux-2.6.22.10/fs/binfmt_elf.c linux-2.6.22.10-vs2.3.0.29/fs/binfmt_elf.c
2874 --- linux-2.6.22.10/fs/binfmt_elf.c     2007-07-09 13:19:22 +0200
2875 +++ linux-2.6.22.10-vs2.3.0.29/fs/binfmt_elf.c  2007-08-05 20:53:12 +0200
2876 @@ -39,6 +39,7 @@
2877  #include <linux/random.h>
2878  #include <linux/elf.h>
2879  #include <linux/utsname.h>
2880 +#include <linux/vs_memory.h>
2881  #include <asm/uaccess.h>
2882  #include <asm/param.h>
2883  #include <asm/page.h>
2884 diff -NurpP --minimal linux-2.6.22.10/fs/binfmt_flat.c linux-2.6.22.10-vs2.3.0.29/fs/binfmt_flat.c
2885 --- linux-2.6.22.10/fs/binfmt_flat.c    2007-07-09 13:19:22 +0200
2886 +++ linux-2.6.22.10-vs2.3.0.29/fs/binfmt_flat.c 2007-08-05 20:53:12 +0200
2887 @@ -36,6 +36,7 @@
2888  #include <linux/init.h>
2889  #include <linux/flat.h>
2890  #include <linux/syscalls.h>
2891 +#include <linux/vs_memory.h>
2892  
2893  #include <asm/byteorder.h>
2894  #include <asm/system.h>
2895 diff -NurpP --minimal linux-2.6.22.10/fs/binfmt_som.c linux-2.6.22.10-vs2.3.0.29/fs/binfmt_som.c
2896 --- linux-2.6.22.10/fs/binfmt_som.c     2006-11-30 21:19:19 +0100
2897 +++ linux-2.6.22.10-vs2.3.0.29/fs/binfmt_som.c  2007-08-05 20:53:12 +0200
2898 @@ -28,6 +28,7 @@
2899  #include <linux/shm.h>
2900  #include <linux/personality.h>
2901  #include <linux/init.h>
2902 +#include <linux/vs_memory.h>
2903  
2904  #include <asm/a.out.h>
2905  #include <asm/uaccess.h>
2906 diff -NurpP --minimal linux-2.6.22.10/fs/block_dev.c linux-2.6.22.10-vs2.3.0.29/fs/block_dev.c
2907 --- linux-2.6.22.10/fs/block_dev.c      2007-07-09 13:19:22 +0200
2908 +++ linux-2.6.22.10-vs2.3.0.29/fs/block_dev.c   2007-10-11 01:10:22 +0200
2909 @@ -23,6 +23,7 @@
2910  #include <linux/uio.h>
2911  #include <linux/namei.h>
2912  #include <linux/log2.h>
2913 +#include <linux/vs_device.h>
2914  #include <asm/uaccess.h>
2915  #include "internal.h"
2916  
2917 @@ -572,6 +573,7 @@ struct block_device *bdget(dev_t dev)
2918                 bdev->bd_invalidated = 0;
2919                 inode->i_mode = S_IFBLK;
2920                 inode->i_rdev = dev;
2921 +               inode->i_mdev = dev;
2922                 inode->i_bdev = bdev;
2923                 inode->i_data.a_ops = &def_blk_aops;
2924                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2925 @@ -610,6 +612,11 @@ EXPORT_SYMBOL(bdput);
2926  static struct block_device *bd_acquire(struct inode *inode)
2927  {
2928         struct block_device *bdev;
2929 +       dev_t mdev;
2930 +
2931 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2932 +               return NULL;
2933 +       inode->i_mdev = mdev;
2934  
2935         spin_lock(&bdev_lock);
2936         bdev = inode->i_bdev;
2937 @@ -620,7 +627,7 @@ static struct block_device *bd_acquire(s
2938         }
2939         spin_unlock(&bdev_lock);
2940  
2941 -       bdev = bdget(inode->i_rdev);
2942 +       bdev = bdget(mdev);
2943         if (bdev) {
2944                 spin_lock(&bdev_lock);
2945                 if (!inode->i_bdev) {
2946 diff -NurpP --minimal linux-2.6.22.10/fs/char_dev.c linux-2.6.22.10-vs2.3.0.29/fs/char_dev.c
2947 --- linux-2.6.22.10/fs/char_dev.c       2007-05-02 19:25:16 +0200
2948 +++ linux-2.6.22.10-vs2.3.0.29/fs/char_dev.c    2007-10-11 01:10:22 +0200
2949 @@ -21,6 +21,7 @@
2950  #include <linux/cdev.h>
2951  #include <linux/mutex.h>
2952  #include <linux/backing-dev.h>
2953 +#include <linux/vs_device.h>
2954  
2955  #ifdef CONFIG_KMOD
2956  #include <linux/kmod.h>
2957 @@ -363,14 +364,21 @@ int chrdev_open(struct inode * inode, st
2958         struct cdev *p;
2959         struct cdev *new = NULL;
2960         int ret = 0;
2961 +       dev_t mdev;
2962 +
2963 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2964 +               return -EPERM;
2965 +       inode->i_mdev = mdev;
2966  
2967         spin_lock(&cdev_lock);
2968         p = inode->i_cdev;
2969         if (!p) {
2970                 struct kobject *kobj;
2971                 int idx;
2972 +
2973                 spin_unlock(&cdev_lock);
2974 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2975 +
2976 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2977                 if (!kobj)
2978                         return -ENXIO;
2979                 new = container_of(kobj, struct cdev, kobj);
2980 diff -NurpP --minimal linux-2.6.22.10/fs/dcache.c linux-2.6.22.10-vs2.3.0.29/fs/dcache.c
2981 --- linux-2.6.22.10/fs/dcache.c 2007-07-09 13:19:23 +0200
2982 +++ linux-2.6.22.10-vs2.3.0.29/fs/dcache.c      2007-08-05 20:53:12 +0200
2983 @@ -31,6 +31,7 @@
2984  #include <linux/seqlock.h>
2985  #include <linux/swap.h>
2986  #include <linux/bootmem.h>
2987 +#include <linux/vs_limit.h>
2988  #include "internal.h"
2989  
2990  
2991 @@ -176,6 +177,7 @@ void dput(struct dentry *dentry)
2992         if (!dentry)
2993                 return;
2994  
2995 +       vx_dentry_dec(dentry);
2996  repeat:
2997         if (atomic_read(&dentry->d_count) == 1)
2998                 might_sleep();
2999 @@ -189,6 +191,8 @@ repeat:
3000                 return;
3001         }
3002  
3003 +       vx_dentry_dec(dentry);
3004 +
3005         /*
3006          * AV: ->d_delete() is _NOT_ allowed to block now.
3007          */
3008 @@ -288,6 +292,7 @@ static inline struct dentry * __dget_loc
3009         if (!list_empty(&dentry->d_lru)) {
3010                 dentry_stat.nr_unused--;
3011                 list_del_init(&dentry->d_lru);
3012 +               vx_dentry_inc(dentry);
3013         }
3014         return dentry;
3015  }
3016 @@ -898,6 +903,9 @@ struct dentry *d_alloc(struct dentry * p
3017         struct dentry *dentry;
3018         char *dname;
3019  
3020 +       if (!vx_dentry_avail(1))
3021 +               return NULL;
3022 +
3023         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); 
3024         if (!dentry)
3025                 return NULL;
3026 @@ -946,6 +954,7 @@ struct dentry *d_alloc(struct dentry * p
3027         if (parent)
3028                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
3029         dentry_stat.nr_dentry++;
3030 +       vx_dentry_inc(dentry);
3031         spin_unlock(&dcache_lock);
3032  
3033         return dentry;
3034 @@ -1295,6 +1304,7 @@ struct dentry * __d_lookup(struct dentry
3035  
3036                 if (!d_unhashed(dentry)) {
3037                         atomic_inc(&dentry->d_count);
3038 +                       vx_dentry_inc(dentry);
3039                         found = dentry;
3040                 }
3041                 spin_unlock(&dentry->d_lock);
3042 diff -NurpP --minimal linux-2.6.22.10/fs/devpts/inode.c linux-2.6.22.10-vs2.3.0.29/fs/devpts/inode.c
3043 --- linux-2.6.22.10/fs/devpts/inode.c   2007-07-09 13:19:23 +0200
3044 +++ linux-2.6.22.10-vs2.3.0.29/fs/devpts/inode.c        2007-10-18 00:59:53 +0200
3045 @@ -17,11 +17,26 @@
3046  #include <linux/namei.h>
3047  #include <linux/mount.h>
3048  #include <linux/tty.h>
3049 +#include <linux/magic.h>
3050  #include <linux/devpts_fs.h>
3051  #include <linux/parser.h>
3052  #include <linux/fsnotify.h>
3053 +#include <linux/vs_base.h>
3054  
3055 -#define DEVPTS_SUPER_MAGIC 0x1cd1
3056 +
3057 +static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
3058 +{
3059 +       int ret = -EACCES;
3060 +
3061 +       /* devpts is xid tagged */
3062 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
3063 +               ret = generic_permission(inode, mask, NULL);
3064 +       return ret;
3065 +}
3066 +
3067 +static struct inode_operations devpts_file_inode_operations = {
3068 +       .permission     = devpts_permission,
3069 +};
3070  
3071  static struct vfsmount *devpts_mnt;
3072  static struct dentry *devpts_root;
3073 @@ -92,6 +107,25 @@ static int devpts_remount(struct super_b
3074         return 0;
3075  }
3076  
3077 +static int devpts_filter(struct dentry *de)
3078 +{
3079 +       /* devpts is xid tagged */
3080 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
3081 +}
3082 +
3083 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
3084 +{
3085 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
3086 +}
3087 +
3088 +static struct file_operations devpts_dir_operations = {
3089 +       .open           = dcache_dir_open,
3090 +       .release        = dcache_dir_close,
3091 +       .llseek         = dcache_dir_lseek,
3092 +       .read           = generic_read_dir,
3093 +       .readdir        = devpts_readdir,
3094 +};
3095 +
3096  static const struct super_operations devpts_sops = {
3097         .statfs         = simple_statfs,
3098         .remount_fs     = devpts_remount,
3099 @@ -117,8 +151,10 @@ devpts_fill_super(struct super_block *s,
3100         inode->i_uid = inode->i_gid = 0;
3101         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
3102         inode->i_op = &simple_dir_inode_operations;
3103 -       inode->i_fop = &simple_dir_operations;
3104 +       inode->i_fop = &devpts_dir_operations;
3105         inode->i_nlink = 2;
3106 +       /* devpts is xid tagged */
3107 +       inode->i_tag = (tag_t)vx_current_xid();
3108  
3109         devpts_root = s->s_root = d_alloc_root(inode);
3110         if (s->s_root)
3111 @@ -176,6 +212,9 @@ int devpts_pty_new(struct tty_struct *tt
3112         inode->i_gid = config.setgid ? config.gid : current->fsgid;
3113         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
3114         init_special_inode(inode, S_IFCHR|config.mode, device);
3115 +       /* devpts is xid tagged */
3116 +       inode->i_tag = (tag_t)vx_current_xid();
3117 +       inode->i_op = &devpts_file_inode_operations;
3118         inode->i_private = tty;
3119  
3120         dentry = get_node(number);
3121 diff -NurpP --minimal linux-2.6.22.10/fs/ecryptfs/inode.c linux-2.6.22.10-vs2.3.0.29/fs/ecryptfs/inode.c
3122 --- linux-2.6.22.10/fs/ecryptfs/inode.c 2007-10-30 01:57:14 +0100
3123 +++ linux-2.6.22.10-vs2.3.0.29/fs/ecryptfs/inode.c      2007-08-11 22:41:51 +0200
3124 @@ -423,7 +423,7 @@ static int ecryptfs_link(struct dentry *
3125         dget(lower_new_dentry);
3126         lower_dir_dentry = lock_parent(lower_new_dentry);
3127         rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
3128 -                     lower_new_dentry);
3129 +                     lower_new_dentry, NULL);
3130         if (rc || !lower_new_dentry->d_inode)
3131                 goto out_lock;
3132         rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
3133 @@ -451,7 +451,7 @@ static int ecryptfs_unlink(struct inode 
3134         struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
3135  
3136         lock_parent(lower_dentry);
3137 -       rc = vfs_unlink(lower_dir_inode, lower_dentry);
3138 +       rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
3139         if (rc) {
3140                 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
3141                 goto out_unlock;
3142 @@ -488,7 +488,7 @@ static int ecryptfs_symlink(struct inode
3143                 goto out_lock;
3144         }
3145         rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
3146 -                        encoded_symname, mode);
3147 +                        encoded_symname, mode, NULL);
3148         kfree(encoded_symname);
3149         if (rc || !lower_dentry->d_inode)
3150                 goto out_lock;
3151 @@ -513,7 +513,7 @@ static int ecryptfs_mkdir(struct inode *
3152  
3153         lower_dentry = ecryptfs_dentry_to_lower(dentry);
3154         lower_dir_dentry = lock_parent(lower_dentry);
3155 -       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
3156 +       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode, NULL);
3157         if (rc || !lower_dentry->d_inode)
3158                 goto out;
3159         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
3160 @@ -539,7 +539,7 @@ static int ecryptfs_rmdir(struct inode *
3161         dget(dentry);
3162         lower_dir_dentry = lock_parent(lower_dentry);
3163         dget(lower_dentry);
3164 -       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
3165 +       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry, NULL);
3166         dput(lower_dentry);
3167         if (!rc)
3168                 d_delete(lower_dentry);
3169 @@ -561,7 +561,7 @@ ecryptfs_mknod(struct inode *dir, struct
3170  
3171         lower_dentry = ecryptfs_dentry_to_lower(dentry);
3172         lower_dir_dentry = lock_parent(lower_dentry);
3173 -       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
3174 +       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev, NULL);
3175         if (rc || !lower_dentry->d_inode)
3176                 goto out;
3177         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
3178 diff -NurpP --minimal linux-2.6.22.10/fs/exec.c linux-2.6.22.10-vs2.3.0.29/fs/exec.c
3179 --- linux-2.6.22.10/fs/exec.c   2007-10-30 01:57:14 +0100
3180 +++ linux-2.6.22.10-vs2.3.0.29/fs/exec.c        2007-10-04 23:47:06 +0200
3181 @@ -51,6 +51,7 @@
3182  #include <linux/cn_proc.h>
3183  #include <linux/audit.h>
3184  #include <linux/signalfd.h>
3185 +#include <linux/vs_memory.h>
3186  
3187  #include <asm/uaccess.h>
3188  #include <asm/mmu_context.h>
3189 @@ -440,7 +441,8 @@ int setup_arg_pages(struct linux_binprm 
3190                         kmem_cache_free(vm_area_cachep, mpnt);
3191                         return ret;
3192                 }
3193 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
3194 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
3195 +               mm->stack_vm = mm->total_vm;
3196         }
3197  
3198         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
3199 @@ -1336,7 +1338,7 @@ static int format_corename(char *corenam
3200                         /* UNIX time of coredump */
3201                         case 't': {
3202                                 struct timeval tv;
3203 -                               do_gettimeofday(&tv);
3204 +                               vx_gettimeofday(&tv);
3205                                 rc = snprintf(out_ptr, out_end - out_ptr,
3206                                               "%lu", tv.tv_sec);
3207                                 if (rc > out_end - out_ptr)
3208 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/balloc.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/balloc.c
3209 --- linux-2.6.22.10/fs/ext2/balloc.c    2007-05-02 19:25:17 +0200
3210 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/balloc.c 2007-08-05 20:53:12 +0200
3211 @@ -16,6 +16,8 @@
3212  #include <linux/sched.h>
3213  #include <linux/buffer_head.h>
3214  #include <linux/capability.h>
3215 +#include <linux/vs_dlimit.h>
3216 +#include <linux/vs_tag.h>
3217  
3218  /*
3219   * balloc.c contains the blocks allocation and deallocation routines
3220 @@ -102,12 +104,13 @@ static int reserve_blocks(struct super_b
3221  {
3222         struct ext2_sb_info *sbi = EXT2_SB(sb);
3223         struct ext2_super_block *es = sbi->s_es;
3224 -       unsigned free_blocks;
3225 -       unsigned root_blocks;
3226 +       unsigned long long free_blocks, root_blocks;
3227  
3228         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3229         root_blocks = le32_to_cpu(es->s_r_blocks_count);
3230  
3231 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3232 +
3233         if (free_blocks < count)
3234                 count = free_blocks;
3235  
3236 @@ -258,6 +261,7 @@ do_more:
3237         }
3238  error_return:
3239         brelse(bitmap_bh);
3240 +       DLIMIT_FREE_BLOCK(inode, freed);
3241         release_blocks(sb, freed);
3242         DQUOT_FREE_BLOCK(inode, freed);
3243  }
3244 @@ -361,6 +365,10 @@ int ext2_new_block(struct inode *inode, 
3245                 *err = -ENOSPC;
3246                 goto out_dquot;
3247         }
3248 +       if (DLIMIT_ALLOC_BLOCK(inode, es_alloc)) {
3249 +               *err = -ENOSPC;
3250 +               goto out_dlimit;
3251 +       }
3252  
3253         ext2_debug ("goal=%lu.\n", goal);
3254  
3255 @@ -508,6 +516,8 @@ got_block:
3256         *err = 0;
3257  out_release:
3258         group_release_blocks(sb, group_no, desc, gdp_bh, group_alloc);
3259 +       DLIMIT_FREE_BLOCK(inode, es_alloc);
3260 +out_dlimit:
3261         release_blocks(sb, es_alloc);
3262  out_dquot:
3263         DQUOT_FREE_BLOCK(inode, dq_alloc);
3264 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/ext2.h linux-2.6.22.10-vs2.3.0.29/fs/ext2/ext2.h
3265 --- linux-2.6.22.10/fs/ext2/ext2.h      2007-07-09 13:19:23 +0200
3266 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/ext2.h   2007-08-05 20:53:12 +0200
3267 @@ -167,6 +167,7 @@ extern const struct file_operations ext2
3268  extern const struct address_space_operations ext2_aops;
3269  extern const struct address_space_operations ext2_aops_xip;
3270  extern const struct address_space_operations ext2_nobh_aops;
3271 +extern int ext2_sync_flags(struct inode *inode);
3272  
3273  /* namei.c */
3274  extern const struct inode_operations ext2_dir_inode_operations;
3275 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/file.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/file.c
3276 --- linux-2.6.22.10/fs/ext2/file.c      2007-05-02 19:25:17 +0200
3277 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/file.c   2007-09-12 20:04:16 +0200
3278 @@ -85,4 +85,5 @@ const struct inode_operations ext2_file_
3279  #endif
3280         .setattr        = ext2_setattr,
3281         .permission     = ext2_permission,
3282 +       .sync_flags     = ext2_sync_flags,
3283  };
3284 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/ialloc.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/ialloc.c
3285 --- linux-2.6.22.10/fs/ext2/ialloc.c    2006-11-30 21:19:19 +0100
3286 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/ialloc.c 2007-08-05 20:53:12 +0200
3287 @@ -17,6 +17,8 @@
3288  #include <linux/backing-dev.h>
3289  #include <linux/buffer_head.h>
3290  #include <linux/random.h>
3291 +#include <linux/vs_dlimit.h>
3292 +#include <linux/vs_tag.h>
3293  #include "ext2.h"
3294  #include "xattr.h"
3295  #include "acl.h"
3296 @@ -125,6 +127,7 @@ void ext2_free_inode (struct inode * ino
3297                 ext2_xattr_delete_inode(inode);
3298                 DQUOT_FREE_INODE(inode);
3299                 DQUOT_DROP(inode);
3300 +               DLIMIT_FREE_INODE(inode);
3301         }
3302  
3303         es = EXT2_SB(sb)->s_es;
3304 @@ -464,6 +467,11 @@ struct inode *ext2_new_inode(struct inod
3305         if (!inode)
3306                 return ERR_PTR(-ENOMEM);
3307  
3308 +       inode->i_tag = dx_current_fstag(sb);
3309 +       if (DLIMIT_ALLOC_INODE(inode)) {
3310 +               err = -ENOSPC;
3311 +               goto fail_dlim;
3312 +       }
3313         ei = EXT2_I(inode);
3314         sbi = EXT2_SB(sb);
3315         es = sbi->s_es;
3316 @@ -577,7 +585,8 @@ got:
3317         inode->i_blocks = 0;
3318         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
3319         memset(ei->i_data, 0, sizeof(ei->i_data));
3320 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
3321 +       ei->i_flags = EXT2_I(dir)->i_flags &
3322 +               ~(EXT2_BTREE_FL|EXT2_IUNLINK_FL|EXT2_BARRIER_FL);
3323         if (S_ISLNK(mode))
3324                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
3325         /* dirsync is only applied to directories */
3326 @@ -625,12 +634,15 @@ fail_free_drop:
3327  
3328  fail_drop:
3329         DQUOT_DROP(inode);
3330 +       DLIMIT_FREE_INODE(inode);
3331         inode->i_flags |= S_NOQUOTA;
3332         inode->i_nlink = 0;
3333         iput(inode);
3334         return ERR_PTR(err);
3335  
3336  fail:
3337 +       DLIMIT_FREE_INODE(inode);
3338 +fail_dlim:
3339         make_bad_inode(inode);
3340         iput(inode);
3341         return ERR_PTR(err);
3342 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/inode.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/inode.c
3343 --- linux-2.6.22.10/fs/ext2/inode.c     2007-07-09 13:19:23 +0200
3344 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/inode.c  2007-08-18 02:52:34 +0200
3345 @@ -31,6 +31,7 @@
3346  #include <linux/writeback.h>
3347  #include <linux/buffer_head.h>
3348  #include <linux/mpage.h>
3349 +#include <linux/vs_tag.h>
3350  #include "ext2.h"
3351  #include "acl.h"
3352  #include "xip.h"
3353 @@ -913,7 +914,7 @@ void ext2_truncate (struct inode * inode
3354                 return;
3355         if (ext2_inode_is_fast_symlink(inode))
3356                 return;
3357 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3358 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3359                 return;
3360  
3361         ext2_discard_prealloc(inode);
3362 @@ -1042,13 +1043,20 @@ void ext2_set_inode_flags(struct inode *
3363  {
3364         unsigned int flags = EXT2_I(inode)->i_flags;
3365  
3366 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3367 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3368 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3369 +
3370 +       if (flags & EXT2_IMMUTABLE_FL)
3371 +               inode->i_flags |= S_IMMUTABLE;
3372 +       if (flags & EXT2_IUNLINK_FL)
3373 +               inode->i_flags |= S_IUNLINK;
3374 +       if (flags & EXT2_BARRIER_FL)
3375 +               inode->i_flags |= S_BARRIER;
3376 +
3377         if (flags & EXT2_SYNC_FL)
3378                 inode->i_flags |= S_SYNC;
3379         if (flags & EXT2_APPEND_FL)
3380                 inode->i_flags |= S_APPEND;
3381 -       if (flags & EXT2_IMMUTABLE_FL)
3382 -               inode->i_flags |= S_IMMUTABLE;
3383         if (flags & EXT2_NOATIME_FL)
3384                 inode->i_flags |= S_NOATIME;
3385         if (flags & EXT2_DIRSYNC_FL)
3386 @@ -1074,12 +1082,37 @@ void ext2_get_inode_flags(struct ext2_in
3387                 ei->i_flags |= EXT2_DIRSYNC_FL;
3388  }
3389  
3390 +int ext2_sync_flags(struct inode *inode)
3391 +{
3392 +       unsigned int oldflags, newflags;
3393 +
3394 +       oldflags = EXT2_I(inode)->i_flags;
3395 +       newflags = oldflags & ~(EXT2_IMMUTABLE_FL |
3396 +               EXT2_IUNLINK_FL | EXT2_BARRIER_FL);
3397 +
3398 +       if (IS_IMMUTABLE(inode))
3399 +               newflags |= EXT2_IMMUTABLE_FL;
3400 +       if (IS_IUNLINK(inode))
3401 +               newflags |= EXT2_IUNLINK_FL;
3402 +       if (IS_BARRIER(inode))
3403 +               newflags |= EXT2_BARRIER_FL;
3404 +
3405 +       if (oldflags ^ newflags) {
3406 +               EXT2_I(inode)->i_flags = newflags;
3407 +               inode->i_ctime = CURRENT_TIME;
3408 +               mark_inode_dirty(inode);
3409 +       }
3410 +       return 0;
3411 +}
3412 +
3413  void ext2_read_inode (struct inode * inode)
3414  {
3415         struct ext2_inode_info *ei = EXT2_I(inode);
3416         ino_t ino = inode->i_ino;
3417         struct buffer_head * bh;
3418         struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
3419 +       uid_t uid;
3420 +       gid_t gid;
3421         int n;
3422  
3423  #ifdef CONFIG_EXT2_FS_POSIX_ACL
3424 @@ -1090,12 +1123,17 @@ void ext2_read_inode (struct inode * ino
3425                 goto bad_inode;
3426  
3427         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3428 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3429 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3430 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3431 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3432         if (!(test_opt (inode->i_sb, NO_UID32))) {
3433 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3434 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3435 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3436 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3437         }
3438 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3439 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3440 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3441 +               le16_to_cpu(raw_inode->i_raw_tag));
3442 +
3443         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3444         inode->i_size = le32_to_cpu(raw_inode->i_size);
3445         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3446 @@ -1192,8 +1230,8 @@ static int ext2_update_inode(struct inod
3447         struct ext2_inode_info *ei = EXT2_I(inode);
3448         struct super_block *sb = inode->i_sb;
3449         ino_t ino = inode->i_ino;
3450 -       uid_t uid = inode->i_uid;
3451 -       gid_t gid = inode->i_gid;
3452 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3453 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3454         struct buffer_head * bh;
3455         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
3456         int n;
3457 @@ -1229,6 +1267,9 @@ static int ext2_update_inode(struct inod
3458                 raw_inode->i_uid_high = 0;
3459                 raw_inode->i_gid_high = 0;
3460         }
3461 +#ifdef CONFIG_TAGGING_INTERN
3462 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3463 +#endif
3464         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3465         raw_inode->i_size = cpu_to_le32(inode->i_size);
3466         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3467 @@ -1315,7 +1356,8 @@ int ext2_setattr(struct dentry *dentry, 
3468         if (error)
3469                 return error;
3470         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3471 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3472 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3473 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3474                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
3475                 if (error)
3476                         return error;
3477 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/ioctl.c
3478 --- linux-2.6.22.10/fs/ext2/ioctl.c     2007-07-09 13:19:23 +0200
3479 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/ioctl.c  2007-08-05 20:53:12 +0200
3480 @@ -13,6 +13,7 @@
3481  #include <linux/sched.h>
3482  #include <linux/compat.h>
3483  #include <linux/smp_lock.h>
3484 +#include <linux/mount.h>
3485  #include <asm/current.h>
3486  #include <asm/uaccess.h>
3487  
3488 @@ -33,7 +34,8 @@ int ext2_ioctl (struct inode * inode, st
3489         case EXT2_IOC_SETFLAGS: {
3490                 unsigned int oldflags;
3491  
3492 -               if (IS_RDONLY(inode))
3493 +               if (IS_RDONLY(inode) ||
3494 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3495                         return -EROFS;
3496  
3497                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3498 @@ -54,7 +56,9 @@ int ext2_ioctl (struct inode * inode, st
3499                  *
3500                  * This test looks nicer. Thanks to Pauline Middelink
3501                  */
3502 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3503 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3504 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3505 +                       EXT2_IMMUTABLE_FL | EXT2_IUNLINK_FL))) {
3506                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3507                                 mutex_unlock(&inode->i_mutex);
3508                                 return -EPERM;
3509 @@ -76,7 +80,8 @@ int ext2_ioctl (struct inode * inode, st
3510         case EXT2_IOC_SETVERSION:
3511                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3512                         return -EPERM;
3513 -               if (IS_RDONLY(inode))
3514 +               if (IS_RDONLY(inode) ||
3515 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3516                         return -EROFS;
3517                 if (get_user(inode->i_generation, (int __user *) arg))
3518                         return -EFAULT; 
3519 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/namei.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/namei.c
3520 --- linux-2.6.22.10/fs/ext2/namei.c     2007-05-02 19:25:17 +0200
3521 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/namei.c  2007-08-05 20:53:12 +0200
3522 @@ -31,6 +31,7 @@
3523   */
3524  
3525  #include <linux/pagemap.h>
3526 +#include <linux/vs_tag.h>
3527  #include "ext2.h"
3528  #include "xattr.h"
3529  #include "acl.h"
3530 @@ -66,6 +67,7 @@ static struct dentry *ext2_lookup(struct
3531                 inode = iget(dir->i_sb, ino);
3532                 if (!inode)
3533                         return ERR_PTR(-EACCES);
3534 +               dx_propagate_tag(nd, inode);
3535         }
3536         return d_splice_alias(inode, dentry);
3537  }
3538 @@ -391,6 +393,7 @@ const struct inode_operations ext2_dir_i
3539  #endif
3540         .setattr        = ext2_setattr,
3541         .permission     = ext2_permission,
3542 +       .sync_flags     = ext2_sync_flags,
3543  };
3544  
3545  const struct inode_operations ext2_special_inode_operations = {
3546 @@ -402,4 +405,5 @@ const struct inode_operations ext2_speci
3547  #endif
3548         .setattr        = ext2_setattr,
3549         .permission     = ext2_permission,
3550 +       .sync_flags     = ext2_sync_flags,
3551  };
3552 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/super.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/super.c
3553 --- linux-2.6.22.10/fs/ext2/super.c     2007-07-09 13:19:23 +0200
3554 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/super.c  2007-08-05 20:53:12 +0200
3555 @@ -321,7 +321,7 @@ enum {
3556         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3557         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3558         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3559 -       Opt_usrquota, Opt_grpquota
3560 +       Opt_usrquota, Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3561  };
3562  
3563  static match_table_t tokens = {
3564 @@ -349,6 +349,9 @@ static match_table_t tokens = {
3565         {Opt_acl, "acl"},
3566         {Opt_noacl, "noacl"},
3567         {Opt_xip, "xip"},
3568 +       {Opt_tag, "tag"},
3569 +       {Opt_notag, "notag"},
3570 +       {Opt_tagid, "tagid=%u"},
3571         {Opt_grpquota, "grpquota"},
3572         {Opt_ignore, "noquota"},
3573         {Opt_quota, "quota"},
3574 @@ -417,6 +420,20 @@ static int parse_options (char * options
3575                 case Opt_nouid32:
3576                         set_opt (sbi->s_mount_opt, NO_UID32);
3577                         break;
3578 +#ifndef CONFIG_TAGGING_NONE
3579 +               case Opt_tag:
3580 +                       set_opt (sbi->s_mount_opt, TAGGED);
3581 +                       break;
3582 +               case Opt_notag:
3583 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3584 +                       break;
3585 +#endif
3586 +#ifdef CONFIG_PROPAGATE
3587 +               case Opt_tagid:
3588 +                       /* use args[0] */
3589 +                       set_opt (sbi->s_mount_opt, TAGGED);
3590 +                       break;
3591 +#endif
3592                 case Opt_nocheck:
3593                         clear_opt (sbi->s_mount_opt, CHECK);
3594                         break;
3595 @@ -727,6 +744,8 @@ static int ext2_fill_super(struct super_
3596         if (!parse_options ((char *) data, sbi))
3597                 goto failed_mount;
3598  
3599 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3600 +               sb->s_flags |= MS_TAGGED;
3601         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3602                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3603                  MS_POSIXACL : 0);
3604 @@ -1035,6 +1054,13 @@ static int ext2_remount (struct super_bl
3605                 goto restore_opts;
3606         }
3607  
3608 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3609 +               !(sb->s_flags & MS_TAGGED)) {
3610 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3611 +                      sb->s_id);
3612 +               return -EINVAL;
3613 +       }
3614 +
3615         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3616                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3617  
3618 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/symlink.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/symlink.c
3619 --- linux-2.6.22.10/fs/ext2/symlink.c   2007-05-02 19:25:17 +0200
3620 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/symlink.c        2007-08-05 20:53:12 +0200
3621 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
3622         .listxattr      = ext2_listxattr,
3623         .removexattr    = generic_removexattr,
3624  #endif
3625 +       .sync_flags     = ext2_sync_flags,
3626  };
3627   
3628  const struct inode_operations ext2_fast_symlink_inode_operations = {
3629 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
3630         .listxattr      = ext2_listxattr,
3631         .removexattr    = generic_removexattr,
3632  #endif
3633 +       .sync_flags     = ext2_sync_flags,
3634  };
3635 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/xattr.c linux-2.6.22.10-vs2.3.0.29/fs/ext2/xattr.c
3636 --- linux-2.6.22.10/fs/ext2/xattr.c     2007-02-06 03:01:18 +0100
3637 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/xattr.c  2007-08-05 20:53:12 +0200
3638 @@ -60,6 +60,7 @@
3639  #include <linux/mbcache.h>
3640  #include <linux/quotaops.h>
3641  #include <linux/rwsem.h>
3642 +#include <linux/vs_dlimit.h>
3643  #include "ext2.h"
3644  #include "xattr.h"
3645  #include "acl.h"
3646 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
3647                                    the inode.  */
3648                                 ea_bdebug(new_bh, "reusing block");
3649  
3650 +                               error = -ENOSPC;
3651 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3652 +                                       goto cleanup;
3653                                 error = -EDQUOT;
3654                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
3655 +                                       DLIMIT_FREE_BLOCK(inode, 1);
3656                                         unlock_buffer(new_bh);
3657                                         goto cleanup;
3658                                 }
3659 @@ -736,6 +741,7 @@ ext2_xattr_set2(struct inode *inode, str
3660                                 le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
3661                         if (ce)
3662                                 mb_cache_entry_release(ce);
3663 +                       DLIMIT_FREE_BLOCK(inode, 1);
3664                         DQUOT_FREE_BLOCK(inode, 1);
3665                         mark_buffer_dirty(old_bh);
3666                         ea_bdebug(old_bh, "refcount now=%d",
3667 @@ -800,6 +806,7 @@ ext2_xattr_delete_inode(struct inode *in
3668                 mark_buffer_dirty(bh);
3669                 if (IS_SYNC(inode))
3670                         sync_dirty_buffer(bh);
3671 +               DLIMIT_FREE_BLOCK(inode, 1);
3672                 DQUOT_FREE_BLOCK(inode, 1);
3673         }
3674         EXT2_I(inode)->i_file_acl = 0;
3675 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/balloc.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/balloc.c
3676 --- linux-2.6.22.10/fs/ext3/balloc.c    2007-05-02 19:25:17 +0200
3677 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/balloc.c 2007-08-05 20:53:12 +0200
3678 @@ -19,6 +19,8 @@
3679  #include <linux/ext3_jbd.h>
3680  #include <linux/quotaops.h>
3681  #include <linux/buffer_head.h>
3682 +#include <linux/vs_dlimit.h>
3683 +#include <linux/vs_tag.h>
3684  
3685  /*
3686   * balloc.c contains the blocks allocation and deallocation routines
3687 @@ -613,8 +615,10 @@ void ext3_free_blocks(handle_t *handle, 
3688                 return;
3689         }
3690         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
3691 -       if (dquot_freed_blocks)
3692 +       if (dquot_freed_blocks) {
3693 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3694                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3695 +       }
3696         return;
3697  }
3698  
3699 @@ -1353,18 +1357,33 @@ out:
3700   *
3701   * Check if filesystem has at least 1 free block available for allocation.
3702   */
3703 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
3704 +static int ext3_has_free_blocks(struct super_block *sb)
3705  {
3706 -       ext3_fsblk_t free_blocks, root_blocks;
3707 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
3708 +       unsigned long long free_blocks, root_blocks;
3709 +       int cond;
3710  
3711         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3712         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
3713 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
3714 +
3715 +       vxdprintk(VXD_CBIT(dlim, 3),
3716 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
3717 +               sb, free_blocks, root_blocks);
3718 +
3719 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3720 +
3721 +       cond = (free_blocks < root_blocks + 1 &&
3722 +               !capable(CAP_SYS_RESOURCE) &&
3723                 sbi->s_resuid != current->fsuid &&
3724 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
3725 -               return 0;
3726 -       }
3727 -       return 1;
3728 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
3729 +
3730 +       vxdprintk(VXD_CBIT(dlim, 3),
3731 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
3732 +               sb, free_blocks, root_blocks,
3733 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
3734 +               sbi->s_resuid, current->fsuid, cond?0:1);
3735 +
3736 +       return (cond ? 0 : 1);
3737  }
3738  
3739  /**
3740 @@ -1381,7 +1400,7 @@ static int ext3_has_free_blocks(struct e
3741   */
3742  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
3743  {
3744 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
3745 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
3746                 return 0;
3747  
3748         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
3749 @@ -1444,6 +1463,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3750                 *errp = -EDQUOT;
3751                 return 0;
3752         }
3753 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3754 +           goto out_dlimit;
3755  
3756         sbi = EXT3_SB(sb);
3757         es = EXT3_SB(sb)->s_es;
3758 @@ -1460,7 +1481,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3759         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
3760                 my_rsv = &block_i->rsv_window_node;
3761  
3762 -       if (!ext3_has_free_blocks(sbi)) {
3763 +       if (!ext3_has_free_blocks(sb)) {
3764                 *errp = -ENOSPC;
3765                 goto out;
3766         }
3767 @@ -1647,12 +1668,16 @@ allocated:
3768         *errp = 0;
3769         brelse(bitmap_bh);
3770         DQUOT_FREE_BLOCK(inode, *count-num);
3771 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3772         *count = num;
3773         return ret_block;
3774  
3775  io_error:
3776         *errp = -EIO;
3777  out:
3778 +       if (!performed_allocation)
3779 +               DLIMIT_FREE_BLOCK(inode, *count);
3780 +out_dlimit:
3781         if (fatal) {
3782                 *errp = fatal;
3783                 ext3_std_error(sb, fatal);
3784 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/file.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/file.c
3785 --- linux-2.6.22.10/fs/ext3/file.c      2007-05-02 19:25:17 +0200
3786 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/file.c   2007-09-12 20:04:16 +0200
3787 @@ -135,5 +135,6 @@ const struct inode_operations ext3_file_
3788         .removexattr    = generic_removexattr,
3789  #endif
3790         .permission     = ext3_permission,
3791 +       .sync_flags     = ext3_sync_flags,
3792  };
3793  
3794 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/ialloc.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/ialloc.c
3795 --- linux-2.6.22.10/fs/ext3/ialloc.c    2006-11-30 21:19:19 +0100
3796 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/ialloc.c 2007-08-05 20:53:12 +0200
3797 @@ -23,6 +23,8 @@
3798  #include <linux/buffer_head.h>
3799  #include <linux/random.h>
3800  #include <linux/bitops.h>
3801 +#include <linux/vs_dlimit.h>
3802 +#include <linux/vs_tag.h>
3803  
3804  #include <asm/byteorder.h>
3805  
3806 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
3807         ext3_xattr_delete_inode(handle, inode);
3808         DQUOT_FREE_INODE(inode);
3809         DQUOT_DROP(inode);
3810 +       DLIMIT_FREE_INODE(inode);
3811  
3812         is_directory = S_ISDIR(inode->i_mode);
3813  
3814 @@ -445,6 +448,12 @@ struct inode *ext3_new_inode(handle_t *h
3815         inode = new_inode(sb);
3816         if (!inode)
3817                 return ERR_PTR(-ENOMEM);
3818 +
3819 +       inode->i_tag = dx_current_fstag(sb);
3820 +       if (DLIMIT_ALLOC_INODE(inode)) {
3821 +               err = -ENOSPC;
3822 +               goto out_dlimit;
3823 +       }
3824         ei = EXT3_I(inode);
3825  
3826         sbi = EXT3_SB(sb);
3827 @@ -566,7 +575,8 @@ got:
3828         ei->i_dir_start_lookup = 0;
3829         ei->i_disksize = 0;
3830  
3831 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
3832 +       ei->i_flags = EXT3_I(dir)->i_flags &
3833 +               ~(EXT3_INDEX_FL|EXT3_IUNLINK_FL|EXT3_BARRIER_FL);
3834         if (S_ISLNK(mode))
3835                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
3836         /* dirsync only applies to directories */
3837 @@ -621,6 +631,8 @@ got:
3838  fail:
3839         ext3_std_error(sb, err);
3840  out:
3841 +       DLIMIT_FREE_INODE(inode);
3842 +out_dlimit:
3843         iput(inode);
3844         ret = ERR_PTR(err);
3845  really_out:
3846 @@ -632,6 +644,7 @@ fail_free_drop:
3847  
3848  fail_drop:
3849         DQUOT_DROP(inode);
3850 +       DLIMIT_FREE_INODE(inode);
3851         inode->i_flags |= S_NOQUOTA;
3852         inode->i_nlink = 0;
3853         iput(inode);
3854 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/inode.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/inode.c
3855 --- linux-2.6.22.10/fs/ext3/inode.c     2007-07-09 13:19:23 +0200
3856 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/inode.c  2007-08-18 02:52:34 +0200
3857 @@ -36,6 +36,7 @@
3858  #include <linux/mpage.h>
3859  #include <linux/uio.h>
3860  #include <linux/bio.h>
3861 +#include <linux/vs_tag.h>
3862  #include "xattr.h"
3863  #include "acl.h"
3864  
3865 @@ -2237,7 +2238,7 @@ void ext3_truncate(struct inode *inode)
3866                 return;
3867         if (ext3_inode_is_fast_symlink(inode))
3868                 return;
3869 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3870 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3871                 return;
3872  
3873         /*
3874 @@ -2559,13 +2560,20 @@ void ext3_set_inode_flags(struct inode *
3875  {
3876         unsigned int flags = EXT3_I(inode)->i_flags;
3877  
3878 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3879 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3880 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3881 +
3882 +       if (flags & EXT3_IMMUTABLE_FL)
3883 +               inode->i_flags |= S_IMMUTABLE;
3884 +       if (flags & EXT3_IUNLINK_FL)
3885 +               inode->i_flags |= S_IUNLINK;
3886 +       if (flags & EXT3_BARRIER_FL)
3887 +               inode->i_flags |= S_BARRIER;
3888 +
3889         if (flags & EXT3_SYNC_FL)
3890                 inode->i_flags |= S_SYNC;
3891         if (flags & EXT3_APPEND_FL)
3892                 inode->i_flags |= S_APPEND;
3893 -       if (flags & EXT3_IMMUTABLE_FL)
3894 -               inode->i_flags |= S_IMMUTABLE;
3895         if (flags & EXT3_NOATIME_FL)
3896                 inode->i_flags |= S_NOATIME;
3897         if (flags & EXT3_DIRSYNC_FL)
3898 @@ -2591,6 +2599,45 @@ void ext3_get_inode_flags(struct ext3_in
3899                 ei->i_flags |= EXT3_DIRSYNC_FL;
3900  }
3901  
3902 +int ext3_sync_flags(struct inode *inode)
3903 +{
3904 +       unsigned int oldflags, newflags;
3905 +       int err = 0;
3906 +
3907 +       oldflags = EXT3_I(inode)->i_flags;
3908 +       newflags = oldflags & ~(EXT3_IMMUTABLE_FL |
3909 +               EXT3_IUNLINK_FL | EXT3_BARRIER_FL);
3910 +
3911 +       if (IS_IMMUTABLE(inode))
3912 +               newflags |= EXT3_IMMUTABLE_FL;
3913 +       if (IS_IUNLINK(inode))
3914 +               newflags |= EXT3_IUNLINK_FL;
3915 +       if (IS_BARRIER(inode))
3916 +               newflags |= EXT3_BARRIER_FL;
3917 +
3918 +       if (oldflags ^ newflags) {
3919 +               handle_t *handle;
3920 +               struct ext3_iloc iloc;
3921 +
3922 +               handle = ext3_journal_start(inode, 1);
3923 +               if (IS_ERR(handle))
3924 +                       return PTR_ERR(handle);
3925 +               if (IS_SYNC(inode))
3926 +                       handle->h_sync = 1;
3927 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3928 +               if (err)
3929 +                       goto flags_err;
3930 +
3931 +               EXT3_I(inode)->i_flags = newflags;
3932 +               inode->i_ctime = CURRENT_TIME;
3933 +
3934 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3935 +       flags_err:
3936 +               ext3_journal_stop(handle);
3937 +       }
3938 +       return err;
3939 +}
3940 +
3941  void ext3_read_inode(struct inode * inode)
3942  {
3943         struct ext3_iloc iloc;
3944 @@ -2598,6 +2645,8 @@ void ext3_read_inode(struct inode * inod
3945         struct ext3_inode_info *ei = EXT3_I(inode);
3946         struct buffer_head *bh;
3947         int block;
3948 +       uid_t uid;
3949 +       gid_t gid;
3950  
3951  #ifdef CONFIG_EXT3_FS_POSIX_ACL
3952         ei->i_acl = EXT3_ACL_NOT_CACHED;
3953 @@ -2610,12 +2659,17 @@ void ext3_read_inode(struct inode * inod
3954         bh = iloc.bh;
3955         raw_inode = ext3_raw_inode(&iloc);
3956         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3957 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3958 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3959 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3960 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3961         if(!(test_opt (inode->i_sb, NO_UID32))) {
3962 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3963 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3964 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3965 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3966         }
3967 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3968 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3969 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3970 +               le16_to_cpu(raw_inode->i_raw_tag));
3971 +
3972         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3973         inode->i_size = le32_to_cpu(raw_inode->i_size);
3974         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3975 @@ -2741,6 +2795,8 @@ static int ext3_do_update_inode(handle_t
3976         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3977         struct ext3_inode_info *ei = EXT3_I(inode);
3978         struct buffer_head *bh = iloc->bh;
3979 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3980 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3981         int err = 0, rc, block;
3982  
3983         /* For fields not not tracking in the in-memory inode,
3984 @@ -2751,29 +2807,32 @@ static int ext3_do_update_inode(handle_t
3985         ext3_get_inode_flags(ei);
3986         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3987         if(!(test_opt(inode->i_sb, NO_UID32))) {
3988 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3989 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3990 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3991 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3992  /*
3993   * Fix up interoperability with old kernels. Otherwise, old inodes get
3994   * re-used with the upper 16 bits of the uid/gid intact
3995   */
3996                 if(!ei->i_dtime) {
3997                         raw_inode->i_uid_high =
3998 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3999 +                               cpu_to_le16(high_16_bits(uid));
4000                         raw_inode->i_gid_high =
4001 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4002 +                               cpu_to_le16(high_16_bits(gid));
4003                 } else {
4004                         raw_inode->i_uid_high = 0;
4005                         raw_inode->i_gid_high = 0;
4006                 }
4007         } else {
4008                 raw_inode->i_uid_low =
4009 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4010 +                       cpu_to_le16(fs_high2lowuid(uid));
4011                 raw_inode->i_gid_low =
4012 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4013 +                       cpu_to_le16(fs_high2lowgid(gid));
4014                 raw_inode->i_uid_high = 0;
4015                 raw_inode->i_gid_high = 0;
4016         }
4017 +#ifdef CONFIG_TAGGING_INTERN
4018 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4019 +#endif
4020         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4021         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4022         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4023 @@ -2926,7 +2985,8 @@ int ext3_setattr(struct dentry *dentry, 
4024                 return error;
4025  
4026         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4027 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4028 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4029 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4030                 handle_t *handle;
4031  
4032                 /* (user+group)*(old+new) structure, inode write (sb,
4033 @@ -2948,6 +3008,8 @@ int ext3_setattr(struct dentry *dentry, 
4034                         inode->i_uid = attr->ia_uid;
4035                 if (attr->ia_valid & ATTR_GID)
4036                         inode->i_gid = attr->ia_gid;
4037 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4038 +                       inode->i_tag = attr->ia_tag;
4039                 error = ext3_mark_inode_dirty(handle, inode);
4040                 ext3_journal_stop(handle);
4041         }
4042 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/ioctl.c
4043 --- linux-2.6.22.10/fs/ext3/ioctl.c     2007-07-09 13:19:23 +0200
4044 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/ioctl.c  2007-08-05 20:53:12 +0200
4045 @@ -8,6 +8,7 @@
4046   */
4047  
4048  #include <linux/fs.h>
4049 +#include <linux/mount.h>
4050  #include <linux/jbd.h>
4051  #include <linux/capability.h>
4052  #include <linux/ext3_fs.h>
4053 @@ -15,6 +16,7 @@
4054  #include <linux/time.h>
4055  #include <linux/compat.h>
4056  #include <linux/smp_lock.h>
4057 +#include <linux/vs_tag.h>
4058  #include <asm/uaccess.h>
4059  
4060  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
4061 @@ -38,7 +40,8 @@ int ext3_ioctl (struct inode * inode, st
4062                 unsigned int oldflags;
4063                 unsigned int jflag;
4064  
4065 -               if (IS_RDONLY(inode))
4066 +               if (IS_RDONLY(inode) ||
4067 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4068                         return -EROFS;
4069  
4070                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4071 @@ -62,7 +65,9 @@ int ext3_ioctl (struct inode * inode, st
4072                  *
4073                  * This test looks nicer. Thanks to Pauline Middelink
4074                  */
4075 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
4076 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
4077 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
4078 +                       EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL))) {
4079                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4080                                 mutex_unlock(&inode->i_mutex);
4081                                 return -EPERM;
4082 @@ -124,7 +129,8 @@ flags_err:
4083  
4084                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4085                         return -EPERM;
4086 -               if (IS_RDONLY(inode))
4087 +               if (IS_RDONLY(inode) ||
4088 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4089                         return -EROFS;
4090                 if (get_user(generation, (int __user *) arg))
4091                         return -EFAULT;
4092 @@ -178,7 +184,8 @@ flags_err:
4093                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4094                         return -ENOTTY;
4095  
4096 -               if (IS_RDONLY(inode))
4097 +               if (IS_RDONLY(inode) ||
4098 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4099                         return -EROFS;
4100  
4101                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4102 @@ -213,7 +220,8 @@ flags_err:
4103                 if (!capable(CAP_SYS_RESOURCE))
4104                         return -EPERM;
4105  
4106 -               if (IS_RDONLY(inode))
4107 +               if (IS_RDONLY(inode) ||
4108 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4109                         return -EROFS;
4110  
4111                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4112 @@ -234,7 +242,8 @@ flags_err:
4113                 if (!capable(CAP_SYS_RESOURCE))
4114                         return -EPERM;
4115  
4116 -               if (IS_RDONLY(inode))
4117 +               if (IS_RDONLY(inode) ||
4118 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4119                         return -EROFS;
4120  
4121                 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
4122 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/namei.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/namei.c
4123 --- linux-2.6.22.10/fs/ext3/namei.c     2007-10-30 01:57:14 +0100
4124 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/namei.c  2007-09-30 14:58:01 +0200
4125 @@ -36,6 +36,7 @@
4126  #include <linux/quotaops.h>
4127  #include <linux/buffer_head.h>
4128  #include <linux/bio.h>
4129 +#include <linux/vs_tag.h>
4130  
4131  #include "namei.h"
4132  #include "xattr.h"
4133 @@ -1052,6 +1053,7 @@ static struct dentry *ext3_lookup(struct
4134  
4135                 if (!inode)
4136                         return ERR_PTR(-EACCES);
4137 +               dx_propagate_tag(nd, inode);
4138         }
4139         return d_splice_alias(inode, dentry);
4140  }
4141 @@ -2443,6 +2445,7 @@ const struct inode_operations ext3_dir_i
4142         .removexattr    = generic_removexattr,
4143  #endif
4144         .permission     = ext3_permission,
4145 +       .sync_flags     = ext3_sync_flags,
4146  };
4147  
4148  const struct inode_operations ext3_special_inode_operations = {
4149 @@ -2454,4 +2457,5 @@ const struct inode_operations ext3_speci
4150         .removexattr    = generic_removexattr,
4151  #endif
4152         .permission     = ext3_permission,
4153 +       .sync_flags     = ext3_sync_flags,
4154  };
4155 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/super.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/super.c
4156 --- linux-2.6.22.10/fs/ext3/super.c     2007-07-09 13:19:23 +0200
4157 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/super.c  2007-08-05 20:53:12 +0200
4158 @@ -674,7 +674,7 @@ enum {
4159         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4160         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4161         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4162 -       Opt_grpquota
4163 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
4164  };
4165  
4166  static match_table_t tokens = {
4167 @@ -724,6 +724,9 @@ static match_table_t tokens = {
4168         {Opt_quota, "quota"},
4169         {Opt_usrquota, "usrquota"},
4170         {Opt_barrier, "barrier=%u"},
4171 +       {Opt_tag, "tag"},
4172 +       {Opt_notag, "notag"},
4173 +       {Opt_tagid, "tagid=%u"},
4174         {Opt_err, NULL},
4175         {Opt_resize, "resize"},
4176  };
4177 @@ -817,6 +820,20 @@ static int parse_options (char *options,
4178                 case Opt_nouid32:
4179                         set_opt (sbi->s_mount_opt, NO_UID32);
4180                         break;
4181 +#ifndef CONFIG_TAGGING_NONE
4182 +               case Opt_tag:
4183 +                       set_opt (sbi->s_mount_opt, TAGGED);
4184 +                       break;
4185 +               case Opt_notag:
4186 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4187 +                       break;
4188 +#endif
4189 +#ifdef CONFIG_PROPAGATE
4190 +               case Opt_tagid:
4191 +                       /* use args[0] */
4192 +                       set_opt (sbi->s_mount_opt, TAGGED);
4193 +                       break;
4194 +#endif
4195                 case Opt_nocheck:
4196                         clear_opt (sbi->s_mount_opt, CHECK);
4197                         break;
4198 @@ -1487,6 +1504,9 @@ static int ext3_fill_super (struct super
4199                             NULL, 0))
4200                 goto failed_mount;
4201  
4202 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
4203 +               sb->s_flags |= MS_TAGGED;
4204 +
4205         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4206                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4207  
4208 @@ -2302,6 +2322,12 @@ static int ext3_remount (struct super_bl
4209  
4210         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
4211                 ext3_abort(sb, __FUNCTION__, "Abort forced by user");
4212 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
4213 +               !(sb->s_flags & MS_TAGGED)) {
4214 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
4215 +                       sb->s_id);
4216 +               return -EINVAL;
4217 +       }
4218  
4219         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4220                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4221 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/symlink.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/symlink.c
4222 --- linux-2.6.22.10/fs/ext3/symlink.c   2007-05-02 19:25:17 +0200
4223 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/symlink.c        2007-08-05 20:53:12 +0200
4224 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
4225         .listxattr      = ext3_listxattr,
4226         .removexattr    = generic_removexattr,
4227  #endif
4228 +       .sync_flags     = ext3_sync_flags,
4229  };
4230  
4231  const struct inode_operations ext3_fast_symlink_inode_operations = {
4232 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
4233         .listxattr      = ext3_listxattr,
4234         .removexattr    = generic_removexattr,
4235  #endif
4236 +       .sync_flags     = ext3_sync_flags,
4237  };
4238 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/xattr.c linux-2.6.22.10-vs2.3.0.29/fs/ext3/xattr.c
4239 --- linux-2.6.22.10/fs/ext3/xattr.c     2007-05-02 19:25:17 +0200
4240 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/xattr.c  2007-08-05 20:53:12 +0200
4241 @@ -58,6 +58,7 @@
4242  #include <linux/mbcache.h>
4243  #include <linux/quotaops.h>
4244  #include <linux/rwsem.h>
4245 +#include <linux/vs_dlimit.h>
4246  #include "xattr.h"
4247  #include "acl.h"
4248  
4249 @@ -497,6 +498,7 @@ ext3_xattr_release_block(handle_t *handl
4250                 error = ext3_journal_dirty_metadata(handle, bh);
4251                 if (IS_SYNC(inode))
4252                         handle->h_sync = 1;
4253 +                       DLIMIT_FREE_BLOCK(inode, 1);
4254                 DQUOT_FREE_BLOCK(inode, 1);
4255                 ea_bdebug(bh, "refcount now=%d; releasing",
4256                           le32_to_cpu(BHDR(bh)->h_refcount));
4257 @@ -771,11 +773,14 @@ inserted:
4258                         if (new_bh == bs->bh)
4259                                 ea_bdebug(new_bh, "keeping");
4260                         else {
4261 +                               error = -ENOSPC;
4262 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4263 +                                       goto cleanup;
4264                                 /* The old block is released after updating
4265                                    the inode. */
4266                                 error = -EDQUOT;
4267                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4268 -                                       goto cleanup;
4269 +                                       goto cleanup_dlimit;
4270                                 error = ext3_journal_get_write_access(handle,
4271                                                                       new_bh);
4272                                 if (error)
4273 @@ -852,6 +857,8 @@ cleanup:
4274  
4275  cleanup_dquot:
4276         DQUOT_FREE_BLOCK(inode, 1);
4277 +cleanup_dlimit:
4278 +       DLIMIT_FREE_BLOCK(inode, 1);
4279         goto cleanup;
4280  
4281  bad_block:
4282 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/balloc.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/balloc.c
4283 --- linux-2.6.22.10/fs/ext4/balloc.c    2007-07-09 13:19:23 +0200
4284 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/balloc.c 2007-08-05 20:53:12 +0200
4285 @@ -19,6 +19,8 @@
4286  #include <linux/ext4_jbd2.h>
4287  #include <linux/quotaops.h>
4288  #include <linux/buffer_head.h>
4289 +#include <linux/vs_dlimit.h>
4290 +#include <linux/vs_tag.h>
4291  
4292  /*
4293   * balloc.c contains the blocks allocation and deallocation routines
4294 @@ -630,8 +632,10 @@ void ext4_free_blocks(handle_t *handle, 
4295                 return;
4296         }
4297         ext4_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
4298 -       if (dquot_freed_blocks)
4299 +       if (dquot_freed_blocks) {
4300 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
4301                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
4302 +       }
4303         return;
4304  }
4305  
4306 @@ -1370,18 +1374,33 @@ out:
4307   *
4308   * Check if filesystem has at least 1 free block available for allocation.
4309   */
4310 -static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
4311 +static int ext4_has_free_blocks(struct super_block *sb)
4312  {
4313 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
4314         ext4_fsblk_t free_blocks, root_blocks;
4315 +       int cond;
4316  
4317         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
4318         root_blocks = ext4_r_blocks_count(sbi->s_es);
4319 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
4320 +
4321 +       vxdprintk(VXD_CBIT(dlim, 3),
4322 +               "ext4_has_free_blocks(%p): free=%llu, root=%llu",
4323 +               sb, free_blocks, root_blocks);
4324 +
4325 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
4326 +
4327 +       cond = (free_blocks < root_blocks + 1 &&
4328 +               !capable(CAP_SYS_RESOURCE) &&
4329                 sbi->s_resuid != current->fsuid &&
4330 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
4331 -               return 0;
4332 -       }
4333 -       return 1;
4334 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
4335 +
4336 +       vxdprintk(VXD_CBIT(dlim, 3),
4337 +               "ext4_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
4338 +               sb, free_blocks, root_blocks,
4339 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
4340 +               sbi->s_resuid, current->fsuid, cond?0:1);
4341 +
4342 +       return (cond ? 0 : 1);
4343  }
4344  
4345  /**
4346 @@ -1398,7 +1417,7 @@ static int ext4_has_free_blocks(struct e
4347   */
4348  int ext4_should_retry_alloc(struct super_block *sb, int *retries)
4349  {
4350 -       if (!ext4_has_free_blocks(EXT4_SB(sb)) || (*retries)++ > 3)
4351 +       if (!ext4_has_free_blocks(sb) || (*retries)++ > 3)
4352                 return 0;
4353  
4354         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
4355 @@ -1461,6 +1480,8 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
4356                 *errp = -EDQUOT;
4357                 return 0;
4358         }
4359 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
4360 +           goto out_dlimit;
4361  
4362         sbi = EXT4_SB(sb);
4363         es = EXT4_SB(sb)->s_es;
4364 @@ -1477,7 +1498,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
4365         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
4366                 my_rsv = &block_i->rsv_window_node;
4367  
4368 -       if (!ext4_has_free_blocks(sbi)) {
4369 +       if (!ext4_has_free_blocks(sb)) {
4370                 *errp = -ENOSPC;
4371                 goto out;
4372         }
4373 @@ -1661,12 +1682,16 @@ allocated:
4374         *errp = 0;
4375         brelse(bitmap_bh);
4376         DQUOT_FREE_BLOCK(inode, *count-num);
4377 +       DLIMIT_FREE_BLOCK(inode, *count-num);
4378         *count = num;
4379         return ret_block;
4380  
4381  io_error:
4382         *errp = -EIO;
4383  out:
4384 +       if (!performed_allocation)
4385 +               DLIMIT_FREE_BLOCK(inode, *count);
4386 +out_dlimit:
4387         if (fatal) {
4388                 *errp = fatal;
4389                 ext4_std_error(sb, fatal);
4390 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/file.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/file.c
4391 --- linux-2.6.22.10/fs/ext4/file.c      2007-05-02 19:25:17 +0200
4392 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/file.c   2007-09-12 20:04:16 +0200
4393 @@ -135,5 +135,6 @@ const struct inode_operations ext4_file_
4394         .removexattr    = generic_removexattr,
4395  #endif
4396         .permission     = ext4_permission,
4397 +       .sync_flags     = ext4_sync_flags,
4398  };
4399  
4400 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/ialloc.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/ialloc.c
4401 --- linux-2.6.22.10/fs/ext4/ialloc.c    2006-11-30 21:19:20 +0100
4402 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/ialloc.c 2007-08-05 20:53:12 +0200
4403 @@ -24,6 +24,8 @@
4404  #include <linux/random.h>
4405  #include <linux/bitops.h>
4406  #include <linux/blkdev.h>
4407 +#include <linux/vs_dlimit.h>
4408 +#include <linux/vs_tag.h>
4409  #include <asm/byteorder.h>
4410  
4411  #include "xattr.h"
4412 @@ -127,6 +129,7 @@ void ext4_free_inode (handle_t *handle, 
4413         ext4_xattr_delete_inode(handle, inode);
4414         DQUOT_FREE_INODE(inode);
4415         DQUOT_DROP(inode);
4416 +       DLIMIT_FREE_INODE(inode);
4417  
4418         is_directory = S_ISDIR(inode->i_mode);
4419  
4420 @@ -448,6 +451,12 @@ struct inode *ext4_new_inode(handle_t *h
4421         inode = new_inode(sb);
4422         if (!inode)
4423                 return ERR_PTR(-ENOMEM);
4424 +
4425 +       inode->i_tag = dx_current_fstag(sb);
4426 +       if (DLIMIT_ALLOC_INODE(inode)) {
4427 +               err = -ENOSPC;
4428 +               goto out_dlimit;
4429 +       }
4430         ei = EXT4_I(inode);
4431  
4432         sbi = EXT4_SB(sb);
4433 @@ -569,7 +578,8 @@ got:
4434         ei->i_dir_start_lookup = 0;
4435         ei->i_disksize = 0;
4436  
4437 -       ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
4438 +       ei->i_flags = EXT4_I(dir)->i_flags &
4439 +               ~(EXT4_INDEX_FL|EXT4_IUNLINK_FL|EXT4_BARRIER_FL);
4440         if (S_ISLNK(mode))
4441                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
4442         /* dirsync only applies to directories */
4443 @@ -635,6 +645,8 @@ got:
4444  fail:
4445         ext4_std_error(sb, err);
4446  out:
4447 +       DLIMIT_FREE_INODE(inode);
4448 +out_dlimit:
4449         iput(inode);
4450         ret = ERR_PTR(err);
4451  really_out:
4452 @@ -646,6 +658,7 @@ fail_free_drop:
4453  
4454  fail_drop:
4455         DQUOT_DROP(inode);
4456 +       DLIMIT_FREE_INODE(inode);
4457         inode->i_flags |= S_NOQUOTA;
4458         inode->i_nlink = 0;
4459         iput(inode);
4460 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/inode.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/inode.c
4461 --- linux-2.6.22.10/fs/ext4/inode.c     2007-07-09 13:19:23 +0200
4462 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/inode.c  2007-08-18 02:52:34 +0200
4463 @@ -36,6 +36,7 @@
4464  #include <linux/mpage.h>
4465  #include <linux/uio.h>
4466  #include <linux/bio.h>
4467 +#include <linux/vs_tag.h>
4468  #include "xattr.h"
4469  #include "acl.h"
4470  
4471 @@ -2244,7 +2245,7 @@ void ext4_truncate(struct inode *inode)
4472                 return;
4473         if (ext4_inode_is_fast_symlink(inode))
4474                 return;
4475 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4476 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4477                 return;
4478  
4479         /*
4480 @@ -2570,19 +2571,65 @@ void ext4_set_inode_flags(struct inode *
4481  {
4482         unsigned int flags = EXT4_I(inode)->i_flags;
4483  
4484 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4485 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
4486 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4487 +
4488 +       if (flags & EXT4_IMMUTABLE_FL)
4489 +               inode->i_flags |= S_IMMUTABLE;
4490 +       if (flags & EXT4_IUNLINK_FL)
4491 +               inode->i_flags |= S_IUNLINK;
4492 +       if (flags & EXT4_BARRIER_FL)
4493 +               inode->i_flags |= S_BARRIER;
4494 +
4495         if (flags & EXT4_SYNC_FL)
4496                 inode->i_flags |= S_SYNC;
4497         if (flags & EXT4_APPEND_FL)
4498                 inode->i_flags |= S_APPEND;
4499 -       if (flags & EXT4_IMMUTABLE_FL)
4500 -               inode->i_flags |= S_IMMUTABLE;
4501         if (flags & EXT4_NOATIME_FL)
4502                 inode->i_flags |= S_NOATIME;
4503         if (flags & EXT4_DIRSYNC_FL)
4504                 inode->i_flags |= S_DIRSYNC;
4505  }
4506  
4507 +int ext4_sync_flags(struct inode *inode)
4508 +{
4509 +       unsigned int oldflags, newflags;
4510 +       int err = 0;
4511 +
4512 +       oldflags = EXT4_I(inode)->i_flags;
4513 +       newflags = oldflags & ~(EXT4_IMMUTABLE_FL |
4514 +               EXT4_IUNLINK_FL | EXT4_BARRIER_FL);
4515 +
4516 +       if (IS_IMMUTABLE(inode))
4517 +               newflags |= EXT4_IMMUTABLE_FL;
4518 +       if (IS_IUNLINK(inode))
4519 +               newflags |= EXT4_IUNLINK_FL;
4520 +       if (IS_BARRIER(inode))
4521 +               newflags |= EXT4_BARRIER_FL;
4522 +
4523 +       if (oldflags ^ newflags) {
4524 +               handle_t *handle;
4525 +               struct ext4_iloc iloc;
4526 +
4527 +               handle = ext4_journal_start(inode, 1);
4528 +               if (IS_ERR(handle))
4529 +                       return PTR_ERR(handle);
4530 +               if (IS_SYNC(inode))
4531 +                       handle->h_sync = 1;
4532 +               err = ext4_reserve_inode_write(handle, inode, &iloc);
4533 +               if (err)
4534 +                       goto flags_err;
4535 +
4536 +               EXT4_I(inode)->i_flags = newflags;
4537 +               inode->i_ctime = CURRENT_TIME;
4538 +
4539 +               err = ext4_mark_iloc_dirty(handle, inode, &iloc);
4540 +       flags_err:
4541 +               ext4_journal_stop(handle);
4542 +       }
4543 +       return err;
4544 +}
4545 +
4546  void ext4_read_inode(struct inode * inode)
4547  {
4548         struct ext4_iloc iloc;
4549 @@ -2590,6 +2637,8 @@ void ext4_read_inode(struct inode * inod
4550         struct ext4_inode_info *ei = EXT4_I(inode);
4551         struct buffer_head *bh;
4552         int block;
4553 +       uid_t uid;
4554 +       gid_t gid;
4555  
4556  #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
4557         ei->i_acl = EXT4_ACL_NOT_CACHED;
4558 @@ -2602,12 +2651,17 @@ void ext4_read_inode(struct inode * inod
4559         bh = iloc.bh;
4560         raw_inode = ext4_raw_inode(&iloc);
4561         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4562 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4563 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4564 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4565 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4566         if(!(test_opt (inode->i_sb, NO_UID32))) {
4567 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4568 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4569 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4570 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4571         }
4572 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4573 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4574 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4575 +               le16_to_cpu(raw_inode->i_raw_tag));
4576 +
4577         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4578         inode->i_size = le32_to_cpu(raw_inode->i_size);
4579         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
4580 @@ -2737,6 +2791,8 @@ static int ext4_do_update_inode(handle_t
4581         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
4582         struct ext4_inode_info *ei = EXT4_I(inode);
4583         struct buffer_head *bh = iloc->bh;
4584 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4585 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4586         int err = 0, rc, block;
4587  
4588         /* For fields not not tracking in the in-memory inode,
4589 @@ -2746,29 +2802,32 @@ static int ext4_do_update_inode(handle_t
4590  
4591         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4592         if(!(test_opt(inode->i_sb, NO_UID32))) {
4593 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4594 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4595 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
4596 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
4597  /*
4598   * Fix up interoperability with old kernels. Otherwise, old inodes get
4599   * re-used with the upper 16 bits of the uid/gid intact
4600   */
4601                 if(!ei->i_dtime) {
4602                         raw_inode->i_uid_high =
4603 -                               cpu_to_le16(high_16_bits(inode->i_uid));
4604 +                               cpu_to_le16(high_16_bits(uid));
4605                         raw_inode->i_gid_high =
4606 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4607 +                               cpu_to_le16(high_16_bits(gid));
4608                 } else {
4609                         raw_inode->i_uid_high = 0;
4610                         raw_inode->i_gid_high = 0;
4611                 }
4612         } else {
4613                 raw_inode->i_uid_low =
4614 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4615 +                       cpu_to_le16(fs_high2lowuid(uid));
4616                 raw_inode->i_gid_low =
4617 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4618 +                       cpu_to_le16(fs_high2lowgid(gid));
4619                 raw_inode->i_uid_high = 0;
4620                 raw_inode->i_gid_high = 0;
4621         }
4622 +#ifdef CONFIG_TAGGING_INTERN
4623 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4624 +#endif
4625         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4626         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4627         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4628 @@ -2925,7 +2984,8 @@ int ext4_setattr(struct dentry *dentry, 
4629                 return error;
4630  
4631         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4632 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4633 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4634 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4635                 handle_t *handle;
4636  
4637                 /* (user+group)*(old+new) structure, inode write (sb,
4638 @@ -2947,6 +3007,8 @@ int ext4_setattr(struct dentry *dentry, 
4639                         inode->i_uid = attr->ia_uid;
4640                 if (attr->ia_valid & ATTR_GID)
4641                         inode->i_gid = attr->ia_gid;
4642 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4643 +                       inode->i_tag = attr->ia_tag;
4644                 error = ext4_mark_inode_dirty(handle, inode);
4645                 ext4_journal_stop(handle);
4646         }
4647 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/ioctl.c
4648 --- linux-2.6.22.10/fs/ext4/ioctl.c     2007-02-06 03:01:18 +0100
4649 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/ioctl.c  2007-08-05 20:53:12 +0200
4650 @@ -8,6 +8,7 @@
4651   */
4652  
4653  #include <linux/fs.h>
4654 +#include <linux/mount.h>
4655  #include <linux/jbd2.h>
4656  #include <linux/capability.h>
4657  #include <linux/ext4_fs.h>
4658 @@ -15,6 +16,7 @@
4659  #include <linux/time.h>
4660  #include <linux/compat.h>
4661  #include <linux/smp_lock.h>
4662 +#include <linux/vs_tag.h>
4663  #include <asm/uaccess.h>
4664  
4665  int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
4666 @@ -37,7 +39,8 @@ int ext4_ioctl (struct inode * inode, st
4667                 unsigned int oldflags;
4668                 unsigned int jflag;
4669  
4670 -               if (IS_RDONLY(inode))
4671 +               if (IS_RDONLY(inode) ||
4672 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4673                         return -EROFS;
4674  
4675                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4676 @@ -61,7 +64,9 @@ int ext4_ioctl (struct inode * inode, st
4677                  *
4678                  * This test looks nicer. Thanks to Pauline Middelink
4679                  */
4680 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
4681 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
4682 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
4683 +                       EXT4_IMMUTABLE_FL | EXT4_IUNLINK_FL))) {
4684                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4685                                 mutex_unlock(&inode->i_mutex);
4686                                 return -EPERM;
4687 @@ -123,7 +128,8 @@ flags_err:
4688  
4689                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4690                         return -EPERM;
4691 -               if (IS_RDONLY(inode))
4692 +               if (IS_RDONLY(inode) ||
4693 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4694                         return -EROFS;
4695                 if (get_user(generation, (int __user *) arg))
4696                         return -EFAULT;
4697 @@ -177,7 +183,8 @@ flags_err:
4698                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4699                         return -ENOTTY;
4700  
4701 -               if (IS_RDONLY(inode))
4702 +               if (IS_RDONLY(inode) ||
4703 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4704                         return -EROFS;
4705  
4706                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4707 @@ -212,7 +219,8 @@ flags_err:
4708                 if (!capable(CAP_SYS_RESOURCE))
4709                         return -EPERM;
4710  
4711 -               if (IS_RDONLY(inode))
4712 +               if (IS_RDONLY(inode) ||
4713 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4714                         return -EROFS;
4715  
4716                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4717 @@ -233,7 +241,8 @@ flags_err:
4718                 if (!capable(CAP_SYS_RESOURCE))
4719                         return -EPERM;
4720  
4721 -               if (IS_RDONLY(inode))
4722 +               if (IS_RDONLY(inode) ||
4723 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4724                         return -EROFS;
4725  
4726                 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
4727 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/namei.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/namei.c
4728 --- linux-2.6.22.10/fs/ext4/namei.c     2007-10-30 01:57:14 +0100
4729 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/namei.c  2007-09-30 14:58:01 +0200
4730 @@ -36,6 +36,7 @@
4731  #include <linux/quotaops.h>
4732  #include <linux/buffer_head.h>
4733  #include <linux/bio.h>
4734 +#include <linux/vs_tag.h>
4735  
4736  #include "namei.h"
4737  #include "xattr.h"
4738 @@ -1050,6 +1051,7 @@ static struct dentry *ext4_lookup(struct
4739  
4740                 if (!inode)
4741                         return ERR_PTR(-EACCES);
4742 +               dx_propagate_tag(nd, inode);
4743         }
4744         return d_splice_alias(inode, dentry);
4745  }
4746 @@ -2441,6 +2443,7 @@ const struct inode_operations ext4_dir_i
4747         .removexattr    = generic_removexattr,
4748  #endif
4749         .permission     = ext4_permission,
4750 +       .sync_flags     = ext4_sync_flags,
4751  };
4752  
4753  const struct inode_operations ext4_special_inode_operations = {
4754 @@ -2452,4 +2455,5 @@ const struct inode_operations ext4_speci
4755         .removexattr    = generic_removexattr,
4756  #endif
4757         .permission     = ext4_permission,
4758 +       .sync_flags     = ext4_sync_flags,
4759  };
4760 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/super.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/super.c
4761 --- linux-2.6.22.10/fs/ext4/super.c     2007-07-09 13:19:23 +0200
4762 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/super.c  2007-08-05 20:53:12 +0200
4763 @@ -725,7 +725,7 @@ enum {
4764         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4765         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4766         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4767 -       Opt_grpquota, Opt_extents,
4768 +       Opt_grpquota, Opt_extents, Opt_tag, Opt_notag, Opt_tagid
4769  };
4770  
4771  static match_table_t tokens = {
4772 @@ -776,6 +776,9 @@ static match_table_t tokens = {
4773         {Opt_usrquota, "usrquota"},
4774         {Opt_barrier, "barrier=%u"},
4775         {Opt_extents, "extents"},
4776 +       {Opt_tag, "tag"},
4777 +       {Opt_notag, "notag"},
4778 +       {Opt_tagid, "tagid=%u"},
4779         {Opt_err, NULL},
4780         {Opt_resize, "resize"},
4781  };
4782 @@ -869,6 +872,20 @@ static int parse_options (char *options,
4783                 case Opt_nouid32:
4784                         set_opt (sbi->s_mount_opt, NO_UID32);
4785                         break;
4786 +#ifndef CONFIG_TAGGING_NONE
4787 +               case Opt_tag:
4788 +                       set_opt (sbi->s_mount_opt, TAGGED);
4789 +                       break;
4790 +               case Opt_notag:
4791 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4792 +                       break;
4793 +#endif
4794 +#ifdef CONFIG_PROPAGATE
4795 +               case Opt_tagid:
4796 +                       /* use args[0] */
4797 +                       set_opt (sbi->s_mount_opt, TAGGED);
4798 +                       break;
4799 +#endif
4800                 case Opt_nocheck:
4801                         clear_opt (sbi->s_mount_opt, CHECK);
4802                         break;
4803 @@ -1546,6 +1563,9 @@ static int ext4_fill_super (struct super
4804                             NULL, 0))
4805                 goto failed_mount;
4806  
4807 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
4808 +               sb->s_flags |= MS_TAGGED;
4809 +
4810         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4811                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4812  
4813 @@ -2377,6 +2397,12 @@ static int ext4_remount (struct super_bl
4814  
4815         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
4816                 ext4_abort(sb, __FUNCTION__, "Abort forced by user");
4817 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
4818 +               !(sb->s_flags & MS_TAGGED)) {
4819 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
4820 +                       sb->s_id);
4821 +               return -EINVAL;
4822 +       }
4823  
4824         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4825                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4826 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/symlink.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/symlink.c
4827 --- linux-2.6.22.10/fs/ext4/symlink.c   2007-05-02 19:25:17 +0200
4828 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/symlink.c        2007-08-05 20:53:12 +0200
4829 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
4830         .listxattr      = ext4_listxattr,
4831         .removexattr    = generic_removexattr,
4832  #endif
4833 +       .sync_flags     = ext4_sync_flags,
4834  };
4835  
4836  const struct inode_operations ext4_fast_symlink_inode_operations = {
4837 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
4838         .listxattr      = ext4_listxattr,
4839         .removexattr    = generic_removexattr,
4840  #endif
4841 +       .sync_flags     = ext4_sync_flags,
4842  };
4843 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/xattr.c linux-2.6.22.10-vs2.3.0.29/fs/ext4/xattr.c
4844 --- linux-2.6.22.10/fs/ext4/xattr.c     2007-05-02 19:25:17 +0200
4845 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/xattr.c  2007-08-05 20:53:12 +0200
4846 @@ -58,6 +58,7 @@
4847  #include <linux/mbcache.h>
4848  #include <linux/quotaops.h>
4849  #include <linux/rwsem.h>
4850 +#include <linux/vs_dlimit.h>
4851  #include "xattr.h"
4852  #include "acl.h"
4853  
4854 @@ -496,6 +497,7 @@ ext4_xattr_release_block(handle_t *handl
4855                 error = ext4_journal_dirty_metadata(handle, bh);
4856                 if (IS_SYNC(inode))
4857                         handle->h_sync = 1;
4858 +                       DLIMIT_FREE_BLOCK(inode, 1);
4859                 DQUOT_FREE_BLOCK(inode, 1);
4860                 ea_bdebug(bh, "refcount now=%d; releasing",
4861                           le32_to_cpu(BHDR(bh)->h_refcount));
4862 @@ -769,11 +771,14 @@ inserted:
4863                         if (new_bh == bs->bh)
4864                                 ea_bdebug(new_bh, "keeping");
4865                         else {
4866 +                               error = -ENOSPC;
4867 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4868 +                                       goto cleanup;
4869                                 /* The old block is released after updating
4870                                    the inode. */
4871                                 error = -EDQUOT;
4872                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4873 -                                       goto cleanup;
4874 +                                       goto cleanup_dlimit;
4875                                 error = ext4_journal_get_write_access(handle,
4876                                                                       new_bh);
4877                                 if (error)
4878 @@ -850,6 +855,8 @@ cleanup:
4879  
4880  cleanup_dquot:
4881         DQUOT_FREE_BLOCK(inode, 1);
4882 +cleanup_dlimit:
4883 +       DLIMIT_FREE_BLOCK(inode, 1);
4884         goto cleanup;
4885  
4886  bad_block:
4887 diff -NurpP --minimal linux-2.6.22.10/fs/fcntl.c linux-2.6.22.10-vs2.3.0.29/fs/fcntl.c
4888 --- linux-2.6.22.10/fs/fcntl.c  2007-02-06 03:01:18 +0100
4889 +++ linux-2.6.22.10-vs2.3.0.29/fs/fcntl.c       2007-08-05 20:53:12 +0200
4890 @@ -18,6 +18,7 @@
4891  #include <linux/ptrace.h>
4892  #include <linux/signal.h>
4893  #include <linux/rcupdate.h>
4894 +#include <linux/vs_limit.h>
4895  
4896  #include <asm/poll.h>
4897  #include <asm/siginfo.h>
4898 @@ -84,6 +85,8 @@ repeat:
4899         error = -EMFILE;
4900         if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
4901                 goto out;
4902 +       if (!vx_files_avail(1))
4903 +               goto out;
4904  
4905         error = expand_files(files, newfd);
4906         if (error < 0)
4907 @@ -124,6 +127,7 @@ static int dupfd(struct file *file, unsi
4908                 FD_SET(fd, fdt->open_fds);
4909                 FD_CLR(fd, fdt->close_on_exec);
4910                 spin_unlock(&files->file_lock);
4911 +               vx_openfd_inc(fd);
4912                 fd_install(fd, file);
4913         } else {
4914                 spin_unlock(&files->file_lock);
4915 @@ -176,6 +180,9 @@ asmlinkage long sys_dup2(unsigned int ol
4916  
4917         if (tofree)
4918                 filp_close(tofree, files);
4919 +       else
4920 +               vx_openfd_inc(newfd);   /* fd was unused */
4921 +
4922         err = newfd;
4923  out:
4924         return err;
4925 diff -NurpP --minimal linux-2.6.22.10/fs/file_table.c linux-2.6.22.10-vs2.3.0.29/fs/file_table.c
4926 --- linux-2.6.22.10/fs/file_table.c     2007-07-09 13:19:23 +0200
4927 +++ linux-2.6.22.10-vs2.3.0.29/fs/file_table.c  2007-08-05 20:53:12 +0200
4928 @@ -20,6 +20,8 @@
4929  #include <linux/fsnotify.h>
4930  #include <linux/sysctl.h>
4931  #include <linux/percpu_counter.h>
4932 +#include <linux/vs_limit.h>
4933 +#include <linux/vs_context.h>
4934  
4935  #include <asm/atomic.h>
4936  
4937 @@ -119,6 +121,8 @@ struct file *get_empty_filp(void)
4938         f->f_gid = tsk->fsgid;
4939         eventpoll_init_file(f);
4940         /* f->f_version: 0 */
4941 +       f->f_xid = vx_current_xid();
4942 +       vx_files_inc(f);
4943         return f;
4944  
4945  over:
4946 @@ -174,6 +178,8 @@ void fastcall __fput(struct file *file)
4947         if (file->f_mode & FMODE_WRITE)
4948                 put_write_access(inode);
4949         put_pid(file->f_owner.pid);
4950 +       vx_files_dec(file);
4951 +       file->f_xid = 0;
4952         file_kill(file);
4953         file->f_path.dentry = NULL;
4954         file->f_path.mnt = NULL;
4955 @@ -239,6 +245,8 @@ void put_filp(struct file *file)
4956  {
4957         if (atomic_dec_and_test(&file->f_count)) {
4958                 security_file_free(file);
4959 +               vx_files_dec(file);
4960 +               file->f_xid = 0;
4961                 file_kill(file);
4962                 file_free(file);
4963         }
4964 diff -NurpP --minimal linux-2.6.22.10/fs/hfsplus/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/hfsplus/ioctl.c
4965 --- linux-2.6.22.10/fs/hfsplus/ioctl.c  2006-11-30 21:19:25 +0100
4966 +++ linux-2.6.22.10-vs2.3.0.29/fs/hfsplus/ioctl.c       2007-08-05 20:53:12 +0200
4967 @@ -16,6 +16,7 @@
4968  #include <linux/fs.h>
4969  #include <linux/sched.h>
4970  #include <linux/xattr.h>
4971 +#include <linux/mount.h>
4972  #include <asm/uaccess.h>
4973  #include "hfsplus_fs.h"
4974  
4975 @@ -35,7 +36,8 @@ int hfsplus_ioctl(struct inode *inode, s
4976                         flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
4977                 return put_user(flags, (int __user *)arg);
4978         case HFSPLUS_IOC_EXT2_SETFLAGS: {
4979 -               if (IS_RDONLY(inode))
4980 +               if (IS_RDONLY(inode) ||
4981 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4982                         return -EROFS;
4983  
4984                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4985 diff -NurpP --minimal linux-2.6.22.10/fs/inode.c linux-2.6.22.10-vs2.3.0.29/fs/inode.c
4986 --- linux-2.6.22.10/fs/inode.c  2007-07-09 13:19:24 +0200
4987 +++ linux-2.6.22.10-vs2.3.0.29/fs/inode.c       2007-10-11 01:10:22 +0200
4988 @@ -115,6 +115,9 @@ static struct inode *alloc_inode(struct 
4989                 struct address_space * const mapping = &inode->i_data;
4990  
4991                 inode->i_sb = sb;
4992 +
4993 +               /* essential because of inode slab reuse */
4994 +               inode->i_tag = 0;
4995                 inode->i_blkbits = sb->s_blocksize_bits;
4996                 inode->i_flags = 0;
4997                 atomic_set(&inode->i_count, 1);
4998 @@ -133,6 +136,7 @@ static struct inode *alloc_inode(struct 
4999                 inode->i_bdev = NULL;
5000                 inode->i_cdev = NULL;
5001                 inode->i_rdev = 0;
5002 +               inode->i_mdev = 0;
5003                 inode->dirtied_when = 0;
5004                 if (security_inode_alloc(inode)) {
5005                         if (inode->i_sb->s_op->destroy_inode)
5006 @@ -231,6 +235,8 @@ void __iget(struct inode * inode)
5007         inodes_stat.nr_unused--;
5008  }
5009  
5010 +EXPORT_SYMBOL_GPL(__iget);
5011 +
5012  /**
5013   * clear_inode - clear an inode
5014   * @inode: inode to clear
5015 @@ -1405,9 +1411,11 @@ void init_special_inode(struct inode *in
5016         if (S_ISCHR(mode)) {
5017                 inode->i_fop = &def_chr_fops;
5018                 inode->i_rdev = rdev;
5019 +               inode->i_mdev = rdev;
5020         } else if (S_ISBLK(mode)) {
5021                 inode->i_fop = &def_blk_fops;
5022                 inode->i_rdev = rdev;
5023 +               inode->i_mdev = rdev;
5024         } else if (S_ISFIFO(mode))
5025                 inode->i_fop = &def_fifo_fops;
5026         else if (S_ISSOCK(mode))
5027 diff -NurpP --minimal linux-2.6.22.10/fs/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/ioctl.c
5028 --- linux-2.6.22.10/fs/ioctl.c  2007-07-09 13:19:24 +0200
5029 +++ linux-2.6.22.10-vs2.3.0.29/fs/ioctl.c       2007-08-05 20:53:12 +0200
5030 @@ -13,6 +13,9 @@
5031  #include <linux/security.h>
5032  #include <linux/module.h>
5033  #include <linux/kallsyms.h>
5034 +#include <linux/proc_fs.h>
5035 +#include <linux/vserver/inode.h>
5036 +#include <linux/vs_tag.h>
5037  
5038  #include <asm/uaccess.h>
5039  #include <asm/ioctls.h>
5040 diff -NurpP --minimal linux-2.6.22.10/fs/ioprio.c linux-2.6.22.10-vs2.3.0.29/fs/ioprio.c
5041 --- linux-2.6.22.10/fs/ioprio.c 2007-05-02 19:25:18 +0200
5042 +++ linux-2.6.22.10-vs2.3.0.29/fs/ioprio.c      2007-08-05 20:53:12 +0200
5043 @@ -25,6 +25,7 @@
5044  #include <linux/capability.h>
5045  #include <linux/syscalls.h>
5046  #include <linux/security.h>
5047 +#include <linux/vs_base.h>
5048  
5049  static int set_task_ioprio(struct task_struct *task, int ioprio)
5050  {
5051 @@ -103,6 +104,8 @@ asmlinkage long sys_ioprio_set(int which
5052                         else
5053                                 pgrp = find_pid(who);
5054                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
5055 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5056 +                                       continue;
5057                                 ret = set_task_ioprio(p, ioprio);
5058                                 if (ret)
5059                                         break;
5060 @@ -112,7 +115,7 @@ asmlinkage long sys_ioprio_set(int which
5061                         if (!who)
5062                                 user = current->user;
5063                         else
5064 -                               user = find_user(who);
5065 +                               user = find_user(vx_current_xid(), who);
5066  
5067                         if (!user)
5068                                 break;
5069 @@ -190,6 +193,8 @@ asmlinkage long sys_ioprio_get(int which
5070                         else
5071                                 pgrp = find_pid(who);
5072                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
5073 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5074 +                                       continue;
5075                                 tmpio = get_task_ioprio(p);
5076                                 if (tmpio < 0)
5077                                         continue;
5078 @@ -203,7 +208,7 @@ asmlinkage long sys_ioprio_get(int which
5079                         if (!who)
5080                                 user = current->user;
5081                         else
5082 -                               user = find_user(who);
5083 +                               user = find_user(vx_current_xid(), who);
5084  
5085                         if (!user)
5086                                 break;
5087 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/dir.c linux-2.6.22.10-vs2.3.0.29/fs/jffs2/dir.c
5088 --- linux-2.6.22.10/fs/jffs2/dir.c      2007-07-09 13:19:26 +0200
5089 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/dir.c   2007-10-05 15:07:22 +0200
5090 @@ -32,7 +32,9 @@ static int jffs2_mkdir (struct inode *,s
5091  static int jffs2_rmdir (struct inode *,struct dentry *);
5092  static int jffs2_mknod (struct inode *,struct dentry *,int,dev_t);
5093  static int jffs2_rename (struct inode *, struct dentry *,
5094 -                        struct inode *, struct dentry *);
5095 +                        struct inode *, struct dentry *);
5096 +
5097 +extern int jffs2_sync_flags(struct inode *);
5098  
5099  const struct file_operations jffs2_dir_operations =
5100  {
5101 @@ -56,6 +58,7 @@ const struct inode_operations jffs2_dir_
5102         .rename =       jffs2_rename,
5103         .permission =   jffs2_permission,
5104         .setattr =      jffs2_setattr,
5105 +       .sync_flags =   jffs2_sync_flags,
5106         .setxattr =     jffs2_setxattr,
5107         .getxattr =     jffs2_getxattr,
5108         .listxattr =    jffs2_listxattr,
5109 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/file.c linux-2.6.22.10-vs2.3.0.29/fs/jffs2/file.c
5110 --- linux-2.6.22.10/fs/jffs2/file.c     2007-07-09 13:19:26 +0200
5111 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/file.c  2007-10-01 20:52:25 +0200
5112 @@ -17,6 +17,7 @@
5113  #include <linux/highmem.h>
5114  #include <linux/crc32.h>
5115  #include <linux/jffs2.h>
5116 +#include <linux/vs_tag.h>
5117  #include "nodelist.h"
5118  
5119  static int jffs2_commit_write (struct file *filp, struct page *pg,
5120 @@ -25,6 +26,9 @@ static int jffs2_prepare_write (struct f
5121                                 unsigned start, unsigned end);
5122  static int jffs2_readpage (struct file *filp, struct page *pg);
5123  
5124 +extern int jffs2_sync_flags(struct inode *);
5125 +
5126 +
5127  int jffs2_fsync(struct file *filp, struct dentry *dentry, int datasync)
5128  {
5129         struct inode *inode = dentry->d_inode;
5130 @@ -47,7 +51,9 @@ const struct file_operations jffs2_file_
5131         .ioctl =        jffs2_ioctl,
5132         .mmap =         generic_file_readonly_mmap,
5133         .fsync =        jffs2_fsync,
5134 -       .sendfile =     generic_file_sendfile
5135 +       .sendfile =     generic_file_sendfile,
5136 +       .splice_read =  generic_file_splice_read,
5137 +       .splice_write = generic_file_splice_write
5138  };
5139  
5140  /* jffs2_file_inode_operations */
5141 @@ -56,6 +62,7 @@ const struct inode_operations jffs2_file
5142  {
5143         .permission =   jffs2_permission,
5144         .setattr =      jffs2_setattr,
5145 +       .sync_flags =   jffs2_sync_flags,
5146         .setxattr =     jffs2_setxattr,
5147         .getxattr =     jffs2_getxattr,
5148         .listxattr =    jffs2_listxattr,
5149 @@ -157,12 +164,14 @@ static int jffs2_prepare_write (struct f
5150                 ri.mode = cpu_to_jemode(inode->i_mode);
5151                 ri.uid = cpu_to_je16(inode->i_uid);
5152                 ri.gid = cpu_to_je16(inode->i_gid);
5153 +               ri.tag = cpu_to_je16(TAGINO_TAG(DX_TAG(inode), inode->i_tag));
5154                 ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs));
5155                 ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds());
5156                 ri.offset = cpu_to_je32(inode->i_size);
5157                 ri.dsize = cpu_to_je32(pageofs - inode->i_size);
5158                 ri.csize = cpu_to_je32(0);
5159                 ri.compr = JFFS2_COMPR_ZERO;
5160 +               ri.flags = cpu_to_je16(f->flags);
5161                 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
5162                 ri.data_crc = cpu_to_je32(0);
5163  
5164 @@ -248,8 +257,10 @@ static int jffs2_commit_write (struct fi
5165         ri->mode = cpu_to_jemode(inode->i_mode);
5166         ri->uid = cpu_to_je16(inode->i_uid);
5167         ri->gid = cpu_to_je16(inode->i_gid);
5168 +       ri->tag = cpu_to_je16(TAGINO_TAG(DX_TAG(inode), inode->i_tag));
5169         ri->isize = cpu_to_je32((uint32_t)inode->i_size);
5170         ri->atime = ri->ctime = ri->mtime = cpu_to_je32(get_seconds());
5171 +       ri->flags = cpu_to_je16(f->flags);
5172  
5173         /* In 2.4, it was already kmapped by generic_file_write(). Doesn't
5174            hurt to do it again. The alternative is ifdefs, which are ugly. */
5175 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/fs.c linux-2.6.22.10-vs2.3.0.29/fs/jffs2/fs.c
5176 --- linux-2.6.22.10/fs/jffs2/fs.c       2007-10-30 01:57:14 +0100
5177 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/fs.c    2007-09-30 14:58:01 +0200
5178 @@ -20,6 +20,7 @@
5179  #include <linux/vmalloc.h>
5180  #include <linux/vfs.h>
5181  #include <linux/crc32.h>
5182 +#include <linux/vs_tag.h>
5183  #include "nodelist.h"
5184  
5185  static int jffs2_flash_setup(struct jffs2_sb_info *c);
5186 @@ -97,6 +98,7 @@ static int jffs2_do_setattr (struct inod
5187  
5188         ri->uid = cpu_to_je16((ivalid & ATTR_UID)?iattr->ia_uid:inode->i_uid);
5189         ri->gid = cpu_to_je16((ivalid & ATTR_GID)?iattr->ia_gid:inode->i_gid);
5190 +       ri->tag = cpu_to_je16((ivalid & ATTR_TAG)?iattr->ia_tag:inode->i_tag);
5191  
5192         if (ivalid & ATTR_MODE)
5193                 if (iattr->ia_mode & S_ISGID &&
5194 @@ -116,6 +118,8 @@ static int jffs2_do_setattr (struct inod
5195         ri->offset = cpu_to_je32(0);
5196         ri->csize = ri->dsize = cpu_to_je32(mdatalen);
5197         ri->compr = JFFS2_COMPR_NONE;
5198 +       ri->flags = cpu_to_je16(f->flags);
5199 +
5200         if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) {
5201                 /* It's an extension. Make it a hole node */
5202                 ri->compr = JFFS2_COMPR_ZERO;
5203 @@ -145,6 +149,7 @@ static int jffs2_do_setattr (struct inod
5204         inode->i_mode = jemode_to_cpu(ri->mode);
5205         inode->i_uid = je16_to_cpu(ri->uid);
5206         inode->i_gid = je16_to_cpu(ri->gid);
5207 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0, je16_to_cpu(ri->tag));
5208  
5209  
5210         old_metadata = f->metadata;
5211 @@ -179,6 +184,48 @@ static int jffs2_do_setattr (struct inod
5212         return 0;
5213  }
5214  
5215 +void jffs2_set_inode_flags(struct inode *inode)
5216 +{
5217 +       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
5218 +       unsigned int flags = f->flags;
5219 +
5220 +       inode->i_flags &= ~(JFFS2_INO_FLAG_IMMUTABLE |
5221 +               JFFS2_INO_FLAG_IUNLINK | JFFS2_INO_FLAG_BARRIER);
5222 +
5223 +       if (flags & JFFS2_INO_FLAG_IMMUTABLE)
5224 +               inode->i_flags |= S_IMMUTABLE;
5225 +       if (flags & JFFS2_INO_FLAG_IUNLINK)
5226 +               inode->i_flags |= S_IUNLINK;
5227 +       if (flags & JFFS2_INO_FLAG_BARRIER)
5228 +               inode->i_flags |= S_BARRIER;
5229 +}
5230 +
5231 +int jffs2_sync_flags(struct inode *inode)
5232 +{
5233 +       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
5234 +       unsigned int oldflags, newflags;
5235 +
5236 +       oldflags = f->flags;
5237 +       newflags = oldflags & ~(JFFS2_INO_FLAG_IMMUTABLE |
5238 +               JFFS2_INO_FLAG_IUNLINK | JFFS2_INO_FLAG_BARRIER);
5239 +
5240 +       if (IS_IMMUTABLE(inode))
5241 +               newflags |= JFFS2_INO_FLAG_IMMUTABLE;
5242 +       if (IS_IUNLINK(inode))
5243 +               newflags |= JFFS2_INO_FLAG_IUNLINK;
5244 +       if (IS_BARRIER(inode))
5245 +               newflags |= JFFS2_INO_FLAG_BARRIER;
5246 +
5247 +       if (oldflags ^ newflags) {
5248 +               f->flags = newflags;
5249 +               inode->i_ctime = CURRENT_TIME;
5250 +               /* strange requirement, see jffs2_dirty_inode() */
5251 +               inode->i_state |= I_DIRTY_DATASYNC;
5252 +               mark_inode_dirty(inode);
5253 +       }
5254 +       return 0;
5255 +}
5256 +
5257  int jffs2_setattr(struct dentry *dentry, struct iattr *iattr)
5258  {
5259         int rc;
5260 @@ -254,6 +301,8 @@ void jffs2_read_inode (struct inode *ino
5261         inode->i_mode = jemode_to_cpu(latest_node.mode);
5262         inode->i_uid = je16_to_cpu(latest_node.uid);
5263         inode->i_gid = je16_to_cpu(latest_node.gid);
5264 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0,
5265 +               je16_to_cpu(latest_node.tag));
5266         inode->i_size = je32_to_cpu(latest_node.isize);
5267         inode->i_atime = ITIME(je32_to_cpu(latest_node.atime));
5268         inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime));
5269 @@ -285,6 +334,7 @@ void jffs2_read_inode (struct inode *ino
5270  
5271                 inode->i_op = &jffs2_dir_inode_operations;
5272                 inode->i_fop = &jffs2_dir_operations;
5273 +               f->flags = je16_to_cpu(latest_node.flags);
5274                 break;
5275         }
5276         case S_IFREG:
5277 @@ -292,6 +342,7 @@ void jffs2_read_inode (struct inode *ino
5278                 inode->i_fop = &jffs2_file_operations;
5279                 inode->i_mapping->a_ops = &jffs2_file_address_operations;
5280                 inode->i_mapping->nrpages = 0;
5281 +               f->flags = je16_to_cpu(latest_node.flags);
5282                 break;
5283  
5284         case S_IFBLK:
5285 @@ -328,7 +379,7 @@ void jffs2_read_inode (struct inode *ino
5286         default:
5287                 printk(KERN_WARNING "jffs2_read_inode(): Bogus imode %o for ino %lu\n", inode->i_mode, (unsigned long)inode->i_ino);
5288         }
5289 -
5290 +       jffs2_set_inode_flags(inode);
5291         up(&f->sem);
5292  
5293         D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n"));
5294 @@ -345,10 +396,11 @@ void jffs2_dirty_inode(struct inode *ino
5295  
5296         D1(printk(KERN_DEBUG "jffs2_dirty_inode() calling setattr() for ino #%lu\n", inode->i_ino));
5297  
5298 -       iattr.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_MTIME|ATTR_CTIME;
5299 +       iattr.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_TAG;
5300         iattr.ia_mode = inode->i_mode;
5301         iattr.ia_uid = inode->i_uid;
5302         iattr.ia_gid = inode->i_gid;
5303 +       iattr.ia_tag = inode->i_tag;
5304         iattr.ia_atime = inode->i_atime;
5305         iattr.ia_mtime = inode->i_mtime;
5306         iattr.ia_ctime = inode->i_ctime;
5307 @@ -422,6 +474,7 @@ struct inode *jffs2_new_inode (struct in
5308  
5309         memset(ri, 0, sizeof(*ri));
5310         /* Set OS-specific defaults for new inodes */
5311 +       ri->tag = cpu_to_je16(dx_current_tag());
5312         ri->uid = cpu_to_je16(current->fsuid);
5313  
5314         if (dir_i->i_mode & S_ISGID) {
5315 @@ -443,14 +496,16 @@ struct inode *jffs2_new_inode (struct in
5316         inode->i_mode = jemode_to_cpu(ri->mode);
5317         inode->i_gid = je16_to_cpu(ri->gid);
5318         inode->i_uid = je16_to_cpu(ri->uid);
5319 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0, je16_to_cpu(ri->tag));
5320         inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
5321         ri->atime = ri->mtime = ri->ctime = cpu_to_je32(I_SEC(inode->i_mtime));
5322  
5323         inode->i_blocks = 0;
5324         inode->i_size = 0;
5325  
5326 +       f->flags = je16_to_cpu(ri->flags);
5327 +       jffs2_set_inode_flags(inode);
5328         insert_inode_hash(inode);
5329 -
5330         return inode;
5331  }
5332  
5333 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/gc.c linux-2.6.22.10-vs2.3.0.29/fs/jffs2/gc.c
5334 --- linux-2.6.22.10/fs/jffs2/gc.c       2007-07-09 13:19:26 +0200
5335 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/gc.c    2007-08-05 20:53:12 +0200
5336 @@ -735,6 +735,7 @@ static int jffs2_garbage_collect_metadat
5337         ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5338         ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5339         ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5340 +       ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5341         ri.isize = cpu_to_je32(ilen);
5342         ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5343         ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5344 @@ -998,6 +999,7 @@ static int jffs2_garbage_collect_hole(st
5345         ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5346         ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5347         ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5348 +       ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5349         ri.isize = cpu_to_je32(ilen);
5350         ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5351         ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5352 @@ -1256,6 +1258,7 @@ static int jffs2_garbage_collect_dnode(s
5353                 ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5354                 ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5355                 ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5356 +               ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5357                 ri.isize = cpu_to_je32(JFFS2_F_I_SIZE(f));
5358                 ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5359                 ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5360 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/jffs2/ioctl.c
5361 --- linux-2.6.22.10/fs/jffs2/ioctl.c    2007-07-09 13:19:26 +0200
5362 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/ioctl.c 2007-08-05 20:53:12 +0200
5363 @@ -10,12 +10,67 @@
5364   */
5365  
5366  #include <linux/fs.h>
5367 +#include <linux/types.h>
5368 +#include <linux/mount.h>
5369 +#include <linux/jffs2.h>
5370 +#include <linux/uaccess.h>
5371 +#include <linux/vs_base.h>
5372 +#include "jffs2_fs_sb.h"
5373 +#include "jffs2_fs_i.h"
5374 +#include "acl.h"
5375 +#include "os-linux.h"
5376 +
5377 +extern void jffs2_set_inode_flags(struct inode *);
5378  
5379  int jffs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
5380                 unsigned long arg)
5381  {
5382 -       /* Later, this will provide for lsattr.jffs2 and chattr.jffs2, which
5383 -          will include compression support etc. */
5384 -       return -ENOTTY;
5385 +       struct jffs2_inode_info *j = JFFS2_INODE_INFO(inode);
5386 +       unsigned int flags, oldflags, newflags;
5387 +
5388 +       switch (cmd) {
5389 +       case JFFS2_IOC_GETFLAGS:
5390 +               flags = j->flags & JFFS2_USER_VISIBLE;
5391 +               return put_user(flags, (int __user *) arg);
5392 +
5393 +       case JFFS2_IOC_SETFLAGS:
5394 +               if (IS_RDONLY(inode) ||
5395 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
5396 +                       return -EROFS;
5397 +
5398 +               if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
5399 +                       return -EACCES;
5400 +
5401 +               if (get_user(flags, (int __user *) arg))
5402 +                       return -EFAULT;
5403 +
5404 +               oldflags = j->flags;
5405 +               newflags = flags & JFFS2_USER_MODIFIABLE;
5406 +               newflags |= oldflags & ~JFFS2_USER_MODIFIABLE;
5407 +
5408 +               /*
5409 +                * The IMMUTABLE flags can only be changed by
5410 +                * the relevant capability.
5411 +                */
5412 +               if (((oldflags ^ newflags) &
5413 +                       (JFFS2_INO_FLAG_IMMUTABLE | JFFS2_INO_FLAG_IUNLINK)) ||
5414 +                       (oldflags & JFFS2_INO_FLAG_IMMUTABLE)) {
5415 +                       if (!capable(CAP_LINUX_IMMUTABLE))
5416 +                               return -EPERM;
5417 +               }
5418 +
5419 +               if (oldflags ^ newflags) {
5420 +                       j->flags = newflags;
5421 +                       inode->i_ctime = CURRENT_TIME;
5422 +                       /* strange requirement, see jffs2_dirty_inode() */
5423 +                       inode->i_state |= I_DIRTY_DATASYNC;
5424 +                       mark_inode_dirty(inode);
5425 +                       jffs2_set_inode_flags(inode);
5426 +               }
5427 +               return 0;
5428 +
5429 +       default:
5430 +               return -ENOTTY;
5431 +       }
5432  }
5433  
5434 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/jffs2_fs_sb.h linux-2.6.22.10-vs2.3.0.29/fs/jffs2/jffs2_fs_sb.h
5435 --- linux-2.6.22.10/fs/jffs2/jffs2_fs_sb.h      2007-07-09 13:19:26 +0200
5436 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/jffs2_fs_sb.h   2007-08-05 20:53:12 +0200
5437 @@ -39,6 +39,7 @@ struct jffs2_sb_info {
5438         uint32_t checked_ino;
5439  
5440         unsigned int flags;
5441 +       unsigned int s_mount_opt;
5442  
5443         struct task_struct *gc_task;    /* GC task struct */
5444         struct completion gc_thread_start; /* GC thread start completion */
5445 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/nodelist.h linux-2.6.22.10-vs2.3.0.29/fs/jffs2/nodelist.h
5446 --- linux-2.6.22.10/fs/jffs2/nodelist.h 2007-07-09 13:19:26 +0200
5447 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/nodelist.h      2007-08-05 20:53:12 +0200
5448 @@ -47,25 +47,25 @@
5449  #elif defined(JFFS2_BIG_ENDIAN)
5450  #define cpu_to_je16(x) ((jint16_t){cpu_to_be16(x)})
5451  #define cpu_to_je32(x) ((jint32_t){cpu_to_be32(x)})
5452 -#define cpu_to_jemode(x) ((jmode_t){cpu_to_be32(os_to_jffs2_mode(x))})
5453 +#define cpu_to_jemode(x) ((jmode_t){cpu_to_be16(os_to_jffs2_mode(x))})
5454  
5455  #define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_be16(x)})
5456  #define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_be32(x)})
5457  
5458  #define je16_to_cpu(x) (be16_to_cpu(x.v16))
5459  #define je32_to_cpu(x) (be32_to_cpu(x.v32))
5460 -#define jemode_to_cpu(x) (be32_to_cpu(jffs2_to_os_mode((x).m)))
5461 +#define jemode_to_cpu(x) (be16_to_cpu(jffs2_to_os_mode((x).m)))
5462  #elif defined(JFFS2_LITTLE_ENDIAN)
5463  #define cpu_to_je16(x) ((jint16_t){cpu_to_le16(x)})
5464  #define cpu_to_je32(x) ((jint32_t){cpu_to_le32(x)})
5465 -#define cpu_to_jemode(x) ((jmode_t){cpu_to_le32(os_to_jffs2_mode(x))})
5466 +#define cpu_to_jemode(x) ((jmode_t){cpu_to_le16(os_to_jffs2_mode(x))})
5467  
5468  #define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_le16(x)})
5469  #define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_le32(x)})
5470  
5471  #define je16_to_cpu(x) (le16_to_cpu(x.v16))
5472  #define je32_to_cpu(x) (le32_to_cpu(x.v32))
5473 -#define jemode_to_cpu(x) (le32_to_cpu(jffs2_to_os_mode((x).m)))
5474 +#define jemode_to_cpu(x) (le16_to_cpu(jffs2_to_os_mode((x).m)))
5475  #else
5476  #error wibble
5477  #endif
5478 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/os-linux.h linux-2.6.22.10-vs2.3.0.29/fs/jffs2/os-linux.h
5479 --- linux-2.6.22.10/fs/jffs2/os-linux.h 2007-07-09 13:19:26 +0200
5480 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/os-linux.h      2007-08-05 20:53:12 +0200
5481 @@ -29,6 +29,7 @@ struct kvec;
5482  #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
5483  #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
5484  #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
5485 +#define JFFS2_F_I_TAG(f) (OFNI_EDONI_2SFFJ(f)->i_tag)
5486  #define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev)
5487  
5488  #define ITIME(sec) ((struct timespec){sec, 0})
5489 @@ -204,6 +205,9 @@ int jffs2_flash_direct_writev(struct jff
5490  int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
5491                         size_t *retlen, const u_char *buf);
5492  
5493 +#define JFFS2_IOC_GETFLAGS             FS_IOC_GETFLAGS
5494 +#define JFFS2_IOC_SETFLAGS             FS_IOC_SETFLAGS
5495 +
5496  #endif /* __JFFS2_OS_LINUX_H__ */
5497  
5498  
5499 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/readinode.c linux-2.6.22.10-vs2.3.0.29/fs/jffs2/readinode.c
5500 --- linux-2.6.22.10/fs/jffs2/readinode.c        2007-07-09 13:19:26 +0200
5501 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/readinode.c     2007-08-05 20:53:12 +0200
5502 @@ -1182,6 +1182,8 @@ static int jffs2_do_read_inode_internal(
5503                 latest_node->isize = cpu_to_je32(0);
5504                 latest_node->gid = cpu_to_je16(0);
5505                 latest_node->uid = cpu_to_je16(0);
5506 +               latest_node->tag = cpu_to_je16(0);
5507 +               latest_node->flags = cpu_to_je16(0);
5508                 if (f->inocache->state == INO_STATE_READING)
5509                         jffs2_set_inocache_state(c, f->inocache, INO_STATE_PRESENT);
5510                 return 0;
5511 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/super.c linux-2.6.22.10-vs2.3.0.29/fs/jffs2/super.c
5512 --- linux-2.6.22.10/fs/jffs2/super.c    2007-07-09 13:19:26 +0200
5513 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/super.c 2007-08-05 20:53:12 +0200
5514 @@ -22,6 +22,7 @@
5515  #include <linux/mtd/super.h>
5516  #include <linux/ctype.h>
5517  #include <linux/namei.h>
5518 +#include <linux/parser.h>
5519  #include "compr.h"
5520  #include "nodelist.h"
5521  
5522 @@ -75,6 +76,49 @@ static const struct super_operations jff
5523         .sync_fs =      jffs2_sync_fs,
5524  };
5525  
5526 +enum {
5527 +       Opt_tag, Opt_notag, Opt_ignore, Opt_err
5528 +};
5529 +
5530 +static match_table_t tokens = {
5531 +       {Opt_tag, "tag"},
5532 +       {Opt_notag, "notag"},
5533 +       {Opt_err, NULL}
5534 +};
5535 +
5536 +static int parse_options (char * options,
5537 +                         struct jffs2_sb_info *sbi)
5538 +{
5539 +       char * p;
5540 +       substring_t args[MAX_OPT_ARGS];
5541 +
5542 +       if (!options)
5543 +               return 1;
5544 +
5545 +       while ((p = strsep (&options, ",")) != NULL) {
5546 +               int token;
5547 +               if (!*p)
5548 +                       continue;
5549 +
5550 +               token = match_token(p, tokens, args);
5551 +               switch (token) {
5552 +#ifndef CONFIG_TAGGING_NONE
5553 +               case Opt_tag:
5554 +                       set_opt (sbi->s_mount_opt, TAGGED);
5555 +                       break;
5556 +               case Opt_notag:
5557 +                       clear_opt (sbi->s_mount_opt, TAGGED);
5558 +                       break;
5559 +#endif
5560 +               case Opt_ignore:
5561 +                       break;
5562 +               default:
5563 +                       return 0;
5564 +               }
5565 +       }
5566 +       return 1;
5567 +}
5568 +
5569  /*
5570   * fill in the superblock
5571   */
5572 @@ -109,6 +153,12 @@ static int jffs2_fill_super(struct super
5573  #ifdef CONFIG_JFFS2_FS_POSIX_ACL
5574         sb->s_flags |= MS_POSIXACL;
5575  #endif
5576 +       if (!parse_options ((char *) data, c))
5577 +               return -EINVAL;
5578 +
5579 +       if (c->s_mount_opt & JFFS2_MOUNT_TAGGED)
5580 +               sb->s_flags |= MS_TAGGED;
5581 +
5582         return jffs2_do_fill_super(sb, data, silent);
5583  }
5584  
5585 diff -NurpP --minimal linux-2.6.22.10/fs/jffs2/write.c linux-2.6.22.10-vs2.3.0.29/fs/jffs2/write.c
5586 --- linux-2.6.22.10/fs/jffs2/write.c    2007-10-30 01:57:14 +0100
5587 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/write.c 2007-09-05 03:06:11 +0200
5588 @@ -44,6 +44,7 @@ int jffs2_do_new_inode(struct jffs2_sb_i
5589         ri->totlen = cpu_to_je32(PAD(sizeof(*ri)));
5590         ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
5591         ri->mode = cpu_to_jemode(mode);
5592 +       ri->flags = cpu_to_je16(0);
5593  
5594         f->highest_version = 1;
5595         ri->version = cpu_to_je32(f->highest_version);
5596 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/acl.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/acl.c
5597 --- linux-2.6.22.10/fs/jfs/acl.c        2006-11-30 21:19:25 +0100
5598 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/acl.c     2007-08-05 20:53:12 +0200
5599 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
5600                 return rc;
5601  
5602         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
5603 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
5604 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
5605 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
5606                 if (DQUOT_TRANSFER(inode, iattr))
5607                         return -EDQUOT;
5608         }
5609 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/file.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/file.c
5610 --- linux-2.6.22.10/fs/jfs/file.c       2007-05-02 19:25:18 +0200
5611 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/file.c    2007-09-12 20:04:16 +0200
5612 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
5613         .setattr        = jfs_setattr,
5614         .permission     = jfs_permission,
5615  #endif
5616 +       .sync_flags     = jfs_sync_flags,
5617  };
5618  
5619  const struct file_operations jfs_file_operations = {
5620 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/inode.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/inode.c
5621 --- linux-2.6.22.10/fs/jfs/inode.c      2007-07-09 13:19:26 +0200
5622 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/inode.c   2007-08-05 20:53:12 +0200
5623 @@ -22,6 +22,7 @@
5624  #include <linux/buffer_head.h>
5625  #include <linux/pagemap.h>
5626  #include <linux/quotaops.h>
5627 +#include <linux/vs_dlimit.h>
5628  #include "jfs_incore.h"
5629  #include "jfs_inode.h"
5630  #include "jfs_filsys.h"
5631 @@ -143,6 +144,7 @@ void jfs_delete_inode(struct inode *inod
5632                 DQUOT_INIT(inode);
5633                 DQUOT_FREE_INODE(inode);
5634                 DQUOT_DROP(inode);
5635 +               DLIMIT_FREE_INODE(inode);
5636         }
5637  
5638         clear_inode(inode);
5639 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/ioctl.c
5640 --- linux-2.6.22.10/fs/jfs/ioctl.c      2007-07-09 13:19:27 +0200
5641 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/ioctl.c   2007-08-05 20:53:12 +0200
5642 @@ -10,6 +10,7 @@
5643  #include <linux/capability.h>
5644  #include <linux/time.h>
5645  #include <linux/sched.h>
5646 +#include <linux/mount.h>
5647  #include <asm/current.h>
5648  #include <asm/uaccess.h>
5649  
5650 @@ -66,7 +67,8 @@ int jfs_ioctl(struct inode * inode, stru
5651         case JFS_IOC_SETFLAGS: {
5652                 unsigned int oldflags;
5653  
5654 -               if (IS_RDONLY(inode))
5655 +               if (IS_RDONLY(inode) ||
5656 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
5657                         return -EROFS;
5658  
5659                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
5660 @@ -87,8 +89,8 @@ int jfs_ioctl(struct inode * inode, stru
5661                  * the relevant capability.
5662                  */
5663                 if ((oldflags & JFS_IMMUTABLE_FL) ||
5664 -                       ((flags ^ oldflags) &
5665 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
5666 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
5667 +                       JFS_IMMUTABLE_FL | JFS_IUNLINK_FL))) {
5668                         if (!capable(CAP_LINUX_IMMUTABLE))
5669                                 return -EPERM;
5670                 }
5671 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_dinode.h linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_dinode.h
5672 --- linux-2.6.22.10/fs/jfs/jfs_dinode.h 2006-11-30 21:19:25 +0100
5673 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_dinode.h      2007-08-05 20:53:12 +0200
5674 @@ -162,9 +162,12 @@ struct dinode {
5675  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
5676  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
5677  
5678 -#define JFS_FL_USER_VISIBLE    0x03F80000
5679 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
5680 +#define JFS_IUNLINK_FL         0x08000000 /* Immutable unlink */
5681 +
5682 +#define JFS_FL_USER_VISIBLE    0x0FF80000
5683  #define JFS_FL_USER_MODIFIABLE 0x03F80000
5684 -#define JFS_FL_INHERIT         0x03C80000
5685 +#define JFS_FL_INHERIT         0x0BC80000
5686  
5687  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
5688  #define JFS_IOC_GETFLAGS       _IOR('f', 1, long)
5689 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_dtree.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_dtree.c
5690 --- linux-2.6.22.10/fs/jfs/jfs_dtree.c  2007-02-06 03:01:24 +0100
5691 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_dtree.c       2007-08-05 20:53:12 +0200
5692 @@ -102,6 +102,7 @@
5693  
5694  #include <linux/fs.h>
5695  #include <linux/quotaops.h>
5696 +#include <linux/vs_dlimit.h>
5697  #include "jfs_incore.h"
5698  #include "jfs_superblock.h"
5699  #include "jfs_filsys.h"
5700 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
5701                  */
5702                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
5703                         goto clean_up;
5704 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
5705 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
5706 -                       goto clean_up;
5707 -               }
5708 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
5709 +                       goto clean_up_dquot;
5710 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
5711 +                       goto clean_up_dlimit;
5712  
5713                 /*
5714                  * Save the table, we're going to overwrite it with the
5715 @@ -479,6 +480,12 @@ static u32 add_index(tid_t tid, struct i
5716  
5717         return index;
5718  
5719 +      clean_up_dlimit:
5720 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
5721 +
5722 +      clean_up_dquot:
5723 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
5724 +
5725        clean_up:
5726  
5727         jfs_ip->next_index--;
5728 @@ -952,6 +959,7 @@ static int dtSplitUp(tid_t tid,
5729         struct tlock *tlck;
5730         struct lv *lv;
5731         int quota_allocation = 0;
5732 +       int dlimit_allocation = 0;
5733  
5734         /* get split page */
5735         smp = split->mp;
5736 @@ -1036,6 +1044,12 @@ static int dtSplitUp(tid_t tid,
5737                 }
5738                 quota_allocation += n;
5739  
5740 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
5741 +                       rc = -ENOSPC;
5742 +                       goto extendOut;
5743 +               }
5744 +               dlimit_allocation += n;
5745 +
5746                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
5747                                     (s64) n, &nxaddr)))
5748                         goto extendOut;
5749 @@ -1309,6 +1323,9 @@ static int dtSplitUp(tid_t tid,
5750        freeKeyName:
5751         kfree(key.name);
5752  
5753 +       /* Rollback dlimit allocation */
5754 +       if (rc && dlimit_allocation)
5755 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
5756         /* Rollback quota allocation */
5757         if (rc && quota_allocation)
5758                 DQUOT_FREE_BLOCK(ip, quota_allocation);
5759 @@ -1376,6 +1393,12 @@ static int dtSplitPage(tid_t tid, struct
5760                 release_metapage(rmp);
5761                 return -EDQUOT;
5762         }
5763 +       /* Allocate blocks to dlimit. */
5764 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5765 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5766 +               release_metapage(rmp);
5767 +               return -ENOSPC;
5768 +       }
5769  
5770         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
5771  
5772 @@ -1926,6 +1949,12 @@ static int dtSplitRoot(tid_t tid,
5773                 release_metapage(rmp);
5774                 return -EDQUOT;
5775         }
5776 +       /* Allocate blocks to dlimit. */
5777 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5778 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5779 +               release_metapage(rmp);
5780 +               return -ENOSPC;
5781 +       }
5782  
5783         BT_MARK_DIRTY(rmp, ip);
5784         /*
5785 @@ -2292,6 +2321,8 @@ static int dtDeleteUp(tid_t tid, struct 
5786  
5787         xlen = lengthPXD(&fp->header.self);
5788  
5789 +       /* Free dlimit allocation. */
5790 +       DLIMIT_FREE_BLOCK(ip, xlen);
5791         /* Free quota allocation. */
5792         DQUOT_FREE_BLOCK(ip, xlen);
5793  
5794 @@ -2368,6 +2399,8 @@ static int dtDeleteUp(tid_t tid, struct 
5795  
5796                                 xlen = lengthPXD(&p->header.self);
5797  
5798 +                               /* Free dlimit allocation */
5799 +                               DLIMIT_FREE_BLOCK(ip, xlen);
5800                                 /* Free quota allocation */
5801                                 DQUOT_FREE_BLOCK(ip, xlen);
5802  
5803 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_extent.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_extent.c
5804 --- linux-2.6.22.10/fs/jfs/jfs_extent.c 2006-11-30 21:19:25 +0100
5805 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_extent.c      2007-08-05 20:53:12 +0200
5806 @@ -18,6 +18,7 @@
5807  
5808  #include <linux/fs.h>
5809  #include <linux/quotaops.h>
5810 +#include <linux/vs_dlimit.h>
5811  #include "jfs_incore.h"
5812  #include "jfs_inode.h"
5813  #include "jfs_superblock.h"
5814 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
5815                 return -EDQUOT;
5816         }
5817  
5818 +       /* Allocate blocks to dlimit. */
5819 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
5820 +               DQUOT_FREE_BLOCK(ip, nxlen);
5821 +               dbFree(ip, nxaddr, (s64) nxlen);
5822 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
5823 +               return -ENOSPC;
5824 +       }
5825 +
5826         /* determine the value of the extent flag */
5827         xflag = abnr ? XAD_NOTRECORDED : 0;
5828  
5829 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
5830          */
5831         if (rc) {
5832                 dbFree(ip, nxaddr, nxlen);
5833 +               DLIMIT_FREE_BLOCK(ip, nxlen);
5834                 DQUOT_FREE_BLOCK(ip, nxlen);
5835                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
5836                 return (rc);
5837 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
5838                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
5839                 return -EDQUOT;
5840         }
5841 +       /* Allocate blocks to dlimit. */
5842 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
5843 +               DQUOT_FREE_BLOCK(ip, nxlen);
5844 +               dbFree(ip, nxaddr, (s64) nxlen);
5845 +               up(&JFS_IP(ip)->commit_sem);
5846 +               return -ENOSPC;
5847 +       }
5848  
5849         delta = nxlen - xlen;
5850  
5851 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
5852                 /* extend the extent */
5853                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
5854                         dbFree(ip, xaddr + xlen, delta);
5855 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
5856                         DQUOT_FREE_BLOCK(ip, nxlen);
5857                         goto exit;
5858                 }
5859 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
5860                  */
5861                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
5862                         dbFree(ip, nxaddr, nxlen);
5863 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
5864                         DQUOT_FREE_BLOCK(ip, nxlen);
5865                         goto exit;
5866                 }
5867 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_filsys.h linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_filsys.h
5868 --- linux-2.6.22.10/fs/jfs/jfs_filsys.h 2007-02-06 03:01:24 +0100
5869 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_filsys.h      2007-08-05 20:53:12 +0200
5870 @@ -264,6 +264,7 @@
5871  #define JFS_NAME_MAX   255
5872  #define JFS_PATH_MAX   BPSIZE
5873  
5874 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
5875  
5876  /*
5877   *     file system state (superblock state)
5878 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_imap.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_imap.c
5879 --- linux-2.6.22.10/fs/jfs/jfs_imap.c   2007-07-09 13:19:27 +0200
5880 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_imap.c        2007-08-05 20:53:12 +0200
5881 @@ -45,6 +45,7 @@
5882  #include <linux/buffer_head.h>
5883  #include <linux/pagemap.h>
5884  #include <linux/quotaops.h>
5885 +#include <linux/vs_tag.h>
5886  
5887  #include "jfs_incore.h"
5888  #include "jfs_inode.h"
5889 @@ -3075,6 +3076,8 @@ static int copy_from_dinode(struct dinod
5890  {
5891         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
5892         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
5893 +       uid_t uid;
5894 +       gid_t gid;
5895  
5896         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
5897         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
5898 @@ -3095,14 +3098,18 @@ static int copy_from_dinode(struct dinod
5899         }
5900         ip->i_nlink = le32_to_cpu(dip->di_nlink);
5901  
5902 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
5903 +       uid = le32_to_cpu(dip->di_uid);
5904 +       gid = le32_to_cpu(dip->di_gid);
5905 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
5906 +
5907 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
5908         if (sbi->uid == -1)
5909                 ip->i_uid = jfs_ip->saved_uid;
5910         else {
5911                 ip->i_uid = sbi->uid;
5912         }
5913  
5914 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
5915 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
5916         if (sbi->gid == -1)
5917                 ip->i_gid = jfs_ip->saved_gid;
5918         else {
5919 @@ -3167,14 +3174,12 @@ static void copy_to_dinode(struct dinode
5920         dip->di_size = cpu_to_le64(ip->i_size);
5921         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
5922         dip->di_nlink = cpu_to_le32(ip->i_nlink);
5923 -       if (sbi->uid == -1)
5924 -               dip->di_uid = cpu_to_le32(ip->i_uid);
5925 -       else
5926 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
5927 -       if (sbi->gid == -1)
5928 -               dip->di_gid = cpu_to_le32(ip->i_gid);
5929 -       else
5930 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
5931 +
5932 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
5933 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
5934 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
5935 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
5936 +
5937         jfs_get_inode_flags(jfs_ip);
5938         /*
5939          * mode2 is only needed for storing the higher order bits.
5940 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_inode.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_inode.c
5941 --- linux-2.6.22.10/fs/jfs/jfs_inode.c  2007-07-09 13:19:27 +0200
5942 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_inode.c       2007-08-05 20:53:12 +0200
5943 @@ -18,6 +18,8 @@
5944  
5945  #include <linux/fs.h>
5946  #include <linux/quotaops.h>
5947 +#include <linux/vs_dlimit.h>
5948 +#include <linux/vs_tag.h>
5949  #include "jfs_incore.h"
5950  #include "jfs_inode.h"
5951  #include "jfs_filsys.h"
5952 @@ -30,19 +32,47 @@ void jfs_set_inode_flags(struct inode *i
5953  {
5954         unsigned int flags = JFS_IP(inode)->mode2;
5955  
5956 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
5957 -               S_NOATIME | S_DIRSYNC | S_SYNC);
5958 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
5959 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5960  
5961         if (flags & JFS_IMMUTABLE_FL)
5962                 inode->i_flags |= S_IMMUTABLE;
5963 +       if (flags & JFS_IUNLINK_FL)
5964 +               inode->i_flags |= S_IUNLINK;
5965 +       if (flags & JFS_BARRIER_FL)
5966 +               inode->i_flags |= S_BARRIER;
5967 +
5968 +       if (flags & JFS_SYNC_FL)
5969 +               inode->i_flags |= S_SYNC;
5970         if (flags & JFS_APPEND_FL)
5971                 inode->i_flags |= S_APPEND;
5972         if (flags & JFS_NOATIME_FL)
5973                 inode->i_flags |= S_NOATIME;
5974         if (flags & JFS_DIRSYNC_FL)
5975                 inode->i_flags |= S_DIRSYNC;
5976 -       if (flags & JFS_SYNC_FL)
5977 -               inode->i_flags |= S_SYNC;
5978 +}
5979 +
5980 +int jfs_sync_flags(struct inode *inode)
5981 +{
5982 +       unsigned int oldflags, newflags;
5983 +
5984 +       oldflags = JFS_IP(inode)->mode2;
5985 +       newflags = oldflags & ~(JFS_IMMUTABLE_FL |
5986 +               JFS_IUNLINK_FL | JFS_BARRIER_FL);
5987 +
5988 +       if (IS_IMMUTABLE(inode))
5989 +               newflags |= JFS_IMMUTABLE_FL;
5990 +       if (IS_IUNLINK(inode))
5991 +               newflags |= JFS_IUNLINK_FL;
5992 +       if (IS_BARRIER(inode))
5993 +               newflags |= JFS_BARRIER_FL;
5994 +
5995 +       if (oldflags ^ newflags) {
5996 +               JFS_IP(inode)->mode2 = newflags;
5997 +               inode->i_ctime = CURRENT_TIME;
5998 +               mark_inode_dirty(inode);
5999 +       }
6000 +       return 0;
6001  }
6002  
6003  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
6004 @@ -108,10 +138,17 @@ struct inode *ialloc(struct inode *paren
6005         jfs_inode->saved_uid = inode->i_uid;
6006         jfs_inode->saved_gid = inode->i_gid;
6007  
6008 +       inode->i_tag = dx_current_fstag(sb);
6009 +       if (DLIMIT_ALLOC_INODE(inode)) {
6010 +               iput(inode);
6011 +               return ERR_PTR(-ENOSPC);
6012 +       }
6013 +
6014         /*
6015          * Allocate inode to quota.
6016          */
6017         if (DQUOT_ALLOC_INODE(inode)) {
6018 +               DLIMIT_FREE_INODE(inode);
6019                 DQUOT_DROP(inode);
6020                 inode->i_flags |= S_NOQUOTA;
6021                 inode->i_nlink = 0;
6022 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_inode.h linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_inode.h
6023 --- linux-2.6.22.10/fs/jfs/jfs_inode.h  2007-07-09 13:19:27 +0200
6024 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_inode.h       2007-08-05 20:53:12 +0200
6025 @@ -33,6 +33,7 @@ extern void jfs_free_zero_link(struct in
6026  extern struct dentry *jfs_get_parent(struct dentry *dentry);
6027  extern void jfs_get_inode_flags(struct jfs_inode_info *);
6028  extern void jfs_set_inode_flags(struct inode *);
6029 +extern int jfs_sync_flags(struct inode *);
6030  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
6031  
6032  extern const struct address_space_operations jfs_aops;
6033 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_xtree.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_xtree.c
6034 --- linux-2.6.22.10/fs/jfs/jfs_xtree.c  2007-05-02 19:25:18 +0200
6035 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_xtree.c       2007-08-05 20:53:12 +0200
6036 @@ -21,6 +21,7 @@
6037  
6038  #include <linux/fs.h>
6039  #include <linux/quotaops.h>
6040 +#include <linux/vs_dlimit.h>
6041  #include "jfs_incore.h"
6042  #include "jfs_filsys.h"
6043  #include "jfs_metapage.h"
6044 @@ -846,7 +847,12 @@ int xtInsert(tid_t tid,            /* transaction 
6045                         hint = 0;
6046                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
6047                         goto out;
6048 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
6049 +                       DQUOT_FREE_BLOCK(ip, xlen);
6050 +                       goto out;
6051 +               }
6052                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
6053 +                       DLIMIT_FREE_BLOCK(ip, xlen);
6054                         DQUOT_FREE_BLOCK(ip, xlen);
6055                         goto out;
6056                 }
6057 @@ -876,6 +882,7 @@ int xtInsert(tid_t tid,             /* transaction 
6058                         /* undo data extent allocation */
6059                         if (*xaddrp == 0) {
6060                                 dbFree(ip, xaddr, (s64) xlen);
6061 +                               DLIMIT_FREE_BLOCK(ip, xlen);
6062                                 DQUOT_FREE_BLOCK(ip, xlen);
6063                         }
6064                         return rc;
6065 @@ -1236,6 +1243,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
6066         struct tlock *tlck;
6067         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
6068         int quota_allocation = 0;
6069 +       int dlimit_allocation = 0;
6070  
6071         smp = split->mp;
6072         sp = XT_PAGE(ip, smp);
6073 @@ -1255,6 +1263,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
6074  
6075         quota_allocation += lengthPXD(pxd);
6076  
6077 +       /* Allocate blocks to dlimit. */
6078 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
6079 +              rc = -ENOSPC;
6080 +              goto clean_up;
6081 +       }
6082 +       dlimit_allocation += lengthPXD(pxd);
6083 +
6084         /*
6085          * allocate the new right page for the split
6086          */
6087 @@ -1456,6 +1471,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
6088  
6089        clean_up:
6090  
6091 +       /* Rollback dlimit allocation. */
6092 +       if (dlimit_allocation)
6093 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
6094         /* Rollback quota allocation. */
6095         if (quota_allocation)
6096                 DQUOT_FREE_BLOCK(ip, quota_allocation);
6097 @@ -1520,6 +1538,12 @@ xtSplitRoot(tid_t tid,
6098                 release_metapage(rmp);
6099                 return -EDQUOT;
6100         }
6101 +       /* Allocate blocks to dlimit. */
6102 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
6103 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
6104 +               release_metapage(rmp);
6105 +               return -ENOSPC;
6106 +       }
6107  
6108         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
6109  
6110 @@ -3951,6 +3975,8 @@ s64 xtTruncate(tid_t tid, struct inode *
6111         else
6112                 ip->i_size = newsize;
6113  
6114 +       /* update dlimit allocation to reflect freed blocks */
6115 +       DLIMIT_FREE_BLOCK(ip, nfreed);
6116         /* update quota allocation to reflect freed blocks */
6117         DQUOT_FREE_BLOCK(ip, nfreed);
6118  
6119 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/namei.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/namei.c
6120 --- linux-2.6.22.10/fs/jfs/namei.c      2007-05-02 19:25:18 +0200
6121 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/namei.c   2007-08-05 20:53:12 +0200
6122 @@ -20,6 +20,7 @@
6123  #include <linux/fs.h>
6124  #include <linux/ctype.h>
6125  #include <linux/quotaops.h>
6126 +#include <linux/vs_tag.h>
6127  #include "jfs_incore.h"
6128  #include "jfs_superblock.h"
6129  #include "jfs_inode.h"
6130 @@ -1469,6 +1470,7 @@ static struct dentry *jfs_lookup(struct 
6131                 return ERR_PTR(-EACCES);
6132         }
6133  
6134 +       dx_propagate_tag(nd, ip);
6135         dentry = d_splice_alias(ip, dentry);
6136  
6137         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
6138 @@ -1521,6 +1523,7 @@ const struct inode_operations jfs_dir_in
6139         .setattr        = jfs_setattr,
6140         .permission     = jfs_permission,
6141  #endif
6142 +       .sync_flags     = jfs_sync_flags,
6143  };
6144  
6145  const struct file_operations jfs_dir_operations = {
6146 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/super.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/super.c
6147 --- linux-2.6.22.10/fs/jfs/super.c      2007-07-09 13:19:27 +0200
6148 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/super.c   2007-08-05 20:53:12 +0200
6149 @@ -194,7 +194,8 @@ static void jfs_put_super(struct super_b
6150  enum {
6151         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
6152         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
6153 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
6154 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
6155 +       Opt_tag, Opt_notag, Opt_tagid
6156  };
6157  
6158  static match_table_t tokens = {
6159 @@ -204,6 +205,10 @@ static match_table_t tokens = {
6160         {Opt_resize, "resize=%u"},
6161         {Opt_resize_nosize, "resize"},
6162         {Opt_errors, "errors=%s"},
6163 +       {Opt_tag, "tag"},
6164 +       {Opt_notag, "notag"},
6165 +       {Opt_tagid, "tagid=%u"},
6166 +       {Opt_tag, "tagxid"},
6167         {Opt_ignore, "noquota"},
6168         {Opt_ignore, "quota"},
6169         {Opt_usrquota, "usrquota"},
6170 @@ -338,6 +343,20 @@ static int parse_options(char *options, 
6171                         }
6172                         break;
6173                 }
6174 +#ifndef CONFIG_TAGGING_NONE
6175 +               case Opt_tag:
6176 +                       *flag |= JFS_TAGGED;
6177 +                       break;
6178 +               case Opt_notag:
6179 +                       *flag &= JFS_TAGGED;
6180 +                       break;
6181 +#endif
6182 +#ifdef CONFIG_PROPAGATE
6183 +               case Opt_tagid:
6184 +                       /* use args[0] */
6185 +                       *flag |= JFS_TAGGED;
6186 +                       break;
6187 +#endif
6188                 default:
6189                         printk("jfs: Unrecognized mount option \"%s\" "
6190                                         " or missing value\n", p);
6191 @@ -368,6 +387,13 @@ static int jfs_remount(struct super_bloc
6192         if (!parse_options(data, sb, &newLVSize, &flag)) {
6193                 return -EINVAL;
6194         }
6195 +
6196 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
6197 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
6198 +                       sb->s_id);
6199 +               return -EINVAL;
6200 +       }
6201 +
6202         if (newLVSize) {
6203                 if (sb->s_flags & MS_RDONLY) {
6204                         printk(KERN_ERR
6205 @@ -439,6 +465,9 @@ static int jfs_fill_super(struct super_b
6206  #ifdef CONFIG_JFS_POSIX_ACL
6207         sb->s_flags |= MS_POSIXACL;
6208  #endif
6209 +       /* map mount option tagxid */
6210 +       if (sbi->flag & JFS_TAGGED)
6211 +               sb->s_flags |= MS_TAGGED;
6212  
6213         if (newLVSize) {
6214                 printk(KERN_ERR "resize option for remount only\n");
6215 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/xattr.c linux-2.6.22.10-vs2.3.0.29/fs/jfs/xattr.c
6216 --- linux-2.6.22.10/fs/jfs/xattr.c      2006-11-30 21:19:26 +0100
6217 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/xattr.c   2007-08-05 20:53:12 +0200
6218 @@ -23,6 +23,7 @@
6219  #include <linux/posix_acl_xattr.h>
6220  #include <linux/quotaops.h>
6221  #include <linux/security.h>
6222 +#include <linux/vs_dlimit.h>
6223  #include "jfs_incore.h"
6224  #include "jfs_superblock.h"
6225  #include "jfs_dmap.h"
6226 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
6227         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
6228                 return -EDQUOT;
6229         }
6230 +       /* Allocate new blocks to dlimit. */
6231 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
6232 +               DQUOT_FREE_BLOCK(ip, nblocks);
6233 +               return -ENOSPC;
6234 +       }
6235  
6236         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
6237         if (rc) {
6238 +               /*Rollback dlimit allocation. */
6239 +               DLIMIT_FREE_BLOCK(ip, nblocks);
6240                 /*Rollback quota allocation. */
6241                 DQUOT_FREE_BLOCK(ip, nblocks);
6242                 return rc;
6243 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
6244  
6245        failed:
6246         /* Rollback quota allocation. */
6247 +       DLIMIT_FREE_BLOCK(ip, nblocks);
6248 +       /* Rollback quota allocation. */
6249         DQUOT_FREE_BLOCK(ip, nblocks);
6250  
6251         dbFree(ip, blkno, nblocks);
6252 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
6253         s64 blkno;
6254         int rc;
6255         int quota_allocation = 0;
6256 +       int dlimit_allocation = 0;
6257  
6258         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
6259         if (ji->ea.flag == 0)
6260 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
6261  
6262                 quota_allocation = blocks_needed;
6263  
6264 +               /* Allocate new blocks to dlimit. */
6265 +               rc = -ENOSPC;
6266 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
6267 +                       goto clean_up;
6268 +               dlimit_allocation = blocks_needed;
6269 +
6270                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
6271                              &blkno);
6272                 if (rc)
6273 @@ -599,6 +616,9 @@ static int ea_get(struct inode *inode, s
6274         return ea_size;
6275  
6276        clean_up:
6277 +       /* Rollback dlimit allocation */
6278 +       if (dlimit_allocation)
6279 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
6280         /* Rollback quota allocation */
6281         if (quota_allocation)
6282                 DQUOT_FREE_BLOCK(inode, quota_allocation);
6283 @@ -675,8 +695,10 @@ static int ea_put(tid_t tid, struct inod
6284         }
6285  
6286         /* If old blocks exist, they must be removed from quota allocation. */
6287 -       if (old_blocks)
6288 +       if (old_blocks) {
6289 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
6290                 DQUOT_FREE_BLOCK(inode, old_blocks);
6291 +       }
6292  
6293         inode->i_ctime = CURRENT_TIME;
6294  
6295 diff -NurpP --minimal linux-2.6.22.10/fs/libfs.c linux-2.6.22.10-vs2.3.0.29/fs/libfs.c
6296 --- linux-2.6.22.10/fs/libfs.c  2007-07-09 13:19:27 +0200
6297 +++ linux-2.6.22.10-vs2.3.0.29/fs/libfs.c       2007-08-05 20:53:12 +0200
6298 @@ -124,7 +124,8 @@ static inline unsigned char dt_type(stru
6299   * both impossible due to the lock on directory.
6300   */
6301  
6302 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
6303 +static inline int do_dcache_readdir_filter(struct file *filp,
6304 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
6305  {
6306         struct dentry *dentry = filp->f_path.dentry;
6307         struct dentry *cursor = filp->private_data;
6308 @@ -157,6 +158,8 @@ int dcache_readdir(struct file * filp, v
6309                                 next = list_entry(p, struct dentry, d_u.d_child);
6310                                 if (d_unhashed(next) || !next->d_inode)
6311                                         continue;
6312 +                               if (filter && !filter(next))
6313 +                                       continue;
6314  
6315                                 spin_unlock(&dcache_lock);
6316                                 if (filldir(dirent, next->d_name.name, 
6317 @@ -175,6 +178,18 @@ int dcache_readdir(struct file * filp, v
6318         return 0;
6319  }
6320  
6321 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
6322 +{
6323 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
6324 +}
6325 +
6326 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
6327 +       int (*filter)(struct dentry *))
6328 +{
6329 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
6330 +}
6331 +
6332 +
6333  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
6334  {
6335         return -EISDIR;
6336 @@ -640,6 +655,7 @@ EXPORT_SYMBOL(dcache_dir_close);
6337  EXPORT_SYMBOL(dcache_dir_lseek);
6338  EXPORT_SYMBOL(dcache_dir_open);
6339  EXPORT_SYMBOL(dcache_readdir);
6340 +EXPORT_SYMBOL(dcache_readdir_filter);
6341  EXPORT_SYMBOL(generic_read_dir);
6342  EXPORT_SYMBOL(get_sb_pseudo);
6343  EXPORT_SYMBOL(simple_commit_write);
6344 diff -NurpP --minimal linux-2.6.22.10/fs/locks.c linux-2.6.22.10-vs2.3.0.29/fs/locks.c
6345 --- linux-2.6.22.10/fs/locks.c  2007-10-30 01:57:14 +0100
6346 +++ linux-2.6.22.10-vs2.3.0.29/fs/locks.c       2007-10-05 15:07:22 +0200
6347 @@ -125,6 +125,8 @@
6348  #include <linux/syscalls.h>
6349  #include <linux/time.h>
6350  #include <linux/rcupdate.h>
6351 +#include <linux/vs_base.h>
6352 +#include <linux/vs_limit.h>
6353  
6354  #include <asm/semaphore.h>
6355  #include <asm/uaccess.h>
6356 @@ -147,6 +149,8 @@ static struct kmem_cache *filelock_cache
6357  /* Allocate an empty lock structure. */
6358  static struct file_lock *locks_alloc_lock(void)
6359  {
6360 +       if (!vx_locks_avail(1))
6361 +               return NULL;
6362         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
6363  }
6364  
6365 @@ -172,6 +176,7 @@ static void locks_free_lock(struct file_
6366         BUG_ON(!list_empty(&fl->fl_block));
6367         BUG_ON(!list_empty(&fl->fl_link));
6368  
6369 +       vx_locks_dec(fl);
6370         locks_release_private(fl);
6371         kmem_cache_free(filelock_cache, fl);
6372  }
6373 @@ -191,6 +196,7 @@ void locks_init_lock(struct file_lock *f
6374         fl->fl_start = fl->fl_end = 0;
6375         fl->fl_ops = NULL;
6376         fl->fl_lmops = NULL;
6377 +       fl->fl_xid = -1;
6378  }
6379  
6380  EXPORT_SYMBOL(locks_init_lock);
6381 @@ -244,6 +250,7 @@ void locks_copy_lock(struct file_lock *n
6382         new->fl_file = fl->fl_file;
6383         new->fl_ops = fl->fl_ops;
6384         new->fl_lmops = fl->fl_lmops;
6385 +       new->fl_xid = fl->fl_xid;
6386  
6387         locks_copy_private(new, fl);
6388  }
6389 @@ -282,6 +289,11 @@ static int flock_make_lock(struct file *
6390         fl->fl_flags = FL_FLOCK;
6391         fl->fl_type = type;
6392         fl->fl_end = OFFSET_MAX;
6393 +
6394 +       vxd_assert(filp->f_xid == vx_current_xid(),
6395 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6396 +       fl->fl_xid = filp->f_xid;
6397 +       vx_locks_inc(fl);
6398         
6399         *lock = fl;
6400         return 0;
6401 @@ -447,6 +459,7 @@ static int lease_init(struct file *filp,
6402  
6403         fl->fl_owner = current->files;
6404         fl->fl_pid = current->tgid;
6405 +       fl->fl_xid = vx_current_xid();
6406  
6407         fl->fl_file = filp;
6408         fl->fl_flags = FL_LEASE;
6409 @@ -466,6 +479,11 @@ static int lease_alloc(struct file *filp
6410         if (fl == NULL)
6411                 goto out;
6412  
6413 +       fl->fl_xid = vx_current_xid();
6414 +       if (filp)
6415 +               vxd_assert(filp->f_xid == fl->fl_xid,
6416 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
6417 +       vx_locks_inc(fl);
6418         error = lease_init(filp, type, fl);
6419         if (error) {
6420                 locks_free_lock(fl);
6421 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
6422         if (found)
6423                 cond_resched();
6424  
6425 +       new_fl->fl_xid = -1;
6426  find_conflict:
6427         for_each_lock(inode, before) {
6428                 struct file_lock *fl = *before;
6429 @@ -787,6 +806,7 @@ find_conflict:
6430                 goto out;
6431         locks_copy_lock(new_fl, request);
6432         locks_insert_lock(before, new_fl);
6433 +       vx_locks_inc(new_fl);
6434         new_fl = NULL;
6435         error = 0;
6436  
6437 @@ -797,7 +817,8 @@ out:
6438         return error;
6439  }
6440  
6441 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
6442 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
6443 +       struct file_lock *conflock, xid_t xid)
6444  {
6445         struct file_lock *fl;
6446         struct file_lock *new_fl = NULL;
6447 @@ -807,6 +828,8 @@ static int __posix_lock_file(struct inod
6448         struct file_lock **before;
6449         int error, added = 0;
6450  
6451 +       vxd_assert(xid == vx_current_xid(),
6452 +               "xid(%d) == current(%d)", xid, vx_current_xid());
6453         /*
6454          * We may need two file_lock structures for this operation,
6455          * so we get them in advance to avoid races.
6456 @@ -817,7 +840,11 @@ static int __posix_lock_file(struct inod
6457             (request->fl_type != F_UNLCK ||
6458              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
6459                 new_fl = locks_alloc_lock();
6460 +               new_fl->fl_xid = xid;
6461 +               vx_locks_inc(new_fl);
6462                 new_fl2 = locks_alloc_lock();
6463 +               new_fl2->fl_xid = xid;
6464 +               vx_locks_inc(new_fl2);
6465         }
6466  
6467         lock_kernel();
6468 @@ -1016,7 +1043,8 @@ static int __posix_lock_file(struct inod
6469  int posix_lock_file(struct file *filp, struct file_lock *fl,
6470                         struct file_lock *conflock)
6471  {
6472 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
6473 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
6474 +               fl, conflock, filp->f_xid);
6475  }
6476  EXPORT_SYMBOL(posix_lock_file);
6477  
6478 @@ -1106,7 +1134,7 @@ int locks_mandatory_area(int read_write,
6479         fl.fl_end = offset + count - 1;
6480  
6481         for (;;) {
6482 -               error = __posix_lock_file(inode, &fl, NULL);
6483 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
6484                 if (error != -EAGAIN)
6485                         break;
6486                 if (!(fl.fl_flags & FL_SLEEP))
6487 @@ -1410,8 +1438,8 @@ static int __setlease(struct file *filp,
6488                 goto out;
6489  
6490         locks_copy_lock(fl, lease);
6491 -
6492         locks_insert_lock(before, fl);
6493 +       vx_locks_inc(fl);
6494  
6495         *flp = fl;
6496         error = 0;
6497 @@ -1738,6 +1766,11 @@ int fcntl_setlk(unsigned int fd, struct 
6498         if (file_lock == NULL)
6499                 return -ENOLCK;
6500  
6501 +       vxd_assert(filp->f_xid == vx_current_xid(),
6502 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6503 +       file_lock->fl_xid = filp->f_xid;
6504 +       vx_locks_inc(file_lock);
6505 +
6506         /*
6507          * This might block, so we do it before checking the inode.
6508          */
6509 @@ -1864,6 +1897,11 @@ int fcntl_setlk64(unsigned int fd, struc
6510         if (file_lock == NULL)
6511                 return -ENOLCK;
6512  
6513 +       vxd_assert(filp->f_xid == vx_current_xid(),
6514 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6515 +       file_lock->fl_xid = filp->f_xid;
6516 +       vx_locks_inc(file_lock);
6517 +
6518         /*
6519          * This might block, so we do it before checking the inode.
6520          */
6521 @@ -2168,6 +2206,10 @@ int get_locks_status(char *buffer, char 
6522         list_for_each(tmp, &file_lock_list) {
6523                 struct list_head *btmp;
6524                 struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link);
6525 +
6526 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
6527 +                       continue;
6528 +
6529                 lock_get_status(q, fl, ++i, "");
6530                 move_lock_status(&q, &pos, offset);
6531  
6532 diff -NurpP --minimal linux-2.6.22.10/fs/namei.c linux-2.6.22.10-vs2.3.0.29/fs/namei.c
6533 --- linux-2.6.22.10/fs/namei.c  2007-07-09 13:19:27 +0200
6534 +++ linux-2.6.22.10-vs2.3.0.29/fs/namei.c       2007-10-29 23:41:56 +0100
6535 @@ -31,6 +31,13 @@
6536  #include <linux/file.h>
6537  #include <linux/fcntl.h>
6538  #include <linux/namei.h>
6539 +#include <linux/proc_fs.h>
6540 +#include <linux/vserver/inode.h>
6541 +#include <linux/vs_base.h>
6542 +#include <linux/vs_tag.h>
6543 +#include <linux/vs_cowbl.h>
6544 +#include <linux/vs_device.h>
6545 +#include <linux/vs_context.h>
6546  #include <asm/namei.h>
6547  #include <asm/uaccess.h>
6548  
6549 @@ -224,6 +231,28 @@ int generic_permission(struct inode *ino
6550         return -EACCES;
6551  }
6552  
6553 +static inline int dx_barrier(struct inode *inode)
6554 +{
6555 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
6556 +               vxwprintk_task(1, "did hit the barrier.");
6557 +               return 1;
6558 +       }
6559 +       return 0;
6560 +}
6561 +
6562 +static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
6563 +{
6564 +       if (dx_barrier(inode))
6565 +               return -EACCES;
6566 +       if (dx_notagcheck(nd) ||
6567 +           dx_check(inode->i_tag, DX_HOSTID|DX_ADMIN|DX_WATCH|DX_IDENT))
6568 +               return 0;
6569 +
6570 +       vxwprintk_task(1, "denied access to %p[#%d,%lu] »%s«.",
6571 +               inode, inode->i_tag, inode->i_ino, vxd_cond_path(nd));
6572 +       return -EACCES;
6573 +}
6574 +
6575  int permission(struct inode *inode, int mask, struct nameidata *nd)
6576  {
6577         umode_t mode = inode->i_mode;
6578 @@ -234,14 +263,14 @@ int permission(struct inode *inode, int 
6579                 /*
6580                  * Nobody gets write access to a read-only fs.
6581                  */
6582 -               if (IS_RDONLY(inode) &&
6583 +               if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->mnt))) &&
6584                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
6585                         return -EROFS;
6586  
6587                 /*
6588                  * Nobody gets write access to an immutable file.
6589                  */
6590 -               if (IS_IMMUTABLE(inode))
6591 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
6592                         return -EACCES;
6593         }
6594  
6595 @@ -257,6 +286,12 @@ int permission(struct inode *inode, int 
6596  
6597         /* Ordinary permission routines do not understand MAY_APPEND. */
6598         submask = mask & ~MAY_APPEND;
6599 +
6600 +       if ((inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC) &&
6601 +               (inode->i_sb->s_magic != PROC_SUPER_MAGIC) &&
6602 +               (retval = dx_permission(inode, mask, nd)))
6603 +               return retval;
6604 +
6605         if (inode->i_op && inode->i_op->permission)
6606                 retval = inode->i_op->permission(inode, submask, nd);
6607         else
6608 @@ -432,6 +467,8 @@ static int exec_permission_lite(struct i
6609  {
6610         umode_t mode = inode->i_mode;
6611  
6612 +       if (dx_barrier(inode))
6613 +               return -EACCES;
6614         if (inode->i_op && inode->i_op->permission)
6615                 return -EAGAIN;
6616  
6617 @@ -732,7 +769,8 @@ static __always_inline void follow_dotdo
6618                 if (nd->dentry == fs->root &&
6619                     nd->mnt == fs->rootmnt) {
6620                          read_unlock(&fs->lock);
6621 -                       break;
6622 +                       /* for sane '/' avoid follow_mount() */
6623 +                       return;
6624                 }
6625                  read_unlock(&fs->lock);
6626                 spin_lock(&dcache_lock);
6627 @@ -769,16 +807,39 @@ static int do_lookup(struct nameidata *n
6628  {
6629         struct vfsmount *mnt = nd->mnt;
6630         struct dentry *dentry = __d_lookup(nd->dentry, name);
6631 +       struct inode *inode;
6632  
6633         if (!dentry)
6634                 goto need_lookup;
6635         if (dentry->d_op && dentry->d_op->d_revalidate)
6636                 goto need_revalidate;
6637 +       inode = dentry->d_inode;
6638 +       if (!inode)
6639 +               goto done;
6640 +
6641 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
6642 +               struct proc_dir_entry *de = PDE(inode);
6643 +
6644 +               if (de && !vx_hide_check(0, de->vx_flags))
6645 +                       goto hidden;
6646 +       } else if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
6647 +               if (!vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
6648 +                       goto hidden;
6649 +       } else {
6650 +               if (!dx_notagcheck(nd) && !dx_check(inode->i_tag,
6651 +                       DX_WATCH | DX_ADMIN | DX_HOSTID | DX_IDENT))
6652 +                       goto hidden;
6653 +       }
6654  done:
6655         path->mnt = mnt;
6656         path->dentry = dentry;
6657         __follow_mount(path);
6658         return 0;
6659 +hidden:
6660 +       vxwprintk_task(1, "did lookup hidden %p[#%d,%lu] »%s«.",
6661 +               inode, inode->i_tag, inode->i_ino, vxd_path(dentry, mnt));
6662 +       dput(dentry);
6663 +       return -ENOENT;
6664  
6665  need_lookup:
6666         dentry = real_lookup(nd->dentry, name, nd);
6667 @@ -1399,7 +1460,8 @@ static inline int check_sticky(struct in
6668   * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
6669   *     nfs_async_unlink().
6670   */
6671 -static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
6672 +static int may_delete(struct inode *dir, struct dentry *victim,
6673 +       int isdir, struct nameidata *nd)
6674  {
6675         int error;
6676  
6677 @@ -1409,13 +1471,13 @@ static int may_delete(struct inode *dir,
6678         BUG_ON(victim->d_parent->d_inode != dir);
6679         audit_inode_child(victim->d_name.name, victim->d_inode, dir);
6680  
6681 -       error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
6682 +       error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
6683         if (error)
6684                 return error;
6685         if (IS_APPEND(dir))
6686                 return -EPERM;
6687         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
6688 -           IS_IMMUTABLE(victim->d_inode))
6689 +               IS_IXORUNLINK(victim->d_inode))
6690                 return -EPERM;
6691         if (isdir) {
6692                 if (!S_ISDIR(victim->d_inode->i_mode))
6693 @@ -1546,6 +1608,14 @@ int may_open(struct nameidata *nd, int a
6694         if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
6695                 return -EISDIR;
6696  
6697 +#ifdef CONFIG_VSERVER_COWBL
6698 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
6699 +               if (IS_COW_LINK(inode))
6700 +                       return -EMLINK;
6701 +               inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
6702 +               mark_inode_dirty(inode);
6703 +       }
6704 +#endif
6705         error = vfs_permission(nd, acc_mode);
6706         if (error)
6707                 return error;
6708 @@ -1562,7 +1632,8 @@ int may_open(struct nameidata *nd, int a
6709                         return -EACCES;
6710  
6711                 flag &= ~O_TRUNC;
6712 -       } else if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
6713 +       } else if ((IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
6714 +               && (flag & FMODE_WRITE))
6715                 return -EROFS;
6716         /*
6717          * An append-only file must be opened in append mode for writing.
6718 @@ -1650,6 +1721,11 @@ int open_namei(int dfd, const char *path
6719         struct dentry *dir;
6720         int count = 0;
6721  
6722 +#ifdef CONFIG_VSERVER_COWBL
6723 +       int rflag = flag;
6724 +       int rmode = mode;
6725 +restart:
6726 +#endif
6727         acc_mode = ACC_MODE(flag);
6728  
6729         /* O_TRUNC implies we need access checks for write permissions */
6730 @@ -1743,6 +1819,22 @@ do_last:
6731                 goto exit;
6732  ok:
6733         error = may_open(nd, acc_mode, flag);
6734 +#ifdef CONFIG_VSERVER_COWBL
6735 +       if (error == -EMLINK) {
6736 +               struct dentry *dentry;
6737 +               dentry = cow_break_link(pathname);
6738 +               if (IS_ERR(dentry)) {
6739 +                       error = PTR_ERR(dentry);
6740 +                       goto exit;
6741 +               }
6742 +               dput(dentry);
6743 +               release_open_intent(nd);
6744 +               path_release(nd);
6745 +               flag = rflag;
6746 +               mode = rmode;
6747 +               goto restart;
6748 +       }
6749 +#endif
6750         if (error)
6751                 goto exit;
6752         return 0;
6753 @@ -1854,16 +1946,25 @@ fail:
6754  }
6755  EXPORT_SYMBOL_GPL(lookup_create);
6756  
6757 -int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
6758 +int vfs_mknod(struct inode *dir, struct dentry *dentry,
6759 +       int mode, dev_t dev, struct nameidata *nd)
6760  {
6761 -       int error = may_create(dir, dentry, NULL);
6762 +       int error = may_create(dir, dentry, nd);
6763  
6764         if (error)
6765                 return error;
6766  
6767 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
6768 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
6769 +               goto okay;
6770 +
6771 +       if (!capable(CAP_MKNOD))
6772                 return -EPERM;
6773  
6774 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
6775 +               return -EPERM;
6776 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
6777 +               return -EPERM;
6778 +okay:
6779         if (!dir->i_op || !dir->i_op->mknod)
6780                 return -EPERM;
6781  
6782 @@ -1906,11 +2007,12 @@ asmlinkage long sys_mknodat(int dfd, con
6783                         error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
6784                         break;
6785                 case S_IFCHR: case S_IFBLK:
6786 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
6787 -                                       new_decode_dev(dev));
6788 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6789 +                                       new_decode_dev(dev), &nd);
6790                         break;
6791                 case S_IFIFO: case S_IFSOCK:
6792 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
6793 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6794 +                                       0, &nd);
6795                         break;
6796                 case S_IFDIR:
6797                         error = -EPERM;
6798 @@ -1933,9 +2035,10 @@ asmlinkage long sys_mknod(const char __u
6799         return sys_mknodat(AT_FDCWD, filename, mode, dev);
6800  }
6801  
6802 -int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
6803 +int vfs_mkdir(struct inode *dir, struct dentry *dentry,
6804 +       int mode, struct nameidata *nd)
6805  {
6806 -       int error = may_create(dir, dentry, NULL);
6807 +       int error = may_create(dir, dentry, nd);
6808  
6809         if (error)
6810                 return error;
6811 @@ -1977,7 +2080,7 @@ asmlinkage long sys_mkdirat(int dfd, con
6812  
6813         if (!IS_POSIXACL(nd.dentry->d_inode))
6814                 mode &= ~current->fs->umask;
6815 -       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
6816 +       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode, &nd);
6817         dput(dentry);
6818  out_unlock:
6819         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6820 @@ -2020,9 +2123,10 @@ void dentry_unhash(struct dentry *dentry
6821         spin_unlock(&dcache_lock);
6822  }
6823  
6824 -int vfs_rmdir(struct inode *dir, struct dentry *dentry)
6825 +int vfs_rmdir(struct inode *dir, struct dentry *dentry,
6826 +       struct nameidata *nd)
6827  {
6828 -       int error = may_delete(dir, dentry, 1);
6829 +       int error = may_delete(dir, dentry, 1, nd);
6830  
6831         if (error)
6832                 return error;
6833 @@ -2084,7 +2188,7 @@ static long do_rmdir(int dfd, const char
6834         error = PTR_ERR(dentry);
6835         if (IS_ERR(dentry))
6836                 goto exit2;
6837 -       error = vfs_rmdir(nd.dentry->d_inode, dentry);
6838 +       error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
6839         dput(dentry);
6840  exit2:
6841         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6842 @@ -2100,9 +2204,10 @@ asmlinkage long sys_rmdir(const char __u
6843         return do_rmdir(AT_FDCWD, pathname);
6844  }
6845  
6846 -int vfs_unlink(struct inode *dir, struct dentry *dentry)
6847 +int vfs_unlink(struct inode *dir, struct dentry *dentry,
6848 +       struct nameidata *nd)
6849  {
6850 -       int error = may_delete(dir, dentry, 0);
6851 +       int error = may_delete(dir, dentry, 0, nd);
6852  
6853         if (error)
6854                 return error;
6855 @@ -2164,7 +2269,7 @@ static long do_unlinkat(int dfd, const c
6856                 inode = dentry->d_inode;
6857                 if (inode)
6858                         atomic_inc(&inode->i_count);
6859 -               error = vfs_unlink(nd.dentry->d_inode, dentry);
6860 +               error = vfs_unlink(nd.dentry->d_inode, dentry, &nd);
6861         exit2:
6862                 dput(dentry);
6863         }
6864 @@ -2199,9 +2304,10 @@ asmlinkage long sys_unlink(const char __
6865         return do_unlinkat(AT_FDCWD, pathname);
6866  }
6867  
6868 -int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
6869 +int vfs_symlink(struct inode *dir, struct dentry *dentry,
6870 +       const char *oldname, int mode, struct nameidata *nd)
6871  {
6872 -       int error = may_create(dir, dentry, NULL);
6873 +       int error = may_create(dir, dentry, nd);
6874  
6875         if (error)
6876                 return error;
6877 @@ -2245,7 +2351,7 @@ asmlinkage long sys_symlinkat(const char
6878         if (IS_ERR(dentry))
6879                 goto out_unlock;
6880  
6881 -       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
6882 +       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO, &nd);
6883         dput(dentry);
6884  out_unlock:
6885         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6886 @@ -2262,7 +2368,8 @@ asmlinkage long sys_symlink(const char _
6887         return sys_symlinkat(oldname, AT_FDCWD, newname);
6888  }
6889  
6890 -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
6891 +int vfs_link(struct dentry *old_dentry, struct inode *dir,
6892 +       struct dentry *new_dentry, struct nameidata *nd)
6893  {
6894         struct inode *inode = old_dentry->d_inode;
6895         int error;
6896 @@ -2270,7 +2377,7 @@ int vfs_link(struct dentry *old_dentry, 
6897         if (!inode)
6898                 return -ENOENT;
6899  
6900 -       error = may_create(dir, new_dentry, NULL);
6901 +       error = may_create(dir, new_dentry, nd);
6902         if (error)
6903                 return error;
6904  
6905 @@ -2280,7 +2387,7 @@ int vfs_link(struct dentry *old_dentry, 
6906         /*
6907          * A link to an append-only or immutable file cannot be created.
6908          */
6909 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
6910 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
6911                 return -EPERM;
6912         if (!dir->i_op || !dir->i_op->link)
6913                 return -EPERM;
6914 @@ -2340,7 +2447,7 @@ asmlinkage long sys_linkat(int olddfd, c
6915         error = PTR_ERR(new_dentry);
6916         if (IS_ERR(new_dentry))
6917                 goto out_unlock;
6918 -       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
6919 +       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
6920         dput(new_dentry);
6921  out_unlock:
6922         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6923 @@ -2472,14 +2579,14 @@ int vfs_rename(struct inode *old_dir, st
6924         if (old_dentry->d_inode == new_dentry->d_inode)
6925                 return 0;
6926   
6927 -       error = may_delete(old_dir, old_dentry, is_dir);
6928 +       error = may_delete(old_dir, old_dentry, is_dir, NULL);
6929         if (error)
6930                 return error;
6931  
6932         if (!new_dentry->d_inode)
6933                 error = may_create(new_dir, new_dentry, NULL);
6934         else
6935 -               error = may_delete(new_dir, new_dentry, is_dir);
6936 +               error = may_delete(new_dir, new_dentry, is_dir, NULL);
6937         if (error)
6938                 return error;
6939  
6940 @@ -2557,6 +2664,9 @@ static int do_rename(int olddfd, const c
6941         error = -EINVAL;
6942         if (old_dentry == trap)
6943                 goto exit4;
6944 +       error = -EROFS;
6945 +       if (MNT_IS_RDONLY(newnd.mnt))
6946 +               goto exit4;
6947         new_dentry = lookup_hash(&newnd);
6948         error = PTR_ERR(new_dentry);
6949         if (IS_ERR(new_dentry))
6950 @@ -2650,6 +2760,216 @@ int vfs_follow_link(struct nameidata *nd
6951         return __vfs_follow_link(nd, link);
6952  }
6953  
6954 +
6955 +#ifdef CONFIG_VSERVER_COWBL
6956 +
6957 +#include <linux/file.h>
6958 +
6959 +static inline
6960 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6961 +{
6962 +       loff_t ppos = 0;
6963 +
6964 +       return do_splice_direct(in, &ppos, out, len, 0);
6965 +}
6966 +
6967 +struct dentry *cow_break_link(const char *pathname)
6968 +{
6969 +       int ret, mode, pathlen, redo = 0;
6970 +       struct nameidata old_nd, dir_nd;
6971 +       struct dentry *old_dentry, *new_dentry;
6972 +       struct dentry *dir, *res = NULL;
6973 +       struct vfsmount *old_mnt, *new_mnt;
6974 +       struct file *old_file;
6975 +       struct file *new_file;
6976 +       char *to, *path, pad='\251';
6977 +       loff_t size;
6978 +
6979 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
6980 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6981 +       ret = -ENOMEM;
6982 +       if (!path)
6983 +               goto out;
6984 +
6985 +       /* old_nd will have refs to dentry and mnt */
6986 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
6987 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
6988 +       if (ret < 0)
6989 +               goto out_free_path;
6990 +
6991 +       old_dentry = old_nd.dentry;
6992 +       old_mnt = old_nd.mnt;
6993 +       mode = old_dentry->d_inode->i_mode;
6994 +
6995 +       to = d_path(old_dentry, old_mnt, path, PATH_MAX-2);
6996 +       pathlen = strlen(to);
6997 +       vxdprintk(VXD_CBIT(misc, 2), "old path »%s« [»%.*s«:%d]", to,
6998 +               old_dentry->d_name.len, old_dentry->d_name.name,
6999 +               old_dentry->d_name.len);
7000 +
7001 +       to[pathlen + 1] = 0;
7002 +retry:
7003 +       to[pathlen] = pad--;
7004 +       ret = -EMLINK;
7005 +       if (pad <= '\240')
7006 +               goto out_rel_old;
7007 +
7008 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
7009 +       /* dir_nd will have refs to dentry and mnt */
7010 +       ret = path_lookup(to,
7011 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
7012 +       vxdprintk(VXD_CBIT(misc, 2),
7013 +               "path_lookup(new): %d", ret);
7014 +       if (ret < 0)
7015 +               goto retry;
7016 +
7017 +       /* this puppy downs the inode mutex */
7018 +       new_dentry = lookup_create(&dir_nd, 0);
7019 +       vxdprintk(VXD_CBIT(misc, 2),
7020 +               "lookup_create(new): %p [»%.*s«:%d]", new_dentry,
7021 +               new_dentry->d_name.len, new_dentry->d_name.name,
7022 +               new_dentry->d_name.len);
7023 +       if (!new_dentry || IS_ERR(new_dentry)) {
7024 +               path_release(&dir_nd);
7025 +               goto retry;
7026 +       }
7027 +       dir = dir_nd.dentry;
7028 +
7029 +       ret = vfs_create(dir_nd.dentry->d_inode, new_dentry, mode, &dir_nd);
7030 +       vxdprintk(VXD_CBIT(misc, 2),
7031 +               "vfs_create(new): %d", ret);
7032 +       if (ret == -EEXIST) {
7033 +               mutex_unlock(&dir->d_inode->i_mutex);
7034 +               dput(new_dentry);
7035 +               path_release(&dir_nd);
7036 +               goto retry;
7037 +       }
7038 +       else if (ret < 0)
7039 +               goto out_unlock_new;
7040 +
7041 +       /* drop out early, ret passes ENOENT */
7042 +       ret = -ENOENT;
7043 +       if ((redo = d_unhashed(old_dentry)))
7044 +               goto out_unlock_new;
7045 +
7046 +       new_mnt = dir_nd.mnt;
7047 +       dget(old_dentry);
7048 +       mntget(old_mnt);
7049 +       /* this one cleans up the dentry/mnt in case of failure */
7050 +       old_file = dentry_open(old_dentry, old_mnt, O_RDONLY);
7051 +       vxdprintk(VXD_CBIT(misc, 2),
7052 +               "dentry_open(old): %p", old_file);
7053 +       if (!old_file || IS_ERR(old_file)) {
7054 +               res = IS_ERR(old_file) ? (void *) old_file : res;
7055 +               goto out_unlock_new;
7056 +       }
7057 +
7058 +       dget(new_dentry);
7059 +       mntget(new_mnt);
7060 +       /* this one cleans up the dentry/mnt in case of failure */
7061 +       new_file = dentry_open(new_dentry, new_mnt, O_WRONLY);
7062 +       vxdprintk(VXD_CBIT(misc, 2),
7063 +               "dentry_open(new): %p", new_file);
7064 +
7065 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
7066 +       if (!new_file || IS_ERR(new_file))
7067 +               goto out_fput_old;
7068 +
7069 +       size = i_size_read(old_file->f_dentry->d_inode);
7070 +       ret = do_cow_splice(old_file, new_file, size);
7071 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
7072 +       if (ret < 0) {
7073 +               goto out_fput_both;
7074 +       } else if (ret < size) {
7075 +               ret = -ENOSPC;
7076 +               goto out_fput_both;
7077 +       } else {
7078 +               struct inode *old_inode = old_dentry->d_inode;
7079 +               struct inode *new_inode = new_dentry->d_inode;
7080 +               struct iattr attr = {
7081 +                       .ia_uid = old_inode->i_uid,
7082 +                       .ia_gid = old_inode->i_gid,
7083 +                       .ia_valid = ATTR_UID | ATTR_GID
7084 +                       };
7085 +
7086 +               ret = inode_setattr(new_inode, &attr);
7087 +               if (ret)
7088 +                       goto out_fput_both;
7089 +       }
7090 +
7091 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
7092 +
7093 +       /* drop out late */
7094 +       ret = -ENOENT;
7095 +       if ((redo = d_unhashed(old_dentry)))
7096 +               goto out_unlock;
7097 +
7098 +       vxdprintk(VXD_CBIT(misc, 2),
7099 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
7100 +               new_dentry->d_name.len, new_dentry->d_name.name,
7101 +               new_dentry->d_name.len,
7102 +               old_dentry->d_name.len, old_dentry->d_name.name,
7103 +               old_dentry->d_name.len);
7104 +       ret = vfs_rename(dir_nd.dentry->d_inode, new_dentry,
7105 +               old_nd.dentry->d_parent->d_inode, old_dentry);
7106 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
7107 +       res = new_dentry;
7108 +
7109 +out_unlock:
7110 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
7111 +
7112 +out_fput_both:
7113 +       vxdprintk(VXD_CBIT(misc, 3),
7114 +               "fput(new_file=%p[#%d])", new_file,
7115 +               atomic_read(&new_file->f_count));
7116 +       fput(new_file);
7117 +
7118 +out_fput_old:
7119 +       vxdprintk(VXD_CBIT(misc, 3),
7120 +               "fput(old_file=%p[#%d])", old_file,
7121 +               atomic_read(&old_file->f_count));
7122 +       fput(old_file);
7123 +
7124 +out_unlock_new:
7125 +       mutex_unlock(&dir->d_inode->i_mutex);
7126 +       if (!ret)
7127 +               goto out_redo;
7128 +
7129 +       /* error path cleanup */
7130 +       vfs_unlink(dir->d_inode, new_dentry, &dir_nd);
7131 +       dput(new_dentry);
7132 +
7133 +out_redo:
7134 +       if (!redo)
7135 +               goto out_rel_both;
7136 +       /* lookup dentry once again */
7137 +       path_release(&old_nd);
7138 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
7139 +       if (ret)
7140 +               goto out_rel_both;
7141 +
7142 +       new_dentry = old_nd.dentry;
7143 +       vxdprintk(VXD_CBIT(misc, 2),
7144 +               "path_lookup(redo): %p [»%.*s«:%d]", new_dentry,
7145 +               new_dentry->d_name.len, new_dentry->d_name.name,
7146 +               new_dentry->d_name.len);
7147 +       dget(new_dentry);
7148 +       res = new_dentry;
7149 +
7150 +out_rel_both:
7151 +       path_release(&dir_nd);
7152 +out_rel_old:
7153 +       path_release(&old_nd);
7154 +out_free_path:
7155 +       kfree(path);
7156 +out:
7157 +       if (ret)
7158 +               res = ERR_PTR(ret);
7159 +       return res;
7160 +}
7161 +
7162 +#endif
7163 +
7164  /* get the link contents into pagecache */
7165  static char *page_getlink(struct dentry * dentry, struct page **ppage)
7166  {
7167 diff -NurpP --minimal linux-2.6.22.10/fs/namespace.c linux-2.6.22.10-vs2.3.0.29/fs/namespace.c
7168 --- linux-2.6.22.10/fs/namespace.c      2007-07-09 13:19:27 +0200
7169 +++ linux-2.6.22.10-vs2.3.0.29/fs/namespace.c   2007-09-05 02:29:17 +0200
7170 @@ -25,6 +25,11 @@
7171  #include <linux/security.h>
7172  #include <linux/mount.h>
7173  #include <linux/ramfs.h>
7174 +#include <linux/vs_base.h>
7175 +#include <linux/vs_context.h>
7176 +#include <linux/vs_tag.h>
7177 +#include <linux/vserver/space.h>
7178 +#include <linux/vserver/global.h>
7179  #include <asm/uaccess.h>
7180  #include <asm/unistd.h>
7181  #include "pnode.h"
7182 @@ -240,6 +245,7 @@ static struct vfsmount *clone_mnt(struct
7183                 mnt->mnt_root = dget(root);
7184                 mnt->mnt_mountpoint = mnt->mnt_root;
7185                 mnt->mnt_parent = mnt;
7186 +               mnt->mnt_tag = old->mnt_tag;
7187  
7188                 if (flag & CL_SLAVE) {
7189                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
7190 @@ -348,48 +354,91 @@ static inline void mangle(struct seq_fil
7191         seq_escape(m, s, " \t\n\\");
7192  }
7193  
7194 +static int mnt_is_reachable(struct vfsmount *mnt)
7195 +{
7196 +       struct vfsmount *root_mnt;
7197 +       struct dentry *root, *point;
7198 +       int ret;
7199 +
7200 +       if (mnt == mnt->mnt_ns->root)
7201 +               return 1;
7202 +
7203 +       spin_lock(&vfsmount_lock);
7204 +       root_mnt = current->fs->rootmnt;
7205 +       root = current->fs->root;
7206 +       point = root;
7207 +
7208 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
7209 +               point = mnt->mnt_mountpoint;
7210 +               mnt = mnt->mnt_parent;
7211 +       }
7212 +
7213 +       ret = (mnt == root_mnt) && is_subdir(point, root);
7214 +
7215 +       spin_unlock(&vfsmount_lock);
7216 +
7217 +       return ret;
7218 +}
7219 +
7220  static int show_vfsmnt(struct seq_file *m, void *v)
7221  {
7222         struct vfsmount *mnt = v;
7223         int err = 0;
7224         static struct proc_fs_info {
7225 -               int flag;
7226 -               char *str;
7227 +               int s_flag;
7228 +               int mnt_flag;
7229 +               char *set_str;
7230 +               char *unset_str;
7231         } fs_info[] = {
7232 -               { MS_SYNCHRONOUS, ",sync" },
7233 -               { MS_DIRSYNC, ",dirsync" },
7234 -               { MS_MANDLOCK, ",mand" },
7235 -               { 0, NULL }
7236 -       };
7237 -       static struct proc_fs_info mnt_info[] = {
7238 -               { MNT_NOSUID, ",nosuid" },
7239 -               { MNT_NODEV, ",nodev" },
7240 -               { MNT_NOEXEC, ",noexec" },
7241 -               { MNT_NOATIME, ",noatime" },
7242 -               { MNT_NODIRATIME, ",nodiratime" },
7243 -               { MNT_RELATIME, ",relatime" },
7244 -               { 0, NULL }
7245 +               { MS_RDONLY, MNT_RDONLY, "ro", "rw" },
7246 +               { MS_SYNCHRONOUS, 0, ",sync", NULL },
7247 +               { MS_DIRSYNC, 0, ",dirsync", NULL },
7248 +               { MS_MANDLOCK, 0, ",mand", NULL },
7249 +               { MS_TAGGED, 0, ",tag", NULL },
7250 +               { MS_NOATIME, MNT_NOATIME, ",noatime", NULL },
7251 +               { MS_NODIRATIME, MNT_NODIRATIME, ",nodiratime", NULL },
7252 +               { MS_RELATIME, MNT_RELATIME, ",relatime", NULL },
7253 +               { 0, MNT_NOSUID, ",nosuid", NULL },
7254 +               { 0, MNT_NODEV, ",nodev", NULL },
7255 +               { 0, MNT_NOEXEC, ",noexec", NULL },
7256 +               { 0, 0, NULL, NULL }
7257         };
7258 -       struct proc_fs_info *fs_infop;
7259 +       struct proc_fs_info *p;
7260 +       unsigned long s_flags = mnt->mnt_sb->s_flags;
7261 +       int mnt_flags = mnt->mnt_flags;
7262  
7263 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
7264 -       seq_putc(m, ' ');
7265 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7266 -       seq_putc(m, ' ');
7267 -       mangle(m, mnt->mnt_sb->s_type->name);
7268 -       if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
7269 -               seq_putc(m, '.');
7270 -               mangle(m, mnt->mnt_sb->s_subtype);
7271 -       }
7272 -       seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
7273 -       for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
7274 -               if (mnt->mnt_sb->s_flags & fs_infop->flag)
7275 -                       seq_puts(m, fs_infop->str);
7276 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7277 +               return 0;
7278 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7279 +               return 0;
7280 +
7281 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7282 +               mnt == current->fs->rootmnt) {
7283 +               seq_puts(m, "/dev/root / ");
7284 +       } else {
7285 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
7286 +               seq_putc(m, ' ');
7287 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7288 +               seq_putc(m, ' ');
7289 +
7290 +               if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
7291 +                       seq_putc(m, '.');
7292 +                       mangle(m, mnt->mnt_sb->s_subtype);
7293 +               }
7294         }
7295 -       for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
7296 -               if (mnt->mnt_flags & fs_infop->flag)
7297 -                       seq_puts(m, fs_infop->str);
7298 +       mangle(m, mnt->mnt_sb->s_type->name);
7299 +       seq_putc(m, ' ');
7300 +       for (p = fs_info; (p->s_flag | p->mnt_flag) ; p++) {
7301 +               if ((s_flags & p->s_flag) || (mnt_flags & p->mnt_flag)) {
7302 +                       if (p->set_str)
7303 +                               seq_puts(m, p->set_str);
7304 +               } else {
7305 +                       if (p->unset_str)
7306 +                               seq_puts(m, p->unset_str);
7307 +               }
7308         }
7309 +       if (mnt->mnt_flags & MNT_TAGID)
7310 +               seq_printf(m, ",tag=%d", mnt->mnt_tag);
7311         if (mnt->mnt_sb->s_op->show_options)
7312                 err = mnt->mnt_sb->s_op->show_options(m, mnt);
7313         seq_puts(m, " 0 0\n");
7314 @@ -408,17 +457,27 @@ static int show_vfsstat(struct seq_file 
7315         struct vfsmount *mnt = v;
7316         int err = 0;
7317  
7318 -       /* device */
7319 -       if (mnt->mnt_devname) {
7320 -               seq_puts(m, "device ");
7321 -               mangle(m, mnt->mnt_devname);
7322 -       } else
7323 -               seq_puts(m, "no device");
7324 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7325 +               return 0;
7326 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7327 +               return 0;
7328  
7329 -       /* mount point */
7330 -       seq_puts(m, " mounted on ");
7331 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7332 -       seq_putc(m, ' ');
7333 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7334 +               mnt == current->fs->rootmnt) {
7335 +               seq_puts(m, "device /dev/root mounted on / ");
7336 +       } else {
7337 +               /* device */
7338 +               if (mnt->mnt_devname) {
7339 +                       seq_puts(m, "device ");
7340 +                       mangle(m, mnt->mnt_devname);
7341 +               } else
7342 +                       seq_puts(m, "no device");
7343 +
7344 +               /* mount point */
7345 +               seq_puts(m, " mounted on ");
7346 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7347 +               seq_putc(m, ' ');
7348 +       }
7349  
7350         /* file system type */
7351         seq_puts(m, "with fstype ");
7352 @@ -648,7 +707,7 @@ asmlinkage long sys_umount(char __user *
7353                 goto dput_and_out;
7354  
7355         retval = -EPERM;
7356 -       if (!capable(CAP_SYS_ADMIN))
7357 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7358                 goto dput_and_out;
7359  
7360         retval = do_umount(nd.mnt, flags);
7361 @@ -672,7 +731,7 @@ asmlinkage long sys_oldumount(char __use
7362  
7363  static int mount_is_safe(struct nameidata *nd)
7364  {
7365 -       if (capable(CAP_SYS_ADMIN))
7366 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7367                 return 0;
7368         return -EPERM;
7369  #ifdef notyet
7370 @@ -904,11 +963,13 @@ static int do_change_type(struct nameida
7371  /*
7372   * do loopback mount.
7373   */
7374 -static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
7375 +static int do_loopback(struct nameidata *nd, char *old_name, tag_t tag,
7376 +       unsigned long flags, int mnt_flags)
7377  {
7378         struct nameidata old_nd;
7379         struct vfsmount *mnt = NULL;
7380         int err = mount_is_safe(nd);
7381 +       int recurse = flags & MS_REC;
7382         if (err)
7383                 return err;
7384         if (!old_name || !*old_name)
7385 @@ -934,6 +995,12 @@ static int do_loopback(struct nameidata 
7386         if (!mnt)
7387                 goto out;
7388  
7389 +       mnt->mnt_flags = mnt_flags;
7390 +       if (flags & MS_TAGID) {
7391 +               mnt->mnt_tag = tag;
7392 +               mnt->mnt_flags |= MNT_TAGID;
7393 +       }
7394 +
7395         err = graft_tree(mnt, nd);
7396         if (err) {
7397                 LIST_HEAD(umount_list);
7398 @@ -942,6 +1009,7 @@ static int do_loopback(struct nameidata 
7399                 spin_unlock(&vfsmount_lock);
7400                 release_mounts(&umount_list);
7401         }
7402 +       mnt->mnt_flags = mnt_flags;
7403  
7404  out:
7405         up_write(&namespace_sem);
7406 @@ -955,12 +1023,12 @@ out:
7407   * on it - tough luck.
7408   */
7409  static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
7410 -                     void *data)
7411 +                     void *data, xid_t xid)
7412  {
7413         int err;
7414         struct super_block *sb = nd->mnt->mnt_sb;
7415  
7416 -       if (!capable(CAP_SYS_ADMIN))
7417 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
7418                 return -EPERM;
7419  
7420         if (!check_mnt(nd->mnt))
7421 @@ -994,7 +1062,7 @@ static int do_move_mount(struct nameidat
7422         struct nameidata old_nd, parent_nd;
7423         struct vfsmount *p;
7424         int err = 0;
7425 -       if (!capable(CAP_SYS_ADMIN))
7426 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7427                 return -EPERM;
7428         if (!old_name || !*old_name)
7429                 return -EINVAL;
7430 @@ -1074,7 +1142,7 @@ static int do_new_mount(struct nameidata
7431                 return -EINVAL;
7432  
7433         /* we need capabilities... */
7434 -       if (!capable(CAP_SYS_ADMIN))
7435 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7436                 return -EPERM;
7437  
7438         mnt = do_kern_mount(type, flags, name, data);
7439 @@ -1386,6 +1454,7 @@ long do_mount(char *dev_name, char *dir_
7440         struct nameidata nd;
7441         int retval = 0;
7442         int mnt_flags = 0;
7443 +       tag_t tag = 0;
7444  
7445         /* Discard magic */
7446         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
7447 @@ -1401,7 +1470,17 @@ long do_mount(char *dev_name, char *dir_
7448         if (data_page)
7449                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
7450  
7451 +       retval = dx_parse_tag(data_page, &tag, 1);
7452 +       if (retval) {
7453 +               mnt_flags |= retval;
7454 +               /* FIXME: bind and re-mounts get the tag flag? */
7455 +               if (flags & (MS_BIND|MS_REMOUNT))
7456 +                       flags |= MS_TAGID;
7457 +       }
7458 +
7459         /* Separate the per-mountpoint flags */
7460 +       if (flags & MS_RDONLY)
7461 +               mnt_flags |= MNT_RDONLY;
7462         if (flags & MS_NOSUID)
7463                 mnt_flags |= MNT_NOSUID;
7464         if (flags & MS_NODEV)
7465 @@ -1415,6 +1494,8 @@ long do_mount(char *dev_name, char *dir_
7466         if (flags & MS_RELATIME)
7467                 mnt_flags |= MNT_RELATIME;
7468  
7469 +       if (!capable(CAP_SYS_ADMIN))
7470 +               mnt_flags |= MNT_NODEV;
7471         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
7472                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME);
7473  
7474 @@ -1429,9 +1510,9 @@ long do_mount(char *dev_name, char *dir_
7475  
7476         if (flags & MS_REMOUNT)
7477                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
7478 -                                   data_page);
7479 +                                   data_page, tag);
7480         else if (flags & MS_BIND)
7481 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
7482 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
7483         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
7484                 retval = do_change_type(&nd, flags);
7485         else if (flags & MS_MOVE)
7486 @@ -1504,6 +1585,7 @@ static struct mnt_namespace *dup_mnt_ns(
7487                 q = next_mnt(q, new_ns->root);
7488         }
7489         up_write(&namespace_sem);
7490 +       atomic_inc(&vs_global_mnt_ns);
7491  
7492         if (rootmnt)
7493                 mntput(rootmnt);
7494 @@ -1866,5 +1948,6 @@ void __put_mnt_ns(struct mnt_namespace *
7495         spin_unlock(&vfsmount_lock);
7496         up_write(&namespace_sem);
7497         release_mounts(&umount_list);
7498 +       atomic_dec(&vs_global_mnt_ns);
7499         kfree(ns);
7500  }
7501 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/client.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/client.c
7502 --- linux-2.6.22.10/fs/nfs/client.c     2007-07-09 13:19:27 +0200
7503 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/client.c  2007-08-05 20:53:13 +0200
7504 @@ -521,6 +521,9 @@ static int nfs_init_server_rpcclient(str
7505         if (server->flags & NFS4_MOUNT_INTR)
7506                 server->client->cl_intr = 1;
7507  
7508 +       server->client->cl_tag = 0;
7509 +       if (server->flags & NFS_MOUNT_TAGGED)
7510 +               server->client->cl_tag = 1;
7511         return 0;
7512  }
7513  
7514 @@ -678,6 +681,10 @@ static void nfs_server_set_fsinfo(struct
7515                 server->acdirmin = server->acdirmax = 0;
7516         }
7517  
7518 +       /* FIXME: needs fsinfo
7519 +       if (server->flags & NFS_MOUNT_TAGGED)
7520 +               sb->s_flags |= MS_TAGGED;       */
7521 +
7522         server->maxfilesize = fsinfo->maxfilesize;
7523  
7524         /* We're airborne Set socket buffersize */
7525 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/dir.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/dir.c
7526 --- linux-2.6.22.10/fs/nfs/dir.c        2007-07-09 13:19:27 +0200
7527 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/dir.c     2007-08-05 20:53:13 +0200
7528 @@ -34,6 +34,7 @@
7529  #include <linux/namei.h>
7530  #include <linux/mount.h>
7531  #include <linux/sched.h>
7532 +#include <linux/vs_tag.h>
7533  
7534  #include "nfs4_fs.h"
7535  #include "delegation.h"
7536 @@ -956,6 +957,7 @@ static struct dentry *nfs_lookup(struct 
7537         if (IS_ERR(res))
7538                 goto out_unlock;
7539  
7540 +       dx_propagate_tag(nd, inode);
7541  no_entry:
7542         res = d_materialise_unique(dentry, inode);
7543         if (res != NULL) {
7544 @@ -998,7 +1000,8 @@ static int is_atomic_open(struct inode *
7545         if (nd->flags & LOOKUP_DIRECTORY)
7546                 return 0;
7547         /* Are we trying to write to a read only partition? */
7548 -       if (IS_RDONLY(dir) && (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7549 +       if ((IS_RDONLY(dir) || MNT_IS_RDONLY(nd->mnt)) &&
7550 +               (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7551                 return 0;
7552         return 1;
7553  }
7554 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/inode.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/inode.c
7555 --- linux-2.6.22.10/fs/nfs/inode.c      2007-07-09 13:19:27 +0200
7556 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/inode.c   2007-08-05 20:53:13 +0200
7557 @@ -37,6 +37,7 @@
7558  #include <linux/vfs.h>
7559  #include <linux/inet.h>
7560  #include <linux/nfs_xdr.h>
7561 +#include <linux/vs_tag.h>
7562  
7563  #include <asm/system.h>
7564  #include <asm/uaccess.h>
7565 @@ -285,8 +286,10 @@ nfs_fhget(struct super_block *sb, struct
7566                         nfsi->change_attr = fattr->change_attr;
7567                 inode->i_size = nfs_size_to_loff_t(fattr->size);
7568                 inode->i_nlink = fattr->nlink;
7569 -               inode->i_uid = fattr->uid;
7570 -               inode->i_gid = fattr->gid;
7571 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7572 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7573 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7574 +                                        /* maybe fattr->xid someday */
7575                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7576                         /*
7577                          * report the blocks in 512byte units
7578 @@ -377,6 +380,8 @@ void nfs_setattr_update_inode(struct ino
7579                         inode->i_uid = attr->ia_uid;
7580                 if ((attr->ia_valid & ATTR_GID) != 0)
7581                         inode->i_gid = attr->ia_gid;
7582 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
7583 +                       inode->i_tag = attr->ia_tag;
7584                 spin_lock(&inode->i_lock);
7585                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7586                 spin_unlock(&inode->i_lock);
7587 @@ -825,6 +830,9 @@ static int nfs_check_inode_attributes(st
7588         struct nfs_inode *nfsi = NFS_I(inode);
7589         loff_t cur_size, new_isize;
7590         int data_unstable;
7591 +       uid_t uid;
7592 +       gid_t gid;
7593 +       tag_t tag;
7594  
7595  
7596         /* Has the inode gone and changed behind our back? */
7597 @@ -852,10 +860,15 @@ static int nfs_check_inode_attributes(st
7598         if (cur_size != new_isize && nfsi->npages == 0)
7599                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
7600  
7601 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7602 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7603 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7604 +
7605         /* Have any file permissions changed? */
7606         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
7607 -                       || inode->i_uid != fattr->uid
7608 -                       || inode->i_gid != fattr->gid)
7609 +                       || inode->i_uid != uid
7610 +                       || inode->i_gid != gid
7611 +                       || inode->i_tag != tag)
7612                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7613  
7614         /* Has the link count changed? */
7615 @@ -946,6 +959,9 @@ static int nfs_update_inode(struct inode
7616         unsigned int    invalid = 0;
7617         unsigned long now = jiffies;
7618         int data_stable;
7619 +       uid_t uid;
7620 +       gid_t gid;
7621 +       tag_t tag;
7622  
7623         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
7624                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
7625 @@ -1022,15 +1038,21 @@ static int nfs_update_inode(struct inode
7626         }
7627         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
7628  
7629 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7630 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7631 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7632 +
7633         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
7634 -           inode->i_uid != fattr->uid ||
7635 -           inode->i_gid != fattr->gid)
7636 +           inode->i_uid != uid ||
7637 +           inode->i_gid != gid ||
7638 +           inode->i_tag != tag)
7639                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7640  
7641         inode->i_mode = fattr->mode;
7642         inode->i_nlink = fattr->nlink;
7643 -       inode->i_uid = fattr->uid;
7644 -       inode->i_gid = fattr->gid;
7645 +       inode->i_uid = uid;
7646 +       inode->i_gid = gid;
7647 +       inode->i_tag = tag;
7648  
7649         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7650                 /*
7651 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/nfs3xdr.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/nfs3xdr.c
7652 --- linux-2.6.22.10/fs/nfs/nfs3xdr.c    2007-07-09 13:19:27 +0200
7653 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/nfs3xdr.c 2007-08-05 20:53:13 +0200
7654 @@ -22,6 +22,7 @@
7655  #include <linux/nfs3.h>
7656  #include <linux/nfs_fs.h>
7657  #include <linux/nfsacl.h>
7658 +#include <linux/vs_tag.h>
7659  #include "internal.h"
7660  
7661  #define NFSDBG_FACILITY                NFSDBG_XDR
7662 @@ -178,7 +179,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
7663  }
7664  
7665  static inline __be32 *
7666 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
7667 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
7668  {
7669         if (attr->ia_valid & ATTR_MODE) {
7670                 *p++ = xdr_one;
7671 @@ -186,15 +187,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
7672         } else {
7673                 *p++ = xdr_zero;
7674         }
7675 -       if (attr->ia_valid & ATTR_UID) {
7676 +       if (attr->ia_valid & ATTR_UID ||
7677 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7678                 *p++ = xdr_one;
7679 -               *p++ = htonl(attr->ia_uid);
7680 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
7681         } else {
7682                 *p++ = xdr_zero;
7683         }
7684 -       if (attr->ia_valid & ATTR_GID) {
7685 +       if (attr->ia_valid & ATTR_GID ||
7686 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7687                 *p++ = xdr_one;
7688 -               *p++ = htonl(attr->ia_gid);
7689 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
7690         } else {
7691                 *p++ = xdr_zero;
7692         }
7693 @@ -279,7 +282,8 @@ static int
7694  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
7695  {
7696         p = xdr_encode_fhandle(p, args->fh);
7697 -       p = xdr_encode_sattr(p, args->sattr);
7698 +       p = xdr_encode_sattr(p, args->sattr,
7699 +               req->rq_task->tk_client->cl_tag);
7700         *p++ = htonl(args->guard);
7701         if (args->guard)
7702                 p = xdr_encode_time3(p, &args->guardtime);
7703 @@ -370,7 +374,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
7704                 *p++ = args->verifier[0];
7705                 *p++ = args->verifier[1];
7706         } else
7707 -               p = xdr_encode_sattr(p, args->sattr);
7708 +               p = xdr_encode_sattr(p, args->sattr,
7709 +                       req->rq_task->tk_client->cl_tag);
7710  
7711         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7712         return 0;
7713 @@ -384,7 +389,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
7714  {
7715         p = xdr_encode_fhandle(p, args->fh);
7716         p = xdr_encode_array(p, args->name, args->len);
7717 -       p = xdr_encode_sattr(p, args->sattr);
7718 +       p = xdr_encode_sattr(p, args->sattr,
7719 +               req->rq_task->tk_client->cl_tag);
7720         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7721         return 0;
7722  }
7723 @@ -397,7 +403,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
7724  {
7725         p = xdr_encode_fhandle(p, args->fromfh);
7726         p = xdr_encode_array(p, args->fromname, args->fromlen);
7727 -       p = xdr_encode_sattr(p, args->sattr);
7728 +       p = xdr_encode_sattr(p, args->sattr,
7729 +               req->rq_task->tk_client->cl_tag);
7730         *p++ = htonl(args->pathlen);
7731         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7732  
7733 @@ -415,7 +422,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
7734         p = xdr_encode_fhandle(p, args->fh);
7735         p = xdr_encode_array(p, args->name, args->len);
7736         *p++ = htonl(args->type);
7737 -       p = xdr_encode_sattr(p, args->sattr);
7738 +       p = xdr_encode_sattr(p, args->sattr,
7739 +               req->rq_task->tk_client->cl_tag);
7740         if (args->type == NF3CHR || args->type == NF3BLK) {
7741                 *p++ = htonl(MAJOR(args->rdev));
7742                 *p++ = htonl(MINOR(args->rdev));
7743 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/nfsroot.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/nfsroot.c
7744 --- linux-2.6.22.10/fs/nfs/nfsroot.c    2007-07-09 13:19:27 +0200
7745 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/nfsroot.c 2007-08-05 20:53:13 +0200
7746 @@ -118,12 +118,12 @@ static int mount_port __initdata = 0;             /
7747  enum {
7748         /* Options that take integer arguments */
7749         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
7750 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
7751 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
7752         /* Options that take no arguments */
7753         Opt_soft, Opt_hard, Opt_intr,
7754         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
7755         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
7756 -       Opt_acl, Opt_noacl,
7757 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
7758         /* Error token */
7759         Opt_err
7760  };
7761 @@ -160,6 +160,9 @@ static match_table_t __initdata tokens =
7762         {Opt_tcp, "tcp"},
7763         {Opt_acl, "acl"},
7764         {Opt_noacl, "noacl"},
7765 +       {Opt_tag, "tag"},
7766 +       {Opt_notag, "notag"},
7767 +       {Opt_tagid, "tagid=%u"},
7768         {Opt_err, NULL}
7769         
7770  };
7771 @@ -274,6 +277,20 @@ static int __init root_nfs_parse(char *n
7772                         case Opt_noacl:
7773                                 nfs_data.flags |= NFS_MOUNT_NOACL;
7774                                 break;
7775 +#ifndef CONFIG_TAGGING_NONE
7776 +                       case Opt_tag:
7777 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7778 +                               break;
7779 +                       case Opt_notag:
7780 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
7781 +                               break;
7782 +#endif
7783 +#ifdef CONFIG_PROPAGATE
7784 +                       case Opt_tagid:
7785 +                               /* use args[0] */
7786 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7787 +                               break;
7788 +#endif
7789                         default:
7790                                 printk(KERN_WARNING "Root-NFS: unknown "
7791                                         "option: %s\n", p);
7792 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/super.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/super.c
7793 --- linux-2.6.22.10/fs/nfs/super.c      2007-10-30 01:57:14 +0100
7794 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/super.c   2007-09-30 14:58:01 +0200
7795 @@ -45,6 +45,7 @@
7796  #include <linux/inet.h>
7797  #include <linux/nfs_xdr.h>
7798  #include <linux/magic.h>
7799 +#include <linux/vs_tag.h>
7800  
7801  #include <asm/system.h>
7802  #include <asm/uaccess.h>
7803 @@ -291,6 +292,7 @@ static void nfs_show_mount_options(struc
7804                 { NFS_MOUNT_NONLM, ",nolock", "" },
7805                 { NFS_MOUNT_NOACL, ",noacl", "" },
7806                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
7807 +               { NFS_MOUNT_TAGGED, ",tag", "" },
7808                 { 0, NULL, NULL }
7809         };
7810         const struct proc_nfs_info *nfs_infop;
7811 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/auth.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/auth.c
7812 --- linux-2.6.22.10/fs/nfsd/auth.c      2006-06-18 04:54:42 +0200
7813 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/auth.c   2007-08-05 20:53:13 +0200
7814 @@ -9,6 +9,7 @@
7815  #include <linux/sunrpc/svc.h>
7816  #include <linux/sunrpc/svcauth.h>
7817  #include <linux/nfsd/nfsd.h>
7818 +#include <linux/vs_tag.h>
7819  
7820  #define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
7821  
7822 @@ -41,19 +42,22 @@ int nfsd_setuser(struct svc_rqst *rqstp,
7823                 get_group_info(cred.cr_group_info);
7824  
7825         if (cred.cr_uid != (uid_t) -1)
7826 -               current->fsuid = cred.cr_uid;
7827 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7828         else
7829                 current->fsuid = exp->ex_anon_uid;
7830         if (cred.cr_gid != (gid_t) -1)
7831 -               current->fsgid = cred.cr_gid;
7832 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7833         else
7834                 current->fsgid = exp->ex_anon_gid;
7835  
7836 +       /* this desperately needs a tag :) */
7837 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
7838 +
7839         if (!cred.cr_group_info)
7840                 return -ENOMEM;
7841         ret = set_current_groups(cred.cr_group_info);
7842         put_group_info(cred.cr_group_info);
7843 -       if ((cred.cr_uid)) {
7844 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
7845                 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
7846         } else {
7847                 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
7848 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs3xdr.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs3xdr.c
7849 --- linux-2.6.22.10/fs/nfsd/nfs3xdr.c   2007-07-09 13:19:27 +0200
7850 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs3xdr.c        2007-08-05 20:53:13 +0200
7851 @@ -21,6 +21,7 @@
7852  #include <linux/sunrpc/svc.h>
7853  #include <linux/nfsd/nfsd.h>
7854  #include <linux/nfsd/xdr3.h>
7855 +#include <linux/vs_tag.h>
7856  
7857  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7858  
7859 @@ -107,6 +108,8 @@ static __be32 *
7860  decode_sattr3(__be32 *p, struct iattr *iap)
7861  {
7862         u32     tmp;
7863 +       uid_t   uid = 0;
7864 +       gid_t   gid = 0;
7865  
7866         iap->ia_valid = 0;
7867  
7868 @@ -116,12 +119,15 @@ decode_sattr3(__be32 *p, struct iattr *i
7869         }
7870         if (*p++) {
7871                 iap->ia_valid |= ATTR_UID;
7872 -               iap->ia_uid = ntohl(*p++);
7873 +               uid = ntohl(*p++);
7874         }
7875         if (*p++) {
7876                 iap->ia_valid |= ATTR_GID;
7877 -               iap->ia_gid = ntohl(*p++);
7878 +               gid = ntohl(*p++);
7879         }
7880 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7881 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7882 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7883         if (*p++) {
7884                 u64     newsize;
7885  
7886 @@ -180,8 +186,10 @@ encode_fattr3(struct svc_rqst *rqstp, __
7887         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
7888         *p++ = htonl((u32) stat->mode);
7889         *p++ = htonl((u32) stat->nlink);
7890 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7891 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7892 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7893 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7894 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7895 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7896         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
7897                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
7898         } else {
7899 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs4recover.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs4recover.c
7900 --- linux-2.6.22.10/fs/nfsd/nfs4recover.c       2007-07-09 13:19:27 +0200
7901 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs4recover.c    2007-08-05 20:53:13 +0200
7902 @@ -156,7 +156,7 @@ nfsd4_create_clid_dir(struct nfs4_client
7903                 dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
7904                 goto out_put;
7905         }
7906 -       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU);
7907 +       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU, NULL);
7908  out_put:
7909         dput(dentry);
7910  out_unlock:
7911 @@ -260,7 +260,7 @@ nfsd4_remove_clid_file(struct dentry *di
7912                 return -EINVAL;
7913         }
7914         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7915 -       status = vfs_unlink(dir->d_inode, dentry);
7916 +       status = vfs_unlink(dir->d_inode, dentry, NULL);
7917         mutex_unlock(&dir->d_inode->i_mutex);
7918         return status;
7919  }
7920 @@ -275,7 +275,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,
7921          * a kernel from the future.... */
7922         nfsd4_list_rec_dir(dentry, nfsd4_remove_clid_file);
7923         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7924 -       status = vfs_rmdir(dir->d_inode, dentry);
7925 +       status = vfs_rmdir(dir->d_inode, dentry, NULL);
7926         mutex_unlock(&dir->d_inode->i_mutex);
7927         return status;
7928  }
7929 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs4xdr.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs4xdr.c
7930 --- linux-2.6.22.10/fs/nfsd/nfs4xdr.c   2007-07-09 13:19:27 +0200
7931 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs4xdr.c        2007-08-05 20:53:13 +0200
7932 @@ -56,6 +56,7 @@
7933  #include <linux/nfsd_idmap.h>
7934  #include <linux/nfs4.h>
7935  #include <linux/nfs4_acl.h>
7936 +#include <linux/vs_tag.h>
7937  
7938  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7939  
7940 @@ -1727,14 +1728,18 @@ out_acl:
7941                 WRITE32(stat.nlink);
7942         }
7943         if (bmval1 & FATTR4_WORD1_OWNER) {
7944 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7945 +               status = nfsd4_encode_user(rqstp,
7946 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7947 +                       stat.uid, stat.tag), &p, &buflen);
7948                 if (status == nfserr_resource)
7949                         goto out_resource;
7950                 if (status)
7951                         goto out;
7952         }
7953         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7954 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7955 +               status = nfsd4_encode_group(rqstp,
7956 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7957 +                       stat.gid, stat.tag), &p, &buflen);
7958                 if (status == nfserr_resource)
7959                         goto out_resource;
7960                 if (status)
7961 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfsxdr.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfsxdr.c
7962 --- linux-2.6.22.10/fs/nfsd/nfsxdr.c    2007-07-09 13:19:27 +0200
7963 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfsxdr.c 2007-08-05 20:53:13 +0200
7964 @@ -15,6 +15,7 @@
7965  #include <linux/nfsd/nfsd.h>
7966  #include <linux/nfsd/xdr.h>
7967  #include <linux/mm.h>
7968 +#include <linux/vs_tag.h>
7969  
7970  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7971  
7972 @@ -97,6 +98,8 @@ static __be32 *
7973  decode_sattr(__be32 *p, struct iattr *iap)
7974  {
7975         u32     tmp, tmp1;
7976 +       uid_t   uid = 0;
7977 +       gid_t   gid = 0;
7978  
7979         iap->ia_valid = 0;
7980  
7981 @@ -110,12 +113,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7982         }
7983         if ((tmp = ntohl(*p++)) != (u32)-1) {
7984                 iap->ia_valid |= ATTR_UID;
7985 -               iap->ia_uid = tmp;
7986 +               uid = tmp;
7987         }
7988         if ((tmp = ntohl(*p++)) != (u32)-1) {
7989                 iap->ia_valid |= ATTR_GID;
7990 -               iap->ia_gid = tmp;
7991 +               gid = tmp;
7992         }
7993 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7994 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7995 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7996         if ((tmp = ntohl(*p++)) != (u32)-1) {
7997                 iap->ia_valid |= ATTR_SIZE;
7998                 iap->ia_size = tmp;
7999 @@ -160,8 +166,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
8000         *p++ = htonl(nfs_ftypes[type >> 12]);
8001         *p++ = htonl((u32) stat->mode);
8002         *p++ = htonl((u32) stat->nlink);
8003 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
8004 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
8005 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
8006 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
8007 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
8008 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
8009  
8010         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
8011                 *p++ = htonl(NFS_MAXPATHLEN);
8012 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/vfs.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/vfs.c
8013 --- linux-2.6.22.10/fs/nfsd/vfs.c       2007-10-30 01:57:14 +0100
8014 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/vfs.c    2007-08-11 22:41:51 +0200
8015 @@ -1186,13 +1186,13 @@ nfsd_create(struct svc_rqst *rqstp, stru
8016                 host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
8017                 break;
8018         case S_IFDIR:
8019 -               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
8020 +               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode, NULL);
8021                 break;
8022         case S_IFCHR:
8023         case S_IFBLK:
8024         case S_IFIFO:
8025         case S_IFSOCK:
8026 -               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
8027 +               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev, NULL);
8028                 break;
8029         default:
8030                 printk("nfsd: bad file type %o in nfsd_create\n", type);
8031 @@ -1466,11 +1466,13 @@ nfsd_symlink(struct svc_rqst *rqstp, str
8032                 else {
8033                         strncpy(path_alloced, path, plen);
8034                         path_alloced[plen] = 0;
8035 -                       host_err = vfs_symlink(dentry->d_inode, dnew, path_alloced, mode);
8036 +                       host_err = vfs_symlink(dentry->d_inode, dnew,
8037 +                               path_alloced, mode, NULL);
8038                         kfree(path_alloced);
8039                 }
8040         } else
8041 -               host_err = vfs_symlink(dentry->d_inode, dnew, path, mode);
8042 +               host_err = vfs_symlink(dentry->d_inode, dnew,
8043 +                       path, mode, NULL);
8044  
8045         if (!host_err) {
8046                 if (EX_ISSYNC(fhp->fh_export))
8047 @@ -1529,7 +1531,7 @@ nfsd_link(struct svc_rqst *rqstp, struct
8048         dold = tfhp->fh_dentry;
8049         dest = dold->d_inode;
8050  
8051 -       host_err = vfs_link(dold, dirp, dnew);
8052 +       host_err = vfs_link(dold, dirp, dnew, NULL);
8053         if (!host_err) {
8054                 if (EX_ISSYNC(ffhp->fh_export)) {
8055                         err = nfserrno(nfsd_sync_dir(ddir));
8056 @@ -1694,9 +1696,9 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
8057                         host_err = -EPERM;
8058                 } else
8059  #endif
8060 -               host_err = vfs_unlink(dirp, rdentry);
8061 +               host_err = vfs_unlink(dirp, rdentry, NULL);
8062         } else { /* It's RMDIR */
8063 -               host_err = vfs_rmdir(dirp, rdentry);
8064 +               host_err = vfs_rmdir(dirp, rdentry, NULL);
8065         }
8066  
8067         dput(rdentry);
8068 @@ -1807,7 +1809,8 @@ nfsd_permission(struct svc_export *exp, 
8069          */
8070         if (!(acc & MAY_LOCAL_ACCESS))
8071                 if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
8072 -                       if (EX_RDONLY(exp) || IS_RDONLY(inode))
8073 +                       if (EX_RDONLY(exp) || IS_RDONLY(inode)
8074 +                               || MNT_IS_RDONLY(exp->ex_mnt))
8075                                 return nfserr_rofs;
8076                         if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
8077                                 return nfserr_perm;
8078 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/dlm/dlmfs.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlm/dlmfs.c
8079 --- linux-2.6.22.10/fs/ocfs2/dlm/dlmfs.c        2007-07-09 13:19:28 +0200
8080 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlm/dlmfs.c     2007-08-05 20:53:13 +0200
8081 @@ -43,6 +43,7 @@
8082  #include <linux/init.h>
8083  #include <linux/string.h>
8084  #include <linux/backing-dev.h>
8085 +#include <linux/vs_tag.h>
8086  
8087  #include <asm/uaccess.h>
8088  
8089 @@ -331,6 +332,7 @@ static struct inode *dlmfs_get_root_inod
8090                 inode->i_mode = mode;
8091                 inode->i_uid = current->fsuid;
8092                 inode->i_gid = current->fsgid;
8093 +               inode->i_tag = dx_current_fstag(sb);
8094                 inode->i_blocks = 0;
8095                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
8096                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
8097 @@ -357,6 +359,7 @@ static struct inode *dlmfs_get_inode(str
8098         inode->i_mode = mode;
8099         inode->i_uid = current->fsuid;
8100         inode->i_gid = current->fsgid;
8101 +       inode->i_tag = dx_current_fstag(sb);
8102         inode->i_blocks = 0;
8103         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
8104         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
8105 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/dlmglue.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlmglue.c
8106 --- linux-2.6.22.10/fs/ocfs2/dlmglue.c  2007-07-09 13:19:28 +0200
8107 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlmglue.c       2007-08-05 20:53:13 +0200
8108 @@ -1475,6 +1475,7 @@ static void __ocfs2_stuff_meta_lvb(struc
8109         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
8110         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
8111         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
8112 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
8113         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
8114         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
8115         lvb->lvb_iatime_packed  =
8116 @@ -1527,6 +1528,7 @@ static void ocfs2_refresh_inode_from_lvb
8117  
8118         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
8119         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
8120 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
8121         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
8122         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
8123         ocfs2_unpack_timespec(&inode->i_atime,
8124 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/dlmglue.h linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlmglue.h
8125 --- linux-2.6.22.10/fs/ocfs2/dlmglue.h  2007-07-09 13:19:28 +0200
8126 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlmglue.h       2007-08-05 20:53:13 +0200
8127 @@ -34,7 +34,7 @@
8128  struct ocfs2_meta_lvb {
8129         __u8         lvb_version;
8130         __u8         lvb_reserved0;
8131 -       __be16       lvb_reserved1;
8132 +       __be16       lvb_itag;
8133         __be32       lvb_iclusters;
8134         __be32       lvb_iuid;
8135         __be32       lvb_igid;
8136 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/file.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/file.c
8137 --- linux-2.6.22.10/fs/ocfs2/file.c     2007-10-30 01:57:14 +0100
8138 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/file.c  2007-09-05 03:06:11 +0200
8139 @@ -943,13 +943,15 @@ int ocfs2_setattr(struct dentry *dentry,
8140                 mlog(0, "uid change: %d\n", attr->ia_uid);
8141         if (attr->ia_valid & ATTR_GID)
8142                 mlog(0, "gid change: %d\n", attr->ia_gid);
8143 +       if (attr->ia_valid & ATTR_TAG)
8144 +               mlog(0, "tag change: %d\n", attr->ia_tag);
8145         if (attr->ia_valid & ATTR_SIZE)
8146                 mlog(0, "size change...\n");
8147         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
8148                 mlog(0, "time change...\n");
8149  
8150  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
8151 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
8152 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
8153         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
8154                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
8155                 return 0;
8156 @@ -1805,6 +1807,7 @@ bail:
8157  const struct inode_operations ocfs2_file_iops = {
8158         .setattr        = ocfs2_setattr,
8159         .getattr        = ocfs2_getattr,
8160 +       .sync_flags     = ocfs2_sync_flags,
8161         .permission     = ocfs2_permission,
8162  };
8163  
8164 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/inode.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/inode.c
8165 --- linux-2.6.22.10/fs/ocfs2/inode.c    2007-07-09 13:19:28 +0200
8166 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/inode.c 2007-08-05 20:53:13 +0200
8167 @@ -28,6 +28,7 @@
8168  #include <linux/slab.h>
8169  #include <linux/highmem.h>
8170  #include <linux/pagemap.h>
8171 +#include <linux/vs_tag.h>
8172  
8173  #include <asm/byteorder.h>
8174  
8175 @@ -42,6 +43,7 @@
8176  #include "file.h"
8177  #include "heartbeat.h"
8178  #include "inode.h"
8179 +#include "ioctl.h"
8180  #include "journal.h"
8181  #include "namei.h"
8182  #include "suballoc.h"
8183 @@ -77,6 +79,10 @@ void ocfs2_set_inode_flags(struct inode 
8184  
8185         if (flags & OCFS2_IMMUTABLE_FL)
8186                 inode->i_flags |= S_IMMUTABLE;
8187 +       if (flags & OCFS2_IUNLINK_FL)
8188 +               inode->i_flags |= S_IUNLINK;
8189 +       if (flags & OCFS2_BARRIER_FL)
8190 +               inode->i_flags |= S_BARRIER;
8191  
8192         if (flags & OCFS2_SYNC_FL)
8193                 inode->i_flags |= S_SYNC;
8194 @@ -107,6 +113,27 @@ void ocfs2_get_inode_flags(struct ocfs2_
8195                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
8196  }
8197  
8198 +int ocfs2_sync_flags(struct inode *inode)
8199 +{
8200 +       unsigned int oldflags, newflags;
8201 +
8202 +       oldflags = OCFS2_I(inode)->ip_flags;
8203 +       newflags = oldflags & ~(OCFS2_IMMUTABLE_FL |
8204 +               OCFS2_IUNLINK_FL | OCFS2_BARRIER_FL);
8205 +
8206 +       if (IS_IMMUTABLE(inode))
8207 +               newflags |= OCFS2_IMMUTABLE_FL;
8208 +       if (IS_IUNLINK(inode))
8209 +               newflags |= OCFS2_IUNLINK_FL;
8210 +       if (IS_BARRIER(inode))
8211 +               newflags |= OCFS2_BARRIER_FL;
8212 +
8213 +       if (oldflags ^ newflags)
8214 +               return ocfs2_set_inode_attr(inode,
8215 +                       newflags, OCFS2_FL_MASK);
8216 +       return 0;
8217 +}
8218 +
8219  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
8220  {
8221         struct inode *inode = NULL;
8222 @@ -212,6 +239,8 @@ int ocfs2_populate_inode(struct inode *i
8223         struct super_block *sb;
8224         struct ocfs2_super *osb;
8225         int status = -EINVAL;
8226 +       uid_t uid;
8227 +       gid_t gid;
8228  
8229         mlog_entry("(0x%p, size:%llu)\n", inode,
8230                    (unsigned long long)le64_to_cpu(fe->i_size));
8231 @@ -246,8 +275,12 @@ int ocfs2_populate_inode(struct inode *i
8232         inode->i_generation = le32_to_cpu(fe->i_generation);
8233         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
8234         inode->i_mode = le16_to_cpu(fe->i_mode);
8235 -       inode->i_uid = le32_to_cpu(fe->i_uid);
8236 -       inode->i_gid = le32_to_cpu(fe->i_gid);
8237 +       uid = le32_to_cpu(fe->i_uid);
8238 +       gid = le32_to_cpu(fe->i_gid);
8239 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8240 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8241 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
8242 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
8243  
8244         /* Fast symlinks will have i_size but no allocated clusters. */
8245         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
8246 @@ -1224,8 +1257,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
8247  
8248         fe->i_size = cpu_to_le64(i_size_read(inode));
8249         fe->i_links_count = cpu_to_le16(inode->i_nlink);
8250 -       fe->i_uid = cpu_to_le32(inode->i_uid);
8251 -       fe->i_gid = cpu_to_le32(inode->i_gid);
8252 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
8253 +               inode->i_uid, inode->i_tag));
8254 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
8255 +               inode->i_gid, inode->i_tag));
8256 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
8257         fe->i_mode = cpu_to_le16(inode->i_mode);
8258         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
8259         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
8260 @@ -1253,15 +1289,24 @@ leave:
8261  void ocfs2_refresh_inode(struct inode *inode,
8262                          struct ocfs2_dinode *fe)
8263  {
8264 +       uid_t uid;
8265 +       gid_t gid;
8266 +
8267         spin_lock(&OCFS2_I(inode)->ip_lock);
8268  
8269         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
8270         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
8271 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
8272 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
8273         ocfs2_set_inode_flags(inode);
8274         i_size_write(inode, le64_to_cpu(fe->i_size));
8275         inode->i_nlink = le16_to_cpu(fe->i_links_count);
8276 -       inode->i_uid = le32_to_cpu(fe->i_uid);
8277 -       inode->i_gid = le32_to_cpu(fe->i_gid);
8278 +       uid = le32_to_cpu(fe->i_uid);
8279 +       gid = le32_to_cpu(fe->i_gid);
8280 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8281 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8282 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
8283 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
8284         inode->i_mode = le16_to_cpu(fe->i_mode);
8285         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
8286                 inode->i_blocks = 0;
8287 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/inode.h linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/inode.h
8288 --- linux-2.6.22.10/fs/ocfs2/inode.h    2007-07-09 13:19:28 +0200
8289 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/inode.h 2007-08-05 20:53:13 +0200
8290 @@ -142,6 +142,7 @@ int ocfs2_aio_write(struct file *file, s
8291  
8292  void ocfs2_set_inode_flags(struct inode *inode);
8293  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
8294 +int ocfs2_sync_flags(struct inode *inode);
8295  
8296  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
8297  {
8298 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ioctl.c
8299 --- linux-2.6.22.10/fs/ocfs2/ioctl.c    2007-07-09 13:19:28 +0200
8300 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ioctl.c 2007-08-05 20:53:13 +0200
8301 @@ -39,7 +39,8 @@ static int ocfs2_get_inode_attr(struct i
8302         return status;
8303  }
8304  
8305 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8306 +/* Called with inode->i_mutex locked */
8307 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8308                                 unsigned mask)
8309  {
8310         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
8311 @@ -49,8 +50,6 @@ static int ocfs2_set_inode_attr(struct i
8312         unsigned oldflags;
8313         int status;
8314  
8315 -       mutex_lock(&inode->i_mutex);
8316 -
8317         status = ocfs2_meta_lock(inode, &bh, 1);
8318         if (status < 0) {
8319                 mlog_errno(status);
8320 @@ -101,8 +100,6 @@ static int ocfs2_set_inode_attr(struct i
8321  bail_unlock:
8322         ocfs2_meta_unlock(inode, 1);
8323  bail:
8324 -       mutex_unlock(&inode->i_mutex);
8325 -
8326         if (bh)
8327                 brelse(bh);
8328  
8329 @@ -110,6 +107,16 @@ bail:
8330         return status;
8331  }
8332  
8333 +static inline int ocfs2_set_inode_attr_lock(struct inode *inode,
8334 +       unsigned flags, unsigned mask)
8335 +{
8336 +       int ret;
8337 +       mutex_lock(&inode->i_mutex);
8338 +       ret = ocfs2_set_inode_attr(inode, flags, mask);
8339 +       mutex_unlock(&inode->i_mutex);
8340 +       return ret;
8341 +}
8342 +
8343  int ocfs2_ioctl(struct inode * inode, struct file * filp,
8344         unsigned int cmd, unsigned long arg)
8345  {
8346 @@ -128,7 +135,7 @@ int ocfs2_ioctl(struct inode * inode, st
8347                 if (get_user(flags, (int __user *) arg))
8348                         return -EFAULT;
8349  
8350 -               return ocfs2_set_inode_attr(inode, flags,
8351 +               return ocfs2_set_inode_attr_lock(inode, flags,
8352                         OCFS2_FL_MODIFIABLE);
8353         default:
8354                 return -ENOTTY;
8355 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ioctl.h linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ioctl.h
8356 --- linux-2.6.22.10/fs/ocfs2/ioctl.h    2007-07-09 13:19:28 +0200
8357 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ioctl.h 2007-08-05 20:53:13 +0200
8358 @@ -10,6 +10,9 @@
8359  #ifndef OCFS2_IOCTL_H
8360  #define OCFS2_IOCTL_H
8361  
8362 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8363 +                               unsigned mask);
8364 +
8365  int ocfs2_ioctl(struct inode * inode, struct file * filp,
8366         unsigned int cmd, unsigned long arg);
8367  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
8368 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/namei.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/namei.c
8369 --- linux-2.6.22.10/fs/ocfs2/namei.c    2007-07-09 13:19:28 +0200
8370 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/namei.c 2007-08-05 20:53:13 +0200
8371 @@ -40,6 +40,7 @@
8372  #include <linux/types.h>
8373  #include <linux/slab.h>
8374  #include <linux/highmem.h>
8375 +#include <linux/vs_tag.h>
8376  
8377  #define MLOG_MASK_PREFIX ML_NAMEI
8378  #include <cluster/masklog.h>
8379 @@ -483,6 +484,9 @@ static int ocfs2_mknod_locked(struct ocf
8380         u64 fe_blkno = 0;
8381         u16 suballoc_bit;
8382         struct inode *inode = NULL;
8383 +       uid_t uid;
8384 +       gid_t gid;
8385 +       tag_t tag;
8386  
8387         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
8388                    (unsigned long)dev, dentry->d_name.len,
8389 @@ -542,13 +546,19 @@ static int ocfs2_mknod_locked(struct ocf
8390         fe->i_blkno = cpu_to_le64(fe_blkno);
8391         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
8392         fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
8393 -       fe->i_uid = cpu_to_le32(current->fsuid);
8394 +
8395 +       tag = dx_current_fstag(osb->sb);
8396 +       uid = current->fsuid;
8397         if (dir->i_mode & S_ISGID) {
8398 -               fe->i_gid = cpu_to_le32(dir->i_gid);
8399 +               gid = dir->i_gid;
8400                 if (S_ISDIR(mode))
8401                         mode |= S_ISGID;
8402         } else
8403 -               fe->i_gid = cpu_to_le32(current->fsgid);
8404 +               gid = current->fsgid;
8405 +
8406 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
8407 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
8408 +       inode->i_tag = tag;
8409         fe->i_mode = cpu_to_le16(mode);
8410         if (S_ISCHR(mode) || S_ISBLK(mode))
8411                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
8412 @@ -2316,5 +2326,6 @@ const struct inode_operations ocfs2_dir_
8413         .rename         = ocfs2_rename,
8414         .setattr        = ocfs2_setattr,
8415         .getattr        = ocfs2_getattr,
8416 +       .sync_flags     = ocfs2_sync_flags,
8417         .permission     = ocfs2_permission,
8418  };
8419 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ocfs2.h linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ocfs2.h
8420 --- linux-2.6.22.10/fs/ocfs2/ocfs2.h    2007-07-09 13:19:28 +0200
8421 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ocfs2.h 2007-08-05 20:53:13 +0200
8422 @@ -170,6 +170,7 @@ enum ocfs2_mount_options
8423         OCFS2_MOUNT_NOINTR  = 1 << 2,   /* Don't catch signals */
8424         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
8425         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
8426 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
8427  };
8428  
8429  #define OCFS2_OSB_SOFT_RO      0x0001
8430 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ocfs2_fs.h linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ocfs2_fs.h
8431 --- linux-2.6.22.10/fs/ocfs2/ocfs2_fs.h 2007-07-09 13:19:28 +0200
8432 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ocfs2_fs.h      2007-08-05 20:53:13 +0200
8433 @@ -152,8 +152,12 @@
8434  #define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
8435  #define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
8436  
8437 +#define OCFS2_BARRIER_FL       (0x04000000)    /* Barrier for chroot() */
8438 +#define OCFS2_IUNLINK_FL       (0x08000000)    /* Immutable unlink */
8439 +
8440  #define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
8441  #define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
8442 +#define OCFS2_FL_MASK          (0x0F0100FF)
8443  
8444  /*
8445   * Extent record flags (e_node.leaf.flags)
8446 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/super.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/super.c
8447 --- linux-2.6.22.10/fs/ocfs2/super.c    2007-07-09 13:19:28 +0200
8448 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/super.c 2007-08-05 20:53:13 +0200
8449 @@ -140,6 +140,7 @@ enum {
8450         Opt_data_ordered,
8451         Opt_data_writeback,
8452         Opt_atime_quantum,
8453 +       Opt_tag, Opt_notag, Opt_tagid,
8454         Opt_err,
8455  };
8456  
8457 @@ -154,6 +155,9 @@ static match_table_t tokens = {
8458         {Opt_data_ordered, "data=ordered"},
8459         {Opt_data_writeback, "data=writeback"},
8460         {Opt_atime_quantum, "atime_quantum=%u"},
8461 +       {Opt_tag, "tag"},
8462 +       {Opt_notag, "notag"},
8463 +       {Opt_tagid, "tagid=%u"},
8464         {Opt_err, NULL}
8465  };
8466  
8467 @@ -362,6 +366,13 @@ static int ocfs2_remount(struct super_bl
8468                 goto out;
8469         }
8470  
8471 +       if ((parsed_options & OCFS2_MOUNT_TAGGED) &&
8472 +               !(sb->s_flags & MS_TAGGED)) {
8473 +               ret = -EINVAL;
8474 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
8475 +               goto out;
8476 +       }
8477 +
8478         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
8479             (parsed_options & OCFS2_MOUNT_HB_LOCAL)) {
8480                 ret = -EINVAL;
8481 @@ -654,6 +665,9 @@ static int ocfs2_fill_super(struct super
8482  
8483         ocfs2_complete_mount_recovery(osb);
8484  
8485 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
8486 +               sb->s_flags |= MS_TAGGED;
8487 +
8488         if (ocfs2_mount_local(osb))
8489                 snprintf(nodestr, sizeof(nodestr), "local");
8490         else
8491 @@ -782,6 +796,20 @@ static int ocfs2_parse_options(struct su
8492                         else
8493                                 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
8494                         break;
8495 +#ifndef CONFIG_TAGGING_NONE
8496 +               case Opt_tag:
8497 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
8498 +                       break;
8499 +               case Opt_notag:
8500 +                       *mount_opt &= ~OCFS2_MOUNT_TAGGED;
8501 +                       break;
8502 +#endif
8503 +#ifdef CONFIG_PROPAGATE
8504 +               case Opt_tagid:
8505 +                       /* use args[0] */
8506 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
8507 +                       break;
8508 +#endif
8509                 default:
8510                         mlog(ML_ERROR,
8511                              "Unrecognized mount option \"%s\" "
8512 diff -NurpP --minimal linux-2.6.22.10/fs/open.c linux-2.6.22.10-vs2.3.0.29/fs/open.c
8513 --- linux-2.6.22.10/fs/open.c   2007-07-09 13:19:28 +0200
8514 +++ linux-2.6.22.10-vs2.3.0.29/fs/open.c        2007-08-05 20:53:13 +0200
8515 @@ -26,22 +26,31 @@
8516  #include <linux/syscalls.h>
8517  #include <linux/rcupdate.h>
8518  #include <linux/audit.h>
8519 +#include <linux/vs_base.h>
8520 +#include <linux/vs_limit.h>
8521 +#include <linux/vs_dlimit.h>
8522 +#include <linux/vs_tag.h>
8523 +#include <linux/vs_cowbl.h>
8524  
8525  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
8526  {
8527         int retval = -ENODEV;
8528  
8529         if (dentry) {
8530 +               struct super_block *sb = dentry->d_sb;
8531 +
8532                 retval = -ENOSYS;
8533 -               if (dentry->d_sb->s_op->statfs) {
8534 +               if (sb->s_op->statfs) {
8535                         memset(buf, 0, sizeof(*buf));
8536                         retval = security_sb_statfs(dentry);
8537                         if (retval)
8538                                 return retval;
8539 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
8540 +                       retval = sb->s_op->statfs(dentry, buf);
8541                         if (retval == 0 && buf->f_frsize == 0)
8542                                 buf->f_frsize = buf->f_bsize;
8543                 }
8544 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
8545 +                       vx_vsi_statfs(sb, buf);
8546         }
8547         return retval;
8548  }
8549 @@ -248,7 +257,7 @@ static long do_sys_truncate(const char _
8550                 goto dput_and_out;
8551  
8552         error = -EROFS;
8553 -       if (IS_RDONLY(inode))
8554 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
8555                 goto dput_and_out;
8556  
8557         error = -EPERM;
8558 @@ -397,7 +406,7 @@ asmlinkage long sys_faccessat(int dfd, c
8559            special_file(nd.dentry->d_inode->i_mode))
8560                 goto out_path_release;
8561  
8562 -       if(IS_RDONLY(nd.dentry->d_inode))
8563 +       if(IS_RDONLY(nd.dentry->d_inode) || MNT_IS_RDONLY(nd.mnt))
8564                 res = -EROFS;
8565  
8566  out_path_release:
8567 @@ -511,7 +520,7 @@ asmlinkage long sys_fchmod(unsigned int 
8568         audit_inode(NULL, inode);
8569  
8570         err = -EROFS;
8571 -       if (IS_RDONLY(inode))
8572 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(file->f_vfsmnt))
8573                 goto out_putf;
8574         err = -EPERM;
8575         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8576 @@ -541,11 +550,11 @@ asmlinkage long sys_fchmodat(int dfd, co
8577         error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
8578         if (error)
8579                 goto out;
8580 -       inode = nd.dentry->d_inode;
8581  
8582 -       error = -EROFS;
8583 -       if (IS_RDONLY(inode))
8584 +       error = cow_check_and_break(&nd);
8585 +       if (error)
8586                 goto dput_and_out;
8587 +       inode = nd.dentry->d_inode;
8588  
8589         error = -EPERM;
8590         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8591 @@ -570,7 +579,8 @@ asmlinkage long sys_chmod(const char __u
8592         return sys_fchmodat(AT_FDCWD, filename, mode);
8593  }
8594  
8595 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
8596 +static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
8597 +       uid_t user, gid_t group)
8598  {
8599         struct inode * inode;
8600         int error;
8601 @@ -582,7 +592,7 @@ static int chown_common(struct dentry * 
8602                 goto out;
8603         }
8604         error = -EROFS;
8605 -       if (IS_RDONLY(inode))
8606 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt))
8607                 goto out;
8608         error = -EPERM;
8609         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8610 @@ -590,11 +600,11 @@ static int chown_common(struct dentry * 
8611         newattrs.ia_valid =  ATTR_CTIME;
8612         if (user != (uid_t) -1) {
8613                 newattrs.ia_valid |= ATTR_UID;
8614 -               newattrs.ia_uid = user;
8615 +               newattrs.ia_uid = dx_map_uid(user);
8616         }
8617         if (group != (gid_t) -1) {
8618                 newattrs.ia_valid |= ATTR_GID;
8619 -               newattrs.ia_gid = group;
8620 +               newattrs.ia_gid = dx_map_gid(group);
8621         }
8622         if (!S_ISDIR(inode->i_mode))
8623                 newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID;
8624 @@ -613,7 +623,11 @@ asmlinkage long sys_chown(const char __u
8625         error = user_path_walk(filename, &nd);
8626         if (error)
8627                 goto out;
8628 -       error = chown_common(nd.dentry, user, group);
8629 +#ifdef CONFIG_VSERVER_COWBL
8630 +       error = cow_check_and_break(&nd);
8631 +       if (!error)
8632 +#endif
8633 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8634         path_release(&nd);
8635  out:
8636         return error;
8637 @@ -633,7 +647,11 @@ asmlinkage long sys_fchownat(int dfd, co
8638         error = __user_walk_fd(dfd, filename, follow, &nd);
8639         if (error)
8640                 goto out;
8641 -       error = chown_common(nd.dentry, user, group);
8642 +#ifdef CONFIG_VSERVER_COWBL
8643 +       error = cow_check_and_break(&nd);
8644 +       if (!error)
8645 +#endif
8646 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8647         path_release(&nd);
8648  out:
8649         return error;
8650 @@ -647,7 +665,11 @@ asmlinkage long sys_lchown(const char __
8651         error = user_path_walk_link(filename, &nd);
8652         if (error)
8653                 goto out;
8654 -       error = chown_common(nd.dentry, user, group);
8655 +#ifdef CONFIG_VSERVER_COWBL
8656 +       error = cow_check_and_break(&nd);
8657 +       if (!error)
8658 +#endif
8659 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8660         path_release(&nd);
8661  out:
8662         return error;
8663 @@ -666,7 +688,7 @@ asmlinkage long sys_fchown(unsigned int 
8664  
8665         dentry = file->f_path.dentry;
8666         audit_inode(NULL, dentry->d_inode);
8667 -       error = chown_common(dentry, user, group);
8668 +       error = chown_common(dentry, file->f_vfsmnt, user, group);
8669         fput(file);
8670  out:
8671         return error;
8672 @@ -893,6 +915,7 @@ repeat:
8673         FD_SET(fd, fdt->open_fds);
8674         FD_CLR(fd, fdt->close_on_exec);
8675         files->next_fd = fd + 1;
8676 +       vx_openfd_inc(fd);
8677  #if 1
8678         /* Sanity check */
8679         if (fdt->fd[fd] != NULL) {
8680 @@ -915,6 +938,7 @@ static void __put_unused_fd(struct files
8681         __FD_CLR(fd, fdt->open_fds);
8682         if (fd < files->next_fd)
8683                 files->next_fd = fd;
8684 +       vx_openfd_dec(fd);
8685  }
8686  
8687  void fastcall put_unused_fd(unsigned int fd)
8688 diff -NurpP --minimal linux-2.6.22.10/fs/proc/array.c linux-2.6.22.10-vs2.3.0.29/fs/proc/array.c
8689 --- linux-2.6.22.10/fs/proc/array.c     2007-07-09 13:19:28 +0200
8690 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/array.c  2007-10-05 15:07:22 +0200
8691 @@ -75,6 +75,8 @@
8692  #include <linux/cpuset.h>
8693  #include <linux/rcupdate.h>
8694  #include <linux/delayacct.h>
8695 +#include <linux/vs_context.h>
8696 +#include <linux/vs_network.h>
8697  
8698  #include <asm/uaccess.h>
8699  #include <asm/pgtable.h>
8700 @@ -134,8 +136,9 @@ static const char *task_state_array[] = 
8701         "D (disk sleep)",       /*  2 */
8702         "T (stopped)",          /*  4 */
8703         "T (tracing stop)",     /*  8 */
8704 -       "Z (zombie)",           /* 16 */
8705 -       "X (dead)"              /* 32 */
8706 +       "H (on hold)",          /* 16 */
8707 +       "Z (zombie)",           /* 32 */
8708 +       "X (dead)",             /* 64 */
8709  };
8710  
8711  static inline const char * get_task_state(struct task_struct *tsk)
8712 @@ -144,7 +147,8 @@ static inline const char * get_task_stat
8713                                             TASK_INTERRUPTIBLE |
8714                                             TASK_UNINTERRUPTIBLE |
8715                                             TASK_STOPPED |
8716 -                                           TASK_TRACED)) |
8717 +                                          TASK_TRACED |
8718 +                                          TASK_ONHOLD)) |
8719                         (tsk->exit_state & (EXIT_ZOMBIE |
8720                                             EXIT_DEAD));
8721         const char **p = &task_state_array[0];
8722 @@ -161,8 +165,16 @@ static inline char * task_state(struct t
8723         struct group_info *group_info;
8724         int g;
8725         struct fdtable *fdt = NULL;
8726 +       pid_t pid, ptgid, tppid, tgid;
8727  
8728         rcu_read_lock();
8729 +       tgid = vx_map_tgid(p->tgid);
8730 +       pid = vx_map_pid(p->pid);
8731 +       ptgid = vx_map_pid(pid_alive(p) ?
8732 +               rcu_dereference(p->real_parent)->tgid : 0);
8733 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
8734 +               rcu_dereference(p->parent)->pid : 0);
8735 +
8736         buffer += sprintf(buffer,
8737                 "State:\t%s\n"
8738                 "SleepAVG:\t%lu%%\n"
8739 @@ -174,9 +186,7 @@ static inline char * task_state(struct t
8740                 "Gid:\t%d\t%d\t%d\t%d\n",
8741                 get_task_state(p),
8742                 (p->sleep_avg/1024)*100/(1020000000/1024),
8743 -               p->tgid, p->pid,
8744 -               pid_alive(p) ? rcu_dereference(p->real_parent)->tgid : 0,
8745 -               pid_alive(p) && p->ptrace ? rcu_dereference(p->parent)->pid : 0,
8746 +               tgid, pid, (pid > 1) ? ptgid : 0, tppid,
8747                 p->uid, p->euid, p->suid, p->fsuid,
8748                 p->gid, p->egid, p->sgid, p->fsgid);
8749  
8750 @@ -283,12 +293,15 @@ static inline char * task_sig(struct tas
8751  
8752  static inline char *task_cap(struct task_struct *p, char *buffer)
8753  {
8754 -    return buffer + sprintf(buffer, "CapInh:\t%016x\n"
8755 -                           "CapPrm:\t%016x\n"
8756 -                           "CapEff:\t%016x\n",
8757 -                           cap_t(p->cap_inheritable),
8758 -                           cap_t(p->cap_permitted),
8759 -                           cap_t(p->cap_effective));
8760 +       struct vx_info *vxi = p->vx_info;
8761 +
8762 +       return buffer + sprintf(buffer,
8763 +               "CapInh:\t%016x\n"
8764 +               "CapPrm:\t%016x\n"
8765 +               "CapEff:\t%016x\n",
8766 +               (unsigned)vx_info_mbcap(vxi, p->cap_inheritable),
8767 +               (unsigned)vx_info_mbcap(vxi, p->cap_permitted),
8768 +               (unsigned)vx_info_mbcap(vxi, p->cap_effective));
8769  }
8770  
8771  int proc_pid_status(struct task_struct *task, char * buffer)
8772 @@ -306,6 +319,12 @@ int proc_pid_status(struct task_struct *
8773         buffer = task_sig(task, buffer);
8774         buffer = task_cap(task, buffer);
8775         buffer = cpuset_task_status_allowed(task, buffer);
8776 +
8777 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
8778 +               goto skip;
8779 +       buffer += sprintf (buffer,"VxID: %d\n", vx_task_xid(task));
8780 +       buffer += sprintf (buffer,"NxID: %d\n", nx_task_nid(task));
8781 +skip:
8782  #if defined(CONFIG_S390)
8783         buffer = task_show_regs(task, buffer);
8784  #endif
8785 @@ -320,7 +339,7 @@ static int do_task_stat(struct task_stru
8786         sigset_t sigign, sigcatch;
8787         char state;
8788         int res;
8789 -       pid_t ppid = 0, pgid = -1, sid = -1;
8790 +       pid_t pid = 0, ppid = 0, pgid = -1, sid = -1;
8791         int num_threads = 0;
8792         struct mm_struct *mm;
8793         unsigned long long start_time;
8794 @@ -382,8 +401,10 @@ static int do_task_stat(struct task_stru
8795                 }
8796  
8797                 sid = signal_session(sig);
8798 -               pgid = process_group(task);
8799 -               ppid = rcu_dereference(task->real_parent)->tgid;
8800 +               pid = vx_info_map_pid(task->vx_info, task->pid);
8801 +               pgid = vx_info_map_pid(task->vx_info, process_group(task));
8802 +               ppid = (pid > 1) ? vx_info_map_tgid(task->vx_info,
8803 +                       rcu_dereference(task->real_parent)->tgid) : 0;
8804  
8805                 unlock_task_sighand(task, &flags);
8806         }
8807 @@ -410,10 +431,21 @@ static int do_task_stat(struct task_stru
8808         /* convert nsec -> ticks */
8809         start_time = nsec_to_clock_t(start_time);
8810  
8811 +       /* fixup start time for virt uptime */
8812 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
8813 +               unsigned long long bias =
8814 +                       current->vx_info->cvirt.bias_clock;
8815 +
8816 +               if (start_time > bias)
8817 +                       start_time -= bias;
8818 +               else
8819 +                       start_time = 0;
8820 +       }
8821 +
8822         res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %u %lu \
8823  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
8824  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu\n",
8825 -               task->pid,
8826 +               pid,
8827                 tcomm,
8828                 state,
8829                 ppid,
8830 diff -NurpP --minimal linux-2.6.22.10/fs/proc/base.c linux-2.6.22.10-vs2.3.0.29/fs/proc/base.c
8831 --- linux-2.6.22.10/fs/proc/base.c      2007-07-09 13:19:28 +0200
8832 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/base.c   2007-09-05 02:49:29 +0200
8833 @@ -73,6 +73,9 @@
8834  #include <linux/poll.h>
8835  #include <linux/nsproxy.h>
8836  #include <linux/oom.h>
8837 +#include <linux/vs_context.h>
8838 +#include <linux/vs_network.h>
8839 +
8840  #include "internal.h"
8841  
8842  /* NOTE:
8843 @@ -1049,6 +1052,8 @@ static struct inode *proc_pid_make_inode
8844                 inode->i_uid = task->euid;
8845                 inode->i_gid = task->egid;
8846         }
8847 +       /* procfs is xid tagged */
8848 +       inode->i_tag = (tag_t)vx_task_xid(task);
8849         security_task_to_inode(task, inode);
8850  
8851  out:
8852 @@ -1082,6 +1087,8 @@ static int pid_getattr(struct vfsmount *
8853  
8854  /* dentry stuff */
8855  
8856 +static unsigned name_to_int(struct dentry *dentry);
8857 +
8858  /*
8859   *     Exceptional case: normally we are not allowed to unhash a busy
8860   * directory. In this case, however, we can do it - no aliasing problems
8861 @@ -1102,6 +1109,12 @@ static int pid_revalidate(struct dentry 
8862         struct inode *inode = dentry->d_inode;
8863         struct task_struct *task = get_proc_task(inode);
8864         if (task) {
8865 +               unsigned pid = name_to_int(dentry);
8866 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
8867 +                       put_task_struct(task);
8868 +                       goto drop;
8869 +               }
8870 +
8871                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
8872                     task_dumpable(task)) {
8873                         inode->i_uid = task->euid;
8874 @@ -1115,6 +1128,7 @@ static int pid_revalidate(struct dentry 
8875                 put_task_struct(task);
8876                 return 1;
8877         }
8878 +drop:
8879         d_drop(dentry);
8880         return 0;
8881  }
8882 @@ -1595,6 +1609,13 @@ static struct dentry *proc_pident_lookup
8883         if (!task)
8884                 goto out_no_task;
8885  
8886 +       /* TODO: maybe we can come up with a generic approach? */
8887 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
8888 +               (dentry->d_name.len == 5) &&
8889 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
8890 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
8891 +               goto out;
8892 +
8893         /*
8894          * Yes, it does not scale. And it should not. Don't add
8895          * new entries into /proc/<tgid>/ without very good reasons.
8896 @@ -1790,14 +1811,14 @@ static int proc_self_readlink(struct den
8897                               int buflen)
8898  {
8899         char tmp[PROC_NUMBUF];
8900 -       sprintf(tmp, "%d", current->tgid);
8901 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8902         return vfs_readlink(dentry,buffer,buflen,tmp);
8903  }
8904  
8905  static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
8906  {
8907         char tmp[PROC_NUMBUF];
8908 -       sprintf(tmp, "%d", current->tgid);
8909 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8910         return ERR_PTR(vfs_follow_link(nd,tmp));
8911  }
8912  
8913 @@ -1891,7 +1912,7 @@ out_iput:
8914  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
8915  {
8916         struct dentry *error;
8917 -       struct task_struct *task = get_proc_task(dir);
8918 +       struct task_struct *task = get_proc_task_real(dir);
8919         const struct pid_entry *p, *last;
8920  
8921         error = ERR_PTR(-ENOENT);
8922 @@ -1956,6 +1977,9 @@ static int proc_pid_io_accounting(struct
8923  static const struct file_operations proc_task_operations;
8924  static const struct inode_operations proc_task_inode_operations;
8925  
8926 +extern int proc_pid_vx_info(struct task_struct *, char *);
8927 +extern int proc_pid_nx_info(struct task_struct *, char *);
8928 +
8929  static const struct pid_entry tgid_base_stuff[] = {
8930         DIR("task",       S_IRUGO|S_IXUGO, task),
8931         DIR("fd",         S_IRUSR|S_IXUSR, fd),
8932 @@ -1995,6 +2019,8 @@ static const struct pid_entry tgid_base_
8933  #ifdef CONFIG_CPUSETS
8934         REG("cpuset",     S_IRUGO, cpuset),
8935  #endif
8936 +       INF("vinfo",      S_IRUGO, pid_vx_info),
8937 +       INF("ninfo",      S_IRUGO, pid_nx_info),
8938         INF("oom_score",  S_IRUGO, oom_score),
8939         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
8940  #ifdef CONFIG_AUDITSYSCALL
8941 @@ -2141,9 +2167,11 @@ struct dentry *proc_pid_lookup(struct in
8942         tgid = name_to_int(dentry);
8943         if (tgid == ~0U)
8944                 goto out;
8945 +       if (vx_current_initpid(tgid))
8946 +               goto out;
8947  
8948         rcu_read_lock();
8949 -       task = find_task_by_pid(tgid);
8950 +       task = vx_find_proc_task_by_pid(tgid);
8951         if (task)
8952                 get_task_struct(task);
8953         rcu_read_unlock();
8954 @@ -2198,7 +2226,7 @@ static int proc_pid_fill_cache(struct fi
8955         struct task_struct *task, int tgid)
8956  {
8957         char name[PROC_NUMBUF];
8958 -       int len = snprintf(name, sizeof(name), "%d", tgid);
8959 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(tgid));
8960         return proc_fill_cache(filp, dirent, filldir, name, len,
8961                                 proc_pid_instantiate, task, NULL);
8962  }
8963 @@ -2207,7 +2235,7 @@ static int proc_pid_fill_cache(struct fi
8964  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
8965  {
8966         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
8967 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
8968 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
8969         struct task_struct *task;
8970         int tgid;
8971  
8972 @@ -2226,6 +2254,8 @@ int proc_pid_readdir(struct file * filp,
8973              put_task_struct(task), task = next_tgid(tgid + 1)) {
8974                 tgid = task->pid;
8975                 filp->f_pos = tgid + TGID_OFFSET;
8976 +               if (!vx_proc_task_visible(task))
8977 +                       continue;
8978                 if (proc_pid_fill_cache(filp, dirent, filldir, task, tgid) < 0) {
8979                         put_task_struct(task);
8980                         goto out;
8981 @@ -2352,9 +2382,11 @@ static struct dentry *proc_task_lookup(s
8982         tid = name_to_int(dentry);
8983         if (tid == ~0U)
8984                 goto out;
8985 +       if (vx_current_initpid(tid))
8986 +               goto out;
8987  
8988         rcu_read_lock();
8989 -       task = find_task_by_pid(tid);
8990 +       task = vx_find_proc_task_by_pid(tid);
8991         if (task)
8992                 get_task_struct(task);
8993         rcu_read_unlock();
8994 @@ -2499,7 +2531,7 @@ static int proc_task_readdir(struct file
8995         for (task = first_tid(leader, tid, pos - 2);
8996              task;
8997              task = next_tid(task), pos++) {
8998 -               tid = task->pid;
8999 +               tid = vx_map_pid(task->pid);
9000                 if (proc_task_fill_cache(filp, dirent, filldir, task, tid) < 0) {
9001                         /* returning this tgid failed, save it as the first
9002                          * pid for the next readir call */
9003 diff -NurpP --minimal linux-2.6.22.10/fs/proc/generic.c linux-2.6.22.10-vs2.3.0.29/fs/proc/generic.c
9004 --- linux-2.6.22.10/fs/proc/generic.c   2007-07-09 13:19:28 +0200
9005 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/generic.c        2007-08-05 20:53:13 +0200
9006 @@ -20,6 +20,7 @@
9007  #include <linux/namei.h>
9008  #include <linux/bitops.h>
9009  #include <linux/spinlock.h>
9010 +#include <linux/vserver/inode.h>
9011  #include <asm/uaccess.h>
9012  
9013  #include "internal.h"
9014 @@ -395,6 +396,8 @@ struct dentry *proc_lookup(struct inode 
9015                 for (de = de->subdir; de ; de = de->next) {
9016                         if (de->namelen != dentry->d_name.len)
9017                                 continue;
9018 +                       if (!vx_hide_check(0, de->vx_flags))
9019 +                               continue;
9020                         if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
9021                                 unsigned int ino = de->low_ino;
9022  
9023 @@ -402,6 +405,8 @@ struct dentry *proc_lookup(struct inode 
9024                                 spin_unlock(&proc_subdir_lock);
9025                                 error = -EINVAL;
9026                                 inode = proc_get_inode(dir->i_sb, ino, de);
9027 +                               /* generic proc entries belong to the host */
9028 +                               inode->i_tag = 0;
9029                                 spin_lock(&proc_subdir_lock);
9030                                 break;
9031                         }
9032 @@ -482,6 +487,8 @@ int proc_readdir(struct file * filp,
9033  
9034                                 /* filldir passes info to user space */
9035                                 de_get(de);
9036 +                               if (!vx_hide_check(0, de->vx_flags))
9037 +                                       goto skip;
9038                                 spin_unlock(&proc_subdir_lock);
9039                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
9040                                             de->low_ino, de->mode >> 12) < 0) {
9041 @@ -489,6 +496,7 @@ int proc_readdir(struct file * filp,
9042                                         goto out;
9043                                 }
9044                                 spin_lock(&proc_subdir_lock);
9045 +                       skip:
9046                                 filp->f_pos++;
9047                                 next = de->next;
9048                                 de_put(de);
9049 @@ -613,6 +621,7 @@ static struct proc_dir_entry *proc_creat
9050         ent->namelen = len;
9051         ent->mode = mode;
9052         ent->nlink = nlink;
9053 +       ent->vx_flags = IATTR_PROC_DEFAULT;
9054   out:
9055         return ent;
9056  }
9057 @@ -633,7 +642,8 @@ struct proc_dir_entry *proc_symlink(cons
9058                                 kfree(ent->data);
9059                                 kfree(ent);
9060                                 ent = NULL;
9061 -                       }
9062 +                       } else
9063 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
9064                 } else {
9065                         kfree(ent);
9066                         ent = NULL;
9067 diff -NurpP --minimal linux-2.6.22.10/fs/proc/inode.c linux-2.6.22.10-vs2.3.0.29/fs/proc/inode.c
9068 --- linux-2.6.22.10/fs/proc/inode.c     2007-07-09 13:19:28 +0200
9069 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/inode.c  2007-08-05 20:53:13 +0200
9070 @@ -160,6 +160,8 @@ struct inode *proc_get_inode(struct supe
9071                         inode->i_uid = de->uid;
9072                         inode->i_gid = de->gid;
9073                 }
9074 +               if (de->vx_flags)
9075 +                       PROC_I(inode)->vx_flags = de->vx_flags;
9076                 if (de->size)
9077                         inode->i_size = de->size;
9078                 if (de->nlink)
9079 diff -NurpP --minimal linux-2.6.22.10/fs/proc/internal.h linux-2.6.22.10-vs2.3.0.29/fs/proc/internal.h
9080 --- linux-2.6.22.10/fs/proc/internal.h  2007-07-09 13:19:28 +0200
9081 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/internal.h       2007-08-05 20:53:13 +0200
9082 @@ -10,6 +10,7 @@
9083   */
9084  
9085  #include <linux/proc_fs.h>
9086 +#include <linux/vs_pid.h>
9087  
9088  #ifdef CONFIG_PROC_SYSCTL
9089  extern int proc_sys_init(void);
9090 @@ -64,11 +65,16 @@ static inline struct pid *proc_pid(struc
9091         return PROC_I(inode)->pid;
9092  }
9093  
9094 -static inline struct task_struct *get_proc_task(struct inode *inode)
9095 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
9096  {
9097         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
9098  }
9099  
9100 +static inline struct task_struct *get_proc_task(struct inode *inode)
9101 +{
9102 +       return vx_get_proc_task(inode, proc_pid(inode));
9103 +}
9104 +
9105  static inline int proc_fd(struct inode *inode)
9106  {
9107         return PROC_I(inode)->fd;
9108 diff -NurpP --minimal linux-2.6.22.10/fs/proc/proc_misc.c linux-2.6.22.10-vs2.3.0.29/fs/proc/proc_misc.c
9109 --- linux-2.6.22.10/fs/proc/proc_misc.c 2007-07-09 13:19:28 +0200
9110 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/proc_misc.c      2007-08-05 20:53:13 +0200
9111 @@ -53,6 +53,8 @@
9112  #include <asm/div64.h>
9113  #include "internal.h"
9114  
9115 +#include <linux/vs_cvirt.h>
9116 +
9117  #define LOAD_INT(x) ((x) >> FSHIFT)
9118  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
9119  /*
9120 @@ -82,17 +84,32 @@ static int proc_calc_metrics(char *page,
9121  static int loadavg_read_proc(char *page, char **start, off_t off,
9122                                  int count, int *eof, void *data)
9123  {
9124 +       unsigned int running, threads;
9125         int a, b, c;
9126         int len;
9127  
9128 -       a = avenrun[0] + (FIXED_1/200);
9129 -       b = avenrun[1] + (FIXED_1/200);
9130 -       c = avenrun[2] + (FIXED_1/200);
9131 -       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
9132 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
9133 +               struct vx_info *vxi = current->vx_info;
9134 +
9135 +               a = vxi->cvirt.load[0] + (FIXED_1/200);
9136 +               b = vxi->cvirt.load[1] + (FIXED_1/200);
9137 +               c = vxi->cvirt.load[2] + (FIXED_1/200);
9138 +
9139 +               running = atomic_read(&vxi->cvirt.nr_running);
9140 +               threads = atomic_read(&vxi->cvirt.nr_threads);
9141 +       } else {
9142 +               a = avenrun[0] + (FIXED_1/200);
9143 +               b = avenrun[1] + (FIXED_1/200);
9144 +               c = avenrun[2] + (FIXED_1/200);
9145 +
9146 +               running = nr_running();
9147 +               threads = nr_threads;
9148 +       }
9149 +       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",
9150                 LOAD_INT(a), LOAD_FRAC(a),
9151                 LOAD_INT(b), LOAD_FRAC(b),
9152                 LOAD_INT(c), LOAD_FRAC(c),
9153 -               nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);
9154 +               running, threads, current->nsproxy->pid_ns->last_pid);
9155         return proc_calc_metrics(page, start, off, count, eof, len);
9156  }
9157  
9158 @@ -106,6 +123,9 @@ static int uptime_read_proc(char *page, 
9159  
9160         do_posix_clock_monotonic_gettime(&uptime);
9161         cputime_to_timespec(idletime, &idle);
9162 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
9163 +               vx_vsi_uptime(&uptime, &idle);
9164 +
9165         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
9166                         (unsigned long) uptime.tv_sec,
9167                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
9168 @@ -137,7 +157,7 @@ static int meminfo_read_proc(char *page,
9169  
9170         cached = global_page_state(NR_FILE_PAGES) -
9171                         total_swapcache_pages - i.bufferram;
9172 -       if (cached < 0)
9173 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
9174                 cached = 0;
9175  
9176         get_vmalloc_info(&vmi);
9177 diff -NurpP --minimal linux-2.6.22.10/fs/proc/root.c linux-2.6.22.10-vs2.3.0.29/fs/proc/root.c
9178 --- linux-2.6.22.10/fs/proc/root.c      2007-05-02 19:25:21 +0200
9179 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/root.c   2007-08-05 20:53:13 +0200
9180 @@ -22,6 +22,9 @@
9181  #include "internal.h"
9182  
9183  struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver;
9184 +struct proc_dir_entry *proc_virtual;
9185 +
9186 +extern void proc_vx_init(void);
9187  
9188  static int proc_get_sb(struct file_system_type *fs_type,
9189         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
9190 @@ -79,6 +82,7 @@ void __init proc_root_init(void)
9191         proc_device_tree_init();
9192  #endif
9193         proc_bus = proc_mkdir("bus", NULL);
9194 +       proc_vx_init();
9195         proc_sys_init();
9196  }
9197  
9198 diff -NurpP --minimal linux-2.6.22.10/fs/quota.c linux-2.6.22.10-vs2.3.0.29/fs/quota.c
9199 --- linux-2.6.22.10/fs/quota.c  2007-07-09 13:19:28 +0200
9200 +++ linux-2.6.22.10-vs2.3.0.29/fs/quota.c       2007-08-05 20:53:13 +0200
9201 @@ -16,6 +16,7 @@
9202  #include <linux/buffer_head.h>
9203  #include <linux/capability.h>
9204  #include <linux/quotaops.h>
9205 +#include <linux/vs_context.h>
9206  
9207  /* Check validity of generic quotactl commands */
9208  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
9209 @@ -80,11 +81,11 @@ static int generic_quotactl_valid(struct
9210         if (cmd == Q_GETQUOTA) {
9211                 if (((type == USRQUOTA && current->euid != id) ||
9212                      (type == GRPQUOTA && !in_egroup_p(id))) &&
9213 -                   !capable(CAP_SYS_ADMIN))
9214 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9215                         return -EPERM;
9216         }
9217         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
9218 -               if (!capable(CAP_SYS_ADMIN))
9219 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9220                         return -EPERM;
9221  
9222         return 0;
9223 @@ -131,10 +132,10 @@ static int xqm_quotactl_valid(struct sup
9224         if (cmd == Q_XGETQUOTA) {
9225                 if (((type == XQM_USRQUOTA && current->euid != id) ||
9226                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
9227 -                    !capable(CAP_SYS_ADMIN))
9228 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9229                         return -EPERM;
9230         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
9231 -               if (!capable(CAP_SYS_ADMIN))
9232 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9233                         return -EPERM;
9234         }
9235  
9236 @@ -327,6 +328,46 @@ static int do_quotactl(struct super_bloc
9237         return 0;
9238  }
9239  
9240 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
9241 +
9242 +#include <linux/vroot.h>
9243 +#include <linux/major.h>
9244 +#include <linux/module.h>
9245 +#include <linux/kallsyms.h>
9246 +#include <linux/vserver/debug.h>
9247 +
9248 +static vroot_grb_func *vroot_get_real_bdev = NULL;
9249 +
9250 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
9251 +
9252 +int register_vroot_grb(vroot_grb_func *func) {
9253 +       int ret = -EBUSY;
9254 +
9255 +       spin_lock(&vroot_grb_lock);
9256 +       if (!vroot_get_real_bdev) {
9257 +               vroot_get_real_bdev = func;
9258 +               ret = 0;
9259 +       }
9260 +       spin_unlock(&vroot_grb_lock);
9261 +       return ret;
9262 +}
9263 +EXPORT_SYMBOL(register_vroot_grb);
9264 +
9265 +int unregister_vroot_grb(vroot_grb_func *func) {
9266 +       int ret = -EINVAL;
9267 +
9268 +       spin_lock(&vroot_grb_lock);
9269 +       if (vroot_get_real_bdev) {
9270 +               vroot_get_real_bdev = NULL;
9271 +               ret = 0;
9272 +       }
9273 +       spin_unlock(&vroot_grb_lock);
9274 +       return ret;
9275 +}
9276 +EXPORT_SYMBOL(unregister_vroot_grb);
9277 +
9278 +#endif
9279 +
9280  /*
9281   * look up a superblock on which quota ops will be performed
9282   * - use the name of a block device to find the superblock thereon
9283 @@ -344,6 +385,22 @@ static inline struct super_block *quotac
9284         putname(tmp);
9285         if (IS_ERR(bdev))
9286                 return ERR_PTR(PTR_ERR(bdev));
9287 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
9288 +       if (bdev && bdev->bd_inode &&
9289 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
9290 +               struct block_device *bdnew = (void *)-EINVAL;
9291 +
9292 +               if (vroot_get_real_bdev)
9293 +                       bdnew = vroot_get_real_bdev(bdev);
9294 +               else
9295 +                       vxdprintk(VXD_CBIT(misc, 0),
9296 +                                       "vroot_get_real_bdev not set");
9297 +               bdput(bdev);
9298 +               if (IS_ERR(bdnew))
9299 +                       return ERR_PTR(PTR_ERR(bdnew));
9300 +               bdev = bdnew;
9301 +       }
9302 +#endif
9303         sb = get_super(bdev);
9304         bdput(bdev);
9305         if (!sb)
9306 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/bitmap.c linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/bitmap.c
9307 --- linux-2.6.22.10/fs/reiserfs/bitmap.c        2007-02-06 03:01:29 +0100
9308 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/bitmap.c     2007-10-05 15:07:22 +0200
9309 @@ -13,6 +13,7 @@
9310  #include <linux/reiserfs_fs_sb.h>
9311  #include <linux/reiserfs_fs_i.h>
9312  #include <linux/quotaops.h>
9313 +#include <linux/vs_dlimit.h>
9314  
9315  #define PREALLOCATION_SIZE 9
9316  
9317 @@ -425,8 +426,10 @@ static void _reiserfs_free_block(struct 
9318         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
9319  
9320         journal_mark_dirty(th, s, sbh);
9321 -       if (for_unformatted)
9322 +       if (for_unformatted) {
9323 +               DLIMIT_FREE_BLOCK(inode, 1);
9324                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
9325 +       }
9326  }
9327  
9328  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
9329 @@ -1034,6 +1037,7 @@ static inline int blocknrs_and_prealloc_
9330         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
9331         int passno = 0;
9332         int nr_allocated = 0;
9333 +       int blocks;
9334  
9335         determine_prealloc_size(hint);
9336         if (!hint->formatted_node) {
9337 @@ -1043,19 +1047,30 @@ static inline int blocknrs_and_prealloc_
9338                                "reiserquota: allocating %d blocks id=%u",
9339                                amount_needed, hint->inode->i_uid);
9340  #endif
9341 -               quota_ret =
9342 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
9343 -               if (quota_ret)  /* Quota exceeded? */
9344 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
9345 +                       amount_needed);
9346 +               if (quota_ret)
9347                         return QUOTA_EXCEEDED;
9348 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
9349 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
9350 +                               amount_needed);
9351 +                       return NO_DISK_SPACE;
9352 +               }
9353 +
9354                 if (hint->preallocate && hint->prealloc_size) {
9355  #ifdef REISERQUOTA_DEBUG
9356                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
9357                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
9358                                        hint->prealloc_size, hint->inode->i_uid);
9359  #endif
9360 -                       quota_ret =
9361 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
9362 -                                                        hint->prealloc_size);
9363 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
9364 +                               hint->prealloc_size);
9365 +                       if (!quota_ret &&
9366 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
9367 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
9368 +                                       hint->prealloc_size);
9369 +                               quota_ret = 1;
9370 +                       }
9371                         if (quota_ret)
9372                                 hint->preallocate = hint->prealloc_size = 0;
9373                 }
9374 @@ -1087,7 +1102,10 @@ static inline int blocknrs_and_prealloc_
9375                                                nr_allocated,
9376                                                hint->inode->i_uid);
9377  #endif
9378 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
9379 +                               /* Free not allocated blocks */
9380 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
9381 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
9382 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
9383                         }
9384                         while (nr_allocated--)
9385                                 reiserfs_free_block(hint->th, hint->inode,
9386 @@ -1118,10 +1136,10 @@ static inline int blocknrs_and_prealloc_
9387                                REISERFS_I(hint->inode)->i_prealloc_count,
9388                                hint->inode->i_uid);
9389  #endif
9390 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
9391 -                                        hint->prealloc_size - nr_allocated -
9392 -                                        REISERFS_I(hint->inode)->
9393 -                                        i_prealloc_count);
9394 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
9395 +                       REISERFS_I(hint->inode)->i_prealloc_count;
9396 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
9397 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
9398         }
9399  
9400         return CARRY_ON;
9401 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/file.c linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/file.c
9402 --- linux-2.6.22.10/fs/reiserfs/file.c  2007-07-09 13:19:28 +0200
9403 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/file.c       2007-09-12 20:04:16 +0200
9404 @@ -1546,4 +1546,5 @@ const struct inode_operations reiserfs_f
9405         .listxattr = reiserfs_listxattr,
9406         .removexattr = reiserfs_removexattr,
9407         .permission = reiserfs_permission,
9408 +       .sync_flags = reiserfs_sync_flags,
9409  };
9410 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/inode.c linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/inode.c
9411 --- linux-2.6.22.10/fs/reiserfs/inode.c 2007-07-09 13:19:28 +0200
9412 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/inode.c      2007-08-05 20:53:13 +0200
9413 @@ -16,6 +16,8 @@
9414  #include <linux/mpage.h>
9415  #include <linux/writeback.h>
9416  #include <linux/quotaops.h>
9417 +#include <linux/vs_dlimit.h>
9418 +#include <linux/vs_tag.h>
9419  
9420  static int reiserfs_commit_write(struct file *f, struct page *page,
9421                                  unsigned from, unsigned to);
9422 @@ -50,6 +52,7 @@ void reiserfs_delete_inode(struct inode 
9423                  * stat data deletion */
9424                 if (!err) 
9425                         DQUOT_FREE_INODE(inode);
9426 +               DLIMIT_FREE_INODE(inode);
9427  
9428                 if (journal_end(&th, inode->i_sb, jbegin_count))
9429                         goto out;
9430 @@ -1112,6 +1115,8 @@ static void init_inode(struct inode *ino
9431         struct buffer_head *bh;
9432         struct item_head *ih;
9433         __u32 rdev;
9434 +       uid_t uid;
9435 +       gid_t gid;
9436         //int version = ITEM_VERSION_1;
9437  
9438         bh = PATH_PLAST_BUFFER(path);
9439 @@ -1135,12 +1140,13 @@ static void init_inode(struct inode *ino
9440                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
9441                 unsigned long blocks;
9442  
9443 +               uid = sd_v1_uid(sd);
9444 +               gid = sd_v1_gid(sd);
9445 +
9446                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
9447                 set_inode_sd_version(inode, STAT_DATA_V1);
9448                 inode->i_mode = sd_v1_mode(sd);
9449                 inode->i_nlink = sd_v1_nlink(sd);
9450 -               inode->i_uid = sd_v1_uid(sd);
9451 -               inode->i_gid = sd_v1_gid(sd);
9452                 inode->i_size = sd_v1_size(sd);
9453                 inode->i_atime.tv_sec = sd_v1_atime(sd);
9454                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
9455 @@ -1182,11 +1188,12 @@ static void init_inode(struct inode *ino
9456                 // (directories and symlinks)
9457                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
9458  
9459 +               uid    = sd_v2_uid(sd);
9460 +               gid    = sd_v2_gid(sd);
9461 +
9462                 inode->i_mode = sd_v2_mode(sd);
9463                 inode->i_nlink = sd_v2_nlink(sd);
9464 -               inode->i_uid = sd_v2_uid(sd);
9465                 inode->i_size = sd_v2_size(sd);
9466 -               inode->i_gid = sd_v2_gid(sd);
9467                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
9468                 inode->i_atime.tv_sec = sd_v2_atime(sd);
9469                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
9470 @@ -1216,6 +1223,10 @@ static void init_inode(struct inode *ino
9471                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
9472         }
9473  
9474 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
9475 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
9476 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
9477 +
9478         pathrelse(path);
9479         if (S_ISREG(inode->i_mode)) {
9480                 inode->i_op = &reiserfs_file_inode_operations;
9481 @@ -1238,13 +1249,15 @@ static void init_inode(struct inode *ino
9482  static void inode2sd(void *sd, struct inode *inode, loff_t size)
9483  {
9484         struct stat_data *sd_v2 = (struct stat_data *)sd;
9485 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
9486 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
9487         __u16 flags;
9488  
9489 +       set_sd_v2_uid(sd_v2, uid);
9490 +       set_sd_v2_gid(sd_v2, gid);
9491         set_sd_v2_mode(sd_v2, inode->i_mode);
9492         set_sd_v2_nlink(sd_v2, inode->i_nlink);
9493 -       set_sd_v2_uid(sd_v2, inode->i_uid);
9494         set_sd_v2_size(sd_v2, size);
9495 -       set_sd_v2_gid(sd_v2, inode->i_gid);
9496         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
9497         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
9498         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
9499 @@ -1775,6 +1788,10 @@ int reiserfs_new_inode(struct reiserfs_t
9500  
9501         BUG_ON(!th->t_trans_id);
9502  
9503 +       if (DLIMIT_ALLOC_INODE(inode)) {
9504 +               err = -ENOSPC;
9505 +               goto out_bad_dlimit;
9506 +       }
9507         if (DQUOT_ALLOC_INODE(inode)) {
9508                 err = -EDQUOT;
9509                 goto out_end_trans;
9510 @@ -1960,6 +1977,9 @@ int reiserfs_new_inode(struct reiserfs_t
9511         DQUOT_FREE_INODE(inode);
9512  
9513        out_end_trans:
9514 +       DLIMIT_FREE_INODE(inode);
9515 +
9516 +      out_bad_dlimit:
9517         journal_end(th, th->t_super, th->t_blocks_allocated);
9518         /* Drop can be outside and it needs more credits so it's better to have it outside */
9519         DQUOT_DROP(inode);
9520 @@ -2690,6 +2710,14 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
9521                         inode->i_flags |= S_IMMUTABLE;
9522                 else
9523                         inode->i_flags &= ~S_IMMUTABLE;
9524 +               if (sd_attrs & REISERFS_IUNLINK_FL)
9525 +                       inode->i_flags |= S_IUNLINK;
9526 +               else
9527 +                       inode->i_flags &= ~S_IUNLINK;
9528 +               if (sd_attrs & REISERFS_BARRIER_FL)
9529 +                       inode->i_flags |= S_BARRIER;
9530 +               else
9531 +                       inode->i_flags &= ~S_BARRIER;
9532                 if (sd_attrs & REISERFS_APPEND_FL)
9533                         inode->i_flags |= S_APPEND;
9534                 else
9535 @@ -2712,6 +2740,14 @@ void i_attrs_to_sd_attrs(struct inode *i
9536                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
9537                 else
9538                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
9539 +               if (inode->i_flags & S_IUNLINK)
9540 +                       *sd_attrs |= REISERFS_IUNLINK_FL;
9541 +               else
9542 +                       *sd_attrs &= ~REISERFS_IUNLINK_FL;
9543 +               if (inode->i_flags & S_BARRIER)
9544 +                       *sd_attrs |= REISERFS_BARRIER_FL;
9545 +               else
9546 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
9547                 if (inode->i_flags & S_SYNC)
9548                         *sd_attrs |= REISERFS_SYNC_FL;
9549                 else
9550 @@ -2891,6 +2927,22 @@ static ssize_t reiserfs_direct_IO(int rw
9551                                   reiserfs_get_blocks_direct_io, NULL);
9552  }
9553  
9554 +int reiserfs_sync_flags(struct inode *inode)
9555 +{
9556 +       u16 oldflags, newflags;
9557 +
9558 +       oldflags = REISERFS_I(inode)->i_attrs;
9559 +       newflags = oldflags;
9560 +       i_attrs_to_sd_attrs(inode, &newflags);
9561 +
9562 +       if (oldflags ^ newflags) {
9563 +               REISERFS_I(inode)->i_attrs = newflags;
9564 +               inode->i_ctime = CURRENT_TIME_SEC;
9565 +               mark_inode_dirty(inode);
9566 +       }
9567 +       return 0;
9568 +}
9569 +
9570  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
9571  {
9572         struct inode *inode = dentry->d_inode;
9573 @@ -2940,9 +2992,11 @@ int reiserfs_setattr(struct dentry *dent
9574         }
9575  
9576         error = inode_change_ok(inode, attr);
9577 +
9578         if (!error) {
9579                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
9580 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
9581 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
9582 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
9583                         error = reiserfs_chown_xattrs(inode, attr);
9584  
9585                         if (!error) {
9586 @@ -2972,6 +3026,9 @@ int reiserfs_setattr(struct dentry *dent
9587                                         inode->i_uid = attr->ia_uid;
9588                                 if (attr->ia_valid & ATTR_GID)
9589                                         inode->i_gid = attr->ia_gid;
9590 +                               if ((attr->ia_valid & ATTR_TAG) &&
9591 +                                       IS_TAGGED(inode))
9592 +                                       inode->i_tag = attr->ia_tag;
9593                                 mark_inode_dirty(inode);
9594                                 error =
9595                                     journal_end(&th, inode->i_sb, jbegin_count);
9596 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/ioctl.c
9597 --- linux-2.6.22.10/fs/reiserfs/ioctl.c 2007-02-06 03:01:29 +0100
9598 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/ioctl.c      2007-08-05 20:53:13 +0200
9599 @@ -6,6 +6,7 @@
9600  #include <linux/fs.h>
9601  #include <linux/reiserfs_fs.h>
9602  #include <linux/time.h>
9603 +#include <linux/mount.h>
9604  #include <asm/uaccess.h>
9605  #include <linux/pagemap.h>
9606  #include <linux/smp_lock.h>
9607 @@ -24,7 +25,7 @@ static int reiserfs_unpack(struct inode 
9608  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
9609                    unsigned long arg)
9610  {
9611 -       unsigned int flags;
9612 +       unsigned int flags, oldflags;
9613  
9614         switch (cmd) {
9615         case REISERFS_IOC_UNPACK:
9616 @@ -43,12 +44,14 @@ int reiserfs_ioctl(struct inode *inode, 
9617  
9618                 flags = REISERFS_I(inode)->i_attrs;
9619                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
9620 +               flags &= REISERFS_FL_USER_VISIBLE;
9621                 return put_user(flags, (int __user *)arg);
9622         case REISERFS_IOC_SETFLAGS:{
9623                         if (!reiserfs_attrs(inode->i_sb))
9624                                 return -ENOTTY;
9625  
9626 -                       if (IS_RDONLY(inode))
9627 +                       if (IS_RDONLY(inode) ||
9628 +                               (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9629                                 return -EROFS;
9630  
9631                         if ((current->fsuid != inode->i_uid)
9632 @@ -58,10 +61,12 @@ int reiserfs_ioctl(struct inode *inode, 
9633                         if (get_user(flags, (int __user *)arg))
9634                                 return -EFAULT;
9635  
9636 -                       if (((flags ^ REISERFS_I(inode)->
9637 -                             i_attrs) & (REISERFS_IMMUTABLE_FL |
9638 -                                         REISERFS_APPEND_FL))
9639 -                           && !capable(CAP_LINUX_IMMUTABLE))
9640 +                       oldflags = REISERFS_I(inode) -> i_attrs;
9641 +                       if (((oldflags & REISERFS_IMMUTABLE_FL) ||
9642 +                               ((flags ^ oldflags) &
9643 +                               (REISERFS_IMMUTABLE_FL | REISERFS_IUNLINK_FL |
9644 +                                REISERFS_APPEND_FL))) &&
9645 +                               !capable(CAP_LINUX_IMMUTABLE))
9646                                 return -EPERM;
9647  
9648                         if ((flags & REISERFS_NOTAIL_FL) &&
9649 @@ -72,6 +77,9 @@ int reiserfs_ioctl(struct inode *inode, 
9650                                 if (result)
9651                                         return result;
9652                         }
9653 +
9654 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
9655 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
9656                         sd_attrs_to_i_attrs(flags, inode);
9657                         REISERFS_I(inode)->i_attrs = flags;
9658                         inode->i_ctime = CURRENT_TIME_SEC;
9659 @@ -83,7 +91,8 @@ int reiserfs_ioctl(struct inode *inode, 
9660         case REISERFS_IOC_SETVERSION:
9661                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
9662                         return -EPERM;
9663 -               if (IS_RDONLY(inode))
9664 +               if (IS_RDONLY(inode) ||
9665 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9666                         return -EROFS;
9667                 if (get_user(inode->i_generation, (int __user *)arg))
9668                         return -EFAULT;
9669 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/namei.c linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/namei.c
9670 --- linux-2.6.22.10/fs/reiserfs/namei.c 2007-07-09 13:19:28 +0200
9671 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/namei.c      2007-08-05 20:53:13 +0200
9672 @@ -17,6 +17,7 @@
9673  #include <linux/reiserfs_acl.h>
9674  #include <linux/reiserfs_xattr.h>
9675  #include <linux/quotaops.h>
9676 +#include <linux/vs_tag.h>
9677  
9678  #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; }
9679  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
9680 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
9681                         reiserfs_write_unlock(dir->i_sb);
9682                         return ERR_PTR(-EACCES);
9683                 }
9684 +               dx_propagate_tag(nd, inode);
9685  
9686                 /* Propogate the priv_object flag so we know we're in the priv tree */
9687                 if (is_reiserfs_priv_object(dir))
9688 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
9689         } else {
9690                 inode->i_gid = current->fsgid;
9691         }
9692 +       inode->i_tag = dx_current_fstag(inode->i_sb);
9693         DQUOT_INIT(inode);
9694         return 0;
9695  }
9696 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
9697         .listxattr = reiserfs_listxattr,
9698         .removexattr = reiserfs_removexattr,
9699         .permission = reiserfs_permission,
9700 +       .sync_flags = reiserfs_sync_flags,
9701  };
9702  
9703  /*
9704 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
9705         .listxattr = reiserfs_listxattr,
9706         .removexattr = reiserfs_removexattr,
9707         .permission = reiserfs_permission,
9708 +       .sync_flags = reiserfs_sync_flags,
9709  
9710  };
9711  
9712 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
9713         .listxattr = reiserfs_listxattr,
9714         .removexattr = reiserfs_removexattr,
9715         .permission = reiserfs_permission,
9716 +       .sync_flags = reiserfs_sync_flags,
9717  
9718  };
9719 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/stree.c linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/stree.c
9720 --- linux-2.6.22.10/fs/reiserfs/stree.c 2007-07-09 13:19:28 +0200
9721 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/stree.c      2007-08-05 20:53:13 +0200
9722 @@ -55,6 +55,7 @@
9723  #include <linux/reiserfs_fs.h>
9724  #include <linux/buffer_head.h>
9725  #include <linux/quotaops.h>
9726 +#include <linux/vs_dlimit.h>
9727  
9728  /* Does the buffer contain a disk block which is in the tree. */
9729  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
9730 @@ -1296,6 +1297,7 @@ int reiserfs_delete_item(struct reiserfs
9731                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
9732                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
9733  #endif
9734 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9735         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9736  
9737         /* Return deleted body length */
9738 @@ -1384,6 +1386,7 @@ void reiserfs_delete_solid_item(struct r
9739  #endif
9740                                 DQUOT_FREE_SPACE_NODIRTY(inode,
9741                                                          quota_cut_bytes);
9742 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
9743                         }
9744                         break;
9745                 }
9746 @@ -1737,6 +1740,7 @@ int reiserfs_cut_from_item(struct reiser
9747                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
9748                        quota_cut_bytes, p_s_inode->i_uid, '?');
9749  #endif
9750 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9751         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9752         return n_ret_value;
9753  }
9754 @@ -1978,6 +1982,11 @@ int reiserfs_paste_into_item(struct reis
9755                 pathrelse(p_s_search_path);
9756                 return -EDQUOT;
9757         }
9758 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
9759 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9760 +               pathrelse(p_s_search_path);
9761 +               return -ENOSPC;
9762 +       }
9763         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
9764                        n_pasted_size);
9765  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
9766 @@ -2030,6 +2039,7 @@ int reiserfs_paste_into_item(struct reis
9767                        n_pasted_size, inode->i_uid,
9768                        key2type(&(p_s_key->on_disk_key)));
9769  #endif
9770 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
9771         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9772         return retval;
9773  }
9774 @@ -2067,6 +2077,11 @@ int reiserfs_insert_item(struct reiserfs
9775                         pathrelse(p_s_path);
9776                         return -EDQUOT;
9777                 }
9778 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
9779 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9780 +                       pathrelse(p_s_path);
9781 +                       return -ENOSPC;
9782 +               }
9783         }
9784         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
9785                        IH_SIZE + ih_item_len(p_s_ih));
9786 @@ -2114,7 +2129,9 @@ int reiserfs_insert_item(struct reiserfs
9787                        "reiserquota insert_item(): freeing %u id=%u type=%c",
9788                        quota_bytes, inode->i_uid, head2type(p_s_ih));
9789  #endif
9790 -       if (inode)
9791 +       if (inode) {
9792 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
9793                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9794 +       }
9795         return retval;
9796  }
9797 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/super.c linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/super.c
9798 --- linux-2.6.22.10/fs/reiserfs/super.c 2007-07-09 13:19:28 +0200
9799 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/super.c      2007-08-05 20:53:13 +0200
9800 @@ -882,6 +882,14 @@ static int reiserfs_parse_options(struct
9801                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
9802                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
9803  #endif
9804 +#ifndef CONFIG_TAGGING_NONE
9805 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
9806 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
9807 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
9808 +#endif
9809 +#ifdef CONFIG_PROPAGATE
9810 +               {"tag",.arg_required = 'T',.values = NULL},
9811 +#endif
9812  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
9813                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
9814                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
9815 @@ -1143,6 +1151,12 @@ static int reiserfs_remount(struct super
9816                 return -EINVAL;
9817         }
9818  
9819 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
9820 +               !(s->s_flags & MS_TAGGED)) {
9821 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
9822 +               return -EINVAL;
9823 +       }
9824 +
9825         handle_attrs(s);
9826  
9827         /* Add options that are safe here */
9828 @@ -1591,6 +1605,10 @@ static int reiserfs_fill_super(struct su
9829                 goto error;
9830         }
9831  
9832 +       /* map mount option tagxid */
9833 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
9834 +               s->s_flags |= MS_TAGGED;
9835 +
9836         rs = SB_DISK_SUPER_BLOCK(s);
9837         /* Let's do basic sanity check to verify that underlying device is not
9838            smaller than the filesystem. If the check fails then abort and scream,
9839 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/xattr.c linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/xattr.c
9840 --- linux-2.6.22.10/fs/reiserfs/xattr.c 2007-07-09 13:19:28 +0200
9841 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/xattr.c      2007-08-05 20:53:13 +0200
9842 @@ -35,6 +35,7 @@
9843  #include <linux/namei.h>
9844  #include <linux/errno.h>
9845  #include <linux/fs.h>
9846 +#include <linux/mount.h>
9847  #include <linux/file.h>
9848  #include <linux/pagemap.h>
9849  #include <linux/xattr.h>
9850 @@ -775,7 +776,7 @@ int reiserfs_delete_xattrs(struct inode 
9851         if (dir->d_inode->i_nlink <= 2) {
9852                 root = get_xa_root(inode->i_sb, XATTR_REPLACE);
9853                 reiserfs_write_lock_xattrs(inode->i_sb);
9854 -               err = vfs_rmdir(root->d_inode, dir);
9855 +               err = vfs_rmdir(root->d_inode, dir, NULL);
9856                 reiserfs_write_unlock_xattrs(inode->i_sb);
9857                 dput(root);
9858         } else {
9859 diff -NurpP --minimal linux-2.6.22.10/fs/stat.c linux-2.6.22.10-vs2.3.0.29/fs/stat.c
9860 --- linux-2.6.22.10/fs/stat.c   2007-07-09 13:19:28 +0200
9861 +++ linux-2.6.22.10-vs2.3.0.29/fs/stat.c        2007-08-05 20:53:13 +0200
9862 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
9863         stat->nlink = inode->i_nlink;
9864         stat->uid = inode->i_uid;
9865         stat->gid = inode->i_gid;
9866 +       stat->tag = inode->i_tag;
9867         stat->rdev = inode->i_rdev;
9868         stat->atime = inode->i_atime;
9869         stat->mtime = inode->i_mtime;
9870 diff -NurpP --minimal linux-2.6.22.10/fs/super.c linux-2.6.22.10-vs2.3.0.29/fs/super.c
9871 --- linux-2.6.22.10/fs/super.c  2007-07-09 13:19:28 +0200
9872 +++ linux-2.6.22.10-vs2.3.0.29/fs/super.c       2007-10-20 00:00:59 +0200
9873 @@ -37,6 +37,9 @@
9874  #include <linux/idr.h>
9875  #include <linux/kobject.h>
9876  #include <linux/mutex.h>
9877 +#include <linux/devpts_fs.h>
9878 +#include <linux/proc_fs.h>
9879 +#include <linux/vs_context.h>
9880  #include <asm/uaccess.h>
9881  
9882  
9883 @@ -860,12 +863,18 @@ struct vfsmount *
9884  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
9885  {
9886         struct vfsmount *mnt;
9887 +       struct super_block *sb;
9888         char *secdata = NULL;
9889         int error;
9890  
9891         if (!type)
9892                 return ERR_PTR(-ENODEV);
9893  
9894 +       error = -EPERM;
9895 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
9896 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
9897 +               goto out;
9898 +
9899         error = -ENOMEM;
9900         mnt = alloc_vfsmnt(name);
9901         if (!mnt)
9902 @@ -885,7 +894,14 @@ vfs_kern_mount(struct file_system_type *
9903         if (error < 0)
9904                 goto out_free_secdata;
9905  
9906 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
9907 +       sb = mnt->mnt_sb;
9908 +       error = -EPERM;
9909 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
9910 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
9911 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
9912 +               goto out_sb;
9913 +
9914 +       error = security_sb_kern_mount(sb, secdata);
9915         if (error)
9916                 goto out_sb;
9917  
9918 diff -NurpP --minimal linux-2.6.22.10/fs/sysfs/mount.c linux-2.6.22.10-vs2.3.0.29/fs/sysfs/mount.c
9919 --- linux-2.6.22.10/fs/sysfs/mount.c    2007-07-09 13:19:28 +0200
9920 +++ linux-2.6.22.10-vs2.3.0.29/fs/sysfs/mount.c 2007-08-05 20:53:13 +0200
9921 @@ -12,8 +12,6 @@
9922  
9923  #include "sysfs.h"
9924  
9925 -/* Random magic number */
9926 -#define SYSFS_MAGIC 0x62656572
9927  
9928  struct vfsmount *sysfs_mount;
9929  struct super_block * sysfs_sb = NULL;
9930 @@ -48,7 +46,7 @@ static int sysfs_fill_super(struct super
9931  
9932         sb->s_blocksize = PAGE_CACHE_SIZE;
9933         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
9934 -       sb->s_magic = SYSFS_MAGIC;
9935 +       sb->s_magic = SYSFS_SUPER_MAGIC;
9936         sb->s_op = &sysfs_ops;
9937         sb->s_time_gran = 1;
9938         sysfs_sb = sb;
9939 diff -NurpP --minimal linux-2.6.22.10/fs/utimes.c linux-2.6.22.10-vs2.3.0.29/fs/utimes.c
9940 --- linux-2.6.22.10/fs/utimes.c 2007-07-09 13:19:29 +0200
9941 +++ linux-2.6.22.10-vs2.3.0.29/fs/utimes.c      2007-08-05 20:53:13 +0200
9942 @@ -6,6 +6,8 @@
9943  #include <linux/sched.h>
9944  #include <linux/stat.h>
9945  #include <linux/utime.h>
9946 +#include <linux/mount.h>
9947 +#include <linux/vs_cowbl.h>
9948  #include <asm/uaccess.h>
9949  #include <asm/unistd.h>
9950  
9951 @@ -70,11 +72,13 @@ long do_utimes(int dfd, char __user *fil
9952                 if (error)
9953                         goto out;
9954  
9955 +               error = cow_check_and_break(&nd);
9956 +               if (error)
9957 +                       goto dput_and_out;
9958                 dentry = nd.dentry;
9959         }
9960  
9961         inode = dentry->d_inode;
9962 -
9963         error = -EROFS;
9964         if (IS_RDONLY(inode))
9965                 goto dput_and_out;
9966 diff -NurpP --minimal linux-2.6.22.10/fs/xattr.c linux-2.6.22.10-vs2.3.0.29/fs/xattr.c
9967 --- linux-2.6.22.10/fs/xattr.c  2007-07-09 13:19:29 +0200
9968 +++ linux-2.6.22.10-vs2.3.0.29/fs/xattr.c       2007-08-05 20:53:13 +0200
9969 @@ -17,6 +17,7 @@
9970  #include <linux/module.h>
9971  #include <linux/fsnotify.h>
9972  #include <linux/audit.h>
9973 +#include <linux/mount.h>
9974  #include <asm/uaccess.h>
9975  
9976  
9977 @@ -194,7 +195,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
9978   */
9979  static long
9980  setxattr(struct dentry *d, char __user *name, void __user *value,
9981 -        size_t size, int flags)
9982 +        size_t size, int flags, struct vfsmount *mnt)
9983  {
9984         int error;
9985         void *kvalue = NULL;
9986 @@ -221,6 +222,9 @@ setxattr(struct dentry *d, char __user *
9987                 }
9988         }
9989  
9990 +       if (MNT_IS_RDONLY(mnt))
9991 +               return -EROFS;
9992 +
9993         error = vfs_setxattr(d, kname, kvalue, size, flags);
9994         kfree(kvalue);
9995         return error;
9996 @@ -236,7 +240,7 @@ sys_setxattr(char __user *path, char __u
9997         error = user_path_walk(path, &nd);
9998         if (error)
9999                 return error;
10000 -       error = setxattr(nd.dentry, name, value, size, flags);
10001 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
10002         path_release(&nd);
10003         return error;
10004  }
10005 @@ -251,7 +255,7 @@ sys_lsetxattr(char __user *path, char __
10006         error = user_path_walk_link(path, &nd);
10007         if (error)
10008                 return error;
10009 -       error = setxattr(nd.dentry, name, value, size, flags);
10010 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
10011         path_release(&nd);
10012         return error;
10013  }
10014 @@ -269,7 +273,7 @@ sys_fsetxattr(int fd, char __user *name,
10015                 return error;
10016         dentry = f->f_path.dentry;
10017         audit_inode(NULL, dentry->d_inode);
10018 -       error = setxattr(dentry, name, value, size, flags);
10019 +       error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt);
10020         fput(f);
10021         return error;
10022  }
10023 @@ -433,7 +437,7 @@ sys_flistxattr(int fd, char __user *list
10024   * Extended attribute REMOVE operations
10025   */
10026  static long
10027 -removexattr(struct dentry *d, char __user *name)
10028 +removexattr(struct dentry *d, char __user *name, struct vfsmount *mnt)
10029  {
10030         int error;
10031         char kname[XATTR_NAME_MAX + 1];
10032 @@ -444,6 +448,9 @@ removexattr(struct dentry *d, char __use
10033         if (error < 0)
10034                 return error;
10035  
10036 +       if (MNT_IS_RDONLY(mnt))
10037 +               return -EROFS;
10038 +
10039         return vfs_removexattr(d, kname);
10040  }
10041  
10042 @@ -456,7 +463,7 @@ sys_removexattr(char __user *path, char 
10043         error = user_path_walk(path, &nd);
10044         if (error)
10045                 return error;
10046 -       error = removexattr(nd.dentry, name);
10047 +       error = removexattr(nd.dentry, name, nd.mnt);
10048         path_release(&nd);
10049         return error;
10050  }
10051 @@ -470,7 +477,7 @@ sys_lremovexattr(char __user *path, char
10052         error = user_path_walk_link(path, &nd);
10053         if (error)
10054                 return error;
10055 -       error = removexattr(nd.dentry, name);
10056 +       error = removexattr(nd.dentry, name, nd.mnt);
10057         path_release(&nd);
10058         return error;
10059  }
10060 @@ -487,7 +494,7 @@ sys_fremovexattr(int fd, char __user *na
10061                 return error;
10062         dentry = f->f_path.dentry;
10063         audit_inode(NULL, dentry->d_inode);
10064 -       error = removexattr(dentry, name);
10065 +       error = removexattr(dentry, name, f->f_vfsmnt);
10066         fput(f);
10067         return error;
10068  }
10069 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_ioctl.c
10070 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_ioctl.c        2007-05-02 19:25:22 +0200
10071 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_ioctl.c     2007-08-05 20:53:13 +0200
10072 @@ -1128,6 +1128,10 @@ xfs_di2lxflags(
10073  
10074         if (di_flags & XFS_DIFLAG_IMMUTABLE)
10075                 flags |= FS_IMMUTABLE_FL;
10076 +       if (di_flags & XFS_DIFLAG_IUNLINK)
10077 +               flags |= FS_IUNLINK_FL;
10078 +       if (di_flags & XFS_DIFLAG_BARRIER)
10079 +               flags |= FS_BARRIER_FL;
10080         if (di_flags & XFS_DIFLAG_APPEND)
10081                 flags |= FS_APPEND_FL;
10082         if (di_flags & XFS_DIFLAG_SYNC)
10083 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_iops.c
10084 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_iops.c 2007-05-02 19:25:22 +0200
10085 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_iops.c      2007-08-05 20:53:13 +0200
10086 @@ -51,6 +51,7 @@
10087  #include <linux/xattr.h>
10088  #include <linux/namei.h>
10089  #include <linux/security.h>
10090 +#include <linux/vs_tag.h>
10091  
10092  /*
10093   * Get a XFS inode from a given vnode.
10094 @@ -400,6 +401,7 @@ xfs_vn_lookup(
10095                 d_add(dentry, NULL);
10096                 return NULL;
10097         }
10098 +       dx_propagate_tag(nd, vn_to_inode(cvp));
10099  
10100         return d_splice_alias(vn_to_inode(cvp), dentry);
10101  }
10102 @@ -657,6 +659,10 @@ xfs_vn_setattr(
10103         int             flags = 0;
10104         int             error;
10105  
10106 +       error = inode_change_ok(inode, attr);
10107 +       if (error)
10108 +               return error;
10109 +
10110         if (ia_valid & ATTR_UID) {
10111                 vattr.va_mask |= XFS_AT_UID;
10112                 vattr.va_uid = attr->ia_uid;
10113 @@ -665,6 +671,10 @@ xfs_vn_setattr(
10114                 vattr.va_mask |= XFS_AT_GID;
10115                 vattr.va_gid = attr->ia_gid;
10116         }
10117 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode)) {
10118 +               vattr.va_mask |= XFS_AT_TAG;
10119 +               vattr.va_tag = attr->ia_tag;
10120 +       }
10121         if (ia_valid & ATTR_SIZE) {
10122                 vattr.va_mask |= XFS_AT_SIZE;
10123                 vattr.va_size = attr->ia_size;
10124 @@ -710,6 +720,42 @@ xfs_vn_truncate(
10125  }
10126  
10127  STATIC int
10128 +xfs_vn_sync_flags(struct inode *inode)
10129 +{
10130 +       unsigned int oldflags, newflags;
10131 +       int             flags = 0;
10132 +       int             error;
10133 +       bhv_vattr_t     vattr;
10134 +       bhv_vnode_t     *vp = vn_from_inode(inode);
10135 +
10136 +       memset(&vattr, 0, sizeof vattr);
10137 +
10138 +       vattr.va_mask = XFS_AT_XFLAGS;
10139 +       error = bhv_vop_getattr(vp, &vattr, 0, NULL);
10140 +
10141 +       if (error)
10142 +               return error;
10143 +       oldflags = vattr.va_xflags;
10144 +       newflags = oldflags & ~(XFS_XFLAG_IMMUTABLE |
10145 +               XFS_XFLAG_IUNLINK | XFS_XFLAG_BARRIER);
10146 +
10147 +       if (IS_IMMUTABLE(inode))
10148 +               newflags |= XFS_XFLAG_IMMUTABLE;
10149 +       if (IS_IUNLINK(inode))
10150 +               newflags |= XFS_XFLAG_IUNLINK;
10151 +       if (IS_BARRIER(inode))
10152 +               newflags |= XFS_XFLAG_BARRIER;
10153 +
10154 +       if (oldflags ^ newflags) {
10155 +               vattr.va_xflags = newflags;
10156 +               vattr.va_mask |= XFS_AT_XFLAGS;
10157 +               error = bhv_vop_setattr(vp, &vattr, flags, NULL);
10158 +       }
10159 +       vn_revalidate(vp);
10160 +       return error;
10161 +}
10162 +
10163 +STATIC int
10164  xfs_vn_setxattr(
10165         struct dentry   *dentry,
10166         const char      *name,
10167 @@ -822,6 +868,7 @@ const struct inode_operations xfs_inode_
10168         .getxattr               = xfs_vn_getxattr,
10169         .listxattr              = xfs_vn_listxattr,
10170         .removexattr            = xfs_vn_removexattr,
10171 +       .sync_flags             = xfs_vn_sync_flags,
10172  };
10173  
10174  const struct inode_operations xfs_dir_inode_operations = {
10175 @@ -841,6 +888,7 @@ const struct inode_operations xfs_dir_in
10176         .getxattr               = xfs_vn_getxattr,
10177         .listxattr              = xfs_vn_listxattr,
10178         .removexattr            = xfs_vn_removexattr,
10179 +       .sync_flags             = xfs_vn_sync_flags,
10180  };
10181  
10182  const struct inode_operations xfs_symlink_inode_operations = {
10183 @@ -854,4 +902,5 @@ const struct inode_operations xfs_symlin
10184         .getxattr               = xfs_vn_getxattr,
10185         .listxattr              = xfs_vn_listxattr,
10186         .removexattr            = xfs_vn_removexattr,
10187 +       .sync_flags             = xfs_vn_sync_flags,
10188  };
10189 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_linux.h
10190 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_linux.h        2007-05-02 19:25:22 +0200
10191 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_linux.h     2007-08-05 20:53:13 +0200
10192 @@ -129,6 +129,7 @@
10193  #define current_pid()          (current->pid)
10194  #define current_fsuid(cred)    (current->fsuid)
10195  #define current_fsgid(cred)    (current->fsgid)
10196 +#define current_fstag(cred,vp) (dx_current_fstag(vn_to_inode(vp)->i_sb))
10197  #define current_test_flags(f)  (current->flags & (f))
10198  #define current_set_flags_nested(sp, f)                \
10199                 (*(sp) = current->flags, current->flags |= (f))
10200 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_super.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_super.c
10201 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_super.c        2007-07-09 13:19:29 +0200
10202 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_super.c     2007-08-05 20:53:13 +0200
10203 @@ -157,6 +157,7 @@ xfs_revalidate_inode(
10204         inode->i_nlink  = ip->i_d.di_nlink;
10205         inode->i_uid    = ip->i_d.di_uid;
10206         inode->i_gid    = ip->i_d.di_gid;
10207 +       inode->i_tag    = ip->i_d.di_tag;
10208  
10209         switch (inode->i_mode & S_IFMT) {
10210         case S_IFBLK:
10211 @@ -184,6 +185,14 @@ xfs_revalidate_inode(
10212                 inode->i_flags |= S_IMMUTABLE;
10213         else
10214                 inode->i_flags &= ~S_IMMUTABLE;
10215 +       if (ip->i_d.di_flags & XFS_DIFLAG_IUNLINK)
10216 +               inode->i_flags |= S_IUNLINK;
10217 +       else
10218 +               inode->i_flags &= ~S_IUNLINK;
10219 +       if (ip->i_d.di_flags & XFS_DIFLAG_BARRIER)
10220 +               inode->i_flags |= S_BARRIER;
10221 +       else
10222 +               inode->i_flags &= ~S_BARRIER;
10223         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
10224                 inode->i_flags |= S_APPEND;
10225         else
10226 @@ -712,6 +721,12 @@ xfs_fs_remount(
10227         int                     error;
10228  
10229         error = bhv_vfs_parseargs(vfsp, options, args, 1);
10230 +       if ((args->flags2 & XFSMNT2_TAGGED) &&
10231 +               !(sb->s_flags & MS_TAGGED)) {
10232 +               printk("XFS: %s: tagging not permitted on remount.\n",
10233 +                       sb->s_id);
10234 +               error = EINVAL;
10235 +       }
10236         if (!error)
10237                 error = bhv_vfs_mntupdate(vfsp, flags, args);
10238         kmem_free(args, sizeof(*args));
10239 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_vnode.c
10240 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.c        2007-05-02 19:25:22 +0200
10241 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_vnode.c     2007-08-05 20:53:13 +0200
10242 @@ -119,6 +119,7 @@ vn_revalidate_core(
10243         inode->i_nlink      = vap->va_nlink;
10244         inode->i_uid        = vap->va_uid;
10245         inode->i_gid        = vap->va_gid;
10246 +       inode->i_tag        = vap->va_tag;
10247         inode->i_blocks     = vap->va_nblocks;
10248         inode->i_mtime      = vap->va_mtime;
10249         inode->i_ctime      = vap->va_ctime;
10250 @@ -126,6 +127,14 @@ vn_revalidate_core(
10251                 inode->i_flags |= S_IMMUTABLE;
10252         else
10253                 inode->i_flags &= ~S_IMMUTABLE;
10254 +       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10255 +               inode->i_flags |= S_IUNLINK;
10256 +       else
10257 +               inode->i_flags &= ~S_IUNLINK;
10258 +       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10259 +               inode->i_flags |= S_BARRIER;
10260 +       else
10261 +               inode->i_flags &= ~S_BARRIER;
10262         if (vap->va_xflags & XFS_XFLAG_APPEND)
10263                 inode->i_flags |= S_APPEND;
10264         else
10265 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.h linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_vnode.h
10266 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.h        2007-07-09 13:19:29 +0200
10267 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_vnode.h     2007-08-05 20:53:13 +0200
10268 @@ -350,6 +350,7 @@ typedef struct bhv_vattr {
10269         xfs_nlink_t     va_nlink;       /* number of references to file */
10270         uid_t           va_uid;         /* owner user id */
10271         gid_t           va_gid;         /* owner group id */
10272 +       tag_t           va_tag;         /* owner group id */
10273         xfs_ino_t       va_nodeid;      /* file id */
10274         xfs_off_t       va_size;        /* file size in bytes */
10275         u_long          va_blocksize;   /* blocksize preferred for i/o */
10276 @@ -398,13 +399,15 @@ typedef struct bhv_vattr {
10277  #define XFS_AT_PROJID          0x04000000
10278  #define XFS_AT_SIZE_NOPERM     0x08000000
10279  #define XFS_AT_GENCOUNT                0x10000000
10280 +#define XFS_AT_TAG             0x20000000
10281  
10282  #define XFS_AT_ALL     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
10283                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
10284                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
10285                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
10286                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
10287 -               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
10288 +               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT\
10289 +               XFS_AT_TAG)
10290  
10291  #define XFS_AT_STAT    (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
10292                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
10293 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/quota/xfs_qm_syscalls.c
10294 --- linux-2.6.22.10/fs/xfs/quota/xfs_qm_syscalls.c      2007-07-09 13:19:29 +0200
10295 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/quota/xfs_qm_syscalls.c   2007-08-05 20:53:13 +0200
10296 @@ -17,6 +17,7 @@
10297   */
10298  
10299  #include <linux/capability.h>
10300 +#include <linux/vs_context.h>
10301  
10302  #include "xfs.h"
10303  #include "xfs_fs.h"
10304 @@ -211,7 +212,7 @@ xfs_qm_scall_quotaoff(
10305         xfs_qoff_logitem_t      *qoffstart;
10306         int                     nculprits;
10307  
10308 -       if (!force && !capable(CAP_SYS_ADMIN))
10309 +       if (!force && !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10310                 return XFS_ERROR(EPERM);
10311         /*
10312          * No file system can have quotas enabled on disk but not in core.
10313 @@ -380,7 +381,7 @@ xfs_qm_scall_trunc_qfiles(
10314         int             error;
10315         xfs_inode_t     *qip;
10316  
10317 -       if (!capable(CAP_SYS_ADMIN))
10318 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10319                 return XFS_ERROR(EPERM);
10320         error = 0;
10321         if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) {
10322 @@ -425,7 +426,7 @@ xfs_qm_scall_quotaon(
10323         uint            accflags;
10324         __int64_t       sbflags;
10325  
10326 -       if (!capable(CAP_SYS_ADMIN))
10327 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10328                 return XFS_ERROR(EPERM);
10329  
10330         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
10331 @@ -594,7 +595,7 @@ xfs_qm_scall_setqlim(
10332         int                     error;
10333         xfs_qcnt_t              hard, soft;
10334  
10335 -       if (!capable(CAP_SYS_ADMIN))
10336 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10337                 return XFS_ERROR(EPERM);
10338  
10339         if ((newlim->d_fieldmask &
10340 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_clnt.h linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_clnt.h
10341 --- linux-2.6.22.10/fs/xfs/xfs_clnt.h   2006-06-18 04:54:50 +0200
10342 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_clnt.h        2007-08-05 20:53:13 +0200
10343 @@ -99,5 +99,7 @@ struct xfs_mount_args {
10344   */
10345  #define XFSMNT2_COMPAT_IOSIZE  0x00000001      /* don't report large preferred
10346                                                  * I/O size in stat(2) */
10347 +#define XFSMNT2_TAGGED         0x80000000      /* context tagging */
10348 +
10349  
10350  #endif /* __XFS_CLNT_H__ */
10351 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_dinode.h linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_dinode.h
10352 --- linux-2.6.22.10/fs/xfs/xfs_dinode.h 2006-09-20 16:58:40 +0200
10353 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_dinode.h      2007-08-05 20:53:13 +0200
10354 @@ -53,7 +53,8 @@ typedef struct xfs_dinode_core
10355         __uint32_t      di_gid;         /* owner's group id */
10356         __uint32_t      di_nlink;       /* number of links to file */
10357         __uint16_t      di_projid;      /* owner's project id */
10358 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
10359 +       __uint16_t      di_tag;         /* context tagging */
10360 +       __uint8_t       di_pad[6];      /* unused, zeroed space */
10361         __uint16_t      di_flushiter;   /* incremented on flush */
10362         xfs_timestamp_t di_atime;       /* time last accessed */
10363         xfs_timestamp_t di_mtime;       /* time last modified */
10364 @@ -257,6 +258,9 @@ typedef enum xfs_dinode_fmt
10365  #define XFS_DIFLAG_EXTSIZE_BIT      11 /* inode extent size allocator hint */
10366  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
10367  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
10368 +#define XFS_DIFLAG_BARRIER_BIT 14      /* chroot() barrier */
10369 +#define XFS_DIFLAG_IUNLINK_BIT 15      /* immutable unlink */
10370 +
10371  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
10372  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
10373  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
10374 @@ -271,12 +275,15 @@ typedef enum xfs_dinode_fmt
10375  #define XFS_DIFLAG_EXTSIZE       (1 << XFS_DIFLAG_EXTSIZE_BIT)
10376  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
10377  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
10378 +#define XFS_DIFLAG_BARRIER      (1 << XFS_DIFLAG_BARRIER_BIT)
10379 +#define XFS_DIFLAG_IUNLINK      (1 << XFS_DIFLAG_IUNLINK_BIT)
10380  
10381  #define XFS_DIFLAG_ANY \
10382         (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
10383          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
10384          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
10385          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
10386 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG)
10387 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_BARRIER | \
10388 +        XFS_DIFLAG_IUNLINK)
10389  
10390  #endif /* __XFS_DINODE_H__ */
10391 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_fs.h linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_fs.h
10392 --- linux-2.6.22.10/fs/xfs/xfs_fs.h     2006-11-30 21:19:29 +0100
10393 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_fs.h  2007-08-05 20:53:13 +0200
10394 @@ -66,6 +66,8 @@ struct fsxattr {
10395  #define XFS_XFLAG_EXTSIZE      0x00000800      /* extent size allocator hint */
10396  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
10397  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
10398 +#define XFS_XFLAG_BARRIER      0x00004000      /* chroot() barrier */
10399 +#define XFS_XFLAG_IUNLINK      0x00008000      /* immutable unlink */
10400  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
10401  
10402  /*
10403 @@ -294,7 +296,8 @@ typedef struct xfs_bstat {
10404         __s32           bs_extents;     /* number of extents            */
10405         __u32           bs_gen;         /* generation count             */
10406         __u16           bs_projid;      /* project id                   */
10407 -       unsigned char   bs_pad[14];     /* pad space, unused            */
10408 +       __u16           bs_tag;         /* context tagging              */
10409 +       unsigned char   bs_pad[12];     /* pad space, unused            */
10410         __u32           bs_dmevmask;    /* DMIG event mask              */
10411         __u16           bs_dmstate;     /* DMIG state info              */
10412         __u16           bs_aextents;    /* attribute number of extents  */
10413 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_inode.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_inode.c
10414 --- linux-2.6.22.10/fs/xfs/xfs_inode.c  2007-07-09 13:19:34 +0200
10415 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_inode.c       2007-08-05 20:53:13 +0200
10416 @@ -49,6 +49,7 @@
10417  #include "xfs_quota.h"
10418  #include "xfs_acl.h"
10419  
10420 +#include <linux/vs_tag.h>
10421  
10422  kmem_zone_t *xfs_ifork_zone;
10423  kmem_zone_t *xfs_inode_zone;
10424 @@ -736,20 +737,35 @@ xfs_xlate_dinode_core(
10425         xfs_dinode_core_t       *buf_core = (xfs_dinode_core_t *)buf;
10426         xfs_dinode_core_t       *mem_core = (xfs_dinode_core_t *)dip;
10427         xfs_arch_t              arch = ARCH_CONVERT;
10428 +       uint32_t                uid = 0, gid = 0;
10429 +       uint16_t                tag = 0;
10430  
10431         ASSERT(dir);
10432  
10433 +       if (dir < 0) {
10434 +               tag = mem_core->di_tag;
10435 +               /* FIXME: supposed to use superblock flag */
10436 +               uid = TAGINO_UID(1, mem_core->di_uid, tag);
10437 +               gid = TAGINO_GID(1, mem_core->di_gid, tag);
10438 +               tag = TAGINO_TAG(1, tag);
10439 +       }
10440 +
10441         INT_XLATE(buf_core->di_magic, mem_core->di_magic, dir, arch);
10442         INT_XLATE(buf_core->di_mode, mem_core->di_mode, dir, arch);
10443         INT_XLATE(buf_core->di_version, mem_core->di_version, dir, arch);
10444         INT_XLATE(buf_core->di_format, mem_core->di_format, dir, arch);
10445         INT_XLATE(buf_core->di_onlink, mem_core->di_onlink, dir, arch);
10446 -       INT_XLATE(buf_core->di_uid, mem_core->di_uid, dir, arch);
10447 -       INT_XLATE(buf_core->di_gid, mem_core->di_gid, dir, arch);
10448 +       INT_XLATE(buf_core->di_uid, uid, dir, arch);
10449 +       INT_XLATE(buf_core->di_gid, gid, dir, arch);
10450 +       INT_XLATE(buf_core->di_tag, tag, dir, arch);
10451         INT_XLATE(buf_core->di_nlink, mem_core->di_nlink, dir, arch);
10452         INT_XLATE(buf_core->di_projid, mem_core->di_projid, dir, arch);
10453  
10454         if (dir > 0) {
10455 +               /* FIXME: supposed to use superblock flag */
10456 +               mem_core->di_uid = INOTAG_UID(1, uid, gid);
10457 +               mem_core->di_gid = INOTAG_GID(1, uid, gid);
10458 +               mem_core->di_tag = INOTAG_TAG(1, uid, gid, tag);
10459                 memcpy(mem_core->di_pad, buf_core->di_pad,
10460                         sizeof(buf_core->di_pad));
10461         } else {
10462 @@ -797,6 +813,10 @@ _xfs_dic2xflags(
10463                         flags |= XFS_XFLAG_PREALLOC;
10464                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
10465                         flags |= XFS_XFLAG_IMMUTABLE;
10466 +               if (di_flags & XFS_DIFLAG_IUNLINK)
10467 +                       flags |= XFS_XFLAG_IUNLINK;
10468 +               if (di_flags & XFS_DIFLAG_BARRIER)
10469 +                       flags |= XFS_XFLAG_BARRIER;
10470                 if (di_flags & XFS_DIFLAG_APPEND)
10471                         flags |= XFS_XFLAG_APPEND;
10472                 if (di_flags & XFS_DIFLAG_SYNC)
10473 @@ -1129,6 +1149,7 @@ xfs_ialloc(
10474         ASSERT(ip->i_d.di_nlink == nlink);
10475         ip->i_d.di_uid = current_fsuid(cr);
10476         ip->i_d.di_gid = current_fsgid(cr);
10477 +       ip->i_d.di_tag = current_fstag(cr, vp);
10478         ip->i_d.di_projid = prid;
10479         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
10480  
10481 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_itable.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_itable.c
10482 --- linux-2.6.22.10/fs/xfs/xfs_itable.c 2007-07-09 13:19:34 +0200
10483 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_itable.c      2007-08-05 20:53:13 +0200
10484 @@ -89,6 +89,7 @@ xfs_bulkstat_one_iget(
10485         buf->bs_mode = dic->di_mode;
10486         buf->bs_uid = dic->di_uid;
10487         buf->bs_gid = dic->di_gid;
10488 +       buf->bs_tag = dic->di_tag;
10489         buf->bs_size = dic->di_size;
10490         vn_atime_to_bstime(vp, &buf->bs_atime);
10491         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
10492 @@ -163,6 +164,7 @@ xfs_bulkstat_one_dinode(
10493         buf->bs_mode = INT_GET(dic->di_mode, ARCH_CONVERT);
10494         buf->bs_uid = INT_GET(dic->di_uid, ARCH_CONVERT);
10495         buf->bs_gid = INT_GET(dic->di_gid, ARCH_CONVERT);
10496 +       buf->bs_tag = INT_GET(dic->di_tag, ARCH_CONVERT);
10497         buf->bs_size = INT_GET(dic->di_size, ARCH_CONVERT);
10498         buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
10499         buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
10500 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_mount.h linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_mount.h
10501 --- linux-2.6.22.10/fs/xfs/xfs_mount.h  2007-05-02 19:25:23 +0200
10502 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_mount.h       2007-08-05 20:53:13 +0200
10503 @@ -464,6 +464,7 @@ typedef struct xfs_mount {
10504  #define XFS_MOUNT_NO_PERCPU_SB (1ULL << 23)    /* don't use per-cpu superblock
10505                                                    counters */
10506  
10507 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
10508  
10509  /*
10510   * Default minimum read and write sizes.
10511 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_vfsops.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_vfsops.c
10512 --- linux-2.6.22.10/fs/xfs/xfs_vfsops.c 2007-07-09 13:19:34 +0200
10513 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_vfsops.c      2007-08-05 20:53:13 +0200
10514 @@ -300,6 +300,8 @@ xfs_start_flags(
10515  
10516         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
10517                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
10518 +       if (ap->flags2 & XFSMNT2_TAGGED)
10519 +               mp->m_flags |= XFS_MOUNT_TAGGED;
10520  
10521         /*
10522          * no recovery flag requires a read-only mount
10523 @@ -394,6 +396,8 @@ xfs_finish_flags(
10524                         return XFS_ERROR(EINVAL);
10525         }
10526  
10527 +       if (ap->flags2 & XFSMNT2_TAGGED)
10528 +               vfs->vfs_super->s_flags |= MS_TAGGED;
10529         return 0;
10530  }
10531  
10532 @@ -1645,6 +1649,9 @@ xfs_vget(
10533                                          * in stat(). */
10534  #define MNTOPT_ATTR2   "attr2"         /* do use attr2 attribute format */
10535  #define MNTOPT_NOATTR2 "noattr2"       /* do not use attr2 attribute format */
10536 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
10537 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
10538 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
10539  
10540  STATIC unsigned long
10541  suffix_strtoul(char *s, char **endp, unsigned int base)
10542 @@ -1831,6 +1838,19 @@ xfs_parseargs(
10543                         args->flags |= XFSMNT_ATTR2;
10544                 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
10545                         args->flags &= ~XFSMNT_ATTR2;
10546 +#ifndef CONFIG_TAGGING_NONE
10547 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
10548 +                       args->flags2 |= XFSMNT2_TAGGED;
10549 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
10550 +                       args->flags2 &= ~XFSMNT2_TAGGED;
10551 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
10552 +                       args->flags2 |= XFSMNT2_TAGGED;
10553 +#endif
10554 +#ifdef CONFIG_PROPAGATE
10555 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
10556 +                       /* use value */
10557 +                       args->flags2 |= XFSMNT2_TAGGED;
10558 +#endif
10559                 } else if (!strcmp(this_char, "osyncisdsync")) {
10560                         /* no-op, this is now the default */
10561                         cmn_err(CE_WARN,
10562 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_vnodeops.c linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_vnodeops.c
10563 --- linux-2.6.22.10/fs/xfs/xfs_vnodeops.c       2007-07-09 13:19:34 +0200
10564 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_vnodeops.c    2007-08-05 20:53:13 +0200
10565 @@ -159,6 +159,7 @@ xfs_getattr(
10566         vap->va_mode = ip->i_d.di_mode;
10567         vap->va_uid = ip->i_d.di_uid;
10568         vap->va_gid = ip->i_d.di_gid;
10569 +       vap->va_tag = ip->i_d.di_tag;
10570         vap->va_projid = ip->i_d.di_projid;
10571  
10572         /*
10573 @@ -259,6 +260,7 @@ xfs_setattr(
10574         uint                    commit_flags=0;
10575         uid_t                   uid=0, iuid=0;
10576         gid_t                   gid=0, igid=0;
10577 +       tag_t                   tag=0, itag=0;
10578         int                     timeflags = 0;
10579         bhv_vnode_t             *vp;
10580         xfs_prid_t              projid=0, iprojid=0;
10581 @@ -315,6 +317,7 @@ xfs_setattr(
10582             (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID))) {
10583                 uint    qflags = 0;
10584  
10585 +               /* TODO: handle tagging? */
10586                 if ((mask & XFS_AT_UID) && XFS_IS_UQUOTA_ON(mp)) {
10587                         uid = vap->va_uid;
10588                         qflags |= XFS_QMOPT_UQUOTA;
10589 @@ -394,6 +397,8 @@ xfs_setattr(
10590         if (mask &
10591             (XFS_AT_MODE|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_UID|
10592              XFS_AT_GID|XFS_AT_PROJID)) {
10593 +               /* TODO: handle tagging? */
10594 +
10595                 /*
10596                  * CAP_FOWNER overrides the following restrictions:
10597                  *
10598 @@ -442,7 +447,7 @@ xfs_setattr(
10599          * and can change the group id only to a group of which he
10600          * or she is a member.
10601          */
10602 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10603 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10604                 /*
10605                  * These IDs could have changed since we last looked at them.
10606                  * But, we're assured that if the ownership did change
10607 @@ -450,10 +455,12 @@ xfs_setattr(
10608                  * would have changed also.
10609                  */
10610                 iuid = ip->i_d.di_uid;
10611 -               iprojid = ip->i_d.di_projid;
10612                 igid = ip->i_d.di_gid;
10613 -               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10614 +               itag = ip->i_d.di_tag;
10615 +               iprojid = ip->i_d.di_projid;
10616                 uid = (mask & XFS_AT_UID) ? vap->va_uid : iuid;
10617 +               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10618 +               tag = (mask & XFS_AT_TAG) ? vap->va_tag : itag;
10619                 projid = (mask & XFS_AT_PROJID) ? (xfs_prid_t)vap->va_projid :
10620                          iprojid;
10621  
10622 @@ -481,6 +488,7 @@ xfs_setattr(
10623                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
10624                     (XFS_IS_PQUOTA_ON(mp) && iprojid != projid) ||
10625                     (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
10626 +                       /* TODO: handle tagging? */
10627                         ASSERT(tp);
10628                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
10629                                                 capable(CAP_FOWNER) ?
10630 @@ -706,7 +714,7 @@ xfs_setattr(
10631          * and can change the group id only to a group of which he
10632          * or she is a member.
10633          */
10634 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10635 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10636                 /*
10637                  * CAP_FSETID overrides the following restrictions:
10638                  *
10639 @@ -722,6 +730,9 @@ xfs_setattr(
10640                  * Change the ownerships and register quota modifications
10641                  * in the transaction.
10642                  */
10643 +               if (itag != tag) {
10644 +                       ip->i_d.di_tag = tag;
10645 +               }
10646                 if (iuid != uid) {
10647                         if (XFS_IS_UQUOTA_ON(mp)) {
10648                                 ASSERT(mask & XFS_AT_UID);
10649 @@ -802,6 +813,10 @@ xfs_setattr(
10650                         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
10651                         if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
10652                                 di_flags |= XFS_DIFLAG_IMMUTABLE;
10653 +                       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10654 +                               di_flags |= XFS_DIFLAG_IUNLINK;
10655 +                       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10656 +                               di_flags |= XFS_DIFLAG_BARRIER;
10657                         if (vap->va_xflags & XFS_XFLAG_APPEND)
10658                                 di_flags |= XFS_DIFLAG_APPEND;
10659                         if (vap->va_xflags & XFS_XFLAG_SYNC)
10660 diff -NurpP --minimal linux-2.6.22.10/include/asm-alpha/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-alpha/socket.h
10661 --- linux-2.6.22.10/include/asm-alpha/socket.h  2007-07-09 13:19:35 +0200
10662 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-alpha/socket.h       2007-08-05 20:53:13 +0200
10663 @@ -55,6 +55,8 @@
10664  #define SO_TIMESTAMPNS         35
10665  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10666  
10667 +#define SO_PEERTAG             36
10668 +
10669  /* Security levels - as per NRL IPv6 - don't actually do anything */
10670  #define SO_SECURITY_AUTHENTICATION             19
10671  #define SO_SECURITY_ENCRYPTION_TRANSPORT       20
10672 diff -NurpP --minimal linux-2.6.22.10/include/asm-arm/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-arm/socket.h
10673 --- linux-2.6.22.10/include/asm-arm/socket.h    2007-07-09 13:19:39 +0200
10674 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-arm/socket.h 2007-08-05 20:53:13 +0200
10675 @@ -52,4 +52,6 @@
10676  #define SO_TIMESTAMPNS         35
10677  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10678  
10679 +#define SO_PEERTAG             36
10680 +
10681  #endif /* _ASM_SOCKET_H */
10682 diff -NurpP --minimal linux-2.6.22.10/include/asm-arm/tlb.h linux-2.6.22.10-vs2.3.0.29/include/asm-arm/tlb.h
10683 --- linux-2.6.22.10/include/asm-arm/tlb.h       2006-06-18 04:54:58 +0200
10684 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-arm/tlb.h    2007-08-05 20:53:13 +0200
10685 @@ -28,6 +28,7 @@
10686  #else /* !CONFIG_MMU */
10687  
10688  #include <asm/pgalloc.h>
10689 +#include <linux/vs_memory.h>
10690  
10691  /*
10692   * TLB handling.  This allows us to remove pages from the page
10693 diff -NurpP --minimal linux-2.6.22.10/include/asm-arm26/tlb.h linux-2.6.22.10-vs2.3.0.29/include/asm-arm26/tlb.h
10694 --- linux-2.6.22.10/include/asm-arm26/tlb.h     2006-01-03 17:30:02 +0100
10695 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-arm26/tlb.h  2007-08-05 20:53:13 +0200
10696 @@ -3,6 +3,7 @@
10697  
10698  #include <asm/pgalloc.h>
10699  #include <asm/tlbflush.h>
10700 +#include <linux/vs_memory.h>
10701  
10702  /*
10703   * TLB handling.  This allows us to remove pages from the page
10704 diff -NurpP --minimal linux-2.6.22.10/include/asm-arm26/unistd.h linux-2.6.22.10-vs2.3.0.29/include/asm-arm26/unistd.h
10705 --- linux-2.6.22.10/include/asm-arm26/unistd.h  2007-02-06 03:01:35 +0100
10706 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-arm26/unistd.h       2007-08-05 20:53:13 +0200
10707 @@ -302,6 +302,8 @@
10708  #define __NR_mq_getsetattr             (__NR_SYSCALL_BASE+279)
10709  #define __NR_waitid                    (__NR_SYSCALL_BASE+280)
10710  
10711 +#define __NR_vserver                   (__NR_SYSCALL_BASE+313)
10712 +
10713  /*
10714   * The following SWIs are ARM private. FIXME - make appropriate for arm26
10715   */
10716 diff -NurpP --minimal linux-2.6.22.10/include/asm-cris/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-cris/socket.h
10717 --- linux-2.6.22.10/include/asm-cris/socket.h   2007-07-09 13:19:40 +0200
10718 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-cris/socket.h        2007-08-05 20:53:13 +0200
10719 @@ -54,6 +54,8 @@
10720  #define SO_TIMESTAMPNS         35
10721  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10722  
10723 +#define SO_PEERTAG             36
10724 +
10725  #endif /* _ASM_SOCKET_H */
10726  
10727  
10728 diff -NurpP --minimal linux-2.6.22.10/include/asm-frv/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-frv/socket.h
10729 --- linux-2.6.22.10/include/asm-frv/socket.h    2007-07-09 13:19:40 +0200
10730 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-frv/socket.h 2007-08-05 20:53:13 +0200
10731 @@ -52,5 +52,7 @@
10732  #define SO_TIMESTAMPNS         35
10733  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10734  
10735 +#define SO_PEERTAG             36
10736 +
10737  #endif /* _ASM_SOCKET_H */
10738  
10739 diff -NurpP --minimal linux-2.6.22.10/include/asm-generic/tlb.h linux-2.6.22.10-vs2.3.0.29/include/asm-generic/tlb.h
10740 --- linux-2.6.22.10/include/asm-generic/tlb.h   2006-11-30 21:19:31 +0100
10741 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-generic/tlb.h        2007-08-05 20:53:13 +0200
10742 @@ -14,6 +14,7 @@
10743  #define _ASM_GENERIC__TLB_H
10744  
10745  #include <linux/swap.h>
10746 +#include <linux/vs_memory.h>
10747  #include <asm/pgalloc.h>
10748  #include <asm/tlbflush.h>
10749  
10750 diff -NurpP --minimal linux-2.6.22.10/include/asm-h8300/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-h8300/socket.h
10751 --- linux-2.6.22.10/include/asm-h8300/socket.h  2007-07-09 13:19:40 +0200
10752 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-h8300/socket.h       2007-08-05 20:53:13 +0200
10753 @@ -52,4 +52,6 @@
10754  #define SO_TIMESTAMPNS         35
10755  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10756  
10757 +#define SO_PEERTAG             36
10758 +
10759  #endif /* _ASM_SOCKET_H */
10760 diff -NurpP --minimal linux-2.6.22.10/include/asm-i386/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-i386/socket.h
10761 --- linux-2.6.22.10/include/asm-i386/socket.h   2007-07-09 13:19:42 +0200
10762 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-i386/socket.h        2007-08-05 20:53:13 +0200
10763 @@ -52,4 +52,6 @@
10764  #define SO_TIMESTAMPNS         35
10765  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10766  
10767 +#define SO_PEERTAG             36
10768 +
10769  #endif /* _ASM_SOCKET_H */
10770 diff -NurpP --minimal linux-2.6.22.10/include/asm-ia64/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-ia64/socket.h
10771 --- linux-2.6.22.10/include/asm-ia64/socket.h   2007-07-09 13:19:43 +0200
10772 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-ia64/socket.h        2007-08-05 20:53:13 +0200
10773 @@ -61,4 +61,6 @@
10774  #define SO_TIMESTAMPNS         35
10775  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10776  
10777 +#define SO_PEERTAG             36
10778 +
10779  #endif /* _ASM_IA64_SOCKET_H */
10780 diff -NurpP --minimal linux-2.6.22.10/include/asm-ia64/tlb.h linux-2.6.22.10-vs2.3.0.29/include/asm-ia64/tlb.h
10781 --- linux-2.6.22.10/include/asm-ia64/tlb.h      2006-09-20 16:58:40 +0200
10782 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-ia64/tlb.h   2007-08-05 20:53:13 +0200
10783 @@ -40,6 +40,7 @@
10784  #include <linux/mm.h>
10785  #include <linux/pagemap.h>
10786  #include <linux/swap.h>
10787 +#include <linux/vs_memory.h>
10788  
10789  #include <asm/pgalloc.h>
10790  #include <asm/processor.h>
10791 diff -NurpP --minimal linux-2.6.22.10/include/asm-m32r/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-m32r/socket.h
10792 --- linux-2.6.22.10/include/asm-m32r/socket.h   2007-07-09 13:19:43 +0200
10793 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-m32r/socket.h        2007-08-05 20:53:13 +0200
10794 @@ -52,4 +52,6 @@
10795  #define SO_TIMESTAMPNS         35
10796  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10797  
10798 +#define SO_PEERTAG             36
10799 +
10800  #endif /* _ASM_M32R_SOCKET_H */
10801 diff -NurpP --minimal linux-2.6.22.10/include/asm-mips/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-mips/socket.h
10802 --- linux-2.6.22.10/include/asm-mips/socket.h   2007-07-09 13:19:44 +0200
10803 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-mips/socket.h        2007-08-05 20:53:13 +0200
10804 @@ -73,6 +73,8 @@ To add: #define SO_REUSEPORT 0x0200   /* A
10805  #define SO_TIMESTAMPNS         35
10806  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10807  
10808 +#define SO_PEERTAG             36
10809 +
10810  #ifdef __KERNEL__
10811  
10812  /** sock_type - Socket types
10813 diff -NurpP --minimal linux-2.6.22.10/include/asm-parisc/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-parisc/socket.h
10814 --- linux-2.6.22.10/include/asm-parisc/socket.h 2007-07-09 13:19:44 +0200
10815 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-parisc/socket.h      2007-08-05 20:53:13 +0200
10816 @@ -51,5 +51,6 @@
10817  
10818  #define SO_PEERSEC             0x401d
10819  #define SO_PASSSEC             0x401e
10820 +#define SO_PEERTAG             0x401f
10821  
10822  #endif /* _ASM_SOCKET_H */
10823 diff -NurpP --minimal linux-2.6.22.10/include/asm-powerpc/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/socket.h
10824 --- linux-2.6.22.10/include/asm-powerpc/socket.h        2007-07-09 13:19:44 +0200
10825 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/socket.h     2007-08-05 20:53:13 +0200
10826 @@ -59,4 +59,6 @@
10827  #define SO_TIMESTAMPNS         35
10828  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10829  
10830 +#define SO_PEERTAG             36
10831 +
10832  #endif /* _ASM_POWERPC_SOCKET_H */
10833 diff -NurpP --minimal linux-2.6.22.10/include/asm-powerpc/systbl.h linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/systbl.h
10834 --- linux-2.6.22.10/include/asm-powerpc/systbl.h        2007-07-09 13:19:44 +0200
10835 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/systbl.h     2007-08-05 20:53:13 +0200
10836 @@ -260,7 +260,7 @@ COMPAT_SYS_SPU(fstatfs64)
10837  SYSX(sys_ni_syscall, ppc_fadvise64_64, ppc_fadvise64_64)
10838  PPC_SYS_SPU(rtas)
10839  OLDSYS(debug_setcontext)
10840 -SYSCALL(ni_syscall)
10841 +SYSX(sys_vserver, sys32_vserver, sys_vserver)
10842  COMPAT_SYS(migrate_pages)
10843  COMPAT_SYS(mbind)
10844  COMPAT_SYS(get_mempolicy)
10845 diff -NurpP --minimal linux-2.6.22.10/include/asm-powerpc/unistd.h linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/unistd.h
10846 --- linux-2.6.22.10/include/asm-powerpc/unistd.h        2007-07-09 13:19:45 +0200
10847 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/unistd.h     2007-08-05 20:53:13 +0200
10848 @@ -275,7 +275,7 @@
10849  #endif
10850  #define __NR_rtas              255
10851  #define __NR_sys_debug_setcontext 256
10852 -/* Number 257 is reserved for vserver */
10853 +#define __NR_vserver           257
10854  #define __NR_migrate_pages     258
10855  #define __NR_mbind             259
10856  #define __NR_get_mempolicy     260
10857 diff -NurpP --minimal linux-2.6.22.10/include/asm-s390/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-s390/socket.h
10858 --- linux-2.6.22.10/include/asm-s390/socket.h   2007-07-09 13:19:45 +0200
10859 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-s390/socket.h        2007-08-05 20:53:13 +0200
10860 @@ -60,4 +60,6 @@
10861  #define SO_TIMESTAMPNS         35
10862  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10863  
10864 +#define SO_PEERTAG             36
10865 +
10866  #endif /* _ASM_SOCKET_H */
10867 diff -NurpP --minimal linux-2.6.22.10/include/asm-s390/unistd.h linux-2.6.22.10-vs2.3.0.29/include/asm-s390/unistd.h
10868 --- linux-2.6.22.10/include/asm-s390/unistd.h   2007-07-09 13:19:45 +0200
10869 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-s390/unistd.h        2007-08-05 20:53:13 +0200
10870 @@ -202,7 +202,7 @@
10871  #define __NR_clock_gettime     (__NR_timer_create+6)
10872  #define __NR_clock_getres      (__NR_timer_create+7)
10873  #define __NR_clock_nanosleep   (__NR_timer_create+8)
10874 -/* Number 263 is reserved for vserver */
10875 +#define __NR_vserver           263
10876  #define __NR_statfs64          265
10877  #define __NR_fstatfs64         266
10878  #define __NR_remap_file_pages  267
10879 diff -NurpP --minimal linux-2.6.22.10/include/asm-sh/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-sh/socket.h
10880 --- linux-2.6.22.10/include/asm-sh/socket.h     2007-07-09 13:19:45 +0200
10881 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sh/socket.h  2007-08-05 20:53:13 +0200
10882 @@ -52,4 +52,6 @@
10883  #define SO_TIMESTAMPNS         35
10884  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10885  
10886 +#define SO_PEERTAG             36
10887 +
10888  #endif /* __ASM_SH_SOCKET_H */
10889 diff -NurpP --minimal linux-2.6.22.10/include/asm-sparc/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-sparc/socket.h
10890 --- linux-2.6.22.10/include/asm-sparc/socket.h  2007-07-09 13:19:54 +0200
10891 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc/socket.h       2007-08-05 20:53:13 +0200
10892 @@ -52,6 +52,8 @@
10893  #define SO_TIMESTAMPNS         0x0021
10894  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10895  
10896 +#define SO_PEERTAG             36
10897 +
10898  /* Security levels - as per NRL IPv6 - don't actually do anything */
10899  #define SO_SECURITY_AUTHENTICATION             0x5001
10900  #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
10901 diff -NurpP --minimal linux-2.6.22.10/include/asm-sparc/unistd.h linux-2.6.22.10-vs2.3.0.29/include/asm-sparc/unistd.h
10902 --- linux-2.6.22.10/include/asm-sparc/unistd.h  2007-07-09 13:19:54 +0200
10903 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc/unistd.h       2007-08-05 20:53:13 +0200
10904 @@ -283,7 +283,7 @@
10905  #define __NR_timer_getoverrun  264
10906  #define __NR_timer_delete      265
10907  #define __NR_timer_create      266
10908 -/* #define __NR_vserver                267 Reserved for VSERVER */
10909 +#define __NR_vserver           267
10910  #define __NR_io_setup          268
10911  #define __NR_io_destroy                269
10912  #define __NR_io_submit         270
10913 diff -NurpP --minimal linux-2.6.22.10/include/asm-sparc64/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/socket.h
10914 --- linux-2.6.22.10/include/asm-sparc64/socket.h        2007-07-09 13:19:54 +0200
10915 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/socket.h     2007-08-05 20:53:13 +0200
10916 @@ -52,6 +52,8 @@
10917  #define SO_TIMESTAMPNS         0x0021
10918  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10919  
10920 +#define SO_PEERTAG             0x0022
10921 +
10922  /* Security levels - as per NRL IPv6 - don't actually do anything */
10923  #define SO_SECURITY_AUTHENTICATION             0x5001
10924  #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
10925 diff -NurpP --minimal linux-2.6.22.10/include/asm-sparc64/tlb.h linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/tlb.h
10926 --- linux-2.6.22.10/include/asm-sparc64/tlb.h   2007-07-09 13:19:54 +0200
10927 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/tlb.h        2007-08-05 20:53:13 +0200
10928 @@ -3,6 +3,7 @@
10929  
10930  #include <linux/swap.h>
10931  #include <linux/pagemap.h>
10932 +#include <linux/vs_memory.h>
10933  #include <asm/pgalloc.h>
10934  #include <asm/tlbflush.h>
10935  #include <asm/mmu_context.h>
10936 diff -NurpP --minimal linux-2.6.22.10/include/asm-sparc64/unistd.h linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/unistd.h
10937 --- linux-2.6.22.10/include/asm-sparc64/unistd.h        2007-07-09 13:19:54 +0200
10938 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/unistd.h     2007-08-05 20:53:13 +0200
10939 @@ -285,7 +285,7 @@
10940  #define __NR_timer_getoverrun  264
10941  #define __NR_timer_delete      265
10942  #define __NR_timer_create      266
10943 -/* #define __NR_vserver                267 Reserved for VSERVER */
10944 +#define __NR_vserver           267
10945  #define __NR_io_setup          268
10946  #define __NR_io_destroy                269
10947  #define __NR_io_submit         270
10948 diff -NurpP --minimal linux-2.6.22.10/include/asm-v850/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-v850/socket.h
10949 --- linux-2.6.22.10/include/asm-v850/socket.h   2007-07-09 13:19:55 +0200
10950 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-v850/socket.h        2007-08-05 20:53:13 +0200
10951 @@ -52,4 +52,6 @@
10952  #define SO_TIMESTAMPNS         35
10953  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10954  
10955 +#define SO_PEERTAG             36
10956 +
10957  #endif /* __V850_SOCKET_H__ */
10958 diff -NurpP --minimal linux-2.6.22.10/include/asm-x86_64/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-x86_64/socket.h
10959 --- linux-2.6.22.10/include/asm-x86_64/socket.h 2007-07-09 13:19:55 +0200
10960 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-x86_64/socket.h      2007-08-05 20:53:13 +0200
10961 @@ -52,4 +52,6 @@
10962  #define SO_TIMESTAMPNS         35
10963  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10964  
10965 +#define SO_PEERTAG             36
10966 +
10967  #endif /* _ASM_SOCKET_H */
10968 diff -NurpP --minimal linux-2.6.22.10/include/asm-x86_64/unistd.h linux-2.6.22.10-vs2.3.0.29/include/asm-x86_64/unistd.h
10969 --- linux-2.6.22.10/include/asm-x86_64/unistd.h 2007-07-09 13:19:55 +0200
10970 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-x86_64/unistd.h      2007-08-05 20:53:13 +0200
10971 @@ -532,7 +532,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
10972  #define __NR_utimes            235
10973  __SYSCALL(__NR_utimes, sys_utimes)
10974  #define __NR_vserver           236
10975 -__SYSCALL(__NR_vserver, sys_ni_syscall)
10976 +__SYSCALL(__NR_vserver, sys_vserver)
10977  #define __NR_mbind             237
10978  __SYSCALL(__NR_mbind, sys_mbind)
10979  #define __NR_set_mempolicy     238
10980 diff -NurpP --minimal linux-2.6.22.10/include/asm-xtensa/socket.h linux-2.6.22.10-vs2.3.0.29/include/asm-xtensa/socket.h
10981 --- linux-2.6.22.10/include/asm-xtensa/socket.h 2007-07-09 13:19:55 +0200
10982 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-xtensa/socket.h      2007-08-05 20:53:13 +0200
10983 @@ -63,4 +63,6 @@
10984  #define SO_TIMESTAMPNS         35
10985  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10986  
10987 +#define SO_PEERTAG             36
10988 +
10989  #endif /* _XTENSA_SOCKET_H */
10990 diff -NurpP --minimal linux-2.6.22.10/include/linux/Kbuild linux-2.6.22.10-vs2.3.0.29/include/linux/Kbuild
10991 --- linux-2.6.22.10/include/linux/Kbuild        2007-10-30 01:57:14 +0100
10992 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/Kbuild     2007-09-30 14:58:01 +0200
10993 @@ -351,3 +351,6 @@ unifdef-y += xattr.h
10994  unifdef-y += xfrm.h
10995  
10996  objhdr-y += version.h
10997 +
10998 +header-y += vserver/
10999 +
11000 diff -NurpP --minimal linux-2.6.22.10/include/linux/capability.h linux-2.6.22.10-vs2.3.0.29/include/linux/capability.h
11001 --- linux-2.6.22.10/include/linux/capability.h  2007-07-09 13:19:55 +0200
11002 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/capability.h       2007-08-05 20:53:13 +0200
11003 @@ -237,6 +237,7 @@ typedef __u32 kernel_cap_t;
11004     arbitrary SCSI commands */
11005  /* Allow setting encryption key on loopback filesystem */
11006  /* Allow setting zone reclaim policy */
11007 +/* Allow the selection of a security context */
11008  
11009  #define CAP_SYS_ADMIN        21
11010  
11011 @@ -290,6 +291,11 @@ typedef __u32 kernel_cap_t;
11012  
11013  #define CAP_AUDIT_CONTROL    30
11014  
11015 +/* Allow context manipulations */
11016 +/* Allow changing context info on files */
11017 +
11018 +#define CAP_CONTEXT         31
11019 +
11020  #ifdef __KERNEL__
11021  /* 
11022   * Bounding set
11023 diff -NurpP --minimal linux-2.6.22.10/include/linux/devpts_fs.h linux-2.6.22.10-vs2.3.0.29/include/linux/devpts_fs.h
11024 --- linux-2.6.22.10/include/linux/devpts_fs.h   2004-08-14 12:55:59 +0200
11025 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/devpts_fs.h        2007-10-06 18:19:52 +0200
11026 @@ -30,5 +30,4 @@ static inline void devpts_pty_kill(int n
11027  
11028  #endif
11029  
11030 -
11031  #endif /* _LINUX_DEVPTS_FS_H */
11032 diff -NurpP --minimal linux-2.6.22.10/include/linux/ext2_fs.h linux-2.6.22.10-vs2.3.0.29/include/linux/ext2_fs.h
11033 --- linux-2.6.22.10/include/linux/ext2_fs.h     2006-11-30 21:19:37 +0100
11034 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/ext2_fs.h  2007-10-05 15:07:22 +0200
11035 @@ -188,6 +188,8 @@ struct ext2_group_desc
11036  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
11037  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
11038  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
11039 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
11040 +#define EXT2_IUNLINK_FL                        FS_IUNLINK_FL   /* Immutable unlink */
11041  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
11042  
11043  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
11044 @@ -244,7 +246,7 @@ struct ext2_inode {
11045                 struct {
11046                         __u8    l_i_frag;       /* Fragment number */
11047                         __u8    l_i_fsize;      /* Fragment size */
11048 -                       __u16   i_pad1;
11049 +                       __u16   l_i_tag;        /* Context Tag */
11050                         __le16  l_i_uid_high;   /* these 2 fields    */
11051                         __le16  l_i_gid_high;   /* were reserved2[0] */
11052                         __u32   l_i_reserved2;
11053 @@ -276,6 +278,7 @@ struct ext2_inode {
11054  #define i_gid_low      i_gid
11055  #define i_uid_high     osd2.linux2.l_i_uid_high
11056  #define i_gid_high     osd2.linux2.l_i_gid_high
11057 +#define i_raw_tag      osd2.linux2.l_i_tag
11058  #define i_reserved2    osd2.linux2.l_i_reserved2
11059  #endif
11060  
11061 @@ -317,8 +320,9 @@ struct ext2_inode {
11062  #define EXT2_MOUNT_XATTR_USER          0x004000  /* Extended user attributes */
11063  #define EXT2_MOUNT_POSIX_ACL           0x008000  /* POSIX Access Control Lists */
11064  #define EXT2_MOUNT_XIP                 0x010000  /* Execute in place */
11065 -#define EXT2_MOUNT_USRQUOTA            0x020000 /* user quota */
11066 -#define EXT2_MOUNT_GRPQUOTA            0x040000 /* group quota */
11067 +#define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
11068 +#define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
11069 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
11070  
11071  
11072  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
11073 diff -NurpP --minimal linux-2.6.22.10/include/linux/ext3_fs.h linux-2.6.22.10-vs2.3.0.29/include/linux/ext3_fs.h
11074 --- linux-2.6.22.10/include/linux/ext3_fs.h     2007-07-09 13:19:56 +0200
11075 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/ext3_fs.h  2007-08-05 20:53:13 +0200
11076 @@ -177,6 +177,8 @@ struct ext3_group_desc
11077  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
11078  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
11079  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
11080 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
11081 +#define EXT3_IUNLINK_FL                        0x08000000 /* Immutable unlink */
11082  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
11083  
11084  #define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
11085 @@ -296,7 +298,7 @@ struct ext3_inode {
11086                 struct {
11087                         __u8    l_i_frag;       /* Fragment number */
11088                         __u8    l_i_fsize;      /* Fragment size */
11089 -                       __u16   i_pad1;
11090 +                       __u16   l_i_tag;        /* Context Tag */
11091                         __le16  l_i_uid_high;   /* these 2 fields    */
11092                         __le16  l_i_gid_high;   /* were reserved2[0] */
11093                         __u32   l_i_reserved2;
11094 @@ -330,6 +332,7 @@ struct ext3_inode {
11095  #define i_gid_low      i_gid
11096  #define i_uid_high     osd2.linux2.l_i_uid_high
11097  #define i_gid_high     osd2.linux2.l_i_gid_high
11098 +#define i_raw_tag      osd2.linux2.l_i_tag
11099  #define i_reserved2    osd2.linux2.l_i_reserved2
11100  
11101  #elif defined(__GNU__)
11102 @@ -384,6 +387,7 @@ struct ext3_inode {
11103  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
11104  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
11105  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
11106 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
11107  
11108  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
11109  #ifndef _LINUX_EXT2_FS_H
11110 @@ -812,6 +816,7 @@ struct buffer_head * ext3_bread (handle_
11111  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
11112         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
11113         int create, int extend_disksize);
11114 +extern int ext3_sync_flags(struct inode *inode);
11115  
11116  extern void ext3_read_inode (struct inode *);
11117  extern int  ext3_write_inode (struct inode *, int);
11118 diff -NurpP --minimal linux-2.6.22.10/include/linux/ext4_fs.h linux-2.6.22.10-vs2.3.0.29/include/linux/ext4_fs.h
11119 --- linux-2.6.22.10/include/linux/ext4_fs.h     2007-07-09 13:19:56 +0200
11120 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/ext4_fs.h  2007-08-05 20:53:13 +0200
11121 @@ -189,8 +189,10 @@ struct ext4_group_desc
11122  #define EXT4_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
11123  #define EXT4_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
11124  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
11125 -#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
11126  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
11127 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
11128 +#define EXT4_IUNLINK_FL                        0x08000000 /* Immutable unlink */
11129 +#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
11130  
11131  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
11132  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
11133 @@ -312,7 +314,8 @@ struct ext4_inode {
11134                         __le16  l_i_file_acl_high;
11135                         __le16  l_i_uid_high;   /* these 2 fields */
11136                         __le16  l_i_gid_high;   /* were reserved2[0] */
11137 -                       __u32   l_i_reserved2;
11138 +                       __u16   l_i_tag;        /* Context Tag */
11139 +                       __u16   l_i_reserved2;
11140                 } linux2;
11141                 struct {
11142                         __u8    h_i_frag;       /* Fragment number */
11143 @@ -344,6 +347,7 @@ struct ext4_inode {
11144  #define i_gid_low      i_gid
11145  #define i_uid_high     osd2.linux2.l_i_uid_high
11146  #define i_gid_high     osd2.linux2.l_i_gid_high
11147 +#define i_raw_tag      osd2.linux2.l_i_tag
11148  #define i_reserved2    osd2.linux2.l_i_reserved2
11149  
11150  #elif defined(__GNU__)
11151 @@ -400,6 +404,7 @@ struct ext4_inode {
11152  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
11153  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
11154  #define EXT4_MOUNT_EXTENTS             0x400000 /* Extents support */
11155 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
11156  
11157  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
11158  #ifndef _LINUX_EXT2_FS_H
11159 @@ -850,6 +855,7 @@ struct buffer_head * ext4_bread (handle_
11160  int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
11161         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
11162         int create, int extend_disksize);
11163 +extern int ext4_sync_flags(struct inode *inode);
11164  
11165  extern void ext4_read_inode (struct inode *);
11166  extern int  ext4_write_inode (struct inode *, int);
11167 diff -NurpP --minimal linux-2.6.22.10/include/linux/fs.h linux-2.6.22.10-vs2.3.0.29/include/linux/fs.h
11168 --- linux-2.6.22.10/include/linux/fs.h  2007-07-09 13:19:56 +0200
11169 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/fs.h       2007-10-20 00:01:05 +0200
11170 @@ -123,6 +123,8 @@ extern int dir_notify_enable;
11171  #define MS_SLAVE       (1<<19) /* change to slave */
11172  #define MS_SHARED      (1<<20) /* change to shared */
11173  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
11174 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
11175 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11176  #define MS_ACTIVE      (1<<30)
11177  #define MS_NOUSER      (1<<31)
11178  
11179 @@ -149,6 +151,8 @@ extern int dir_notify_enable;
11180  #define S_NOCMTIME     128     /* Do not update file c/mtime */
11181  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
11182  #define S_PRIVATE      512     /* Inode is fs-internal */
11183 +#define S_BARRIER      1024    /* Barrier for chroot() */
11184 +#define S_IUNLINK      2048    /* Immutable unlink */
11185  
11186  /*
11187   * Note that nosuid etc flags are inode-specific: setting some file-system
11188 @@ -165,24 +169,36 @@ extern int dir_notify_enable;
11189   */
11190  #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
11191  
11192 -#define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
11193 +#define IS_RDONLY(inode)       __IS_FLG(inode, MS_RDONLY)
11194  #define IS_SYNC(inode)         (__IS_FLG(inode, MS_SYNCHRONOUS) || \
11195                                         ((inode)->i_flags & S_SYNC))
11196  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
11197                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
11198  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
11199 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
11200 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
11201 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
11202  
11203  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
11204  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
11205  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
11206 +#define IS_IUNLINK(inode)      ((inode)->i_flags & S_IUNLINK)
11207 +#define IS_IXORUNLINK(inode)   ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
11208  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
11209  
11210 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
11211  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
11212  #define IS_NOCMTIME(inode)     ((inode)->i_flags & S_NOCMTIME)
11213  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
11214  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
11215  
11216 +#ifdef CONFIG_VSERVER_COWBL
11217 +#  define IS_COW(inode)                (IS_IUNLINK(inode) && IS_IMMUTABLE(inode))
11218 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
11219 +#else
11220 +#  define IS_COW(inode)                (0)
11221 +#  define IS_COW_LINK(inode)   (0)
11222 +#endif
11223 +
11224  /* the read-only stuff doesn't really belong here, but any other place is
11225     probably as bad and I don't want to create yet another include file. */
11226  
11227 @@ -256,12 +272,13 @@ extern int dir_notify_enable;
11228  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
11229  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11230  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11231 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11232 +#define FS_IUNLINK_FL                  0x08000000 /* Immutable unlink */
11233  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11234  
11235  #define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11236  #define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11237  
11238 -
11239  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11240  #define SYNC_FILE_RANGE_WRITE          2
11241  #define SYNC_FILE_RANGE_WAIT_AFTER     4
11242 @@ -327,6 +344,7 @@ typedef void (dio_iodone_t)(struct kiocb
11243  #define ATTR_KILL_SUID 2048
11244  #define ATTR_KILL_SGID 4096
11245  #define ATTR_FILE      8192
11246 +#define ATTR_TAG       16384
11247  
11248  /*
11249   * This is the Inode Attributes structure, used for notify_change().  It
11250 @@ -342,6 +360,7 @@ struct iattr {
11251         umode_t         ia_mode;
11252         uid_t           ia_uid;
11253         gid_t           ia_gid;
11254 +       tag_t           ia_tag;
11255         loff_t          ia_size;
11256         struct timespec ia_atime;
11257         struct timespec ia_mtime;
11258 @@ -355,6 +374,9 @@ struct iattr {
11259         struct file     *ia_file;
11260  };
11261  
11262 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
11263 +#define ATTR_FLAG_IUNLINK      1024    /* Immutable unlink */
11264 +
11265  /*
11266   * Includes for diskquotas.
11267   */
11268 @@ -537,7 +559,9 @@ struct inode {
11269         unsigned int            i_nlink;
11270         uid_t                   i_uid;
11271         gid_t                   i_gid;
11272 +       tag_t                   i_tag;
11273         dev_t                   i_rdev;
11274 +       dev_t                   i_mdev;
11275         unsigned long           i_version;
11276         loff_t                  i_size;
11277  #ifdef __NEED_I_SIZE_ORDERED
11278 @@ -672,12 +696,12 @@ static inline void i_size_write(struct i
11279  
11280  static inline unsigned iminor(const struct inode *inode)
11281  {
11282 -       return MINOR(inode->i_rdev);
11283 +       return MINOR(inode->i_mdev);
11284  }
11285  
11286  static inline unsigned imajor(const struct inode *inode)
11287  {
11288 -       return MAJOR(inode->i_rdev);
11289 +       return MAJOR(inode->i_mdev);
11290  }
11291  
11292  extern struct block_device *I_BDEV(struct inode *inode);
11293 @@ -728,6 +752,7 @@ struct file {
11294         loff_t                  f_pos;
11295         struct fown_struct      f_owner;
11296         unsigned int            f_uid, f_gid;
11297 +       xid_t                   f_xid;
11298         struct file_ra_state    f_ra;
11299  
11300         unsigned long           f_version;
11301 @@ -811,6 +836,7 @@ struct file_lock {
11302         unsigned char fl_type;
11303         loff_t fl_start;
11304         loff_t fl_end;
11305 +       xid_t fl_xid;
11306  
11307         struct fasync_struct *  fl_fasync; /* for lease break notifications */
11308         unsigned long fl_break_time;    /* for nonblocking lease breaks */
11309 @@ -993,12 +1019,12 @@ extern void unlock_super(struct super_bl
11310   */
11311  extern int vfs_permission(struct nameidata *, int);
11312  extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
11313 -extern int vfs_mkdir(struct inode *, struct dentry *, int);
11314 -extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
11315 -extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
11316 -extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
11317 -extern int vfs_rmdir(struct inode *, struct dentry *);
11318 -extern int vfs_unlink(struct inode *, struct dentry *);
11319 +extern int vfs_mkdir(struct inode *, struct dentry *, int, struct nameidata *);
11320 +extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t, struct nameidata *);
11321 +extern int vfs_symlink(struct inode *, struct dentry *, const char *, int, struct nameidata *);
11322 +extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct nameidata *);
11323 +extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *);
11324 +extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *);
11325  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
11326  
11327  /*
11328 @@ -1138,6 +1164,7 @@ struct inode_operations {
11329         ssize_t (*listxattr) (struct dentry *, char *, size_t);
11330         int (*removexattr) (struct dentry *, const char *);
11331         void (*truncate_range)(struct inode *, loff_t, loff_t);
11332 +       int (*sync_flags) (struct inode *);
11333  };
11334  
11335  struct seq_file;
11336 @@ -1153,6 +1180,7 @@ extern ssize_t vfs_readv(struct file *, 
11337                 unsigned long, loff_t *);
11338  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
11339                 unsigned long, loff_t *);
11340 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
11341  
11342  /*
11343   * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
11344 @@ -1898,6 +1926,7 @@ extern int dcache_dir_open(struct inode 
11345  extern int dcache_dir_close(struct inode *, struct file *);
11346  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
11347  extern int dcache_readdir(struct file *, void *, filldir_t);
11348 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
11349  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
11350  extern int simple_statfs(struct dentry *, struct kstatfs *);
11351  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
11352 diff -NurpP --minimal linux-2.6.22.10/include/linux/init_task.h linux-2.6.22.10-vs2.3.0.29/include/linux/init_task.h
11353 --- linux-2.6.22.10/include/linux/init_task.h   2007-07-09 13:19:56 +0200
11354 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/init_task.h        2007-08-05 20:53:13 +0200
11355 @@ -169,6 +169,10 @@ extern struct group_info init_groups;
11356         },                                                              \
11357         INIT_TRACE_IRQFLAGS                                             \
11358         INIT_LOCKDEP                                                    \
11359 +       .xid            = 0,                                            \
11360 +       .vx_info        = NULL,                                         \
11361 +       .nid            = 0,                                            \
11362 +       .nx_info        = NULL,                                         \
11363  }
11364  
11365  
11366 diff -NurpP --minimal linux-2.6.22.10/include/linux/ipc.h linux-2.6.22.10-vs2.3.0.29/include/linux/ipc.h
11367 --- linux-2.6.22.10/include/linux/ipc.h 2007-07-09 13:19:56 +0200
11368 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/ipc.h      2007-08-05 20:53:13 +0200
11369 @@ -63,6 +63,7 @@ struct kern_ipc_perm
11370         key_t           key;
11371         uid_t           uid;
11372         gid_t           gid;
11373 +       xid_t           xid;
11374         uid_t           cuid;
11375         gid_t           cgid;
11376         mode_t          mode; 
11377 diff -NurpP --minimal linux-2.6.22.10/include/linux/jffs2.h linux-2.6.22.10-vs2.3.0.29/include/linux/jffs2.h
11378 --- linux-2.6.22.10/include/linux/jffs2.h       2006-11-30 21:19:38 +0100
11379 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/jffs2.h    2007-10-05 15:07:22 +0200
11380 @@ -82,12 +82,36 @@
11381  //#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
11382  
11383  
11384 -#define JFFS2_INO_FLAG_PREREAD   1     /* Do read_inode() for this one at
11385 +#define JFFS2_INO_FLAG_PREREAD   0x01  /* Do read_inode() for this one at
11386                                            mount time, don't wait for it to
11387                                            happen later */
11388 -#define JFFS2_INO_FLAG_USERCOMPR  2    /* User has requested a specific
11389 +#define JFFS2_INO_FLAG_USERCOMPR 0x02  /* User has requested a specific
11390                                            compression type */
11391  
11392 +#define JFFS2_INO_FLAG_IMMUTABLE 0x10  /* immutable node */
11393 +#define JFFS2_INO_FLAG_IUNLINK   0x20  /* immutable unlink */
11394 +#define JFFS2_INO_FLAG_BARRIER   0x40  /* barrier */
11395 +
11396 +#define JFFS2_USER_VISIBLE       0x10
11397 +#define JFFS2_USER_MODIFIABLE    0x10
11398 +
11399 +/*
11400 + * Mount flags
11401 + */
11402 +#define JFFS2_MOUNT_TAGGED     (1<<24)   /* Enable Context Tags */
11403 +
11404 +#define clear_opt(o, opt)      o &= ~JFFS2_MOUNT_##opt
11405 +#define set_opt(o, opt)                o |= JFFS2_MOUNT_##opt
11406 +
11407 +/*
11408 + * Maximal mount counts between two filesystem checks
11409 + */
11410 +#define EXT2_DFL_MAX_MNT_COUNT         20      /* Allow 20 mounts */
11411 +#define EXT2_DFL_CHECKINTERVAL         0       /* Don't use interval check */
11412 +
11413 +/*
11414 + * Behaviour when detecting errors
11415 + */
11416  
11417  /* These can go once we've made sure we've caught all uses without
11418     byteswapping */
11419 @@ -97,7 +121,7 @@ typedef struct {
11420  } __attribute__((packed)) jint32_t;
11421  
11422  typedef struct {
11423 -       uint32_t m;
11424 +       uint16_t m;
11425  } __attribute__((packed)) jmode_t;
11426  
11427  typedef struct {
11428 @@ -145,7 +169,8 @@ struct jffs2_raw_inode
11429         jint32_t hdr_crc;
11430         jint32_t ino;        /* Inode number.  */
11431         jint32_t version;    /* Version number.  */
11432 -       jmode_t mode;       /* The file's type or mode.  */
11433 +       jmode_t mode;        /* The file's type or mode.  */
11434 +       jint16_t tag;        /* context tagging */
11435         jint16_t uid;        /* The file's owner.  */
11436         jint16_t gid;        /* The file's group.  */
11437         jint32_t isize;      /* Total resultant size of this inode (used for truncations)  */
11438 diff -NurpP --minimal linux-2.6.22.10/include/linux/loop.h linux-2.6.22.10-vs2.3.0.29/include/linux/loop.h
11439 --- linux-2.6.22.10/include/linux/loop.h        2007-07-09 13:19:56 +0200
11440 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/loop.h     2007-08-05 20:53:13 +0200
11441 @@ -45,6 +45,7 @@ struct loop_device {
11442         struct loop_func_table *lo_encryption;
11443         __u32           lo_init[2];
11444         uid_t           lo_key_owner;   /* Who set the key */
11445 +       xid_t           lo_xid;
11446         int             (*ioctl)(struct loop_device *, int cmd, 
11447                                  unsigned long arg); 
11448  
11449 diff -NurpP --minimal linux-2.6.22.10/include/linux/magic.h linux-2.6.22.10-vs2.3.0.29/include/linux/magic.h
11450 --- linux-2.6.22.10/include/linux/magic.h       2007-07-09 13:19:56 +0200
11451 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/magic.h    2007-10-06 18:19:33 +0200
11452 @@ -3,7 +3,7 @@
11453  
11454  #define ADFS_SUPER_MAGIC       0xadf5
11455  #define AFFS_SUPER_MAGIC       0xadff
11456 -#define AFS_SUPER_MAGIC                0x5346414F
11457 +#define AFS_SUPER_MAGIC                0x5346414F
11458  #define AUTOFS_SUPER_MAGIC     0x0187
11459  #define CODA_SUPER_MAGIC       0x73757245
11460  #define EFS_SUPER_MAGIC                0x414A53
11461 @@ -27,6 +27,7 @@
11462  #define NFS_SUPER_MAGIC                0x6969
11463  #define OPENPROM_SUPER_MAGIC   0x9fa1
11464  #define PROC_SUPER_MAGIC       0x9fa0
11465 +#define DEVPTS_SUPER_MAGIC     0x1cd1
11466  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
11467  
11468  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
11469 diff -NurpP --minimal linux-2.6.22.10/include/linux/major.h linux-2.6.22.10-vs2.3.0.29/include/linux/major.h
11470 --- linux-2.6.22.10/include/linux/major.h       2007-07-09 13:19:56 +0200
11471 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/major.h    2007-08-05 20:53:13 +0200
11472 @@ -15,6 +15,7 @@
11473  #define HD_MAJOR               IDE0_MAJOR
11474  #define PTY_SLAVE_MAJOR                3
11475  #define TTY_MAJOR              4
11476 +#define VROOT_MAJOR            4
11477  #define TTYAUX_MAJOR           5
11478  #define LP_MAJOR               6
11479  #define VCS_MAJOR              7
11480 diff -NurpP --minimal linux-2.6.22.10/include/linux/mount.h linux-2.6.22.10-vs2.3.0.29/include/linux/mount.h
11481 --- linux-2.6.22.10/include/linux/mount.h       2007-07-09 13:19:56 +0200
11482 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/mount.h    2007-09-05 02:29:04 +0200
11483 @@ -28,6 +28,9 @@ struct mnt_namespace;
11484  #define MNT_NOATIME    0x08
11485  #define MNT_NODIRATIME 0x10
11486  #define MNT_RELATIME   0x20
11487 +#define MNT_RDONLY     0x40
11488 +
11489 +#define MNT_IS_RDONLY(m)       ((m) && ((m)->mnt_flags & MNT_RDONLY))
11490  
11491  #define MNT_SHRINKABLE 0x100
11492  
11493 @@ -35,6 +38,10 @@ struct mnt_namespace;
11494  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
11495  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
11496  
11497 +#define MNT_TAGID      0x10000
11498 +#define MNT_NOTAG      0x20000
11499 +#define MNT_NOTAGCHECK 0x40000
11500 +
11501  struct vfsmount {
11502         struct list_head mnt_hash;
11503         struct vfsmount *mnt_parent;    /* fs we are mounted on */
11504 @@ -61,6 +68,7 @@ struct vfsmount {
11505         atomic_t mnt_count;
11506         int mnt_expiry_mark;            /* true if marked for expiry */
11507         int mnt_pinned;
11508 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
11509  };
11510  
11511  static inline struct vfsmount *mntget(struct vfsmount *mnt)
11512 diff -NurpP --minimal linux-2.6.22.10/include/linux/net.h linux-2.6.22.10-vs2.3.0.29/include/linux/net.h
11513 --- linux-2.6.22.10/include/linux/net.h 2007-07-09 13:19:56 +0200
11514 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/net.h      2007-08-05 20:53:13 +0200
11515 @@ -63,6 +63,7 @@ typedef enum {
11516  #define SOCK_NOSPACE           2
11517  #define SOCK_PASSCRED          3
11518  #define SOCK_PASSSEC           4
11519 +#define SOCK_USER_SOCKET       5
11520  
11521  #ifndef ARCH_HAS_SOCKET_TYPES
11522  /**
11523 diff -NurpP --minimal linux-2.6.22.10/include/linux/nfs_mount.h linux-2.6.22.10-vs2.3.0.29/include/linux/nfs_mount.h
11524 --- linux-2.6.22.10/include/linux/nfs_mount.h   2007-07-09 13:20:00 +0200
11525 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/nfs_mount.h        2007-08-05 20:53:13 +0200
11526 @@ -62,6 +62,7 @@ struct nfs_mount_data {
11527  #define NFS_MOUNT_STRICTLOCK   0x1000  /* reserved for NFSv4 */
11528  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
11529  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11530 +#define NFS_MOUNT_TAGGED       0x8000  /* context tagging */
11531  #define NFS_MOUNT_FLAGMASK     0xFFFF
11532  
11533  #endif
11534 diff -NurpP --minimal linux-2.6.22.10/include/linux/nsproxy.h linux-2.6.22.10-vs2.3.0.29/include/linux/nsproxy.h
11535 --- linux-2.6.22.10/include/linux/nsproxy.h     2007-07-09 13:20:00 +0200
11536 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/nsproxy.h  2007-08-05 20:53:13 +0200
11537 @@ -3,6 +3,7 @@
11538  
11539  #include <linux/spinlock.h>
11540  #include <linux/sched.h>
11541 +#include <linux/vserver/debug.h>
11542  
11543  struct mnt_namespace;
11544  struct uts_namespace;
11545 @@ -32,26 +33,46 @@ struct nsproxy {
11546  extern struct nsproxy init_nsproxy;
11547  
11548  int copy_namespaces(int flags, struct task_struct *tsk);
11549 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
11550  void get_task_namespaces(struct task_struct *tsk);
11551  void free_nsproxy(struct nsproxy *ns);
11552  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
11553         struct fs_struct *);
11554  
11555 -static inline void put_nsproxy(struct nsproxy *ns)
11556 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
11557 +
11558 +static inline void __get_nsproxy(struct nsproxy *ns,
11559 +       const char *_file, int _line)
11560  {
11561 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
11562 +               ns, atomic_read(&ns->count), _file, _line);
11563 +       atomic_inc(&ns->count);
11564 +}
11565 +
11566 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
11567 +
11568 +static inline void __put_nsproxy(struct nsproxy *ns,
11569 +       const char *_file, int _line)
11570 +{
11571 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
11572 +               ns, atomic_read(&ns->count), _file, _line);
11573         if (atomic_dec_and_test(&ns->count)) {
11574                 free_nsproxy(ns);
11575         }
11576  }
11577  
11578 -static inline void exit_task_namespaces(struct task_struct *p)
11579 +#define        exit_task_namespaces(p) __exit_task_namespaces(p, __FILE__, __LINE__)
11580 +
11581 +static inline void __exit_task_namespaces(struct task_struct *p,
11582 +       const char *_file, int _line)
11583  {
11584         struct nsproxy *ns = p->nsproxy;
11585         if (ns) {
11586                 task_lock(p);
11587                 p->nsproxy = NULL;
11588                 task_unlock(p);
11589 -               put_nsproxy(ns);
11590 +               __put_nsproxy(ns, _file, _line);
11591         }
11592  }
11593 +
11594  #endif
11595 diff -NurpP --minimal linux-2.6.22.10/include/linux/pid.h linux-2.6.22.10-vs2.3.0.29/include/linux/pid.h
11596 --- linux-2.6.22.10/include/linux/pid.h 2007-07-09 13:20:00 +0200
11597 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/pid.h      2007-08-05 20:53:13 +0200
11598 @@ -8,7 +8,8 @@ enum pid_type
11599         PIDTYPE_PID,
11600         PIDTYPE_PGID,
11601         PIDTYPE_SID,
11602 -       PIDTYPE_MAX
11603 +       PIDTYPE_MAX,
11604 +       PIDTYPE_REALPID
11605  };
11606  
11607  /*
11608 diff -NurpP --minimal linux-2.6.22.10/include/linux/proc_fs.h linux-2.6.22.10-vs2.3.0.29/include/linux/proc_fs.h
11609 --- linux-2.6.22.10/include/linux/proc_fs.h     2007-07-09 13:20:00 +0200
11610 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/proc_fs.h  2007-08-05 20:53:13 +0200
11611 @@ -54,6 +54,7 @@ struct proc_dir_entry {
11612         nlink_t nlink;
11613         uid_t uid;
11614         gid_t gid;
11615 +       int vx_flags;
11616         loff_t size;
11617         const struct inode_operations *proc_iops;
11618         const struct file_operations *proc_fops;
11619 @@ -246,13 +247,20 @@ static inline void kclist_add(struct kco
11620  extern void kclist_add(struct kcore_list *, void *, size_t);
11621  #endif
11622  
11623 +struct vx_info;
11624 +struct nx_info;
11625 +
11626  union proc_op {
11627         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
11628         int (*proc_read)(struct task_struct *task, char *page);
11629 +       int (*proc_vs_read)(char *page);
11630 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
11631 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
11632  };
11633  
11634  struct proc_inode {
11635         struct pid *pid;
11636 +       int vx_flags;
11637         int fd;
11638         union proc_op op;
11639         struct proc_dir_entry *pde;
11640 diff -NurpP --minimal linux-2.6.22.10/include/linux/reiserfs_fs.h linux-2.6.22.10-vs2.3.0.29/include/linux/reiserfs_fs.h
11641 --- linux-2.6.22.10/include/linux/reiserfs_fs.h 2007-05-02 19:25:34 +0200
11642 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/reiserfs_fs.h      2007-08-05 20:53:13 +0200
11643 @@ -821,6 +821,10 @@ struct stat_data_v1 {
11644  #define REISERFS_COMPR_FL     FS_COMPR_FL
11645  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
11646  
11647 +/* unfortunately reiserfs sdattr is only 16 bit */
11648 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
11649 +#define REISERFS_IUNLINK_FL   (FS_IUNLINK_FL >> 16)
11650 +
11651  /* persistent flags that file inherits from the parent directory */
11652  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
11653                                 REISERFS_SYNC_FL |      \
11654 @@ -830,6 +834,9 @@ struct stat_data_v1 {
11655                                 REISERFS_COMPR_FL |     \
11656                                 REISERFS_NOTAIL_FL )
11657  
11658 +#define REISERFS_FL_USER_VISIBLE       0x80FF
11659 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
11660 +
11661  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
11662     address blocks) */
11663  struct stat_data {
11664 @@ -1901,6 +1908,7 @@ static inline void reiserfs_update_sd(st
11665  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
11666  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
11667  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
11668 +int reiserfs_sync_flags(struct inode *inode);
11669  
11670  /* namei.c */
11671  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
11672 diff -NurpP --minimal linux-2.6.22.10/include/linux/reiserfs_fs_sb.h linux-2.6.22.10-vs2.3.0.29/include/linux/reiserfs_fs_sb.h
11673 --- linux-2.6.22.10/include/linux/reiserfs_fs_sb.h      2007-07-09 13:20:00 +0200
11674 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/reiserfs_fs_sb.h   2007-08-05 20:53:13 +0200
11675 @@ -458,6 +458,7 @@ enum reiserfs_mount_options {
11676         REISERFS_POSIXACL,
11677         REISERFS_BARRIER_NONE,
11678         REISERFS_BARRIER_FLUSH,
11679 +       REISERFS_TAGGED,
11680  
11681         /* Actions on error */
11682         REISERFS_ERROR_PANIC,
11683 diff -NurpP --minimal linux-2.6.22.10/include/linux/sched.h linux-2.6.22.10-vs2.3.0.29/include/linux/sched.h
11684 --- linux-2.6.22.10/include/linux/sched.h       2007-07-09 13:20:01 +0200
11685 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sched.h    2007-10-04 23:47:06 +0200
11686 @@ -26,6 +26,7 @@
11687  #define CLONE_STOPPED          0x02000000      /* Start in stopped state */
11688  #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
11689  #define CLONE_NEWIPC           0x08000000      /* New ipcs */
11690 +#define CLONE_KTHREAD          0x10000000      /* clone a kernel thread */
11691  
11692  /*
11693   * Scheduling policies
11694 @@ -94,7 +95,7 @@ struct bio;
11695   * List of flags we want to share for kernel threads,
11696   * if only because they are not used by them anyway.
11697   */
11698 -#define CLONE_KERNEL   (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
11699 +#define CLONE_KERNEL   (CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_KTHREAD)
11700  
11701  /*
11702   * These are the constant used to fake the fixed-point load-average
11703 @@ -146,12 +147,13 @@ extern unsigned long weighted_cpuload(co
11704  #define TASK_UNINTERRUPTIBLE   2
11705  #define TASK_STOPPED           4
11706  #define TASK_TRACED            8
11707 +#define TASK_ONHOLD            16
11708  /* in tsk->exit_state */
11709 -#define EXIT_ZOMBIE            16
11710 -#define EXIT_DEAD              32
11711 +#define EXIT_ZOMBIE            32
11712 +#define EXIT_DEAD              64
11713  /* in tsk->state again */
11714 -#define TASK_NONINTERACTIVE    64
11715 -#define TASK_DEAD              128
11716 +#define TASK_NONINTERACTIVE    128
11717 +#define TASK_DEAD              256
11718  
11719  #define __set_task_state(tsk, state_value)             \
11720         do { (tsk)->state = (state_value); } while (0)
11721 @@ -287,27 +289,30 @@ extern void arch_unmap_area_topdown(stru
11722   * The mm counters are not protected by its page_table_lock,
11723   * so must be incremented atomically.
11724   */
11725 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
11726 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
11727 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
11728 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
11729 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
11730  typedef atomic_long_t mm_counter_t;
11731 +#define __set_mm_counter(mm, member, value) \
11732 +       atomic_long_set(&(mm)->_##member, value)
11733 +#define get_mm_counter(mm, member) \
11734 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
11735  
11736  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11737  /*
11738   * The mm counters are protected by its page_table_lock,
11739   * so can be incremented directly.
11740   */
11741 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
11742 -#define get_mm_counter(mm, member) ((mm)->_##member)
11743 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
11744 -#define inc_mm_counter(mm, member) (mm)->_##member++
11745 -#define dec_mm_counter(mm, member) (mm)->_##member--
11746  typedef unsigned long mm_counter_t;
11747 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
11748 +#define get_mm_counter(mm, member) ((mm)->_##member)
11749  
11750  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11751  
11752 +#define set_mm_counter(mm, member, value) \
11753 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
11754 +#define add_mm_counter(mm, member, value) \
11755 +       vx_ ## member ## pages_add((mm), (value))
11756 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
11757 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
11758 +
11759  #define get_mm_rss(mm)                                 \
11760         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
11761  #define update_hiwater_rss(mm) do {                    \
11762 @@ -365,6 +370,7 @@ struct mm_struct {
11763  
11764         /* Architecture-specific MM context */
11765         mm_context_t context;
11766 +       struct vx_info *mm_vx_info;
11767  
11768         /* Swap token stuff */
11769         /*
11770 @@ -570,9 +576,10 @@ struct user_struct {
11771         /* Hash table maintenance information */
11772         struct list_head uidhash_list;
11773         uid_t uid;
11774 +       xid_t xid;
11775  };
11776  
11777 -extern struct user_struct *find_user(uid_t);
11778 +extern struct user_struct *find_user(xid_t, uid_t);
11779  
11780  extern struct user_struct root_user;
11781  #define INIT_USER (&root_user)
11782 @@ -969,6 +976,15 @@ struct task_struct {
11783         
11784         void *security;
11785         struct audit_context *audit_context;
11786 +
11787 +/* vserver context data */
11788 +       struct vx_info *vx_info;
11789 +       struct nx_info *nx_info;
11790 +
11791 +       xid_t xid;
11792 +       nid_t nid;
11793 +       tag_t tag;
11794 +
11795         seccomp_t seccomp;
11796  
11797  /* Thread group tracking */
11798 @@ -1290,12 +1306,16 @@ extern struct task_struct init_task;
11799  
11800  extern struct   mm_struct init_mm;
11801  
11802 -#define find_task_by_pid(nr)   find_task_by_pid_type(PIDTYPE_PID, nr)
11803 +#define find_task_by_real_pid(nr) \
11804 +       find_task_by_pid_type(PIDTYPE_REALPID, nr)
11805 +#define find_task_by_pid(nr) \
11806 +       find_task_by_pid_type(PIDTYPE_PID, nr)
11807 +
11808  extern struct task_struct *find_task_by_pid_type(int type, int pid);
11809  extern void __set_special_pids(pid_t session, pid_t pgrp);
11810  
11811  /* per-UID process charging. */
11812 -extern struct user_struct * alloc_uid(uid_t);
11813 +extern struct user_struct * alloc_uid(xid_t, uid_t);
11814  static inline struct user_struct *get_uid(struct user_struct *u)
11815  {
11816         atomic_inc(&u->__count);
11817 diff -NurpP --minimal linux-2.6.22.10/include/linux/shmem_fs.h linux-2.6.22.10-vs2.3.0.29/include/linux/shmem_fs.h
11818 --- linux-2.6.22.10/include/linux/shmem_fs.h    2006-11-30 21:19:39 +0100
11819 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/shmem_fs.h 2007-08-05 20:53:13 +0200
11820 @@ -8,6 +8,9 @@
11821  
11822  #define SHMEM_NR_DIRECT 16
11823  
11824 +#define TMPFS_SUPER_MAGIC      0x01021994
11825 +
11826 +
11827  struct shmem_inode_info {
11828         spinlock_t              lock;
11829         unsigned long           flags;
11830 diff -NurpP --minimal linux-2.6.22.10/include/linux/stat.h linux-2.6.22.10-vs2.3.0.29/include/linux/stat.h
11831 --- linux-2.6.22.10/include/linux/stat.h        2007-07-09 13:20:01 +0200
11832 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/stat.h     2007-08-05 20:53:13 +0200
11833 @@ -66,6 +66,7 @@ struct kstat {
11834         unsigned int    nlink;
11835         uid_t           uid;
11836         gid_t           gid;
11837 +       tag_t           tag;
11838         dev_t           rdev;
11839         loff_t          size;
11840         struct timespec  atime;
11841 diff -NurpP --minimal linux-2.6.22.10/include/linux/sunrpc/auth.h linux-2.6.22.10-vs2.3.0.29/include/linux/sunrpc/auth.h
11842 --- linux-2.6.22.10/include/linux/sunrpc/auth.h 2006-11-30 21:19:40 +0100
11843 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sunrpc/auth.h      2007-08-05 20:53:13 +0200
11844 @@ -24,6 +24,7 @@
11845  struct auth_cred {
11846         uid_t   uid;
11847         gid_t   gid;
11848 +       tag_t   tag;
11849         struct group_info *group_info;
11850  };
11851  
11852 diff -NurpP --minimal linux-2.6.22.10/include/linux/sunrpc/clnt.h linux-2.6.22.10-vs2.3.0.29/include/linux/sunrpc/clnt.h
11853 --- linux-2.6.22.10/include/linux/sunrpc/clnt.h 2007-07-09 13:20:01 +0200
11854 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sunrpc/clnt.h      2007-08-05 20:53:13 +0200
11855 @@ -43,7 +43,8 @@ struct rpc_clnt {
11856                                 cl_discrtry : 1,/* disconnect before retry */
11857                                 cl_autobind : 1,/* use getport() */
11858                                 cl_oneshot  : 1,/* dispose after use */
11859 -                               cl_dead     : 1;/* abandoned */
11860 +                               cl_dead     : 1,/* abandoned */
11861 +                               cl_tag      : 1;/* context tagging */
11862  
11863         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
11864  
11865 diff -NurpP --minimal linux-2.6.22.10/include/linux/syscalls.h linux-2.6.22.10-vs2.3.0.29/include/linux/syscalls.h
11866 --- linux-2.6.22.10/include/linux/syscalls.h    2007-07-09 13:20:01 +0200
11867 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/syscalls.h 2007-08-05 20:53:13 +0200
11868 @@ -294,6 +294,8 @@ asmlinkage long sys_symlink(const char _
11869  asmlinkage long sys_unlink(const char __user *pathname);
11870  asmlinkage long sys_rename(const char __user *oldname,
11871                                 const char __user *newname);
11872 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
11873 +                               umode_t mode);
11874  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
11875  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
11876  
11877 diff -NurpP --minimal linux-2.6.22.10/include/linux/sysctl.h linux-2.6.22.10-vs2.3.0.29/include/linux/sysctl.h
11878 --- linux-2.6.22.10/include/linux/sysctl.h      2007-07-09 13:20:01 +0200
11879 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sysctl.h   2007-08-05 20:53:13 +0200
11880 @@ -106,6 +106,7 @@ enum
11881         KERN_CAP_BSET=14,       /* int: capability bounding set */
11882         KERN_PANIC=15,          /* int: panic timeout */
11883         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11884 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11885  
11886         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11887         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11888 diff -NurpP --minimal linux-2.6.22.10/include/linux/sysfs.h linux-2.6.22.10-vs2.3.0.29/include/linux/sysfs.h
11889 --- linux-2.6.22.10/include/linux/sysfs.h       2007-07-09 13:20:01 +0200
11890 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sysfs.h    2007-08-05 20:53:13 +0200
11891 @@ -15,6 +15,8 @@
11892  #include <linux/list.h>
11893  #include <asm/atomic.h>
11894  
11895 +#define SYSFS_SUPER_MAGIC      0x62656572
11896 +
11897  struct kobject;
11898  struct module;
11899  struct nameidata;
11900 diff -NurpP --minimal linux-2.6.22.10/include/linux/time.h linux-2.6.22.10-vs2.3.0.29/include/linux/time.h
11901 --- linux-2.6.22.10/include/linux/time.h        2007-07-09 13:20:01 +0200
11902 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/time.h     2007-08-05 20:53:13 +0200
11903 @@ -176,6 +176,9 @@ static inline void timespec_add_ns(struc
11904         }
11905         a->tv_nsec = ns;
11906  }
11907 +
11908 +#include <linux/vs_time.h>
11909 +
11910  #endif /* __KERNEL__ */
11911  
11912  #define NFDBITS                        __NFDBITS
11913 diff -NurpP --minimal linux-2.6.22.10/include/linux/types.h linux-2.6.22.10-vs2.3.0.29/include/linux/types.h
11914 --- linux-2.6.22.10/include/linux/types.h       2007-02-06 03:01:52 +0100
11915 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/types.h    2007-08-05 20:53:13 +0200
11916 @@ -39,6 +39,9 @@ typedef __kernel_uid32_t      uid_t;
11917  typedef __kernel_gid32_t       gid_t;
11918  typedef __kernel_uid16_t        uid16_t;
11919  typedef __kernel_gid16_t        gid16_t;
11920 +typedef unsigned int           xid_t;
11921 +typedef unsigned int           nid_t;
11922 +typedef unsigned int           tag_t;
11923  
11924  #ifdef CONFIG_UID16
11925  /* This is defined by include/asm-{arch}/posix_types.h */
11926 diff -NurpP --minimal linux-2.6.22.10/include/linux/vroot.h linux-2.6.22.10-vs2.3.0.29/include/linux/vroot.h
11927 --- linux-2.6.22.10/include/linux/vroot.h       1970-01-01 01:00:00 +0100
11928 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vroot.h    2007-08-05 20:53:13 +0200
11929 @@ -0,0 +1,51 @@
11930 +
11931 +/*
11932 + * include/linux/vroot.h
11933 + *
11934 + * written by Herbert Pötzl, 9/11/2002
11935 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
11936 + *
11937 + * Copyright (C) 2002-2007 by Herbert Pötzl.
11938 + * Redistribution of this file is permitted under the
11939 + * GNU General Public License.
11940 + */
11941 +
11942 +#ifndef _LINUX_VROOT_H
11943 +#define _LINUX_VROOT_H
11944 +
11945 +
11946 +#ifdef __KERNEL__
11947 +
11948 +/* Possible states of device */
11949 +enum {
11950 +       Vr_unbound,
11951 +       Vr_bound,
11952 +};
11953 +
11954 +struct vroot_device {
11955 +       int             vr_number;
11956 +       int             vr_refcnt;
11957 +
11958 +       struct semaphore        vr_ctl_mutex;
11959 +       struct block_device    *vr_device;
11960 +       int                     vr_state;
11961 +};
11962 +
11963 +
11964 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
11965 +
11966 +extern int register_vroot_grb(vroot_grb_func *);
11967 +extern int unregister_vroot_grb(vroot_grb_func *);
11968 +
11969 +#endif /* __KERNEL__ */
11970 +
11971 +#define MAX_VROOT_DEFAULT      8
11972 +
11973 +/*
11974 + * IOCTL commands --- we will commandeer 0x56 ('V')
11975 + */
11976 +
11977 +#define VROOT_SET_DEV          0x5600
11978 +#define VROOT_CLR_DEV          0x5601
11979 +
11980 +#endif /* _LINUX_VROOT_H */
11981 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_base.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_base.h
11982 --- linux-2.6.22.10/include/linux/vs_base.h     1970-01-01 01:00:00 +0100
11983 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_base.h  2007-08-05 20:53:13 +0200
11984 @@ -0,0 +1,9 @@
11985 +#ifndef _VS_BASE_H
11986 +#define _VS_BASE_H
11987 +
11988 +#include "vserver/base.h"
11989 +#include "vserver/debug.h"
11990 +
11991 +#else
11992 +#warning duplicate inclusion
11993 +#endif
11994 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_context.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_context.h
11995 --- linux-2.6.22.10/include/linux/vs_context.h  1970-01-01 01:00:00 +0100
11996 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_context.h       2007-10-01 14:57:41 +0200
11997 @@ -0,0 +1,224 @@
11998 +#ifndef _VS_CONTEXT_H
11999 +#define _VS_CONTEXT_H
12000 +
12001 +#include "vserver/base.h"
12002 +#include "vserver/context.h"
12003 +#include "vserver/history.h"
12004 +#include "vserver/debug.h"
12005 +
12006 +
12007 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
12008 +
12009 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
12010 +       const char *_file, int _line, void *_here)
12011 +{
12012 +       if (!vxi)
12013 +               return NULL;
12014 +
12015 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
12016 +               vxi, vxi ? vxi->vx_id : 0,
12017 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12018 +               _file, _line);
12019 +       __vxh_get_vx_info(vxi, _here);
12020 +
12021 +       atomic_inc(&vxi->vx_usecnt);
12022 +       return vxi;
12023 +}
12024 +
12025 +
12026 +extern void free_vx_info(struct vx_info *);
12027 +
12028 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
12029 +
12030 +static inline void __put_vx_info(struct vx_info *vxi,
12031 +       const char *_file, int _line, void *_here)
12032 +{
12033 +       if (!vxi)
12034 +               return;
12035 +
12036 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
12037 +               vxi, vxi ? vxi->vx_id : 0,
12038 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12039 +               _file, _line);
12040 +       __vxh_put_vx_info(vxi, _here);
12041 +
12042 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
12043 +               free_vx_info(vxi);
12044 +}
12045 +
12046 +
12047 +#define init_vx_info(p, i) \
12048 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
12049 +
12050 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
12051 +       const char *_file, int _line, void *_here)
12052 +{
12053 +       if (vxi) {
12054 +               vxlprintk(VXD_CBIT(xid, 3),
12055 +                       "init_vx_info(%p[#%d.%d])",
12056 +                       vxi, vxi ? vxi->vx_id : 0,
12057 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12058 +                       _file, _line);
12059 +               __vxh_init_vx_info(vxi, vxp, _here);
12060 +
12061 +               atomic_inc(&vxi->vx_usecnt);
12062 +       }
12063 +       *vxp = vxi;
12064 +}
12065 +
12066 +
12067 +#define set_vx_info(p, i) \
12068 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
12069 +
12070 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
12071 +       const char *_file, int _line, void *_here)
12072 +{
12073 +       struct vx_info *vxo;
12074 +
12075 +       if (!vxi)
12076 +               return;
12077 +
12078 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
12079 +               vxi, vxi ? vxi->vx_id : 0,
12080 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12081 +               _file, _line);
12082 +       __vxh_set_vx_info(vxi, vxp, _here);
12083 +
12084 +       atomic_inc(&vxi->vx_usecnt);
12085 +       vxo = xchg(vxp, vxi);
12086 +       BUG_ON(vxo);
12087 +}
12088 +
12089 +
12090 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
12091 +
12092 +static inline void __clr_vx_info(struct vx_info **vxp,
12093 +       const char *_file, int _line, void *_here)
12094 +{
12095 +       struct vx_info *vxo;
12096 +
12097 +       vxo = xchg(vxp, NULL);
12098 +       if (!vxo)
12099 +               return;
12100 +
12101 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
12102 +               vxo, vxo ? vxo->vx_id : 0,
12103 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
12104 +               _file, _line);
12105 +       __vxh_clr_vx_info(vxo, vxp, _here);
12106 +
12107 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
12108 +               free_vx_info(vxo);
12109 +}
12110 +
12111 +
12112 +#define claim_vx_info(v, p) \
12113 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12114 +
12115 +static inline void __claim_vx_info(struct vx_info *vxi,
12116 +       struct task_struct *task,
12117 +       const char *_file, int _line, void *_here)
12118 +{
12119 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
12120 +               vxi, vxi ? vxi->vx_id : 0,
12121 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12122 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12123 +               task, _file, _line);
12124 +       __vxh_claim_vx_info(vxi, task, _here);
12125 +
12126 +       atomic_inc(&vxi->vx_tasks);
12127 +}
12128 +
12129 +
12130 +extern void unhash_vx_info(struct vx_info *);
12131 +
12132 +#define release_vx_info(v, p) \
12133 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12134 +
12135 +static inline void __release_vx_info(struct vx_info *vxi,
12136 +       struct task_struct *task,
12137 +       const char *_file, int _line, void *_here)
12138 +{
12139 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
12140 +               vxi, vxi ? vxi->vx_id : 0,
12141 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12142 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12143 +               task, _file, _line);
12144 +       __vxh_release_vx_info(vxi, task, _here);
12145 +
12146 +       might_sleep();
12147 +
12148 +       if (atomic_dec_and_test(&vxi->vx_tasks))
12149 +               unhash_vx_info(vxi);
12150 +}
12151 +
12152 +
12153 +#define task_get_vx_info(p) \
12154 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
12155 +
12156 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
12157 +       const char *_file, int _line, void *_here)
12158 +{
12159 +       struct vx_info *vxi;
12160 +
12161 +       task_lock(p);
12162 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
12163 +               p, _file, _line);
12164 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
12165 +       task_unlock(p);
12166 +       return vxi;
12167 +}
12168 +
12169 +
12170 +static inline void __wakeup_vx_info(struct vx_info *vxi)
12171 +{
12172 +       if (waitqueue_active(&vxi->vx_wait))
12173 +               wake_up_interruptible(&vxi->vx_wait);
12174 +}
12175 +
12176 +
12177 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
12178 +
12179 +static inline void __enter_vx_info(struct vx_info *vxi,
12180 +       struct vx_info_save *vxis, const char *_file, int _line)
12181 +{
12182 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
12183 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
12184 +               current->xid, current->vx_info, _file, _line);
12185 +       vxis->vxi = xchg(&current->vx_info, vxi);
12186 +       vxis->xid = current->xid;
12187 +       current->xid = vxi ? vxi->vx_id : 0;
12188 +}
12189 +
12190 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
12191 +
12192 +static inline void __leave_vx_info(struct vx_info_save *vxis,
12193 +       const char *_file, int _line)
12194 +{
12195 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
12196 +               vxis, vxis->xid, vxis->vxi, current,
12197 +               current->xid, current->vx_info, _file, _line);
12198 +       (void)xchg(&current->vx_info, vxis->vxi);
12199 +       current->xid = vxis->xid;
12200 +}
12201 +
12202 +
12203 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
12204 +{
12205 +       vxis->vxi = xchg(&current->vx_info, NULL);
12206 +       vxis->xid = xchg(&current->xid, (xid_t)0);
12207 +}
12208 +
12209 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
12210 +{
12211 +       (void)xchg(&current->xid, vxis->xid);
12212 +       (void)xchg(&current->vx_info, vxis->vxi);
12213 +}
12214 +
12215 +extern void exit_vx_info(struct task_struct *, int);
12216 +extern void exit_vx_info_early(struct task_struct *, int);
12217 +
12218 +
12219 +#else
12220 +#warning duplicate inclusion
12221 +#endif
12222 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_cowbl.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_cowbl.h
12223 --- linux-2.6.22.10/include/linux/vs_cowbl.h    1970-01-01 01:00:00 +0100
12224 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_cowbl.h 2007-08-05 20:53:13 +0200
12225 @@ -0,0 +1,44 @@
12226 +#ifndef _VS_COWBL_H
12227 +#define _VS_COWBL_H
12228 +
12229 +#include <linux/fs.h>
12230 +#include <linux/dcache.h>
12231 +#include <linux/namei.h>
12232 +
12233 +extern struct dentry *cow_break_link(const char *pathname);
12234 +
12235 +static inline int cow_check_and_break(struct nameidata *nd)
12236 +{
12237 +       struct inode *inode = nd->dentry->d_inode;
12238 +       int error = 0;
12239 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
12240 +               return -EROFS;
12241 +       if (IS_COW(inode)) {
12242 +               if (IS_COW_LINK(inode)) {
12243 +                       struct dentry *new_dentry, *old_dentry = nd->dentry;
12244 +                       char *path, *buf;
12245 +
12246 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
12247 +                       if (!buf) {
12248 +                               return -ENOMEM;
12249 +                       }
12250 +                       path = d_path(nd->dentry, nd->mnt, buf, PATH_MAX);
12251 +                       new_dentry = cow_break_link(path);
12252 +                       kfree(buf);
12253 +                       if (!IS_ERR(new_dentry)) {
12254 +                               nd->dentry = new_dentry;
12255 +                               dput(old_dentry);
12256 +                       } else
12257 +                               error = PTR_ERR(new_dentry);
12258 +               } else {
12259 +                       inode->i_flags &= ~(S_IUNLINK | S_IMMUTABLE);
12260 +                       inode->i_ctime = CURRENT_TIME;
12261 +                       mark_inode_dirty(inode);
12262 +               }
12263 +       }
12264 +       return error;
12265 +}
12266 +
12267 +#else
12268 +#warning duplicate inclusion
12269 +#endif
12270 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_cvirt.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_cvirt.h
12271 --- linux-2.6.22.10/include/linux/vs_cvirt.h    1970-01-01 01:00:00 +0100
12272 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_cvirt.h 2007-08-05 20:53:13 +0200
12273 @@ -0,0 +1,49 @@
12274 +#ifndef _VS_CVIRT_H
12275 +#define _VS_CVIRT_H
12276 +
12277 +#include "vserver/cvirt.h"
12278 +#include "vserver/context.h"
12279 +#include "vserver/base.h"
12280 +#include "vserver/debug.h"
12281 +
12282 +
12283 +static inline void vx_activate_task(struct task_struct *p)
12284 +{
12285 +       struct vx_info *vxi;
12286 +
12287 +       if ((vxi = p->vx_info)) {
12288 +               vx_update_load(vxi);
12289 +               atomic_inc(&vxi->cvirt.nr_running);
12290 +       }
12291 +}
12292 +
12293 +static inline void vx_deactivate_task(struct task_struct *p)
12294 +{
12295 +       struct vx_info *vxi;
12296 +
12297 +       if ((vxi = p->vx_info)) {
12298 +               vx_update_load(vxi);
12299 +               atomic_dec(&vxi->cvirt.nr_running);
12300 +       }
12301 +}
12302 +
12303 +static inline void vx_uninterruptible_inc(struct task_struct *p)
12304 +{
12305 +       struct vx_info *vxi;
12306 +
12307 +       if ((vxi = p->vx_info))
12308 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
12309 +}
12310 +
12311 +static inline void vx_uninterruptible_dec(struct task_struct *p)
12312 +{
12313 +       struct vx_info *vxi;
12314 +
12315 +       if ((vxi = p->vx_info))
12316 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
12317 +}
12318 +
12319 +
12320 +#else
12321 +#warning duplicate inclusion
12322 +#endif
12323 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_device.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_device.h
12324 --- linux-2.6.22.10/include/linux/vs_device.h   1970-01-01 01:00:00 +0100
12325 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_device.h        2007-10-11 01:10:22 +0200
12326 @@ -0,0 +1,45 @@
12327 +#ifndef _VS_DEVICE_H
12328 +#define _VS_DEVICE_H
12329 +
12330 +#include "vserver/base.h"
12331 +#include "vserver/device.h"
12332 +#include "vserver/debug.h"
12333 +
12334 +
12335 +#ifdef CONFIG_VSERVER_DEVICE
12336 +
12337 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
12338 +
12339 +#define vs_device_perm(v, d, m, p) \
12340 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
12341 +
12342 +#else
12343 +
12344 +static inline
12345 +int vs_map_device(struct vx_info *vxi,
12346 +       dev_t device, dev_t *target, umode_t mode)
12347 +{
12348 +       if (target)
12349 +               *target = device;
12350 +       return ~0;
12351 +}
12352 +
12353 +#define vs_device_perm(v, d, m, p) ((p) == (p))
12354 +
12355 +#endif
12356 +
12357 +
12358 +#define vs_map_chrdev(d, t, p) \
12359 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
12360 +#define vs_map_blkdev(d, t, p) \
12361 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
12362 +
12363 +#define vs_chrdev_perm(d, p) \
12364 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
12365 +#define vs_blkdev_perm(d, p) \
12366 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
12367 +
12368 +
12369 +#else
12370 +#warning duplicate inclusion
12371 +#endif
12372 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_dlimit.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_dlimit.h
12373 --- linux-2.6.22.10/include/linux/vs_dlimit.h   1970-01-01 01:00:00 +0100
12374 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_dlimit.h        2007-08-15 22:04:43 +0200
12375 @@ -0,0 +1,211 @@
12376 +#ifndef _VS_DLIMIT_H
12377 +#define _VS_DLIMIT_H
12378 +
12379 +#include <linux/fs.h>
12380 +
12381 +#include "vserver/dlimit.h"
12382 +#include "vserver/base.h"
12383 +#include "vserver/debug.h"
12384 +
12385 +
12386 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
12387 +
12388 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
12389 +       const char *_file, int _line)
12390 +{
12391 +       if (!dli)
12392 +               return NULL;
12393 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
12394 +               dli, dli ? dli->dl_tag : 0,
12395 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12396 +               _file, _line);
12397 +       atomic_inc(&dli->dl_usecnt);
12398 +       return dli;
12399 +}
12400 +
12401 +
12402 +#define free_dl_info(i) \
12403 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
12404 +
12405 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
12406 +
12407 +static inline void __put_dl_info(struct dl_info *dli,
12408 +       const char *_file, int _line)
12409 +{
12410 +       if (!dli)
12411 +               return;
12412 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
12413 +               dli, dli ? dli->dl_tag : 0,
12414 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12415 +               _file, _line);
12416 +       if (atomic_dec_and_test(&dli->dl_usecnt))
12417 +               free_dl_info(dli);
12418 +}
12419 +
12420 +
12421 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
12422 +
12423 +static inline int __dl_alloc_space(struct super_block *sb,
12424 +       tag_t tag, dlsize_t nr, const char *file, int line)
12425 +{
12426 +       struct dl_info *dli = NULL;
12427 +       int ret = 0;
12428 +
12429 +       if (nr == 0)
12430 +               goto out;
12431 +       dli = locate_dl_info(sb, tag);
12432 +       if (!dli)
12433 +               goto out;
12434 +
12435 +       spin_lock(&dli->dl_lock);
12436 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
12437 +       if (!ret)
12438 +               dli->dl_space_used += nr;
12439 +       spin_unlock(&dli->dl_lock);
12440 +       put_dl_info(dli);
12441 +out:
12442 +       vxlprintk(VXD_CBIT(dlim, 1),
12443 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
12444 +               sb, tag, __dlimit_char(dli), (long long)nr,
12445 +               ret, file, line);
12446 +       return ret;
12447 +}
12448 +
12449 +static inline void __dl_free_space(struct super_block *sb,
12450 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
12451 +{
12452 +       struct dl_info *dli = NULL;
12453 +
12454 +       if (nr == 0)
12455 +               goto out;
12456 +       dli = locate_dl_info(sb, tag);
12457 +       if (!dli)
12458 +               goto out;
12459 +
12460 +       spin_lock(&dli->dl_lock);
12461 +       if (dli->dl_space_used > nr)
12462 +               dli->dl_space_used -= nr;
12463 +       else
12464 +               dli->dl_space_used = 0;
12465 +       spin_unlock(&dli->dl_lock);
12466 +       put_dl_info(dli);
12467 +out:
12468 +       vxlprintk(VXD_CBIT(dlim, 1),
12469 +               "FREE  (%p,#%d)%c %lld bytes",
12470 +               sb, tag, __dlimit_char(dli), (long long)nr,
12471 +               _file, _line);
12472 +}
12473 +
12474 +static inline int __dl_alloc_inode(struct super_block *sb,
12475 +       tag_t tag, const char *_file, int _line)
12476 +{
12477 +       struct dl_info *dli;
12478 +       int ret = 0;
12479 +
12480 +       dli = locate_dl_info(sb, tag);
12481 +       if (!dli)
12482 +               goto out;
12483 +
12484 +       spin_lock(&dli->dl_lock);
12485 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
12486 +       if (!ret)
12487 +               dli->dl_inodes_used++;
12488 +       spin_unlock(&dli->dl_lock);
12489 +       put_dl_info(dli);
12490 +out:
12491 +       vxlprintk(VXD_CBIT(dlim, 0),
12492 +               "ALLOC (%p,#%d)%c inode (%d)",
12493 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
12494 +       return ret;
12495 +}
12496 +
12497 +static inline void __dl_free_inode(struct super_block *sb,
12498 +       tag_t tag, const char *_file, int _line)
12499 +{
12500 +       struct dl_info *dli;
12501 +
12502 +       dli = locate_dl_info(sb, tag);
12503 +       if (!dli)
12504 +               goto out;
12505 +
12506 +       spin_lock(&dli->dl_lock);
12507 +       if (dli->dl_inodes_used > 1)
12508 +               dli->dl_inodes_used--;
12509 +       else
12510 +               dli->dl_inodes_used = 0;
12511 +       spin_unlock(&dli->dl_lock);
12512 +       put_dl_info(dli);
12513 +out:
12514 +       vxlprintk(VXD_CBIT(dlim, 0),
12515 +               "FREE  (%p,#%d)%c inode",
12516 +               sb, tag, __dlimit_char(dli), _file, _line);
12517 +}
12518 +
12519 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
12520 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
12521 +       const char *_file, int _line)
12522 +{
12523 +       struct dl_info *dli;
12524 +       uint64_t broot, bfree;
12525 +
12526 +       dli = locate_dl_info(sb, tag);
12527 +       if (!dli)
12528 +               return;
12529 +
12530 +       spin_lock(&dli->dl_lock);
12531 +       broot = (dli->dl_space_total -
12532 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
12533 +               >> sb->s_blocksize_bits;
12534 +       bfree = (dli->dl_space_total - dli->dl_space_used)
12535 +                       >> sb->s_blocksize_bits;
12536 +       spin_unlock(&dli->dl_lock);
12537 +
12538 +       vxlprintk(VXD_CBIT(dlim, 2),
12539 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
12540 +               (long long)bfree, (long long)broot,
12541 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
12542 +               _file, _line);
12543 +       if (free_blocks) {
12544 +               if (*free_blocks > bfree)
12545 +                       *free_blocks = bfree;
12546 +       }
12547 +       if (root_blocks) {
12548 +               if (*root_blocks > broot)
12549 +                       *root_blocks = broot;
12550 +       }
12551 +       put_dl_info(dli);
12552 +}
12553 +
12554 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
12555 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12556 +               __FILE__, __LINE__ )
12557 +
12558 +#define DLIMIT_FREE_SPACE(in, bytes) \
12559 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12560 +               __FILE__, __LINE__ )
12561 +
12562 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
12563 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
12564 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12565 +               __FILE__, __LINE__ )
12566 +
12567 +#define DLIMIT_FREE_BLOCK(in, nr) \
12568 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
12569 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12570 +               __FILE__, __LINE__ )
12571 +
12572 +
12573 +#define DLIMIT_ALLOC_INODE(in) \
12574 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12575 +
12576 +#define DLIMIT_FREE_INODE(in) \
12577 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12578 +
12579 +
12580 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
12581 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
12582 +
12583 +
12584 +#else
12585 +#warning duplicate inclusion
12586 +#endif
12587 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_inet.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_inet.h
12588 --- linux-2.6.22.10/include/linux/vs_inet.h     1970-01-01 01:00:00 +0100
12589 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_inet.h  2007-10-05 15:07:22 +0200
12590 @@ -0,0 +1,341 @@
12591 +#ifndef _VS_INET_H
12592 +#define _VS_INET_H
12593 +
12594 +#include "vserver/base.h"
12595 +#include "vserver/network.h"
12596 +#include "vserver/debug.h"
12597 +
12598 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
12599 +
12600 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
12601 +                       NIPQUAD((a)->mask), (a)->type
12602 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
12603 +
12604 +
12605 +static inline
12606 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
12607 +{
12608 +       __be32 ip = nxa->ip[0].s_addr;
12609 +       __be32 mask = nxa->mask.s_addr;
12610 +       __be32 bcast = ip | ~mask;
12611 +       int ret = 0;
12612 +
12613 +       switch (nxa->type & tmask) {
12614 +       case NXA_TYPE_MASK:
12615 +               ret = (ip == (addr & mask));
12616 +               break;
12617 +       case NXA_TYPE_ADDR:
12618 +               ret = 3;
12619 +               if (addr == ip)
12620 +                       break;
12621 +               /* fall through to broadcast */
12622 +       case NXA_MOD_BCAST:
12623 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
12624 +               break;
12625 +       case NXA_TYPE_RANGE:
12626 +               ret = ((nxa->ip[0].s_addr <= addr) &&
12627 +                       (nxa->ip[1].s_addr > addr));
12628 +               break;
12629 +       case NXA_TYPE_ANY:
12630 +               ret = 2;
12631 +               break;
12632 +       }
12633 +
12634 +       vxdprintk(VXD_CBIT(net, 0),
12635 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
12636 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
12637 +       return ret;
12638 +}
12639 +
12640 +static inline
12641 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
12642 +{
12643 +       struct nx_addr_v4 *nxa;
12644 +       int ret = 1;
12645 +
12646 +       if (!nxi)
12647 +               goto out;
12648 +
12649 +       ret = 2;
12650 +       /* allow 127.0.0.1 when remapping lback */
12651 +       if ((tmask & NXA_LOOPBACK) &&
12652 +               (addr == IPI_LOOPBACK) &&
12653 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12654 +               goto out;
12655 +       ret = 3;
12656 +       /* check for lback address */
12657 +       if ((tmask & NXA_MOD_LBACK) &&
12658 +               (nxi->v4_lback.s_addr == addr))
12659 +               goto out;
12660 +       ret = 4;
12661 +       /* check for broadcast address */
12662 +       if ((tmask & NXA_MOD_BCAST) &&
12663 +               (nxi->v4_bcast.s_addr == addr))
12664 +               goto out;
12665 +       ret = 5;
12666 +       /* check for v4 addresses */
12667 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
12668 +               if (v4_addr_match(nxa, addr, tmask))
12669 +                       goto out;
12670 +       ret = 0;
12671 +out:
12672 +       vxdprintk(VXD_CBIT(net, 0),
12673 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
12674 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
12675 +       return ret;
12676 +}
12677 +
12678 +static inline
12679 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
12680 +{
12681 +       /* FIXME: needs full range checks */
12682 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
12683 +}
12684 +
12685 +static inline
12686 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
12687 +{
12688 +       struct nx_addr_v4 *ptr;
12689 +
12690 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
12691 +               if (v4_nx_addr_match(ptr, nxa, mask))
12692 +                       return 1;
12693 +       return 0;
12694 +}
12695 +
12696 +#include <net/inet_sock.h>
12697 +
12698 +/*
12699 + *     Check if a given address matches for a socket
12700 + *
12701 + *     nxi:            the socket's nx_info if any
12702 + *     addr:           to be verified address
12703 + */
12704 +static inline
12705 +int v4_sock_addr_match (
12706 +       struct nx_info *nxi,
12707 +       struct inet_sock *inet,
12708 +       __be32 addr)
12709 +{
12710 +       __be32 saddr = inet->rcv_saddr;
12711 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
12712 +
12713 +       if (addr && (saddr == addr || bcast == addr))
12714 +               return 1;
12715 +       if (!saddr)
12716 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
12717 +       return 0;
12718 +}
12719 +
12720 +
12721 +/* inet related checks and helpers */
12722 +
12723 +
12724 +struct in_ifaddr;
12725 +struct net_device;
12726 +struct sock;
12727 +
12728 +#ifdef CONFIG_INET
12729 +
12730 +#include <linux/netdevice.h>
12731 +#include <linux/inetdevice.h>
12732 +#include <net/inet_timewait_sock.h>
12733 +
12734 +
12735 +int dev_in_nx_info(struct net_device *, struct nx_info *);
12736 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
12737 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
12738 +
12739 +
12740 +/*
12741 + *     check if address is covered by socket
12742 + *
12743 + *     sk:     the socket to check against
12744 + *     addr:   the address in question (must be != 0)
12745 + */
12746 +
12747 +static inline
12748 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
12749 +{
12750 +       struct nx_info *nxi = sk->sk_nx_info;
12751 +       __be32 saddr = inet_rcv_saddr(sk);
12752 +
12753 +       vxdprintk(VXD_CBIT(net, 5),
12754 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
12755 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
12756 +               (sk->sk_socket?sk->sk_socket->flags:0));
12757 +
12758 +       if (saddr) {            /* direct address match */
12759 +               return v4_addr_match(nxa, saddr, -1);
12760 +       } else if (nxi) {       /* match against nx_info */
12761 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
12762 +       } else {                /* unrestricted any socket */
12763 +               return 1;
12764 +       }
12765 +}
12766 +
12767 +
12768 +
12769 +static inline
12770 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
12771 +{
12772 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p »%s«) %d",
12773 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
12774 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
12775 +
12776 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12777 +               return 1;
12778 +       if (dev_in_nx_info(dev, nxi))
12779 +               return 1;
12780 +       return 0;
12781 +}
12782 +
12783 +
12784 +static inline
12785 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
12786 +{
12787 +       if (!nxi)
12788 +               return 1;
12789 +       if (!ifa)
12790 +               return 0;
12791 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
12792 +}
12793 +
12794 +static inline
12795 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
12796 +{
12797 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
12798 +               nxi, nxi ? nxi->nx_id : 0, ifa,
12799 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
12800 +
12801 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12802 +               return 1;
12803 +       if (v4_ifa_in_nx_info(ifa, nxi))
12804 +               return 1;
12805 +       return 0;
12806 +}
12807 +
12808 +
12809 +struct nx_v4_sock_addr {
12810 +       __be32 saddr;   /* Address used for validation */
12811 +       __be32 baddr;   /* Address used for socket bind */
12812 +};
12813 +
12814 +static inline
12815 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
12816 +       struct nx_v4_sock_addr *nsa)
12817 +{
12818 +       struct sock *sk = &inet->sk;
12819 +       struct nx_info *nxi = sk->sk_nx_info;
12820 +       __be32 saddr = addr->sin_addr.s_addr;
12821 +       __be32 baddr = saddr;
12822 +
12823 +       vxdprintk(VXD_CBIT(net, 3),
12824 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
12825 +               sk, sk->sk_nx_info, sk->sk_socket,
12826 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
12827 +               NIPQUAD(saddr));
12828 +
12829 +       if (nxi) {
12830 +               if (saddr == INADDR_ANY) {
12831 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
12832 +                               baddr = nxi->v4.ip[0].s_addr;
12833 +               } else if (saddr == IPI_LOOPBACK) {
12834 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12835 +                               baddr = nxi->v4_lback.s_addr;
12836 +               } else {        /* normal address bind */
12837 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
12838 +                               return -EADDRNOTAVAIL;
12839 +               }
12840 +       }
12841 +
12842 +       vxdprintk(VXD_CBIT(net, 3),
12843 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
12844 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
12845 +
12846 +       nsa->saddr = saddr;
12847 +       nsa->baddr = baddr;
12848 +       return 0;
12849 +}
12850 +
12851 +static inline
12852 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
12853 +{
12854 +       inet->saddr = nsa->baddr;
12855 +       inet->rcv_saddr = nsa->baddr;
12856 +}
12857 +
12858 +
12859 +/*
12860 + *      helper to simplify inet_lookup_listener
12861 + *
12862 + *      nxi:   the socket's nx_info if any
12863 + *      addr:  to be verified address
12864 + *      saddr: socket address
12865 + */
12866 +static inline int v4_inet_addr_match (
12867 +       struct nx_info *nxi,
12868 +       __be32 addr,
12869 +       __be32 saddr)
12870 +{
12871 +       if (addr && (saddr == addr))
12872 +               return 1;
12873 +       if (!saddr)
12874 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
12875 +       return 0;
12876 +}
12877 +
12878 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
12879 +{
12880 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
12881 +               (addr == nxi->v4_lback.s_addr))
12882 +               return IPI_LOOPBACK;
12883 +       return addr;
12884 +}
12885 +
12886 +static inline
12887 +int nx_info_has_v4(struct nx_info *nxi)
12888 +{
12889 +       if (!nxi)
12890 +               return 1;
12891 +       if (NX_IPV4(nxi))
12892 +               return 1;
12893 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12894 +               return 1;
12895 +       return 0;
12896 +}
12897 +
12898 +#else /* CONFIG_INET */
12899 +
12900 +static inline
12901 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
12902 +{
12903 +       return 1;
12904 +}
12905 +
12906 +static inline
12907 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
12908 +{
12909 +       return 1;
12910 +}
12911 +
12912 +static inline
12913 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
12914 +{
12915 +       return 1;
12916 +}
12917 +
12918 +static inline
12919 +int nx_info_has_v4(struct nx_info *nxi)
12920 +{
12921 +       return 0;
12922 +}
12923 +
12924 +#endif /* CONFIG_INET */
12925 +
12926 +#define current_nx_info_has_v4() \
12927 +       nx_info_has_v4(current_nx_info())
12928 +
12929 +#else
12930 +#warning duplicate inclusion
12931 +#endif
12932 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_inet6.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_inet6.h
12933 --- linux-2.6.22.10/include/linux/vs_inet6.h    1970-01-01 01:00:00 +0100
12934 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_inet6.h 2007-10-05 14:54:36 +0200
12935 @@ -0,0 +1,228 @@
12936 +#ifndef _VS_INET6_H
12937 +#define _VS_INET6_H
12938 +
12939 +#include <net/ipv6.h>
12940 +#include "vserver/base.h"
12941 +#include "vserver/network.h"
12942 +#include "vserver/debug.h"
12943 +
12944 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
12945 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
12946 +
12947 +
12948 +#ifdef CONFIG_IPV6
12949 +
12950 +static inline
12951 +int v6_addr_match(struct nx_addr_v6 *nxa,
12952 +       const struct in6_addr *addr, uint16_t mask)
12953 +{
12954 +       switch (nxa->type & mask) {
12955 +       case NXA_TYPE_MASK:
12956 +               return ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
12957 +       case NXA_TYPE_ADDR:
12958 +               return ipv6_addr_equal(&nxa->ip, addr);
12959 +       case NXA_TYPE_ANY:
12960 +               return 1;
12961 +       default:
12962 +               return 0;
12963 +       }
12964 +}
12965 +
12966 +static inline
12967 +int v6_addr_in_nx_info(struct nx_info *nxi,
12968 +       const struct in6_addr *addr, uint16_t mask)
12969 +{
12970 +       struct nx_addr_v6 *nxa;
12971 +
12972 +       if (!nxi)
12973 +               return 1;
12974 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
12975 +               if (v6_addr_match(nxa, addr, mask))
12976 +                       return 1;
12977 +       return 0;
12978 +}
12979 +
12980 +static inline
12981 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
12982 +{
12983 +       /* FIXME: needs full range checks */
12984 +       return v6_addr_match(nxa, &addr->ip, mask);
12985 +}
12986 +
12987 +static inline
12988 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
12989 +{
12990 +       struct nx_addr_v6 *ptr;
12991 +
12992 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
12993 +               if (v6_nx_addr_match(ptr, nxa, mask))
12994 +                       return 1;
12995 +       return 0;
12996 +}
12997 +
12998 +
12999 +/*
13000 + *     Check if a given address matches for a socket
13001 + *
13002 + *     nxi:            the socket's nx_info if any
13003 + *     addr:           to be verified address
13004 + */
13005 +static inline
13006 +int v6_sock_addr_match (
13007 +       struct nx_info *nxi,
13008 +       struct inet_sock *inet,
13009 +       struct in6_addr *addr)
13010 +{
13011 +       struct sock *sk = &inet->sk;
13012 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13013 +
13014 +       if (!ipv6_addr_any(addr) &&
13015 +               ipv6_addr_equal(saddr, addr))
13016 +               return 1;
13017 +       if (ipv6_addr_any(saddr))
13018 +               return v6_addr_in_nx_info(nxi, addr, -1);
13019 +       return 0;
13020 +}
13021 +
13022 +/*
13023 + *     check if address is covered by socket
13024 + *
13025 + *     sk:     the socket to check against
13026 + *     addr:   the address in question (must be != 0)
13027 + */
13028 +
13029 +static inline
13030 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13031 +{
13032 +       struct nx_info *nxi = sk->sk_nx_info;
13033 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13034 +
13035 +       vxdprintk(VXD_CBIT(net, 5),
13036 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
13037 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
13038 +               (sk->sk_socket?sk->sk_socket->flags:0));
13039 +
13040 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13041 +               return v6_addr_match(nxa, saddr, -1);
13042 +       } else if (nxi) {               /* match against nx_info */
13043 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13044 +       } else {                        /* unrestricted any socket */
13045 +               return 1;
13046 +       }
13047 +}
13048 +
13049 +
13050 +/* inet related checks and helpers */
13051 +
13052 +
13053 +struct in_ifaddr;
13054 +struct net_device;
13055 +struct sock;
13056 +
13057 +
13058 +#include <linux/netdevice.h>
13059 +#include <linux/inetdevice.h>
13060 +#include <net/inet_timewait_sock.h>
13061 +
13062 +
13063 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13064 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13065 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13066 +
13067 +
13068 +
13069 +static inline
13070 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13071 +{
13072 +       if (!nxi)
13073 +               return 1;
13074 +       if (!ifa)
13075 +               return 0;
13076 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13077 +}
13078 +
13079 +static inline
13080 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13081 +{
13082 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13083 +               return 1;
13084 +       if (v6_ifa_in_nx_info(ifa, nxi))
13085 +               return 1;
13086 +       return 0;
13087 +}
13088 +
13089 +
13090 +struct nx_v6_sock_addr {
13091 +       struct in6_addr saddr;  /* Address used for validation */
13092 +       struct in6_addr baddr;  /* Address used for socket bind */
13093 +};
13094 +
13095 +static inline
13096 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13097 +       struct nx_v6_sock_addr *nsa)
13098 +{
13099 +       // struct sock *sk = &inet->sk;
13100 +       // struct nx_info *nxi = sk->sk_nx_info;
13101 +       struct in6_addr saddr = addr->sin6_addr;
13102 +       struct in6_addr baddr = saddr;
13103 +
13104 +       nsa->saddr = saddr;
13105 +       nsa->baddr = baddr;
13106 +       return 0;
13107 +}
13108 +
13109 +static inline
13110 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13111 +{
13112 +       // struct sock *sk = &inet->sk;
13113 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13114 +
13115 +       // *saddr = nsa->baddr;
13116 +       // inet->saddr = nsa->baddr;
13117 +}
13118 +
13119 +static inline
13120 +int nx_info_has_v6(struct nx_info *nxi)
13121 +{
13122 +       if (!nxi)
13123 +               return 1;
13124 +       if (NX_IPV6(nxi))
13125 +               return 1;
13126 +       return 0;
13127 +}
13128 +
13129 +#else /* CONFIG_IPV6 */
13130 +
13131 +static inline
13132 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13133 +{
13134 +       return 1;
13135 +}
13136 +
13137 +
13138 +static inline
13139 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13140 +{
13141 +       return 1;
13142 +}
13143 +
13144 +static inline
13145 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13146 +{
13147 +       return 1;
13148 +}
13149 +
13150 +static inline
13151 +int nx_info_has_v6(struct nx_info *nxi)
13152 +{
13153 +       return 0;
13154 +}
13155 +
13156 +#endif /* CONFIG_IPV6 */
13157 +
13158 +#define current_nx_info_has_v6() \
13159 +       nx_info_has_v6(current_nx_info())
13160 +
13161 +#else
13162 +#warning duplicate inclusion
13163 +#endif
13164 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_limit.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_limit.h
13165 --- linux-2.6.22.10/include/linux/vs_limit.h    1970-01-01 01:00:00 +0100
13166 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_limit.h 2007-08-05 20:53:13 +0200
13167 @@ -0,0 +1,140 @@
13168 +#ifndef _VS_LIMIT_H
13169 +#define _VS_LIMIT_H
13170 +
13171 +#include "vserver/limit.h"
13172 +#include "vserver/base.h"
13173 +#include "vserver/context.h"
13174 +#include "vserver/debug.h"
13175 +#include "vserver/context.h"
13176 +#include "vserver/limit_int.h"
13177 +
13178 +
13179 +#define vx_acc_cres(v, d, p, r) \
13180 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13181 +
13182 +#define vx_acc_cres_cond(x, d, p, r) \
13183 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13184 +       r, d, p, __FILE__, __LINE__)
13185 +
13186 +
13187 +#define vx_add_cres(v, a, p, r) \
13188 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13189 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13190 +
13191 +#define vx_add_cres_cond(x, a, p, r) \
13192 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13193 +       r, a, p, __FILE__, __LINE__)
13194 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13195 +
13196 +
13197 +/* process and file limits */
13198 +
13199 +#define vx_nproc_inc(p) \
13200 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13201 +
13202 +#define vx_nproc_dec(p) \
13203 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13204 +
13205 +#define vx_files_inc(f) \
13206 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13207 +
13208 +#define vx_files_dec(f) \
13209 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13210 +
13211 +#define vx_locks_inc(l) \
13212 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13213 +
13214 +#define vx_locks_dec(l) \
13215 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13216 +
13217 +#define vx_openfd_inc(f) \
13218 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
13219 +
13220 +#define vx_openfd_dec(f) \
13221 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
13222 +
13223 +
13224 +#define vx_cres_avail(v, n, r) \
13225 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13226 +
13227 +
13228 +#define vx_nproc_avail(n) \
13229 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
13230 +
13231 +#define vx_files_avail(n) \
13232 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
13233 +
13234 +#define vx_locks_avail(n) \
13235 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
13236 +
13237 +#define vx_openfd_avail(n) \
13238 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
13239 +
13240 +
13241 +/* dentry limits */
13242 +
13243 +#define vx_dentry_inc(d) do {                                          \
13244 +       if (atomic_read(&d->d_count) == 1)                              \
13245 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
13246 +       } while (0)
13247 +
13248 +#define vx_dentry_dec(d) do {                                          \
13249 +       if (atomic_read(&d->d_count) == 0)                              \
13250 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
13251 +       } while (0)
13252 +
13253 +#define vx_dentry_avail(n) \
13254 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
13255 +
13256 +
13257 +/* socket limits */
13258 +
13259 +#define vx_sock_inc(s) \
13260 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13261 +
13262 +#define vx_sock_dec(s) \
13263 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13264 +
13265 +#define vx_sock_avail(n) \
13266 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
13267 +
13268 +
13269 +/* ipc resource limits */
13270 +
13271 +#define vx_ipcmsg_add(v, u, a) \
13272 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13273 +
13274 +#define vx_ipcmsg_sub(v, u, a) \
13275 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13276 +
13277 +#define vx_ipcmsg_avail(v, a) \
13278 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13279 +
13280 +
13281 +#define vx_ipcshm_add(v, k, a) \
13282 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13283 +
13284 +#define vx_ipcshm_sub(v, k, a) \
13285 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13286 +
13287 +#define vx_ipcshm_avail(v, a) \
13288 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13289 +
13290 +
13291 +#define vx_semary_inc(a) \
13292 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
13293 +
13294 +#define vx_semary_dec(a) \
13295 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
13296 +
13297 +
13298 +#define vx_nsems_add(a,n) \
13299 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13300 +
13301 +#define vx_nsems_sub(a,n) \
13302 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13303 +
13304 +
13305 +#else
13306 +#warning duplicate inclusion
13307 +#endif
13308 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_memory.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_memory.h
13309 --- linux-2.6.22.10/include/linux/vs_memory.h   1970-01-01 01:00:00 +0100
13310 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_memory.h        2007-08-05 20:53:13 +0200
13311 @@ -0,0 +1,159 @@
13312 +#ifndef _VS_MEMORY_H
13313 +#define _VS_MEMORY_H
13314 +
13315 +#include "vserver/limit.h"
13316 +#include "vserver/base.h"
13317 +#include "vserver/context.h"
13318 +#include "vserver/debug.h"
13319 +#include "vserver/context.h"
13320 +#include "vserver/limit_int.h"
13321 +
13322 +
13323 +#define __acc_add_long(a, v)   (*(v) += (a))
13324 +#define __acc_inc_long(v)      (++*(v))
13325 +#define __acc_dec_long(v)      (--*(v))
13326 +
13327 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
13328 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
13329 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
13330 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
13331 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13332 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
13333 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
13334 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
13335 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13336 +
13337 +
13338 +#define vx_acc_page(m, d, v, r) do {                                   \
13339 +       if ((d) > 0)                                                    \
13340 +               __acc_inc_long(&(m)->v);                                \
13341 +       else                                                            \
13342 +               __acc_dec_long(&(m)->v);                                \
13343 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13344 +} while (0)
13345 +
13346 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
13347 +       if ((d) > 0)                                                    \
13348 +               __acc_inc_atomic(&(m)->v);                              \
13349 +       else                                                            \
13350 +               __acc_dec_atomic(&(m)->v);                              \
13351 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13352 +} while (0)
13353 +
13354 +
13355 +#define vx_acc_pages(m, p, v, r) do {                                  \
13356 +       unsigned long __p = (p);                                        \
13357 +       __acc_add_long(__p, &(m)->v);                                   \
13358 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13359 +} while (0)
13360 +
13361 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
13362 +       unsigned long __p = (p);                                        \
13363 +       __acc_add_atomic(__p, &(m)->v);                                 \
13364 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13365 +} while (0)
13366 +
13367 +
13368 +
13369 +#define vx_acc_vmpage(m, d) \
13370 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
13371 +#define vx_acc_vmlpage(m, d) \
13372 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
13373 +#define vx_acc_file_rsspage(m, d) \
13374 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
13375 +#define vx_acc_anon_rsspage(m, d) \
13376 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
13377 +
13378 +#define vx_acc_vmpages(m, p) \
13379 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
13380 +#define vx_acc_vmlpages(m, p) \
13381 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
13382 +#define vx_acc_file_rsspages(m, p) \
13383 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
13384 +#define vx_acc_anon_rsspages(m, p) \
13385 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
13386 +
13387 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
13388 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
13389 +
13390 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
13391 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
13392 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
13393 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
13394 +
13395 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
13396 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
13397 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
13398 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
13399 +
13400 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
13401 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
13402 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
13403 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
13404 +
13405 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
13406 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
13407 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
13408 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
13409 +
13410 +
13411 +#define vx_pages_avail(m, p, r) \
13412 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
13413 +
13414 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
13415 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
13416 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
13417 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
13418 +
13419 +#define vx_rss_avail(m, p) \
13420 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
13421 +
13422 +
13423 +enum {
13424 +       VXPT_UNKNOWN = 0,
13425 +       VXPT_ANON,
13426 +       VXPT_NONE,
13427 +       VXPT_FILE,
13428 +       VXPT_SWAP,
13429 +       VXPT_WRITE
13430 +};
13431 +
13432 +#if 0
13433 +#define        vx_page_fault(mm, vma, type, ret)
13434 +#else
13435 +
13436 +static inline
13437 +void __vx_page_fault(struct mm_struct *mm,
13438 +       struct vm_area_struct *vma, int type, int ret)
13439 +{
13440 +       struct vx_info *vxi = mm->mm_vx_info;
13441 +       int what;
13442 +/*
13443 +       static char *page_type[6] =
13444 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
13445 +       static char *page_what[4] =
13446 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
13447 +*/
13448 +
13449 +       if (!vxi)
13450 +               return;
13451 +
13452 +       what = (ret & 0x3);
13453 +
13454 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
13455 +               type, what, ret, page_type[type], page_what[what]);
13456 +*/
13457 +       if (ret & VM_FAULT_WRITE)
13458 +               what |= 0x4;
13459 +       atomic_inc(&vxi->cacct.page[type][what]);
13460 +}
13461 +
13462 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
13463 +#endif
13464 +
13465 +
13466 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
13467 +
13468 +#else
13469 +#warning duplicate inclusion
13470 +#endif
13471 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_network.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_network.h
13472 --- linux-2.6.22.10/include/linux/vs_network.h  1970-01-01 01:00:00 +0100
13473 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_network.h       2007-08-05 20:53:13 +0200
13474 @@ -0,0 +1,166 @@
13475 +#ifndef _NX_VS_NETWORK_H
13476 +#define _NX_VS_NETWORK_H
13477 +
13478 +#include "vserver/context.h"
13479 +#include "vserver/network.h"
13480 +#include "vserver/base.h"
13481 +#include "vserver/debug.h"
13482 +
13483 +
13484 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
13485 +
13486 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
13487 +       const char *_file, int _line)
13488 +{
13489 +       if (!nxi)
13490 +               return NULL;
13491 +
13492 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
13493 +               nxi, nxi ? nxi->nx_id : 0,
13494 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13495 +               _file, _line);
13496 +
13497 +       atomic_inc(&nxi->nx_usecnt);
13498 +       return nxi;
13499 +}
13500 +
13501 +
13502 +extern void free_nx_info(struct nx_info *);
13503 +
13504 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
13505 +
13506 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
13507 +{
13508 +       if (!nxi)
13509 +               return;
13510 +
13511 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
13512 +               nxi, nxi ? nxi->nx_id : 0,
13513 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13514 +               _file, _line);
13515 +
13516 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
13517 +               free_nx_info(nxi);
13518 +}
13519 +
13520 +
13521 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
13522 +
13523 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
13524 +               const char *_file, int _line)
13525 +{
13526 +       if (nxi) {
13527 +               vxlprintk(VXD_CBIT(nid, 3),
13528 +                       "init_nx_info(%p[#%d.%d])",
13529 +                       nxi, nxi ? nxi->nx_id : 0,
13530 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13531 +                       _file, _line);
13532 +
13533 +               atomic_inc(&nxi->nx_usecnt);
13534 +       }
13535 +       *nxp = nxi;
13536 +}
13537 +
13538 +
13539 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
13540 +
13541 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
13542 +       const char *_file, int _line)
13543 +{
13544 +       struct nx_info *nxo;
13545 +
13546 +       if (!nxi)
13547 +               return;
13548 +
13549 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
13550 +               nxi, nxi ? nxi->nx_id : 0,
13551 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13552 +               _file, _line);
13553 +
13554 +       atomic_inc(&nxi->nx_usecnt);
13555 +       nxo = xchg(nxp, nxi);
13556 +       BUG_ON(nxo);
13557 +}
13558 +
13559 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
13560 +
13561 +static inline void __clr_nx_info(struct nx_info **nxp,
13562 +       const char *_file, int _line)
13563 +{
13564 +       struct nx_info *nxo;
13565 +
13566 +       nxo = xchg(nxp, NULL);
13567 +       if (!nxo)
13568 +               return;
13569 +
13570 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
13571 +               nxo, nxo ? nxo->nx_id : 0,
13572 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
13573 +               _file, _line);
13574 +
13575 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
13576 +               free_nx_info(nxo);
13577 +}
13578 +
13579 +
13580 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
13581 +
13582 +static inline void __claim_nx_info(struct nx_info *nxi,
13583 +       struct task_struct *task, const char *_file, int _line)
13584 +{
13585 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
13586 +               nxi, nxi ? nxi->nx_id : 0,
13587 +               nxi?atomic_read(&nxi->nx_usecnt):0,
13588 +               nxi?atomic_read(&nxi->nx_tasks):0,
13589 +               task, _file, _line);
13590 +
13591 +       atomic_inc(&nxi->nx_tasks);
13592 +}
13593 +
13594 +
13595 +extern void unhash_nx_info(struct nx_info *);
13596 +
13597 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
13598 +
13599 +static inline void __release_nx_info(struct nx_info *nxi,
13600 +       struct task_struct *task, const char *_file, int _line)
13601 +{
13602 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
13603 +               nxi, nxi ? nxi->nx_id : 0,
13604 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13605 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
13606 +               task, _file, _line);
13607 +
13608 +       might_sleep();
13609 +
13610 +       if (atomic_dec_and_test(&nxi->nx_tasks))
13611 +               unhash_nx_info(nxi);
13612 +}
13613 +
13614 +
13615 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
13616 +
13617 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
13618 +       const char *_file, int _line)
13619 +{
13620 +       struct nx_info *nxi;
13621 +
13622 +       task_lock(p);
13623 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
13624 +               p, _file, _line);
13625 +       nxi = __get_nx_info(p->nx_info, _file, _line);
13626 +       task_unlock(p);
13627 +       return nxi;
13628 +}
13629 +
13630 +
13631 +static inline void exit_nx_info(struct task_struct *p)
13632 +{
13633 +       if (p->nx_info)
13634 +               release_nx_info(p->nx_info, p);
13635 +}
13636 +
13637 +
13638 +#else
13639 +#warning duplicate inclusion
13640 +#endif
13641 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_pid.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_pid.h
13642 --- linux-2.6.22.10/include/linux/vs_pid.h      1970-01-01 01:00:00 +0100
13643 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_pid.h   2007-09-05 02:49:29 +0200
13644 @@ -0,0 +1,133 @@
13645 +#ifndef _VS_PID_H
13646 +#define _VS_PID_H
13647 +
13648 +#include "vserver/base.h"
13649 +#include "vserver/context.h"
13650 +#include "vserver/debug.h"
13651 +#include <linux/pid_namespace.h>
13652 +
13653 +
13654 +/* pid faking stuff */
13655 +
13656 +
13657 +#define vx_info_map_pid(v, p) \
13658 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
13659 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13660 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
13661 +#define vx_map_tgid(p) vx_map_pid(p)
13662 +
13663 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13664 +       const char *func, const char *file, int line)
13665 +{
13666 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13667 +               vxfprintk(VXD_CBIT(cvirt, 2),
13668 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13669 +                       vxi, (long long)vxi->vx_flags, pid,
13670 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13671 +                       func, file, line);
13672 +               if (pid == 0)
13673 +                       return 0;
13674 +               if (pid == vxi->vx_initpid)
13675 +                       return 1;
13676 +       }
13677 +       return pid;
13678 +}
13679 +
13680 +#define vx_info_rmap_pid(v, p) \
13681 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
13682 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
13683 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13684 +
13685 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13686 +       const char *func, const char *file, int line)
13687 +{
13688 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13689 +               vxfprintk(VXD_CBIT(cvirt, 2),
13690 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13691 +                       vxi, (long long)vxi->vx_flags, pid,
13692 +                       (pid == 1) ? vxi->vx_initpid : pid,
13693 +                       func, file, line);
13694 +               if ((pid == 1) && vxi->vx_initpid)
13695 +                       return vxi->vx_initpid;
13696 +               if (pid == vxi->vx_initpid)
13697 +                       return ~0U;
13698 +       }
13699 +       return pid;
13700 +}
13701 +
13702 +
13703 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
13704 +
13705 +static inline
13706 +int vx_proc_task_visible(struct task_struct *task)
13707 +{
13708 +       if ((task->pid == 1) &&
13709 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
13710 +               /* show a blend through init */
13711 +               goto visible;
13712 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
13713 +               goto visible;
13714 +       return 0;
13715 +visible:
13716 +       return 1;
13717 +}
13718 +
13719 +static inline
13720 +struct task_struct *vx_find_proc_task_by_pid(int pid)
13721 +{
13722 +       struct task_struct *task = find_task_by_pid(pid);
13723 +
13724 +       if (task && !vx_proc_task_visible(task)) {
13725 +               vxdprintk(VXD_CBIT(misc, 6),
13726 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
13727 +                       task, task->xid, task->pid,
13728 +                       current, current->xid, current->pid);
13729 +               task = NULL;
13730 +       }
13731 +       return task;
13732 +}
13733 +
13734 +static inline
13735 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
13736 +{
13737 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
13738 +
13739 +       if (task && !vx_proc_task_visible(task)) {
13740 +               vxdprintk(VXD_CBIT(misc, 6),
13741 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
13742 +                       task, task->xid, task->pid,
13743 +                       current, current->xid, current->pid);
13744 +               put_task_struct(task);
13745 +               task = NULL;
13746 +       }
13747 +       return task;
13748 +}
13749 +
13750 +
13751 +static inline
13752 +struct task_struct *vx_child_reaper(struct task_struct *p)
13753 +{
13754 +       struct vx_info *vxi = p->vx_info;
13755 +       struct task_struct *reaper = child_reaper(p);
13756 +
13757 +       if (!vxi)
13758 +               goto out;
13759 +
13760 +       BUG_ON(!p->vx_info->vx_reaper);
13761 +
13762 +       /* child reaper for the guest reaper */
13763 +       if (vxi->vx_reaper == p)
13764 +               goto out;
13765 +
13766 +       reaper = vxi->vx_reaper;
13767 +out:
13768 +       vxdprintk(VXD_CBIT(xid, 7),
13769 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
13770 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
13771 +       return reaper;
13772 +}
13773 +
13774 +
13775 +#else
13776 +#warning duplicate inclusion
13777 +#endif
13778 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_sched.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_sched.h
13779 --- linux-2.6.22.10/include/linux/vs_sched.h    1970-01-01 01:00:00 +0100
13780 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_sched.h 2007-08-05 20:53:13 +0200
13781 @@ -0,0 +1,110 @@
13782 +#ifndef _VS_SCHED_H
13783 +#define _VS_SCHED_H
13784 +
13785 +#include "vserver/base.h"
13786 +#include "vserver/context.h"
13787 +#include "vserver/sched.h"
13788 +
13789 +
13790 +#define VAVAVOOM_RATIO          50
13791 +
13792 +#define MAX_PRIO_BIAS           20
13793 +#define MIN_PRIO_BIAS          -20
13794 +
13795 +
13796 +#ifdef CONFIG_VSERVER_HARDCPU
13797 +
13798 +/*
13799 + * effective_prio - return the priority that is based on the static
13800 + * priority but is modified by bonuses/penalties.
13801 + *
13802 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
13803 + * into a -4 ... 0 ... +4 bonus/penalty range.
13804 + *
13805 + * Additionally, we scale another amount based on the number of
13806 + * CPU tokens currently held by the context, if the process is
13807 + * part of a context (and the appropriate SCHED flag is set).
13808 + * This ranges from -5 ... 0 ... +15, quadratically.
13809 + *
13810 + * So, the total bonus is -9 .. 0 .. +19
13811 + * We use ~50% of the full 0...39 priority range so that:
13812 + *
13813 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
13814 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
13815 + *    unless that context is far exceeding its CPU allocation.
13816 + *
13817 + * Both properties are important to certain workloads.
13818 + */
13819 +static inline
13820 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
13821 +{
13822 +       int vavavoom, max;
13823 +
13824 +       /* lots of tokens = lots of vavavoom
13825 +        *      no tokens = no vavavoom      */
13826 +       if ((vavavoom = sched_pc->tokens) >= 0) {
13827 +               max = sched_pc->tokens_max;
13828 +               vavavoom = max - vavavoom;
13829 +               max = max * max;
13830 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
13831 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
13832 +               return vavavoom;
13833 +       }
13834 +       return 0;
13835 +}
13836 +
13837 +
13838 +static inline
13839 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
13840 +{
13841 +       struct vx_info *vxi = p->vx_info;
13842 +       struct _vx_sched_pc *sched_pc;
13843 +
13844 +       if (!vxi)
13845 +               return prio;
13846 +
13847 +       sched_pc = &vx_cpu(vxi, sched_pc);
13848 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
13849 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
13850 +
13851 +               sched_pc->vavavoom = vavavoom;
13852 +               prio += vavavoom;
13853 +       }
13854 +       prio += sched_pc->prio_bias;
13855 +       return prio;
13856 +}
13857 +
13858 +#else /* !CONFIG_VSERVER_HARDCPU */
13859 +
13860 +static inline
13861 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
13862 +{
13863 +       struct vx_info *vxi = p->vx_info;
13864 +
13865 +       if (vxi)
13866 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
13867 +       return prio;
13868 +}
13869 +
13870 +#endif /* CONFIG_VSERVER_HARDCPU */
13871 +
13872 +
13873 +static inline void vx_account_user(struct vx_info *vxi,
13874 +       cputime_t cputime, int nice)
13875 +{
13876 +       if (!vxi)
13877 +               return;
13878 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
13879 +}
13880 +
13881 +static inline void vx_account_system(struct vx_info *vxi,
13882 +       cputime_t cputime, int idle)
13883 +{
13884 +       if (!vxi)
13885 +               return;
13886 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
13887 +}
13888 +
13889 +#else
13890 +#warning duplicate inclusion
13891 +#endif
13892 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_socket.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_socket.h
13893 --- linux-2.6.22.10/include/linux/vs_socket.h   1970-01-01 01:00:00 +0100
13894 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_socket.h        2007-08-05 20:53:13 +0200
13895 @@ -0,0 +1,80 @@
13896 +#ifndef _VS_SOCKET_H
13897 +#define _VS_SOCKET_H
13898 +
13899 +#include "vserver/debug.h"
13900 +#include "vserver/base.h"
13901 +#include "vserver/cacct.h"
13902 +#include "vserver/context.h"
13903 +#include "vserver/tag.h"
13904 +
13905 +
13906 +/* socket accounting */
13907 +
13908 +#include <linux/socket.h>
13909 +
13910 +static inline int vx_sock_type(int family)
13911 +{
13912 +       switch (family) {
13913 +       case PF_UNSPEC:
13914 +               return VXA_SOCK_UNSPEC;
13915 +       case PF_UNIX:
13916 +               return VXA_SOCK_UNIX;
13917 +       case PF_INET:
13918 +               return VXA_SOCK_INET;
13919 +       case PF_INET6:
13920 +               return VXA_SOCK_INET6;
13921 +       case PF_PACKET:
13922 +               return VXA_SOCK_PACKET;
13923 +       default:
13924 +               return VXA_SOCK_OTHER;
13925 +       }
13926 +}
13927 +
13928 +#define vx_acc_sock(v, f, p, s) \
13929 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
13930 +
13931 +static inline void __vx_acc_sock(struct vx_info *vxi,
13932 +       int family, int pos, int size, char *file, int line)
13933 +{
13934 +       if (vxi) {
13935 +               int type = vx_sock_type(family);
13936 +
13937 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
13938 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
13939 +       }
13940 +}
13941 +
13942 +#define vx_sock_recv(sk, s) \
13943 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
13944 +#define vx_sock_send(sk, s) \
13945 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
13946 +#define vx_sock_fail(sk, s) \
13947 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
13948 +
13949 +
13950 +#define sock_vx_init(s) do {           \
13951 +       (s)->sk_xid = 0;                \
13952 +       (s)->sk_vx_info = NULL;         \
13953 +       } while (0)
13954 +
13955 +#define sock_nx_init(s) do {           \
13956 +       (s)->sk_nid = 0;                \
13957 +       (s)->sk_nx_info = NULL;         \
13958 +       } while (0)
13959 +
13960 +static inline
13961 +int vx_socket_peer_tag(struct socket *sock, int level,
13962 +       char __user *optval, int __user *optlen, int len)
13963 +{
13964 +       struct peer_tag tag;
13965 +
13966 +       tag.xid = sock->sk->sk_xid;
13967 +       tag.nid = sock->sk->sk_nid;
13968 +       if (copy_to_user(optval, &tag, sizeof(tag)))
13969 +               return -EFAULT;
13970 +       return 0;
13971 +}
13972 +
13973 +#else
13974 +#warning duplicate inclusion
13975 +#endif
13976 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_tag.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_tag.h
13977 --- linux-2.6.22.10/include/linux/vs_tag.h      1970-01-01 01:00:00 +0100
13978 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_tag.h   2007-08-15 19:11:32 +0200
13979 @@ -0,0 +1,43 @@
13980 +#ifndef _VS_TAG_H
13981 +#define _VS_TAG_H
13982 +
13983 +#include <linux/vserver/tag.h>
13984 +
13985 +/* check conditions */
13986 +
13987 +#define DX_ADMIN       0x0001
13988 +#define DX_WATCH       0x0002
13989 +#define DX_HOSTID      0x0008
13990 +
13991 +#define DX_IDENT       0x0010
13992 +
13993 +#define DX_ARG_MASK    0x0010
13994 +
13995 +
13996 +#define dx_task_tag(t) ((t)->tag)
13997 +
13998 +#define dx_current_tag() dx_task_tag(current)
13999 +
14000 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14001 +
14002 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14003 +
14004 +
14005 +/*
14006 + * check current context for ADMIN/WATCH and
14007 + * optionally against supplied argument
14008 + */
14009 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14010 +{
14011 +       if (mode & DX_ARG_MASK) {
14012 +               if ((mode & DX_IDENT) && (id == cid))
14013 +                       return 1;
14014 +       }
14015 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14016 +               ((mode & DX_WATCH) && (cid == 1)) ||
14017 +               ((mode & DX_HOSTID) && (id == 0)));
14018 +}
14019 +
14020 +#else
14021 +#warning duplicate inclusion
14022 +#endif
14023 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_time.h linux-2.6.22.10-vs2.3.0.29/include/linux/vs_time.h
14024 --- linux-2.6.22.10/include/linux/vs_time.h     1970-01-01 01:00:00 +0100
14025 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_time.h  2007-08-05 20:53:13 +0200
14026 @@ -0,0 +1,19 @@
14027 +#ifndef _VS_TIME_H
14028 +#define _VS_TIME_H
14029 +
14030 +
14031 +/* time faking stuff */
14032 +
14033 +#ifdef CONFIG_VSERVER_VTIME
14034 +
14035 +extern void vx_gettimeofday(struct timeval *tv);
14036 +extern int vx_settimeofday(struct timespec *ts);
14037 +
14038 +#else
14039 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14040 +#define        vx_settimeofday(t)      do_settimeofday(t)
14041 +#endif
14042 +
14043 +#else
14044 +#warning duplicate inclusion
14045 +#endif
14046 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/Kbuild linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/Kbuild
14047 --- linux-2.6.22.10/include/linux/vserver/Kbuild        1970-01-01 01:00:00 +0100
14048 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/Kbuild     2007-10-11 01:10:22 +0200
14049 @@ -0,0 +1,8 @@
14050 +
14051 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
14052 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
14053 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
14054 +       debug_cmd.h device_cmd.h
14055 +
14056 +unifdef-y += switch.h network.h monitor.h inode.h device.h
14057 +
14058 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/base.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/base.h
14059 --- linux-2.6.22.10/include/linux/vserver/base.h        1970-01-01 01:00:00 +0100
14060 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/base.h     2007-09-17 14:07:30 +0200
14061 @@ -0,0 +1,218 @@
14062 +#ifndef _VX_BASE_H
14063 +#define _VX_BASE_H
14064 +
14065 +
14066 +/* context state changes */
14067 +
14068 +enum {
14069 +       VSC_STARTUP = 1,
14070 +       VSC_SHUTDOWN,
14071 +
14072 +       VSC_NETUP,
14073 +       VSC_NETDOWN,
14074 +};
14075 +
14076 +
14077 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
14078 +
14079 +/* check conditions */
14080 +
14081 +#define VS_ADMIN       0x0001
14082 +#define VS_WATCH       0x0002
14083 +#define VS_HIDE                0x0004
14084 +#define VS_HOSTID      0x0008
14085 +
14086 +#define VS_IDENT       0x0010
14087 +#define VS_EQUIV       0x0020
14088 +#define VS_PARENT      0x0040
14089 +#define VS_CHILD       0x0080
14090 +
14091 +#define VS_ARG_MASK    0x00F0
14092 +
14093 +#ifdef CONFIG_VSERVER_PRIVACY
14094 +#define VS_ADMIN_P     (0)
14095 +#define VS_WATCH_P     (0)
14096 +#else
14097 +#define VS_ADMIN_P     VS_ADMIN
14098 +#define VS_WATCH_P     VS_WATCH
14099 +#endif
14100 +
14101 +#define VS_HARDIRQ     0x1000
14102 +#define VS_SOFTIRQ     0x2000
14103 +#define VS_IRQ         0x4000
14104 +
14105 +#define VS_IRQ_MASK    0xF000
14106 +
14107 +#include <linux/hardirq.h>
14108 +
14109 +/*
14110 + * check current context for ADMIN/WATCH and
14111 + * optionally against supplied argument
14112 + */
14113 +static inline int __vs_check(int cid, int id, unsigned int mode)
14114 +{
14115 +       if (mode & VS_ARG_MASK) {
14116 +               if ((mode & VS_IDENT) && (id == cid))
14117 +                       return 1;
14118 +       }
14119 +       if (mode & VS_IRQ_MASK) {
14120 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
14121 +                       return 1;
14122 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
14123 +                       return 1;
14124 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
14125 +                       return 1;
14126 +       }
14127 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
14128 +               ((mode & VS_WATCH) && (cid == 1)) ||
14129 +               ((mode & VS_HOSTID) && (id == 0)));
14130 +}
14131 +
14132 +#define vx_task_xid(t) ((t)->xid)
14133 +
14134 +#define vx_current_xid() vx_task_xid(current)
14135 +
14136 +#define current_vx_info() (current->vx_info)
14137 +
14138 +
14139 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
14140 +
14141 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
14142 +
14143 +
14144 +#define nx_task_nid(t) ((t)->nid)
14145 +
14146 +#define nx_current_nid() nx_task_nid(current)
14147 +
14148 +#define current_nx_info() (current->nx_info)
14149 +
14150 +
14151 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
14152 +
14153 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
14154 +
14155 +
14156 +
14157 +/* generic flag merging */
14158 +
14159 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
14160 +
14161 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
14162 +
14163 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
14164 +
14165 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
14166 +
14167 +
14168 +/* context flags */
14169 +
14170 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
14171 +
14172 +#define vx_current_flags()     __vx_flags(current->vx_info)
14173 +
14174 +#define vx_info_flags(v, m, f) \
14175 +       vs_check_flags(__vx_flags(v), m, f)
14176 +
14177 +#define task_vx_flags(t, m, f) \
14178 +       ((t) && vx_info_flags((t)->vx_info, m, f))
14179 +
14180 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
14181 +
14182 +
14183 +/* context caps */
14184 +
14185 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
14186 +
14187 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
14188 +
14189 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
14190 +
14191 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
14192 +
14193 +
14194 +
14195 +/* network flags */
14196 +
14197 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
14198 +
14199 +#define nx_current_flags()     __nx_flags(current->nx_info)
14200 +
14201 +#define nx_info_flags(n, m, f) \
14202 +       vs_check_flags(__nx_flags(n), m, f)
14203 +
14204 +#define task_nx_flags(t, m, f) \
14205 +       ((t) && nx_info_flags((t)->nx_info, m, f))
14206 +
14207 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
14208 +
14209 +
14210 +/* network caps */
14211 +
14212 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
14213 +
14214 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
14215 +
14216 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
14217 +
14218 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
14219 +
14220 +
14221 +/* context mask capabilities */
14222 +
14223 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
14224 +
14225 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
14226 +
14227 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
14228 +
14229 +
14230 +/* context bcap mask */
14231 +
14232 +#define __vx_bcaps(v)  ((v) ? (v)->vx_bcaps : ~0 )
14233 +
14234 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
14235 +
14236 +#define vx_info_bcaps(v, c)    (__vx_bcaps(v) & (c))
14237 +
14238 +#define vx_bcaps(c)    vx_info_bcaps(current->vx_info, c)
14239 +
14240 +
14241 +#define vx_info_cap_bset(v)    ((v) ? (v)->vx_cap_bset : cap_bset)
14242 +
14243 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
14244 +
14245 +
14246 +#define __vx_info_mbcap(v, b) \
14247 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
14248 +       vx_info_bcaps(v, b) : (b))
14249 +
14250 +#define vx_info_mbcap(v, b)    __vx_info_mbcap(v, cap_t(b))
14251 +
14252 +#define task_vx_mbcap(t, b) \
14253 +       vx_info_mbcap((t)->vx_info, (t)->b)
14254 +
14255 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
14256 +
14257 +#define vx_cap_raised(v, c, f) (vx_info_mbcap(v, c) & CAP_TO_MASK(f))
14258 +
14259 +#define vx_capable(b, c) (capable(b) || \
14260 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
14261 +
14262 +#define nx_capable(b, c) (capable(b) || \
14263 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
14264 +
14265 +#define vx_current_initpid(n) \
14266 +       (current->vx_info && \
14267 +       (current->vx_info->vx_initpid == (n)))
14268 +
14269 +
14270 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
14271 +
14272 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
14273 +
14274 +
14275 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
14276 +
14277 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
14278 +
14279 +#endif
14280 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cacct.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct.h
14281 --- linux-2.6.22.10/include/linux/vserver/cacct.h       1970-01-01 01:00:00 +0100
14282 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct.h    2007-08-05 20:53:13 +0200
14283 @@ -0,0 +1,15 @@
14284 +#ifndef _VX_CACCT_H
14285 +#define _VX_CACCT_H
14286 +
14287 +
14288 +enum sock_acc_field {
14289 +       VXA_SOCK_UNSPEC = 0,
14290 +       VXA_SOCK_UNIX,
14291 +       VXA_SOCK_INET,
14292 +       VXA_SOCK_INET6,
14293 +       VXA_SOCK_PACKET,
14294 +       VXA_SOCK_OTHER,
14295 +       VXA_SOCK_SIZE   /* array size */
14296 +};
14297 +
14298 +#endif /* _VX_CACCT_H */
14299 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cacct_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_cmd.h
14300 --- linux-2.6.22.10/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00 +0100
14301 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_cmd.h        2007-08-05 20:53:13 +0200
14302 @@ -0,0 +1,23 @@
14303 +#ifndef _VX_CACCT_CMD_H
14304 +#define _VX_CACCT_CMD_H
14305 +
14306 +
14307 +/* virtual host info name commands */
14308 +
14309 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
14310 +
14311 +struct vcmd_sock_stat_v0 {
14312 +       uint32_t field;
14313 +       uint32_t count[3];
14314 +       uint64_t total[3];
14315 +};
14316 +
14317 +
14318 +#ifdef __KERNEL__
14319 +
14320 +#include <linux/compiler.h>
14321 +
14322 +extern int vc_sock_stat(struct vx_info *, void __user *);
14323 +
14324 +#endif /* __KERNEL__ */
14325 +#endif /* _VX_CACCT_CMD_H */
14326 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cacct_def.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_def.h
14327 --- linux-2.6.22.10/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00 +0100
14328 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_def.h        2007-08-05 20:53:13 +0200
14329 @@ -0,0 +1,43 @@
14330 +#ifndef _VX_CACCT_DEF_H
14331 +#define _VX_CACCT_DEF_H
14332 +
14333 +#include <asm/atomic.h>
14334 +#include <linux/vserver/cacct.h>
14335 +
14336 +
14337 +struct _vx_sock_acc {
14338 +       atomic_long_t count;
14339 +       atomic_long_t total;
14340 +};
14341 +
14342 +/* context sub struct */
14343 +
14344 +struct _vx_cacct {
14345 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
14346 +       atomic_t slab[8];
14347 +       atomic_t page[6][8];
14348 +};
14349 +
14350 +#ifdef CONFIG_VSERVER_DEBUG
14351 +
14352 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
14353 +{
14354 +       int i, j;
14355 +
14356 +       printk("\t_vx_cacct:");
14357 +       for (i = 0; i < 6; i++) {
14358 +               struct _vx_sock_acc *ptr = cacct->sock[i];
14359 +
14360 +               printk("\t [%d] =", i);
14361 +               for (j = 0; j < 3; j++) {
14362 +                       printk(" [%d] = %8lu, %8lu", j,
14363 +                               atomic_long_read(&ptr[j].count),
14364 +                               atomic_long_read(&ptr[j].total));
14365 +               }
14366 +               printk("\n");
14367 +       }
14368 +}
14369 +
14370 +#endif
14371 +
14372 +#endif /* _VX_CACCT_DEF_H */
14373 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cacct_int.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_int.h
14374 --- linux-2.6.22.10/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00 +0100
14375 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_int.h        2007-08-05 20:53:13 +0200
14376 @@ -0,0 +1,21 @@
14377 +#ifndef _VX_CACCT_INT_H
14378 +#define _VX_CACCT_INT_H
14379 +
14380 +
14381 +#ifdef __KERNEL__
14382 +
14383 +static inline
14384 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
14385 +{
14386 +       return atomic_long_read(&cacct->sock[type][pos].count);
14387 +}
14388 +
14389 +
14390 +static inline
14391 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
14392 +{
14393 +       return atomic_long_read(&cacct->sock[type][pos].total);
14394 +}
14395 +
14396 +#endif /* __KERNEL__ */
14397 +#endif /* _VX_CACCT_INT_H */
14398 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/context.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/context.h
14399 --- linux-2.6.22.10/include/linux/vserver/context.h     1970-01-01 01:00:00 +0100
14400 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/context.h  2007-10-11 01:10:22 +0200
14401 @@ -0,0 +1,176 @@
14402 +#ifndef _VX_CONTEXT_H
14403 +#define _VX_CONTEXT_H
14404 +
14405 +#include <linux/types.h>
14406 +#include <linux/capability.h>
14407 +
14408 +
14409 +/* context flags */
14410 +
14411 +#define VXF_INFO_SCHED         0x00000002
14412 +#define VXF_INFO_NPROC         0x00000004
14413 +#define VXF_INFO_PRIVATE       0x00000008
14414 +
14415 +#define VXF_INFO_INIT          0x00000010
14416 +#define VXF_INFO_HIDE          0x00000020
14417 +#define VXF_INFO_ULIMIT                0x00000040
14418 +#define VXF_INFO_NSPACE                0x00000080
14419 +
14420 +#define VXF_SCHED_HARD         0x00000100
14421 +#define VXF_SCHED_PRIO         0x00000200
14422 +#define VXF_SCHED_PAUSE                0x00000400
14423 +
14424 +#define VXF_VIRT_MEM           0x00010000
14425 +#define VXF_VIRT_UPTIME                0x00020000
14426 +#define VXF_VIRT_CPU           0x00040000
14427 +#define VXF_VIRT_LOAD          0x00080000
14428 +#define VXF_VIRT_TIME          0x00100000
14429 +
14430 +#define VXF_HIDE_MOUNT         0x01000000
14431 +/* was VXF_HIDE_NETIF          0x02000000 */
14432 +#define VXF_HIDE_VINFO         0x04000000
14433 +
14434 +#define VXF_STATE_SETUP                (1ULL << 32)
14435 +#define VXF_STATE_INIT         (1ULL << 33)
14436 +#define VXF_STATE_ADMIN                (1ULL << 34)
14437 +
14438 +#define VXF_SC_HELPER          (1ULL << 36)
14439 +#define VXF_REBOOT_KILL                (1ULL << 37)
14440 +#define VXF_PERSISTENT         (1ULL << 38)
14441 +
14442 +#define VXF_FORK_RSS           (1ULL << 48)
14443 +#define VXF_PROLIFIC           (1ULL << 49)
14444 +
14445 +#define VXF_IGNEG_NICE         (1ULL << 52)
14446 +
14447 +#define VXF_ONE_TIME           (0x0007ULL << 32)
14448 +
14449 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
14450 +
14451 +
14452 +/* context migration */
14453 +
14454 +#define VXM_SET_INIT           0x00000001
14455 +#define VXM_SET_REAPER         0x00000002
14456 +
14457 +/* context caps */
14458 +
14459 +#define VXC_CAP_MASK           0x00000000
14460 +
14461 +#define VXC_SET_UTSNAME                0x00000001
14462 +#define VXC_SET_RLIMIT         0x00000002
14463 +
14464 +/* was VXC_RAW_ICMP            0x00000100 */
14465 +#define VXC_SYSLOG             0x00001000
14466 +
14467 +#define VXC_SECURE_MOUNT       0x00010000
14468 +#define VXC_SECURE_REMOUNT     0x00020000
14469 +#define VXC_BINARY_MOUNT       0x00040000
14470 +
14471 +#define VXC_QUOTA_CTL          0x00100000
14472 +#define VXC_ADMIN_MAPPER       0x00200000
14473 +#define VXC_ADMIN_CLOOP                0x00400000
14474 +
14475 +#define VXC_KTHREAD            0x01000000
14476 +
14477 +
14478 +#ifdef __KERNEL__
14479 +
14480 +#include <linux/list.h>
14481 +#include <linux/spinlock.h>
14482 +#include <linux/rcupdate.h>
14483 +
14484 +#include "limit_def.h"
14485 +#include "sched_def.h"
14486 +#include "cvirt_def.h"
14487 +#include "cacct_def.h"
14488 +#include "device_def.h"
14489 +
14490 +struct _vx_info_pc {
14491 +       struct _vx_sched_pc sched_pc;
14492 +       struct _vx_cvirt_pc cvirt_pc;
14493 +};
14494 +
14495 +struct vx_info {
14496 +       struct hlist_node vx_hlist;             /* linked list of contexts */
14497 +       xid_t vx_id;                            /* context id */
14498 +       atomic_t vx_usecnt;                     /* usage count */
14499 +       atomic_t vx_tasks;                      /* tasks count */
14500 +       struct vx_info *vx_parent;              /* parent context */
14501 +       int vx_state;                           /* context state */
14502 +
14503 +       unsigned long vx_nsmask;                /* assignment mask */
14504 +       struct nsproxy *vx_nsproxy;             /* private namespace */
14505 +       struct fs_struct *vx_fs;                /* private namespace fs */
14506 +
14507 +       uint64_t vx_flags;                      /* context flags */
14508 +       uint64_t vx_bcaps;                      /* bounding caps (system) */
14509 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
14510 +       kernel_cap_t vx_cap_bset;               /* the guest's bset */
14511 +
14512 +       struct task_struct *vx_reaper;          /* guest reaper process */
14513 +       pid_t vx_initpid;                       /* PID of guest init */
14514 +       int64_t vx_badness_bias;                /* OOM points bias */
14515 +
14516 +       struct _vx_limit limit;                 /* vserver limits */
14517 +       struct _vx_sched sched;                 /* vserver scheduler */
14518 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
14519 +       struct _vx_cacct cacct;                 /* context accounting */
14520 +
14521 +       struct _vx_device dmap;                 /* default device map targets */
14522 +
14523 +#ifndef CONFIG_SMP
14524 +       struct _vx_info_pc info_pc;             /* per cpu data */
14525 +#else
14526 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
14527 +#endif
14528 +
14529 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
14530 +       int reboot_cmd;                         /* last sys_reboot() cmd */
14531 +       int exit_code;                          /* last process exit code */
14532 +
14533 +       char vx_name[65];                       /* vserver name */
14534 +};
14535 +
14536 +#ifndef CONFIG_SMP
14537 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
14538 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
14539 +#else
14540 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
14541 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
14542 +#endif
14543 +
14544 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
14545 +
14546 +
14547 +struct vx_info_save {
14548 +       struct vx_info *vxi;
14549 +       xid_t xid;
14550 +};
14551 +
14552 +
14553 +/* status flags */
14554 +
14555 +#define VXS_HASHED     0x0001
14556 +#define VXS_PAUSED     0x0010
14557 +#define VXS_SHUTDOWN   0x0100
14558 +#define VXS_HELPER     0x1000
14559 +#define VXS_RELEASED   0x8000
14560 +
14561 +
14562 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
14563 +extern void release_vx_info(struct vx_info *, struct task_struct *);
14564 +
14565 +extern struct vx_info *lookup_vx_info(int);
14566 +extern struct vx_info *lookup_or_create_vx_info(int);
14567 +
14568 +extern int get_xid_list(int, unsigned int *, int);
14569 +extern int xid_is_hashed(xid_t);
14570 +
14571 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
14572 +
14573 +extern long vs_state_change(struct vx_info *, unsigned int);
14574 +
14575 +
14576 +#endif /* __KERNEL__ */
14577 +#endif /* _VX_CONTEXT_H */
14578 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/context_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/context_cmd.h
14579 --- linux-2.6.22.10/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00 +0100
14580 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/context_cmd.h      2007-08-19 00:40:28 +0200
14581 @@ -0,0 +1,128 @@
14582 +#ifndef _VX_CONTEXT_CMD_H
14583 +#define _VX_CONTEXT_CMD_H
14584 +
14585 +
14586 +/* vinfo commands */
14587 +
14588 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
14589 +
14590 +#ifdef __KERNEL__
14591 +extern int vc_task_xid(uint32_t);
14592 +
14593 +#endif /* __KERNEL__ */
14594 +
14595 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
14596 +
14597 +struct vcmd_vx_info_v0 {
14598 +       uint32_t xid;
14599 +       uint32_t initpid;
14600 +       /* more to come */
14601 +};
14602 +
14603 +#ifdef __KERNEL__
14604 +extern int vc_vx_info(struct vx_info *, void __user *);
14605 +
14606 +#endif /* __KERNEL__ */
14607 +
14608 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
14609 +
14610 +struct vcmd_ctx_stat_v0 {
14611 +       uint32_t usecnt;
14612 +       uint32_t tasks;
14613 +       /* more to come */
14614 +};
14615 +
14616 +#ifdef __KERNEL__
14617 +extern int vc_ctx_stat(struct vx_info *, void __user *);
14618 +
14619 +#endif /* __KERNEL__ */
14620 +
14621 +/* context commands */
14622 +
14623 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
14624 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
14625 +
14626 +struct vcmd_ctx_create {
14627 +       uint64_t flagword;
14628 +};
14629 +
14630 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
14631 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
14632 +
14633 +struct vcmd_ctx_migrate {
14634 +       uint64_t flagword;
14635 +};
14636 +
14637 +#ifdef __KERNEL__
14638 +extern int vc_ctx_create(uint32_t, void __user *);
14639 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
14640 +
14641 +#endif /* __KERNEL__ */
14642 +
14643 +
14644 +/* flag commands */
14645 +
14646 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
14647 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
14648 +
14649 +struct vcmd_ctx_flags_v0 {
14650 +       uint64_t flagword;
14651 +       uint64_t mask;
14652 +};
14653 +
14654 +#ifdef __KERNEL__
14655 +extern int vc_get_cflags(struct vx_info *, void __user *);
14656 +extern int vc_set_cflags(struct vx_info *, void __user *);
14657 +
14658 +#endif /* __KERNEL__ */
14659 +
14660 +
14661 +/* context caps commands */
14662 +
14663 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
14664 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
14665 +
14666 +struct vcmd_ctx_caps_v1 {
14667 +       uint64_t ccaps;
14668 +       uint64_t cmask;
14669 +};
14670 +
14671 +#ifdef __KERNEL__
14672 +extern int vc_get_ccaps(struct vx_info *, void __user *);
14673 +extern int vc_set_ccaps(struct vx_info *, void __user *);
14674 +
14675 +#endif /* __KERNEL__ */
14676 +
14677 +
14678 +/* bcaps commands */
14679 +
14680 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
14681 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
14682 +
14683 +struct vcmd_bcaps {
14684 +       uint64_t bcaps;
14685 +       uint64_t bmask;
14686 +};
14687 +
14688 +#ifdef __KERNEL__
14689 +extern int vc_get_bcaps(struct vx_info *, void __user *);
14690 +extern int vc_set_bcaps(struct vx_info *, void __user *);
14691 +
14692 +#endif /* __KERNEL__ */
14693 +
14694 +
14695 +/* OOM badness */
14696 +
14697 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
14698 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
14699 +
14700 +struct vcmd_badness_v0 {
14701 +       int64_t bias;
14702 +};
14703 +
14704 +#ifdef __KERNEL__
14705 +extern int vc_get_badness(struct vx_info *, void __user *);
14706 +extern int vc_set_badness(struct vx_info *, void __user *);
14707 +
14708 +#endif /* __KERNEL__ */
14709 +#endif /* _VX_CONTEXT_CMD_H */
14710 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cvirt.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt.h
14711 --- linux-2.6.22.10/include/linux/vserver/cvirt.h       1970-01-01 01:00:00 +0100
14712 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt.h    2007-08-05 20:53:13 +0200
14713 @@ -0,0 +1,20 @@
14714 +#ifndef _VX_CVIRT_H
14715 +#define _VX_CVIRT_H
14716 +
14717 +
14718 +#ifdef __KERNEL__
14719 +
14720 +struct timespec;
14721 +
14722 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14723 +
14724 +
14725 +struct vx_info;
14726 +
14727 +void vx_update_load(struct vx_info *);
14728 +
14729 +
14730 +int vx_do_syslog(int, char __user *, int);
14731 +
14732 +#endif /* __KERNEL__ */
14733 +#endif /* _VX_CVIRT_H */
14734 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cvirt_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt_cmd.h
14735 --- linux-2.6.22.10/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00 +0100
14736 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt_cmd.h        2007-08-05 20:53:13 +0200
14737 @@ -0,0 +1,53 @@
14738 +#ifndef _VX_CVIRT_CMD_H
14739 +#define _VX_CVIRT_CMD_H
14740 +
14741 +
14742 +/* virtual host info name commands */
14743 +
14744 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
14745 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
14746 +
14747 +struct vcmd_vhi_name_v0 {
14748 +       uint32_t field;
14749 +       char name[65];
14750 +};
14751 +
14752 +
14753 +enum vhi_name_field {
14754 +       VHIN_CONTEXT = 0,
14755 +       VHIN_SYSNAME,
14756 +       VHIN_NODENAME,
14757 +       VHIN_RELEASE,
14758 +       VHIN_VERSION,
14759 +       VHIN_MACHINE,
14760 +       VHIN_DOMAINNAME,
14761 +};
14762 +
14763 +
14764 +#ifdef __KERNEL__
14765 +
14766 +#include <linux/compiler.h>
14767 +
14768 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
14769 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
14770 +
14771 +#endif /* __KERNEL__ */
14772 +
14773 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
14774 +
14775 +struct vcmd_virt_stat_v0 {
14776 +       uint64_t offset;
14777 +       uint64_t uptime;
14778 +       uint32_t nr_threads;
14779 +       uint32_t nr_running;
14780 +       uint32_t nr_uninterruptible;
14781 +       uint32_t nr_onhold;
14782 +       uint32_t nr_forks;
14783 +       uint32_t load[3];
14784 +};
14785 +
14786 +#ifdef __KERNEL__
14787 +extern int vc_virt_stat(struct vx_info *, void __user *);
14788 +
14789 +#endif /* __KERNEL__ */
14790 +#endif /* _VX_CVIRT_CMD_H */
14791 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cvirt_def.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt_def.h
14792 --- linux-2.6.22.10/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00 +0100
14793 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt_def.h        2007-08-05 20:53:13 +0200
14794 @@ -0,0 +1,81 @@
14795 +#ifndef _VX_CVIRT_DEF_H
14796 +#define _VX_CVIRT_DEF_H
14797 +
14798 +#include <linux/jiffies.h>
14799 +#include <linux/spinlock.h>
14800 +#include <linux/wait.h>
14801 +#include <linux/time.h>
14802 +#include <linux/utsname.h>
14803 +#include <asm/atomic.h>
14804 +
14805 +
14806 +struct _vx_usage_stat {
14807 +       uint64_t user;
14808 +       uint64_t nice;
14809 +       uint64_t system;
14810 +       uint64_t softirq;
14811 +       uint64_t irq;
14812 +       uint64_t idle;
14813 +       uint64_t iowait;
14814 +};
14815 +
14816 +struct _vx_syslog {
14817 +       wait_queue_head_t log_wait;
14818 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
14819 +
14820 +       unsigned long log_start;        /* next char to be read by syslog() */
14821 +       unsigned long con_start;        /* next char to be sent to consoles */
14822 +       unsigned long log_end;  /* most-recently-written-char + 1 */
14823 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
14824 +
14825 +       char log_buf[1024];
14826 +};
14827 +
14828 +
14829 +/* context sub struct */
14830 +
14831 +struct _vx_cvirt {
14832 +       atomic_t nr_threads;            /* number of current threads */
14833 +       atomic_t nr_running;            /* number of running threads */
14834 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
14835 +
14836 +       atomic_t nr_onhold;             /* processes on hold */
14837 +       uint32_t onhold_last;           /* jiffies when put on hold */
14838 +
14839 +       struct timeval bias_tv;         /* time offset to the host */
14840 +       struct timespec bias_idle;
14841 +       struct timespec bias_uptime;    /* context creation point */
14842 +       uint64_t bias_clock;            /* offset in clock_t */
14843 +
14844 +       spinlock_t load_lock;           /* lock for the load averages */
14845 +       atomic_t load_updates;          /* nr of load updates done so far */
14846 +       uint32_t load_last;             /* last time load was calculated */
14847 +       uint32_t load[3];               /* load averages 1,5,15 */
14848 +
14849 +       atomic_t total_forks;           /* number of forks so far */
14850 +
14851 +       struct _vx_syslog syslog;
14852 +};
14853 +
14854 +struct _vx_cvirt_pc {
14855 +       struct _vx_usage_stat cpustat;
14856 +};
14857 +
14858 +
14859 +#ifdef CONFIG_VSERVER_DEBUG
14860 +
14861 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
14862 +{
14863 +       printk("\t_vx_cvirt:\n");
14864 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
14865 +               atomic_read(&cvirt->nr_threads),
14866 +               atomic_read(&cvirt->nr_running),
14867 +               atomic_read(&cvirt->nr_uninterruptible),
14868 +               atomic_read(&cvirt->nr_onhold));
14869 +       /* add rest here */
14870 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
14871 +}
14872 +
14873 +#endif
14874 +
14875 +#endif /* _VX_CVIRT_DEF_H */
14876 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/debug.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/debug.h
14877 --- linux-2.6.22.10/include/linux/vserver/debug.h       1970-01-01 01:00:00 +0100
14878 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/debug.h    2007-10-25 17:05:55 +0200
14879 @@ -0,0 +1,130 @@
14880 +#ifndef _VX_DEBUG_H
14881 +#define _VX_DEBUG_H
14882 +
14883 +
14884 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
14885 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
14886 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
14887 +
14888 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
14889 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
14890 +#define VXF_DEV                "%p[%lu,%d:%d]"
14891 +
14892 +
14893 +#define __FUNC__       __func__
14894 +
14895 +
14896 +#define vxd_path(d, m)                                         \
14897 +       ({ static char _buffer[PATH_MAX];                       \
14898 +          d_path(d, m, _buffer, sizeof(_buffer)); })
14899 +
14900 +#define vxd_cond_path(n)                                       \
14901 +       ((n) ? vxd_path((n)->dentry, (n)->mnt) : "<null>" )
14902 +
14903 +
14904 +#ifdef CONFIG_VSERVER_DEBUG
14905 +
14906 +extern unsigned int vx_debug_switch;
14907 +extern unsigned int vx_debug_xid;
14908 +extern unsigned int vx_debug_nid;
14909 +extern unsigned int vx_debug_tag;
14910 +extern unsigned int vx_debug_net;
14911 +extern unsigned int vx_debug_limit;
14912 +extern unsigned int vx_debug_cres;
14913 +extern unsigned int vx_debug_dlim;
14914 +extern unsigned int vx_debug_quota;
14915 +extern unsigned int vx_debug_cvirt;
14916 +extern unsigned int vx_debug_space;
14917 +extern unsigned int vx_debug_misc;
14918 +
14919 +
14920 +#define VX_LOGLEVEL    "vxD: "
14921 +#define VX_PROC_FMT    "%p: "
14922 +#define VX_PROCESS     current
14923 +
14924 +#define vxdprintk(c, f, x...)                                  \
14925 +       do {                                                    \
14926 +               if (c)                                          \
14927 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
14928 +                               VX_PROCESS , ##x);              \
14929 +       } while (0)
14930 +
14931 +#define vxlprintk(c, f, x...)                                  \
14932 +       do {                                                    \
14933 +               if (c)                                          \
14934 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
14935 +       } while (0)
14936 +
14937 +#define vxfprintk(c, f, x...)                                  \
14938 +       do {                                                    \
14939 +               if (c)                                          \
14940 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
14941 +       } while (0)
14942 +
14943 +
14944 +struct vx_info;
14945 +
14946 +void dump_vx_info(struct vx_info *, int);
14947 +void dump_vx_info_inactive(int);
14948 +
14949 +#else  /* CONFIG_VSERVER_DEBUG */
14950 +
14951 +#define vx_debug_switch 0
14952 +#define vx_debug_xid   0
14953 +#define vx_debug_nid   0
14954 +#define vx_debug_tag   0
14955 +#define vx_debug_net   0
14956 +#define vx_debug_limit 0
14957 +#define vx_debug_cres  0
14958 +#define vx_debug_dlim  0
14959 +#define vx_debug_cvirt 0
14960 +
14961 +#define vxdprintk(x...) do { } while (0)
14962 +#define vxlprintk(x...) do { } while (0)
14963 +#define vxfprintk(x...) do { } while (0)
14964 +
14965 +#endif /* CONFIG_VSERVER_DEBUG */
14966 +
14967 +
14968 +#ifdef CONFIG_VSERVER_WARN
14969 +
14970 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
14971 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
14972 +#define VX_WARN_XID    "[xid #%u] "
14973 +#define VX_WARN_NID    "[nid #%u] "
14974 +#define VX_WARN_TAG    "[tag #%u] "
14975 +
14976 +#define vxwprintk(c, f, x...)                                  \
14977 +       do {                                                    \
14978 +               if (c)                                          \
14979 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
14980 +       } while (0)
14981 +
14982 +#else  /* CONFIG_VSERVER_WARN */
14983 +
14984 +#define vxwprintk(x...) do { } while (0)
14985 +
14986 +#endif /* CONFIG_VSERVER_WARN */
14987 +
14988 +#define vxwprintk_task(c, f, x...)                             \
14989 +       vxwprintk(c, VX_WARN_TASK f,                            \
14990 +               current->comm, current->pid,                    \
14991 +               current->xid, current->nid, current->tag, ##x)
14992 +#define vxwprintk_xid(c, f, x...)                              \
14993 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
14994 +#define vxwprintk_nid(c, f, x...)                              \
14995 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
14996 +#define vxwprintk_tag(c, f, x...)                              \
14997 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
14998 +
14999 +#ifdef CONFIG_VSERVER_DEBUG
15000 +#define vxd_assert_lock(l)     assert_spin_locked(l)
15001 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
15002 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
15003 +#else
15004 +#define vxd_assert_lock(l)     do { } while (0)
15005 +#define vxd_assert(c, f, x...) do { } while (0)
15006 +#endif
15007 +
15008 +
15009 +#endif /* _VX_DEBUG_H */
15010 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/debug_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/debug_cmd.h
15011 --- linux-2.6.22.10/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00 +0100
15012 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/debug_cmd.h        2007-08-05 20:53:13 +0200
15013 @@ -0,0 +1,58 @@
15014 +#ifndef _VX_DEBUG_CMD_H
15015 +#define _VX_DEBUG_CMD_H
15016 +
15017 +
15018 +/* debug commands */
15019 +
15020 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
15021 +
15022 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
15023 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
15024 +
15025 +struct  vcmd_read_history_v0 {
15026 +       uint32_t index;
15027 +       uint32_t count;
15028 +       char __user *data;
15029 +};
15030 +
15031 +struct  vcmd_read_monitor_v0 {
15032 +       uint32_t index;
15033 +       uint32_t count;
15034 +       char __user *data;
15035 +};
15036 +
15037 +
15038 +#ifdef __KERNEL__
15039 +
15040 +#ifdef CONFIG_COMPAT
15041 +
15042 +#include <asm/compat.h>
15043 +
15044 +struct vcmd_read_history_v0_x32 {
15045 +       uint32_t index;
15046 +       uint32_t count;
15047 +       compat_uptr_t data_ptr;
15048 +};
15049 +
15050 +struct vcmd_read_monitor_v0_x32 {
15051 +       uint32_t index;
15052 +       uint32_t count;
15053 +       compat_uptr_t data_ptr;
15054 +};
15055 +
15056 +#endif  /* CONFIG_COMPAT */
15057 +
15058 +extern int vc_dump_history(uint32_t);
15059 +
15060 +extern int vc_read_history(uint32_t, void __user *);
15061 +extern int vc_read_monitor(uint32_t, void __user *);
15062 +
15063 +#ifdef CONFIG_COMPAT
15064 +
15065 +extern int vc_read_history_x32(uint32_t, void __user *);
15066 +extern int vc_read_monitor_x32(uint32_t, void __user *);
15067 +
15068 +#endif  /* CONFIG_COMPAT */
15069 +
15070 +#endif /* __KERNEL__ */
15071 +#endif /* _VX_DEBUG_CMD_H */
15072 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/device.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device.h
15073 --- linux-2.6.22.10/include/linux/vserver/device.h      1970-01-01 01:00:00 +0100
15074 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device.h   2007-10-11 01:10:22 +0200
15075 @@ -0,0 +1,15 @@
15076 +#ifndef _VX_DEVICE_H
15077 +#define _VX_DEVICE_H
15078 +
15079 +
15080 +#define DATTR_CREATE   0x00000001
15081 +#define DATTR_OPEN     0x00000002
15082 +
15083 +#define DATTR_REMAP    0x00000010
15084 +
15085 +#define DATTR_MASK     0x00000013
15086 +
15087 +
15088 +#else  /* _VX_DEVICE_H */
15089 +#warning duplicate inclusion
15090 +#endif /* _VX_DEVICE_H */
15091 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/device_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device_cmd.h
15092 --- linux-2.6.22.10/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00 +0100
15093 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device_cmd.h       2007-10-11 01:10:22 +0200
15094 @@ -0,0 +1,44 @@
15095 +#ifndef _VX_DEVICE_CMD_H
15096 +#define _VX_DEVICE_CMD_H
15097 +
15098 +
15099 +/*  device vserver commands */
15100 +
15101 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
15102 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
15103 +
15104 +struct vcmd_set_mapping_v0 {
15105 +       const char __user *device;
15106 +       const char __user *target;
15107 +       uint32_t flags;
15108 +};
15109 +
15110 +
15111 +#ifdef __KERNEL__
15112 +
15113 +#ifdef CONFIG_COMPAT
15114 +
15115 +#include <asm/compat.h>
15116 +
15117 +struct vcmd_set_mapping_v0_x32 {
15118 +       compat_uptr_t device_ptr;
15119 +       compat_uptr_t target_ptr;
15120 +       uint32_t flags;
15121 +};
15122 +
15123 +#endif /* CONFIG_COMPAT */
15124 +
15125 +#include <linux/compiler.h>
15126 +
15127 +extern int vc_set_mapping(struct vx_info *, void __user *);
15128 +extern int vc_unset_mapping(struct vx_info *, void __user *);
15129 +
15130 +#ifdef CONFIG_COMPAT
15131 +
15132 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
15133 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
15134 +
15135 +#endif /* CONFIG_COMPAT */
15136 +
15137 +#endif /* __KERNEL__ */
15138 +#endif /* _VX_DEVICE_CMD_H */
15139 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/device_def.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device_def.h
15140 --- linux-2.6.22.10/include/linux/vserver/device_def.h  1970-01-01 01:00:00 +0100
15141 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device_def.h       2007-10-11 01:10:22 +0200
15142 @@ -0,0 +1,17 @@
15143 +#ifndef _VX_DEVICE_DEF_H
15144 +#define _VX_DEVICE_DEF_H
15145 +
15146 +#include <linux/types.h>
15147 +
15148 +struct vx_dmap_target {
15149 +       dev_t target;
15150 +       uint32_t flags;
15151 +};
15152 +
15153 +struct _vx_device {
15154 +#ifdef CONFIG_VSERVER_DEVICE
15155 +       struct vx_dmap_target targets[2];
15156 +#endif
15157 +};
15158 +
15159 +#endif /* _VX_DEVICE_DEF_H */
15160 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/dlimit.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/dlimit.h
15161 --- linux-2.6.22.10/include/linux/vserver/dlimit.h      1970-01-01 01:00:00 +0100
15162 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/dlimit.h   2007-08-15 22:03:58 +0200
15163 @@ -0,0 +1,54 @@
15164 +#ifndef _VX_DLIMIT_H
15165 +#define _VX_DLIMIT_H
15166 +
15167 +#include "switch.h"
15168 +
15169 +
15170 +#ifdef __KERNEL__
15171 +
15172 +/*      keep in sync with CDLIM_INFINITY       */
15173 +
15174 +#define DLIM_INFINITY          (~0ULL)
15175 +
15176 +#include <linux/spinlock.h>
15177 +#include <linux/rcupdate.h>
15178 +
15179 +struct super_block;
15180 +
15181 +struct dl_info {
15182 +       struct hlist_node dl_hlist;             /* linked list of contexts */
15183 +       struct rcu_head dl_rcu;                 /* the rcu head */
15184 +       tag_t dl_tag;                           /* context tag */
15185 +       atomic_t dl_usecnt;                     /* usage count */
15186 +       atomic_t dl_refcnt;                     /* reference count */
15187 +
15188 +       struct super_block *dl_sb;              /* associated superblock */
15189 +
15190 +       spinlock_t dl_lock;                     /* protect the values */
15191 +
15192 +       unsigned long long dl_space_used;       /* used space in bytes */
15193 +       unsigned long long dl_space_total;      /* maximum space in bytes */
15194 +       unsigned long dl_inodes_used;           /* used inodes */
15195 +       unsigned long dl_inodes_total;          /* maximum inodes */
15196 +
15197 +       unsigned int dl_nrlmult;                /* non root limit mult */
15198 +};
15199 +
15200 +struct rcu_head;
15201 +
15202 +extern void rcu_free_dl_info(struct rcu_head *);
15203 +extern void unhash_dl_info(struct dl_info *);
15204 +
15205 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
15206 +
15207 +
15208 +struct kstatfs;
15209 +
15210 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
15211 +
15212 +typedef uint64_t dlsize_t;
15213 +
15214 +#endif /* __KERNEL__ */
15215 +#else  /* _VX_DLIMIT_H */
15216 +#warning duplicate inclusion
15217 +#endif /* _VX_DLIMIT_H */
15218 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/dlimit_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/dlimit_cmd.h
15219 --- linux-2.6.22.10/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00 +0100
15220 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/dlimit_cmd.h       2007-08-05 20:53:13 +0200
15221 @@ -0,0 +1,74 @@
15222 +#ifndef _VX_DLIMIT_CMD_H
15223 +#define _VX_DLIMIT_CMD_H
15224 +
15225 +
15226 +/*  dlimit vserver commands */
15227 +
15228 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
15229 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
15230 +
15231 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
15232 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
15233 +
15234 +struct vcmd_ctx_dlimit_base_v0 {
15235 +       const char __user *name;
15236 +       uint32_t flags;
15237 +};
15238 +
15239 +struct vcmd_ctx_dlimit_v0 {
15240 +       const char __user *name;
15241 +       uint32_t space_used;                    /* used space in kbytes */
15242 +       uint32_t space_total;                   /* maximum space in kbytes */
15243 +       uint32_t inodes_used;                   /* used inodes */
15244 +       uint32_t inodes_total;                  /* maximum inodes */
15245 +       uint32_t reserved;                      /* reserved for root in % */
15246 +       uint32_t flags;
15247 +};
15248 +
15249 +#define CDLIM_UNSET            ((uint32_t)0UL)
15250 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
15251 +#define CDLIM_KEEP             ((uint32_t)~1UL)
15252 +
15253 +#ifdef __KERNEL__
15254 +
15255 +#ifdef CONFIG_COMPAT
15256 +
15257 +#include <asm/compat.h>
15258 +
15259 +struct vcmd_ctx_dlimit_base_v0_x32 {
15260 +       compat_uptr_t name_ptr;
15261 +       uint32_t flags;
15262 +};
15263 +
15264 +struct vcmd_ctx_dlimit_v0_x32 {
15265 +       compat_uptr_t name_ptr;
15266 +       uint32_t space_used;                    /* used space in kbytes */
15267 +       uint32_t space_total;                   /* maximum space in kbytes */
15268 +       uint32_t inodes_used;                   /* used inodes */
15269 +       uint32_t inodes_total;                  /* maximum inodes */
15270 +       uint32_t reserved;                      /* reserved for root in % */
15271 +       uint32_t flags;
15272 +};
15273 +
15274 +#endif /* CONFIG_COMPAT */
15275 +
15276 +#include <linux/compiler.h>
15277 +
15278 +extern int vc_add_dlimit(uint32_t, void __user *);
15279 +extern int vc_rem_dlimit(uint32_t, void __user *);
15280 +
15281 +extern int vc_set_dlimit(uint32_t, void __user *);
15282 +extern int vc_get_dlimit(uint32_t, void __user *);
15283 +
15284 +#ifdef CONFIG_COMPAT
15285 +
15286 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
15287 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
15288 +
15289 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
15290 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
15291 +
15292 +#endif /* CONFIG_COMPAT */
15293 +
15294 +#endif /* __KERNEL__ */
15295 +#endif /* _VX_DLIMIT_CMD_H */
15296 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/global.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/global.h
15297 --- linux-2.6.22.10/include/linux/vserver/global.h      1970-01-01 01:00:00 +0100
15298 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/global.h   2007-08-05 20:53:13 +0200
15299 @@ -0,0 +1,18 @@
15300 +#ifndef _VX_GLOBAL_H
15301 +#define _VX_GLOBAL_H
15302 +
15303 +
15304 +extern atomic_t vx_global_ctotal;
15305 +extern atomic_t vx_global_cactive;
15306 +
15307 +extern atomic_t nx_global_ctotal;
15308 +extern atomic_t nx_global_cactive;
15309 +
15310 +extern atomic_t vs_global_nsproxy;
15311 +extern atomic_t vs_global_fs;
15312 +extern atomic_t vs_global_mnt_ns;
15313 +extern atomic_t vs_global_uts_ns;
15314 +extern atomic_t vs_global_ipc_ns;
15315 +
15316 +
15317 +#endif /* _VX_GLOBAL_H */
15318 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/history.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/history.h
15319 --- linux-2.6.22.10/include/linux/vserver/history.h     1970-01-01 01:00:00 +0100
15320 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/history.h  2007-08-05 20:53:13 +0200
15321 @@ -0,0 +1,197 @@
15322 +#ifndef _VX_HISTORY_H
15323 +#define _VX_HISTORY_H
15324 +
15325 +
15326 +enum {
15327 +       VXH_UNUSED = 0,
15328 +       VXH_THROW_OOPS = 1,
15329 +
15330 +       VXH_GET_VX_INFO,
15331 +       VXH_PUT_VX_INFO,
15332 +       VXH_INIT_VX_INFO,
15333 +       VXH_SET_VX_INFO,
15334 +       VXH_CLR_VX_INFO,
15335 +       VXH_CLAIM_VX_INFO,
15336 +       VXH_RELEASE_VX_INFO,
15337 +       VXH_ALLOC_VX_INFO,
15338 +       VXH_DEALLOC_VX_INFO,
15339 +       VXH_HASH_VX_INFO,
15340 +       VXH_UNHASH_VX_INFO,
15341 +       VXH_LOC_VX_INFO,
15342 +       VXH_LOOKUP_VX_INFO,
15343 +       VXH_CREATE_VX_INFO,
15344 +};
15345 +
15346 +struct _vxhe_vxi {
15347 +       struct vx_info *ptr;
15348 +       unsigned xid;
15349 +       unsigned usecnt;
15350 +       unsigned tasks;
15351 +};
15352 +
15353 +struct _vxhe_set_clr {
15354 +       void *data;
15355 +};
15356 +
15357 +struct _vxhe_loc_lookup {
15358 +       unsigned arg;
15359 +};
15360 +
15361 +struct _vx_hist_entry {
15362 +       void *loc;
15363 +       unsigned short seq;
15364 +       unsigned short type;
15365 +       struct _vxhe_vxi vxi;
15366 +       union {
15367 +               struct _vxhe_set_clr sc;
15368 +               struct _vxhe_loc_lookup ll;
15369 +       };
15370 +};
15371 +
15372 +#ifdef CONFIG_VSERVER_HISTORY
15373 +
15374 +extern unsigned volatile int vxh_active;
15375 +
15376 +struct _vx_hist_entry *vxh_advance(void *loc);
15377 +
15378 +
15379 +static inline
15380 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
15381 +{
15382 +       entry->vxi.ptr = vxi;
15383 +       if (vxi) {
15384 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
15385 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
15386 +               entry->vxi.xid = vxi->vx_id;
15387 +       }
15388 +}
15389 +
15390 +
15391 +#define        __HERE__ current_text_addr()
15392 +
15393 +#define __VXH_BODY(__type, __data, __here)     \
15394 +       struct _vx_hist_entry *entry;           \
15395 +                                               \
15396 +       preempt_disable();                      \
15397 +       entry = vxh_advance(__here);            \
15398 +       __data;                                 \
15399 +       entry->type = __type;                   \
15400 +       preempt_enable();
15401 +
15402 +
15403 +       /* pass vxi only */
15404 +
15405 +#define __VXH_SMPL                             \
15406 +       __vxh_copy_vxi(entry, vxi)
15407 +
15408 +static inline
15409 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
15410 +{
15411 +       __VXH_BODY(__type, __VXH_SMPL, __here)
15412 +}
15413 +
15414 +       /* pass vxi and data (void *) */
15415 +
15416 +#define __VXH_DATA                             \
15417 +       __vxh_copy_vxi(entry, vxi);             \
15418 +       entry->sc.data = data
15419 +
15420 +static inline
15421 +void   __vxh_data(struct vx_info *vxi, void *data,
15422 +                       int __type, void *__here)
15423 +{
15424 +       __VXH_BODY(__type, __VXH_DATA, __here)
15425 +}
15426 +
15427 +       /* pass vxi and arg (long) */
15428 +
15429 +#define __VXH_LONG                             \
15430 +       __vxh_copy_vxi(entry, vxi);             \
15431 +       entry->ll.arg = arg
15432 +
15433 +static inline
15434 +void   __vxh_long(struct vx_info *vxi, long arg,
15435 +                       int __type, void *__here)
15436 +{
15437 +       __VXH_BODY(__type, __VXH_LONG, __here)
15438 +}
15439 +
15440 +
15441 +static inline
15442 +void   __vxh_throw_oops(void *__here)
15443 +{
15444 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
15445 +       /* prevent further acquisition */
15446 +       vxh_active = 0;
15447 +}
15448 +
15449 +
15450 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
15451 +
15452 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
15453 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
15454 +
15455 +#define __vxh_init_vx_info(v, d, h) \
15456 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
15457 +#define __vxh_set_vx_info(v, d, h) \
15458 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
15459 +#define __vxh_clr_vx_info(v, d, h) \
15460 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
15461 +
15462 +#define __vxh_claim_vx_info(v, d, h) \
15463 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
15464 +#define __vxh_release_vx_info(v, d, h) \
15465 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
15466 +
15467 +#define vxh_alloc_vx_info(v) \
15468 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
15469 +#define vxh_dealloc_vx_info(v) \
15470 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
15471 +
15472 +#define vxh_hash_vx_info(v) \
15473 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
15474 +#define vxh_unhash_vx_info(v) \
15475 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
15476 +
15477 +#define vxh_loc_vx_info(v, l) \
15478 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
15479 +#define vxh_lookup_vx_info(v, l) \
15480 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
15481 +#define vxh_create_vx_info(v, l) \
15482 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
15483 +
15484 +extern void vxh_dump_history(void);
15485 +
15486 +
15487 +#else  /* CONFIG_VSERVER_HISTORY */
15488 +
15489 +#define        __HERE__        0
15490 +
15491 +#define vxh_throw_oops()               do { } while (0)
15492 +
15493 +#define __vxh_get_vx_info(v, h)                do { } while (0)
15494 +#define __vxh_put_vx_info(v, h)                do { } while (0)
15495 +
15496 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
15497 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
15498 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
15499 +
15500 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
15501 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
15502 +
15503 +#define vxh_alloc_vx_info(v)           do { } while (0)
15504 +#define vxh_dealloc_vx_info(v)         do { } while (0)
15505 +
15506 +#define vxh_hash_vx_info(v)            do { } while (0)
15507 +#define vxh_unhash_vx_info(v)          do { } while (0)
15508 +
15509 +#define vxh_loc_vx_info(v, l)          do { } while (0)
15510 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
15511 +#define vxh_create_vx_info(v, l)       do { } while (0)
15512 +
15513 +#define vxh_dump_history()             do { } while (0)
15514 +
15515 +
15516 +#endif /* CONFIG_VSERVER_HISTORY */
15517 +
15518 +#endif /* _VX_HISTORY_H */
15519 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/inode.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/inode.h
15520 --- linux-2.6.22.10/include/linux/vserver/inode.h       1970-01-01 01:00:00 +0100
15521 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/inode.h    2007-08-05 20:53:13 +0200
15522 @@ -0,0 +1,38 @@
15523 +#ifndef _VX_INODE_H
15524 +#define _VX_INODE_H
15525 +
15526 +
15527 +#define IATTR_TAG      0x01000000
15528 +
15529 +#define IATTR_ADMIN    0x00000001
15530 +#define IATTR_WATCH    0x00000002
15531 +#define IATTR_HIDE     0x00000004
15532 +#define IATTR_FLAGS    0x00000007
15533 +
15534 +#define IATTR_BARRIER  0x00010000
15535 +#define IATTR_IUNLINK  0x00020000
15536 +#define IATTR_IMMUTABLE 0x00040000
15537 +
15538 +#ifdef __KERNEL__
15539 +
15540 +
15541 +#ifdef CONFIG_VSERVER_PROC_SECURE
15542 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
15543 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
15544 +#else
15545 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
15546 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
15547 +#endif
15548 +
15549 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
15550 +
15551 +#endif /* __KERNEL__ */
15552 +
15553 +/* inode ioctls */
15554 +
15555 +#define FIOC_GETXFLG   _IOR('x', 5, long)
15556 +#define FIOC_SETXFLG   _IOW('x', 6, long)
15557 +
15558 +#else  /* _VX_INODE_H */
15559 +#warning duplicate inclusion
15560 +#endif /* _VX_INODE_H */
15561 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/inode_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/inode_cmd.h
15562 --- linux-2.6.22.10/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00 +0100
15563 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/inode_cmd.h        2007-08-15 18:08:31 +0200
15564 @@ -0,0 +1,59 @@
15565 +#ifndef _VX_INODE_CMD_H
15566 +#define _VX_INODE_CMD_H
15567 +
15568 +
15569 +/*  inode vserver commands */
15570 +
15571 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
15572 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
15573 +
15574 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
15575 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
15576 +
15577 +struct vcmd_ctx_iattr_v1 {
15578 +       const char __user *name;
15579 +       uint32_t tag;
15580 +       uint32_t flags;
15581 +       uint32_t mask;
15582 +};
15583 +
15584 +struct vcmd_ctx_fiattr_v0 {
15585 +       uint32_t tag;
15586 +       uint32_t flags;
15587 +       uint32_t mask;
15588 +};
15589 +
15590 +
15591 +#ifdef __KERNEL__
15592 +
15593 +
15594 +#ifdef CONFIG_COMPAT
15595 +
15596 +#include <asm/compat.h>
15597 +
15598 +struct vcmd_ctx_iattr_v1_x32 {
15599 +       compat_uptr_t name_ptr;
15600 +       uint32_t tag;
15601 +       uint32_t flags;
15602 +       uint32_t mask;
15603 +};
15604 +
15605 +#endif /* CONFIG_COMPAT */
15606 +
15607 +#include <linux/compiler.h>
15608 +
15609 +extern int vc_get_iattr(void __user *);
15610 +extern int vc_set_iattr(void __user *);
15611 +
15612 +extern int vc_fget_iattr(uint32_t, void __user *);
15613 +extern int vc_fset_iattr(uint32_t, void __user *);
15614 +
15615 +#ifdef CONFIG_COMPAT
15616 +
15617 +extern int vc_get_iattr_x32(void __user *);
15618 +extern int vc_set_iattr_x32(void __user *);
15619 +
15620 +#endif /* CONFIG_COMPAT */
15621 +
15622 +#endif /* __KERNEL__ */
15623 +#endif /* _VX_INODE_CMD_H */
15624 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/limit.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit.h
15625 --- linux-2.6.22.10/include/linux/vserver/limit.h       1970-01-01 01:00:00 +0100
15626 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit.h    2007-08-15 22:27:29 +0200
15627 @@ -0,0 +1,70 @@
15628 +#ifndef _VX_LIMIT_H
15629 +#define _VX_LIMIT_H
15630 +
15631 +#define VLIMIT_NSOCK   16
15632 +#define VLIMIT_OPENFD  17
15633 +#define VLIMIT_ANON    18
15634 +#define VLIMIT_SHMEM   19
15635 +#define VLIMIT_SEMARY  20
15636 +#define VLIMIT_NSEMS   21
15637 +#define VLIMIT_DENTRY  22
15638 +#define VLIMIT_MAPPED  23
15639 +
15640 +
15641 +#ifdef __KERNEL__
15642 +
15643 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
15644 +
15645 +/*     keep in sync with CRLIM_INFINITY */
15646 +
15647 +#define        VLIM_INFINITY   (~0ULL)
15648 +
15649 +#include <asm/atomic.h>
15650 +#include <asm/resource.h>
15651 +
15652 +#ifndef RLIM_INFINITY
15653 +#warning RLIM_INFINITY is undefined
15654 +#endif
15655 +
15656 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
15657 +
15658 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
15659 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
15660 +
15661 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
15662 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
15663 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
15664 +
15665 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
15666 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
15667 +
15668 +typedef atomic_long_t rlim_atomic_t;
15669 +typedef unsigned long rlim_t;
15670 +
15671 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
15672 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
15673 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
15674 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
15675 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
15676 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
15677 +
15678 +
15679 +#if    (RLIM_INFINITY == VLIM_INFINITY)
15680 +#define        VX_VLIM(r) ((long long)(long)(r))
15681 +#define        VX_RLIM(v) ((rlim_t)(v))
15682 +#else
15683 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
15684 +               ? VLIM_INFINITY : (long long)(r))
15685 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
15686 +               ? RLIM_INFINITY : (rlim_t)(v))
15687 +#endif
15688 +
15689 +struct sysinfo;
15690 +
15691 +void vx_vsi_meminfo(struct sysinfo *);
15692 +void vx_vsi_swapinfo(struct sysinfo *);
15693 +
15694 +#define NUM_LIMITS     24
15695 +
15696 +#endif /* __KERNEL__ */
15697 +#endif /* _VX_LIMIT_H */
15698 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/limit_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_cmd.h
15699 --- linux-2.6.22.10/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00 +0100
15700 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_cmd.h        2007-08-05 20:53:13 +0200
15701 @@ -0,0 +1,69 @@
15702 +#ifndef _VX_LIMIT_CMD_H
15703 +#define _VX_LIMIT_CMD_H
15704 +
15705 +
15706 +/*  rlimit vserver commands */
15707 +
15708 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
15709 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
15710 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
15711 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
15712 +
15713 +struct vcmd_ctx_rlimit_v0 {
15714 +       uint32_t id;
15715 +       uint64_t minimum;
15716 +       uint64_t softlimit;
15717 +       uint64_t maximum;
15718 +};
15719 +
15720 +struct vcmd_ctx_rlimit_mask_v0 {
15721 +       uint32_t minimum;
15722 +       uint32_t softlimit;
15723 +       uint32_t maximum;
15724 +};
15725 +
15726 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
15727 +
15728 +struct vcmd_rlimit_stat_v0 {
15729 +       uint32_t id;
15730 +       uint32_t hits;
15731 +       uint64_t value;
15732 +       uint64_t minimum;
15733 +       uint64_t maximum;
15734 +};
15735 +
15736 +#define CRLIM_UNSET            (0ULL)
15737 +#define CRLIM_INFINITY         (~0ULL)
15738 +#define CRLIM_KEEP             (~1ULL)
15739 +
15740 +#ifdef __KERNEL__
15741 +
15742 +#ifdef CONFIG_IA32_EMULATION
15743 +
15744 +struct vcmd_ctx_rlimit_v0_x32 {
15745 +       uint32_t id;
15746 +       uint64_t minimum;
15747 +       uint64_t softlimit;
15748 +       uint64_t maximum;
15749 +} __attribute__ ((aligned (4)));
15750 +
15751 +#endif /* CONFIG_IA32_EMULATION */
15752 +
15753 +#include <linux/compiler.h>
15754 +
15755 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
15756 +extern int vc_get_rlimit(struct vx_info *, void __user *);
15757 +extern int vc_set_rlimit(struct vx_info *, void __user *);
15758 +extern int vc_reset_minmax(struct vx_info *, void __user *);
15759 +
15760 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
15761 +
15762 +#ifdef CONFIG_IA32_EMULATION
15763 +
15764 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
15765 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
15766 +
15767 +#endif /* CONFIG_IA32_EMULATION */
15768 +
15769 +#endif /* __KERNEL__ */
15770 +#endif /* _VX_LIMIT_CMD_H */
15771 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/limit_def.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_def.h
15772 --- linux-2.6.22.10/include/linux/vserver/limit_def.h   1970-01-01 01:00:00 +0100
15773 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_def.h        2007-08-05 20:53:13 +0200
15774 @@ -0,0 +1,47 @@
15775 +#ifndef _VX_LIMIT_DEF_H
15776 +#define _VX_LIMIT_DEF_H
15777 +
15778 +#include <asm/atomic.h>
15779 +#include <asm/resource.h>
15780 +
15781 +#include "limit.h"
15782 +
15783 +
15784 +struct _vx_res_limit {
15785 +       rlim_t soft;            /* Context soft limit */
15786 +       rlim_t hard;            /* Context hard limit */
15787 +
15788 +       rlim_atomic_t rcur;     /* Current value */
15789 +       rlim_t rmin;            /* Context minimum */
15790 +       rlim_t rmax;            /* Context maximum */
15791 +
15792 +       atomic_t lhit;          /* Limit hits */
15793 +};
15794 +
15795 +/* context sub struct */
15796 +
15797 +struct _vx_limit {
15798 +       struct _vx_res_limit res[NUM_LIMITS];
15799 +};
15800 +
15801 +#ifdef CONFIG_VSERVER_DEBUG
15802 +
15803 +static inline void __dump_vx_limit(struct _vx_limit *limit)
15804 +{
15805 +       int i;
15806 +
15807 +       printk("\t_vx_limit:");
15808 +       for (i = 0; i < NUM_LIMITS; i++) {
15809 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
15810 +                       i, (unsigned long)__rlim_get(limit, i),
15811 +                       (unsigned long)__rlim_rmin(limit, i),
15812 +                       (unsigned long)__rlim_rmax(limit, i),
15813 +                       (long)__rlim_soft(limit, i),
15814 +                       (long)__rlim_hard(limit, i),
15815 +                       atomic_read(&__rlim_lhit(limit, i)));
15816 +       }
15817 +}
15818 +
15819 +#endif
15820 +
15821 +#endif /* _VX_LIMIT_DEF_H */
15822 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/limit_int.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_int.h
15823 --- linux-2.6.22.10/include/linux/vserver/limit_int.h   1970-01-01 01:00:00 +0100
15824 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_int.h        2007-08-05 20:53:13 +0200
15825 @@ -0,0 +1,198 @@
15826 +#ifndef _VX_LIMIT_INT_H
15827 +#define _VX_LIMIT_INT_H
15828 +
15829 +#include "context.h"
15830 +
15831 +#ifdef __KERNEL__
15832 +
15833 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
15834 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
15835 +
15836 +extern const char *vlimit_name[NUM_LIMITS];
15837 +
15838 +static inline void __vx_acc_cres(struct vx_info *vxi,
15839 +       int res, int dir, void *_data, char *_file, int _line)
15840 +{
15841 +       if (VXD_RCRES_COND(res))
15842 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
15843 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15844 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15845 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
15846 +       if (!vxi)
15847 +               return;
15848 +
15849 +       if (dir > 0)
15850 +               __rlim_inc(&vxi->limit, res);
15851 +       else
15852 +               __rlim_dec(&vxi->limit, res);
15853 +}
15854 +
15855 +static inline void __vx_add_cres(struct vx_info *vxi,
15856 +       int res, int amount, void *_data, char *_file, int _line)
15857 +{
15858 +       if (VXD_RCRES_COND(res))
15859 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
15860 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15861 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15862 +                       amount, _data, _file, _line);
15863 +       if (amount == 0)
15864 +               return;
15865 +       if (!vxi)
15866 +               return;
15867 +       __rlim_add(&vxi->limit, res, amount);
15868 +}
15869 +
15870 +static inline
15871 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
15872 +{
15873 +       int cond = (value > __rlim_rmax(limit, res));
15874 +
15875 +       if (cond)
15876 +               __rlim_rmax(limit, res) = value;
15877 +       return cond;
15878 +}
15879 +
15880 +static inline
15881 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
15882 +{
15883 +       int cond = (value < __rlim_rmin(limit, res));
15884 +
15885 +       if (cond)
15886 +               __rlim_rmin(limit, res) = value;
15887 +       return cond;
15888 +}
15889 +
15890 +static inline
15891 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
15892 +{
15893 +       if (!__vx_cres_adjust_max(limit, res, value))
15894 +               __vx_cres_adjust_min(limit, res, value);
15895 +}
15896 +
15897 +
15898 +/*     return values:
15899 +        +1 ... no limit hit
15900 +        -1 ... over soft limit
15901 +         0 ... over hard limit         */
15902 +
15903 +static inline int __vx_cres_avail(struct vx_info *vxi,
15904 +       int res, int num, char *_file, int _line)
15905 +{
15906 +       struct _vx_limit *limit;
15907 +       rlim_t value;
15908 +
15909 +       if (VXD_RLIMIT_COND(res))
15910 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
15911 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15912 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
15913 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
15914 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15915 +                       num, _file, _line);
15916 +       if (!vxi)
15917 +               return 1;
15918 +
15919 +       limit = &vxi->limit;
15920 +       value = __rlim_get(limit, res);
15921 +
15922 +       if (!__vx_cres_adjust_max(limit, res, value))
15923 +               __vx_cres_adjust_min(limit, res, value);
15924 +
15925 +       if (num == 0)
15926 +               return 1;
15927 +
15928 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
15929 +               return -1;
15930 +       if (value + num <= __rlim_soft(limit, res))
15931 +               return -1;
15932 +
15933 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
15934 +               return 1;
15935 +       if (value + num <= __rlim_hard(limit, res))
15936 +               return 1;
15937 +
15938 +       __rlim_hit(limit, res);
15939 +       return 0;
15940 +}
15941 +
15942 +
15943 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
15944 +
15945 +static inline
15946 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
15947 +{
15948 +       rlim_t value, sum = 0;
15949 +       int res;
15950 +
15951 +       while ((res = *array++)) {
15952 +               value = __rlim_get(limit, res);
15953 +               __vx_cres_fixup(limit, res, value);
15954 +               sum += value;
15955 +       }
15956 +       return sum;
15957 +}
15958 +
15959 +static inline
15960 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
15961 +{
15962 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
15963 +       int res = *array;
15964 +
15965 +       if (value == __rlim_get(limit, res))
15966 +               return value;
15967 +
15968 +       __rlim_set(limit, res, value);
15969 +       /* now adjust min/max */
15970 +       if (!__vx_cres_adjust_max(limit, res, value))
15971 +               __vx_cres_adjust_min(limit, res, value);
15972 +
15973 +       return value;
15974 +}
15975 +
15976 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
15977 +       const int *array, int num, char *_file, int _line)
15978 +{
15979 +       struct _vx_limit *limit;
15980 +       rlim_t value = 0;
15981 +       int res;
15982 +
15983 +       if (num == 0)
15984 +               return 1;
15985 +       if (!vxi)
15986 +               return 1;
15987 +
15988 +       limit = &vxi->limit;
15989 +       res = *array;
15990 +       value = __vx_cres_array_sum(limit, array + 1);
15991 +
15992 +       __rlim_set(limit, res, value);
15993 +       __vx_cres_fixup(limit, res, value);
15994 +
15995 +       return __vx_cres_avail(vxi, res, num, _file, _line);
15996 +}
15997 +
15998 +
15999 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
16000 +{
16001 +       rlim_t value;
16002 +       int res;
16003 +
16004 +       /* complex resources first */
16005 +       if ((id < 0) || (id == RLIMIT_RSS))
16006 +               __vx_cres_array_fixup(limit, VLA_RSS);
16007 +
16008 +       for (res = 0; res < NUM_LIMITS; res++) {
16009 +               if ((id > 0) && (res != id))
16010 +                       continue;
16011 +
16012 +               value = __rlim_get(limit, res);
16013 +               __vx_cres_fixup(limit, res, value);
16014 +
16015 +               /* not supposed to happen, maybe warn? */
16016 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
16017 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
16018 +       }
16019 +}
16020 +
16021 +
16022 +#endif /* __KERNEL__ */
16023 +#endif /* _VX_LIMIT_INT_H */
16024 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/monitor.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/monitor.h
16025 --- linux-2.6.22.10/include/linux/vserver/monitor.h     1970-01-01 01:00:00 +0100
16026 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/monitor.h  2007-08-15 23:16:12 +0200
16027 @@ -0,0 +1,96 @@
16028 +#ifndef _VX_MONITOR_H
16029 +#define _VX_MONITOR_H
16030 +
16031 +#include <linux/types.h>
16032 +
16033 +enum {
16034 +       VXM_UNUSED = 0,
16035 +
16036 +       VXM_SYNC = 0x10,
16037 +
16038 +       VXM_UPDATE = 0x20,
16039 +       VXM_UPDATE_1,
16040 +       VXM_UPDATE_2,
16041 +
16042 +       VXM_RQINFO_1 = 0x24,
16043 +       VXM_RQINFO_2,
16044 +
16045 +       VXM_ACTIVATE = 0x40,
16046 +       VXM_DEACTIVATE,
16047 +       VXM_IDLE,
16048 +
16049 +       VXM_HOLD = 0x44,
16050 +       VXM_UNHOLD,
16051 +
16052 +       VXM_MIGRATE = 0x48,
16053 +       VXM_RESCHED,
16054 +
16055 +       /* all other bits are flags */
16056 +       VXM_SCHED = 0x80,
16057 +};
16058 +
16059 +struct _vxm_update_1 {
16060 +       uint32_t tokens_max;
16061 +       uint32_t fill_rate;
16062 +       uint32_t interval;
16063 +};
16064 +
16065 +struct _vxm_update_2 {
16066 +       uint32_t tokens_min;
16067 +       uint32_t fill_rate;
16068 +       uint32_t interval;
16069 +};
16070 +
16071 +struct _vxm_rqinfo_1 {
16072 +       uint16_t running;
16073 +       uint16_t onhold;
16074 +       uint16_t iowait;
16075 +       uint16_t uintr;
16076 +       uint32_t idle_tokens;
16077 +};
16078 +
16079 +struct _vxm_rqinfo_2 {
16080 +       uint32_t norm_time;
16081 +       uint32_t idle_time;
16082 +       uint32_t idle_skip;
16083 +};
16084 +
16085 +struct _vxm_sched {
16086 +       uint32_t tokens;
16087 +       uint32_t norm_time;
16088 +       uint32_t idle_time;
16089 +};
16090 +
16091 +struct _vxm_task {
16092 +       uint16_t pid;
16093 +       uint16_t state;
16094 +};
16095 +
16096 +struct _vxm_event {
16097 +       uint32_t jif;
16098 +       union {
16099 +               uint32_t seq;
16100 +               uint32_t sec;
16101 +       };
16102 +       union {
16103 +               uint32_t tokens;
16104 +               uint32_t nsec;
16105 +               struct _vxm_task tsk;
16106 +       };
16107 +};
16108 +
16109 +struct _vx_mon_entry {
16110 +       uint16_t type;
16111 +       uint16_t xid;
16112 +       union {
16113 +               struct _vxm_event ev;
16114 +               struct _vxm_sched sd;
16115 +               struct _vxm_update_1 u1;
16116 +               struct _vxm_update_2 u2;
16117 +               struct _vxm_rqinfo_1 q1;
16118 +               struct _vxm_rqinfo_2 q2;
16119 +       };
16120 +};
16121 +
16122 +
16123 +#endif /* _VX_MONITOR_H */
16124 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/network.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/network.h
16125 --- linux-2.6.22.10/include/linux/vserver/network.h     1970-01-01 01:00:00 +0100
16126 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/network.h  2007-10-05 12:29:05 +0200
16127 @@ -0,0 +1,143 @@
16128 +#ifndef _VX_NETWORK_H
16129 +#define _VX_NETWORK_H
16130 +
16131 +#include <linux/types.h>
16132 +
16133 +
16134 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
16135 +
16136 +
16137 +/* network flags */
16138 +
16139 +#define NXF_INFO_PRIVATE       0x00000008
16140 +
16141 +#define NXF_SINGLE_IP          0x00000100
16142 +#define NXF_LBACK_REMAP                0x00000200
16143 +
16144 +#define NXF_HIDE_NETIF         0x02000000
16145 +#define NXF_HIDE_LBACK         0x04000000
16146 +
16147 +#define NXF_STATE_SETUP                (1ULL << 32)
16148 +#define NXF_STATE_ADMIN                (1ULL << 34)
16149 +
16150 +#define NXF_SC_HELPER          (1ULL << 36)
16151 +#define NXF_PERSISTENT         (1ULL << 38)
16152 +
16153 +#define NXF_ONE_TIME           (0x0005ULL << 32)
16154 +
16155 +
16156 +#define        NXF_INIT_SET            (__nxf_init_set())
16157 +
16158 +static inline uint64_t __nxf_init_set(void) {
16159 +       return    NXF_STATE_ADMIN
16160 +#ifdef CONFIG_VSERVER_AUTO_LBACK
16161 +               | NXF_LBACK_REMAP
16162 +               | NXF_HIDE_LBACK
16163 +#endif
16164 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
16165 +               | NXF_SINGLE_IP
16166 +#endif
16167 +               | NXF_HIDE_NETIF;
16168 +}
16169 +
16170 +
16171 +/* network caps */
16172 +
16173 +#define NXC_RAW_ICMP           0x00000100
16174 +
16175 +
16176 +/* address types */
16177 +
16178 +#define NXA_TYPE_IPV4          0x0001
16179 +#define NXA_TYPE_IPV6          0x0002
16180 +
16181 +#define NXA_TYPE_NONE          0x0000
16182 +#define NXA_TYPE_ANY           0x00FF
16183 +
16184 +#define NXA_TYPE_ADDR          0x0010
16185 +#define NXA_TYPE_MASK          0x0020
16186 +#define NXA_TYPE_RANGE         0x0040
16187 +
16188 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
16189 +
16190 +#define NXA_MOD_BCAST          0x0100
16191 +#define NXA_MOD_LBACK          0x0200
16192 +
16193 +#define NXA_LOOPBACK           0x1000
16194 +
16195 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
16196 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
16197 +
16198 +#ifdef __KERNEL__
16199 +
16200 +#include <linux/list.h>
16201 +#include <linux/spinlock.h>
16202 +#include <linux/rcupdate.h>
16203 +#include <linux/in.h>
16204 +#include <linux/in6.h>
16205 +#include <asm/atomic.h>
16206 +
16207 +struct nx_addr_v4 {
16208 +       struct nx_addr_v4 *next;
16209 +       struct in_addr ip[2];
16210 +       struct in_addr mask;
16211 +       uint16_t type;
16212 +       uint16_t flags;
16213 +};
16214 +
16215 +struct nx_addr_v6 {
16216 +       struct nx_addr_v6 *next;
16217 +       struct in6_addr ip;
16218 +       struct in6_addr mask;
16219 +       uint32_t prefix;
16220 +       uint16_t type;
16221 +       uint16_t flags;
16222 +};
16223 +
16224 +struct nx_info {
16225 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
16226 +       nid_t nx_id;                    /* vnet id */
16227 +       atomic_t nx_usecnt;             /* usage count */
16228 +       atomic_t nx_tasks;              /* tasks count */
16229 +       int nx_state;                   /* context state */
16230 +
16231 +       uint64_t nx_flags;              /* network flag word */
16232 +       uint64_t nx_ncaps;              /* network capabilities */
16233 +
16234 +       struct in_addr v4_lback;        /* Loopback address */
16235 +       struct in_addr v4_bcast;        /* Broadcast address */
16236 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
16237 +#ifdef CONFIG_IPV6
16238 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
16239 +#endif
16240 +       char nx_name[65];               /* network context name */
16241 +};
16242 +
16243 +
16244 +/* status flags */
16245 +
16246 +#define NXS_HASHED      0x0001
16247 +#define NXS_SHUTDOWN    0x0100
16248 +#define NXS_RELEASED    0x8000
16249 +
16250 +extern struct nx_info *lookup_nx_info(int);
16251 +
16252 +extern int get_nid_list(int, unsigned int *, int);
16253 +extern int nid_is_hashed(nid_t);
16254 +
16255 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
16256 +
16257 +extern long vs_net_change(struct nx_info *, unsigned int);
16258 +
16259 +struct sock;
16260 +
16261 +
16262 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
16263 +#ifdef  CONFIG_IPV6
16264 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
16265 +#else
16266 +#define NX_IPV6(n)     (0)
16267 +#endif
16268 +
16269 +#endif /* __KERNEL__ */
16270 +#endif /* _VX_NETWORK_H */
16271 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/network_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/network_cmd.h
16272 --- linux-2.6.22.10/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00 +0100
16273 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/network_cmd.h      2007-08-15 20:08:10 +0200
16274 @@ -0,0 +1,150 @@
16275 +#ifndef _VX_NETWORK_CMD_H
16276 +#define _VX_NETWORK_CMD_H
16277 +
16278 +
16279 +/* vinfo commands */
16280 +
16281 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
16282 +
16283 +#ifdef __KERNEL__
16284 +extern int vc_task_nid(uint32_t);
16285 +
16286 +#endif /* __KERNEL__ */
16287 +
16288 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
16289 +
16290 +struct vcmd_nx_info_v0 {
16291 +       uint32_t nid;
16292 +       /* more to come */
16293 +};
16294 +
16295 +#ifdef __KERNEL__
16296 +extern int vc_nx_info(struct nx_info *, void __user *);
16297 +
16298 +#endif /* __KERNEL__ */
16299 +
16300 +#include <linux/in.h>
16301 +#include <linux/in6.h>
16302 +
16303 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
16304 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
16305 +
16306 +struct  vcmd_net_create {
16307 +       uint64_t flagword;
16308 +};
16309 +
16310 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
16311 +
16312 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
16313 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
16314 +
16315 +struct vcmd_net_addr_v0 {
16316 +       uint16_t type;
16317 +       uint16_t count;
16318 +       struct in_addr ip[4];
16319 +       struct in_addr mask[4];
16320 +};
16321 +
16322 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
16323 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
16324 +
16325 +struct vcmd_net_addr_ipv4_v1 {
16326 +       uint16_t type;
16327 +       uint16_t flags;
16328 +       struct in_addr ip;
16329 +       struct in_addr mask;
16330 +};
16331 +
16332 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
16333 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
16334 +
16335 +struct vcmd_net_addr_ipv6_v1 {
16336 +       uint16_t type;
16337 +       uint16_t flags;
16338 +       uint32_t prefix;
16339 +       struct in6_addr ip;
16340 +       struct in6_addr mask;
16341 +};
16342 +
16343 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
16344 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
16345 +
16346 +struct vcmd_match_ipv4_v0 {
16347 +       uint16_t type;
16348 +       uint16_t flags;
16349 +       uint16_t parent;
16350 +       uint16_t prefix;
16351 +       struct in_addr ip;
16352 +       struct in_addr ip2;
16353 +       struct in_addr mask;
16354 +};
16355 +
16356 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
16357 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
16358 +
16359 +struct vcmd_match_ipv6_v0 {
16360 +       uint16_t type;
16361 +       uint16_t flags;
16362 +       uint16_t parent;
16363 +       uint16_t prefix;
16364 +       struct in6_addr ip;
16365 +       struct in6_addr ip2;
16366 +       struct in6_addr mask;
16367 +};
16368 +
16369 +
16370 +#ifdef __KERNEL__
16371 +extern int vc_net_create(uint32_t, void __user *);
16372 +extern int vc_net_migrate(struct nx_info *, void __user *);
16373 +
16374 +extern int vc_net_add(struct nx_info *, void __user *);
16375 +extern int vc_net_remove(struct nx_info *, void __user *);
16376 +
16377 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
16378 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
16379 +
16380 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
16381 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
16382 +
16383 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
16384 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
16385 +
16386 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
16387 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
16388 +
16389 +#endif /* __KERNEL__ */
16390 +
16391 +
16392 +/* flag commands */
16393 +
16394 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
16395 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
16396 +
16397 +struct vcmd_net_flags_v0 {
16398 +       uint64_t flagword;
16399 +       uint64_t mask;
16400 +};
16401 +
16402 +#ifdef __KERNEL__
16403 +extern int vc_get_nflags(struct nx_info *, void __user *);
16404 +extern int vc_set_nflags(struct nx_info *, void __user *);
16405 +
16406 +#endif /* __KERNEL__ */
16407 +
16408 +
16409 +/* network caps commands */
16410 +
16411 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
16412 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
16413 +
16414 +struct vcmd_net_caps_v0 {
16415 +       uint64_t ncaps;
16416 +       uint64_t cmask;
16417 +};
16418 +
16419 +#ifdef __KERNEL__
16420 +extern int vc_get_ncaps(struct nx_info *, void __user *);
16421 +extern int vc_set_ncaps(struct nx_info *, void __user *);
16422 +
16423 +#endif /* __KERNEL__ */
16424 +#endif /* _VX_CONTEXT_CMD_H */
16425 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/percpu.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/percpu.h
16426 --- linux-2.6.22.10/include/linux/vserver/percpu.h      1970-01-01 01:00:00 +0100
16427 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/percpu.h   2007-08-05 20:53:13 +0200
16428 @@ -0,0 +1,14 @@
16429 +#ifndef _VX_PERCPU_H
16430 +#define _VX_PERCPU_H
16431 +
16432 +#include "cvirt_def.h"
16433 +#include "sched_def.h"
16434 +
16435 +struct _vx_percpu {
16436 +       struct _vx_cvirt_pc cvirt;
16437 +       struct _vx_sched_pc sched;
16438 +};
16439 +
16440 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
16441 +
16442 +#endif /* _VX_PERCPU_H */
16443 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/sched.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched.h
16444 --- linux-2.6.22.10/include/linux/vserver/sched.h       1970-01-01 01:00:00 +0100
16445 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched.h    2007-08-05 20:53:13 +0200
16446 @@ -0,0 +1,26 @@
16447 +#ifndef _VX_SCHED_H
16448 +#define _VX_SCHED_H
16449 +
16450 +
16451 +#ifdef __KERNEL__
16452 +
16453 +struct timespec;
16454 +
16455 +void vx_vsi_uptime(struct timespec *, struct timespec *);
16456 +
16457 +
16458 +struct vx_info;
16459 +
16460 +void vx_update_load(struct vx_info *);
16461 +
16462 +
16463 +int vx_tokens_recalc(struct _vx_sched_pc *,
16464 +       unsigned long *, unsigned long *, int [2]);
16465 +
16466 +void vx_update_sched_param(struct _vx_sched *sched,
16467 +       struct _vx_sched_pc *sched_pc);
16468 +
16469 +#endif /* __KERNEL__ */
16470 +#else  /* _VX_SCHED_H */
16471 +#warning duplicate inclusion
16472 +#endif /* _VX_SCHED_H */
16473 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/sched_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched_cmd.h
16474 --- linux-2.6.22.10/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00 +0100
16475 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched_cmd.h        2007-08-05 20:53:13 +0200
16476 @@ -0,0 +1,108 @@
16477 +#ifndef _VX_SCHED_CMD_H
16478 +#define _VX_SCHED_CMD_H
16479 +
16480 +
16481 +/*  sched vserver commands */
16482 +
16483 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
16484 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
16485 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
16486 +
16487 +struct vcmd_set_sched_v2 {
16488 +       int32_t fill_rate;
16489 +       int32_t interval;
16490 +       int32_t tokens;
16491 +       int32_t tokens_min;
16492 +       int32_t tokens_max;
16493 +       uint64_t cpu_mask;
16494 +};
16495 +
16496 +struct vcmd_set_sched_v3 {
16497 +       uint32_t set_mask;
16498 +       int32_t fill_rate;
16499 +       int32_t interval;
16500 +       int32_t tokens;
16501 +       int32_t tokens_min;
16502 +       int32_t tokens_max;
16503 +       int32_t priority_bias;
16504 +};
16505 +
16506 +struct vcmd_set_sched_v4 {
16507 +       uint32_t set_mask;
16508 +       int32_t fill_rate;
16509 +       int32_t interval;
16510 +       int32_t tokens;
16511 +       int32_t tokens_min;
16512 +       int32_t tokens_max;
16513 +       int32_t prio_bias;
16514 +       int32_t cpu_id;
16515 +       int32_t bucket_id;
16516 +};
16517 +
16518 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
16519 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
16520 +
16521 +struct vcmd_sched_v5 {
16522 +       uint32_t mask;
16523 +       int32_t cpu_id;
16524 +       int32_t bucket_id;
16525 +       int32_t fill_rate[2];
16526 +       int32_t interval[2];
16527 +       int32_t tokens;
16528 +       int32_t tokens_min;
16529 +       int32_t tokens_max;
16530 +       int32_t prio_bias;
16531 +};
16532 +
16533 +#define VXSM_FILL_RATE         0x0001
16534 +#define VXSM_INTERVAL          0x0002
16535 +#define VXSM_FILL_RATE2                0x0004
16536 +#define VXSM_INTERVAL2         0x0008
16537 +#define VXSM_TOKENS            0x0010
16538 +#define VXSM_TOKENS_MIN                0x0020
16539 +#define VXSM_TOKENS_MAX                0x0040
16540 +#define VXSM_PRIO_BIAS         0x0100
16541 +
16542 +#define VXSM_IDLE_TIME         0x0200
16543 +#define VXSM_FORCE             0x0400
16544 +
16545 +#define        VXSM_V3_MASK            0x0173
16546 +#define        VXSM_SET_MASK           0x01FF
16547 +
16548 +#define VXSM_CPU_ID            0x1000
16549 +#define VXSM_BUCKET_ID         0x2000
16550 +
16551 +#define VXSM_MSEC              0x4000
16552 +
16553 +#define SCHED_KEEP             (-2)    /* only for v2 */
16554 +
16555 +#ifdef __KERNEL__
16556 +
16557 +#include <linux/compiler.h>
16558 +
16559 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
16560 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
16561 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
16562 +extern int vc_set_sched(struct vx_info *, void __user *);
16563 +extern int vc_get_sched(struct vx_info *, void __user *);
16564 +
16565 +#endif /* __KERNEL__ */
16566 +
16567 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
16568 +
16569 +struct vcmd_sched_info {
16570 +       int32_t cpu_id;
16571 +       int32_t bucket_id;
16572 +       uint64_t user_msec;
16573 +       uint64_t sys_msec;
16574 +       uint64_t hold_msec;
16575 +       uint32_t token_usec;
16576 +       int32_t vavavoom;
16577 +};
16578 +
16579 +#ifdef __KERNEL__
16580 +
16581 +extern int vc_sched_info(struct vx_info *, void __user *);
16582 +
16583 +#endif /* __KERNEL__ */
16584 +#endif /* _VX_SCHED_CMD_H */
16585 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/sched_def.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched_def.h
16586 --- linux-2.6.22.10/include/linux/vserver/sched_def.h   1970-01-01 01:00:00 +0100
16587 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched_def.h        2007-08-05 20:53:13 +0200
16588 @@ -0,0 +1,68 @@
16589 +#ifndef _VX_SCHED_DEF_H
16590 +#define _VX_SCHED_DEF_H
16591 +
16592 +#include <linux/spinlock.h>
16593 +#include <linux/jiffies.h>
16594 +#include <linux/cpumask.h>
16595 +#include <asm/atomic.h>
16596 +#include <asm/param.h>
16597 +
16598 +
16599 +/* context sub struct */
16600 +
16601 +struct _vx_sched {
16602 +       spinlock_t tokens_lock;         /* lock for token bucket */
16603 +
16604 +       int tokens;                     /* number of CPU tokens */
16605 +       int fill_rate[2];               /* Fill rate: add X tokens... */
16606 +       int interval[2];                /* Divisor:   per Y jiffies   */
16607 +       int tokens_min;                 /* Limit:     minimum for unhold */
16608 +       int tokens_max;                 /* Limit:     no more than N tokens */
16609 +
16610 +       int prio_bias;                  /* bias offset for priority */
16611 +
16612 +       unsigned update_mask;           /* which features should be updated */
16613 +       cpumask_t update;               /* CPUs which should update */
16614 +};
16615 +
16616 +struct _vx_sched_pc {
16617 +       int tokens;                     /* number of CPU tokens */
16618 +       int flags;                      /* bucket flags */
16619 +
16620 +       int fill_rate[2];               /* Fill rate: add X tokens... */
16621 +       int interval[2];                /* Divisor:   per Y jiffies   */
16622 +       int tokens_min;                 /* Limit:     minimum for unhold */
16623 +       int tokens_max;                 /* Limit:     no more than N tokens */
16624 +
16625 +       int prio_bias;                  /* bias offset for priority */
16626 +       int vavavoom;                   /* last calculated vavavoom */
16627 +
16628 +       unsigned long norm_time;        /* last time accounted */
16629 +       unsigned long idle_time;        /* non linear time for fair sched */
16630 +       unsigned long token_time;       /* token time for accounting */
16631 +       unsigned long onhold;           /* jiffies when put on hold */
16632 +
16633 +       uint64_t user_ticks;            /* token tick events */
16634 +       uint64_t sys_ticks;             /* token tick events */
16635 +       uint64_t hold_ticks;            /* token ticks paused */
16636 +};
16637 +
16638 +
16639 +#define VXSF_ONHOLD    0x0001
16640 +#define VXSF_IDLE_TIME 0x0100
16641 +
16642 +#ifdef CONFIG_VSERVER_DEBUG
16643 +
16644 +static inline void __dump_vx_sched(struct _vx_sched *sched)
16645 +{
16646 +       printk("\t_vx_sched:\n");
16647 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
16648 +               sched->fill_rate[0], sched->interval[0],
16649 +               sched->fill_rate[1], sched->interval[1],
16650 +               sched->tokens_min, sched->tokens_max);
16651 +       printk("\t priority = %4d\n", sched->prio_bias);
16652 +}
16653 +
16654 +#endif
16655 +
16656 +#endif /* _VX_SCHED_DEF_H */
16657 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/signal.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/signal.h
16658 --- linux-2.6.22.10/include/linux/vserver/signal.h      1970-01-01 01:00:00 +0100
16659 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/signal.h   2007-08-05 20:53:13 +0200
16660 @@ -0,0 +1,14 @@
16661 +#ifndef _VX_SIGNAL_H
16662 +#define _VX_SIGNAL_H
16663 +
16664 +
16665 +#ifdef __KERNEL__
16666 +
16667 +struct vx_info;
16668 +
16669 +int vx_info_kill(struct vx_info *, int, int);
16670 +
16671 +#endif /* __KERNEL__ */
16672 +#else  /* _VX_SIGNAL_H */
16673 +#warning duplicate inclusion
16674 +#endif /* _VX_SIGNAL_H */
16675 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/signal_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/signal_cmd.h
16676 --- linux-2.6.22.10/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00 +0100
16677 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/signal_cmd.h       2007-08-05 20:53:13 +0200
16678 @@ -0,0 +1,43 @@
16679 +#ifndef _VX_SIGNAL_CMD_H
16680 +#define _VX_SIGNAL_CMD_H
16681 +
16682 +
16683 +/*  signalling vserver commands */
16684 +
16685 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
16686 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
16687 +
16688 +struct vcmd_ctx_kill_v0 {
16689 +       int32_t pid;
16690 +       int32_t sig;
16691 +};
16692 +
16693 +struct vcmd_wait_exit_v0 {
16694 +       int32_t reboot_cmd;
16695 +       int32_t exit_code;
16696 +};
16697 +
16698 +#ifdef __KERNEL__
16699 +
16700 +extern int vc_ctx_kill(struct vx_info *, void __user *);
16701 +extern int vc_wait_exit(struct vx_info *, void __user *);
16702 +
16703 +#endif /* __KERNEL__ */
16704 +
16705 +/*  process alteration commands */
16706 +
16707 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
16708 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
16709 +
16710 +struct vcmd_pflags_v0 {
16711 +       uint32_t flagword;
16712 +       uint32_t mask;
16713 +};
16714 +
16715 +#ifdef __KERNEL__
16716 +
16717 +extern int vc_get_pflags(uint32_t pid, void __user *);
16718 +extern int vc_set_pflags(uint32_t pid, void __user *);
16719 +
16720 +#endif /* __KERNEL__ */
16721 +#endif /* _VX_SIGNAL_CMD_H */
16722 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/space.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/space.h
16723 --- linux-2.6.22.10/include/linux/vserver/space.h       1970-01-01 01:00:00 +0100
16724 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/space.h    2007-08-05 20:53:13 +0200
16725 @@ -0,0 +1,13 @@
16726 +#ifndef _VX_SPACE_H
16727 +#define _VX_SPACE_H
16728 +
16729 +
16730 +#include <linux/types.h>
16731 +
16732 +struct vx_info;
16733 +
16734 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
16735 +
16736 +#else  /* _VX_SPACE_H */
16737 +#warning duplicate inclusion
16738 +#endif /* _VX_SPACE_H */
16739 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/space_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/space_cmd.h
16740 --- linux-2.6.22.10/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00 +0100
16741 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/space_cmd.h        2007-08-05 20:53:13 +0200
16742 @@ -0,0 +1,26 @@
16743 +#ifndef _VX_SPACE_CMD_H
16744 +#define _VX_SPACE_CMD_H
16745 +
16746 +
16747 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
16748 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
16749 +
16750 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
16751 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
16752 +
16753 +#define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
16754 +
16755 +
16756 +struct vcmd_space_mask {
16757 +       uint64_t mask;
16758 +};
16759 +
16760 +
16761 +#ifdef __KERNEL__
16762 +
16763 +extern int vc_enter_space(struct vx_info *, void __user *);
16764 +extern int vc_set_space(struct vx_info *, void __user *);
16765 +extern int vc_get_space_mask(struct vx_info *, void __user *);
16766 +
16767 +#endif /* __KERNEL__ */
16768 +#endif /* _VX_SPACE_CMD_H */
16769 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/switch.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/switch.h
16770 --- linux-2.6.22.10/include/linux/vserver/switch.h      1970-01-01 01:00:00 +0100
16771 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/switch.h   2007-10-11 01:10:22 +0200
16772 @@ -0,0 +1,99 @@
16773 +#ifndef _VX_SWITCH_H
16774 +#define _VX_SWITCH_H
16775 +
16776 +#include <linux/types.h>
16777 +
16778 +
16779 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
16780 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
16781 +#define VC_VERSION(c)          ((c) & 0xFFF)
16782 +
16783 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
16784 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
16785 +
16786 +/*
16787 +
16788 +  Syscall Matrix V2.8
16789 +
16790 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
16791 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
16792 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
16793 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16794 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
16795 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
16796 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16797 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
16798 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
16799 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16800 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
16801 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
16802 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16803 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
16804 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
16805 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16806 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
16807 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
16808 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16809 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
16810 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
16811 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
16812 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
16813 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
16814 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16815 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
16816 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
16817 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16818 +
16819 +*/
16820 +
16821 +#define VC_CAT_VERSION         0
16822 +
16823 +#define VC_CAT_VSETUP          1
16824 +#define VC_CAT_VHOST           2
16825 +
16826 +#define VC_CAT_DEVICE          6
16827 +
16828 +#define VC_CAT_VPROC           9
16829 +#define VC_CAT_PROCALT         10
16830 +#define VC_CAT_PROCMIG         11
16831 +#define VC_CAT_PROCTRL         12
16832 +
16833 +#define VC_CAT_SCHED           14
16834 +#define VC_CAT_MEMCTRL         20
16835 +
16836 +#define VC_CAT_VNET            25
16837 +#define VC_CAT_NETALT          26
16838 +#define VC_CAT_NETMIG          27
16839 +#define VC_CAT_NETCTRL         28
16840 +
16841 +#define VC_CAT_TAGMIG          35
16842 +#define VC_CAT_DLIMIT          36
16843 +#define VC_CAT_INODE           38
16844 +
16845 +#define VC_CAT_VSTAT           40
16846 +#define VC_CAT_VINFO           46
16847 +#define VC_CAT_EVENT           48
16848 +
16849 +#define VC_CAT_FLAGS           52
16850 +#define VC_CAT_DEBUG           56
16851 +#define VC_CAT_RLIMIT          60
16852 +
16853 +#define VC_CAT_SYSTEST         61
16854 +#define VC_CAT_COMPAT          63
16855 +
16856 +/*  query version */
16857 +
16858 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
16859 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
16860 +
16861 +
16862 +#ifdef __KERNEL__
16863 +
16864 +#include <linux/errno.h>
16865 +
16866 +
16867 +#else  /* __KERNEL__ */
16868 +#define __user
16869 +#endif /* __KERNEL__ */
16870 +
16871 +#endif /* _VX_SWITCH_H */
16872 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/tag.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/tag.h
16873 --- linux-2.6.22.10/include/linux/vserver/tag.h 1970-01-01 01:00:00 +0100
16874 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/tag.h      2007-10-10 19:05:04 +0200
16875 @@ -0,0 +1,143 @@
16876 +#ifndef _DX_TAG_H
16877 +#define _DX_TAG_H
16878 +
16879 +#include <linux/types.h>
16880 +
16881 +
16882 +#define DX_TAG(in)     (IS_TAGGED(in))
16883 +
16884 +
16885 +#ifdef CONFIG_DX_TAG_NFSD
16886 +#define DX_TAG_NFSD    1
16887 +#else
16888 +#define DX_TAG_NFSD    0
16889 +#endif
16890 +
16891 +
16892 +#ifdef CONFIG_TAGGING_NONE
16893 +
16894 +#define MAX_UID                0xFFFFFFFF
16895 +#define MAX_GID                0xFFFFFFFF
16896 +
16897 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
16898 +
16899 +#define TAGINO_UID(cond, uid, tag)     (uid)
16900 +#define TAGINO_GID(cond, gid, tag)     (gid)
16901 +
16902 +#endif
16903 +
16904 +
16905 +#ifdef CONFIG_TAGGING_GID16
16906 +
16907 +#define MAX_UID                0xFFFFFFFF
16908 +#define MAX_GID                0x0000FFFF
16909 +
16910 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16911 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
16912 +
16913 +#define TAGINO_UID(cond, uid, tag)     (uid)
16914 +#define TAGINO_GID(cond, gid, tag)     \
16915 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
16916 +
16917 +#endif
16918 +
16919 +
16920 +#ifdef CONFIG_TAGGING_ID24
16921 +
16922 +#define MAX_UID                0x00FFFFFF
16923 +#define MAX_GID                0x00FFFFFF
16924 +
16925 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16926 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
16927 +
16928 +#define TAGINO_UID(cond, uid, tag)     \
16929 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
16930 +#define TAGINO_GID(cond, gid, tag)     \
16931 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
16932 +
16933 +#endif
16934 +
16935 +
16936 +#ifdef CONFIG_TAGGING_UID16
16937 +
16938 +#define MAX_UID                0x0000FFFF
16939 +#define MAX_GID                0xFFFFFFFF
16940 +
16941 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16942 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
16943 +
16944 +#define TAGINO_UID(cond, uid, tag)     \
16945 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
16946 +#define TAGINO_GID(cond, gid, tag)     (gid)
16947 +
16948 +#endif
16949 +
16950 +
16951 +#ifdef CONFIG_TAGGING_INTERN
16952 +
16953 +#define MAX_UID                0xFFFFFFFF
16954 +#define MAX_GID                0xFFFFFFFF
16955 +
16956 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16957 +       ((cond) ? (tag) : 0)
16958 +
16959 +#define TAGINO_UID(cond, uid, tag)     (uid)
16960 +#define TAGINO_GID(cond, gid, tag)     (gid)
16961 +
16962 +#endif
16963 +
16964 +
16965 +#ifndef CONFIG_TAGGING_NONE
16966 +#define dx_current_fstag(sb)   \
16967 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
16968 +#else
16969 +#define dx_current_fstag(sb)   (0)
16970 +#endif
16971 +
16972 +#ifndef CONFIG_TAGGING_INTERN
16973 +#define TAGINO_TAG(cond, tag)  (0)
16974 +#else
16975 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
16976 +#endif
16977 +
16978 +#define INOTAG_UID(cond, uid, gid)     \
16979 +       ((cond) ? ((uid) & MAX_UID) : (uid))
16980 +#define INOTAG_GID(cond, uid, gid)     \
16981 +       ((cond) ? ((gid) & MAX_GID) : (gid))
16982 +
16983 +
16984 +static inline uid_t dx_map_uid(uid_t uid)
16985 +{
16986 +       if ((uid > MAX_UID) && (uid != -1))
16987 +               uid = -2;
16988 +       return (uid & MAX_UID);
16989 +}
16990 +
16991 +static inline gid_t dx_map_gid(gid_t gid)
16992 +{
16993 +       if ((gid > MAX_GID) && (gid != -1))
16994 +               gid = -2;
16995 +       return (gid & MAX_GID);
16996 +}
16997 +
16998 +struct peer_tag {
16999 +       int32_t xid;
17000 +       int32_t nid;
17001 +};
17002 +
17003 +#define dx_notagcheck(nd) \
17004 +       ((nd) && (nd)->mnt && ((nd)->mnt->mnt_flags & MNT_NOTAGCHECK))
17005 +
17006 +int dx_parse_tag(char *string, tag_t *tag, int remove);
17007 +
17008 +#ifdef CONFIG_PROPAGATE
17009 +
17010 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
17011 +
17012 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
17013 +
17014 +#else
17015 +#define dx_propagate_tag(n, i) do { } while (0)
17016 +#endif
17017 +
17018 +#endif /* _DX_TAG_H */
17019 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/tag_cmd.h linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/tag_cmd.h
17020 --- linux-2.6.22.10/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00 +0100
17021 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/tag_cmd.h  2007-08-15 20:16:43 +0200
17022 @@ -0,0 +1,22 @@
17023 +#ifndef _VX_TAG_CMD_H
17024 +#define _VX_TAG_CMD_H
17025 +
17026 +
17027 +/* vinfo commands */
17028 +
17029 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
17030 +
17031 +#ifdef __KERNEL__
17032 +extern int vc_task_tag(uint32_t);
17033 +
17034 +#endif /* __KERNEL__ */
17035 +
17036 +/* context commands */
17037 +
17038 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
17039 +
17040 +#ifdef __KERNEL__
17041 +extern int vc_tag_migrate(uint32_t);
17042 +
17043 +#endif /* __KERNEL__ */
17044 +#endif /* _VX_TAG_CMD_H */
17045 diff -NurpP --minimal linux-2.6.22.10/include/net/addrconf.h linux-2.6.22.10-vs2.3.0.29/include/net/addrconf.h
17046 --- linux-2.6.22.10/include/net/addrconf.h      2007-07-09 13:20:01 +0200
17047 +++ linux-2.6.22.10-vs2.3.0.29/include/net/addrconf.h   2007-08-12 00:22:19 +0200
17048 @@ -69,10 +69,12 @@ extern struct inet6_ifaddr *        ipv6_get_if
17049                                                 int strict);
17050  extern int                     ipv6_get_saddr(struct dst_entry *dst, 
17051                                                struct in6_addr *daddr,
17052 -                                              struct in6_addr *saddr);
17053 +                                              struct in6_addr *saddr,
17054 +                                              struct nx_info *nxi);
17055  extern int                     ipv6_dev_get_saddr(struct net_device *dev, 
17056                                                struct in6_addr *daddr,
17057 -                                              struct in6_addr *saddr);
17058 +                                              struct in6_addr *saddr,
17059 +                                              struct nx_info *nxi);
17060  extern int                     ipv6_get_lladdr(struct net_device *dev,
17061                                                 struct in6_addr *addr,
17062                                                 unsigned char banned_flags);
17063 diff -NurpP --minimal linux-2.6.22.10/include/net/af_unix.h linux-2.6.22.10-vs2.3.0.29/include/net/af_unix.h
17064 --- linux-2.6.22.10/include/net/af_unix.h       2007-07-09 13:20:01 +0200
17065 +++ linux-2.6.22.10-vs2.3.0.29/include/net/af_unix.h    2007-08-05 20:53:13 +0200
17066 @@ -4,6 +4,7 @@
17067  #include <linux/socket.h>
17068  #include <linux/un.h>
17069  #include <linux/mutex.h>
17070 +#include <linux/vs_base.h>
17071  #include <net/sock.h>
17072  
17073  extern void unix_inflight(struct file *fp);
17074 @@ -17,9 +18,9 @@ extern spinlock_t unix_table_lock;
17075  
17076  extern atomic_t unix_tot_inflight;
17077  
17078 -static inline struct sock *first_unix_socket(int *i)
17079 +static inline struct sock *next_unix_socket_table(int *i)
17080  {
17081 -       for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
17082 +       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17083                 if (!hlist_empty(&unix_socket_table[*i]))
17084                         return __sk_head(&unix_socket_table[*i]);
17085         }
17086 @@ -28,16 +29,19 @@ static inline struct sock *first_unix_so
17087  
17088  static inline struct sock *next_unix_socket(int *i, struct sock *s)
17089  {
17090 -       struct sock *next = sk_next(s);
17091 -       /* More in this chain? */
17092 -       if (next)
17093 -               return next;
17094 -       /* Look for next non-empty chain. */
17095 -       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17096 -               if (!hlist_empty(&unix_socket_table[*i]))
17097 -                       return __sk_head(&unix_socket_table[*i]);
17098 -       }
17099 -       return NULL;
17100 +       do {
17101 +               if (s)
17102 +                       s = sk_next(s);
17103 +               if (!s)
17104 +                       s = next_unix_socket_table(i);
17105 +       } while (s && !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT));
17106 +       return s;
17107 +}
17108 +
17109 +static inline struct sock *first_unix_socket(int *i)
17110 +{
17111 +       *i = 0;
17112 +       return next_unix_socket(i, NULL);
17113  }
17114  
17115  #define forall_unix_sockets(i, s) \
17116 diff -NurpP --minimal linux-2.6.22.10/include/net/inet_timewait_sock.h linux-2.6.22.10-vs2.3.0.29/include/net/inet_timewait_sock.h
17117 --- linux-2.6.22.10/include/net/inet_timewait_sock.h    2007-05-02 19:25:35 +0200
17118 +++ linux-2.6.22.10-vs2.3.0.29/include/net/inet_timewait_sock.h 2007-08-05 20:53:13 +0200
17119 @@ -115,6 +115,10 @@ struct inet_timewait_sock {
17120  #define tw_refcnt              __tw_common.skc_refcnt
17121  #define tw_hash                        __tw_common.skc_hash
17122  #define tw_prot                        __tw_common.skc_prot
17123 +#define tw_xid         __tw_common.skc_xid
17124 +#define tw_vx_info             __tw_common.skc_vx_info
17125 +#define tw_nid         __tw_common.skc_nid
17126 +#define tw_nx_info             __tw_common.skc_nx_info
17127         volatile unsigned char  tw_substate;
17128         /* 3 bits hole, try to pack */
17129         unsigned char           tw_rcv_wscale;
17130 diff -NurpP --minimal linux-2.6.22.10/include/net/route.h linux-2.6.22.10-vs2.3.0.29/include/net/route.h
17131 --- linux-2.6.22.10/include/net/route.h 2007-05-02 19:25:35 +0200
17132 +++ linux-2.6.22.10-vs2.3.0.29/include/net/route.h      2007-09-18 03:52:05 +0200
17133 @@ -27,12 +27,16 @@
17134  #include <net/dst.h>
17135  #include <net/inetpeer.h>
17136  #include <net/flow.h>
17137 +#include <net/inet_sock.h>
17138  #include <linux/in_route.h>
17139  #include <linux/rtnetlink.h>
17140  #include <linux/route.h>
17141  #include <linux/ip.h>
17142  #include <linux/cache.h>
17143  #include <linux/security.h>
17144 +#include <linux/vs_base.h>
17145 +#include <linux/vs_inet.h>
17146 +#include <linux/in.h>
17147  
17148  #ifndef __KERNEL__
17149  #warning This file is not supposed to be used outside of kernel.
17150 @@ -143,6 +147,8 @@ static inline char rt_tos2priority(u8 to
17151         return ip_tos2prio[IPTOS_TOS(tos)>>1];
17152  }
17153  
17154 +extern int ip_v4_find_src(struct nx_info *, struct rtable **, struct flowi *);
17155 +
17156  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
17157                                    __be32 src, u32 tos, int oif, u8 protocol,
17158                                    __be16 sport, __be16 dport, struct sock *sk,
17159 @@ -158,7 +164,21 @@ static inline int ip_route_connect(struc
17160                                          .dport = dport } } };
17161  
17162         int err;
17163 -       if (!dst || !src) {
17164 +       struct nx_info *nx_info = current->nx_info;
17165 +
17166 +       if (sk)
17167 +               nx_info = sk->sk_nx_info;
17168 +
17169 +       vxdprintk(VXD_CBIT(net, 4),
17170 +               "ip_route_connect(%p) %p,%p;%lx",
17171 +               sk, nx_info, sk->sk_socket,
17172 +               (sk->sk_socket?sk->sk_socket->flags:0));
17173 +
17174 +       err = ip_v4_find_src(nx_info, rp, &fl);
17175 +       if (err)
17176 +               return err;
17177 +
17178 +       if (!fl.fl4_dst || !fl.fl4_src) {
17179                 err = __ip_route_output_key(rp, &fl);
17180                 if (err)
17181                         return err;
17182 diff -NurpP --minimal linux-2.6.22.10/include/net/sock.h linux-2.6.22.10-vs2.3.0.29/include/net/sock.h
17183 --- linux-2.6.22.10/include/net/sock.h  2007-07-09 13:20:02 +0200
17184 +++ linux-2.6.22.10-vs2.3.0.29/include/net/sock.h       2007-08-05 20:53:13 +0200
17185 @@ -119,6 +119,10 @@ struct sock_common {
17186         atomic_t                skc_refcnt;
17187         unsigned int            skc_hash;
17188         struct proto            *skc_prot;
17189 +       xid_t                   skc_xid;
17190 +       struct vx_info          *skc_vx_info;
17191 +       nid_t                   skc_nid;
17192 +       struct nx_info          *skc_nx_info;
17193  };
17194  
17195  /**
17196 @@ -195,6 +199,10 @@ struct sock {
17197  #define sk_refcnt              __sk_common.skc_refcnt
17198  #define sk_hash                        __sk_common.skc_hash
17199  #define sk_prot                        __sk_common.skc_prot
17200 +#define sk_xid                 __sk_common.skc_xid
17201 +#define sk_vx_info             __sk_common.skc_vx_info
17202 +#define sk_nid                 __sk_common.skc_nid
17203 +#define sk_nx_info             __sk_common.skc_nx_info
17204         unsigned char           sk_shutdown : 2,
17205                                 sk_no_check : 2,
17206                                 sk_userlocks : 4;
17207 diff -NurpP --minimal linux-2.6.22.10/init/main.c linux-2.6.22.10-vs2.3.0.29/init/main.c
17208 --- linux-2.6.22.10/init/main.c 2007-07-09 13:20:03 +0200
17209 +++ linux-2.6.22.10-vs2.3.0.29/init/main.c      2007-08-05 20:53:13 +0200
17210 @@ -55,6 +55,7 @@
17211  #include <linux/pid_namespace.h>
17212  #include <linux/device.h>
17213  #include <linux/kthread.h>
17214 +#include <linux/vserver/percpu.h>
17215  
17216  #include <asm/io.h>
17217  #include <asm/bugs.h>
17218 @@ -364,12 +365,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
17219  
17220  static void __init setup_per_cpu_areas(void)
17221  {
17222 -       unsigned long size, i;
17223 +       unsigned long size, vspc, i;
17224         char *ptr;
17225         unsigned long nr_possible_cpus = num_possible_cpus();
17226  
17227 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
17228 +
17229         /* Copy section for each CPU (we discard the original) */
17230 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
17231 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
17232         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
17233  
17234         for_each_possible_cpu(i) {
17235 diff -NurpP --minimal linux-2.6.22.10/ipc/mqueue.c linux-2.6.22.10-vs2.3.0.29/ipc/mqueue.c
17236 --- linux-2.6.22.10/ipc/mqueue.c        2007-07-09 13:20:03 +0200
17237 +++ linux-2.6.22.10-vs2.3.0.29/ipc/mqueue.c     2007-10-01 14:57:41 +0200
17238 @@ -29,6 +29,8 @@
17239  #include <linux/audit.h>
17240  #include <linux/signal.h>
17241  #include <linux/mutex.h>
17242 +#include <linux/vs_context.h>
17243 +#include <linux/vs_limit.h>
17244  
17245  #include <net/sock.h>
17246  #include "util.h"
17247 @@ -151,17 +153,20 @@ static struct inode *mqueue_get_inode(st
17248                         spin_lock(&mq_lock);
17249                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
17250                             u->mq_bytes + mq_bytes >
17251 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
17252 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
17253 +                           !vx_ipcmsg_avail(p->vx_info, mq_bytes)) {
17254                                 spin_unlock(&mq_lock);
17255                                 goto out_inode;
17256                         }
17257                         u->mq_bytes += mq_bytes;
17258 +                       vx_ipcmsg_add(p->vx_info, u, mq_bytes);
17259                         spin_unlock(&mq_lock);
17260  
17261                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
17262                         if (!info->messages) {
17263                                 spin_lock(&mq_lock);
17264                                 u->mq_bytes -= mq_bytes;
17265 +                               vx_ipcmsg_sub(p->vx_info, u, mq_bytes);
17266                                 spin_unlock(&mq_lock);
17267                                 goto out_inode;
17268                         }
17269 @@ -257,10 +262,14 @@ static void mqueue_delete_inode(struct i
17270                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
17271         user = info->user;
17272         if (user) {
17273 +               struct vx_info *vxi = lookup_vx_info(user->xid);
17274 +
17275                 spin_lock(&mq_lock);
17276                 user->mq_bytes -= mq_bytes;
17277 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
17278                 queues_count--;
17279                 spin_unlock(&mq_lock);
17280 +               put_vx_info(vxi);
17281                 free_uid(user);
17282         }
17283  }
17284 @@ -748,7 +757,7 @@ asmlinkage long sys_mq_unlink(const char
17285         if (inode)
17286                 atomic_inc(&inode->i_count);
17287  
17288 -       err = vfs_unlink(dentry->d_parent->d_inode, dentry);
17289 +       err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
17290  out_err:
17291         dput(dentry);
17292  
17293 diff -NurpP --minimal linux-2.6.22.10/ipc/msg.c linux-2.6.22.10-vs2.3.0.29/ipc/msg.c
17294 --- linux-2.6.22.10/ipc/msg.c   2007-02-06 03:01:55 +0100
17295 +++ linux-2.6.22.10-vs2.3.0.29/ipc/msg.c        2007-08-05 20:53:13 +0200
17296 @@ -36,6 +36,7 @@
17297  #include <linux/seq_file.h>
17298  #include <linux/mutex.h>
17299  #include <linux/nsproxy.h>
17300 +#include <linux/vs_base.h>
17301  
17302  #include <asm/current.h>
17303  #include <asm/uaccess.h>
17304 @@ -149,6 +150,7 @@ static int newque (struct ipc_namespace 
17305  
17306         msq->q_perm.mode = msgflg & S_IRWXUGO;
17307         msq->q_perm.key = key;
17308 +       msq->q_perm.xid = vx_current_xid();
17309  
17310         msq->q_perm.security = NULL;
17311         retval = security_msg_queue_alloc(msq);
17312 diff -NurpP --minimal linux-2.6.22.10/ipc/sem.c linux-2.6.22.10-vs2.3.0.29/ipc/sem.c
17313 --- linux-2.6.22.10/ipc/sem.c   2007-07-09 13:20:03 +0200
17314 +++ linux-2.6.22.10-vs2.3.0.29/ipc/sem.c        2007-08-05 20:53:13 +0200
17315 @@ -82,6 +82,8 @@
17316  #include <linux/seq_file.h>
17317  #include <linux/mutex.h>
17318  #include <linux/nsproxy.h>
17319 +#include <linux/vs_base.h>
17320 +#include <linux/vs_limit.h>
17321  
17322  #include <asm/uaccess.h>
17323  #include "util.h"
17324 @@ -229,6 +231,7 @@ static int newary (struct ipc_namespace 
17325  
17326         sma->sem_perm.mode = (semflg & S_IRWXUGO);
17327         sma->sem_perm.key = key;
17328 +       sma->sem_perm.xid = vx_current_xid();
17329  
17330         sma->sem_perm.security = NULL;
17331         retval = security_sem_alloc(sma);
17332 @@ -244,6 +247,9 @@ static int newary (struct ipc_namespace 
17333                 return -ENOSPC;
17334         }
17335         ns->used_sems += nsems;
17336 +       /* FIXME: obsoleted? */
17337 +       vx_semary_inc(sma);
17338 +       vx_nsems_add(sma, nsems);
17339  
17340         sma->sem_id = sem_buildid(ns, id, sma->sem_perm.seq);
17341         sma->sem_base = (struct sem *) &sma[1];
17342 @@ -525,6 +531,9 @@ static void freeary (struct ipc_namespac
17343         sem_unlock(sma);
17344  
17345         ns->used_sems -= sma->sem_nsems;
17346 +       /* FIXME: obsoleted? */
17347 +       vx_nsems_sub(sma, sma->sem_nsems);
17348 +       vx_semary_dec(sma);
17349         size = sizeof (*sma) + sma->sem_nsems * sizeof (struct sem);
17350         security_sem_free(sma);
17351         ipc_rcu_putref(sma);
17352 diff -NurpP --minimal linux-2.6.22.10/ipc/shm.c linux-2.6.22.10-vs2.3.0.29/ipc/shm.c
17353 --- linux-2.6.22.10/ipc/shm.c   2007-10-30 01:57:14 +0100
17354 +++ linux-2.6.22.10-vs2.3.0.29/ipc/shm.c        2007-10-01 14:57:41 +0200
17355 @@ -38,6 +38,8 @@
17356  #include <linux/mutex.h>
17357  #include <linux/nsproxy.h>
17358  #include <linux/mount.h>
17359 +#include <linux/vs_context.h>
17360 +#include <linux/vs_limit.h>
17361  
17362  #include <asm/uaccess.h>
17363  
17364 @@ -185,7 +187,12 @@ static void shm_open(struct vm_area_stru
17365   */
17366  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
17367  {
17368 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17369 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
17370 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17371 +
17372 +       vx_ipcshm_sub(vxi, shp, numpages);
17373 +       ns->shm_tot -= numpages;
17374 +
17375         shm_rmid(ns, shp->id);
17376         shm_unlock(shp);
17377         if (!is_file_hugepages(shp->shm_file))
17378 @@ -195,6 +202,7 @@ static void shm_destroy(struct ipc_names
17379                                                 shp->mlock_user);
17380         fput (shp->shm_file);
17381         security_shm_free(shp);
17382 +       put_vx_info(vxi);
17383         ipc_rcu_putref(shp);
17384  }
17385  
17386 @@ -351,11 +359,15 @@ static int newseg (struct ipc_namespace 
17387         if (ns->shm_tot + numpages > ns->shm_ctlall)
17388                 return -ENOSPC;
17389  
17390 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
17391 +               return -ENOSPC;
17392 +
17393         shp = ipc_rcu_alloc(sizeof(*shp));
17394         if (!shp)
17395                 return -ENOMEM;
17396  
17397         shp->shm_perm.key = key;
17398 +       shp->shm_perm.xid = vx_current_xid();
17399         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
17400         shp->mlock_user = NULL;
17401  
17402 @@ -406,6 +418,7 @@ static int newseg (struct ipc_namespace 
17403         file->f_dentry->d_inode->i_ino = shp->id;
17404  
17405         ns->shm_tot += numpages;
17406 +       vx_ipcshm_add(current->vx_info, key, numpages);
17407         shm_unlock(shp);
17408         return shp->id;
17409  
17410 diff -NurpP --minimal linux-2.6.22.10/ipc/util.c linux-2.6.22.10-vs2.3.0.29/ipc/util.c
17411 --- linux-2.6.22.10/ipc/util.c  2007-07-09 13:20:03 +0200
17412 +++ linux-2.6.22.10-vs2.3.0.29/ipc/util.c       2007-08-05 20:53:13 +0200
17413 @@ -32,6 +32,8 @@
17414  #include <linux/proc_fs.h>
17415  #include <linux/audit.h>
17416  #include <linux/nsproxy.h>
17417 +#include <linux/vs_base.h>
17418 +#include <linux/vserver/global.h>
17419  
17420  #include <asm/unistd.h>
17421  
17422 @@ -72,6 +74,7 @@ static struct ipc_namespace *clone_ipc_n
17423                 goto err_shm;
17424  
17425         kref_init(&ns->kref);
17426 +       atomic_inc(&vs_global_ipc_ns);
17427         return ns;
17428  
17429  err_shm:
17430 @@ -108,6 +111,7 @@ void free_ipc_ns(struct kref *kref)
17431         sem_exit_ns(ns);
17432         msg_exit_ns(ns);
17433         shm_exit_ns(ns);
17434 +       atomic_dec(&vs_global_ipc_ns);
17435         kfree(ns);
17436  }
17437  #else
17438 diff -NurpP --minimal linux-2.6.22.10/kernel/Makefile linux-2.6.22.10-vs2.3.0.29/kernel/Makefile
17439 --- linux-2.6.22.10/kernel/Makefile     2007-07-09 13:20:03 +0200
17440 +++ linux-2.6.22.10-vs2.3.0.29/kernel/Makefile  2007-08-05 20:53:13 +0200
17441 @@ -10,6 +10,8 @@ obj-y     = sched.o fork.o exec_domain.o
17442             kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
17443             hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o
17444  
17445 +obj-y    += vserver/
17446 +
17447  obj-$(CONFIG_STACKTRACE) += stacktrace.o
17448  obj-y += time/
17449  obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
17450 diff -NurpP --minimal linux-2.6.22.10/kernel/capability.c linux-2.6.22.10-vs2.3.0.29/kernel/capability.c
17451 --- linux-2.6.22.10/kernel/capability.c 2007-05-02 19:25:37 +0200
17452 +++ linux-2.6.22.10-vs2.3.0.29/kernel/capability.c      2007-08-05 20:53:13 +0200
17453 @@ -12,6 +12,7 @@
17454  #include <linux/module.h>
17455  #include <linux/security.h>
17456  #include <linux/syscalls.h>
17457 +#include <linux/vs_context.h>
17458  #include <asm/uaccess.h>
17459  
17460  unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
17461 @@ -103,6 +104,8 @@ static inline int cap_set_pg(int pgrp_nr
17462  
17463         pgrp = find_pid(pgrp_nr);
17464         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
17465 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
17466 +                       continue;
17467                 target = g;
17468                 while_each_thread(g, target) {
17469                         if (!security_capset_check(target, effective,
17470 @@ -246,8 +249,12 @@ int __capable(struct task_struct *t, int
17471  }
17472  EXPORT_SYMBOL(__capable);
17473  
17474 +#include <linux/vserver/base.h>
17475  int capable(int cap)
17476  {
17477 +       /* here for now so we don't require task locking */
17478 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
17479 +               return 0;
17480         return __capable(current, cap);
17481  }
17482  EXPORT_SYMBOL(capable);
17483 diff -NurpP --minimal linux-2.6.22.10/kernel/compat.c linux-2.6.22.10-vs2.3.0.29/kernel/compat.c
17484 --- linux-2.6.22.10/kernel/compat.c     2007-07-09 13:20:03 +0200
17485 +++ linux-2.6.22.10-vs2.3.0.29/kernel/compat.c  2007-08-05 20:53:13 +0200
17486 @@ -846,7 +846,7 @@ asmlinkage long compat_sys_time(compat_t
17487         compat_time_t i;
17488         struct timeval tv;
17489  
17490 -       do_gettimeofday(&tv);
17491 +       vx_gettimeofday(&tv);
17492         i = tv.tv_sec;
17493  
17494         if (tloc) {
17495 @@ -870,7 +870,7 @@ asmlinkage long compat_sys_stime(compat_
17496         if (err)
17497                 return err;
17498  
17499 -       do_settimeofday(&tv);
17500 +       vx_settimeofday(&tv);
17501         return 0;
17502  }
17503  
17504 diff -NurpP --minimal linux-2.6.22.10/kernel/exit.c linux-2.6.22.10-vs2.3.0.29/kernel/exit.c
17505 --- linux-2.6.22.10/kernel/exit.c       2007-07-09 13:20:03 +0200
17506 +++ linux-2.6.22.10-vs2.3.0.29/kernel/exit.c    2007-10-01 18:31:46 +0200
17507 @@ -44,6 +44,11 @@
17508  #include <linux/resource.h>
17509  #include <linux/blkdev.h>
17510  #include <linux/task_io_accounting_ops.h>
17511 +#include <linux/vs_limit.h>
17512 +#include <linux/vs_context.h>
17513 +#include <linux/vs_network.h>
17514 +#include <linux/vs_pid.h>
17515 +#include <linux/vserver/global.h>
17516  
17517  #include <asm/uaccess.h>
17518  #include <asm/unistd.h>
17519 @@ -443,9 +448,11 @@ static void close_files(struct files_str
17520                                         filp_close(file, files);
17521                                         cond_resched();
17522                                 }
17523 +                               vx_openfd_dec(i);
17524                         }
17525                         i++;
17526                         set >>= 1;
17527 +                       cond_resched();
17528                 }
17529         }
17530  }
17531 @@ -525,6 +532,7 @@ static inline void __put_fs_struct(struc
17532                         dput(fs->altroot);
17533                         mntput(fs->altrootmnt);
17534                 }
17535 +               atomic_dec(&vs_global_fs);
17536                 kmem_cache_free(fs_cachep, fs);
17537         }
17538  }
17539 @@ -596,6 +604,14 @@ static void exit_mm(struct task_struct *
17540  static inline void
17541  choose_new_parent(struct task_struct *p, struct task_struct *reaper)
17542  {
17543 +       /* check for reaper context */
17544 +       vxwprintk((p->xid != reaper->xid) && (reaper != child_reaper(p)),
17545 +               "rogue reaper: %p[%d,#%u] <> %p[%d,#%u]",
17546 +               p, p->pid, p->xid, reaper, reaper->pid, reaper->xid);
17547 +
17548 +       if (p == reaper)
17549 +               reaper = vx_child_reaper(p);
17550 +
17551         /*
17552          * Make sure we're not reparenting to ourselves and that
17553          * the parent is not a zombie.
17554 @@ -687,7 +703,7 @@ forget_original_parent(struct task_struc
17555         do {
17556                 reaper = next_thread(reaper);
17557                 if (reaper == father) {
17558 -                       reaper = child_reaper(father);
17559 +                       reaper = vx_child_reaper(father);
17560                         break;
17561                 }
17562         } while (reaper->exit_state);
17563 @@ -964,6 +980,8 @@ fastcall NORET_TYPE void do_exit(long co
17564         tsk->exit_code = code;
17565         proc_exit_connector(tsk);
17566         exit_task_namespaces(tsk);
17567 +       /* needs to stay before exit_notify() */
17568 +       exit_vx_info_early(tsk, code);
17569         exit_notify(tsk);
17570  #ifdef CONFIG_NUMA
17571         mpol_free(tsk->mempolicy);
17572 @@ -994,6 +1012,10 @@ fastcall NORET_TYPE void do_exit(long co
17573         if (tsk->splice_pipe)
17574                 __free_pipe_info(tsk->splice_pipe);
17575  
17576 +       /* needs to stay after exit_notify() */
17577 +       exit_vx_info(tsk, code);
17578 +       exit_nx_info(tsk);
17579 +
17580         preempt_disable();
17581         /* causes final put_task_struct in finish_task_switch(). */
17582         tsk->state = TASK_DEAD;
17583 diff -NurpP --minimal linux-2.6.22.10/kernel/fork.c linux-2.6.22.10-vs2.3.0.29/kernel/fork.c
17584 --- linux-2.6.22.10/kernel/fork.c       2007-07-09 13:20:03 +0200
17585 +++ linux-2.6.22.10-vs2.3.0.29/kernel/fork.c    2007-10-25 17:05:55 +0200
17586 @@ -49,6 +49,11 @@
17587  #include <linux/delayacct.h>
17588  #include <linux/taskstats_kern.h>
17589  #include <linux/random.h>
17590 +#include <linux/vs_context.h>
17591 +#include <linux/vs_network.h>
17592 +#include <linux/vs_limit.h>
17593 +#include <linux/vs_memory.h>
17594 +#include <linux/vserver/global.h>
17595  
17596  #include <asm/pgtable.h>
17597  #include <asm/pgalloc.h>
17598 @@ -108,6 +113,8 @@ void free_task(struct task_struct *tsk)
17599  {
17600         free_thread_info(tsk->stack);
17601         rt_mutex_debug_task_free(tsk);
17602 +       clr_vx_info(&tsk->vx_info);
17603 +       clr_nx_info(&tsk->nx_info);
17604         free_task_struct(tsk);
17605  }
17606  EXPORT_SYMBOL(free_task);
17607 @@ -215,6 +222,8 @@ static inline int dup_mmap(struct mm_str
17608         mm->free_area_cache = oldmm->mmap_base;
17609         mm->cached_hole_size = ~0UL;
17610         mm->map_count = 0;
17611 +       __set_mm_counter(mm, file_rss, 0);
17612 +       __set_mm_counter(mm, anon_rss, 0);
17613         cpus_clear(mm->cpu_vm_mask);
17614         mm->mm_rb = RB_ROOT;
17615         rb_link = &mm->mm_rb.rb_node;
17616 @@ -226,7 +235,7 @@ static inline int dup_mmap(struct mm_str
17617  
17618                 if (mpnt->vm_flags & VM_DONTCOPY) {
17619                         long pages = vma_pages(mpnt);
17620 -                       mm->total_vm -= pages;
17621 +                       vx_vmpages_sub(mm, pages);
17622                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
17623                                                                 -pages);
17624                         continue;
17625 @@ -327,7 +336,7 @@ static inline void mm_free_pgd(struct mm
17626  
17627  #include <linux/init_task.h>
17628  
17629 -static struct mm_struct * mm_init(struct mm_struct * mm)
17630 +static struct mm_struct * mm_init(struct mm_struct * mm, struct vx_info *vxi)
17631  {
17632         atomic_set(&mm->mm_users, 1);
17633         atomic_set(&mm->mm_count, 1);
17634 @@ -335,8 +344,8 @@ static struct mm_struct * mm_init(struct
17635         INIT_LIST_HEAD(&mm->mmlist);
17636         mm->core_waiters = 0;
17637         mm->nr_ptes = 0;
17638 -       set_mm_counter(mm, file_rss, 0);
17639 -       set_mm_counter(mm, anon_rss, 0);
17640 +       __set_mm_counter(mm, file_rss, 0);
17641 +       __set_mm_counter(mm, anon_rss, 0);
17642         spin_lock_init(&mm->page_table_lock);
17643         rwlock_init(&mm->ioctx_list_lock);
17644         mm->ioctx_list = NULL;
17645 @@ -345,6 +354,7 @@ static struct mm_struct * mm_init(struct
17646  
17647         if (likely(!mm_alloc_pgd(mm))) {
17648                 mm->def_flags = 0;
17649 +               set_vx_info(&mm->mm_vx_info, vxi);
17650                 return mm;
17651         }
17652         free_mm(mm);
17653 @@ -361,7 +371,7 @@ struct mm_struct * mm_alloc(void)
17654         mm = allocate_mm();
17655         if (mm) {
17656                 memset(mm, 0, sizeof(*mm));
17657 -               mm = mm_init(mm);
17658 +               mm = mm_init(mm, current->vx_info);
17659         }
17660         return mm;
17661  }
17662 @@ -376,6 +386,7 @@ void fastcall __mmdrop(struct mm_struct 
17663         BUG_ON(mm == &init_mm);
17664         mm_free_pgd(mm);
17665         destroy_context(mm);
17666 +       clr_vx_info(&mm->mm_vx_info);
17667         free_mm(mm);
17668  }
17669  
17670 @@ -490,12 +501,13 @@ static struct mm_struct *dup_mm(struct t
17671                 goto fail_nomem;
17672  
17673         memcpy(mm, oldmm, sizeof(*mm));
17674 +       mm->mm_vx_info = NULL;
17675  
17676         /* Initializing for Swap token stuff */
17677         mm->token_priority = 0;
17678         mm->last_interval = 0;
17679  
17680 -       if (!mm_init(mm))
17681 +       if (!mm_init(mm, oldmm->mm_vx_info))
17682                 goto fail_nomem;
17683  
17684         if (init_new_context(tsk, mm))
17685 @@ -521,6 +533,7 @@ fail_nocontext:
17686          * If init_new_context() failed, we cannot use mmput() to free the mm
17687          * because it calls destroy_context()
17688          */
17689 +       clr_vx_info(&mm->mm_vx_info);
17690         mm_free_pgd(mm);
17691         free_mm(mm);
17692         return NULL;
17693 @@ -591,6 +604,7 @@ static inline struct fs_struct *__copy_f
17694                         fs->altroot = NULL;
17695                 }
17696                 read_unlock(&old->lock);
17697 +               atomic_inc(&vs_global_fs);
17698         }
17699         return fs;
17700  }
17701 @@ -709,6 +723,8 @@ static struct files_struct *dup_fd(struc
17702                 struct file *f = *old_fds++;
17703                 if (f) {
17704                         get_file(f);
17705 +                       /* TODO: sum it first for check and performance */
17706 +                       vx_openfd_inc(open_files - i);
17707                 } else {
17708                         /*
17709                          * The fd may be claimed in the fd bitmap but not yet
17710 @@ -961,6 +977,8 @@ static struct task_struct *copy_process(
17711  {
17712         int retval;
17713         struct task_struct *p = NULL;
17714 +       struct vx_info *vxi;
17715 +       struct nx_info *nxi;
17716  
17717         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
17718                 return ERR_PTR(-EINVAL);
17719 @@ -995,12 +1013,30 @@ static struct task_struct *copy_process(
17720         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
17721         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
17722  #endif
17723 +       init_vx_info(&p->vx_info, current->vx_info);
17724 +       init_nx_info(&p->nx_info, current->nx_info);
17725 +
17726 +       /* check vserver memory */
17727 +       if (p->mm && !(clone_flags & CLONE_VM)) {
17728 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
17729 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17730 +               else
17731 +                       goto bad_fork_free;
17732 +       }
17733 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
17734 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
17735 +                       goto bad_fork_cleanup_vm;
17736 +       }
17737 +
17738         retval = -EAGAIN;
17739 +       if (!vx_nproc_avail(1))
17740 +               goto bad_fork_cleanup_vm;
17741 +
17742         if (atomic_read(&p->user->processes) >=
17743                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
17744                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
17745                                 p->user != &root_user)
17746 -                       goto bad_fork_free;
17747 +                       goto bad_fork_cleanup_vm;
17748         }
17749  
17750         atomic_inc(&p->user->__count);
17751 @@ -1265,6 +1301,18 @@ static struct task_struct *copy_process(
17752  
17753         total_forks++;
17754         spin_unlock(&current->sighand->siglock);
17755 +
17756 +       /* p is copy of current */
17757 +       vxi = p->vx_info;
17758 +       if (vxi) {
17759 +               claim_vx_info(vxi, p);
17760 +               atomic_inc(&vxi->cvirt.nr_threads);
17761 +               atomic_inc(&vxi->cvirt.total_forks);
17762 +               vx_nproc_inc(p);
17763 +       }
17764 +       nxi = p->nx_info;
17765 +       if (nxi)
17766 +               claim_nx_info(nxi, p);
17767         write_unlock_irq(&tasklist_lock);
17768         proc_fork_connector(p);
17769         return p;
17770 @@ -1306,6 +1354,9 @@ bad_fork_cleanup_count:
17771         put_group_info(p->group_info);
17772         atomic_dec(&p->user->processes);
17773         free_uid(p->user);
17774 +bad_fork_cleanup_vm:
17775 +       if (p->mm && !(clone_flags & CLONE_VM))
17776 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17777  bad_fork_free:
17778         free_task(p);
17779  fork_out:
17780 @@ -1367,6 +1418,15 @@ long do_fork(unsigned long clone_flags,
17781  
17782         if (!pid)
17783                 return -EAGAIN;
17784 +
17785 +       /* kernel threads are host only */
17786 +       if ((clone_flags & CLONE_KTHREAD) &&
17787 +               !vx_capable(CAP_SYS_ADMIN, VXC_KTHREAD)) {
17788 +               vxwprintk_task(1, "tried to spawn a kernel thread.");
17789 +               free_pid(pid);
17790 +               return -EPERM;
17791 +       }
17792 +
17793         nr = pid->nr;
17794         if (unlikely(current->ptrace)) {
17795                 trace = fork_traceflag (clone_flags);
17796 diff -NurpP --minimal linux-2.6.22.10/kernel/kthread.c linux-2.6.22.10-vs2.3.0.29/kernel/kthread.c
17797 --- linux-2.6.22.10/kernel/kthread.c    2007-07-09 13:20:03 +0200
17798 +++ linux-2.6.22.10-vs2.3.0.29/kernel/kthread.c 2007-08-05 20:53:13 +0200
17799 @@ -96,7 +96,7 @@ static void create_kthread(struct kthrea
17800         } else {
17801                 wait_for_completion(&create->started);
17802                 read_lock(&tasklist_lock);
17803 -               create->result = find_task_by_pid(pid);
17804 +               create->result = find_task_by_real_pid(pid);
17805                 read_unlock(&tasklist_lock);
17806         }
17807         complete(&create->done);
17808 diff -NurpP --minimal linux-2.6.22.10/kernel/nsproxy.c linux-2.6.22.10-vs2.3.0.29/kernel/nsproxy.c
17809 --- linux-2.6.22.10/kernel/nsproxy.c    2007-07-09 13:20:03 +0200
17810 +++ linux-2.6.22.10-vs2.3.0.29/kernel/nsproxy.c 2007-08-05 20:53:13 +0200
17811 @@ -20,14 +20,11 @@
17812  #include <linux/mnt_namespace.h>
17813  #include <linux/utsname.h>
17814  #include <linux/pid_namespace.h>
17815 +#include <linux/vserver/global.h>
17816 +#include <linux/vserver/debug.h>
17817  
17818  struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
17819  
17820 -static inline void get_nsproxy(struct nsproxy *ns)
17821 -{
17822 -       atomic_inc(&ns->count);
17823 -}
17824 -
17825  void get_task_namespaces(struct task_struct *tsk)
17826  {
17827         struct nsproxy *ns = tsk->nsproxy;
17828 @@ -46,6 +43,9 @@ static inline struct nsproxy *clone_nspr
17829         ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
17830         if (ns)
17831                 atomic_set(&ns->count, 1);
17832 +       vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
17833 +               orig, atomic_read(&orig->count), ns);
17834 +       atomic_inc(&vs_global_nsproxy);
17835         return ns;
17836  }
17837  
17838 @@ -54,28 +54,32 @@ static inline struct nsproxy *clone_nspr
17839   * Return the newly created nsproxy.  Do not attach this to the task,
17840   * leave it to the caller to do proper locking and attach it to task.
17841   */
17842 -static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17843 +static struct nsproxy *unshare_namespaces(int flags, struct nsproxy *orig,
17844                         struct fs_struct *new_fs)
17845  {
17846         struct nsproxy *new_nsp;
17847  
17848 -       new_nsp = clone_nsproxy(tsk->nsproxy);
17849 +       vxdprintk(VXD_CBIT(space, 4),
17850 +               "unshare_namespaces(0x%08x,%p,%p)",
17851 +               flags, orig, new_fs);
17852 +
17853 +       new_nsp = clone_nsproxy(orig);
17854         if (!new_nsp)
17855                 return ERR_PTR(-ENOMEM);
17856  
17857 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
17858 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
17859         if (IS_ERR(new_nsp->mnt_ns))
17860                 goto out_ns;
17861  
17862 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
17863 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
17864         if (IS_ERR(new_nsp->uts_ns))
17865                 goto out_uts;
17866  
17867 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
17868 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
17869         if (IS_ERR(new_nsp->ipc_ns))
17870                 goto out_ipc;
17871  
17872 -       new_nsp->pid_ns = copy_pid_ns(flags, tsk->nsproxy->pid_ns);
17873 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
17874         if (IS_ERR(new_nsp->pid_ns))
17875                 goto out_pid;
17876  
17877 @@ -95,6 +99,33 @@ out_ns:
17878         return ERR_PTR(-ENOMEM);
17879  }
17880  
17881 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17882 +                       struct fs_struct *new_fs)
17883 +{
17884 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
17885 +}
17886 +
17887 +/*
17888 + * copies the nsproxy, setting refcount to 1, and grabbing a
17889 + * reference to all contained namespaces.
17890 + */
17891 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
17892 +{
17893 +       struct nsproxy *ns = clone_nsproxy(orig);
17894 +
17895 +       if (ns) {
17896 +               if (ns->mnt_ns)
17897 +                       get_mnt_ns(ns->mnt_ns);
17898 +               if (ns->uts_ns)
17899 +                       get_uts_ns(ns->uts_ns);
17900 +               if (ns->ipc_ns)
17901 +                       get_ipc_ns(ns->ipc_ns);
17902 +               if (ns->pid_ns)
17903 +                       get_pid_ns(ns->pid_ns);
17904 +       }
17905 +       return ns;
17906 +}
17907 +
17908  /*
17909   * called from clone.  This now handles copy for nsproxy and all
17910   * namespaces therein.
17911 @@ -102,9 +133,12 @@ out_ns:
17912  int copy_namespaces(int flags, struct task_struct *tsk)
17913  {
17914         struct nsproxy *old_ns = tsk->nsproxy;
17915 -       struct nsproxy *new_ns;
17916 +       struct nsproxy *new_ns = NULL;
17917         int err = 0;
17918  
17919 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08x,%p[%p])",
17920 +               flags, tsk, old_ns);
17921 +
17922         if (!old_ns)
17923                 return 0;
17924  
17925 @@ -127,6 +161,9 @@ int copy_namespaces(int flags, struct ta
17926         tsk->nsproxy = new_ns;
17927  out:
17928         put_nsproxy(old_ns);
17929 +       vxdprintk(VXD_CBIT(space, 3),
17930 +               "copy_namespaces(0x%08x,%p[%p]) = %d [%p]",
17931 +               flags, tsk, old_ns, err, new_ns);
17932         return err;
17933  }
17934  
17935 @@ -140,6 +177,7 @@ void free_nsproxy(struct nsproxy *ns)
17936                 put_ipc_ns(ns->ipc_ns);
17937         if (ns->pid_ns)
17938                 put_pid_ns(ns->pid_ns);
17939 +       atomic_dec(&vs_global_nsproxy);
17940         kfree(ns);
17941  }
17942  
17943 @@ -152,6 +190,10 @@ int unshare_nsproxy_namespaces(unsigned 
17944  {
17945         int err = 0;
17946  
17947 +       vxdprintk(VXD_CBIT(space, 4),
17948 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
17949 +               unshare_flags, current->nsproxy);
17950 +
17951         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC)))
17952                 return 0;
17953  
17954 diff -NurpP --minimal linux-2.6.22.10/kernel/pid.c linux-2.6.22.10-vs2.3.0.29/kernel/pid.c
17955 --- linux-2.6.22.10/kernel/pid.c        2007-07-09 13:20:03 +0200
17956 +++ linux-2.6.22.10-vs2.3.0.29/kernel/pid.c     2007-08-05 20:53:13 +0200
17957 @@ -28,6 +28,7 @@
17958  #include <linux/hash.h>
17959  #include <linux/pid_namespace.h>
17960  #include <linux/init_task.h>
17961 +#include <linux/vs_pid.h>
17962  
17963  #define pid_hashfn(nr) hash_long((unsigned long)nr, pidhash_shift)
17964  static struct hlist_head *pid_hash;
17965 @@ -295,6 +296,9 @@ void fastcall transfer_pid(struct task_s
17966  struct task_struct * fastcall pid_task(struct pid *pid, enum pid_type type)
17967  {
17968         struct task_struct *result = NULL;
17969 +
17970 +       if (type == PIDTYPE_REALPID)
17971 +               type = PIDTYPE_PID;
17972         if (pid) {
17973                 struct hlist_node *first;
17974                 first = rcu_dereference(pid->tasks[type].first);
17975 @@ -309,7 +313,17 @@ struct task_struct * fastcall pid_task(s
17976   */
17977  struct task_struct *find_task_by_pid_type(int type, int nr)
17978  {
17979 -       return pid_task(find_pid(nr), type);
17980 +       struct task_struct *task;
17981 +
17982 +       if (type == PIDTYPE_PID)
17983 +               nr = vx_rmap_pid(nr);
17984 +
17985 +       task = pid_task(find_pid(nr), type);
17986 +       if (task && (type != PIDTYPE_REALPID) &&
17987 +               /* maybe VS_WATCH_P in the future? */
17988 +               !vx_check(task->xid, VS_WATCH|VS_IDENT))
17989 +               return NULL;
17990 +       return task;
17991  }
17992  
17993  EXPORT_SYMBOL(find_task_by_pid_type);
17994 diff -NurpP --minimal linux-2.6.22.10/kernel/posix-timers.c linux-2.6.22.10-vs2.3.0.29/kernel/posix-timers.c
17995 --- linux-2.6.22.10/kernel/posix-timers.c       2007-07-09 13:20:03 +0200
17996 +++ linux-2.6.22.10-vs2.3.0.29/kernel/posix-timers.c    2007-10-01 15:41:45 +0200
17997 @@ -47,6 +47,7 @@
17998  #include <linux/wait.h>
17999  #include <linux/workqueue.h>
18000  #include <linux/module.h>
18001 +#include <linux/vs_context.h>
18002  
18003  /*
18004   * Management arrays for POSIX timers.  Timers are kept in slab memory
18005 @@ -297,6 +298,12 @@ void do_schedule_next_timer(struct sigin
18006  
18007  int posix_timer_event(struct k_itimer *timr,int si_private)
18008  {
18009 +       struct vx_info_save vxis;
18010 +       struct vx_info *vxi;
18011 +       int ret;
18012 +
18013 +       vxi = task_get_vx_info(timr->it_process);
18014 +       enter_vx_info(vxi, &vxis);
18015         memset(&timr->sigq->info, 0, sizeof(siginfo_t));
18016         timr->sigq->info.si_sys_private = si_private;
18017         /* Send signal to the process that owns this timer.*/
18018 @@ -309,11 +316,11 @@ int posix_timer_event(struct k_itimer *t
18019  
18020         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
18021                 struct task_struct *leader;
18022 -               int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
18023 -                                       timr->it_process);
18024  
18025 +               ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
18026 +                                   timr->it_process);
18027                 if (likely(ret >= 0))
18028 -                       return ret;
18029 +                       goto out;
18030  
18031                 timr->it_sigev_notify = SIGEV_SIGNAL;
18032                 leader = timr->it_process->group_leader;
18033 @@ -321,8 +328,12 @@ int posix_timer_event(struct k_itimer *t
18034                 timr->it_process = leader;
18035         }
18036  
18037 -       return send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
18038 +       ret = send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
18039                                    timr->it_process);
18040 +out:
18041 +       leave_vx_info(&vxis);
18042 +       put_vx_info(vxi);
18043 +       return ret;
18044  }
18045  EXPORT_SYMBOL_GPL(posix_timer_event);
18046  
18047 @@ -402,7 +413,7 @@ static struct task_struct * good_sigeven
18048         struct task_struct *rtn = current->group_leader;
18049  
18050         if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
18051 -               (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
18052 +               (!(rtn = find_task_by_real_pid(event->sigev_notify_thread_id)) ||
18053                  rtn->tgid != current->tgid ||
18054                  (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
18055                 return NULL;
18056 diff -NurpP --minimal linux-2.6.22.10/kernel/printk.c linux-2.6.22.10-vs2.3.0.29/kernel/printk.c
18057 --- linux-2.6.22.10/kernel/printk.c     2007-07-09 13:20:03 +0200
18058 +++ linux-2.6.22.10-vs2.3.0.29/kernel/printk.c  2007-08-05 20:53:13 +0200
18059 @@ -31,6 +31,7 @@
18060  #include <linux/bootmem.h>
18061  #include <linux/syscalls.h>
18062  #include <linux/jiffies.h>
18063 +#include <linux/vs_cvirt.h>
18064  
18065  #include <asm/uaccess.h>
18066  
18067 @@ -182,18 +183,13 @@ int do_syslog(int type, char __user *buf
18068         unsigned long i, j, limit, count;
18069         int do_clear = 0;
18070         char c;
18071 -       int error = 0;
18072 +       int error;
18073  
18074         error = security_syslog(type);
18075         if (error)
18076                 return error;
18077  
18078 -       switch (type) {
18079 -       case 0:         /* Close log */
18080 -               break;
18081 -       case 1:         /* Open log */
18082 -               break;
18083 -       case 2:         /* Read from log */
18084 +       if ((type >= 2) && (type <= 4)) {
18085                 error = -EINVAL;
18086                 if (!buf || len < 0)
18087                         goto out;
18088 @@ -204,6 +200,16 @@ int do_syslog(int type, char __user *buf
18089                         error = -EFAULT;
18090                         goto out;
18091                 }
18092 +       }
18093 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
18094 +               return vx_do_syslog(type, buf, len);
18095 +
18096 +       switch (type) {
18097 +       case 0:         /* Close log */
18098 +               break;
18099 +       case 1:         /* Open log */
18100 +               break;
18101 +       case 2:         /* Read from log */
18102                 error = wait_event_interruptible(log_wait,
18103                                                         (log_start - log_end));
18104                 if (error)
18105 @@ -228,16 +234,6 @@ int do_syslog(int type, char __user *buf
18106                 do_clear = 1;
18107                 /* FALL THRU */
18108         case 3:         /* Read last kernel messages */
18109 -               error = -EINVAL;
18110 -               if (!buf || len < 0)
18111 -                       goto out;
18112 -               error = 0;
18113 -               if (!len)
18114 -                       goto out;
18115 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
18116 -                       error = -EFAULT;
18117 -                       goto out;
18118 -               }
18119                 count = len;
18120                 if (count > log_buf_len)
18121                         count = log_buf_len;
18122 diff -NurpP --minimal linux-2.6.22.10/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/kernel/ptrace.c
18123 --- linux-2.6.22.10/kernel/ptrace.c     2007-07-09 13:20:03 +0200
18124 +++ linux-2.6.22.10-vs2.3.0.29/kernel/ptrace.c  2007-08-05 20:53:13 +0200
18125 @@ -19,6 +19,7 @@
18126  #include <linux/security.h>
18127  #include <linux/signal.h>
18128  #include <linux/audit.h>
18129 +#include <linux/vs_context.h>
18130  
18131  #include <asm/pgtable.h>
18132  #include <asm/uaccess.h>
18133 @@ -145,6 +146,11 @@ static int may_attach(struct task_struct
18134                 dumpable = task->mm->dumpable;
18135         if (!dumpable && !capable(CAP_SYS_PTRACE))
18136                 return -EPERM;
18137 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
18138 +               return -EPERM;
18139 +       if (!vx_check(task->xid, VS_IDENT) &&
18140 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
18141 +               return -EACCES;
18142  
18143         return security_ptrace(current, task);
18144  }
18145 @@ -471,6 +477,10 @@ asmlinkage long sys_ptrace(long request,
18146                 goto out;
18147         }
18148  
18149 +       ret = -EPERM;
18150 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
18151 +               goto out_put_task_struct;
18152 +
18153         if (request == PTRACE_ATTACH) {
18154                 ret = ptrace_attach(child);
18155                 goto out_put_task_struct;
18156 diff -NurpP --minimal linux-2.6.22.10/kernel/sched.c linux-2.6.22.10-vs2.3.0.29/kernel/sched.c
18157 --- linux-2.6.22.10/kernel/sched.c      2007-07-09 13:20:03 +0200
18158 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched.c   2007-08-05 20:53:13 +0200
18159 @@ -56,6 +56,8 @@
18160  
18161  #include <asm/tlb.h>
18162  #include <asm/unistd.h>
18163 +#include <linux/vs_sched.h>
18164 +#include <linux/vs_cvirt.h>
18165  
18166  /*
18167   * Scheduler clock - returns current time in nanosec units.
18168 @@ -281,6 +283,16 @@ struct rq {
18169         struct task_struct *migration_thread;
18170         struct list_head migration_queue;
18171  #endif
18172 +       unsigned long norm_time;
18173 +       unsigned long idle_time;
18174 +#ifdef CONFIG_VSERVER_IDLETIME
18175 +       int idle_skip;
18176 +#endif
18177 +#ifdef CONFIG_VSERVER_HARDCPU
18178 +       struct list_head hold_queue;
18179 +       unsigned long nr_onhold;
18180 +       int idle_tokens;
18181 +#endif
18182  
18183  #ifdef CONFIG_SCHEDSTATS
18184         /* latency stats */
18185 @@ -714,6 +726,7 @@ sched_info_switch(struct task_struct *pr
18186   */
18187  static void dequeue_task(struct task_struct *p, struct prio_array *array)
18188  {
18189 +       BUG_ON(p->state & TASK_ONHOLD);
18190         array->nr_active--;
18191         list_del(&p->run_list);
18192         if (list_empty(array->queue + p->prio))
18193 @@ -722,6 +735,7 @@ static void dequeue_task(struct task_str
18194  
18195  static void enqueue_task(struct task_struct *p, struct prio_array *array)
18196  {
18197 +       BUG_ON(p->state & TASK_ONHOLD);
18198         sched_info_queued(p);
18199         list_add_tail(&p->run_list, array->queue + p->prio);
18200         __set_bit(p->prio, array->bitmap);
18201 @@ -735,12 +749,14 @@ static void enqueue_task(struct task_str
18202   */
18203  static void requeue_task(struct task_struct *p, struct prio_array *array)
18204  {
18205 +       BUG_ON(p->state & TASK_ONHOLD);
18206         list_move_tail(&p->run_list, array->queue + p->prio);
18207  }
18208  
18209  static inline void
18210  enqueue_task_head(struct task_struct *p, struct prio_array *array)
18211  {
18212 +       BUG_ON(p->state & TASK_ONHOLD);
18213         list_add(&p->run_list, array->queue + p->prio);
18214         __set_bit(p->prio, array->bitmap);
18215         array->nr_active++;
18216 @@ -769,6 +785,10 @@ static inline int __normal_prio(struct t
18217         bonus = CURRENT_BONUS(p) - MAX_BONUS / 2;
18218  
18219         prio = p->static_prio - bonus;
18220 +
18221 +       /* adjust effective priority */
18222 +       prio = vx_adjust_prio(p, prio, MAX_USER_PRIO);
18223 +
18224         if (prio < MAX_RT_PRIO)
18225                 prio = MAX_RT_PRIO;
18226         if (prio > MAX_PRIO-1)
18227 @@ -878,6 +898,9 @@ static int effective_prio(struct task_st
18228         return p->prio;
18229  }
18230  
18231 +#include "sched_mon.h"
18232 +
18233 +
18234  /*
18235   * __activate_task - move a task to the runqueue.
18236   */
18237 @@ -887,6 +910,7 @@ static void __activate_task(struct task_
18238  
18239         if (batch_task(p))
18240                 target = rq->expired;
18241 +       vxm_activate_task(p, rq);
18242         enqueue_task(p, target);
18243         inc_nr_running(p, rq);
18244  }
18245 @@ -896,6 +920,7 @@ static void __activate_task(struct task_
18246   */
18247  static inline void __activate_idle_task(struct task_struct *p, struct rq *rq)
18248  {
18249 +       vxm_activate_idle(p, rq);
18250         enqueue_task_head(p, rq->active);
18251         inc_nr_running(p, rq);
18252  }
18253 @@ -1030,19 +1055,30 @@ static void activate_task(struct task_st
18254         }
18255         p->timestamp = now;
18256  out:
18257 +       vx_activate_task(p);
18258         __activate_task(p, rq);
18259  }
18260  
18261  /*
18262 - * deactivate_task - remove a task from the runqueue.
18263 + * __deactivate_task - remove a task from the runqueue.
18264   */
18265 -static void deactivate_task(struct task_struct *p, struct rq *rq)
18266 +static void __deactivate_task(struct task_struct *p, struct rq *rq)
18267  {
18268         dec_nr_running(p, rq);
18269         dequeue_task(p, p->array);
18270 +       vxm_deactivate_task(p, rq);
18271         p->array = NULL;
18272  }
18273  
18274 +static inline
18275 +void deactivate_task(struct task_struct *p, struct rq *rq)
18276 +{
18277 +       vx_deactivate_task(p);
18278 +       __deactivate_task(p, rq);
18279 +}
18280 +
18281 +#include "sched_hard.h"
18282 +
18283  /*
18284   * resched_task - mark a task 'to be rescheduled now'.
18285   *
18286 @@ -1129,6 +1165,7 @@ migrate_task(struct task_struct *p, int 
18287  {
18288         struct rq *rq = task_rq(p);
18289  
18290 +       vxm_migrate_task(p, rq, dest_cpu);
18291         /*
18292          * If the task is not on a runqueue (and not running), then
18293          * it is sufficient to simply update the task's cpu field.
18294 @@ -1518,6 +1555,12 @@ static int try_to_wake_up(struct task_st
18295  
18296         rq = task_rq_lock(p, &flags);
18297         old_state = p->state;
18298 +
18299 +       /* we need to unhold suspended tasks */
18300 +       if (old_state & TASK_ONHOLD) {
18301 +               vx_unhold_task(p, rq);
18302 +               old_state = p->state;
18303 +       }
18304         if (!(old_state & state))
18305                 goto out;
18306  
18307 @@ -1625,6 +1668,7 @@ out_activate:
18308  #endif /* CONFIG_SMP */
18309         if (old_state == TASK_UNINTERRUPTIBLE) {
18310                 rq->nr_uninterruptible--;
18311 +               vx_uninterruptible_dec(p);
18312                 /*
18313                  * Tasks on involuntary sleep don't earn
18314                  * sleep_avg beyond just interactive state.
18315 @@ -1676,7 +1720,7 @@ int fastcall wake_up_state(struct task_s
18316         return try_to_wake_up(p, state, 0);
18317  }
18318  
18319 -static void task_running_tick(struct rq *rq, struct task_struct *p);
18320 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu);
18321  /*
18322   * Perform scheduler related setup for a newly forked process p.
18323   * p is forked by current.
18324 @@ -1737,7 +1781,7 @@ void fastcall sched_fork(struct task_str
18325                  * runqueue lock is not a problem.
18326                  */
18327                 current->time_slice = 1;
18328 -               task_running_tick(cpu_rq(cpu), current);
18329 +               task_running_tick(cpu_rq(cpu), current, cpu);
18330         }
18331         local_irq_enable();
18332         put_cpu();
18333 @@ -1772,6 +1816,7 @@ void fastcall wake_up_new_task(struct ta
18334  
18335         p->prio = effective_prio(p);
18336  
18337 +       vx_activate_task(p);
18338         if (likely(cpu == this_cpu)) {
18339                 if (!(clone_flags & CLONE_VM)) {
18340                         /*
18341 @@ -1783,6 +1828,7 @@ void fastcall wake_up_new_task(struct ta
18342                                 __activate_task(p, rq);
18343                         else {
18344                                 p->prio = current->prio;
18345 +                               BUG_ON(p->state & TASK_ONHOLD);
18346                                 p->normal_prio = current->normal_prio;
18347                                 list_add_tail(&p->run_list, &current->run_list);
18348                                 p->array = current->array;
18349 @@ -3351,13 +3397,16 @@ static inline int expired_starving(struc
18350  void account_user_time(struct task_struct *p, cputime_t cputime)
18351  {
18352         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18353 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18354         cputime64_t tmp;
18355 +       int nice = (TASK_NICE(p) > 0);
18356  
18357         p->utime = cputime_add(p->utime, cputime);
18358 +       vx_account_user(vxi, cputime, nice);
18359  
18360         /* Add user time to cpustat. */
18361         tmp = cputime_to_cputime64(cputime);
18362 -       if (TASK_NICE(p) > 0)
18363 +       if (nice)
18364                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
18365         else
18366                 cpustat->user = cputime64_add(cpustat->user, tmp);
18367 @@ -3373,10 +3422,12 @@ void account_system_time(struct task_str
18368                          cputime_t cputime)
18369  {
18370         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18371 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18372         struct rq *rq = this_rq();
18373         cputime64_t tmp;
18374  
18375         p->stime = cputime_add(p->stime, cputime);
18376 +       vx_account_system(vxi, cputime, (p == rq->idle));
18377  
18378         /* Add system time to cpustat. */
18379         tmp = cputime_to_cputime64(cputime);
18380 @@ -3415,7 +3466,7 @@ void account_steal_time(struct task_stru
18381                 cpustat->steal = cputime64_add(cpustat->steal, tmp);
18382  }
18383  
18384 -static void task_running_tick(struct rq *rq, struct task_struct *p)
18385 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu)
18386  {
18387         if (p->array != rq->active) {
18388                 /* Task has expired but was not scheduled yet */
18389 @@ -3445,7 +3496,7 @@ static void task_running_tick(struct rq 
18390                 }
18391                 goto out_unlock;
18392         }
18393 -       if (!--p->time_slice) {
18394 +       if (vx_need_resched(p, --p->time_slice, cpu)) {
18395                 dequeue_task(p, rq->active);
18396                 set_tsk_need_resched(p);
18397                 p->prio = effective_prio(p);
18398 @@ -3506,9 +3557,12 @@ void scheduler_tick(void)
18399         struct rq *rq = cpu_rq(cpu);
18400  
18401         update_cpu_clock(p, rq, now);
18402 +       vxm_sync(now, cpu);
18403  
18404 -       if (!idle_at_tick)
18405 -               task_running_tick(rq, p);
18406 +       if (idle_at_tick)
18407 +               vx_idle_resched(rq);
18408 +       else
18409 +               task_running_tick(rq, p, cpu);
18410  #ifdef CONFIG_SMP
18411         update_load(rq);
18412         rq->idle_at_tick = idle_at_tick;
18413 @@ -3630,14 +3684,25 @@ need_resched_nonpreemptible:
18414                                 unlikely(signal_pending(prev))))
18415                         prev->state = TASK_RUNNING;
18416                 else {
18417 -                       if (prev->state == TASK_UNINTERRUPTIBLE)
18418 +                       if (prev->state == TASK_UNINTERRUPTIBLE) {
18419                                 rq->nr_uninterruptible++;
18420 +                               vx_uninterruptible_inc(prev);
18421 +                       }
18422                         deactivate_task(prev, rq);
18423                 }
18424         }
18425  
18426         cpu = smp_processor_id();
18427 +       vx_set_rq_time(rq, jiffies);
18428 +try_unhold:
18429 +       vx_try_unhold(rq, cpu);
18430 +pick_next:
18431 +
18432         if (unlikely(!rq->nr_running)) {
18433 +               /* can we skip idle time? */
18434 +               if (vx_try_skip(rq, cpu))
18435 +                       goto try_unhold;
18436 +
18437                 idle_balance(cpu, rq);
18438                 if (!rq->nr_running) {
18439                         next = rq->idle;
18440 @@ -3663,6 +3728,10 @@ need_resched_nonpreemptible:
18441         queue = array->queue + idx;
18442         next = list_entry(queue->next, struct task_struct, run_list);
18443  
18444 +       /* check before we schedule this context */
18445 +       if (!vx_schedule(next, rq, cpu))
18446 +               goto pick_next;
18447 +
18448         if (!rt_task(next) && interactive_sleep(next->sleep_type)) {
18449                 unsigned long long delta = now - next->timestamp;
18450                 if (unlikely((long long)(now - next->timestamp) < 0))
18451 @@ -4263,7 +4332,7 @@ asmlinkage long sys_nice(int increment)
18452                 nice = 19;
18453  
18454         if (increment < 0 && !can_nice(current, nice))
18455 -               return -EPERM;
18456 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
18457  
18458         retval = security_task_setnice(current, nice);
18459         if (retval)
18460 @@ -4435,6 +4504,7 @@ recheck:
18461         oldprio = p->prio;
18462         __setscheduler(p, policy, param->sched_priority);
18463         if (array) {
18464 +               vx_activate_task(p);
18465                 __activate_task(p, rq);
18466                 /*
18467                  * Reschedule if we are currently running on this runqueue and
18468 @@ -5188,6 +5258,7 @@ static int __migrate_task(struct task_st
18469                 p->timestamp = p->timestamp - rq_src->most_recent_timestamp
18470                                 + rq_dest->most_recent_timestamp;
18471                 deactivate_task(p, rq_src);
18472 +               vx_activate_task(p);
18473                 __activate_task(p, rq_dest);
18474                 if (TASK_PREEMPTS_CURR(p, rq_dest))
18475                         resched_task(rq_dest->curr);
18476 @@ -7058,7 +7129,10 @@ void __init sched_init(void)
18477                 INIT_LIST_HEAD(&rq->migration_queue);
18478  #endif
18479                 atomic_set(&rq->nr_iowait, 0);
18480 -
18481 +#ifdef CONFIG_VSERVER_HARDCPU
18482 +               INIT_LIST_HEAD(&rq->hold_queue);
18483 +               rq->nr_onhold = 0;
18484 +#endif
18485                 for (j = 0; j < 2; j++) {
18486                         array = rq->arrays + j;
18487                         for (k = 0; k < MAX_PRIO; k++) {
18488 @@ -7144,6 +7218,7 @@ void normalize_rt_tasks(void)
18489                         deactivate_task(p, task_rq(p));
18490                 __setscheduler(p, SCHED_NORMAL, 0);
18491                 if (array) {
18492 +                       vx_activate_task(p);
18493                         __activate_task(p, task_rq(p));
18494                         resched_task(rq->curr);
18495                 }
18496 diff -NurpP --minimal linux-2.6.22.10/kernel/sched_hard.h linux-2.6.22.10-vs2.3.0.29/kernel/sched_hard.h
18497 --- linux-2.6.22.10/kernel/sched_hard.h 1970-01-01 01:00:00 +0100
18498 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched_hard.h      2007-08-05 20:53:13 +0200
18499 @@ -0,0 +1,324 @@
18500 +
18501 +#ifdef CONFIG_VSERVER_IDLELIMIT
18502 +
18503 +/*
18504 + * vx_idle_resched - reschedule after maxidle
18505 + */
18506 +static inline
18507 +void vx_idle_resched(struct rq *rq)
18508 +{
18509 +       /* maybe have a better criterion for paused */
18510 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
18511 +               set_need_resched();
18512 +}
18513 +
18514 +#else /* !CONFIG_VSERVER_IDLELIMIT */
18515 +
18516 +#define vx_idle_resched(rq)
18517 +
18518 +#endif /* CONFIG_VSERVER_IDLELIMIT */
18519 +
18520 +
18521 +
18522 +#ifdef CONFIG_VSERVER_IDLETIME
18523 +
18524 +#define vx_set_rq_min_skip(rq, min)            \
18525 +       (rq)->idle_skip = (min)
18526 +
18527 +#define vx_save_min_skip(ret, min, val)                \
18528 +       __vx_save_min_skip(ret, min, val)
18529 +
18530 +static inline
18531 +void __vx_save_min_skip(int ret, int *min, int val)
18532 +{
18533 +       if (ret > -2)
18534 +               return;
18535 +       if ((*min > val) || !*min)
18536 +               *min = val;
18537 +}
18538 +
18539 +static inline
18540 +int vx_try_skip(struct rq *rq, int cpu)
18541 +{
18542 +       /* artificially advance time */
18543 +       if (rq->idle_skip > 0) {
18544 +               vxdprintk(list_empty(&rq->hold_queue),
18545 +                       "hold queue empty on cpu %d", cpu);
18546 +               rq->idle_time += rq->idle_skip;
18547 +               vxm_idle_skip(rq, cpu);
18548 +               return 1;
18549 +       }
18550 +       return 0;
18551 +}
18552 +
18553 +#else /* !CONFIG_VSERVER_IDLETIME */
18554 +
18555 +#define vx_set_rq_min_skip(rq, min)            \
18556 +       ({ int dummy = (min); dummy; })
18557 +
18558 +#define vx_save_min_skip(ret, min, val)
18559 +
18560 +static inline
18561 +int vx_try_skip(struct rq *rq, int cpu)
18562 +{
18563 +       return 0;
18564 +}
18565 +
18566 +#endif /* CONFIG_VSERVER_IDLETIME */
18567 +
18568 +
18569 +
18570 +#ifdef CONFIG_VSERVER_HARDCPU
18571 +
18572 +#define vx_set_rq_max_idle(rq, max)            \
18573 +       (rq)->idle_tokens = (max)
18574 +
18575 +#define vx_save_max_idle(ret, min, val)                \
18576 +       __vx_save_max_idle(ret, min, val)
18577 +
18578 +static inline
18579 +void __vx_save_max_idle(int ret, int *min, int val)
18580 +{
18581 +       if (*min > val)
18582 +               *min = val;
18583 +}
18584 +
18585 +
18586 +/*
18587 + * vx_hold_task - put a task on the hold queue
18588 + */
18589 +static inline
18590 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18591 +{
18592 +       __deactivate_task(p, rq);
18593 +       p->state |= TASK_ONHOLD;
18594 +       /* a new one on hold */
18595 +       rq->nr_onhold++;
18596 +       vxm_hold_task(p, rq);
18597 +       list_add_tail(&p->run_list, &rq->hold_queue);
18598 +}
18599 +
18600 +/*
18601 + * vx_unhold_task - put a task back to the runqueue
18602 + */
18603 +static inline
18604 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18605 +{
18606 +       list_del(&p->run_list);
18607 +       /* one less waiting */
18608 +       rq->nr_onhold--;
18609 +       p->state &= ~TASK_ONHOLD;
18610 +       enqueue_task(p, rq->expired);
18611 +       inc_nr_running(p, rq);
18612 +       vxm_unhold_task(p, rq);
18613 +
18614 +       if (p->static_prio < rq->best_expired_prio)
18615 +               rq->best_expired_prio = p->static_prio;
18616 +}
18617 +
18618 +unsigned long nr_onhold(void)
18619 +{
18620 +       unsigned long i, sum = 0;
18621 +
18622 +       for_each_online_cpu(i)
18623 +               sum += cpu_rq(i)->nr_onhold;
18624 +
18625 +       return sum;
18626 +}
18627 +
18628 +
18629 +
18630 +static inline
18631 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
18632 +{
18633 +       return sched_pc->tokens;
18634 +}
18635 +
18636 +static inline
18637 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
18638 +{
18639 +       sched_pc->tokens--;
18640 +}
18641 +
18642 +static inline
18643 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18644 +{
18645 +       struct vx_info *vxi = p->vx_info;
18646 +
18647 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
18648 +               struct _vx_sched_pc *sched_pc =
18649 +                       &vx_per_cpu(vxi, sched_pc, cpu);
18650 +               int tokens;
18651 +
18652 +               /* maybe we can simplify that to decrement
18653 +                  the token counter unconditional? */
18654 +
18655 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
18656 +                       __vx_consume_token(sched_pc);
18657 +
18658 +               /* for tokens > 0, one token was consumed */
18659 +               if (tokens < 2)
18660 +                       slice = 0;
18661 +       }
18662 +       vxm_need_resched(p, slice, cpu);
18663 +       return (slice == 0);
18664 +}
18665 +
18666 +
18667 +#define vx_set_rq_time(rq, time) do {  \
18668 +       rq->norm_time = time;           \
18669 +} while (0)
18670 +
18671 +
18672 +static inline
18673 +void vx_try_unhold(struct rq *rq, int cpu)
18674 +{
18675 +       struct vx_info *vxi = NULL;
18676 +       struct list_head *l, *n;
18677 +       int maxidle = HZ;
18678 +       int minskip = 0;
18679 +
18680 +       /* nothing to do? what about pause? */
18681 +       if (list_empty(&rq->hold_queue))
18682 +               return;
18683 +
18684 +       list_for_each_safe(l, n, &rq->hold_queue) {
18685 +               int ret, delta_min[2];
18686 +               struct _vx_sched_pc *sched_pc;
18687 +               struct task_struct *p;
18688 +
18689 +               p = list_entry(l, struct task_struct, run_list);
18690 +               /* don't bother with same context */
18691 +               if (vxi == p->vx_info)
18692 +                       continue;
18693 +
18694 +               vxi = p->vx_info;
18695 +               /* ignore paused contexts */
18696 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
18697 +                       continue;
18698 +
18699 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18700 +
18701 +               /* recalc tokens */
18702 +               vxm_sched_info(sched_pc, vxi, cpu);
18703 +               ret = vx_tokens_recalc(sched_pc,
18704 +                       &rq->norm_time, &rq->idle_time, delta_min);
18705 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18706 +
18707 +               if (ret > 0) {
18708 +                       /* we found a runable context */
18709 +                       vx_unhold_task(p, rq);
18710 +                       break;
18711 +               }
18712 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
18713 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
18714 +       }
18715 +       vx_set_rq_max_idle(rq, maxidle);
18716 +       vx_set_rq_min_skip(rq, minskip);
18717 +       vxm_rq_max_min(rq, cpu);
18718 +}
18719 +
18720 +
18721 +static inline
18722 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18723 +{
18724 +       struct vx_info *vxi = next->vx_info;
18725 +       struct _vx_sched_pc *sched_pc;
18726 +       int delta_min[2];
18727 +       int flags, ret;
18728 +
18729 +       if (!vxi)
18730 +               return 1;
18731 +
18732 +       flags = vxi->vx_flags;
18733 +
18734 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
18735 +               goto put_on_hold;
18736 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
18737 +               return 1;
18738 +
18739 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18740 +#ifdef CONFIG_SMP
18741 +       /* update scheduler params */
18742 +       if (cpu_isset(cpu, vxi->sched.update)) {
18743 +               vx_update_sched_param(&vxi->sched, sched_pc);
18744 +               vxm_update_sched(sched_pc, vxi, cpu);
18745 +               cpu_clear(cpu, vxi->sched.update);
18746 +       }
18747 +#endif
18748 +       vxm_sched_info(sched_pc, vxi, cpu);
18749 +       ret  = vx_tokens_recalc(sched_pc,
18750 +               &rq->norm_time, &rq->idle_time, delta_min);
18751 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18752 +
18753 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
18754 +               return 1;
18755 +
18756 +       if (unlikely(ret < 0)) {
18757 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
18758 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
18759 +               vxm_rq_max_min(rq, cpu);
18760 +       put_on_hold:
18761 +               vx_hold_task(next, rq);
18762 +               return 0;
18763 +       }
18764 +       return 1;
18765 +}
18766 +
18767 +
18768 +#else /* CONFIG_VSERVER_HARDCPU */
18769 +
18770 +static inline
18771 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18772 +{
18773 +       return;
18774 +}
18775 +
18776 +static inline
18777 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18778 +{
18779 +       return;
18780 +}
18781 +
18782 +unsigned long nr_onhold(void)
18783 +{
18784 +       return 0;
18785 +}
18786 +
18787 +
18788 +static inline
18789 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18790 +{
18791 +       return (slice == 0);
18792 +}
18793 +
18794 +
18795 +#define vx_set_rq_time(rq, time)
18796 +
18797 +static inline
18798 +void vx_try_unhold(struct rq *rq, int cpu)
18799 +{
18800 +       return;
18801 +}
18802 +
18803 +static inline
18804 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18805 +{
18806 +       struct vx_info *vxi = next->vx_info;
18807 +       struct _vx_sched_pc *sched_pc;
18808 +       int delta_min[2];
18809 +       int ret;
18810 +
18811 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
18812 +               return 1;
18813 +
18814 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18815 +       vxm_sched_info(sched_pc, vxi, cpu);
18816 +       ret  = vx_tokens_recalc(sched_pc,
18817 +               &rq->norm_time, &rq->idle_time, delta_min);
18818 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18819 +       return 1;
18820 +}
18821 +
18822 +#endif /* CONFIG_VSERVER_HARDCPU */
18823 +
18824 diff -NurpP --minimal linux-2.6.22.10/kernel/sched_mon.h linux-2.6.22.10-vs2.3.0.29/kernel/sched_mon.h
18825 --- linux-2.6.22.10/kernel/sched_mon.h  1970-01-01 01:00:00 +0100
18826 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched_mon.h       2007-08-05 20:53:13 +0200
18827 @@ -0,0 +1,200 @@
18828 +
18829 +#include <linux/vserver/monitor.h>
18830 +
18831 +#ifdef  CONFIG_VSERVER_MONITOR
18832 +
18833 +#ifdef CONFIG_VSERVER_HARDCPU
18834 +#define HARDCPU(x) (x)
18835 +#else
18836 +#define HARDCPU(x) (0)
18837 +#endif
18838 +
18839 +#ifdef CONFIG_VSERVER_IDLETIME
18840 +#define IDLETIME(x) (x)
18841 +#else
18842 +#define IDLETIME(x) (0)
18843 +#endif
18844 +
18845 +struct _vx_mon_entry *vxm_advance(int cpu);
18846 +
18847 +
18848 +static inline
18849 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
18850 +{
18851 +       entry->type = type;
18852 +       entry->xid = xid;
18853 +}
18854 +
18855 +static inline
18856 +void   __vxm_sync(int cpu)
18857 +{
18858 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18859 +
18860 +       __vxm_basic(entry, 0, VXM_SYNC);
18861 +       entry->ev.sec = xtime.tv_sec;
18862 +       entry->ev.nsec = xtime.tv_nsec;
18863 +}
18864 +
18865 +static inline
18866 +void   __vxm_task(struct task_struct *p, int type)
18867 +{
18868 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
18869 +
18870 +       __vxm_basic(entry, p->xid, type);
18871 +       entry->ev.tsk.pid = p->pid;
18872 +       entry->ev.tsk.state = p->state;
18873 +}
18874 +
18875 +static inline
18876 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18877 +{
18878 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18879 +
18880 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
18881 +       entry->sd.tokens = s->tokens;
18882 +       entry->sd.norm_time = s->norm_time;
18883 +       entry->sd.idle_time = s->idle_time;
18884 +}
18885 +
18886 +static inline
18887 +void   __vxm_rqinfo1(struct rq *q, int cpu)
18888 +{
18889 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18890 +
18891 +       entry->type = VXM_RQINFO_1;
18892 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
18893 +       entry->q1.running = q->nr_running;
18894 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
18895 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
18896 +       entry->q1.uintr = q->nr_uninterruptible;
18897 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
18898 +}
18899 +
18900 +static inline
18901 +void   __vxm_rqinfo2(struct rq *q, int cpu)
18902 +{
18903 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18904 +
18905 +       entry->type = VXM_RQINFO_2;
18906 +       entry->xid = (unsigned long)q & 0xffff;
18907 +       entry->q2.norm_time = q->norm_time;
18908 +       entry->q2.idle_time = q->idle_time;
18909 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
18910 +}
18911 +
18912 +static inline
18913 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18914 +{
18915 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18916 +
18917 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
18918 +       entry->ev.tokens = s->tokens;
18919 +}
18920 +
18921 +static inline
18922 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18923 +{
18924 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18925 +
18926 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
18927 +       entry->u1.tokens_max = s->tokens_max;
18928 +       entry->u1.fill_rate = s->fill_rate[0];
18929 +       entry->u1.interval = s->interval[0];
18930 +}
18931 +
18932 +static inline
18933 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18934 +{
18935 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18936 +
18937 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
18938 +       entry->u2.tokens_min = s->tokens_min;
18939 +       entry->u2.fill_rate = s->fill_rate[1];
18940 +       entry->u2.interval = s->interval[1];
18941 +}
18942 +
18943 +
18944 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
18945 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
18946 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
18947 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
18948 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
18949 +
18950 +static inline
18951 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
18952 +{
18953 +       __vxm_task(p, VXM_MIGRATE);
18954 +       __vxm_rqinfo1(rq, task_cpu(p));
18955 +       __vxm_rqinfo2(rq, task_cpu(p));
18956 +}
18957 +
18958 +static inline
18959 +void   vxm_idle_skip(struct rq *rq, int cpu)
18960 +{
18961 +       __vxm_rqinfo1(rq, cpu);
18962 +       __vxm_rqinfo2(rq, cpu);
18963 +}
18964 +
18965 +static inline
18966 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
18967 +{
18968 +       if (slice)
18969 +               return;
18970 +
18971 +       __vxm_task(p, VXM_RESCHED);
18972 +}
18973 +
18974 +static inline
18975 +void   vxm_sync(unsigned long now, int cpu)
18976 +{
18977 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
18978 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
18979 +               return;
18980 +
18981 +       __vxm_sync(cpu);
18982 +}
18983 +
18984 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
18985 +
18986 +static inline
18987 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
18988 +       struct vx_info *vxi, int cpu)
18989 +{
18990 +       __vxm_sched(s, vxi, cpu);
18991 +       __vxm_rqinfo2(rq, cpu);
18992 +}
18993 +
18994 +static inline
18995 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18996 +{
18997 +       __vxm_sched(s, vxi, cpu);
18998 +       __vxm_update(s, vxi, cpu);
18999 +       __vxm_update1(s, vxi, cpu);
19000 +       __vxm_update2(s, vxi, cpu);
19001 +}
19002 +
19003 +static inline
19004 +void   vxm_rq_max_min(struct rq *rq, int cpu)
19005 +{
19006 +       __vxm_rqinfo1(rq, cpu);
19007 +       __vxm_rqinfo2(rq, cpu);
19008 +}
19009 +
19010 +#else  /* CONFIG_VSERVER_MONITOR */
19011 +
19012 +#define        vxm_activate_task(t,q)          do { } while (0)
19013 +#define        vxm_activate_idle(t,q)          do { } while (0)
19014 +#define        vxm_deactivate_task(t,q)        do { } while (0)
19015 +#define        vxm_hold_task(t,q)              do { } while (0)
19016 +#define        vxm_unhold_task(t,q)            do { } while (0)
19017 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
19018 +#define        vxm_idle_skip(q,c)              do { } while (0)
19019 +#define        vxm_need_resched(t,s,c)         do { } while (0)
19020 +#define        vxm_sync(s,c)                   do { } while (0)
19021 +#define        vxm_sched_info(s,v,c)           do { } while (0)
19022 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
19023 +#define        vxm_update_sched(s,v,c)         do { } while (0)
19024 +#define        vxm_rq_max_min(q,c)             do { } while (0)
19025 +
19026 +#endif /* CONFIG_VSERVER_MONITOR */
19027 +
19028 diff -NurpP --minimal linux-2.6.22.10/kernel/signal.c linux-2.6.22.10-vs2.3.0.29/kernel/signal.c
19029 --- linux-2.6.22.10/kernel/signal.c     2007-10-30 01:57:15 +0100
19030 +++ linux-2.6.22.10-vs2.3.0.29/kernel/signal.c  2007-09-30 14:58:01 +0200
19031 @@ -26,6 +26,8 @@
19032  #include <linux/freezer.h>
19033  #include <linux/pid_namespace.h>
19034  #include <linux/nsproxy.h>
19035 +#include <linux/vs_context.h>
19036 +#include <linux/vs_pid.h>
19037  
19038  #include <asm/param.h>
19039  #include <asm/uaccess.h>
19040 @@ -523,19 +525,34 @@ static int check_kill_permission(int sig
19041         if (!valid_signal(sig))
19042                 return error;
19043  
19044 +       if ((info != SEND_SIG_NOINFO) &&
19045 +               (is_si_special(info) || !SI_FROMUSER(info)))
19046 +               goto skip;
19047 +
19048 +       vxdprintk(VXD_CBIT(misc, 7),
19049 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
19050 +               sig, info, t, vx_task_xid(t), t->pid);
19051 +
19052         error = audit_signal_info(sig, t); /* Let audit system see the signal */
19053         if (error)
19054                 return error;
19055  
19056         error = -EPERM;
19057 -       if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
19058 -           && ((sig != SIGCONT) ||
19059 +       if (((sig != SIGCONT) ||
19060                 (process_session(current) != process_session(t)))
19061             && (current->euid ^ t->suid) && (current->euid ^ t->uid)
19062             && (current->uid ^ t->suid) && (current->uid ^ t->uid)
19063             && !capable(CAP_KILL))
19064                 return error;
19065  
19066 +       error = -ESRCH;
19067 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
19068 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
19069 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
19070 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
19071 +               return error;
19072 +       }
19073 +skip:
19074         return security_task_kill(t, info, sig, 0);
19075  }
19076  
19077 @@ -1043,7 +1060,7 @@ int kill_pid_info(int sig, struct siginf
19078  
19079         p = pid_task(pid, PIDTYPE_PID);
19080         error = -ESRCH;
19081 -       if (p)
19082 +       if (p && vx_check(vx_task_xid(p), VS_IDENT))
19083                 error = group_send_sig_info(sig, info, p);
19084  
19085         if (unlikely(sig_needs_tasklist(sig)))
19086 @@ -1057,7 +1074,7 @@ kill_proc_info(int sig, struct siginfo *
19087  {
19088         int error;
19089         rcu_read_lock();
19090 -       error = kill_pid_info(sig, info, find_pid(pid));
19091 +       error = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
19092         rcu_read_unlock();
19093         return error;
19094  }
19095 @@ -1118,7 +1135,9 @@ static int kill_something_info(int sig, 
19096  
19097                 read_lock(&tasklist_lock);
19098                 for_each_process(p) {
19099 -                       if (p->pid > 1 && p->tgid != current->tgid) {
19100 +                       if (vx_check(vx_task_xid(p), VS_ADMIN_P|VS_IDENT) &&
19101 +                               p->pid > 1 && p->tgid != current->tgid &&
19102 +                               !vx_current_initpid(p->pid)) {
19103                                 int err = group_send_sig_info(sig, info, p);
19104                                 ++count;
19105                                 if (err != -EPERM)
19106 @@ -1128,9 +1147,9 @@ static int kill_something_info(int sig, 
19107                 read_unlock(&tasklist_lock);
19108                 ret = count ? retval : -ESRCH;
19109         } else if (pid < 0) {
19110 -               ret = kill_pgrp_info(sig, info, find_pid(-pid));
19111 +               ret = kill_pgrp_info(sig, info, find_pid(vx_rmap_pid(-pid)));
19112         } else {
19113 -               ret = kill_pid_info(sig, info, find_pid(pid));
19114 +               ret = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
19115         }
19116         rcu_read_unlock();
19117         return ret;
19118 @@ -1814,6 +1833,11 @@ relock:
19119                 if (current == child_reaper(current))
19120                         continue;
19121  
19122 +               /* virtual init is protected against user signals */
19123 +               if ((info->si_code == SI_USER) &&
19124 +                       vx_current_initpid(current->pid))
19125 +                       continue;
19126 +
19127                 if (sig_kernel_stop(signr)) {
19128                         /*
19129                          * The default action is to stop all threads in
19130 diff -NurpP --minimal linux-2.6.22.10/kernel/softirq.c linux-2.6.22.10-vs2.3.0.29/kernel/softirq.c
19131 --- linux-2.6.22.10/kernel/softirq.c    2007-07-09 13:20:03 +0200
19132 +++ linux-2.6.22.10-vs2.3.0.29/kernel/softirq.c 2007-08-05 20:53:13 +0200
19133 @@ -18,6 +18,7 @@
19134  #include <linux/rcupdate.h>
19135  #include <linux/smp.h>
19136  #include <linux/tick.h>
19137 +#include <linux/vs_context.h>
19138  
19139  #include <asm/irq.h>
19140  /*
19141 diff -NurpP --minimal linux-2.6.22.10/kernel/sys.c linux-2.6.22.10-vs2.3.0.29/kernel/sys.c
19142 --- linux-2.6.22.10/kernel/sys.c        2007-10-30 01:57:15 +0100
19143 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sys.c     2007-10-30 01:21:54 +0100
19144 @@ -36,6 +36,7 @@
19145  #include <linux/compat.h>
19146  #include <linux/syscalls.h>
19147  #include <linux/kprobes.h>
19148 +#include <linux/vs_pid.h>
19149  
19150  #include <asm/uaccess.h>
19151  #include <asm/io.h>
19152 @@ -639,7 +640,10 @@ static int set_one_prio(struct task_stru
19153                 goto out;
19154         }
19155         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
19156 -               error = -EACCES;
19157 +               if (vx_flags(VXF_IGNEG_NICE, 0))
19158 +                       error = 0;
19159 +               else
19160 +                       error = -EACCES;
19161                 goto out;
19162         }
19163         no_nice = security_task_setnice(p, niceval);
19164 @@ -687,6 +691,8 @@ asmlinkage long sys_setpriority(int whic
19165                         else
19166                                 pgrp = task_pgrp(current);
19167                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19168 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19169 +                                       continue;
19170                                 error = set_one_prio(p, niceval, error);
19171                         } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
19172                         break;
19173 @@ -695,7 +701,8 @@ asmlinkage long sys_setpriority(int whic
19174                         if (!who)
19175                                 who = current->uid;
19176                         else
19177 -                               if ((who != current->uid) && !(user = find_user(who)))
19178 +                               if ((who != current->uid) &&
19179 +                                       !(user = find_user(vx_current_xid(), who)))
19180                                         goto out_unlock;        /* No processes for this user */
19181  
19182                         do_each_thread(g, p)
19183 @@ -747,6 +754,8 @@ asmlinkage long sys_getpriority(int whic
19184                         else
19185                                 pgrp = task_pgrp(current);
19186                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19187 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19188 +                                       continue;
19189                                 niceval = 20 - task_nice(p);
19190                                 if (niceval > retval)
19191                                         retval = niceval;
19192 @@ -757,7 +766,8 @@ asmlinkage long sys_getpriority(int whic
19193                         if (!who)
19194                                 who = current->uid;
19195                         else
19196 -                               if ((who != current->uid) && !(user = find_user(who)))
19197 +                               if ((who != current->uid) &&
19198 +                                       !(user = find_user(vx_current_xid(), who)))
19199                                         goto out_unlock;        /* No processes for this user */
19200  
19201                         do_each_thread(g, p)
19202 @@ -871,6 +881,9 @@ void kernel_power_off(void)
19203         machine_power_off();
19204  }
19205  EXPORT_SYMBOL_GPL(kernel_power_off);
19206 +
19207 +long vs_reboot(unsigned int, void __user *);
19208 +
19209  /*
19210   * Reboot system call: for obvious reasons only root may call it,
19211   * and even root needs to set up some magic numbers in the registers
19212 @@ -901,6 +914,9 @@ asmlinkage long sys_reboot(int magic1, i
19213         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
19214                 cmd = LINUX_REBOOT_CMD_HALT;
19215  
19216 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
19217 +               return vs_reboot(cmd, arg);
19218 +
19219         lock_kernel();
19220         switch (cmd) {
19221         case LINUX_REBOOT_CMD_RESTART:
19222 @@ -1080,7 +1096,7 @@ static int set_user(uid_t new_ruid, int 
19223  {
19224         struct user_struct *new_user;
19225  
19226 -       new_user = alloc_uid(new_ruid);
19227 +       new_user = alloc_uid(vx_current_xid(), new_ruid);
19228         if (!new_user)
19229                 return -EAGAIN;
19230  
19231 @@ -1434,15 +1450,18 @@ asmlinkage long sys_setpgid(pid_t pid, p
19232  {
19233         struct task_struct *p;
19234         struct task_struct *group_leader = current->group_leader;
19235 +       pid_t rpgid;
19236         int err = -EINVAL;
19237  
19238         if (!pid)
19239 -               pid = group_leader->pid;
19240 +               pid = vx_map_pid(group_leader->pid);
19241         if (!pgid)
19242                 pgid = pid;
19243         if (pgid < 0)
19244                 return -EINVAL;
19245  
19246 +       rpgid = vx_rmap_pid(pgid);
19247 +
19248         /* From this point forward we keep holding onto the tasklist lock
19249          * so that our parent does not change from under us. -DaveM
19250          */
19251 @@ -1476,20 +1495,20 @@ asmlinkage long sys_setpgid(pid_t pid, p
19252  
19253         if (pgid != pid) {
19254                 struct task_struct *g =
19255 -                       find_task_by_pid_type(PIDTYPE_PGID, pgid);
19256 +                       find_task_by_pid_type(PIDTYPE_PGID, rpgid);
19257  
19258                 if (!g || task_session(g) != task_session(group_leader))
19259                         goto out;
19260         }
19261  
19262 -       err = security_task_setpgid(p, pgid);
19263 +       err = security_task_setpgid(p, rpgid);
19264         if (err)
19265                 goto out;
19266  
19267 -       if (process_group(p) != pgid) {
19268 +       if (process_group(p) != rpgid) {
19269                 detach_pid(p, PIDTYPE_PGID);
19270 -               p->signal->pgrp = pgid;
19271 -               attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
19272 +               p->signal->pgrp = rpgid;
19273 +               attach_pid(p, PIDTYPE_PGID, find_pid(rpgid));
19274         }
19275  
19276         err = 0;
19277 @@ -1502,7 +1521,7 @@ out:
19278  asmlinkage long sys_getpgid(pid_t pid)
19279  {
19280         if (!pid)
19281 -               return process_group(current);
19282 +               return vx_rmap_pid(process_group(current));
19283         else {
19284                 int retval;
19285                 struct task_struct *p;
19286 @@ -1514,7 +1533,7 @@ asmlinkage long sys_getpgid(pid_t pid)
19287                 if (p) {
19288                         retval = security_task_getpgid(p);
19289                         if (!retval)
19290 -                               retval = process_group(p);
19291 +                               retval = vx_rmap_pid(process_group(p));
19292                 }
19293                 read_unlock(&tasklist_lock);
19294                 return retval;
19295 @@ -1865,7 +1884,7 @@ asmlinkage long sys_sethostname(char __u
19296         int errno;
19297         char tmp[__NEW_UTS_LEN];
19298  
19299 -       if (!capable(CAP_SYS_ADMIN))
19300 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19301                 return -EPERM;
19302         if (len < 0 || len > __NEW_UTS_LEN)
19303                 return -EINVAL;
19304 @@ -1910,7 +1929,7 @@ asmlinkage long sys_setdomainname(char _
19305         int errno;
19306         char tmp[__NEW_UTS_LEN];
19307  
19308 -       if (!capable(CAP_SYS_ADMIN))
19309 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19310                 return -EPERM;
19311         if (len < 0 || len > __NEW_UTS_LEN)
19312                 return -EINVAL;
19313 @@ -1977,7 +1996,7 @@ asmlinkage long sys_setrlimit(unsigned i
19314                 return -EINVAL;
19315         old_rlim = current->signal->rlim + resource;
19316         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
19317 -           !capable(CAP_SYS_RESOURCE))
19318 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
19319                 return -EPERM;
19320         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
19321                 return -EPERM;
19322 diff -NurpP --minimal linux-2.6.22.10/kernel/sysctl.c linux-2.6.22.10-vs2.3.0.29/kernel/sysctl.c
19323 --- linux-2.6.22.10/kernel/sysctl.c     2007-07-09 13:20:03 +0200
19324 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sysctl.c  2007-08-05 20:53:13 +0200
19325 @@ -89,6 +89,7 @@ static int ngroups_max = NGROUPS_MAX;
19326  #ifdef CONFIG_KMOD
19327  extern char modprobe_path[];
19328  #endif
19329 +extern char vshelper_path[];
19330  #ifdef CONFIG_CHR_DEV_SG
19331  extern int sg_big_buff;
19332  #endif
19333 @@ -343,6 +344,15 @@ static ctl_table kern_table[] = {
19334                 .strategy       = &sysctl_string,
19335         },
19336  #endif
19337 +       {
19338 +               .ctl_name       = KERN_VSHELPER,
19339 +               .procname       = "vshelper",
19340 +               .data           = &vshelper_path,
19341 +               .maxlen         = 256,
19342 +               .mode           = 0644,
19343 +               .proc_handler   = &proc_dostring,
19344 +               .strategy       = &sysctl_string,
19345 +       },
19346  #ifdef CONFIG_CHR_DEV_SG
19347         {
19348                 .ctl_name       = KERN_SG_BIG_BUFF,
19349 diff -NurpP --minimal linux-2.6.22.10/kernel/time.c linux-2.6.22.10-vs2.3.0.29/kernel/time.c
19350 --- linux-2.6.22.10/kernel/time.c       2007-07-09 13:20:03 +0200
19351 +++ linux-2.6.22.10-vs2.3.0.29/kernel/time.c    2007-08-05 20:53:13 +0200
19352 @@ -60,7 +60,7 @@ asmlinkage long sys_time(time_t __user *
19353         time_t i;
19354         struct timeval tv;
19355  
19356 -       do_gettimeofday(&tv);
19357 +       vx_gettimeofday(&tv);
19358         i = tv.tv_sec;
19359  
19360         if (tloc) {
19361 @@ -91,7 +91,7 @@ asmlinkage long sys_stime(time_t __user 
19362         if (err)
19363                 return err;
19364  
19365 -       do_settimeofday(&tv);
19366 +       vx_settimeofday(&tv);
19367         return 0;
19368  }
19369  
19370 @@ -101,7 +101,7 @@ asmlinkage long sys_gettimeofday(struct 
19371  {
19372         if (likely(tv != NULL)) {
19373                 struct timeval ktv;
19374 -               do_gettimeofday(&ktv);
19375 +               vx_gettimeofday(&ktv);
19376                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
19377                         return -EFAULT;
19378         }
19379 @@ -175,7 +175,7 @@ int do_sys_settimeofday(struct timespec 
19380                 /* SMP safe, again the code in arch/foo/time.c should
19381                  * globally block out interrupts when it runs.
19382                  */
19383 -               return do_settimeofday(tv);
19384 +               return vx_settimeofday(tv);
19385         }
19386         return 0;
19387  }
19388 @@ -388,7 +388,7 @@ void getnstimeofday(struct timespec *tv)
19389  {
19390         struct timeval x;
19391  
19392 -       do_gettimeofday(&x);
19393 +       vx_gettimeofday(&x);
19394         tv->tv_sec = x.tv_sec;
19395         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
19396  }
19397 diff -NurpP --minimal linux-2.6.22.10/kernel/timer.c linux-2.6.22.10-vs2.3.0.29/kernel/timer.c
19398 --- linux-2.6.22.10/kernel/timer.c      2007-07-09 13:20:04 +0200
19399 +++ linux-2.6.22.10-vs2.3.0.29/kernel/timer.c   2007-08-05 20:53:13 +0200
19400 @@ -36,6 +36,10 @@
19401  #include <linux/delay.h>
19402  #include <linux/tick.h>
19403  #include <linux/kallsyms.h>
19404 +#include <linux/vs_base.h>
19405 +#include <linux/vs_cvirt.h>
19406 +#include <linux/vs_pid.h>
19407 +#include <linux/vserver/sched.h>
19408  
19409  #include <asm/uaccess.h>
19410  #include <asm/unistd.h>
19411 @@ -921,12 +925,6 @@ asmlinkage unsigned long sys_alarm(unsig
19412  
19413  #endif
19414  
19415 -#ifndef __alpha__
19416 -
19417 -/*
19418 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
19419 - * should be moved into arch/i386 instead?
19420 - */
19421  
19422  /**
19423   * sys_getpid - return the thread group id of the current process
19424 @@ -939,7 +937,7 @@ asmlinkage unsigned long sys_alarm(unsig
19425   */
19426  asmlinkage long sys_getpid(void)
19427  {
19428 -       return current->tgid;
19429 +       return vx_map_tgid(current->tgid);
19430  }
19431  
19432  /*
19433 @@ -955,10 +953,23 @@ asmlinkage long sys_getppid(void)
19434         rcu_read_lock();
19435         pid = rcu_dereference(current->real_parent)->tgid;
19436         rcu_read_unlock();
19437 +       return vx_map_pid(pid);
19438 +}
19439  
19440 -       return pid;
19441 +#ifdef __alpha__
19442 +
19443 +/*
19444 + * The Alpha uses getxpid, getxuid, and getxgid instead.
19445 + */
19446 +
19447 +asmlinkage long do_getxpid(long *ppid)
19448 +{
19449 +       *ppid = sys_getppid();
19450 +       return sys_getpid();
19451  }
19452  
19453 +#else /* _alpha_ */
19454 +
19455  asmlinkage long sys_getuid(void)
19456  {
19457         /* Only we change this so SMP safe */
19458 @@ -1118,6 +1129,8 @@ int do_sysinfo(struct sysinfo *info)
19459                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
19460                         tp.tv_sec++;
19461                 }
19462 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
19463 +                       vx_vsi_uptime(&tp, NULL);
19464                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
19465  
19466                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
19467 diff -NurpP --minimal linux-2.6.22.10/kernel/user.c linux-2.6.22.10-vs2.3.0.29/kernel/user.c
19468 --- linux-2.6.22.10/kernel/user.c       2007-02-06 03:01:56 +0100
19469 +++ linux-2.6.22.10-vs2.3.0.29/kernel/user.c    2007-08-05 20:53:13 +0200
19470 @@ -23,8 +23,8 @@
19471  #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
19472  #define UIDHASH_SZ             (1 << UIDHASH_BITS)
19473  #define UIDHASH_MASK           (UIDHASH_SZ - 1)
19474 -#define __uidhashfn(uid)       (((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
19475 -#define uidhashentry(uid)      (uidhash_table + __uidhashfn((uid)))
19476 +#define __uidhashfn(xid,uid)   ((((uid) >> UIDHASH_BITS) + ((uid)^(xid))) & UIDHASH_MASK)
19477 +#define uidhashentry(xid,uid)  (uidhash_table + __uidhashfn((xid),(uid)))
19478  
19479  static struct kmem_cache *uid_cachep;
19480  static struct list_head uidhash_table[UIDHASH_SZ];
19481 @@ -66,7 +66,7 @@ static inline void uid_hash_remove(struc
19482         list_del(&up->uidhash_list);
19483  }
19484  
19485 -static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *hashent)
19486 +static inline struct user_struct *uid_hash_find(xid_t xid, uid_t uid, struct list_head *hashent)
19487  {
19488         struct list_head *up;
19489  
19490 @@ -75,7 +75,7 @@ static inline struct user_struct *uid_ha
19491  
19492                 user = list_entry(up, struct user_struct, uidhash_list);
19493  
19494 -               if(user->uid == uid) {
19495 +               if(user->uid == uid && user->xid == xid) {
19496                         atomic_inc(&user->__count);
19497                         return user;
19498                 }
19499 @@ -90,13 +90,13 @@ static inline struct user_struct *uid_ha
19500   *
19501   * If the user_struct could not be found, return NULL.
19502   */
19503 -struct user_struct *find_user(uid_t uid)
19504 +struct user_struct *find_user(xid_t xid, uid_t uid)
19505  {
19506         struct user_struct *ret;
19507         unsigned long flags;
19508  
19509         spin_lock_irqsave(&uidhash_lock, flags);
19510 -       ret = uid_hash_find(uid, uidhashentry(uid));
19511 +       ret = uid_hash_find(xid, uid, uidhashentry(xid, uid));
19512         spin_unlock_irqrestore(&uidhash_lock, flags);
19513         return ret;
19514  }
19515 @@ -120,13 +120,13 @@ void free_uid(struct user_struct *up)
19516         }
19517  }
19518  
19519 -struct user_struct * alloc_uid(uid_t uid)
19520 +struct user_struct * alloc_uid(xid_t xid, uid_t uid)
19521  {
19522 -       struct list_head *hashent = uidhashentry(uid);
19523 +       struct list_head *hashent = uidhashentry(xid, uid);
19524         struct user_struct *up;
19525  
19526         spin_lock_irq(&uidhash_lock);
19527 -       up = uid_hash_find(uid, hashent);
19528 +       up = uid_hash_find(xid, uid, hashent);
19529         spin_unlock_irq(&uidhash_lock);
19530  
19531         if (!up) {
19532 @@ -136,6 +136,7 @@ struct user_struct * alloc_uid(uid_t uid
19533                 if (!new)
19534                         return NULL;
19535                 new->uid = uid;
19536 +               new->xid = xid;
19537                 atomic_set(&new->__count, 1);
19538                 atomic_set(&new->processes, 0);
19539                 atomic_set(&new->files, 0);
19540 @@ -158,7 +159,7 @@ struct user_struct * alloc_uid(uid_t uid
19541                  * on adding the same user already..
19542                  */
19543                 spin_lock_irq(&uidhash_lock);
19544 -               up = uid_hash_find(uid, hashent);
19545 +               up = uid_hash_find(xid, uid, hashent);
19546                 if (up) {
19547                         key_put(new->uid_keyring);
19548                         key_put(new->session_keyring);
19549 @@ -215,7 +216,7 @@ static int __init uid_cache_init(void)
19550  
19551         /* Insert the root user immediately (init already runs as root) */
19552         spin_lock_irq(&uidhash_lock);
19553 -       uid_hash_insert(&root_user, uidhashentry(0));
19554 +       uid_hash_insert(&root_user, uidhashentry(0,0));
19555         spin_unlock_irq(&uidhash_lock);
19556  
19557         return 0;
19558 diff -NurpP --minimal linux-2.6.22.10/kernel/utsname.c linux-2.6.22.10-vs2.3.0.29/kernel/utsname.c
19559 --- linux-2.6.22.10/kernel/utsname.c    2007-07-09 13:20:04 +0200
19560 +++ linux-2.6.22.10-vs2.3.0.29/kernel/utsname.c 2007-08-05 20:53:13 +0200
19561 @@ -13,6 +13,7 @@
19562  #include <linux/uts.h>
19563  #include <linux/utsname.h>
19564  #include <linux/version.h>
19565 +#include <linux/vserver/global.h>
19566  
19567  /*
19568   * Clone a new ns copying an original utsname, setting refcount to 1
19569 @@ -27,6 +28,7 @@ static struct uts_namespace *clone_uts_n
19570         if (ns) {
19571                 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
19572                 kref_init(&ns->kref);
19573 +               atomic_inc(&vs_global_uts_ns);
19574         }
19575         return ns;
19576  }
19577 @@ -58,5 +60,6 @@ void free_uts_ns(struct kref *kref)
19578         struct uts_namespace *ns;
19579  
19580         ns = container_of(kref, struct uts_namespace, kref);
19581 +       atomic_dec(&vs_global_uts_ns);
19582         kfree(ns);
19583  }
19584 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/Kconfig linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Kconfig
19585 --- linux-2.6.22.10/kernel/vserver/Kconfig      1970-01-01 01:00:00 +0100
19586 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Kconfig   2007-10-11 01:10:22 +0200
19587 @@ -0,0 +1,249 @@
19588 +#
19589 +# Linux VServer configuration
19590 +#
19591 +
19592 +menu "Linux VServer"
19593 +
19594 +config VSERVER_AUTO_LBACK
19595 +       bool    "Automatically Assign Loopback IP"
19596 +       default y
19597 +       help
19598 +         Automatically assign a guest specific loopback
19599 +         IP and add it to the kernel network stack on
19600 +         startup.
19601 +
19602 +config VSERVER_AUTO_SINGLE
19603 +       bool    "Automatic Single IP Special Casing"
19604 +       depends on EXPERIMENTAL
19605 +       default y
19606 +       help
19607 +         This allows network contexts with a single IP to
19608 +         automatically remap 0.0.0.0 bindings to that IP,
19609 +         avoiding further network checks and improving
19610 +         performance.
19611 +
19612 +         (note: such guests do not allow to change the ip
19613 +          on the fly and do not show loopback addresses)
19614 +
19615 +config VSERVER_COWBL
19616 +       bool    "Enable COW Immutable Link Breaking"
19617 +       default y
19618 +       help
19619 +         This enables the COW (Copy-On-Write) link break code.
19620 +         It allows you to treat unified files like normal files
19621 +         when writing to them (which will implicitely break the
19622 +         link and create a copy of the unified file)
19623 +
19624 +config VSERVER_VTIME
19625 +       bool    "Enable Virtualized Guest Time"
19626 +       depends on EXPERIMENTAL
19627 +       default n
19628 +       help
19629 +         This enables per guest time offsets to allow for
19630 +         adjusting the system clock individually per guest.
19631 +         this adds some overhead to the time functions and
19632 +         therefore should not be enabled without good reason.
19633 +
19634 +config VSERVER_DEVICE
19635 +       bool    "Enable Guest Device Mapping"
19636 +       depends on EXPERIMENTAL
19637 +       default n
19638 +       help
19639 +         This enables generic device remapping.
19640 +
19641 +config VSERVER_PROC_SECURE
19642 +       bool    "Enable Proc Security"
19643 +       depends on PROC_FS
19644 +       default y
19645 +       help
19646 +         This configures ProcFS security to initially hide
19647 +         non-process entries for all contexts except the main and
19648 +         spectator context (i.e. for all guests), which is a secure
19649 +         default.
19650 +
19651 +         (note: on 1.2x the entries were visible by default)
19652 +
19653 +config VSERVER_HARDCPU
19654 +       bool    "Enable Hard CPU Limits"
19655 +       default y
19656 +       help
19657 +         Activate the Hard CPU Limits
19658 +
19659 +         This will compile in code that allows the Token Bucket
19660 +         Scheduler to put processes on hold when a context's
19661 +         tokens are depleted (provided that its per-context
19662 +         sched_hard flag is set).
19663 +
19664 +         Processes belonging to that context will not be able
19665 +         to consume CPU resources again until a per-context
19666 +         configured minimum of tokens has been reached.
19667 +
19668 +config VSERVER_IDLETIME
19669 +       bool    "Avoid idle CPUs by skipping Time"
19670 +       depends on VSERVER_HARDCPU
19671 +       default y
19672 +       help
19673 +         This option allows the scheduler to artificially
19674 +         advance time (per cpu) when otherwise the idle
19675 +         task would be scheduled, thus keeping the cpu
19676 +         busy and sharing the available resources among
19677 +         certain contexts.
19678 +
19679 +config VSERVER_IDLELIMIT
19680 +       bool    "Limit the IDLE task"
19681 +       depends on VSERVER_HARDCPU
19682 +       default n
19683 +       help
19684 +         Limit the idle slices, so the the next context
19685 +         will be scheduled as soon as possible.
19686 +
19687 +         This might improve interactivity and latency, but
19688 +         will also marginally increase scheduling overhead.
19689 +
19690 +choice
19691 +       prompt  "Persistent Inode Tagging"
19692 +       default TAGGING_ID24
19693 +       help
19694 +         This adds persistent context information to filesystems
19695 +         mounted with the tagxid option. Tagging is a requirement
19696 +         for per-context disk limits and per-context quota.
19697 +
19698 +
19699 +config TAGGING_NONE
19700 +       bool    "Disabled"
19701 +       help
19702 +         do not store per-context information in inodes.
19703 +
19704 +config TAGGING_UID16
19705 +       bool    "UID16/GID32"
19706 +       help
19707 +         reduces UID to 16 bit, but leaves GID at 32 bit.
19708 +
19709 +config TAGGING_GID16
19710 +       bool    "UID32/GID16"
19711 +       help
19712 +         reduces GID to 16 bit, but leaves UID at 32 bit.
19713 +
19714 +config TAGGING_ID24
19715 +       bool    "UID24/GID24"
19716 +       help
19717 +         uses the upper 8bit from UID and GID for XID tagging
19718 +         which leaves 24bit for UID/GID each, which should be
19719 +         more than sufficient for normal use.
19720 +
19721 +config TAGGING_INTERN
19722 +       bool    "UID32/GID32"
19723 +       help
19724 +         this uses otherwise reserved inode fields in the on
19725 +         disk representation, which limits the use to a few
19726 +         filesystems (currently ext2 and ext3)
19727 +
19728 +endchoice
19729 +
19730 +config TAG_NFSD
19731 +       bool    "Tag NFSD User Auth and Files"
19732 +       default n
19733 +       help
19734 +         Enable this if you do want the in-kernel NFS
19735 +         Server to use the tagging specified above.
19736 +         (will require patched clients too)
19737 +
19738 +config VSERVER_PRIVACY
19739 +       bool    "Honor Privacy Aspects of Guests"
19740 +       default n
19741 +       help
19742 +         When enabled, most context checks will disallow
19743 +         access to structures assigned to a specific context,
19744 +         like ptys or loop devices.
19745 +
19746 +config VSERVER_CONTEXTS
19747 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
19748 +       range 1 65533
19749 +       default "768"   if 64BIT
19750 +       default "256"
19751 +       help
19752 +         This setting will optimize certain data structures
19753 +         and memory allocations according to the expected
19754 +         maximum.
19755 +
19756 +         note: this is not a strict upper limit.
19757 +
19758 +config VSERVER_WARN
19759 +       bool    "VServer Warnings"
19760 +       default y
19761 +       help
19762 +         This enables various runtime warnings, which will
19763 +         notify about potential manipulation attempts or
19764 +         resource shortage. It is generally considered to
19765 +         be a good idea to have that enabled.
19766 +
19767 +config VSERVER_DEBUG
19768 +       bool    "VServer Debugging Code"
19769 +       default n
19770 +       help
19771 +         Set this to yes if you want to be able to activate
19772 +         debugging output at runtime. It adds a very small
19773 +         overhead to all vserver related functions and
19774 +         increases the kernel size by about 20k.
19775 +
19776 +config VSERVER_HISTORY
19777 +       bool    "VServer History Tracing"
19778 +       depends on VSERVER_DEBUG
19779 +       default n
19780 +       help
19781 +         Set this to yes if you want to record the history of
19782 +         linux-vserver activities, so they can be replayed in
19783 +         the event of a kernel panic or oops.
19784 +
19785 +config VSERVER_HISTORY_SIZE
19786 +       int     "Per-CPU History Size (32-65536)"
19787 +       depends on VSERVER_HISTORY
19788 +       range 32 65536
19789 +       default 64
19790 +       help
19791 +         This allows you to specify the number of entries in
19792 +         the per-CPU history buffer.
19793 +
19794 +config VSERVER_MONITOR
19795 +       bool    "VServer Scheduling Monitor"
19796 +       depends on VSERVER_DEBUG
19797 +       default n
19798 +       help
19799 +         Set this to yes if you want to record the scheduling
19800 +         decisions, so that they can be relayed to userspace
19801 +         for detailed analysis.
19802 +
19803 +config VSERVER_MONITOR_SIZE
19804 +       int     "Per-CPU Monitor Queue Size (32-65536)"
19805 +       depends on VSERVER_MONITOR
19806 +       range 32 65536
19807 +       default 1024
19808 +       help
19809 +         This allows you to specify the number of entries in
19810 +         the per-CPU scheduling monitor buffer.
19811 +
19812 +config VSERVER_MONITOR_SYNC
19813 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
19814 +       depends on VSERVER_MONITOR
19815 +       range 0 65536
19816 +       default 256
19817 +       help
19818 +         This allows you to specify the interval in ticks
19819 +         when a time sync entry is inserted.
19820 +
19821 +endmenu
19822 +
19823 +
19824 +config VSERVER
19825 +       bool
19826 +       default y
19827 +       select UTS_NS
19828 +       select SYSVIPC
19829 +       select IPC_NS
19830 +
19831 +config VSERVER_SECURITY
19832 +       bool
19833 +       depends on SECURITY
19834 +       default y
19835 +       select SECURITY_CAPABILITIES
19836 +
19837 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/Makefile linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Makefile
19838 --- linux-2.6.22.10/kernel/vserver/Makefile     1970-01-01 01:00:00 +0100
19839 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Makefile  2007-10-11 01:10:22 +0200
19840 @@ -0,0 +1,18 @@
19841 +#
19842 +# Makefile for the Linux vserver routines.
19843 +#
19844 +
19845 +
19846 +obj-y          += vserver.o
19847 +
19848 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
19849 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
19850 +                  dlimit.o tag.o
19851 +
19852 +vserver-$(CONFIG_INET) += inet.o
19853 +vserver-$(CONFIG_PROC_FS) += proc.o
19854 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
19855 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
19856 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
19857 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
19858 +
19859 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cacct.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct.c
19860 --- linux-2.6.22.10/kernel/vserver/cacct.c      1970-01-01 01:00:00 +0100
19861 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct.c   2007-08-15 21:54:31 +0200
19862 @@ -0,0 +1,42 @@
19863 +/*
19864 + *  linux/kernel/vserver/cacct.c
19865 + *
19866 + *  Virtual Server: Context Accounting
19867 + *
19868 + *  Copyright (C) 2006-2007 Herbert Pötzl
19869 + *
19870 + *  V0.01  added accounting stats
19871 + *
19872 + */
19873 +
19874 +#include <linux/types.h>
19875 +#include <linux/vs_context.h>
19876 +#include <linux/vserver/cacct_cmd.h>
19877 +#include <linux/vserver/cacct_int.h>
19878 +
19879 +#include <asm/errno.h>
19880 +#include <asm/uaccess.h>
19881 +
19882 +
19883 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
19884 +{
19885 +       struct vcmd_sock_stat_v0 vc_data;
19886 +       int j, field;
19887 +
19888 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19889 +               return -EFAULT;
19890 +
19891 +       field = vc_data.field;
19892 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
19893 +               return -EINVAL;
19894 +
19895 +       for (j = 0; j < 3; j++) {
19896 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
19897 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
19898 +       }
19899 +
19900 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19901 +               return -EFAULT;
19902 +       return 0;
19903 +}
19904 +
19905 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cacct_init.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct_init.h
19906 --- linux-2.6.22.10/kernel/vserver/cacct_init.h 1970-01-01 01:00:00 +0100
19907 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct_init.h      2007-08-05 20:53:13 +0200
19908 @@ -0,0 +1,25 @@
19909 +
19910 +
19911 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
19912 +{
19913 +       int i, j;
19914 +
19915 +
19916 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19917 +               for (j = 0; j < 3; j++) {
19918 +                       atomic_set(&cacct->sock[i][j].count, 0);
19919 +                       atomic_set(&cacct->sock[i][j].total, 0);
19920 +               }
19921 +       }
19922 +       for (i = 0; i < 8; i++)
19923 +               atomic_set(&cacct->slab[i], 0);
19924 +       for (i = 0; i < 5; i++)
19925 +               for (j = 0; j < 4; j++)
19926 +                       atomic_set(&cacct->page[i][j], 0);
19927 +}
19928 +
19929 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
19930 +{
19931 +       return;
19932 +}
19933 +
19934 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cacct_proc.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct_proc.h
19935 --- linux-2.6.22.10/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00 +0100
19936 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct_proc.h      2007-08-05 20:53:13 +0200
19937 @@ -0,0 +1,53 @@
19938 +#ifndef _VX_CACCT_PROC_H
19939 +#define _VX_CACCT_PROC_H
19940 +
19941 +#include <linux/vserver/cacct_int.h>
19942 +
19943 +
19944 +#define VX_SOCKA_TOP   \
19945 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
19946 +
19947 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
19948 +{
19949 +       int i, j, length = 0;
19950 +       static char *type[VXA_SOCK_SIZE] = {
19951 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
19952 +       };
19953 +
19954 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
19955 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19956 +               length += sprintf(buffer + length, "%s:", type[i]);
19957 +               for (j = 0; j < 3; j++) {
19958 +                       length += sprintf(buffer + length,
19959 +                               "\t%10lu/%-10lu",
19960 +                               vx_sock_count(cacct, i, j),
19961 +                               vx_sock_total(cacct, i, j));
19962 +               }
19963 +               buffer[length++] = '\n';
19964 +       }
19965 +
19966 +       length += sprintf(buffer + length, "\n");
19967 +       length += sprintf(buffer + length,
19968 +               "slab:\t %8u %8u %8u %8u\n",
19969 +               atomic_read(&cacct->slab[1]),
19970 +               atomic_read(&cacct->slab[4]),
19971 +               atomic_read(&cacct->slab[0]),
19972 +               atomic_read(&cacct->slab[2]));
19973 +
19974 +       length += sprintf(buffer + length, "\n");
19975 +       for (i = 0; i < 5; i++) {
19976 +               length += sprintf(buffer + length,
19977 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
19978 +                       atomic_read(&cacct->page[i][0]),
19979 +                       atomic_read(&cacct->page[i][1]),
19980 +                       atomic_read(&cacct->page[i][2]),
19981 +                       atomic_read(&cacct->page[i][3]),
19982 +                       atomic_read(&cacct->page[i][4]),
19983 +                       atomic_read(&cacct->page[i][5]),
19984 +                       atomic_read(&cacct->page[i][6]),
19985 +                       atomic_read(&cacct->page[i][7]));
19986 +       }
19987 +       return length;
19988 +}
19989 +
19990 +#endif /* _VX_CACCT_PROC_H */
19991 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/context.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/context.c
19992 --- linux-2.6.22.10/kernel/vserver/context.c    1970-01-01 01:00:00 +0100
19993 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/context.c 2007-10-05 14:54:36 +0200
19994 @@ -0,0 +1,966 @@
19995 +/*
19996 + *  linux/kernel/vserver/context.c
19997 + *
19998 + *  Virtual Server: Context Support
19999 + *
20000 + *  Copyright (C) 2003-2007  Herbert Pötzl
20001 + *
20002 + *  V0.01  context helper
20003 + *  V0.02  vx_ctx_kill syscall command
20004 + *  V0.03  replaced context_info calls
20005 + *  V0.04  redesign of struct (de)alloc
20006 + *  V0.05  rlimit basic implementation
20007 + *  V0.06  task_xid and info commands
20008 + *  V0.07  context flags and caps
20009 + *  V0.08  switch to RCU based hash
20010 + *  V0.09  revert to non RCU for now
20011 + *  V0.10  and back to working RCU hash
20012 + *  V0.11  and back to locking again
20013 + *  V0.12  referenced context store
20014 + *  V0.13  separate per cpu data
20015 + *  V0.14  changed vcmds to vxi arg
20016 + *  V0.15  added context stat
20017 + *  V0.16  have __create claim() the vxi
20018 + *  V0.17  removed older and legacy stuff
20019 + *
20020 + */
20021 +
20022 +#include <linux/slab.h>
20023 +#include <linux/types.h>
20024 +#include <linux/pid_namespace.h>
20025 +
20026 +#include <linux/vserver/context.h>
20027 +#include <linux/vserver/network.h>
20028 +#include <linux/vserver/debug.h>
20029 +#include <linux/vserver/limit.h>
20030 +#include <linux/vserver/limit_int.h>
20031 +#include <linux/vserver/space.h>
20032 +
20033 +#include <linux/vs_context.h>
20034 +#include <linux/vs_limit.h>
20035 +#include <linux/vserver/context_cmd.h>
20036 +
20037 +#include "cvirt_init.h"
20038 +#include "cacct_init.h"
20039 +#include "limit_init.h"
20040 +#include "sched_init.h"
20041 +
20042 +
20043 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
20044 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
20045 +
20046 +
20047 +/*     now inactive context structures */
20048 +
20049 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
20050 +
20051 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
20052 +
20053 +
20054 +/*     __alloc_vx_info()
20055 +
20056 +       * allocate an initialized vx_info struct
20057 +       * doesn't make it visible (hash)                        */
20058 +
20059 +static struct vx_info *__alloc_vx_info(xid_t xid)
20060 +{
20061 +       struct vx_info *new = NULL;
20062 +       int cpu;
20063 +
20064 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
20065 +
20066 +       /* would this benefit from a slab cache? */
20067 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
20068 +       if (!new)
20069 +               return 0;
20070 +
20071 +       memset(new, 0, sizeof(struct vx_info));
20072 +#ifdef CONFIG_SMP
20073 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
20074 +       if (!new->ptr_pc)
20075 +               goto error;
20076 +#endif
20077 +       new->vx_id = xid;
20078 +       INIT_HLIST_NODE(&new->vx_hlist);
20079 +       atomic_set(&new->vx_usecnt, 0);
20080 +       atomic_set(&new->vx_tasks, 0);
20081 +       new->vx_parent = NULL;
20082 +       new->vx_state = 0;
20083 +       init_waitqueue_head(&new->vx_wait);
20084 +
20085 +       /* prepare reaper */
20086 +       get_task_struct(init_pid_ns.child_reaper);
20087 +       new->vx_reaper = init_pid_ns.child_reaper;
20088 +       new->vx_badness_bias = 0;
20089 +
20090 +       /* rest of init goes here */
20091 +       vx_info_init_limit(&new->limit);
20092 +       vx_info_init_sched(&new->sched);
20093 +       vx_info_init_cvirt(&new->cvirt);
20094 +       vx_info_init_cacct(&new->cacct);
20095 +
20096 +       /* per cpu data structures */
20097 +       for_each_possible_cpu(cpu) {
20098 +               vx_info_init_sched_pc(
20099 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
20100 +               vx_info_init_cvirt_pc(
20101 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
20102 +       }
20103 +
20104 +       new->vx_flags = VXF_INIT_SET;
20105 +       new->vx_bcaps = CAP_INIT_EFF_SET;
20106 +       new->vx_ccaps = 0;
20107 +       new->vx_cap_bset = cap_bset;
20108 +
20109 +       new->reboot_cmd = 0;
20110 +       new->exit_code = 0;
20111 +
20112 +       new->vx_nsproxy = copy_nsproxy(current->nsproxy);
20113 +
20114 +       vxdprintk(VXD_CBIT(xid, 0),
20115 +               "alloc_vx_info(%d) = %p", xid, new);
20116 +       vxh_alloc_vx_info(new);
20117 +       atomic_inc(&vx_global_ctotal);
20118 +       return new;
20119 +#ifdef CONFIG_SMP
20120 +error:
20121 +       kfree(new);
20122 +       return 0;
20123 +#endif
20124 +}
20125 +
20126 +/*     __dealloc_vx_info()
20127 +
20128 +       * final disposal of vx_info                             */
20129 +
20130 +static void __dealloc_vx_info(struct vx_info *vxi)
20131 +{
20132 +       int cpu;
20133 +
20134 +       vxdprintk(VXD_CBIT(xid, 0),
20135 +               "dealloc_vx_info(%p)", vxi);
20136 +       vxh_dealloc_vx_info(vxi);
20137 +
20138 +       vxi->vx_id = -1;
20139 +
20140 +       vx_info_exit_limit(&vxi->limit);
20141 +       vx_info_exit_sched(&vxi->sched);
20142 +       vx_info_exit_cvirt(&vxi->cvirt);
20143 +       vx_info_exit_cacct(&vxi->cacct);
20144 +
20145 +       for_each_possible_cpu(cpu) {
20146 +               vx_info_exit_sched_pc(
20147 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
20148 +               vx_info_exit_cvirt_pc(
20149 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
20150 +       }
20151 +
20152 +       vxi->vx_state |= VXS_RELEASED;
20153 +
20154 +#ifdef CONFIG_SMP
20155 +       free_percpu(vxi->ptr_pc);
20156 +#endif
20157 +       kfree(vxi);
20158 +       atomic_dec(&vx_global_ctotal);
20159 +}
20160 +
20161 +static void __shutdown_vx_info(struct vx_info *vxi)
20162 +{
20163 +       struct nsproxy *nsproxy;
20164 +       struct fs_struct *fs;
20165 +
20166 +       might_sleep();
20167 +
20168 +       vxi->vx_state |= VXS_SHUTDOWN;
20169 +       vs_state_change(vxi, VSC_SHUTDOWN);
20170 +
20171 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
20172 +       fs = xchg(&vxi->vx_fs, NULL);
20173 +
20174 +       if (nsproxy)
20175 +               put_nsproxy(nsproxy);
20176 +       if (fs)
20177 +               put_fs_struct(fs);
20178 +}
20179 +
20180 +/* exported stuff */
20181 +
20182 +void free_vx_info(struct vx_info *vxi)
20183 +{
20184 +       unsigned long flags;
20185 +
20186 +       /* check for reference counts first */
20187 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
20188 +       BUG_ON(atomic_read(&vxi->vx_tasks));
20189 +
20190 +       /* context must not be hashed */
20191 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
20192 +
20193 +       /* context shutdown is mandatory */
20194 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
20195 +
20196 +       BUG_ON(vxi->vx_nsproxy);
20197 +       BUG_ON(vxi->vx_fs);
20198 +
20199 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
20200 +       hlist_del(&vxi->vx_hlist);
20201 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
20202 +
20203 +       __dealloc_vx_info(vxi);
20204 +}
20205 +
20206 +
20207 +/*     hash table for vx_info hash */
20208 +
20209 +#define VX_HASH_SIZE   13
20210 +
20211 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
20212 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
20213 +
20214 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20215 +
20216 +
20217 +static inline unsigned int __hashval(xid_t xid)
20218 +{
20219 +       return (xid % VX_HASH_SIZE);
20220 +}
20221 +
20222 +
20223 +
20224 +/*     __hash_vx_info()
20225 +
20226 +       * add the vxi to the global hash table
20227 +       * requires the hash_lock to be held                     */
20228 +
20229 +static inline void __hash_vx_info(struct vx_info *vxi)
20230 +{
20231 +       struct hlist_head *head;
20232 +
20233 +       vxd_assert_lock(&vx_info_hash_lock);
20234 +       vxdprintk(VXD_CBIT(xid, 4),
20235 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
20236 +       vxh_hash_vx_info(vxi);
20237 +
20238 +       /* context must not be hashed */
20239 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
20240 +
20241 +       vxi->vx_state |= VXS_HASHED;
20242 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
20243 +       hlist_add_head(&vxi->vx_hlist, head);
20244 +       atomic_inc(&vx_global_cactive);
20245 +}
20246 +
20247 +/*     __unhash_vx_info()
20248 +
20249 +       * remove the vxi from the global hash table
20250 +       * requires the hash_lock to be held                     */
20251 +
20252 +static inline void __unhash_vx_info(struct vx_info *vxi)
20253 +{
20254 +       unsigned long flags;
20255 +
20256 +       vxd_assert_lock(&vx_info_hash_lock);
20257 +       vxdprintk(VXD_CBIT(xid, 4),
20258 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
20259 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
20260 +       vxh_unhash_vx_info(vxi);
20261 +
20262 +       /* context must be hashed */
20263 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
20264 +       /* but without tasks */
20265 +       BUG_ON(atomic_read(&vxi->vx_tasks));
20266 +
20267 +       vxi->vx_state &= ~VXS_HASHED;
20268 +       hlist_del_init(&vxi->vx_hlist);
20269 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
20270 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
20271 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
20272 +       atomic_dec(&vx_global_cactive);
20273 +}
20274 +
20275 +
20276 +/*     __lookup_vx_info()
20277 +
20278 +       * requires the hash_lock to be held
20279 +       * doesn't increment the vx_refcnt                       */
20280 +
20281 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
20282 +{
20283 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
20284 +       struct hlist_node *pos;
20285 +       struct vx_info *vxi;
20286 +
20287 +       vxd_assert_lock(&vx_info_hash_lock);
20288 +       hlist_for_each(pos, head) {
20289 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20290 +
20291 +               if (vxi->vx_id == xid)
20292 +                       goto found;
20293 +       }
20294 +       vxi = NULL;
20295 +found:
20296 +       vxdprintk(VXD_CBIT(xid, 0),
20297 +               "__lookup_vx_info(#%u): %p[#%u]",
20298 +               xid, vxi, vxi ? vxi->vx_id : 0);
20299 +       vxh_lookup_vx_info(vxi, xid);
20300 +       return vxi;
20301 +}
20302 +
20303 +
20304 +/*     __create_vx_info()
20305 +
20306 +       * create the requested context
20307 +       * get(), claim() and hash it                            */
20308 +
20309 +static struct vx_info *__create_vx_info(int id)
20310 +{
20311 +       struct vx_info *new, *vxi = NULL;
20312 +
20313 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
20314 +
20315 +       if (!(new = __alloc_vx_info(id)))
20316 +               return ERR_PTR(-ENOMEM);
20317 +
20318 +       /* required to make dynamic xids unique */
20319 +       spin_lock(&vx_info_hash_lock);
20320 +
20321 +       /* static context requested */
20322 +       if ((vxi = __lookup_vx_info(id))) {
20323 +               vxdprintk(VXD_CBIT(xid, 0),
20324 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
20325 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20326 +                       vxi = ERR_PTR(-EBUSY);
20327 +               else
20328 +                       vxi = ERR_PTR(-EEXIST);
20329 +               goto out_unlock;
20330 +       }
20331 +       /* new context */
20332 +       vxdprintk(VXD_CBIT(xid, 0),
20333 +               "create_vx_info(%d) = %p (new)", id, new);
20334 +       claim_vx_info(new, NULL);
20335 +       __hash_vx_info(get_vx_info(new));
20336 +       vxi = new, new = NULL;
20337 +
20338 +out_unlock:
20339 +       spin_unlock(&vx_info_hash_lock);
20340 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
20341 +       if (new)
20342 +               __dealloc_vx_info(new);
20343 +       return vxi;
20344 +}
20345 +
20346 +
20347 +/*     exported stuff                                          */
20348 +
20349 +
20350 +void unhash_vx_info(struct vx_info *vxi)
20351 +{
20352 +       __shutdown_vx_info(vxi);
20353 +       spin_lock(&vx_info_hash_lock);
20354 +       __unhash_vx_info(vxi);
20355 +       spin_unlock(&vx_info_hash_lock);
20356 +       __wakeup_vx_info(vxi);
20357 +}
20358 +
20359 +
20360 +/*     lookup_vx_info()
20361 +
20362 +       * search for a vx_info and get() it
20363 +       * negative id means current                             */
20364 +
20365 +struct vx_info *lookup_vx_info(int id)
20366 +{
20367 +       struct vx_info *vxi = NULL;
20368 +
20369 +       if (id < 0) {
20370 +               vxi = get_vx_info(current->vx_info);
20371 +       } else if (id > 1) {
20372 +               spin_lock(&vx_info_hash_lock);
20373 +               vxi = get_vx_info(__lookup_vx_info(id));
20374 +               spin_unlock(&vx_info_hash_lock);
20375 +       }
20376 +       return vxi;
20377 +}
20378 +
20379 +/*     xid_is_hashed()
20380 +
20381 +       * verify that xid is still hashed                       */
20382 +
20383 +int xid_is_hashed(xid_t xid)
20384 +{
20385 +       int hashed;
20386 +
20387 +       spin_lock(&vx_info_hash_lock);
20388 +       hashed = (__lookup_vx_info(xid) != NULL);
20389 +       spin_unlock(&vx_info_hash_lock);
20390 +       return hashed;
20391 +}
20392 +
20393 +#ifdef CONFIG_PROC_FS
20394 +
20395 +/*     get_xid_list()
20396 +
20397 +       * get a subset of hashed xids for proc
20398 +       * assumes size is at least one                          */
20399 +
20400 +int get_xid_list(int index, unsigned int *xids, int size)
20401 +{
20402 +       int hindex, nr_xids = 0;
20403 +
20404 +       /* only show current and children */
20405 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
20406 +               if (index > 0)
20407 +                       return 0;
20408 +               xids[nr_xids] = vx_current_xid();
20409 +               return 1;
20410 +       }
20411 +
20412 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
20413 +               struct hlist_head *head = &vx_info_hash[hindex];
20414 +               struct hlist_node *pos;
20415 +
20416 +               spin_lock(&vx_info_hash_lock);
20417 +               hlist_for_each(pos, head) {
20418 +                       struct vx_info *vxi;
20419 +
20420 +                       if (--index > 0)
20421 +                               continue;
20422 +
20423 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20424 +                       xids[nr_xids] = vxi->vx_id;
20425 +                       if (++nr_xids >= size) {
20426 +                               spin_unlock(&vx_info_hash_lock);
20427 +                               goto out;
20428 +                       }
20429 +               }
20430 +               /* keep the lock time short */
20431 +               spin_unlock(&vx_info_hash_lock);
20432 +       }
20433 +out:
20434 +       return nr_xids;
20435 +}
20436 +#endif
20437 +
20438 +#ifdef CONFIG_VSERVER_DEBUG
20439 +
20440 +void   dump_vx_info_inactive(int level)
20441 +{
20442 +       struct hlist_node *entry, *next;
20443 +
20444 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
20445 +               struct vx_info *vxi =
20446 +                       list_entry(entry, struct vx_info, vx_hlist);
20447 +
20448 +               dump_vx_info(vxi, level);
20449 +       }
20450 +}
20451 +
20452 +#endif
20453 +
20454 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
20455 +{
20456 +       struct user_struct *new_user, *old_user;
20457 +
20458 +       if (!p || !vxi)
20459 +               BUG();
20460 +
20461 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
20462 +               return -EACCES;
20463 +
20464 +       new_user = alloc_uid(vxi->vx_id, p->uid);
20465 +       if (!new_user)
20466 +               return -ENOMEM;
20467 +
20468 +       old_user = p->user;
20469 +       if (new_user != old_user) {
20470 +               atomic_inc(&new_user->processes);
20471 +               atomic_dec(&old_user->processes);
20472 +               p->user = new_user;
20473 +       }
20474 +       free_uid(old_user);
20475 +       return 0;
20476 +}
20477 +
20478 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
20479 +{
20480 +       p->cap_effective &= vxi->vx_cap_bset;
20481 +       p->cap_inheritable &= vxi->vx_cap_bset;
20482 +       p->cap_permitted &= vxi->vx_cap_bset;
20483 +}
20484 +
20485 +
20486 +#include <linux/file.h>
20487 +
20488 +static int vx_openfd_task(struct task_struct *tsk)
20489 +{
20490 +       struct files_struct *files = tsk->files;
20491 +       struct fdtable *fdt;
20492 +       const unsigned long *bptr;
20493 +       int count, total;
20494 +
20495 +       /* no rcu_read_lock() because of spin_lock() */
20496 +       spin_lock(&files->file_lock);
20497 +       fdt = files_fdtable(files);
20498 +       bptr = fdt->open_fds->fds_bits;
20499 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
20500 +       for (total = 0; count > 0; count--) {
20501 +               if (*bptr)
20502 +                       total += hweight_long(*bptr);
20503 +               bptr++;
20504 +       }
20505 +       spin_unlock(&files->file_lock);
20506 +       return total;
20507 +}
20508 +
20509 +
20510 +/*     for *space compatibility */
20511 +
20512 +asmlinkage long sys_unshare(unsigned long);
20513 +
20514 +/*
20515 + *     migrate task to new context
20516 + *     gets vxi, puts old_vxi on change
20517 + *     optionally unshares namespaces (hack)
20518 + */
20519 +
20520 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
20521 +{
20522 +       struct vx_info *old_vxi;
20523 +       int ret = 0;
20524 +
20525 +       if (!p || !vxi)
20526 +               BUG();
20527 +
20528 +       vxdprintk(VXD_CBIT(xid, 5),
20529 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
20530 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
20531 +
20532 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
20533 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20534 +               return -EACCES;
20535 +
20536 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
20537 +               return -EFAULT;
20538 +
20539 +       old_vxi = task_get_vx_info(p);
20540 +       if (old_vxi == vxi)
20541 +               goto out;
20542 +
20543 +       if (!(ret = vx_migrate_user(p, vxi))) {
20544 +               int openfd;
20545 +
20546 +               task_lock(p);
20547 +               openfd = vx_openfd_task(p);
20548 +
20549 +               if (old_vxi) {
20550 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
20551 +                       atomic_dec(&old_vxi->cvirt.nr_running);
20552 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
20553 +                       /* FIXME: what about the struct files here? */
20554 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
20555 +                       /* account for the executable */
20556 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
20557 +               }
20558 +               atomic_inc(&vxi->cvirt.nr_threads);
20559 +               atomic_inc(&vxi->cvirt.nr_running);
20560 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
20561 +               /* FIXME: what about the struct files here? */
20562 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
20563 +               /* account for the executable */
20564 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
20565 +
20566 +               if (old_vxi) {
20567 +                       release_vx_info(old_vxi, p);
20568 +                       clr_vx_info(&p->vx_info);
20569 +               }
20570 +               claim_vx_info(vxi, p);
20571 +               set_vx_info(&p->vx_info, vxi);
20572 +               p->xid = vxi->vx_id;
20573 +
20574 +               vxdprintk(VXD_CBIT(xid, 5),
20575 +                       "moved task %p into vxi:%p[#%d]",
20576 +                       p, vxi, vxi->vx_id);
20577 +
20578 +               vx_mask_cap_bset(vxi, p);
20579 +               task_unlock(p);
20580 +
20581 +               /* hack for *spaces to provide compatibility */
20582 +               if (unshare) {
20583 +                       struct nsproxy *old_nsp, *new_nsp;
20584 +
20585 +                       ret = unshare_nsproxy_namespaces(
20586 +                               CLONE_NEWUTS | CLONE_NEWIPC,
20587 +                               &new_nsp, NULL);
20588 +                       if (ret)
20589 +                               goto out;
20590 +
20591 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
20592 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC);
20593 +                       put_nsproxy(old_nsp);
20594 +               }
20595 +       }
20596 +out:
20597 +       put_vx_info(old_vxi);
20598 +       return ret;
20599 +}
20600 +
20601 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
20602 +{
20603 +       struct task_struct *old_reaper;
20604 +
20605 +       if (!vxi)
20606 +               return -EINVAL;
20607 +
20608 +       vxdprintk(VXD_CBIT(xid, 6),
20609 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
20610 +               vxi, vxi->vx_id, p, p->xid, p->pid);
20611 +
20612 +       old_reaper = vxi->vx_reaper;
20613 +       if (old_reaper == p)
20614 +               return 0;
20615 +
20616 +       /* set new child reaper */
20617 +       get_task_struct(p);
20618 +       vxi->vx_reaper = p;
20619 +       put_task_struct(old_reaper);
20620 +       return 0;
20621 +}
20622 +
20623 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
20624 +{
20625 +       if (!vxi)
20626 +               return -EINVAL;
20627 +
20628 +       vxdprintk(VXD_CBIT(xid, 6),
20629 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
20630 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20631 +
20632 +       vxi->vx_flags &= ~VXF_STATE_INIT;
20633 +       vxi->vx_initpid = p->tgid;
20634 +       return 0;
20635 +}
20636 +
20637 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
20638 +{
20639 +       vxdprintk(VXD_CBIT(xid, 6),
20640 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
20641 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20642 +
20643 +       vxi->exit_code = code;
20644 +       vxi->vx_initpid = 0;
20645 +}
20646 +
20647 +
20648 +void vx_set_persistent(struct vx_info *vxi)
20649 +{
20650 +       vxdprintk(VXD_CBIT(xid, 6),
20651 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
20652 +
20653 +       get_vx_info(vxi);
20654 +       claim_vx_info(vxi, NULL);
20655 +}
20656 +
20657 +void vx_clear_persistent(struct vx_info *vxi)
20658 +{
20659 +       vxdprintk(VXD_CBIT(xid, 6),
20660 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
20661 +
20662 +       release_vx_info(vxi, NULL);
20663 +       put_vx_info(vxi);
20664 +}
20665 +
20666 +void vx_update_persistent(struct vx_info *vxi)
20667 +{
20668 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
20669 +               vx_set_persistent(vxi);
20670 +       else
20671 +               vx_clear_persistent(vxi);
20672 +}
20673 +
20674 +
20675 +/*     task must be current or locked          */
20676 +
20677 +void   exit_vx_info(struct task_struct *p, int code)
20678 +{
20679 +       struct vx_info *vxi = p->vx_info;
20680 +
20681 +       if (vxi) {
20682 +               atomic_dec(&vxi->cvirt.nr_threads);
20683 +               vx_nproc_dec(p);
20684 +
20685 +               vxi->exit_code = code;
20686 +               release_vx_info(vxi, p);
20687 +       }
20688 +}
20689 +
20690 +void   exit_vx_info_early(struct task_struct *p, int code)
20691 +{
20692 +       struct vx_info *vxi = p->vx_info;
20693 +
20694 +       if (vxi) {
20695 +               if (vxi->vx_initpid == p->tgid)
20696 +                       vx_exit_init(vxi, p, code);
20697 +               if (vxi->vx_reaper == p)
20698 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
20699 +       }
20700 +}
20701 +
20702 +
20703 +/* vserver syscall commands below here */
20704 +
20705 +/* taks xid and vx_info functions */
20706 +
20707 +#include <asm/uaccess.h>
20708 +
20709 +
20710 +int vc_task_xid(uint32_t id)
20711 +{
20712 +       xid_t xid;
20713 +
20714 +       if (id) {
20715 +               struct task_struct *tsk;
20716 +
20717 +               read_lock(&tasklist_lock);
20718 +               tsk = find_task_by_real_pid(id);
20719 +               xid = (tsk) ? tsk->xid : -ESRCH;
20720 +               read_unlock(&tasklist_lock);
20721 +       } else
20722 +               xid = vx_current_xid();
20723 +       return xid;
20724 +}
20725 +
20726 +
20727 +int vc_vx_info(struct vx_info *vxi, void __user *data)
20728 +{
20729 +       struct vcmd_vx_info_v0 vc_data;
20730 +
20731 +       vc_data.xid = vxi->vx_id;
20732 +       vc_data.initpid = vxi->vx_initpid;
20733 +
20734 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20735 +               return -EFAULT;
20736 +       return 0;
20737 +}
20738 +
20739 +
20740 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
20741 +{
20742 +       struct vcmd_ctx_stat_v0 vc_data;
20743 +
20744 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
20745 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
20746 +
20747 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20748 +               return -EFAULT;
20749 +       return 0;
20750 +}
20751 +
20752 +
20753 +/* context functions */
20754 +
20755 +int vc_ctx_create(uint32_t xid, void __user *data)
20756 +{
20757 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
20758 +       struct vx_info *new_vxi;
20759 +       int ret;
20760 +
20761 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20762 +               return -EFAULT;
20763 +
20764 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
20765 +               return -EINVAL;
20766 +
20767 +       new_vxi = __create_vx_info(xid);
20768 +       if (IS_ERR(new_vxi))
20769 +               return PTR_ERR(new_vxi);
20770 +
20771 +       /* initial flags */
20772 +       new_vxi->vx_flags = vc_data.flagword;
20773 +
20774 +       ret = -ENOEXEC;
20775 +       if (vs_state_change(new_vxi, VSC_STARTUP))
20776 +               goto out;
20777 +
20778 +       ret = vx_migrate_task(current, new_vxi, (!data));
20779 +       if (ret)
20780 +               goto out;
20781 +
20782 +       /* return context id on success */
20783 +       ret = new_vxi->vx_id;
20784 +
20785 +       /* get a reference for persistent contexts */
20786 +       if ((vc_data.flagword & VXF_PERSISTENT))
20787 +               vx_set_persistent(new_vxi);
20788 +out:
20789 +       release_vx_info(new_vxi, NULL);
20790 +       put_vx_info(new_vxi);
20791 +       return ret;
20792 +}
20793 +
20794 +
20795 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
20796 +{
20797 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
20798 +       int ret;
20799 +
20800 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20801 +               return -EFAULT;
20802 +
20803 +       ret = vx_migrate_task(current, vxi, 0);
20804 +       if (ret)
20805 +               return ret;
20806 +       if (vc_data.flagword & VXM_SET_INIT)
20807 +               ret = vx_set_init(vxi, current);
20808 +       if (ret)
20809 +               return ret;
20810 +       if (vc_data.flagword & VXM_SET_REAPER)
20811 +               ret = vx_set_reaper(vxi, current);
20812 +       return ret;
20813 +}
20814 +
20815 +
20816 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
20817 +{
20818 +       struct vcmd_ctx_flags_v0 vc_data;
20819 +
20820 +       vc_data.flagword = vxi->vx_flags;
20821 +
20822 +       /* special STATE flag handling */
20823 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
20824 +
20825 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20826 +               return -EFAULT;
20827 +       return 0;
20828 +}
20829 +
20830 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
20831 +{
20832 +       struct vcmd_ctx_flags_v0 vc_data;
20833 +       uint64_t mask, trigger;
20834 +
20835 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20836 +               return -EFAULT;
20837 +
20838 +       /* special STATE flag handling */
20839 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
20840 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
20841 +
20842 +       if (vxi == current->vx_info) {
20843 +               if (trigger & VXF_STATE_SETUP)
20844 +                       vx_mask_cap_bset(vxi, current);
20845 +               if (trigger & VXF_STATE_INIT) {
20846 +                       int ret;
20847 +
20848 +                       ret = vx_set_init(vxi, current);
20849 +                       if (ret)
20850 +                               return ret;
20851 +                       ret = vx_set_reaper(vxi, current);
20852 +                       if (ret)
20853 +                               return ret;
20854 +               }
20855 +       }
20856 +
20857 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
20858 +               vc_data.flagword, mask);
20859 +       if (trigger & VXF_PERSISTENT)
20860 +               vx_update_persistent(vxi);
20861 +
20862 +       return 0;
20863 +}
20864 +
20865 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
20866 +{
20867 +       if (bcaps)
20868 +               *bcaps = vxi->vx_bcaps;
20869 +       if (ccaps)
20870 +               *ccaps = vxi->vx_ccaps;
20871 +
20872 +       return 0;
20873 +}
20874 +
20875 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
20876 +{
20877 +       struct vcmd_ctx_caps_v1 vc_data;
20878 +       int ret;
20879 +
20880 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
20881 +       if (ret)
20882 +               return ret;
20883 +       vc_data.cmask = ~0ULL;
20884 +
20885 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20886 +               return -EFAULT;
20887 +       return 0;
20888 +}
20889 +
20890 +static int do_set_caps(struct vx_info *vxi,
20891 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
20892 +{
20893 +       vxi->vx_bcaps = vs_mask_flags(vxi->vx_bcaps, bcaps, bmask);
20894 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
20895 +
20896 +       return 0;
20897 +}
20898 +
20899 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
20900 +{
20901 +       struct vcmd_ctx_caps_v1 vc_data;
20902 +
20903 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20904 +               return -EFAULT;
20905 +
20906 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
20907 +}
20908 +
20909 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
20910 +{
20911 +       struct vcmd_bcaps vc_data;
20912 +       int ret;
20913 +
20914 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
20915 +       if (ret)
20916 +               return ret;
20917 +       vc_data.bmask = ~0ULL;
20918 +
20919 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20920 +               return -EFAULT;
20921 +       return 0;
20922 +}
20923 +
20924 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
20925 +{
20926 +       struct vcmd_bcaps vc_data;
20927 +
20928 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20929 +               return -EFAULT;
20930 +
20931 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
20932 +}
20933 +
20934 +
20935 +int vc_get_badness(struct vx_info *vxi, void __user *data)
20936 +{
20937 +       struct vcmd_badness_v0 vc_data;
20938 +
20939 +       vc_data.bias = vxi->vx_badness_bias;
20940 +
20941 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20942 +               return -EFAULT;
20943 +       return 0;
20944 +}
20945 +
20946 +int vc_set_badness(struct vx_info *vxi, void __user *data)
20947 +{
20948 +       struct vcmd_badness_v0 vc_data;
20949 +
20950 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20951 +               return -EFAULT;
20952 +
20953 +       vxi->vx_badness_bias = vc_data.bias;
20954 +       return 0;
20955 +}
20956 +
20957 +#include <linux/module.h>
20958 +
20959 +EXPORT_SYMBOL_GPL(free_vx_info);
20960 +
20961 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cvirt.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt.c
20962 --- linux-2.6.22.10/kernel/vserver/cvirt.c      1970-01-01 01:00:00 +0100
20963 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt.c   2007-08-15 22:00:34 +0200
20964 @@ -0,0 +1,300 @@
20965 +/*
20966 + *  linux/kernel/vserver/cvirt.c
20967 + *
20968 + *  Virtual Server: Context Virtualization
20969 + *
20970 + *  Copyright (C) 2004-2007  Herbert Pötzl
20971 + *
20972 + *  V0.01  broken out from limit.c
20973 + *  V0.02  added utsname stuff
20974 + *  V0.03  changed vcmds to vxi arg
20975 + *
20976 + */
20977 +
20978 +#include <linux/types.h>
20979 +#include <linux/vs_cvirt.h>
20980 +#include <linux/vserver/switch.h>
20981 +#include <linux/vserver/cvirt_cmd.h>
20982 +
20983 +#include <asm/uaccess.h>
20984 +
20985 +
20986 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
20987 +{
20988 +       struct vx_info *vxi = current->vx_info;
20989 +
20990 +       set_normalized_timespec(uptime,
20991 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
20992 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
20993 +       if (!idle)
20994 +               return;
20995 +       set_normalized_timespec(idle,
20996 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
20997 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
20998 +       return;
20999 +}
21000 +
21001 +uint64_t vx_idle_jiffies(void)
21002 +{
21003 +       return init_task.utime + init_task.stime;
21004 +}
21005 +
21006 +
21007 +
21008 +static inline uint32_t __update_loadavg(uint32_t load,
21009 +       int wsize, int delta, int n)
21010 +{
21011 +       unsigned long long calc, prev;
21012 +
21013 +       /* just set it to n */
21014 +       if (unlikely(delta >= wsize))
21015 +               return (n << FSHIFT);
21016 +
21017 +       calc = delta * n;
21018 +       calc <<= FSHIFT;
21019 +       prev = (wsize - delta);
21020 +       prev *= load;
21021 +       calc += prev;
21022 +       do_div(calc, wsize);
21023 +       return calc;
21024 +}
21025 +
21026 +
21027 +void vx_update_load(struct vx_info *vxi)
21028 +{
21029 +       uint32_t now, last, delta;
21030 +       unsigned int nr_running, nr_uninterruptible;
21031 +       unsigned int total;
21032 +       unsigned long flags;
21033 +
21034 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
21035 +
21036 +       now = jiffies;
21037 +       last = vxi->cvirt.load_last;
21038 +       delta = now - last;
21039 +
21040 +       if (delta < 5*HZ)
21041 +               goto out;
21042 +
21043 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
21044 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
21045 +       total = nr_running + nr_uninterruptible;
21046 +
21047 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
21048 +               60*HZ, delta, total);
21049 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
21050 +               5*60*HZ, delta, total);
21051 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
21052 +               15*60*HZ, delta, total);
21053 +
21054 +       vxi->cvirt.load_last = now;
21055 +out:
21056 +       atomic_inc(&vxi->cvirt.load_updates);
21057 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
21058 +}
21059 +
21060 +
21061 +/*
21062 + * Commands to do_syslog:
21063 + *
21064 + *      0 -- Close the log.  Currently a NOP.
21065 + *      1 -- Open the log. Currently a NOP.
21066 + *      2 -- Read from the log.
21067 + *      3 -- Read all messages remaining in the ring buffer.
21068 + *      4 -- Read and clear all messages remaining in the ring buffer
21069 + *      5 -- Clear ring buffer.
21070 + *      6 -- Disable printk's to console
21071 + *      7 -- Enable printk's to console
21072 + *      8 -- Set level of messages printed to console
21073 + *      9 -- Return number of unread characters in the log buffer
21074 + *     10 -- Return size of the log buffer
21075 + */
21076 +int vx_do_syslog(int type, char __user *buf, int len)
21077 +{
21078 +       int error = 0;
21079 +       int do_clear = 0;
21080 +       struct vx_info *vxi = current->vx_info;
21081 +       struct _vx_syslog *log;
21082 +
21083 +       if (!vxi)
21084 +               return -EINVAL;
21085 +       log = &vxi->cvirt.syslog;
21086 +
21087 +       switch (type) {
21088 +       case 0:         /* Close log */
21089 +       case 1:         /* Open log */
21090 +               break;
21091 +       case 2:         /* Read from log */
21092 +               error = wait_event_interruptible(log->log_wait,
21093 +                       (log->log_start - log->log_end));
21094 +               if (error)
21095 +                       break;
21096 +               spin_lock_irq(&log->logbuf_lock);
21097 +               spin_unlock_irq(&log->logbuf_lock);
21098 +               break;
21099 +       case 4:         /* Read/clear last kernel messages */
21100 +               do_clear = 1;
21101 +               /* fall through */
21102 +       case 3:         /* Read last kernel messages */
21103 +               return 0;
21104 +
21105 +       case 5:         /* Clear ring buffer */
21106 +               return 0;
21107 +
21108 +       case 6:         /* Disable logging to console */
21109 +       case 7:         /* Enable logging to console */
21110 +       case 8:         /* Set level of messages printed to console */
21111 +               break;
21112 +
21113 +       case 9:         /* Number of chars in the log buffer */
21114 +               return 0;
21115 +       case 10:        /* Size of the log buffer */
21116 +               return 0;
21117 +       default:
21118 +               error = -EINVAL;
21119 +               break;
21120 +       }
21121 +       return error;
21122 +}
21123 +
21124 +
21125 +/* virtual host info names */
21126 +
21127 +static char *vx_vhi_name(struct vx_info *vxi, int id)
21128 +{
21129 +       struct nsproxy *nsproxy;
21130 +       struct uts_namespace *uts;
21131 +
21132 +
21133 +       if (id == VHIN_CONTEXT)
21134 +               return vxi->vx_name;
21135 +
21136 +       nsproxy = vxi->vx_nsproxy;
21137 +       if (!nsproxy)
21138 +               return NULL;
21139 +
21140 +       uts = nsproxy->uts_ns;
21141 +       if (!uts)
21142 +               return NULL;
21143 +
21144 +       switch (id) {
21145 +       case VHIN_SYSNAME:
21146 +               return uts->name.sysname;
21147 +       case VHIN_NODENAME:
21148 +               return uts->name.nodename;
21149 +       case VHIN_RELEASE:
21150 +               return uts->name.release;
21151 +       case VHIN_VERSION:
21152 +               return uts->name.version;
21153 +       case VHIN_MACHINE:
21154 +               return uts->name.machine;
21155 +       case VHIN_DOMAINNAME:
21156 +               return uts->name.domainname;
21157 +       default:
21158 +               return NULL;
21159 +       }
21160 +       return NULL;
21161 +}
21162 +
21163 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
21164 +{
21165 +       struct vcmd_vhi_name_v0 vc_data;
21166 +       char *name;
21167 +
21168 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21169 +               return -EFAULT;
21170 +
21171 +       name = vx_vhi_name(vxi, vc_data.field);
21172 +       if (!name)
21173 +               return -EINVAL;
21174 +
21175 +       memcpy(name, vc_data.name, 65);
21176 +       return 0;
21177 +}
21178 +
21179 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
21180 +{
21181 +       struct vcmd_vhi_name_v0 vc_data;
21182 +       char *name;
21183 +
21184 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21185 +               return -EFAULT;
21186 +
21187 +       name = vx_vhi_name(vxi, vc_data.field);
21188 +       if (!name)
21189 +               return -EINVAL;
21190 +
21191 +       memcpy(vc_data.name, name, 65);
21192 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21193 +               return -EFAULT;
21194 +       return 0;
21195 +}
21196 +
21197 +
21198 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
21199 +{
21200 +       struct vcmd_virt_stat_v0 vc_data;
21201 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
21202 +       struct timespec uptime;
21203 +
21204 +       do_posix_clock_monotonic_gettime(&uptime);
21205 +       set_normalized_timespec(&uptime,
21206 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
21207 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
21208 +
21209 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
21210 +       vc_data.uptime = timespec_to_ns(&uptime);
21211 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
21212 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
21213 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
21214 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
21215 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
21216 +       vc_data.load[0] = cvirt->load[0];
21217 +       vc_data.load[1] = cvirt->load[1];
21218 +       vc_data.load[2] = cvirt->load[2];
21219 +
21220 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21221 +               return -EFAULT;
21222 +       return 0;
21223 +}
21224 +
21225 +
21226 +#ifdef CONFIG_VSERVER_VTIME
21227 +
21228 +/* virtualized time base */
21229 +
21230 +void vx_gettimeofday(struct timeval *tv)
21231 +{
21232 +       do_gettimeofday(tv);
21233 +       if (!vx_flags(VXF_VIRT_TIME, 0))
21234 +               return;
21235 +
21236 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
21237 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
21238 +
21239 +       if (tv->tv_usec >= USEC_PER_SEC) {
21240 +               tv->tv_sec++;
21241 +               tv->tv_usec -= USEC_PER_SEC;
21242 +       } else if (tv->tv_usec < 0) {
21243 +               tv->tv_sec--;
21244 +               tv->tv_usec += USEC_PER_SEC;
21245 +       }
21246 +}
21247 +
21248 +int vx_settimeofday(struct timespec *ts)
21249 +{
21250 +       struct timeval tv;
21251 +
21252 +       if (!vx_flags(VXF_VIRT_TIME, 0))
21253 +               return do_settimeofday(ts);
21254 +
21255 +       do_gettimeofday(&tv);
21256 +       current->vx_info->cvirt.bias_tv.tv_sec =
21257 +               ts->tv_sec - tv.tv_sec;
21258 +       current->vx_info->cvirt.bias_tv.tv_usec =
21259 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
21260 +       return 0;
21261 +}
21262 +
21263 +#endif
21264 +
21265 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cvirt_init.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt_init.h
21266 --- linux-2.6.22.10/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00 +0100
21267 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt_init.h      2007-10-25 17:05:55 +0200
21268 @@ -0,0 +1,69 @@
21269 +
21270 +
21271 +extern uint64_t vx_idle_jiffies(void);
21272 +
21273 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
21274 +{
21275 +       uint64_t idle_jiffies = vx_idle_jiffies();
21276 +       uint64_t nsuptime;
21277 +
21278 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
21279 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
21280 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
21281 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
21282 +       cvirt->bias_tv.tv_sec = 0;
21283 +       cvirt->bias_tv.tv_usec = 0;
21284 +
21285 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
21286 +       atomic_set(&cvirt->nr_threads, 0);
21287 +       atomic_set(&cvirt->nr_running, 0);
21288 +       atomic_set(&cvirt->nr_uninterruptible, 0);
21289 +       atomic_set(&cvirt->nr_onhold, 0);
21290 +
21291 +       spin_lock_init(&cvirt->load_lock);
21292 +       cvirt->load_last = jiffies;
21293 +       atomic_set(&cvirt->load_updates, 0);
21294 +       cvirt->load[0] = 0;
21295 +       cvirt->load[1] = 0;
21296 +       cvirt->load[2] = 0;
21297 +       atomic_set(&cvirt->total_forks, 0);
21298 +
21299 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
21300 +       init_waitqueue_head(&cvirt->syslog.log_wait);
21301 +       cvirt->syslog.log_start = 0;
21302 +       cvirt->syslog.log_end = 0;
21303 +       cvirt->syslog.con_start = 0;
21304 +       cvirt->syslog.logged_chars = 0;
21305 +}
21306 +
21307 +static inline
21308 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
21309 +{
21310 +       // cvirt_pc->cpustat = { 0 };
21311 +}
21312 +
21313 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
21314 +{
21315 +       int value;
21316 +
21317 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
21318 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
21319 +               cvirt, value);
21320 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
21321 +               "!!! cvirt: %p[nr_running] = %d on exit.",
21322 +               cvirt, value);
21323 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
21324 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
21325 +               cvirt, value);
21326 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
21327 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
21328 +               cvirt, value);
21329 +       return;
21330 +}
21331 +
21332 +static inline
21333 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
21334 +{
21335 +       return;
21336 +}
21337 +
21338 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cvirt_proc.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt_proc.h
21339 --- linux-2.6.22.10/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00 +0100
21340 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt_proc.h      2007-08-05 20:53:13 +0200
21341 @@ -0,0 +1,133 @@
21342 +#ifndef _VX_CVIRT_PROC_H
21343 +#define _VX_CVIRT_PROC_H
21344 +
21345 +#include <linux/nsproxy.h>
21346 +#include <linux/mnt_namespace.h>
21347 +#include <linux/utsname.h>
21348 +#include <linux/ipc.h>
21349 +
21350 +
21351 +static inline
21352 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
21353 +{
21354 +       struct mnt_namespace *ns;
21355 +       struct uts_namespace *uts;
21356 +       struct ipc_namespace *ipc;
21357 +       struct vfsmount *mnt;
21358 +       char *path, *root;
21359 +       int length = 0;
21360 +
21361 +       if (!nsproxy)
21362 +               goto out;
21363 +
21364 +       length += sprintf(buffer + length,
21365 +               "NSProxy:\t%p [%p,%p,%p]\n",
21366 +               nsproxy, nsproxy->mnt_ns,
21367 +               nsproxy->uts_ns, nsproxy->ipc_ns);
21368 +
21369 +       ns = nsproxy->mnt_ns;
21370 +       if (!ns)
21371 +               goto skip_ns;
21372 +
21373 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
21374 +       if (!path)
21375 +               goto skip_ns;
21376 +
21377 +       mnt = ns->root;
21378 +       root = d_path(mnt->mnt_root, mnt->mnt_parent, path, PATH_MAX - 2);
21379 +       length += sprintf(buffer + length,
21380 +               "Namespace:\t%p [#%u]\n"
21381 +               "RootPath:\t%s\n",
21382 +               ns, atomic_read(&ns->count),
21383 +               root);
21384 +       kfree(path);
21385 +skip_ns:
21386 +
21387 +       uts = nsproxy->uts_ns;
21388 +       if (!uts)
21389 +               goto skip_uts;
21390 +
21391 +       length += sprintf(buffer + length,
21392 +               "SysName:\t%.*s\n"
21393 +               "NodeName:\t%.*s\n"
21394 +               "Release:\t%.*s\n"
21395 +               "Version:\t%.*s\n"
21396 +               "Machine:\t%.*s\n"
21397 +               "DomainName:\t%.*s\n",
21398 +               __NEW_UTS_LEN, uts->name.sysname,
21399 +               __NEW_UTS_LEN, uts->name.nodename,
21400 +               __NEW_UTS_LEN, uts->name.release,
21401 +               __NEW_UTS_LEN, uts->name.version,
21402 +               __NEW_UTS_LEN, uts->name.machine,
21403 +               __NEW_UTS_LEN, uts->name.domainname);
21404 +skip_uts:
21405 +
21406 +       ipc = nsproxy->ipc_ns;
21407 +       if (!ipc)
21408 +               goto skip_ipc;
21409 +
21410 +       length += sprintf(buffer + length,
21411 +               "SEMS:\t\t%d %d %d %d  %d\n"
21412 +               "MSG:\t\t%d %d %d\n"
21413 +               "SHM:\t\t%lu %lu  %d %d\n",
21414 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
21415 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
21416 +               ipc->used_sems,
21417 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
21418 +               (unsigned long)ipc->shm_ctlmax,
21419 +               (unsigned long)ipc->shm_ctlall,
21420 +               ipc->shm_ctlmni, ipc->shm_tot);
21421 +skip_ipc:
21422 +out:
21423 +       return length;
21424 +}
21425 +
21426 +
21427 +#include <linux/sched.h>
21428 +
21429 +#define LOAD_INT(x) ((x) >> FSHIFT)
21430 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
21431 +
21432 +static inline
21433 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
21434 +{
21435 +       int length = 0;
21436 +       int a, b, c;
21437 +
21438 +       length += sprintf(buffer + length,
21439 +               "BiasUptime:\t%lu.%02lu\n",
21440 +               (unsigned long)cvirt->bias_uptime.tv_sec,
21441 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
21442 +
21443 +       a = cvirt->load[0] + (FIXED_1 / 200);
21444 +       b = cvirt->load[1] + (FIXED_1 / 200);
21445 +       c = cvirt->load[2] + (FIXED_1 / 200);
21446 +       length += sprintf(buffer + length,
21447 +               "nr_threads:\t%d\n"
21448 +               "nr_running:\t%d\n"
21449 +               "nr_unintr:\t%d\n"
21450 +               "nr_onhold:\t%d\n"
21451 +               "load_updates:\t%d\n"
21452 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
21453 +               "total_forks:\t%d\n",
21454 +               atomic_read(&cvirt->nr_threads),
21455 +               atomic_read(&cvirt->nr_running),
21456 +               atomic_read(&cvirt->nr_uninterruptible),
21457 +               atomic_read(&cvirt->nr_onhold),
21458 +               atomic_read(&cvirt->load_updates),
21459 +               LOAD_INT(a), LOAD_FRAC(a),
21460 +               LOAD_INT(b), LOAD_FRAC(b),
21461 +               LOAD_INT(c), LOAD_FRAC(c),
21462 +               atomic_read(&cvirt->total_forks));
21463 +       return length;
21464 +}
21465 +
21466 +static inline
21467 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
21468 +       char *buffer, int cpu)
21469 +{
21470 +       int length = 0;
21471 +       return length;
21472 +}
21473 +
21474 +#endif /* _VX_CVIRT_PROC_H */
21475 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/debug.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/debug.c
21476 --- linux-2.6.22.10/kernel/vserver/debug.c      1970-01-01 01:00:00 +0100
21477 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/debug.c   2007-10-01 14:57:41 +0200
21478 @@ -0,0 +1,32 @@
21479 +/*
21480 + *  kernel/vserver/debug.c
21481 + *
21482 + *  Copyright (C) 2005-2007 Herbert Pötzl
21483 + *
21484 + *  V0.01  vx_info dump support
21485 + *
21486 + */
21487 +
21488 +#include <linux/module.h>
21489 +
21490 +#include <linux/vserver/context.h>
21491 +
21492 +
21493 +void   dump_vx_info(struct vx_info *vxi, int level)
21494 +{
21495 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
21496 +               atomic_read(&vxi->vx_usecnt),
21497 +               atomic_read(&vxi->vx_tasks),
21498 +               vxi->vx_state);
21499 +       if (level > 0) {
21500 +               __dump_vx_limit(&vxi->limit);
21501 +               __dump_vx_sched(&vxi->sched);
21502 +               __dump_vx_cvirt(&vxi->cvirt);
21503 +               __dump_vx_cacct(&vxi->cacct);
21504 +       }
21505 +       printk("---\n");
21506 +}
21507 +
21508 +
21509 +EXPORT_SYMBOL_GPL(dump_vx_info);
21510 +
21511 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/device.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/device.c
21512 --- linux-2.6.22.10/kernel/vserver/device.c     1970-01-01 01:00:00 +0100
21513 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/device.c  2007-10-11 01:10:22 +0200
21514 @@ -0,0 +1,443 @@
21515 +/*
21516 + *  linux/kernel/vserver/device.c
21517 + *
21518 + *  Linux-VServer: Device Support
21519 + *
21520 + *  Copyright (C) 2006  Herbert Pötzl
21521 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
21522 + *
21523 + *  V0.01  device mapping basics
21524 + *  V0.02  added defaults
21525 + *
21526 + */
21527 +
21528 +#include <linux/slab.h>
21529 +#include <linux/rcupdate.h>
21530 +#include <linux/fs.h>
21531 +#include <linux/namei.h>
21532 +#include <linux/hash.h>
21533 +
21534 +#include <asm/errno.h>
21535 +#include <asm/uaccess.h>
21536 +#include <linux/vserver/base.h>
21537 +#include <linux/vserver/debug.h>
21538 +#include <linux/vserver/context.h>
21539 +#include <linux/vserver/device.h>
21540 +#include <linux/vserver/device_cmd.h>
21541 +
21542 +
21543 +#define DMAP_HASH_BITS 4
21544 +
21545 +
21546 +struct vs_mapping {
21547 +       union {
21548 +               struct hlist_node hlist;
21549 +               struct list_head list;
21550 +       } u;
21551 +#define dm_hlist       u.hlist
21552 +#define dm_list                u.list
21553 +       xid_t xid;
21554 +       dev_t device;
21555 +       struct vx_dmap_target target;
21556 +};
21557 +
21558 +
21559 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
21560 +
21561 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
21562 +
21563 +static struct vx_dmap_target dmap_defaults[2] = {
21564 +       { .flags = DATTR_OPEN },
21565 +       { .flags = DATTR_OPEN },
21566 +};
21567 +
21568 +
21569 +struct kmem_cache *dmap_cachep __read_mostly;
21570 +
21571 +int __init dmap_cache_init(void)
21572 +{
21573 +       dmap_cachep = kmem_cache_create("dmap_cache",
21574 +               sizeof(struct vs_mapping), 0,
21575 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
21576 +       return 0;
21577 +}
21578 +
21579 +__initcall(dmap_cache_init);
21580 +
21581 +
21582 +static inline unsigned int __hashval(dev_t dev, int bits)
21583 +{
21584 +       return hash_long((unsigned long)dev, bits);
21585 +}
21586 +
21587 +
21588 +/*     __hash_mapping()
21589 + *     add the mapping to the hash table
21590 + */
21591 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
21592 +{
21593 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21594 +       struct hlist_head *head, *hash = dmap_main_hash;
21595 +       int device = vdm->device;
21596 +
21597 +       spin_lock(hash_lock);
21598 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
21599 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
21600 +
21601 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
21602 +       hlist_add_head(&vdm->dm_hlist, head);
21603 +       spin_unlock(hash_lock);
21604 +}
21605 +
21606 +
21607 +static inline int __mode_to_default(umode_t mode)
21608 +{
21609 +       switch (mode) {
21610 +       case S_IFBLK:
21611 +               return 0;
21612 +       case S_IFCHR:
21613 +               return 1;
21614 +       default:
21615 +               BUG();
21616 +       }
21617 +}
21618 +
21619 +
21620 +/*     __set_default()
21621 + *     set a default
21622 + */
21623 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
21624 +       struct vx_dmap_target *vdmt)
21625 +{
21626 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21627 +       spin_lock(hash_lock);
21628 +
21629 +       if (vxi)
21630 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
21631 +       else
21632 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
21633 +
21634 +
21635 +       spin_unlock(hash_lock);
21636 +
21637 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
21638 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
21639 +}
21640 +
21641 +
21642 +/*     __remove_default()
21643 + *     remove a default
21644 + */
21645 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
21646 +{
21647 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21648 +       spin_lock(hash_lock);
21649 +
21650 +       if (vxi)
21651 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
21652 +       else    /* remove == reset */
21653 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
21654 +
21655 +       spin_unlock(hash_lock);
21656 +       return 0;
21657 +}
21658 +
21659 +
21660 +/*     __find_mapping()
21661 + *     find a mapping in the hash table
21662 + *
21663 + *     caller must hold hash_lock
21664 + */
21665 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
21666 +       struct vs_mapping **local, struct vs_mapping **global)
21667 +{
21668 +       struct hlist_head *hash = dmap_main_hash;
21669 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
21670 +       struct hlist_node *pos;
21671 +       struct vs_mapping *vdm;
21672 +
21673 +       *local = NULL;
21674 +       if (global)
21675 +               *global = NULL;
21676 +
21677 +       hlist_for_each(pos, head) {
21678 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
21679 +
21680 +               if ((vdm->device == device) &&
21681 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
21682 +                       if (vdm->xid == xid) {
21683 +                               *local = vdm;
21684 +                               return 1;
21685 +                       } else if (global && vdm->xid == 0)
21686 +                               *global = vdm;
21687 +               }
21688 +       }
21689 +
21690 +       if (global && *global)
21691 +               return 0;
21692 +       else
21693 +               return -ENOENT;
21694 +}
21695 +
21696 +
21697 +/*     __lookup_mapping()
21698 + *     find a mapping and store the result in target and flags
21699 + */
21700 +static inline int __lookup_mapping(struct vx_info *vxi,
21701 +       dev_t device, dev_t *target, int *flags, umode_t mode)
21702 +{
21703 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21704 +       struct vs_mapping *vdm, *global;
21705 +       struct vx_dmap_target *vdmt;
21706 +       int ret = 0;
21707 +       xid_t xid = vxi->vx_id;
21708 +       int index;
21709 +
21710 +       spin_lock(hash_lock);
21711 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
21712 +               ret = 1;
21713 +               vdmt = &vdm->target;
21714 +               goto found;
21715 +       }
21716 +
21717 +       index = __mode_to_default(mode);
21718 +       if (vxi && vxi->dmap.targets[index].flags) {
21719 +               ret = 2;
21720 +               vdmt = &vxi->dmap.targets[index];
21721 +       } else if (global) {
21722 +               ret = 3;
21723 +               vdmt = &global->target;
21724 +               goto found;
21725 +       } else {
21726 +               ret = 4;
21727 +               vdmt = &dmap_defaults[index];
21728 +       }
21729 +
21730 +found:
21731 +       if (target && (vdmt->flags & DATTR_REMAP))
21732 +               *target = vdmt->target;
21733 +       else if (target)
21734 +               *target = device;
21735 +       if (flags)
21736 +               *flags = vdmt->flags;
21737 +
21738 +       spin_unlock(hash_lock);
21739 +
21740 +       return ret;
21741 +}
21742 +
21743 +
21744 +/*     __remove_mapping()
21745 + *     remove a mapping from the hash table
21746 + */
21747 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
21748 +       umode_t mode)
21749 +{
21750 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21751 +       struct vs_mapping *vdm = NULL;
21752 +       int ret = 0;
21753 +
21754 +       spin_lock(hash_lock);
21755 +
21756 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
21757 +               NULL);
21758 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
21759 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
21760 +       if (ret < 0)
21761 +               goto out;
21762 +       hlist_del(&vdm->dm_hlist);
21763 +
21764 +out:
21765 +       spin_unlock(hash_lock);
21766 +       if (vdm)
21767 +               kmem_cache_free(dmap_cachep, vdm);
21768 +       return ret;
21769 +}
21770 +
21771 +
21772 +
21773 +int vs_map_device(struct vx_info *vxi,
21774 +       dev_t device, dev_t *target, umode_t mode)
21775 +{
21776 +       int ret, flags = DATTR_MASK;
21777 +
21778 +       if (!vxi) {
21779 +               if (target)
21780 +                       *target = device;
21781 +               goto out;
21782 +       }
21783 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
21784 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
21785 +               device, target ? *target : 0, flags, mode, ret);
21786 +out:
21787 +       return (flags & DATTR_MASK);
21788 +}
21789 +
21790 +
21791 +
21792 +static int do_set_mapping(struct vx_info *vxi,
21793 +       dev_t device, dev_t target, int flags, umode_t mode)
21794 +{
21795 +       if (device) {
21796 +               struct vs_mapping *new;
21797 +
21798 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
21799 +               if (!new)
21800 +                       return -ENOMEM;
21801 +
21802 +               INIT_HLIST_NODE(&new->dm_hlist);
21803 +               new->device = device;
21804 +               new->target.target = target;
21805 +               new->target.flags = flags | mode;
21806 +               new->xid = (vxi ? vxi->vx_id : 0);
21807 +
21808 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
21809 +               __hash_mapping(vxi, new);
21810 +       } else {
21811 +               struct vx_dmap_target new = {
21812 +                       .target = target,
21813 +                       .flags = flags | mode,
21814 +               };
21815 +               __set_default(vxi, mode, &new);
21816 +       }
21817 +       return 0;
21818 +}
21819 +
21820 +
21821 +static int do_unset_mapping(struct vx_info *vxi,
21822 +       dev_t device, dev_t target, int flags, umode_t mode)
21823 +{
21824 +       int ret = -EINVAL;
21825 +
21826 +       if (device) {
21827 +               ret = __remove_mapping(vxi, device, mode);
21828 +               if (ret < 0)
21829 +                       goto out;
21830 +       } else {
21831 +               ret = __remove_default(vxi, mode);
21832 +               if (ret < 0)
21833 +                       goto out;
21834 +       }
21835 +
21836 +out:
21837 +       return ret;
21838 +}
21839 +
21840 +
21841 +static inline int __user_device(const char __user *name, dev_t *dev,
21842 +       umode_t *mode)
21843 +{
21844 +       struct nameidata nd;
21845 +       int ret;
21846 +
21847 +       if (!name) {
21848 +               *dev = 0;
21849 +               return 0;
21850 +       }
21851 +       ret = user_path_walk_link(name, &nd);
21852 +       if (ret)
21853 +               return ret;
21854 +       if (nd.dentry->d_inode) {
21855 +               *dev = nd.dentry->d_inode->i_rdev;
21856 +               *mode = nd.dentry->d_inode->i_mode;
21857 +       }
21858 +       path_release(&nd);
21859 +       return 0;
21860 +}
21861 +
21862 +static inline int __mapping_mode(dev_t device, dev_t target,
21863 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
21864 +{
21865 +       if (device)
21866 +               *mode = device_mode & S_IFMT;
21867 +       else if (target)
21868 +               *mode = target_mode & S_IFMT;
21869 +       else
21870 +               *mode = 0;
21871 +
21872 +       /* if both given, device and target mode have to match */
21873 +       if (device && target &&
21874 +               ((device_mode ^ target_mode) & S_IFMT))
21875 +               return -EINVAL;
21876 +       return 0;
21877 +}
21878 +
21879 +
21880 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
21881 +       const char __user *target_path, int flags, int set)
21882 +{
21883 +       dev_t device = ~0, target = ~0;
21884 +       umode_t device_mode = 0, target_mode = 0, mode;
21885 +       int ret;
21886 +
21887 +       ret = __user_device(device_path, &device, &device_mode);
21888 +       if (ret)
21889 +               return ret;
21890 +       ret = __user_device(target_path, &target, &target_mode);
21891 +       if (ret)
21892 +               return ret;
21893 +
21894 +       ret = __mapping_mode(device, target,
21895 +               device_mode, target_mode, &mode);
21896 +       if (ret)
21897 +               return ret;
21898 +
21899 +       if (set)
21900 +               return do_set_mapping(vxi, device, target,
21901 +                       flags, mode);
21902 +       else
21903 +               return do_unset_mapping(vxi, device, target,
21904 +                       flags, mode);
21905 +}
21906 +
21907 +
21908 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
21909 +{
21910 +       struct vcmd_set_mapping_v0 vc_data;
21911 +
21912 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21913 +               return -EFAULT;
21914 +
21915 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21916 +               vc_data.flags, 1);
21917 +}
21918 +
21919 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
21920 +{
21921 +       struct vcmd_set_mapping_v0 vc_data;
21922 +
21923 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21924 +               return -EFAULT;
21925 +
21926 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21927 +               vc_data.flags, 0);
21928 +}
21929 +
21930 +
21931 +#ifdef CONFIG_COMPAT
21932 +
21933 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
21934 +{
21935 +       struct vcmd_set_mapping_v0_x32 vc_data;
21936 +
21937 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21938 +               return -EFAULT;
21939 +
21940 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21941 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
21942 +}
21943 +
21944 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
21945 +{
21946 +       struct vcmd_set_mapping_v0_x32 vc_data;
21947 +
21948 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21949 +               return -EFAULT;
21950 +
21951 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21952 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
21953 +}
21954 +
21955 +#endif /* CONFIG_COMPAT */
21956 +
21957 +
21958 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/dlimit.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/dlimit.c
21959 --- linux-2.6.22.10/kernel/vserver/dlimit.c     1970-01-01 01:00:00 +0100
21960 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/dlimit.c  2007-08-15 22:07:58 +0200
21961 @@ -0,0 +1,520 @@
21962 +/*
21963 + *  linux/kernel/vserver/dlimit.c
21964 + *
21965 + *  Virtual Server: Context Disk Limits
21966 + *
21967 + *  Copyright (C) 2004-2007  Herbert Pötzl
21968 + *
21969 + *  V0.01  initial version
21970 + *  V0.02  compat32 splitup
21971 + *
21972 + */
21973 +
21974 +#include <linux/statfs.h>
21975 +#include <linux/vs_tag.h>
21976 +#include <linux/vs_dlimit.h>
21977 +#include <linux/vserver/dlimit_cmd.h>
21978 +
21979 +#include <asm/uaccess.h>
21980 +
21981 +/*     __alloc_dl_info()
21982 +
21983 +       * allocate an initialized dl_info struct
21984 +       * doesn't make it visible (hash)                        */
21985 +
21986 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
21987 +{
21988 +       struct dl_info *new = NULL;
21989 +
21990 +       vxdprintk(VXD_CBIT(dlim, 5),
21991 +               "alloc_dl_info(%p,%d)*", sb, tag);
21992 +
21993 +       /* would this benefit from a slab cache? */
21994 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
21995 +       if (!new)
21996 +               return 0;
21997 +
21998 +       memset(new, 0, sizeof(struct dl_info));
21999 +       new->dl_tag = tag;
22000 +       new->dl_sb = sb;
22001 +       INIT_RCU_HEAD(&new->dl_rcu);
22002 +       INIT_HLIST_NODE(&new->dl_hlist);
22003 +       spin_lock_init(&new->dl_lock);
22004 +       atomic_set(&new->dl_refcnt, 0);
22005 +       atomic_set(&new->dl_usecnt, 0);
22006 +
22007 +       /* rest of init goes here */
22008 +
22009 +       vxdprintk(VXD_CBIT(dlim, 4),
22010 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
22011 +       return new;
22012 +}
22013 +
22014 +/*     __dealloc_dl_info()
22015 +
22016 +       * final disposal of dl_info                             */
22017 +
22018 +static void __dealloc_dl_info(struct dl_info *dli)
22019 +{
22020 +       vxdprintk(VXD_CBIT(dlim, 4),
22021 +               "dealloc_dl_info(%p)", dli);
22022 +
22023 +       dli->dl_hlist.next = LIST_POISON1;
22024 +       dli->dl_tag = -1;
22025 +       dli->dl_sb = 0;
22026 +
22027 +       BUG_ON(atomic_read(&dli->dl_usecnt));
22028 +       BUG_ON(atomic_read(&dli->dl_refcnt));
22029 +
22030 +       kfree(dli);
22031 +}
22032 +
22033 +
22034 +/*     hash table for dl_info hash */
22035 +
22036 +#define DL_HASH_SIZE   13
22037 +
22038 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
22039 +
22040 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
22041 +
22042 +
22043 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
22044 +{
22045 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
22046 +}
22047 +
22048 +
22049 +
22050 +/*     __hash_dl_info()
22051 +
22052 +       * add the dli to the global hash table
22053 +       * requires the hash_lock to be held                     */
22054 +
22055 +static inline void __hash_dl_info(struct dl_info *dli)
22056 +{
22057 +       struct hlist_head *head;
22058 +
22059 +       vxdprintk(VXD_CBIT(dlim, 6),
22060 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
22061 +       get_dl_info(dli);
22062 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
22063 +       hlist_add_head_rcu(&dli->dl_hlist, head);
22064 +}
22065 +
22066 +/*     __unhash_dl_info()
22067 +
22068 +       * remove the dli from the global hash table
22069 +       * requires the hash_lock to be held                     */
22070 +
22071 +static inline void __unhash_dl_info(struct dl_info *dli)
22072 +{
22073 +       vxdprintk(VXD_CBIT(dlim, 6),
22074 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
22075 +       hlist_del_rcu(&dli->dl_hlist);
22076 +       put_dl_info(dli);
22077 +}
22078 +
22079 +
22080 +/*     __lookup_dl_info()
22081 +
22082 +       * requires the rcu_read_lock()
22083 +       * doesn't increment the dl_refcnt                       */
22084 +
22085 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
22086 +{
22087 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
22088 +       struct hlist_node *pos;
22089 +       struct dl_info *dli;
22090 +
22091 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
22092 +
22093 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
22094 +                       return dli;
22095 +               }
22096 +       }
22097 +       return NULL;
22098 +}
22099 +
22100 +
22101 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
22102 +{
22103 +       struct dl_info *dli;
22104 +
22105 +       rcu_read_lock();
22106 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
22107 +       vxdprintk(VXD_CBIT(dlim, 7),
22108 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
22109 +       rcu_read_unlock();
22110 +       return dli;
22111 +}
22112 +
22113 +void rcu_free_dl_info(struct rcu_head *head)
22114 +{
22115 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
22116 +       int usecnt, refcnt;
22117 +
22118 +       BUG_ON(!dli || !head);
22119 +
22120 +       usecnt = atomic_read(&dli->dl_usecnt);
22121 +       BUG_ON(usecnt < 0);
22122 +
22123 +       refcnt = atomic_read(&dli->dl_refcnt);
22124 +       BUG_ON(refcnt < 0);
22125 +
22126 +       vxdprintk(VXD_CBIT(dlim, 3),
22127 +               "rcu_free_dl_info(%p)", dli);
22128 +       if (!usecnt)
22129 +               __dealloc_dl_info(dli);
22130 +       else
22131 +               printk("!!! rcu didn't free\n");
22132 +}
22133 +
22134 +
22135 +
22136 +
22137 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
22138 +       uint32_t flags, int add)
22139 +{
22140 +       struct nameidata nd;
22141 +       int ret;
22142 +
22143 +       ret = user_path_walk_link(name, &nd);
22144 +       if (!ret) {
22145 +               struct super_block *sb;
22146 +               struct dl_info *dli;
22147 +
22148 +               ret = -EINVAL;
22149 +               if (!nd.dentry->d_inode)
22150 +                       goto out_release;
22151 +               if (!(sb = nd.dentry->d_inode->i_sb))
22152 +                       goto out_release;
22153 +
22154 +               if (add) {
22155 +                       dli = __alloc_dl_info(sb, id);
22156 +                       spin_lock(&dl_info_hash_lock);
22157 +
22158 +                       ret = -EEXIST;
22159 +                       if (__lookup_dl_info(sb, id))
22160 +                               goto out_unlock;
22161 +                       __hash_dl_info(dli);
22162 +                       dli = NULL;
22163 +               } else {
22164 +                       spin_lock(&dl_info_hash_lock);
22165 +                       dli = __lookup_dl_info(sb, id);
22166 +
22167 +                       ret = -ESRCH;
22168 +                       if (!dli)
22169 +                               goto out_unlock;
22170 +                       __unhash_dl_info(dli);
22171 +               }
22172 +               ret = 0;
22173 +       out_unlock:
22174 +               spin_unlock(&dl_info_hash_lock);
22175 +               if (add && dli)
22176 +                       __dealloc_dl_info(dli);
22177 +       out_release:
22178 +               path_release(&nd);
22179 +       }
22180 +       return ret;
22181 +}
22182 +
22183 +int vc_add_dlimit(uint32_t id, void __user *data)
22184 +{
22185 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
22186 +
22187 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22188 +               return -EFAULT;
22189 +
22190 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
22191 +}
22192 +
22193 +int vc_rem_dlimit(uint32_t id, void __user *data)
22194 +{
22195 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
22196 +
22197 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22198 +               return -EFAULT;
22199 +
22200 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
22201 +}
22202 +
22203 +#ifdef CONFIG_COMPAT
22204 +
22205 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
22206 +{
22207 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
22208 +
22209 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22210 +               return -EFAULT;
22211 +
22212 +       return do_addrem_dlimit(id,
22213 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
22214 +}
22215 +
22216 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
22217 +{
22218 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
22219 +
22220 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22221 +               return -EFAULT;
22222 +
22223 +       return do_addrem_dlimit(id,
22224 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
22225 +}
22226 +
22227 +#endif /* CONFIG_COMPAT */
22228 +
22229 +
22230 +static inline
22231 +int do_set_dlimit(uint32_t id, const char __user *name,
22232 +       uint32_t space_used, uint32_t space_total,
22233 +       uint32_t inodes_used, uint32_t inodes_total,
22234 +       uint32_t reserved, uint32_t flags)
22235 +{
22236 +       struct nameidata nd;
22237 +       int ret;
22238 +
22239 +       ret = user_path_walk_link(name, &nd);
22240 +       if (!ret) {
22241 +               struct super_block *sb;
22242 +               struct dl_info *dli;
22243 +
22244 +               ret = -EINVAL;
22245 +               if (!nd.dentry->d_inode)
22246 +                       goto out_release;
22247 +               if (!(sb = nd.dentry->d_inode->i_sb))
22248 +                       goto out_release;
22249 +               if ((reserved != CDLIM_KEEP &&
22250 +                       reserved > 100) ||
22251 +                       (inodes_used != CDLIM_KEEP &&
22252 +                       inodes_used > inodes_total) ||
22253 +                       (space_used != CDLIM_KEEP &&
22254 +                       space_used > space_total))
22255 +                       goto out_release;
22256 +
22257 +               ret = -ESRCH;
22258 +               dli = locate_dl_info(sb, id);
22259 +               if (!dli)
22260 +                       goto out_release;
22261 +
22262 +               spin_lock(&dli->dl_lock);
22263 +
22264 +               if (inodes_used != CDLIM_KEEP)
22265 +                       dli->dl_inodes_used = inodes_used;
22266 +               if (inodes_total != CDLIM_KEEP)
22267 +                       dli->dl_inodes_total = inodes_total;
22268 +               if (space_used != CDLIM_KEEP) {
22269 +                       dli->dl_space_used = space_used;
22270 +                       dli->dl_space_used <<= 10;
22271 +               }
22272 +               if (space_total == CDLIM_INFINITY)
22273 +                       dli->dl_space_total = DLIM_INFINITY;
22274 +               else if (space_total != CDLIM_KEEP) {
22275 +                       dli->dl_space_total = space_total;
22276 +                       dli->dl_space_total <<= 10;
22277 +               }
22278 +               if (reserved != CDLIM_KEEP)
22279 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
22280 +
22281 +               spin_unlock(&dli->dl_lock);
22282 +
22283 +               put_dl_info(dli);
22284 +               ret = 0;
22285 +
22286 +       out_release:
22287 +               path_release(&nd);
22288 +       }
22289 +       return ret;
22290 +}
22291 +
22292 +int vc_set_dlimit(uint32_t id, void __user *data)
22293 +{
22294 +       struct vcmd_ctx_dlimit_v0 vc_data;
22295 +
22296 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22297 +               return -EFAULT;
22298 +
22299 +       return do_set_dlimit(id, vc_data.name,
22300 +               vc_data.space_used, vc_data.space_total,
22301 +               vc_data.inodes_used, vc_data.inodes_total,
22302 +               vc_data.reserved, vc_data.flags);
22303 +}
22304 +
22305 +#ifdef CONFIG_COMPAT
22306 +
22307 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
22308 +{
22309 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22310 +
22311 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22312 +               return -EFAULT;
22313 +
22314 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
22315 +               vc_data.space_used, vc_data.space_total,
22316 +               vc_data.inodes_used, vc_data.inodes_total,
22317 +               vc_data.reserved, vc_data.flags);
22318 +}
22319 +
22320 +#endif /* CONFIG_COMPAT */
22321 +
22322 +
22323 +static inline
22324 +int do_get_dlimit(uint32_t id, const char __user *name,
22325 +       uint32_t *space_used, uint32_t *space_total,
22326 +       uint32_t *inodes_used, uint32_t *inodes_total,
22327 +       uint32_t *reserved, uint32_t *flags)
22328 +{
22329 +       struct nameidata nd;
22330 +       int ret;
22331 +
22332 +       ret = user_path_walk_link(name, &nd);
22333 +       if (!ret) {
22334 +               struct super_block *sb;
22335 +               struct dl_info *dli;
22336 +
22337 +               ret = -EINVAL;
22338 +               if (!nd.dentry->d_inode)
22339 +                       goto out_release;
22340 +               if (!(sb = nd.dentry->d_inode->i_sb))
22341 +                       goto out_release;
22342 +
22343 +               ret = -ESRCH;
22344 +               dli = locate_dl_info(sb, id);
22345 +               if (!dli)
22346 +                       goto out_release;
22347 +
22348 +               spin_lock(&dli->dl_lock);
22349 +               *inodes_used = dli->dl_inodes_used;
22350 +               *inodes_total = dli->dl_inodes_total;
22351 +               *space_used = dli->dl_space_used >> 10;
22352 +               if (dli->dl_space_total == DLIM_INFINITY)
22353 +                       *space_total = CDLIM_INFINITY;
22354 +               else
22355 +                       *space_total = dli->dl_space_total >> 10;
22356 +
22357 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
22358 +               spin_unlock(&dli->dl_lock);
22359 +
22360 +               put_dl_info(dli);
22361 +               ret = -EFAULT;
22362 +
22363 +               ret = 0;
22364 +       out_release:
22365 +               path_release(&nd);
22366 +       }
22367 +       return ret;
22368 +}
22369 +
22370 +
22371 +int vc_get_dlimit(uint32_t id, void __user *data)
22372 +{
22373 +       struct vcmd_ctx_dlimit_v0 vc_data;
22374 +       int ret;
22375 +
22376 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22377 +               return -EFAULT;
22378 +
22379 +       ret = do_get_dlimit(id, vc_data.name,
22380 +               &vc_data.space_used, &vc_data.space_total,
22381 +               &vc_data.inodes_used, &vc_data.inodes_total,
22382 +               &vc_data.reserved, &vc_data.flags);
22383 +       if (ret)
22384 +               return ret;
22385 +
22386 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22387 +               return -EFAULT;
22388 +       return 0;
22389 +}
22390 +
22391 +#ifdef CONFIG_COMPAT
22392 +
22393 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
22394 +{
22395 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22396 +       int ret;
22397 +
22398 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22399 +               return -EFAULT;
22400 +
22401 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
22402 +               &vc_data.space_used, &vc_data.space_total,
22403 +               &vc_data.inodes_used, &vc_data.inodes_total,
22404 +               &vc_data.reserved, &vc_data.flags);
22405 +       if (ret)
22406 +               return ret;
22407 +
22408 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22409 +               return -EFAULT;
22410 +       return 0;
22411 +}
22412 +
22413 +#endif /* CONFIG_COMPAT */
22414 +
22415 +
22416 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
22417 +{
22418 +       struct dl_info *dli;
22419 +       __u64 blimit, bfree, bavail;
22420 +       __u32 ifree;
22421 +
22422 +       dli = locate_dl_info(sb, dx_current_tag());
22423 +       if (!dli)
22424 +               return;
22425 +
22426 +       spin_lock(&dli->dl_lock);
22427 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
22428 +               goto no_ilim;
22429 +
22430 +       /* reduce max inodes available to limit */
22431 +       if (buf->f_files > dli->dl_inodes_total)
22432 +               buf->f_files = dli->dl_inodes_total;
22433 +
22434 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
22435 +       /* reduce free inodes to min */
22436 +       if (ifree < buf->f_ffree)
22437 +               buf->f_ffree = ifree;
22438 +
22439 +no_ilim:
22440 +       if (dli->dl_space_total == DLIM_INFINITY)
22441 +               goto no_blim;
22442 +
22443 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
22444 +
22445 +       if (dli->dl_space_total < dli->dl_space_used)
22446 +               bfree = 0;
22447 +       else
22448 +               bfree = (dli->dl_space_total - dli->dl_space_used)
22449 +                       >> sb->s_blocksize_bits;
22450 +
22451 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
22452 +       if (bavail < dli->dl_space_used)
22453 +               bavail = 0;
22454 +       else
22455 +               bavail = (bavail - dli->dl_space_used)
22456 +                       >> sb->s_blocksize_bits;
22457 +
22458 +       /* reduce max space available to limit */
22459 +       if (buf->f_blocks > blimit)
22460 +               buf->f_blocks = blimit;
22461 +
22462 +       /* reduce free space to min */
22463 +       if (bfree < buf->f_bfree)
22464 +               buf->f_bfree = bfree;
22465 +
22466 +       /* reduce avail space to min */
22467 +       if (bavail < buf->f_bavail)
22468 +               buf->f_bavail = bavail;
22469 +
22470 +no_blim:
22471 +       spin_unlock(&dli->dl_lock);
22472 +       put_dl_info(dli);
22473 +
22474 +       return;
22475 +}
22476 +
22477 +#include <linux/module.h>
22478 +
22479 +EXPORT_SYMBOL_GPL(locate_dl_info);
22480 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
22481 +
22482 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/helper.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/helper.c
22483 --- linux-2.6.22.10/kernel/vserver/helper.c     1970-01-01 01:00:00 +0100
22484 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/helper.c  2007-08-15 22:12:01 +0200
22485 @@ -0,0 +1,199 @@
22486 +/*
22487 + *  linux/kernel/vserver/helper.c
22488 + *
22489 + *  Virtual Context Support
22490 + *
22491 + *  Copyright (C) 2004-2007  Herbert Pötzl
22492 + *
22493 + *  V0.01  basic helper
22494 + *
22495 + */
22496 +
22497 +#include <linux/kmod.h>
22498 +#include <linux/reboot.h>
22499 +#include <linux/vs_context.h>
22500 +#include <linux/vs_network.h>
22501 +#include <linux/vserver/signal.h>
22502 +
22503 +
22504 +char vshelper_path[255] = "/sbin/vshelper";
22505 +
22506 +
22507 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
22508 +{
22509 +       int ret;
22510 +
22511 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
22512 +               printk( KERN_WARNING
22513 +                       "%s: (%s %s) returned %s with %d\n",
22514 +                       name, argv[1], argv[2],
22515 +                       sync ? "sync" : "async", ret);
22516 +       }
22517 +       vxdprintk(VXD_CBIT(switch, 4),
22518 +               "%s: (%s %s) returned %s with %d",
22519 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
22520 +       return ret;
22521 +}
22522 +
22523 +/*
22524 + *      vshelper path is set via /proc/sys
22525 + *      invoked by vserver sys_reboot(), with
22526 + *      the following arguments
22527 + *
22528 + *      argv [0] = vshelper_path;
22529 + *      argv [1] = action: "restart", "halt", "poweroff", ...
22530 + *      argv [2] = context identifier
22531 + *
22532 + *      envp [*] = type-specific parameters
22533 + */
22534 +
22535 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
22536 +{
22537 +       char id_buf[8], cmd_buf[16];
22538 +       char uid_buf[16], pid_buf[16];
22539 +       int ret;
22540 +
22541 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22542 +       char *envp[] = {"HOME=/", "TERM=linux",
22543 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
22544 +                       uid_buf, pid_buf, cmd_buf, 0};
22545 +
22546 +       if (vx_info_state(vxi, VXS_HELPER))
22547 +               return -EAGAIN;
22548 +       vxi->vx_state |= VXS_HELPER;
22549 +
22550 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22551 +
22552 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22553 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
22554 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
22555 +
22556 +       switch (cmd) {
22557 +       case LINUX_REBOOT_CMD_RESTART:
22558 +               argv[1] = "restart";
22559 +               break;
22560 +
22561 +       case LINUX_REBOOT_CMD_HALT:
22562 +               argv[1] = "halt";
22563 +               break;
22564 +
22565 +       case LINUX_REBOOT_CMD_POWER_OFF:
22566 +               argv[1] = "poweroff";
22567 +               break;
22568 +
22569 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
22570 +               argv[1] = "swsusp";
22571 +               break;
22572 +
22573 +       default:
22574 +               vxi->vx_state &= ~VXS_HELPER;
22575 +               return 0;
22576 +       }
22577 +
22578 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
22579 +       vxi->vx_state &= ~VXS_HELPER;
22580 +       __wakeup_vx_info(vxi);
22581 +       return (ret) ? -EPERM : 0;
22582 +}
22583 +
22584 +
22585 +long vs_reboot(unsigned int cmd, void __user *arg)
22586 +{
22587 +       struct vx_info *vxi = current->vx_info;
22588 +       long ret = 0;
22589 +
22590 +       vxdprintk(VXD_CBIT(misc, 5),
22591 +               "vs_reboot(%p[#%d],%d)",
22592 +               vxi, vxi ? vxi->vx_id : 0, cmd);
22593 +
22594 +       ret = vs_reboot_helper(vxi, cmd, arg);
22595 +       if (ret)
22596 +               return ret;
22597 +
22598 +       vxi->reboot_cmd = cmd;
22599 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
22600 +               switch (cmd) {
22601 +               case LINUX_REBOOT_CMD_RESTART:
22602 +               case LINUX_REBOOT_CMD_HALT:
22603 +               case LINUX_REBOOT_CMD_POWER_OFF:
22604 +                       vx_info_kill(vxi, 0, SIGKILL);
22605 +                       vx_info_kill(vxi, 1, SIGKILL);
22606 +               default:
22607 +                       break;
22608 +               }
22609 +       }
22610 +       return 0;
22611 +}
22612 +
22613 +
22614 +/*
22615 + *      argv [0] = vshelper_path;
22616 + *      argv [1] = action: "startup", "shutdown"
22617 + *      argv [2] = context identifier
22618 + *
22619 + *      envp [*] = type-specific parameters
22620 + */
22621 +
22622 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
22623 +{
22624 +       char id_buf[8], cmd_buf[16];
22625 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22626 +       char *envp[] = {"HOME=/", "TERM=linux",
22627 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22628 +
22629 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
22630 +               return 0;
22631 +
22632 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22633 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22634 +
22635 +       switch (cmd) {
22636 +       case VSC_STARTUP:
22637 +               argv[1] = "startup";
22638 +               break;
22639 +       case VSC_SHUTDOWN:
22640 +               argv[1] = "shutdown";
22641 +               break;
22642 +       default:
22643 +               return 0;
22644 +       }
22645 +
22646 +       return do_vshelper(vshelper_path, argv, envp, 1);
22647 +}
22648 +
22649 +
22650 +/*
22651 + *      argv [0] = vshelper_path;
22652 + *      argv [1] = action: "netup", "netdown"
22653 + *      argv [2] = context identifier
22654 + *
22655 + *      envp [*] = type-specific parameters
22656 + */
22657 +
22658 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
22659 +{
22660 +       char id_buf[8], cmd_buf[16];
22661 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22662 +       char *envp[] = {"HOME=/", "TERM=linux",
22663 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22664 +
22665 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
22666 +               return 0;
22667 +
22668 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
22669 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22670 +
22671 +       switch (cmd) {
22672 +       case VSC_NETUP:
22673 +               argv[1] = "netup";
22674 +               break;
22675 +       case VSC_NETDOWN:
22676 +               argv[1] = "netdown";
22677 +               break;
22678 +       default:
22679 +               return 0;
22680 +       }
22681 +
22682 +       return do_vshelper(vshelper_path, argv, envp, 1);
22683 +}
22684 +
22685 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/history.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/history.c
22686 --- linux-2.6.22.10/kernel/vserver/history.c    1970-01-01 01:00:00 +0100
22687 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/history.c 2007-08-15 22:13:54 +0200
22688 @@ -0,0 +1,258 @@
22689 +/*
22690 + *  kernel/vserver/history.c
22691 + *
22692 + *  Virtual Context History Backtrace
22693 + *
22694 + *  Copyright (C) 2004-2007  Herbert Pötzl
22695 + *
22696 + *  V0.01  basic structure
22697 + *  V0.02  hash/unhash and trace
22698 + *  V0.03  preemption fixes
22699 + *
22700 + */
22701 +
22702 +#include <linux/module.h>
22703 +#include <asm/uaccess.h>
22704 +
22705 +#include <linux/vserver/context.h>
22706 +#include <linux/vserver/debug.h>
22707 +#include <linux/vserver/debug_cmd.h>
22708 +#include <linux/vserver/history.h>
22709 +
22710 +
22711 +#ifdef CONFIG_VSERVER_HISTORY
22712 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
22713 +#else
22714 +#define VXH_SIZE       64
22715 +#endif
22716 +
22717 +struct _vx_history {
22718 +       unsigned int counter;
22719 +
22720 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
22721 +};
22722 +
22723 +
22724 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
22725 +
22726 +unsigned volatile int vxh_active = 1;
22727 +
22728 +static atomic_t sequence = ATOMIC_INIT(0);
22729 +
22730 +
22731 +/*     vxh_advance()
22732 +
22733 +       * requires disabled preemption                          */
22734 +
22735 +struct _vx_hist_entry *vxh_advance(void *loc)
22736 +{
22737 +       unsigned int cpu = smp_processor_id();
22738 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22739 +       struct _vx_hist_entry *entry;
22740 +       unsigned int index;
22741 +
22742 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
22743 +       entry = &hist->entry[index];
22744 +
22745 +       entry->seq = atomic_inc_return(&sequence);
22746 +       entry->loc = loc;
22747 +       return entry;
22748 +}
22749 +
22750 +EXPORT_SYMBOL_GPL(vxh_advance);
22751 +
22752 +
22753 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
22754 +
22755 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
22756 +
22757 +
22758 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
22759 +
22760 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
22761 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
22762 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
22763 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
22764 +
22765 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
22766 +{
22767 +       switch (e->type) {
22768 +       case VXH_THROW_OOPS:
22769 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
22770 +               break;
22771 +
22772 +       case VXH_GET_VX_INFO:
22773 +       case VXH_PUT_VX_INFO:
22774 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22775 +                       VXH_LOC_ARGS(e),
22776 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
22777 +                       VXH_VXI_ARGS(e));
22778 +               break;
22779 +
22780 +       case VXH_INIT_VX_INFO:
22781 +       case VXH_SET_VX_INFO:
22782 +       case VXH_CLR_VX_INFO:
22783 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22784 +                       VXH_LOC_ARGS(e),
22785 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
22786 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
22787 +                       VXH_VXI_ARGS(e), e->sc.data);
22788 +               break;
22789 +
22790 +       case VXH_CLAIM_VX_INFO:
22791 +       case VXH_RELEASE_VX_INFO:
22792 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22793 +                       VXH_LOC_ARGS(e),
22794 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
22795 +                       VXH_VXI_ARGS(e), e->sc.data);
22796 +               break;
22797 +
22798 +       case VXH_ALLOC_VX_INFO:
22799 +       case VXH_DEALLOC_VX_INFO:
22800 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22801 +                       VXH_LOC_ARGS(e),
22802 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
22803 +                       VXH_VXI_ARGS(e));
22804 +               break;
22805 +
22806 +       case VXH_HASH_VX_INFO:
22807 +       case VXH_UNHASH_VX_INFO:
22808 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
22809 +                       VXH_LOC_ARGS(e),
22810 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
22811 +                       VXH_VXI_ARGS(e));
22812 +               break;
22813 +
22814 +       case VXH_LOC_VX_INFO:
22815 +       case VXH_LOOKUP_VX_INFO:
22816 +       case VXH_CREATE_VX_INFO:
22817 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
22818 +                       VXH_LOC_ARGS(e),
22819 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
22820 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
22821 +                       e->ll.arg, VXH_VXI_ARGS(e));
22822 +               break;
22823 +       }
22824 +}
22825 +
22826 +static void __vxh_dump_history(void)
22827 +{
22828 +       unsigned int i, cpu;
22829 +
22830 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
22831 +               atomic_read(&sequence), NR_CPUS);
22832 +
22833 +       for (i = 0; i < VXH_SIZE; i++) {
22834 +               for_each_online_cpu(cpu) {
22835 +                       struct _vx_history *hist =
22836 +                               &per_cpu(vx_history_buffer, cpu);
22837 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
22838 +                       struct _vx_hist_entry *entry = &hist->entry[index];
22839 +
22840 +                       vxh_dump_entry(entry, cpu);
22841 +               }
22842 +       }
22843 +}
22844 +
22845 +void   vxh_dump_history(void)
22846 +{
22847 +       vxh_active = 0;
22848 +#ifdef CONFIG_SMP
22849 +       local_irq_enable();
22850 +       smp_send_stop();
22851 +       local_irq_disable();
22852 +#endif
22853 +       __vxh_dump_history();
22854 +}
22855 +
22856 +
22857 +/* vserver syscall commands below here */
22858 +
22859 +
22860 +int vc_dump_history(uint32_t id)
22861 +{
22862 +       vxh_active = 0;
22863 +       __vxh_dump_history();
22864 +       vxh_active = 1;
22865 +
22866 +       return 0;
22867 +}
22868 +
22869 +
22870 +int do_read_history(struct __user _vx_hist_entry *data,
22871 +       int cpu, uint32_t *index, uint32_t *count)
22872 +{
22873 +       int pos, ret = 0;
22874 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22875 +       int end = hist->counter;
22876 +       int start = end - VXH_SIZE + 2;
22877 +       int idx = *index;
22878 +
22879 +       /* special case: get current pos */
22880 +       if (!*count) {
22881 +               *index = end;
22882 +               return 0;
22883 +       }
22884 +
22885 +       /* have we lost some data? */
22886 +       if (idx < start)
22887 +               idx = start;
22888 +
22889 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22890 +               struct _vx_hist_entry *entry =
22891 +                       &hist->entry[idx % VXH_SIZE];
22892 +
22893 +               /* send entry to userspace */
22894 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22895 +               if (ret)
22896 +                       break;
22897 +       }
22898 +       /* save new index and count */
22899 +       *index = idx;
22900 +       *count = pos;
22901 +       return ret ? ret : (*index < end);
22902 +}
22903 +
22904 +int vc_read_history(uint32_t id, void __user *data)
22905 +{
22906 +       struct vcmd_read_history_v0 vc_data;
22907 +       int ret;
22908 +
22909 +       if (id >= NR_CPUS)
22910 +               return -EINVAL;
22911 +
22912 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22913 +               return -EFAULT;
22914 +
22915 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
22916 +               id, &vc_data.index, &vc_data.count);
22917 +
22918 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22919 +               return -EFAULT;
22920 +       return ret;
22921 +}
22922 +
22923 +#ifdef CONFIG_COMPAT
22924 +
22925 +int vc_read_history_x32(uint32_t id, void __user *data)
22926 +{
22927 +       struct vcmd_read_history_v0_x32 vc_data;
22928 +       int ret;
22929 +
22930 +       if (id >= NR_CPUS)
22931 +               return -EINVAL;
22932 +
22933 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22934 +               return -EFAULT;
22935 +
22936 +       ret = do_read_history((struct __user _vx_hist_entry *)
22937 +               compat_ptr(vc_data.data_ptr),
22938 +               id, &vc_data.index, &vc_data.count);
22939 +
22940 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22941 +               return -EFAULT;
22942 +       return ret;
22943 +}
22944 +
22945 +#endif /* CONFIG_COMPAT */
22946 +
22947 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/inet.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/inet.c
22948 --- linux-2.6.22.10/kernel/vserver/inet.c       1970-01-01 01:00:00 +0100
22949 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/inet.c    2007-10-10 23:55:30 +0200
22950 @@ -0,0 +1,222 @@
22951 +
22952 +#include <linux/in.h>
22953 +#include <linux/inetdevice.h>
22954 +#include <linux/vs_inet6.h>
22955 +#include <linux/vserver/debug.h>
22956 +#include <net/route.h>
22957 +#include <net/addrconf.h>
22958 +
22959 +
22960 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22961 +{
22962 +       int ret = 0;
22963 +
22964 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22965 +               ret = 1;
22966 +       else {
22967 +               struct nx_addr_v4 *ptr;
22968 +
22969 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
22970 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22971 +                               ret = 1;
22972 +                               break;
22973 +                       }
22974 +               }
22975 +       }
22976 +
22977 +       vxdprintk(VXD_CBIT(net, 2),
22978 +               "nx_v4_addr_conflict(%p,%p): %d",
22979 +               nxi1, nxi2, ret);
22980 +
22981 +       return ret;
22982 +}
22983 +
22984 +
22985 +#ifdef CONFIG_IPV6
22986 +
22987 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22988 +{
22989 +       int ret = 0;
22990 +
22991 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22992 +               ret = 1;
22993 +       else {
22994 +               struct nx_addr_v6 *ptr;
22995 +
22996 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
22997 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22998 +                               ret = 1;
22999 +                               break;
23000 +                       }
23001 +               }
23002 +       }
23003 +
23004 +       vxdprintk(VXD_CBIT(net, 2),
23005 +               "nx_v6_addr_conflict(%p,%p): %d",
23006 +               nxi1, nxi2, ret);
23007 +
23008 +       return ret;
23009 +}
23010 +
23011 +#endif
23012 +
23013 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
23014 +{
23015 +       struct in_device *in_dev;
23016 +       struct in_ifaddr **ifap;
23017 +       struct in_ifaddr *ifa;
23018 +       int ret = 0;
23019 +
23020 +       if (!dev)
23021 +               goto out;
23022 +       in_dev = in_dev_get(dev);
23023 +       if (!in_dev)
23024 +               goto out;
23025 +
23026 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23027 +               ifap = &ifa->ifa_next) {
23028 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
23029 +                       ret = 1;
23030 +                       break;
23031 +               }
23032 +       }
23033 +       in_dev_put(in_dev);
23034 +out:
23035 +       return ret;
23036 +}
23037 +
23038 +
23039 +#ifdef CONFIG_IPV6
23040 +
23041 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
23042 +{
23043 +       struct inet6_dev *in_dev;
23044 +       struct inet6_ifaddr **ifap;
23045 +       struct inet6_ifaddr *ifa;
23046 +       int ret = 0;
23047 +
23048 +       if (!dev)
23049 +               goto out;
23050 +       in_dev = in6_dev_get(dev);
23051 +       if (!in_dev)
23052 +               goto out;
23053 +
23054 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
23055 +               ifap = &ifa->if_next) {
23056 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
23057 +                       ret = 1;
23058 +                       break;
23059 +               }
23060 +       }
23061 +       in6_dev_put(in_dev);
23062 +out:
23063 +       return ret;
23064 +}
23065 +
23066 +#endif
23067 +
23068 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
23069 +{
23070 +       int ret = 1;
23071 +
23072 +       if (!nxi)
23073 +               goto out;
23074 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
23075 +               goto out;
23076 +#ifdef CONFIG_IPV6
23077 +       ret = 2;
23078 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
23079 +               goto out;
23080 +#endif
23081 +       ret = 0;
23082 +out:
23083 +       vxdprintk(VXD_CBIT(net, 3),
23084 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
23085 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
23086 +       return ret;
23087 +}
23088 +
23089 +int ip_v4_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
23090 +{
23091 +       if (!nxi)
23092 +               return 0;
23093 +
23094 +       /* FIXME: handle lback only case */
23095 +       if (!NX_IPV4(nxi))
23096 +               return -EPERM;
23097 +
23098 +       vxdprintk(VXD_CBIT(net, 4),
23099 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
23100 +               nxi, nxi ? nxi->nx_id : 0,
23101 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
23102 +
23103 +       /* single IP is unconditional */
23104 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
23105 +               (fl->fl4_src == INADDR_ANY))
23106 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
23107 +
23108 +       if (fl->fl4_src == INADDR_ANY) {
23109 +               struct nx_addr_v4 *ptr;
23110 +               __be32 found;
23111 +               int err;
23112 +
23113 +               err = __ip_route_output_key(rp, fl);
23114 +               if (!err) {
23115 +                       found = (*rp)->rt_src;
23116 +                       ip_rt_put(*rp);
23117 +                       vxdprintk(VXD_CBIT(net, 4),
23118 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
23119 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
23120 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
23121 +                               goto found;
23122 +               }
23123 +
23124 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
23125 +                       __be32 primary = ptr->ip[0].s_addr;
23126 +                       __be32 mask = ptr->mask.s_addr;
23127 +                       __be32 net = primary & mask;
23128 +
23129 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
23130 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
23131 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
23132 +                               NIPQUAD(mask), NIPQUAD(net));
23133 +                       if ((found & mask) != net)
23134 +                               continue;
23135 +
23136 +                       fl->fl4_src = primary;
23137 +                       err = __ip_route_output_key(rp, fl);
23138 +                       vxdprintk(VXD_CBIT(net, 4),
23139 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
23140 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
23141 +                       if (!err) {
23142 +                               found = (*rp)->rt_src;
23143 +                               ip_rt_put(*rp);
23144 +                               if (found == primary)
23145 +                                       goto found;
23146 +                       }
23147 +               }
23148 +               /* still no source ip? */
23149 +               found = LOOPBACK(fl->fl4_dst)
23150 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
23151 +       found:
23152 +               /* assign src ip to flow */
23153 +               fl->fl4_src = found;
23154 +
23155 +       } else {
23156 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
23157 +                       return -EPERM;
23158 +       }
23159 +
23160 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
23161 +               if (LOOPBACK(fl->fl4_dst))
23162 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
23163 +               if (LOOPBACK(fl->fl4_src))
23164 +                       fl->fl4_src = nxi->v4_lback.s_addr;
23165 +       } else if (LOOPBACK(fl->fl4_dst))
23166 +               return -EPERM;
23167 +
23168 +       return 0;
23169 +}
23170 +
23171 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
23172 +
23173 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/init.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/init.c
23174 --- linux-2.6.22.10/kernel/vserver/init.c       1970-01-01 01:00:00 +0100
23175 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/init.c    2007-08-15 22:15:36 +0200
23176 @@ -0,0 +1,45 @@
23177 +/*
23178 + *  linux/kernel/init.c
23179 + *
23180 + *  Virtual Server Init
23181 + *
23182 + *  Copyright (C) 2004-2007  Herbert Pötzl
23183 + *
23184 + *  V0.01  basic structure
23185 + *
23186 + */
23187 +
23188 +#include <linux/init.h>
23189 +
23190 +int    vserver_register_sysctl(void);
23191 +void   vserver_unregister_sysctl(void);
23192 +
23193 +
23194 +static int __init init_vserver(void)
23195 +{
23196 +       int ret = 0;
23197 +
23198 +#ifdef CONFIG_VSERVER_DEBUG
23199 +       vserver_register_sysctl();
23200 +#endif
23201 +       return ret;
23202 +}
23203 +
23204 +
23205 +static void __exit exit_vserver(void)
23206 +{
23207 +
23208 +#ifdef CONFIG_VSERVER_DEBUG
23209 +       vserver_unregister_sysctl();
23210 +#endif
23211 +       return;
23212 +}
23213 +
23214 +/* FIXME: GFP_ZONETYPES gone
23215 +long vx_slab[GFP_ZONETYPES]; */
23216 +long vx_area;
23217 +
23218 +
23219 +module_init(init_vserver);
23220 +module_exit(exit_vserver);
23221 +
23222 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/inode.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/inode.c
23223 --- linux-2.6.22.10/kernel/vserver/inode.c      1970-01-01 01:00:00 +0100
23224 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/inode.c   2007-09-11 17:57:41 +0200
23225 @@ -0,0 +1,409 @@
23226 +/*
23227 + *  linux/kernel/vserver/inode.c
23228 + *
23229 + *  Virtual Server: File System Support
23230 + *
23231 + *  Copyright (C) 2004-2007  Herbert Pötzl
23232 + *
23233 + *  V0.01  separated from vcontext V0.05
23234 + *  V0.02  moved to tag (instead of xid)
23235 + *
23236 + */
23237 +
23238 +#include <linux/tty.h>
23239 +#include <linux/proc_fs.h>
23240 +#include <linux/devpts_fs.h>
23241 +#include <linux/fs.h>
23242 +#include <linux/file.h>
23243 +#include <linux/mount.h>
23244 +#include <linux/parser.h>
23245 +#include <linux/vserver/inode.h>
23246 +#include <linux/vserver/inode_cmd.h>
23247 +#include <linux/vs_base.h>
23248 +#include <linux/vs_tag.h>
23249 +
23250 +#include <asm/uaccess.h>
23251 +
23252 +
23253 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
23254 +{
23255 +       struct proc_dir_entry *entry;
23256 +
23257 +       if (!in || !in->i_sb)
23258 +               return -ESRCH;
23259 +
23260 +       *flags = IATTR_TAG
23261 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
23262 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
23263 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
23264 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
23265 +
23266 +       if (S_ISDIR(in->i_mode))
23267 +               *mask |= IATTR_BARRIER;
23268 +
23269 +       if (IS_TAGGED(in)) {
23270 +               *tag = in->i_tag;
23271 +               *mask |= IATTR_TAG;
23272 +       }
23273 +
23274 +       switch (in->i_sb->s_magic) {
23275 +       case PROC_SUPER_MAGIC:
23276 +               entry = PROC_I(in)->pde;
23277 +
23278 +               /* check for specific inodes? */
23279 +               if (entry)
23280 +                       *mask |= IATTR_FLAGS;
23281 +               if (entry)
23282 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
23283 +               else
23284 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
23285 +               break;
23286 +
23287 +       case DEVPTS_SUPER_MAGIC:
23288 +               *tag = in->i_tag;
23289 +               *mask |= IATTR_TAG;
23290 +               break;
23291 +
23292 +       default:
23293 +               break;
23294 +       }
23295 +       return 0;
23296 +}
23297 +
23298 +int vc_get_iattr(void __user *data)
23299 +{
23300 +       struct nameidata nd;
23301 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
23302 +       int ret;
23303 +
23304 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23305 +               return -EFAULT;
23306 +
23307 +       ret = user_path_walk_link(vc_data.name, &nd);
23308 +       if (!ret) {
23309 +               ret = __vc_get_iattr(nd.dentry->d_inode,
23310 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23311 +               path_release(&nd);
23312 +       }
23313 +       if (ret)
23314 +               return ret;
23315 +
23316 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23317 +               ret = -EFAULT;
23318 +       return ret;
23319 +}
23320 +
23321 +#ifdef CONFIG_COMPAT
23322 +
23323 +int vc_get_iattr_x32(void __user *data)
23324 +{
23325 +       struct nameidata nd;
23326 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
23327 +       int ret;
23328 +
23329 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23330 +               return -EFAULT;
23331 +
23332 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23333 +       if (!ret) {
23334 +               ret = __vc_get_iattr(nd.dentry->d_inode,
23335 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23336 +               path_release(&nd);
23337 +       }
23338 +       if (ret)
23339 +               return ret;
23340 +
23341 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23342 +               ret = -EFAULT;
23343 +       return ret;
23344 +}
23345 +
23346 +#endif /* CONFIG_COMPAT */
23347 +
23348 +
23349 +int vc_fget_iattr(uint32_t fd, void __user *data)
23350 +{
23351 +       struct file *filp;
23352 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
23353 +       int ret;
23354 +
23355 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23356 +               return -EFAULT;
23357 +
23358 +       filp = fget(fd);
23359 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23360 +               return -EBADF;
23361 +
23362 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
23363 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
23364 +
23365 +       fput(filp);
23366 +
23367 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23368 +               ret = -EFAULT;
23369 +       return ret;
23370 +}
23371 +
23372 +
23373 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
23374 +{
23375 +       struct inode *in = de->d_inode;
23376 +       int error = 0, is_proc = 0, has_tag = 0;
23377 +       struct iattr attr = { 0 };
23378 +
23379 +       if (!in || !in->i_sb)
23380 +               return -ESRCH;
23381 +
23382 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
23383 +       if ((*mask & IATTR_FLAGS) && !is_proc)
23384 +               return -EINVAL;
23385 +
23386 +       has_tag = IS_TAGGED(in) ||
23387 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
23388 +       if ((*mask & IATTR_TAG) && !has_tag)
23389 +               return -EINVAL;
23390 +
23391 +       mutex_lock(&in->i_mutex);
23392 +       if (*mask & IATTR_TAG) {
23393 +               attr.ia_tag = *tag;
23394 +               attr.ia_valid |= ATTR_TAG;
23395 +       }
23396 +
23397 +       if (*mask & IATTR_FLAGS) {
23398 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
23399 +               unsigned int iflags = PROC_I(in)->vx_flags;
23400 +
23401 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
23402 +                       | (*flags & IATTR_FLAGS);
23403 +               PROC_I(in)->vx_flags = iflags;
23404 +               if (entry)
23405 +                       entry->vx_flags = iflags;
23406 +       }
23407 +
23408 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
23409 +               if (*mask & IATTR_IMMUTABLE) {
23410 +                       if (*flags & IATTR_IMMUTABLE)
23411 +                               in->i_flags |= S_IMMUTABLE;
23412 +                       else
23413 +                               in->i_flags &= ~S_IMMUTABLE;
23414 +               }
23415 +               if (*mask & IATTR_IUNLINK) {
23416 +                       if (*flags & IATTR_IUNLINK)
23417 +                               in->i_flags |= S_IUNLINK;
23418 +                       else
23419 +                               in->i_flags &= ~S_IUNLINK;
23420 +               }
23421 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
23422 +                       if (*flags & IATTR_BARRIER)
23423 +                               in->i_flags |= S_BARRIER;
23424 +                       else
23425 +                               in->i_flags &= ~S_BARRIER;
23426 +               }
23427 +               if (in->i_op && in->i_op->sync_flags) {
23428 +                       error = in->i_op->sync_flags(in);
23429 +                       if (error)
23430 +                               goto out;
23431 +               }
23432 +       }
23433 +
23434 +       if (attr.ia_valid) {
23435 +               if (in->i_op && in->i_op->setattr)
23436 +                       error = in->i_op->setattr(de, &attr);
23437 +               else {
23438 +                       error = inode_change_ok(in, &attr);
23439 +                       if (!error)
23440 +                               error = inode_setattr(in, &attr);
23441 +               }
23442 +       }
23443 +
23444 +out:
23445 +       mutex_unlock(&in->i_mutex);
23446 +       return error;
23447 +}
23448 +
23449 +int vc_set_iattr(void __user *data)
23450 +{
23451 +       struct nameidata nd;
23452 +       struct vcmd_ctx_iattr_v1 vc_data;
23453 +       int ret;
23454 +
23455 +       if (!capable(CAP_LINUX_IMMUTABLE))
23456 +               return -EPERM;
23457 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23458 +               return -EFAULT;
23459 +
23460 +       ret = user_path_walk_link(vc_data.name, &nd);
23461 +       if (!ret) {
23462 +               ret = __vc_set_iattr(nd.dentry,
23463 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23464 +               path_release(&nd);
23465 +       }
23466 +
23467 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23468 +               ret = -EFAULT;
23469 +       return ret;
23470 +}
23471 +
23472 +#ifdef CONFIG_COMPAT
23473 +
23474 +int vc_set_iattr_x32(void __user *data)
23475 +{
23476 +       struct nameidata nd;
23477 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
23478 +       int ret;
23479 +
23480 +       if (!capable(CAP_LINUX_IMMUTABLE))
23481 +               return -EPERM;
23482 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23483 +               return -EFAULT;
23484 +
23485 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23486 +       if (!ret) {
23487 +               ret = __vc_set_iattr(nd.dentry,
23488 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23489 +               path_release(&nd);
23490 +       }
23491 +
23492 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23493 +               ret = -EFAULT;
23494 +       return ret;
23495 +}
23496 +
23497 +#endif /* CONFIG_COMPAT */
23498 +
23499 +int vc_fset_iattr(uint32_t fd, void __user *data)
23500 +{
23501 +       struct file *filp;
23502 +       struct vcmd_ctx_fiattr_v0 vc_data;
23503 +       int ret;
23504 +
23505 +       if (!capable(CAP_LINUX_IMMUTABLE))
23506 +               return -EPERM;
23507 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23508 +               return -EFAULT;
23509 +
23510 +       filp = fget(fd);
23511 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23512 +               return -EBADF;
23513 +
23514 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
23515 +               &vc_data.flags, &vc_data.mask);
23516 +
23517 +       fput(filp);
23518 +
23519 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23520 +               return -EFAULT;
23521 +       return ret;
23522 +}
23523 +
23524 +
23525 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
23526 +
23527 +static match_table_t tokens = {
23528 +       {Opt_notagcheck, "notagcheck"},
23529 +#ifdef CONFIG_PROPAGATE
23530 +       {Opt_notag, "notag"},
23531 +       {Opt_tag, "tag"},
23532 +       {Opt_tagid, "tagid=%u"},
23533 +#endif
23534 +       {Opt_err, NULL}
23535 +};
23536 +
23537 +
23538 +static void __dx_parse_remove(char *string, char *opt)
23539 +{
23540 +       char *p = strstr(string, opt);
23541 +       char *q = p;
23542 +
23543 +       if (p) {
23544 +               while (*q != '\0' && *q != ',')
23545 +                       q++;
23546 +               while (*q)
23547 +                       *p++ = *q++;
23548 +               while (*p)
23549 +                       *p++ = '\0';
23550 +       }
23551 +}
23552 +
23553 +static inline
23554 +int __dx_parse_tag(char *string, tag_t *tag, int remove)
23555 +{
23556 +       substring_t args[MAX_OPT_ARGS];
23557 +       int token, option = 0;
23558 +
23559 +       if (!string)
23560 +               return 0;
23561 +
23562 +       token = match_token(string, tokens, args);
23563 +
23564 +       vxdprintk(VXD_CBIT(tag, 7),
23565 +               "dx_parse_tag(»%s«): %d:#%d",
23566 +               string, token, option);
23567 +
23568 +       switch (token) {
23569 +       case Opt_tag:
23570 +               if (tag)
23571 +                       *tag = 0;
23572 +               if (remove)
23573 +                       __dx_parse_remove(string, "tag");
23574 +               return MNT_TAGID;
23575 +       case Opt_notag:
23576 +               if (remove)
23577 +                       __dx_parse_remove(string, "notag");
23578 +               return MNT_NOTAG;
23579 +       case Opt_notagcheck:
23580 +               if (remove)
23581 +                       __dx_parse_remove(string, "notagcheck");
23582 +               return MNT_NOTAGCHECK;
23583 +       case Opt_tagid:
23584 +               if (tag && !match_int(args, &option))
23585 +                       *tag = option;
23586 +               if (remove)
23587 +                       __dx_parse_remove(string, "tagid");
23588 +               return MNT_TAGID;
23589 +       }
23590 +       return 0;
23591 +}
23592 +
23593 +int dx_parse_tag(char *string, tag_t *tag, int remove)
23594 +{
23595 +       int retval, flags = 0;
23596 +
23597 +       while ((retval = __dx_parse_tag(string, tag, remove)))
23598 +               flags |= retval;
23599 +       return flags;
23600 +}
23601 +
23602 +#ifdef CONFIG_PROPAGATE
23603 +
23604 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
23605 +{
23606 +       tag_t new_tag = 0;
23607 +       struct vfsmount *mnt;
23608 +       int propagate;
23609 +
23610 +       if (!nd)
23611 +               return;
23612 +       mnt = nd->mnt;
23613 +       if (!mnt)
23614 +               return;
23615 +
23616 +       propagate = (mnt->mnt_flags & MNT_TAGID);
23617 +       if (propagate)
23618 +               new_tag = mnt->mnt_tag;
23619 +
23620 +       vxdprintk(VXD_CBIT(tag, 7),
23621 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
23622 +               inode, inode->i_ino, inode->i_tag,
23623 +               new_tag, (propagate) ? 1 : 0);
23624 +
23625 +       if (propagate)
23626 +               inode->i_tag = new_tag;
23627 +}
23628 +
23629 +#include <linux/module.h>
23630 +
23631 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
23632 +
23633 +#endif /* CONFIG_PROPAGATE */
23634 +
23635 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/limit.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit.c
23636 --- linux-2.6.22.10/kernel/vserver/limit.c      1970-01-01 01:00:00 +0100
23637 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit.c   2007-08-19 00:08:19 +0200
23638 @@ -0,0 +1,318 @@
23639 +/*
23640 + *  linux/kernel/vserver/limit.c
23641 + *
23642 + *  Virtual Server: Context Limits
23643 + *
23644 + *  Copyright (C) 2004-2007  Herbert Pötzl
23645 + *
23646 + *  V0.01  broken out from vcontext V0.05
23647 + *  V0.02  changed vcmds to vxi arg
23648 + *
23649 + */
23650 +
23651 +#include <linux/module.h>
23652 +#include <linux/vs_limit.h>
23653 +#include <linux/vserver/limit.h>
23654 +#include <linux/vserver/limit_cmd.h>
23655 +
23656 +#include <asm/uaccess.h>
23657 +
23658 +
23659 +const char *vlimit_name[NUM_LIMITS] = {
23660 +       [RLIMIT_CPU]            = "CPU",
23661 +       [RLIMIT_RSS]            = "RSS",
23662 +       [RLIMIT_NPROC]          = "NPROC",
23663 +       [RLIMIT_NOFILE]         = "NOFILE",
23664 +       [RLIMIT_MEMLOCK]        = "VML",
23665 +       [RLIMIT_AS]             = "VM",
23666 +       [RLIMIT_LOCKS]          = "LOCKS",
23667 +       [RLIMIT_SIGPENDING]     = "SIGP",
23668 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
23669 +
23670 +       [VLIMIT_NSOCK]          = "NSOCK",
23671 +       [VLIMIT_OPENFD]         = "OPENFD",
23672 +       [VLIMIT_ANON]           = "ANON",
23673 +       [VLIMIT_SHMEM]          = "SHMEM",
23674 +       [VLIMIT_DENTRY]         = "DENTRY",
23675 +};
23676 +
23677 +EXPORT_SYMBOL_GPL(vlimit_name);
23678 +
23679 +#define MASK_ENTRY(x)  (1 << (x))
23680 +
23681 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
23682 +               /* minimum */
23683 +       0
23684 +       ,       /* softlimit */
23685 +       MASK_ENTRY( RLIMIT_RSS          ) |
23686 +       MASK_ENTRY( VLIMIT_ANON         ) |
23687 +       0
23688 +       ,       /* maximum */
23689 +       MASK_ENTRY( RLIMIT_RSS          ) |
23690 +       MASK_ENTRY( RLIMIT_NPROC        ) |
23691 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
23692 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
23693 +       MASK_ENTRY( RLIMIT_AS           ) |
23694 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
23695 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
23696 +
23697 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
23698 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
23699 +       MASK_ENTRY( VLIMIT_ANON         ) |
23700 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
23701 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
23702 +       0
23703 +};
23704 +               /* accounting only */
23705 +uint32_t account_mask =
23706 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
23707 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
23708 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
23709 +       0;
23710 +
23711 +
23712 +static int is_valid_vlimit(int id)
23713 +{
23714 +       uint32_t mask = vlimit_mask.minimum |
23715 +               vlimit_mask.softlimit | vlimit_mask.maximum;
23716 +       return mask & (1 << id);
23717 +}
23718 +
23719 +static int is_accounted_vlimit(int id)
23720 +{
23721 +       if (is_valid_vlimit(id))
23722 +               return 1;
23723 +       return account_mask & (1 << id);
23724 +}
23725 +
23726 +
23727 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
23728 +{
23729 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
23730 +       return VX_VLIM(limit);
23731 +}
23732 +
23733 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
23734 +{
23735 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
23736 +       return VX_VLIM(limit);
23737 +}
23738 +
23739 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
23740 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
23741 +{
23742 +       if (!is_valid_vlimit(id))
23743 +               return -EINVAL;
23744 +
23745 +       if (minimum)
23746 +               *minimum = CRLIM_UNSET;
23747 +       if (softlimit)
23748 +               *softlimit = vc_get_soft(vxi, id);
23749 +       if (maximum)
23750 +               *maximum = vc_get_hard(vxi, id);
23751 +       return 0;
23752 +}
23753 +
23754 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
23755 +{
23756 +       struct vcmd_ctx_rlimit_v0 vc_data;
23757 +       int ret;
23758 +
23759 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23760 +               return -EFAULT;
23761 +
23762 +       ret = do_get_rlimit(vxi, vc_data.id,
23763 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23764 +       if (ret)
23765 +               return ret;
23766 +
23767 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23768 +               return -EFAULT;
23769 +       return 0;
23770 +}
23771 +
23772 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
23773 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
23774 +{
23775 +       if (!is_valid_vlimit(id))
23776 +               return -EINVAL;
23777 +
23778 +       if (maximum != CRLIM_KEEP)
23779 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
23780 +       if (softlimit != CRLIM_KEEP)
23781 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
23782 +
23783 +       /* clamp soft limit */
23784 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
23785 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
23786 +
23787 +       return 0;
23788 +}
23789 +
23790 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
23791 +{
23792 +       struct vcmd_ctx_rlimit_v0 vc_data;
23793 +
23794 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23795 +               return -EFAULT;
23796 +
23797 +       return do_set_rlimit(vxi, vc_data.id,
23798 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23799 +}
23800 +
23801 +#ifdef CONFIG_IA32_EMULATION
23802 +
23803 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
23804 +{
23805 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23806 +
23807 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23808 +               return -EFAULT;
23809 +
23810 +       return do_set_rlimit(vxi, vc_data.id,
23811 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23812 +}
23813 +
23814 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
23815 +{
23816 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23817 +       int ret;
23818 +
23819 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23820 +               return -EFAULT;
23821 +
23822 +       ret = do_get_rlimit(vxi, vc_data.id,
23823 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23824 +       if (ret)
23825 +               return ret;
23826 +
23827 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23828 +               return -EFAULT;
23829 +       return 0;
23830 +}
23831 +
23832 +#endif /* CONFIG_IA32_EMULATION */
23833 +
23834 +
23835 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
23836 +{
23837 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
23838 +               return -EFAULT;
23839 +       return 0;
23840 +}
23841 +
23842 +
23843 +static inline void vx_reset_minmax(struct _vx_limit *limit)
23844 +{
23845 +       rlim_t value;
23846 +       int lim;
23847 +
23848 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23849 +               value = __rlim_get(limit, lim);
23850 +               __rlim_rmax(limit, lim) = value;
23851 +               __rlim_rmin(limit, lim) = value;
23852 +       }
23853 +}
23854 +
23855 +
23856 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
23857 +{
23858 +       vx_reset_minmax(&vxi->limit);
23859 +       return 0;
23860 +}
23861 +
23862 +
23863 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
23864 +{
23865 +       struct vcmd_rlimit_stat_v0 vc_data;
23866 +       struct _vx_limit *limit = &vxi->limit;
23867 +       int id;
23868 +
23869 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23870 +               return -EFAULT;
23871 +
23872 +       id = vc_data.id;
23873 +       if (!is_accounted_vlimit(id))
23874 +               return -EINVAL;
23875 +
23876 +       vx_limit_fixup(limit, id);
23877 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
23878 +       vc_data.value = __rlim_get(limit, id);
23879 +       vc_data.minimum = __rlim_rmin(limit, id);
23880 +       vc_data.maximum = __rlim_rmax(limit, id);
23881 +
23882 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23883 +               return -EFAULT;
23884 +       return 0;
23885 +}
23886 +
23887 +
23888 +void vx_vsi_meminfo(struct sysinfo *val)
23889 +{
23890 +       struct vx_info *vxi = current->vx_info;
23891 +       unsigned long totalram, freeram;
23892 +       rlim_t v;
23893 +
23894 +       /* we blindly accept the max */
23895 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23896 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
23897 +
23898 +       /* total minus used equals free */
23899 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23900 +       freeram = (v < totalram) ? totalram - v : 0;
23901 +
23902 +       val->totalram = totalram;
23903 +       val->freeram = freeram;
23904 +       val->bufferram = 0;
23905 +       val->totalhigh = 0;
23906 +       val->freehigh = 0;
23907 +       return;
23908 +}
23909 +
23910 +void vx_vsi_swapinfo(struct sysinfo *val)
23911 +{
23912 +       struct vx_info *vxi = current->vx_info;
23913 +       unsigned long totalswap, freeswap;
23914 +       rlim_t v, w;
23915 +
23916 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23917 +       if (v == RLIM_INFINITY) {
23918 +               val->freeswap = val->totalswap;
23919 +               return;
23920 +       }
23921 +
23922 +       /* we blindly accept the max */
23923 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
23924 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
23925 +
23926 +       /* currently 'used' swap */
23927 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23928 +       w -= (w > v) ? v : w;
23929 +
23930 +       /* total minus used equals free */
23931 +       freeswap = (w < totalswap) ? totalswap - w : 0;
23932 +
23933 +       val->totalswap = totalswap;
23934 +       val->freeswap = freeswap;
23935 +       return;
23936 +}
23937 +
23938 +
23939 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
23940 +{
23941 +       struct vx_info *vxi = mm->mm_vx_info;
23942 +       unsigned long points;
23943 +       rlim_t v, w;
23944 +
23945 +       if (!vxi)
23946 +               return 0;
23947 +
23948 +       points = vxi->vx_badness_bias;
23949 +
23950 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23951 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23952 +       points += (v > w) ? (v - w) : 0;
23953 +
23954 +       return points;
23955 +}
23956 +
23957 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/limit_init.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit_init.h
23958 --- linux-2.6.22.10/kernel/vserver/limit_init.h 1970-01-01 01:00:00 +0100
23959 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit_init.h      2007-10-25 17:05:55 +0200
23960 @@ -0,0 +1,33 @@
23961 +
23962 +
23963 +static inline void vx_info_init_limit(struct _vx_limit *limit)
23964 +{
23965 +       int lim;
23966 +
23967 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23968 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
23969 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
23970 +               __rlim_set(limit, lim, 0);
23971 +               atomic_set(&__rlim_lhit(limit, lim), 0);
23972 +               __rlim_rmin(limit, lim) = 0;
23973 +               __rlim_rmax(limit, lim) = 0;
23974 +       }
23975 +}
23976 +
23977 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
23978 +{
23979 +#ifdef CONFIG_VSERVER_WARN
23980 +       rlim_t value;
23981 +       int lim;
23982 +
23983 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23984 +               if ((1 << lim) & VLIM_NOCHECK)
23985 +                       continue;
23986 +               value = __rlim_get(limit, lim);
23987 +               vxwprintk_xid(value,
23988 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
23989 +                       limit, vlimit_name[lim], lim, (long)value);
23990 +       }
23991 +#endif
23992 +}
23993 +
23994 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/limit_proc.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit_proc.h
23995 --- linux-2.6.22.10/kernel/vserver/limit_proc.h 1970-01-01 01:00:00 +0100
23996 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit_proc.h      2007-08-05 20:53:13 +0200
23997 @@ -0,0 +1,57 @@
23998 +#ifndef _VX_LIMIT_PROC_H
23999 +#define _VX_LIMIT_PROC_H
24000 +
24001 +#include <linux/vserver/limit_int.h>
24002 +
24003 +
24004 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
24005 +#define VX_LIMIT_TOP   \
24006 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
24007 +
24008 +#define VX_LIMIT_ARG(r)                                \
24009 +       (unsigned long)__rlim_get(limit, r),    \
24010 +       (unsigned long)__rlim_rmin(limit, r),   \
24011 +       (unsigned long)__rlim_rmax(limit, r),   \
24012 +       VX_VLIM(__rlim_soft(limit, r)),         \
24013 +       VX_VLIM(__rlim_hard(limit, r)),         \
24014 +       atomic_read(&__rlim_lhit(limit, r))
24015 +
24016 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
24017 +{
24018 +       vx_limit_fixup(limit, -1);
24019 +       return sprintf(buffer, VX_LIMIT_TOP
24020 +               "PROC"  VX_LIMIT_FMT
24021 +               "VM"    VX_LIMIT_FMT
24022 +               "VML"   VX_LIMIT_FMT
24023 +               "RSS"   VX_LIMIT_FMT
24024 +               "ANON"  VX_LIMIT_FMT
24025 +               "RMAP"  VX_LIMIT_FMT
24026 +               "FILES" VX_LIMIT_FMT
24027 +               "OFD"   VX_LIMIT_FMT
24028 +               "LOCKS" VX_LIMIT_FMT
24029 +               "SOCK"  VX_LIMIT_FMT
24030 +               "MSGQ"  VX_LIMIT_FMT
24031 +               "SHM"   VX_LIMIT_FMT
24032 +               "SEMA"  VX_LIMIT_FMT
24033 +               "SEMS"  VX_LIMIT_FMT
24034 +               "DENT"  VX_LIMIT_FMT,
24035 +               VX_LIMIT_ARG(RLIMIT_NPROC),
24036 +               VX_LIMIT_ARG(RLIMIT_AS),
24037 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
24038 +               VX_LIMIT_ARG(RLIMIT_RSS),
24039 +               VX_LIMIT_ARG(VLIMIT_ANON),
24040 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
24041 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
24042 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
24043 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
24044 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
24045 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
24046 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
24047 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
24048 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
24049 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
24050 +}
24051 +
24052 +#endif /* _VX_LIMIT_PROC_H */
24053 +
24054 +
24055 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/monitor.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/monitor.c
24056 --- linux-2.6.22.10/kernel/vserver/monitor.c    1970-01-01 01:00:00 +0100
24057 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/monitor.c 2007-08-15 23:18:20 +0200
24058 @@ -0,0 +1,138 @@
24059 +/*
24060 + *  kernel/vserver/monitor.c
24061 + *
24062 + *  Virtual Context Scheduler Monitor
24063 + *
24064 + *  Copyright (C) 2006-2007 Herbert Pötzl
24065 + *
24066 + *  V0.01  basic design
24067 + *
24068 + */
24069 +
24070 +#include <linux/module.h>
24071 +#include <linux/jiffies.h>
24072 +#include <asm/uaccess.h>
24073 +#include <asm/atomic.h>
24074 +
24075 +#include <linux/vserver/monitor.h>
24076 +#include <linux/vserver/debug_cmd.h>
24077 +
24078 +
24079 +#ifdef CONFIG_VSERVER_MONITOR
24080 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
24081 +#else
24082 +#define VXM_SIZE       64
24083 +#endif
24084 +
24085 +struct _vx_monitor {
24086 +       unsigned int counter;
24087 +
24088 +       struct _vx_mon_entry entry[VXM_SIZE+1];
24089 +};
24090 +
24091 +
24092 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
24093 +
24094 +unsigned volatile int vxm_active = 1;
24095 +
24096 +static atomic_t sequence = ATOMIC_INIT(0);
24097 +
24098 +
24099 +/*     vxm_advance()
24100 +
24101 +       * requires disabled preemption                          */
24102 +
24103 +struct _vx_mon_entry *vxm_advance(int cpu)
24104 +{
24105 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24106 +       struct _vx_mon_entry *entry;
24107 +       unsigned int index;
24108 +
24109 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
24110 +       entry = &mon->entry[index];
24111 +
24112 +       entry->ev.seq = atomic_inc_return(&sequence);
24113 +       entry->ev.jif = jiffies;
24114 +       return entry;
24115 +}
24116 +
24117 +EXPORT_SYMBOL_GPL(vxm_advance);
24118 +
24119 +
24120 +int do_read_monitor(struct __user _vx_mon_entry *data,
24121 +       int cpu, uint32_t *index, uint32_t *count)
24122 +{
24123 +       int pos, ret = 0;
24124 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24125 +       int end = mon->counter;
24126 +       int start = end - VXM_SIZE + 2;
24127 +       int idx = *index;
24128 +
24129 +       /* special case: get current pos */
24130 +       if (!*count) {
24131 +               *index = end;
24132 +               return 0;
24133 +       }
24134 +
24135 +       /* have we lost some data? */
24136 +       if (idx < start)
24137 +               idx = start;
24138 +
24139 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
24140 +               struct _vx_mon_entry *entry =
24141 +                       &mon->entry[idx % VXM_SIZE];
24142 +
24143 +               /* send entry to userspace */
24144 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
24145 +               if (ret)
24146 +                       break;
24147 +       }
24148 +       /* save new index and count */
24149 +       *index = idx;
24150 +       *count = pos;
24151 +       return ret ? ret : (*index < end);
24152 +}
24153 +
24154 +int vc_read_monitor(uint32_t id, void __user *data)
24155 +{
24156 +       struct vcmd_read_monitor_v0 vc_data;
24157 +       int ret;
24158 +
24159 +       if (id >= NR_CPUS)
24160 +               return -EINVAL;
24161 +
24162 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24163 +               return -EFAULT;
24164 +
24165 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
24166 +               id, &vc_data.index, &vc_data.count);
24167 +
24168 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24169 +               return -EFAULT;
24170 +       return ret;
24171 +}
24172 +
24173 +#ifdef CONFIG_COMPAT
24174 +
24175 +int vc_read_monitor_x32(uint32_t id, void __user *data)
24176 +{
24177 +       struct vcmd_read_monitor_v0_x32 vc_data;
24178 +       int ret;
24179 +
24180 +       if (id >= NR_CPUS)
24181 +               return -EINVAL;
24182 +
24183 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24184 +               return -EFAULT;
24185 +
24186 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
24187 +               compat_ptr(vc_data.data_ptr),
24188 +               id, &vc_data.index, &vc_data.count);
24189 +
24190 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24191 +               return -EFAULT;
24192 +       return ret;
24193 +}
24194 +
24195 +#endif /* CONFIG_COMPAT */
24196 +
24197 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/network.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/network.c
24198 --- linux-2.6.22.10/kernel/vserver/network.c    1970-01-01 01:00:00 +0100
24199 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/network.c 2007-10-05 14:54:36 +0200
24200 @@ -0,0 +1,862 @@
24201 +/*
24202 + *  linux/kernel/vserver/network.c
24203 + *
24204 + *  Virtual Server: Network Support
24205 + *
24206 + *  Copyright (C) 2003-2007  Herbert Pötzl
24207 + *
24208 + *  V0.01  broken out from vcontext V0.05
24209 + *  V0.02  cleaned up implementation
24210 + *  V0.03  added equiv nx commands
24211 + *  V0.04  switch to RCU based hash
24212 + *  V0.05  and back to locking again
24213 + *  V0.06  changed vcmds to nxi arg
24214 + *  V0.07  have __create claim() the nxi
24215 + *
24216 + */
24217 +
24218 +#include <linux/err.h>
24219 +#include <linux/slab.h>
24220 +#include <linux/rcupdate.h>
24221 +
24222 +#include <linux/vs_network.h>
24223 +#include <linux/vserver/network_cmd.h>
24224 +
24225 +
24226 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
24227 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
24228 +
24229 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
24230 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
24231 +
24232 +
24233 +static int __init init_network(void)
24234 +{
24235 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
24236 +               sizeof(struct nx_addr_v4), 0, SLAB_PANIC, NULL, NULL);
24237 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
24238 +               sizeof(struct nx_addr_v6), 0, SLAB_PANIC, NULL, NULL);
24239 +       return 0;
24240 +}
24241 +
24242 +
24243 +/*     __alloc_nx_addr_v4()                                    */
24244 +
24245 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
24246 +{
24247 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
24248 +               nx_addr_v4_cachep, GFP_KERNEL);
24249 +
24250 +       if (!IS_ERR(nxa))
24251 +               memset(nxa, 0, sizeof(*nxa));
24252 +       return nxa;
24253 +}
24254 +
24255 +/*     __dealloc_nx_addr_v4()                                  */
24256 +
24257 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
24258 +{
24259 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
24260 +}
24261 +
24262 +/*     __dealloc_nx_addr_v4_all()                              */
24263 +
24264 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
24265 +{
24266 +       while (nxa) {
24267 +               struct nx_addr_v4 *next = nxa->next;
24268 +
24269 +               __dealloc_nx_addr_v4(nxa);
24270 +               nxa = next;
24271 +       }
24272 +}
24273 +
24274 +
24275 +#ifdef CONFIG_IPV6
24276 +
24277 +/*     __alloc_nx_addr_v6()                                    */
24278 +
24279 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
24280 +{
24281 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
24282 +               nx_addr_v6_cachep, GFP_KERNEL);
24283 +
24284 +       if (!IS_ERR(nxa))
24285 +               memset(nxa, 0, sizeof(*nxa));
24286 +       return nxa;
24287 +}
24288 +
24289 +/*     __dealloc_nx_addr_v6()                                  */
24290 +
24291 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
24292 +{
24293 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
24294 +}
24295 +
24296 +/*     __dealloc_nx_addr_v6_all()                              */
24297 +
24298 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
24299 +{
24300 +       while (nxa) {
24301 +               struct nx_addr_v6 *next = nxa->next;
24302 +
24303 +               __dealloc_nx_addr_v6(nxa);
24304 +               nxa = next;
24305 +       }
24306 +}
24307 +
24308 +#endif /* CONFIG_IPV6 */
24309 +
24310 +
24311 +/*     __alloc_nx_info()
24312 +
24313 +       * allocate an initialized nx_info struct
24314 +       * doesn't make it visible (hash)                        */
24315 +
24316 +static struct nx_info *__alloc_nx_info(nid_t nid)
24317 +{
24318 +       struct nx_info *new = NULL;
24319 +
24320 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
24321 +
24322 +       /* would this benefit from a slab cache? */
24323 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
24324 +       if (!new)
24325 +               return 0;
24326 +
24327 +       memset(new, 0, sizeof(struct nx_info));
24328 +       new->nx_id = nid;
24329 +       INIT_HLIST_NODE(&new->nx_hlist);
24330 +       atomic_set(&new->nx_usecnt, 0);
24331 +       atomic_set(&new->nx_tasks, 0);
24332 +       new->nx_state = 0;
24333 +
24334 +       new->nx_flags = NXF_INIT_SET;
24335 +
24336 +       /* rest of init goes here */
24337 +
24338 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
24339 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
24340 +
24341 +       vxdprintk(VXD_CBIT(nid, 0),
24342 +               "alloc_nx_info(%d) = %p", nid, new);
24343 +       atomic_inc(&nx_global_ctotal);
24344 +       return new;
24345 +}
24346 +
24347 +/*     __dealloc_nx_info()
24348 +
24349 +       * final disposal of nx_info                             */
24350 +
24351 +static void __dealloc_nx_info(struct nx_info *nxi)
24352 +{
24353 +       vxdprintk(VXD_CBIT(nid, 0),
24354 +               "dealloc_nx_info(%p)", nxi);
24355 +
24356 +       nxi->nx_hlist.next = LIST_POISON1;
24357 +       nxi->nx_id = -1;
24358 +
24359 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24360 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24361 +
24362 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
24363 +
24364 +       nxi->nx_state |= NXS_RELEASED;
24365 +       kfree(nxi);
24366 +       atomic_dec(&nx_global_ctotal);
24367 +}
24368 +
24369 +static void __shutdown_nx_info(struct nx_info *nxi)
24370 +{
24371 +       nxi->nx_state |= NXS_SHUTDOWN;
24372 +       vs_net_change(nxi, VSC_NETDOWN);
24373 +}
24374 +
24375 +/*     exported stuff                                          */
24376 +
24377 +void free_nx_info(struct nx_info *nxi)
24378 +{
24379 +       /* context shutdown is mandatory */
24380 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
24381 +
24382 +       /* context must not be hashed */
24383 +       BUG_ON(nxi->nx_state & NXS_HASHED);
24384 +
24385 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24386 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24387 +
24388 +       __dealloc_nx_info(nxi);
24389 +}
24390 +
24391 +
24392 +void __nx_set_lback(struct nx_info *nxi)
24393 +{
24394 +       int nid = nxi->nx_id;
24395 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
24396 +
24397 +       nxi->v4_lback.s_addr = lback;
24398 +}
24399 +
24400 +extern int __nx_inet_add_lback(__be32 addr);
24401 +extern int __nx_inet_del_lback(__be32 addr);
24402 +
24403 +
24404 +/*     hash table for nx_info hash */
24405 +
24406 +#define NX_HASH_SIZE   13
24407 +
24408 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
24409 +
24410 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
24411 +
24412 +
24413 +static inline unsigned int __hashval(nid_t nid)
24414 +{
24415 +       return (nid % NX_HASH_SIZE);
24416 +}
24417 +
24418 +
24419 +
24420 +/*     __hash_nx_info()
24421 +
24422 +       * add the nxi to the global hash table
24423 +       * requires the hash_lock to be held                     */
24424 +
24425 +static inline void __hash_nx_info(struct nx_info *nxi)
24426 +{
24427 +       struct hlist_head *head;
24428 +
24429 +       vxd_assert_lock(&nx_info_hash_lock);
24430 +       vxdprintk(VXD_CBIT(nid, 4),
24431 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
24432 +
24433 +       /* context must not be hashed */
24434 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
24435 +
24436 +       nxi->nx_state |= NXS_HASHED;
24437 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
24438 +       hlist_add_head(&nxi->nx_hlist, head);
24439 +       atomic_inc(&nx_global_cactive);
24440 +}
24441 +
24442 +/*     __unhash_nx_info()
24443 +
24444 +       * remove the nxi from the global hash table
24445 +       * requires the hash_lock to be held                     */
24446 +
24447 +static inline void __unhash_nx_info(struct nx_info *nxi)
24448 +{
24449 +       vxd_assert_lock(&nx_info_hash_lock);
24450 +       vxdprintk(VXD_CBIT(nid, 4),
24451 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
24452 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
24453 +
24454 +       /* context must be hashed */
24455 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
24456 +       /* but without tasks */
24457 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24458 +
24459 +       nxi->nx_state &= ~NXS_HASHED;
24460 +       hlist_del(&nxi->nx_hlist);
24461 +       atomic_dec(&nx_global_cactive);
24462 +}
24463 +
24464 +
24465 +/*     __lookup_nx_info()
24466 +
24467 +       * requires the hash_lock to be held
24468 +       * doesn't increment the nx_refcnt                       */
24469 +
24470 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
24471 +{
24472 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
24473 +       struct hlist_node *pos;
24474 +       struct nx_info *nxi;
24475 +
24476 +       vxd_assert_lock(&nx_info_hash_lock);
24477 +       hlist_for_each(pos, head) {
24478 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24479 +
24480 +               if (nxi->nx_id == nid)
24481 +                       goto found;
24482 +       }
24483 +       nxi = NULL;
24484 +found:
24485 +       vxdprintk(VXD_CBIT(nid, 0),
24486 +               "__lookup_nx_info(#%u): %p[#%u]",
24487 +               nid, nxi, nxi ? nxi->nx_id : 0);
24488 +       return nxi;
24489 +}
24490 +
24491 +
24492 +/*     __create_nx_info()
24493 +
24494 +       * create the requested context
24495 +       * get(), claim() and hash it                            */
24496 +
24497 +static struct nx_info *__create_nx_info(int id)
24498 +{
24499 +       struct nx_info *new, *nxi = NULL;
24500 +
24501 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
24502 +
24503 +       if (!(new = __alloc_nx_info(id)))
24504 +               return ERR_PTR(-ENOMEM);
24505 +
24506 +       /* required to make dynamic xids unique */
24507 +       spin_lock(&nx_info_hash_lock);
24508 +
24509 +       /* static context requested */
24510 +       if ((nxi = __lookup_nx_info(id))) {
24511 +               vxdprintk(VXD_CBIT(nid, 0),
24512 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
24513 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24514 +                       nxi = ERR_PTR(-EBUSY);
24515 +               else
24516 +                       nxi = ERR_PTR(-EEXIST);
24517 +               goto out_unlock;
24518 +       }
24519 +       /* new context */
24520 +       vxdprintk(VXD_CBIT(nid, 0),
24521 +               "create_nx_info(%d) = %p (new)", id, new);
24522 +       claim_nx_info(new, NULL);
24523 +       __nx_set_lback(new);
24524 +       __hash_nx_info(get_nx_info(new));
24525 +       nxi = new, new = NULL;
24526 +
24527 +out_unlock:
24528 +       spin_unlock(&nx_info_hash_lock);
24529 +       if (new)
24530 +               __dealloc_nx_info(new);
24531 +       return nxi;
24532 +}
24533 +
24534 +
24535 +
24536 +/*     exported stuff                                          */
24537 +
24538 +
24539 +void unhash_nx_info(struct nx_info *nxi)
24540 +{
24541 +       __shutdown_nx_info(nxi);
24542 +       spin_lock(&nx_info_hash_lock);
24543 +       __unhash_nx_info(nxi);
24544 +       spin_unlock(&nx_info_hash_lock);
24545 +}
24546 +
24547 +/*     lookup_nx_info()
24548 +
24549 +       * search for a nx_info and get() it
24550 +       * negative id means current                             */
24551 +
24552 +struct nx_info *lookup_nx_info(int id)
24553 +{
24554 +       struct nx_info *nxi = NULL;
24555 +
24556 +       if (id < 0) {
24557 +               nxi = get_nx_info(current->nx_info);
24558 +       } else if (id > 1) {
24559 +               spin_lock(&nx_info_hash_lock);
24560 +               nxi = get_nx_info(__lookup_nx_info(id));
24561 +               spin_unlock(&nx_info_hash_lock);
24562 +       }
24563 +       return nxi;
24564 +}
24565 +
24566 +/*     nid_is_hashed()
24567 +
24568 +       * verify that nid is still hashed                       */
24569 +
24570 +int nid_is_hashed(nid_t nid)
24571 +{
24572 +       int hashed;
24573 +
24574 +       spin_lock(&nx_info_hash_lock);
24575 +       hashed = (__lookup_nx_info(nid) != NULL);
24576 +       spin_unlock(&nx_info_hash_lock);
24577 +       return hashed;
24578 +}
24579 +
24580 +
24581 +#ifdef CONFIG_PROC_FS
24582 +
24583 +/*     get_nid_list()
24584 +
24585 +       * get a subset of hashed nids for proc
24586 +       * assumes size is at least one                          */
24587 +
24588 +int get_nid_list(int index, unsigned int *nids, int size)
24589 +{
24590 +       int hindex, nr_nids = 0;
24591 +
24592 +       /* only show current and children */
24593 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
24594 +               if (index > 0)
24595 +                       return 0;
24596 +               nids[nr_nids] = nx_current_nid();
24597 +               return 1;
24598 +       }
24599 +
24600 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
24601 +               struct hlist_head *head = &nx_info_hash[hindex];
24602 +               struct hlist_node *pos;
24603 +
24604 +               spin_lock(&nx_info_hash_lock);
24605 +               hlist_for_each(pos, head) {
24606 +                       struct nx_info *nxi;
24607 +
24608 +                       if (--index > 0)
24609 +                               continue;
24610 +
24611 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24612 +                       nids[nr_nids] = nxi->nx_id;
24613 +                       if (++nr_nids >= size) {
24614 +                               spin_unlock(&nx_info_hash_lock);
24615 +                               goto out;
24616 +                       }
24617 +               }
24618 +               /* keep the lock time short */
24619 +               spin_unlock(&nx_info_hash_lock);
24620 +       }
24621 +out:
24622 +       return nr_nids;
24623 +}
24624 +#endif
24625 +
24626 +
24627 +/*
24628 + *     migrate task to new network
24629 + *     gets nxi, puts old_nxi on change
24630 + */
24631 +
24632 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
24633 +{
24634 +       struct nx_info *old_nxi;
24635 +       int ret = 0;
24636 +
24637 +       if (!p || !nxi)
24638 +               BUG();
24639 +
24640 +       vxdprintk(VXD_CBIT(nid, 5),
24641 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
24642 +               p, nxi, nxi->nx_id,
24643 +               atomic_read(&nxi->nx_usecnt),
24644 +               atomic_read(&nxi->nx_tasks));
24645 +
24646 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
24647 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24648 +               return -EACCES;
24649 +
24650 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
24651 +               return -EFAULT;
24652 +
24653 +       /* maybe disallow this completely? */
24654 +       old_nxi = task_get_nx_info(p);
24655 +       if (old_nxi == nxi)
24656 +               goto out;
24657 +
24658 +       task_lock(p);
24659 +       if (old_nxi)
24660 +               clr_nx_info(&p->nx_info);
24661 +       claim_nx_info(nxi, p);
24662 +       set_nx_info(&p->nx_info, nxi);
24663 +       p->nid = nxi->nx_id;
24664 +       task_unlock(p);
24665 +
24666 +       vxdprintk(VXD_CBIT(nid, 5),
24667 +               "moved task %p into nxi:%p[#%d]",
24668 +               p, nxi, nxi->nx_id);
24669 +
24670 +       if (old_nxi)
24671 +               release_nx_info(old_nxi, p);
24672 +       ret = 0;
24673 +out:
24674 +       put_nx_info(old_nxi);
24675 +       return ret;
24676 +}
24677 +
24678 +
24679 +void nx_set_persistent(struct nx_info *nxi)
24680 +{
24681 +       vxdprintk(VXD_CBIT(nid, 6),
24682 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
24683 +
24684 +       get_nx_info(nxi);
24685 +       claim_nx_info(nxi, NULL);
24686 +}
24687 +
24688 +void nx_clear_persistent(struct nx_info *nxi)
24689 +{
24690 +       vxdprintk(VXD_CBIT(nid, 6),
24691 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
24692 +
24693 +       release_nx_info(nxi, NULL);
24694 +       put_nx_info(nxi);
24695 +}
24696 +
24697 +void nx_update_persistent(struct nx_info *nxi)
24698 +{
24699 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
24700 +               nx_set_persistent(nxi);
24701 +       else
24702 +               nx_clear_persistent(nxi);
24703 +}
24704 +
24705 +/* vserver syscall commands below here */
24706 +
24707 +/* taks nid and nx_info functions */
24708 +
24709 +#include <asm/uaccess.h>
24710 +
24711 +
24712 +int vc_task_nid(uint32_t id)
24713 +{
24714 +       nid_t nid;
24715 +
24716 +       if (id) {
24717 +               struct task_struct *tsk;
24718 +
24719 +               read_lock(&tasklist_lock);
24720 +               tsk = find_task_by_real_pid(id);
24721 +               nid = (tsk) ? tsk->nid : -ESRCH;
24722 +               read_unlock(&tasklist_lock);
24723 +       } else
24724 +               nid = nx_current_nid();
24725 +       return nid;
24726 +}
24727 +
24728 +
24729 +int vc_nx_info(struct nx_info *nxi, void __user *data)
24730 +{
24731 +       struct vcmd_nx_info_v0 vc_data;
24732 +
24733 +       vc_data.nid = nxi->nx_id;
24734 +
24735 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24736 +               return -EFAULT;
24737 +       return 0;
24738 +}
24739 +
24740 +
24741 +/* network functions */
24742 +
24743 +int vc_net_create(uint32_t nid, void __user *data)
24744 +{
24745 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
24746 +       struct nx_info *new_nxi;
24747 +       int ret;
24748 +
24749 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24750 +               return -EFAULT;
24751 +
24752 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
24753 +               return -EINVAL;
24754 +
24755 +       new_nxi = __create_nx_info(nid);
24756 +       if (IS_ERR(new_nxi))
24757 +               return PTR_ERR(new_nxi);
24758 +
24759 +       /* initial flags */
24760 +       new_nxi->nx_flags = vc_data.flagword;
24761 +
24762 +       ret = -ENOEXEC;
24763 +       if (vs_net_change(new_nxi, VSC_NETUP))
24764 +               goto out;
24765 +
24766 +       ret = nx_migrate_task(current, new_nxi);
24767 +       if (ret)
24768 +               goto out;
24769 +
24770 +       /* return context id on success */
24771 +       ret = new_nxi->nx_id;
24772 +
24773 +       /* get a reference for persistent contexts */
24774 +       if ((vc_data.flagword & NXF_PERSISTENT))
24775 +               nx_set_persistent(new_nxi);
24776 +out:
24777 +       release_nx_info(new_nxi, NULL);
24778 +       put_nx_info(new_nxi);
24779 +       return ret;
24780 +}
24781 +
24782 +
24783 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
24784 +{
24785 +       return nx_migrate_task(current, nxi);
24786 +}
24787 +
24788 +
24789 +
24790 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
24791 +       uint16_t type, uint16_t flags)
24792 +{
24793 +       struct nx_addr_v4 *nxa = &nxi->v4;
24794 +
24795 +       if (NX_IPV4(nxi)) {
24796 +               /* locate last entry */
24797 +               for (; nxa->next; nxa = nxa->next);
24798 +               nxa->next = __alloc_nx_addr_v4();
24799 +               nxa = nxa->next;
24800 +
24801 +               if (IS_ERR(nxa))
24802 +                       return PTR_ERR(nxa);
24803 +       }
24804 +
24805 +       if (nxi->v4.next)
24806 +               /* remove single ip for ip list */
24807 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
24808 +
24809 +       nxa->ip[0].s_addr = ip;
24810 +       nxa->ip[1].s_addr = ip2;
24811 +       nxa->mask.s_addr = mask;
24812 +       nxa->type = type;
24813 +       nxa->flags = flags;
24814 +       return 0;
24815 +}
24816 +
24817 +
24818 +int vc_net_add(struct nx_info *nxi, void __user *data)
24819 +{
24820 +       struct vcmd_net_addr_v0 vc_data;
24821 +       int index, ret = 0;
24822 +
24823 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24824 +               return -EFAULT;
24825 +
24826 +       switch (vc_data.type) {
24827 +       case NXA_TYPE_IPV4:
24828 +               if ((vc_data.count < 1) || (vc_data.count > 4))
24829 +                       return -EINVAL;
24830 +
24831 +               index = 0;
24832 +               while (index < vc_data.count) {
24833 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
24834 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
24835 +                       if (ret)
24836 +                               return ret;
24837 +                       index++;
24838 +               }
24839 +               ret = index;
24840 +               break;
24841 +
24842 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
24843 +               nxi->v4_bcast = vc_data.ip[0];
24844 +               ret = 1;
24845 +               break;
24846 +
24847 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
24848 +               nxi->v4_lback = vc_data.ip[0];
24849 +               ret = 1;
24850 +               break;
24851 +
24852 +       default:
24853 +               ret = -EINVAL;
24854 +               break;
24855 +       }
24856 +       return ret;
24857 +}
24858 +
24859 +int vc_net_remove(struct nx_info *nxi, void __user *data)
24860 +{
24861 +       struct vcmd_net_addr_v0 vc_data;
24862 +
24863 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24864 +               return -EFAULT;
24865 +
24866 +       switch (vc_data.type) {
24867 +       case NXA_TYPE_ANY:
24868 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24869 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24870 +               break;
24871 +
24872 +       default:
24873 +               return -EINVAL;
24874 +       }
24875 +       return 0;
24876 +}
24877 +
24878 +
24879 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
24880 +{
24881 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24882 +
24883 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24884 +               return -EFAULT;
24885 +
24886 +       switch (vc_data.type) {
24887 +       case NXA_TYPE_ADDR:
24888 +       case NXA_TYPE_RANGE:
24889 +       case NXA_TYPE_MASK:
24890 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
24891 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
24892 +
24893 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
24894 +               nxi->v4_bcast = vc_data.ip;
24895 +               break;
24896 +
24897 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
24898 +               nxi->v4_lback = vc_data.ip;
24899 +               break;
24900 +
24901 +       default:
24902 +               return -EINVAL;
24903 +       }
24904 +       return 0;
24905 +}
24906 +
24907 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
24908 +{
24909 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24910 +
24911 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24912 +               return -EFAULT;
24913 +
24914 +       switch (vc_data.type) {
24915 +/*     case NXA_TYPE_ADDR:
24916 +               break;          */
24917 +
24918 +       case NXA_TYPE_ANY:
24919 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24920 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24921 +               break;
24922 +
24923 +       default:
24924 +               return -EINVAL;
24925 +       }
24926 +       return 0;
24927 +}
24928 +
24929 +
24930 +#ifdef CONFIG_IPV6
24931 +
24932 +int do_add_v6_addr(struct nx_info *nxi,
24933 +       struct in6_addr *ip, struct in6_addr *mask,
24934 +       uint32_t prefix, uint16_t type, uint16_t flags)
24935 +{
24936 +       struct nx_addr_v6 *nxa = &nxi->v6;
24937 +
24938 +       if (NX_IPV6(nxi)) {
24939 +               /* locate last entry */
24940 +               for (; nxa->next; nxa = nxa->next);
24941 +               nxa->next = __alloc_nx_addr_v6();
24942 +               nxa = nxa->next;
24943 +
24944 +               if (IS_ERR(nxa))
24945 +                       return PTR_ERR(nxa);
24946 +       }
24947 +
24948 +       nxa->ip = *ip;
24949 +       nxa->mask = *mask;
24950 +       nxa->prefix = prefix;
24951 +       nxa->type = type;
24952 +       nxa->flags = flags;
24953 +       return 0;
24954 +}
24955 +
24956 +
24957 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
24958 +{
24959 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24960 +
24961 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24962 +               return -EFAULT;
24963 +
24964 +       switch (vc_data.type) {
24965 +       case NXA_TYPE_ADDR:
24966 +       case NXA_TYPE_MASK:
24967 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
24968 +                       vc_data.prefix, vc_data.type, vc_data.flags);
24969 +       default:
24970 +               return -EINVAL;
24971 +       }
24972 +       return 0;
24973 +}
24974 +
24975 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
24976 +{
24977 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24978 +
24979 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24980 +               return -EFAULT;
24981 +
24982 +       switch (vc_data.type) {
24983 +       case NXA_TYPE_ANY:
24984 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
24985 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
24986 +               break;
24987 +
24988 +       default:
24989 +               return -EINVAL;
24990 +       }
24991 +       return 0;
24992 +}
24993 +
24994 +#endif /* CONFIG_IPV6 */
24995 +
24996 +
24997 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
24998 +{
24999 +       struct vcmd_net_flags_v0 vc_data;
25000 +
25001 +       vc_data.flagword = nxi->nx_flags;
25002 +
25003 +       /* special STATE flag handling */
25004 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
25005 +
25006 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
25007 +               return -EFAULT;
25008 +       return 0;
25009 +}
25010 +
25011 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
25012 +{
25013 +       struct vcmd_net_flags_v0 vc_data;
25014 +       uint64_t mask, trigger;
25015 +
25016 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25017 +               return -EFAULT;
25018 +
25019 +       /* special STATE flag handling */
25020 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
25021 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
25022 +
25023 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
25024 +               vc_data.flagword, mask);
25025 +       if (trigger & NXF_PERSISTENT)
25026 +               nx_update_persistent(nxi);
25027 +
25028 +       return 0;
25029 +}
25030 +
25031 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
25032 +{
25033 +       struct vcmd_net_caps_v0 vc_data;
25034 +
25035 +       vc_data.ncaps = nxi->nx_ncaps;
25036 +       vc_data.cmask = ~0ULL;
25037 +
25038 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
25039 +               return -EFAULT;
25040 +       return 0;
25041 +}
25042 +
25043 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
25044 +{
25045 +       struct vcmd_net_caps_v0 vc_data;
25046 +
25047 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
25048 +               return -EFAULT;
25049 +
25050 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
25051 +               vc_data.ncaps, vc_data.cmask);
25052 +       return 0;
25053 +}
25054 +
25055 +
25056 +#include <linux/module.h>
25057 +
25058 +module_init(init_network);
25059 +
25060 +EXPORT_SYMBOL_GPL(free_nx_info);
25061 +EXPORT_SYMBOL_GPL(unhash_nx_info);
25062 +
25063 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/proc.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/proc.c
25064 --- linux-2.6.22.10/kernel/vserver/proc.c       1970-01-01 01:00:00 +0100
25065 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/proc.c    2007-10-05 14:54:36 +0200
25066 @@ -0,0 +1,1065 @@
25067 +/*
25068 + *  linux/kernel/vserver/proc.c
25069 + *
25070 + *  Virtual Context Support
25071 + *
25072 + *  Copyright (C) 2003-2007  Herbert Pötzl
25073 + *
25074 + *  V0.01  basic structure
25075 + *  V0.02  adaptation vs1.3.0
25076 + *  V0.03  proc permissions
25077 + *  V0.04  locking/generic
25078 + *  V0.05  next generation procfs
25079 + *  V0.06  inode validation
25080 + *  V0.07  generic rewrite vid
25081 + *  V0.08  remove inode type
25082 + *
25083 + */
25084 +
25085 +#include <linux/proc_fs.h>
25086 +#include <asm/unistd.h>
25087 +
25088 +#include <linux/vs_context.h>
25089 +#include <linux/vs_network.h>
25090 +#include <linux/vs_cvirt.h>
25091 +#include <linux/vs_inet.h>
25092 +#include <linux/vs_inet6.h>
25093 +
25094 +#include <linux/vserver/global.h>
25095 +
25096 +#include "cvirt_proc.h"
25097 +#include "cacct_proc.h"
25098 +#include "limit_proc.h"
25099 +#include "sched_proc.h"
25100 +#include "vci_config.h"
25101 +
25102 +static struct proc_dir_entry *proc_virtual;
25103 +
25104 +static struct proc_dir_entry *proc_virtnet;
25105 +
25106 +
25107 +/* first the actual feeds */
25108 +
25109 +
25110 +static int proc_vci(char *buffer)
25111 +{
25112 +       return sprintf(buffer,
25113 +               "VCIVersion:\t%04x:%04x\n"
25114 +               "VCISyscall:\t%d\n"
25115 +               "VCIKernel:\t%08x\n",
25116 +               VCI_VERSION >> 16,
25117 +               VCI_VERSION & 0xFFFF,
25118 +               __NR_vserver,
25119 +               vci_kernel_config());
25120 +}
25121 +
25122 +static int proc_virtual_info(char *buffer)
25123 +{
25124 +       return proc_vci(buffer);
25125 +}
25126 +
25127 +static int proc_virtual_status(char *buffer)
25128 +{
25129 +       return sprintf(buffer,
25130 +               "#CTotal:\t%d\n"
25131 +               "#CActive:\t%d\n"
25132 +               "#NSProxy:\t%d\t%d %d %d %d\n",
25133 +               atomic_read(&vx_global_ctotal),
25134 +               atomic_read(&vx_global_cactive),
25135 +               atomic_read(&vs_global_nsproxy),
25136 +               atomic_read(&vs_global_fs),
25137 +               atomic_read(&vs_global_mnt_ns),
25138 +               atomic_read(&vs_global_uts_ns),
25139 +               atomic_read(&vs_global_ipc_ns));
25140 +}
25141 +
25142 +
25143 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
25144 +{
25145 +       int length;
25146 +
25147 +       length = sprintf(buffer,
25148 +               "ID:\t%d\n"
25149 +               "Info:\t%p\n"
25150 +               "Init:\t%d\n"
25151 +               "OOM:\t%lld\n",
25152 +               vxi->vx_id,
25153 +               vxi,
25154 +               vxi->vx_initpid,
25155 +               vxi->vx_badness_bias);
25156 +       return length;
25157 +}
25158 +
25159 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
25160 +{
25161 +       int length;
25162 +
25163 +       length = sprintf(buffer,
25164 +               "UseCnt:\t%d\n"
25165 +               "Tasks:\t%d\n"
25166 +               "Flags:\t%016llx\n"
25167 +               "BCaps:\t%016llx\n"
25168 +               "CCaps:\t%016llx\n"
25169 +               "Spaces:\t%08lx\n",
25170 +               atomic_read(&vxi->vx_usecnt),
25171 +               atomic_read(&vxi->vx_tasks),
25172 +               (unsigned long long)vxi->vx_flags,
25173 +               (unsigned long long)vxi->vx_bcaps,
25174 +               (unsigned long long)vxi->vx_ccaps,
25175 +               vxi->vx_nsmask);
25176 +       return length;
25177 +}
25178 +
25179 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
25180 +{
25181 +       return vx_info_proc_limit(&vxi->limit, buffer);
25182 +}
25183 +
25184 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
25185 +{
25186 +       int cpu, length;
25187 +
25188 +       length = vx_info_proc_sched(&vxi->sched, buffer);
25189 +       for_each_online_cpu(cpu) {
25190 +               length += vx_info_proc_sched_pc(
25191 +                       &vx_per_cpu(vxi, sched_pc, cpu),
25192 +                       buffer + length, cpu);
25193 +       }
25194 +       return length;
25195 +}
25196 +
25197 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
25198 +{
25199 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
25200 +}
25201 +
25202 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
25203 +{
25204 +       int cpu, length;
25205 +
25206 +       vx_update_load(vxi);
25207 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
25208 +       for_each_online_cpu(cpu) {
25209 +               length += vx_info_proc_cvirt_pc(
25210 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
25211 +                       buffer + length, cpu);
25212 +       }
25213 +       return length;
25214 +}
25215 +
25216 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
25217 +{
25218 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
25219 +}
25220 +
25221 +
25222 +static int proc_virtnet_info(char *buffer)
25223 +{
25224 +       return proc_vci(buffer);
25225 +}
25226 +
25227 +static int proc_virtnet_status(char *buffer)
25228 +{
25229 +       return sprintf(buffer,
25230 +               "#CTotal:\t%d\n"
25231 +               "#CActive:\t%d\n",
25232 +               atomic_read(&nx_global_ctotal),
25233 +               atomic_read(&nx_global_cactive));
25234 +}
25235 +
25236 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
25237 +{
25238 +       struct nx_addr_v4 *v4a;
25239 +#ifdef CONFIG_IPV6
25240 +       struct nx_addr_v6 *v6a;
25241 +#endif
25242 +       int length, i;
25243 +
25244 +       length = sprintf(buffer,
25245 +               "ID:\t%d\n"
25246 +               "Info:\t%p\n"
25247 +               "Bcast:\t" NIPQUAD_FMT "\n"
25248 +               "Lback:\t" NIPQUAD_FMT "\n",
25249 +               nxi->nx_id,
25250 +               nxi,
25251 +               NIPQUAD(nxi->v4_bcast.s_addr),
25252 +               NIPQUAD(nxi->v4_lback.s_addr));
25253 +
25254 +       if (!NX_IPV4(nxi))
25255 +               goto skip_v4;
25256 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
25257 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
25258 +                       i, NXAV4(v4a));
25259 +skip_v4:
25260 +#ifdef CONFIG_IPV6
25261 +       if (!NX_IPV6(nxi))
25262 +               goto skip_v6;
25263 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
25264 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
25265 +                       i, NXAV6(v6a));
25266 +skip_v6:
25267 +#endif
25268 +       return length;
25269 +}
25270 +
25271 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
25272 +{
25273 +       int length;
25274 +
25275 +       length = sprintf(buffer,
25276 +               "UseCnt:\t%d\n"
25277 +               "Tasks:\t%d\n"
25278 +               "Flags:\t%016llx\n"
25279 +               "NCaps:\t%016llx\n",
25280 +               atomic_read(&nxi->nx_usecnt),
25281 +               atomic_read(&nxi->nx_tasks),
25282 +               (unsigned long long)nxi->nx_flags,
25283 +               (unsigned long long)nxi->nx_ncaps);
25284 +       return length;
25285 +}
25286 +
25287 +
25288 +
25289 +/* here the inode helpers */
25290 +
25291 +struct vs_entry {
25292 +       int len;
25293 +       char *name;
25294 +       mode_t mode;
25295 +       struct inode_operations *iop;
25296 +       struct file_operations *fop;
25297 +       union proc_op op;
25298 +};
25299 +
25300 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
25301 +{
25302 +       struct inode *inode = new_inode(sb);
25303 +
25304 +       if (!inode)
25305 +               goto out;
25306 +
25307 +       inode->i_mode = p->mode;
25308 +       if (p->iop)
25309 +               inode->i_op = p->iop;
25310 +       if (p->fop)
25311 +               inode->i_fop = p->fop;
25312 +
25313 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
25314 +       inode->i_flags |= S_IMMUTABLE;
25315 +
25316 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
25317 +
25318 +       inode->i_uid = 0;
25319 +       inode->i_gid = 0;
25320 +       inode->i_tag = 0;
25321 +out:
25322 +       return inode;
25323 +}
25324 +
25325 +static struct dentry *vs_proc_instantiate(struct inode *dir,
25326 +       struct dentry *dentry, int id, void *ptr)
25327 +{
25328 +       struct vs_entry *p = ptr;
25329 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
25330 +       struct dentry *error = ERR_PTR(-EINVAL);
25331 +
25332 +       if (!inode)
25333 +               goto out;
25334 +
25335 +       PROC_I(inode)->op = p->op;
25336 +       PROC_I(inode)->fd = id;
25337 +       d_add(dentry, inode);
25338 +       error = NULL;
25339 +out:
25340 +       return error;
25341 +}
25342 +
25343 +/* Lookups */
25344 +
25345 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
25346 +
25347 +/*
25348 + * Fill a directory entry.
25349 + *
25350 + * If possible create the dcache entry and derive our inode number and
25351 + * file type from dcache entry.
25352 + *
25353 + * Since all of the proc inode numbers are dynamically generated, the inode
25354 + * numbers do not exist until the inode is cache.  This means creating the
25355 + * the dcache entry in readdir is necessary to keep the inode numbers
25356 + * reported by readdir in sync with the inode numbers reported
25357 + * by stat.
25358 + */
25359 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
25360 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
25361 +{
25362 +       struct dentry *child, *dir = filp->f_dentry;
25363 +       struct inode *inode;
25364 +       struct qstr qname;
25365 +       ino_t ino = 0;
25366 +       unsigned type = DT_UNKNOWN;
25367 +
25368 +       qname.name = name;
25369 +       qname.len  = len;
25370 +       qname.hash = full_name_hash(name, len);
25371 +
25372 +       child = d_lookup(dir, &qname);
25373 +       if (!child) {
25374 +               struct dentry *new;
25375 +               new = d_alloc(dir, &qname);
25376 +               if (new) {
25377 +                       child = instantiate(dir->d_inode, new, id, ptr);
25378 +                       if (child)
25379 +                               dput(new);
25380 +                       else
25381 +                               child = new;
25382 +               }
25383 +       }
25384 +       if (!child || IS_ERR(child) || !child->d_inode)
25385 +               goto end_instantiate;
25386 +       inode = child->d_inode;
25387 +       if (inode) {
25388 +               ino = inode->i_ino;
25389 +               type = inode->i_mode >> 12;
25390 +       }
25391 +       dput(child);
25392 +end_instantiate:
25393 +       if (!ino)
25394 +               ino = find_inode_number(dir, &qname);
25395 +       if (!ino)
25396 +               ino = 1;
25397 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
25398 +}
25399 +
25400 +
25401 +
25402 +/* get and revalidate vx_info/xid */
25403 +
25404 +static inline
25405 +struct vx_info *get_proc_vx_info(struct inode *inode)
25406 +{
25407 +       return lookup_vx_info(PROC_I(inode)->fd);
25408 +}
25409 +
25410 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
25411 +{
25412 +       struct inode *inode = dentry->d_inode;
25413 +       xid_t xid = PROC_I(inode)->fd;
25414 +
25415 +       if (!xid || xid_is_hashed(xid))
25416 +               return 1;
25417 +       d_drop(dentry);
25418 +       return 0;
25419 +}
25420 +
25421 +
25422 +/* get and revalidate nx_info/nid */
25423 +
25424 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
25425 +{
25426 +       struct inode *inode = dentry->d_inode;
25427 +       nid_t nid = PROC_I(inode)->fd;
25428 +
25429 +       if (!nid || nid_is_hashed(nid))
25430 +               return 1;
25431 +       d_drop(dentry);
25432 +       return 0;
25433 +}
25434 +
25435 +
25436 +
25437 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
25438 +
25439 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
25440 +                         size_t count, loff_t *ppos)
25441 +{
25442 +       struct inode *inode = file->f_dentry->d_inode;
25443 +       unsigned long page;
25444 +       ssize_t length = 0;
25445 +
25446 +       if (count > PROC_BLOCK_SIZE)
25447 +               count = PROC_BLOCK_SIZE;
25448 +
25449 +       /* fade that out as soon as stable */
25450 +       WARN_ON(PROC_I(inode)->fd);
25451 +
25452 +       if (!(page = __get_free_page(GFP_KERNEL)))
25453 +               return -ENOMEM;
25454 +
25455 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
25456 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
25457 +
25458 +       if (length >= 0)
25459 +               length = simple_read_from_buffer(buf, count, ppos,
25460 +                       (char *)page, length);
25461 +
25462 +       free_page(page);
25463 +       return length;
25464 +}
25465 +
25466 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
25467 +                         size_t count, loff_t *ppos)
25468 +{
25469 +       struct inode *inode = file->f_dentry->d_inode;
25470 +       struct vx_info *vxi = NULL;
25471 +       xid_t xid = PROC_I(inode)->fd;
25472 +       unsigned long page;
25473 +       ssize_t length = 0;
25474 +
25475 +       if (count > PROC_BLOCK_SIZE)
25476 +               count = PROC_BLOCK_SIZE;
25477 +
25478 +       /* fade that out as soon as stable */
25479 +       WARN_ON(!xid);
25480 +       vxi = lookup_vx_info(xid);
25481 +       if (!vxi)
25482 +               goto out;
25483 +
25484 +       length = -ENOMEM;
25485 +       if (!(page = __get_free_page(GFP_KERNEL)))
25486 +               goto out_put;
25487 +
25488 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
25489 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
25490 +
25491 +       if (length >= 0)
25492 +               length = simple_read_from_buffer(buf, count, ppos,
25493 +                       (char *)page, length);
25494 +
25495 +       free_page(page);
25496 +out_put:
25497 +       put_vx_info(vxi);
25498 +out:
25499 +       return length;
25500 +}
25501 +
25502 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
25503 +                         size_t count, loff_t *ppos)
25504 +{
25505 +       struct inode *inode = file->f_dentry->d_inode;
25506 +       struct nx_info *nxi = NULL;
25507 +       nid_t nid = PROC_I(inode)->fd;
25508 +       unsigned long page;
25509 +       ssize_t length = 0;
25510 +
25511 +       if (count > PROC_BLOCK_SIZE)
25512 +               count = PROC_BLOCK_SIZE;
25513 +
25514 +       /* fade that out as soon as stable */
25515 +       WARN_ON(!nid);
25516 +       nxi = lookup_nx_info(nid);
25517 +       if (!nxi)
25518 +               goto out;
25519 +
25520 +       length = -ENOMEM;
25521 +       if (!(page = __get_free_page(GFP_KERNEL)))
25522 +               goto out_put;
25523 +
25524 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
25525 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
25526 +
25527 +       if (length >= 0)
25528 +               length = simple_read_from_buffer(buf, count, ppos,
25529 +                       (char *)page, length);
25530 +
25531 +       free_page(page);
25532 +out_put:
25533 +       put_nx_info(nxi);
25534 +out:
25535 +       return length;
25536 +}
25537 +
25538 +
25539 +
25540 +/* here comes the lower level */
25541 +
25542 +
25543 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
25544 +       .len  = sizeof(NAME) - 1,       \
25545 +       .name = (NAME),                 \
25546 +       .mode = MODE,                   \
25547 +       .iop  = IOP,                    \
25548 +       .fop  = FOP,                    \
25549 +       .op   = OP,                     \
25550 +}
25551 +
25552 +
25553 +#define DIR(NAME, MODE, OTYPE)                         \
25554 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
25555 +               &proc_ ## OTYPE ## _inode_operations,   \
25556 +               &proc_ ## OTYPE ## _file_operations, { } )
25557 +
25558 +#define INF(NAME, MODE, OTYPE)                         \
25559 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25560 +               &proc_vs_info_file_operations,          \
25561 +               { .proc_vs_read = &proc_##OTYPE } )
25562 +
25563 +#define VINF(NAME, MODE, OTYPE)                                \
25564 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25565 +               &proc_vx_info_file_operations,          \
25566 +               { .proc_vxi_read = &proc_##OTYPE } )
25567 +
25568 +#define NINF(NAME, MODE, OTYPE)                                \
25569 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25570 +               &proc_nx_info_file_operations,          \
25571 +               { .proc_nxi_read = &proc_##OTYPE } )
25572 +
25573 +
25574 +static struct file_operations proc_vs_info_file_operations = {
25575 +       .read =         proc_vs_info_read,
25576 +};
25577 +
25578 +static struct file_operations proc_vx_info_file_operations = {
25579 +       .read =         proc_vx_info_read,
25580 +};
25581 +
25582 +static struct dentry_operations proc_xid_dentry_operations = {
25583 +       .d_revalidate = proc_xid_revalidate,
25584 +};
25585 +
25586 +static struct vs_entry vx_base_stuff[] = {
25587 +       VINF("info",    S_IRUGO, vxi_info),
25588 +       VINF("status",  S_IRUGO, vxi_status),
25589 +       VINF("limit",   S_IRUGO, vxi_limit),
25590 +       VINF("sched",   S_IRUGO, vxi_sched),
25591 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
25592 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
25593 +       VINF("cacct",   S_IRUGO, vxi_cacct),
25594 +       {}
25595 +};
25596 +
25597 +
25598 +
25599 +
25600 +static struct dentry *proc_xid_instantiate(struct inode *dir,
25601 +       struct dentry *dentry, int id, void *ptr)
25602 +{
25603 +       dentry->d_op = &proc_xid_dentry_operations;
25604 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25605 +}
25606 +
25607 +static struct dentry *proc_xid_lookup(struct inode *dir,
25608 +       struct dentry *dentry, struct nameidata *nd)
25609 +{
25610 +       struct vs_entry *p = vx_base_stuff;
25611 +       struct dentry *error = ERR_PTR(-ENOENT);
25612 +
25613 +       for (; p->name; p++) {
25614 +               if (p->len != dentry->d_name.len)
25615 +                       continue;
25616 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25617 +                       break;
25618 +       }
25619 +       if (!p->name)
25620 +               goto out;
25621 +
25622 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25623 +out:
25624 +       return error;
25625 +}
25626 +
25627 +static int proc_xid_readdir(struct file *filp,
25628 +       void *dirent, filldir_t filldir)
25629 +{
25630 +       struct dentry *dentry = filp->f_dentry;
25631 +       struct inode *inode = dentry->d_inode;
25632 +       struct vs_entry *p = vx_base_stuff;
25633 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
25634 +       int pos, index;
25635 +       u64 ino;
25636 +
25637 +       pos = filp->f_pos;
25638 +       switch (pos) {
25639 +       case 0:
25640 +               ino = inode->i_ino;
25641 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25642 +                       goto out;
25643 +               pos++;
25644 +               /* fall through */
25645 +       case 1:
25646 +               ino = parent_ino(dentry);
25647 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25648 +                       goto out;
25649 +               pos++;
25650 +               /* fall through */
25651 +       default:
25652 +               index = pos - 2;
25653 +               if (index >= size)
25654 +                       goto out;
25655 +               for (p += index; p->name; p++) {
25656 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25657 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25658 +                               goto out;
25659 +                       pos++;
25660 +               }
25661 +       }
25662 +out:
25663 +       filp->f_pos = pos;
25664 +       return 1;
25665 +}
25666 +
25667 +
25668 +
25669 +static struct file_operations proc_nx_info_file_operations = {
25670 +       .read =         proc_nx_info_read,
25671 +};
25672 +
25673 +static struct dentry_operations proc_nid_dentry_operations = {
25674 +       .d_revalidate = proc_nid_revalidate,
25675 +};
25676 +
25677 +static struct vs_entry nx_base_stuff[] = {
25678 +       NINF("info",    S_IRUGO, nxi_info),
25679 +       NINF("status",  S_IRUGO, nxi_status),
25680 +       {}
25681 +};
25682 +
25683 +
25684 +static struct dentry *proc_nid_instantiate(struct inode *dir,
25685 +       struct dentry *dentry, int id, void *ptr)
25686 +{
25687 +       dentry->d_op = &proc_nid_dentry_operations;
25688 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25689 +}
25690 +
25691 +static struct dentry *proc_nid_lookup(struct inode *dir,
25692 +       struct dentry *dentry, struct nameidata *nd)
25693 +{
25694 +       struct vs_entry *p = nx_base_stuff;
25695 +       struct dentry *error = ERR_PTR(-ENOENT);
25696 +
25697 +       for (; p->name; p++) {
25698 +               if (p->len != dentry->d_name.len)
25699 +                       continue;
25700 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25701 +                       break;
25702 +       }
25703 +       if (!p->name)
25704 +               goto out;
25705 +
25706 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25707 +out:
25708 +       return error;
25709 +}
25710 +
25711 +static int proc_nid_readdir(struct file *filp,
25712 +       void *dirent, filldir_t filldir)
25713 +{
25714 +       struct dentry *dentry = filp->f_dentry;
25715 +       struct inode *inode = dentry->d_inode;
25716 +       struct vs_entry *p = nx_base_stuff;
25717 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
25718 +       int pos, index;
25719 +       u64 ino;
25720 +
25721 +       pos = filp->f_pos;
25722 +       switch (pos) {
25723 +       case 0:
25724 +               ino = inode->i_ino;
25725 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25726 +                       goto out;
25727 +               pos++;
25728 +               /* fall through */
25729 +       case 1:
25730 +               ino = parent_ino(dentry);
25731 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25732 +                       goto out;
25733 +               pos++;
25734 +               /* fall through */
25735 +       default:
25736 +               index = pos - 2;
25737 +               if (index >= size)
25738 +                       goto out;
25739 +               for (p += index; p->name; p++) {
25740 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25741 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25742 +                               goto out;
25743 +                       pos++;
25744 +               }
25745 +       }
25746 +out:
25747 +       filp->f_pos = pos;
25748 +       return 1;
25749 +}
25750 +
25751 +
25752 +#define MAX_MULBY10    ((~0U - 9) / 10)
25753 +
25754 +static inline int atovid(const char *str, int len)
25755 +{
25756 +       int vid, c;
25757 +
25758 +       vid = 0;
25759 +       while (len-- > 0) {
25760 +               c = *str - '0';
25761 +               str++;
25762 +               if (c > 9)
25763 +                       return -1;
25764 +               if (vid >= MAX_MULBY10)
25765 +                       return -1;
25766 +               vid *= 10;
25767 +               vid += c;
25768 +               if (!vid)
25769 +                       return -1;
25770 +       }
25771 +       return vid;
25772 +}
25773 +
25774 +/* now the upper level (virtual) */
25775 +
25776 +
25777 +static struct file_operations proc_xid_file_operations = {
25778 +       .read =         generic_read_dir,
25779 +       .readdir =      proc_xid_readdir,
25780 +};
25781 +
25782 +static struct inode_operations proc_xid_inode_operations = {
25783 +       .lookup =       proc_xid_lookup,
25784 +};
25785 +
25786 +static struct vs_entry vx_virtual_stuff[] = {
25787 +       INF("info",     S_IRUGO, virtual_info),
25788 +       INF("status",   S_IRUGO, virtual_status),
25789 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
25790 +};
25791 +
25792 +
25793 +static struct dentry *proc_virtual_lookup(struct inode *dir,
25794 +       struct dentry *dentry, struct nameidata *nd)
25795 +{
25796 +       struct vs_entry *p = vx_virtual_stuff;
25797 +       struct dentry *error = ERR_PTR(-ENOENT);
25798 +       int id = 0;
25799 +
25800 +       for (; p->name; p++) {
25801 +               if (p->len != dentry->d_name.len)
25802 +                       continue;
25803 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25804 +                       break;
25805 +       }
25806 +       if (p->name)
25807 +               goto instantiate;
25808 +
25809 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25810 +       if ((id < 0) || !xid_is_hashed(id))
25811 +               goto out;
25812 +
25813 +instantiate:
25814 +       error = proc_xid_instantiate(dir, dentry, id, p);
25815 +out:
25816 +       return error;
25817 +}
25818 +
25819 +static struct file_operations proc_nid_file_operations = {
25820 +       .read =         generic_read_dir,
25821 +       .readdir =      proc_nid_readdir,
25822 +};
25823 +
25824 +static struct inode_operations proc_nid_inode_operations = {
25825 +       .lookup =       proc_nid_lookup,
25826 +};
25827 +
25828 +static struct vs_entry nx_virtnet_stuff[] = {
25829 +       INF("info",     S_IRUGO, virtnet_info),
25830 +       INF("status",   S_IRUGO, virtnet_status),
25831 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
25832 +};
25833 +
25834 +
25835 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
25836 +       struct dentry *dentry, struct nameidata *nd)
25837 +{
25838 +       struct vs_entry *p = nx_virtnet_stuff;
25839 +       struct dentry *error = ERR_PTR(-ENOENT);
25840 +       int id = 0;
25841 +
25842 +       for (; p->name; p++) {
25843 +               if (p->len != dentry->d_name.len)
25844 +                       continue;
25845 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25846 +                       break;
25847 +       }
25848 +       if (p->name)
25849 +               goto instantiate;
25850 +
25851 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25852 +       if ((id < 0) || !nid_is_hashed(id))
25853 +               goto out;
25854 +
25855 +instantiate:
25856 +       error = proc_nid_instantiate(dir, dentry, id, p);
25857 +out:
25858 +       return error;
25859 +}
25860 +
25861 +
25862 +
25863 +#define PROC_NUMBUF 10
25864 +#define PROC_MAXVIDS 32
25865 +
25866 +int proc_virtual_readdir(struct file *filp,
25867 +       void *dirent, filldir_t filldir)
25868 +{
25869 +       struct dentry *dentry = filp->f_dentry;
25870 +       struct inode *inode = dentry->d_inode;
25871 +       struct vs_entry *p = vx_virtual_stuff;
25872 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
25873 +       int pos, index;
25874 +       unsigned int xid_array[PROC_MAXVIDS];
25875 +       char buf[PROC_NUMBUF];
25876 +       unsigned int nr_xids, i;
25877 +       u64 ino;
25878 +
25879 +       pos = filp->f_pos;
25880 +       switch (pos) {
25881 +       case 0:
25882 +               ino = inode->i_ino;
25883 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25884 +                       goto out;
25885 +               pos++;
25886 +               /* fall through */
25887 +       case 1:
25888 +               ino = parent_ino(dentry);
25889 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25890 +                       goto out;
25891 +               pos++;
25892 +               /* fall through */
25893 +       default:
25894 +               index = pos - 2;
25895 +               if (index >= size)
25896 +                       goto entries;
25897 +               for (p += index; p->name; p++) {
25898 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25899 +                               vs_proc_instantiate, 0, p))
25900 +                               goto out;
25901 +                       pos++;
25902 +               }
25903 +       entries:
25904 +               index = pos - size;
25905 +               p = &vx_virtual_stuff[size - 1];
25906 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
25907 +               for (i = 0; i < nr_xids; i++) {
25908 +                       int n, xid = xid_array[i];
25909 +                       unsigned int j = PROC_NUMBUF;
25910 +
25911 +                       n = xid;
25912 +                       do
25913 +                               buf[--j] = '0' + (n % 10);
25914 +                       while (n /= 10);
25915 +
25916 +                       if (proc_fill_cache(filp, dirent, filldir,
25917 +                               buf + j, PROC_NUMBUF - j,
25918 +                               vs_proc_instantiate, xid, p))
25919 +                               goto out;
25920 +                       pos++;
25921 +               }
25922 +       }
25923 +out:
25924 +       filp->f_pos = pos;
25925 +       return 0;
25926 +}
25927 +
25928 +static int proc_virtual_getattr(struct vfsmount *mnt,
25929 +       struct dentry *dentry, struct kstat *stat)
25930 +{
25931 +       struct inode *inode = dentry->d_inode;
25932 +
25933 +       generic_fillattr(inode, stat);
25934 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
25935 +       return 0;
25936 +}
25937 +
25938 +static struct file_operations proc_virtual_dir_operations = {
25939 +       .read =         generic_read_dir,
25940 +       .readdir =      proc_virtual_readdir,
25941 +};
25942 +
25943 +static struct inode_operations proc_virtual_dir_inode_operations = {
25944 +       .getattr =      proc_virtual_getattr,
25945 +       .lookup =       proc_virtual_lookup,
25946 +};
25947 +
25948 +
25949 +
25950 +
25951 +
25952 +int proc_virtnet_readdir(struct file *filp,
25953 +       void *dirent, filldir_t filldir)
25954 +{
25955 +       struct dentry *dentry = filp->f_dentry;
25956 +       struct inode *inode = dentry->d_inode;
25957 +       struct vs_entry *p = nx_virtnet_stuff;
25958 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
25959 +       int pos, index;
25960 +       unsigned int nid_array[PROC_MAXVIDS];
25961 +       char buf[PROC_NUMBUF];
25962 +       unsigned int nr_nids, i;
25963 +       u64 ino;
25964 +
25965 +       pos = filp->f_pos;
25966 +       switch (pos) {
25967 +       case 0:
25968 +               ino = inode->i_ino;
25969 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25970 +                       goto out;
25971 +               pos++;
25972 +               /* fall through */
25973 +       case 1:
25974 +               ino = parent_ino(dentry);
25975 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25976 +                       goto out;
25977 +               pos++;
25978 +               /* fall through */
25979 +       default:
25980 +               index = pos - 2;
25981 +               if (index >= size)
25982 +                       goto entries;
25983 +               for (p += index; p->name; p++) {
25984 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25985 +                               vs_proc_instantiate, 0, p))
25986 +                               goto out;
25987 +                       pos++;
25988 +               }
25989 +       entries:
25990 +               index = pos - size;
25991 +               p = &nx_virtnet_stuff[size - 1];
25992 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
25993 +               for (i = 0; i < nr_nids; i++) {
25994 +                       int n, nid = nid_array[i];
25995 +                       unsigned int j = PROC_NUMBUF;
25996 +
25997 +                       n = nid;
25998 +                       do
25999 +                               buf[--j] = '0' + (n % 10);
26000 +                       while (n /= 10);
26001 +
26002 +                       if (proc_fill_cache(filp, dirent, filldir,
26003 +                               buf + j, PROC_NUMBUF - j,
26004 +                               vs_proc_instantiate, nid, p))
26005 +                               goto out;
26006 +                       pos++;
26007 +               }
26008 +       }
26009 +out:
26010 +       filp->f_pos = pos;
26011 +       return 0;
26012 +}
26013 +
26014 +static int proc_virtnet_getattr(struct vfsmount *mnt,
26015 +       struct dentry *dentry, struct kstat *stat)
26016 +{
26017 +       struct inode *inode = dentry->d_inode;
26018 +
26019 +       generic_fillattr(inode, stat);
26020 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
26021 +       return 0;
26022 +}
26023 +
26024 +static struct file_operations proc_virtnet_dir_operations = {
26025 +       .read =         generic_read_dir,
26026 +       .readdir =      proc_virtnet_readdir,
26027 +};
26028 +
26029 +static struct inode_operations proc_virtnet_dir_inode_operations = {
26030 +       .getattr =      proc_virtnet_getattr,
26031 +       .lookup =       proc_virtnet_lookup,
26032 +};
26033 +
26034 +
26035 +
26036 +void proc_vx_init(void)
26037 +{
26038 +       struct proc_dir_entry *ent;
26039 +
26040 +       ent = proc_mkdir("virtual", 0);
26041 +       if (ent) {
26042 +               ent->proc_fops = &proc_virtual_dir_operations;
26043 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
26044 +       }
26045 +       proc_virtual = ent;
26046 +
26047 +       ent = proc_mkdir("virtnet", 0);
26048 +       if (ent) {
26049 +               ent->proc_fops = &proc_virtnet_dir_operations;
26050 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
26051 +       }
26052 +       proc_virtnet = ent;
26053 +}
26054 +
26055 +
26056 +
26057 +
26058 +/* per pid info */
26059 +
26060 +
26061 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
26062 +{
26063 +       struct vx_info *vxi;
26064 +       char *orig = buffer;
26065 +
26066 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
26067 +
26068 +       vxi = task_get_vx_info(p);
26069 +       if (!vxi)
26070 +               goto out;
26071 +
26072 +       buffer += sprintf(buffer, "BCaps:\t%016llx\n",
26073 +               (unsigned long long)vxi->vx_bcaps);
26074 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
26075 +               (unsigned long long)vxi->vx_ccaps);
26076 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
26077 +               (unsigned long long)vxi->vx_flags);
26078 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
26079 +
26080 +       put_vx_info(vxi);
26081 +out:
26082 +       return buffer - orig;
26083 +}
26084 +
26085 +
26086 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
26087 +{
26088 +       struct nx_info *nxi;
26089 +       struct nx_addr_v4 *v4a;
26090 +#ifdef CONFIG_IPV6
26091 +       struct nx_addr_v6 *v6a;
26092 +#endif
26093 +       char *orig = buffer;
26094 +       int i;
26095 +
26096 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
26097 +
26098 +       nxi = task_get_nx_info(p);
26099 +       if (!nxi)
26100 +               goto out;
26101 +
26102 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
26103 +               (unsigned long long)nxi->nx_ncaps);
26104 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
26105 +               (unsigned long long)nxi->nx_flags);
26106 +
26107 +       buffer += sprintf(buffer,
26108 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
26109 +               NIPQUAD(nxi->v4_bcast.s_addr));
26110 +       buffer += sprintf (buffer,
26111 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
26112 +               NIPQUAD(nxi->v4_lback.s_addr));
26113 +       if (!NX_IPV4(nxi))
26114 +               goto skip_v4;
26115 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
26116 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
26117 +                       i, NXAV4(v4a));
26118 +skip_v4:
26119 +#ifdef CONFIG_IPV6
26120 +       if (!NX_IPV6(nxi))
26121 +               goto skip_v6;
26122 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
26123 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
26124 +                       i, NXAV6(v6a));
26125 +skip_v6:
26126 +#endif
26127 +       put_nx_info(nxi);
26128 +out:
26129 +       return buffer - orig;
26130 +}
26131 +
26132 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/sched.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched.c
26133 --- linux-2.6.22.10/kernel/vserver/sched.c      1970-01-01 01:00:00 +0100
26134 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched.c   2007-08-15 23:32:49 +0200
26135 @@ -0,0 +1,413 @@
26136 +/*
26137 + *  linux/kernel/vserver/sched.c
26138 + *
26139 + *  Virtual Server: Scheduler Support
26140 + *
26141 + *  Copyright (C) 2004-2007  Herbert Pötzl
26142 + *
26143 + *  V0.01  adapted Sam Vilains version to 2.6.3
26144 + *  V0.02  removed legacy interface
26145 + *  V0.03  changed vcmds to vxi arg
26146 + *  V0.04  removed older and legacy interfaces
26147 + *
26148 + */
26149 +
26150 +#include <linux/vs_context.h>
26151 +#include <linux/vs_sched.h>
26152 +#include <linux/vserver/sched_cmd.h>
26153 +
26154 +#include <asm/uaccess.h>
26155 +
26156 +
26157 +#define vxd_check_range(val, min, max) do {            \
26158 +       vxlprintk((val < min) || (val > max),           \
26159 +               "check_range(%ld,%ld,%ld)",             \
26160 +               (long)val, (long)min, (long)max,        \
26161 +               __FILE__, __LINE__);                    \
26162 +       } while (0)
26163 +
26164 +
26165 +void vx_update_sched_param(struct _vx_sched *sched,
26166 +       struct _vx_sched_pc *sched_pc)
26167 +{
26168 +       unsigned int set_mask = sched->update_mask;
26169 +
26170 +       if (set_mask & VXSM_FILL_RATE)
26171 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
26172 +       if (set_mask & VXSM_INTERVAL)
26173 +               sched_pc->interval[0] = sched->interval[0];
26174 +       if (set_mask & VXSM_FILL_RATE2)
26175 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
26176 +       if (set_mask & VXSM_INTERVAL2)
26177 +               sched_pc->interval[1] = sched->interval[1];
26178 +       if (set_mask & VXSM_TOKENS)
26179 +               sched_pc->tokens = sched->tokens;
26180 +       if (set_mask & VXSM_TOKENS_MIN)
26181 +               sched_pc->tokens_min = sched->tokens_min;
26182 +       if (set_mask & VXSM_TOKENS_MAX)
26183 +               sched_pc->tokens_max = sched->tokens_max;
26184 +       if (set_mask & VXSM_PRIO_BIAS)
26185 +               sched_pc->prio_bias = sched->prio_bias;
26186 +
26187 +       if (set_mask & VXSM_IDLE_TIME)
26188 +               sched_pc->flags |= VXSF_IDLE_TIME;
26189 +       else
26190 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
26191 +
26192 +       /* reset time */
26193 +       sched_pc->norm_time = jiffies;
26194 +}
26195 +
26196 +
26197 +/*
26198 + * recalculate the context's scheduling tokens
26199 + *
26200 + * ret > 0 : number of tokens available
26201 + * ret < 0 : on hold, check delta_min[]
26202 + *          -1 only jiffies
26203 + *          -2 also idle time
26204 + *
26205 + */
26206 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
26207 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
26208 +{
26209 +       long delta;
26210 +       long tokens = 0;
26211 +       int flags = sched_pc->flags;
26212 +
26213 +       /* how much time did pass? */
26214 +       delta = *norm_time - sched_pc->norm_time;
26215 +       vxd_check_range(delta, 0, INT_MAX);
26216 +
26217 +       if (delta >= sched_pc->interval[0]) {
26218 +               long tokens, integral;
26219 +
26220 +               /* calc integral token part */
26221 +               tokens = delta / sched_pc->interval[0];
26222 +               integral = tokens * sched_pc->interval[0];
26223 +               tokens *= sched_pc->fill_rate[0];
26224 +#ifdef CONFIG_VSERVER_HARDCPU
26225 +               delta_min[0] = delta - integral;
26226 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
26227 +#endif
26228 +               /* advance time */
26229 +               sched_pc->norm_time += delta;
26230 +
26231 +               /* add tokens */
26232 +               sched_pc->tokens += tokens;
26233 +               sched_pc->token_time += tokens;
26234 +       } else
26235 +               delta_min[0] = delta;
26236 +
26237 +#ifdef CONFIG_VSERVER_IDLETIME
26238 +       if (!(flags & VXSF_IDLE_TIME))
26239 +               goto skip_idle;
26240 +
26241 +       /* how much was the idle skip? */
26242 +       delta = *idle_time - sched_pc->idle_time;
26243 +       vxd_check_range(delta, 0, INT_MAX);
26244 +
26245 +       if (delta >= sched_pc->interval[1]) {
26246 +               long tokens, integral;
26247 +
26248 +               /* calc fair share token part */
26249 +               tokens = delta / sched_pc->interval[1];
26250 +               integral = tokens * sched_pc->interval[1];
26251 +               tokens *= sched_pc->fill_rate[1];
26252 +               delta_min[1] = delta - integral;
26253 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
26254 +
26255 +               /* advance idle time */
26256 +               sched_pc->idle_time += integral;
26257 +
26258 +               /* add tokens */
26259 +               sched_pc->tokens += tokens;
26260 +               sched_pc->token_time += tokens;
26261 +       } else
26262 +               delta_min[1] = delta;
26263 +skip_idle:
26264 +#endif
26265 +
26266 +       /* clip at maximum */
26267 +       if (sched_pc->tokens > sched_pc->tokens_max)
26268 +               sched_pc->tokens = sched_pc->tokens_max;
26269 +       tokens = sched_pc->tokens;
26270 +
26271 +       if ((flags & VXSF_ONHOLD)) {
26272 +               /* can we unhold? */
26273 +               if (tokens >= sched_pc->tokens_min) {
26274 +                       flags &= ~VXSF_ONHOLD;
26275 +                       sched_pc->hold_ticks +=
26276 +                               *norm_time - sched_pc->onhold;
26277 +               } else
26278 +                       goto on_hold;
26279 +       } else {
26280 +               /* put on hold? */
26281 +               if (tokens <= 0) {
26282 +                       flags |= VXSF_ONHOLD;
26283 +                       sched_pc->onhold = *norm_time;
26284 +                       goto on_hold;
26285 +               }
26286 +       }
26287 +       sched_pc->flags = flags;
26288 +       return tokens;
26289 +
26290 +on_hold:
26291 +       tokens = sched_pc->tokens_min - tokens;
26292 +       sched_pc->flags = flags;
26293 +       BUG_ON(tokens < 0);
26294 +
26295 +#ifdef CONFIG_VSERVER_HARDCPU
26296 +       /* next interval? */
26297 +       if (!sched_pc->fill_rate[0])
26298 +               delta_min[0] = HZ;
26299 +       else if (tokens > sched_pc->fill_rate[0])
26300 +               delta_min[0] += sched_pc->interval[0] *
26301 +                       tokens / sched_pc->fill_rate[0];
26302 +       else
26303 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
26304 +       vxd_check_range(delta_min[0], 0, INT_MAX);
26305 +
26306 +#ifdef CONFIG_VSERVER_IDLETIME
26307 +       if (!(flags & VXSF_IDLE_TIME))
26308 +               return -1;
26309 +
26310 +       /* next interval? */
26311 +       if (!sched_pc->fill_rate[1])
26312 +               delta_min[1] = HZ;
26313 +       else if (tokens > sched_pc->fill_rate[1])
26314 +               delta_min[1] += sched_pc->interval[1] *
26315 +                       tokens / sched_pc->fill_rate[1];
26316 +       else
26317 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
26318 +       vxd_check_range(delta_min[1], 0, INT_MAX);
26319 +
26320 +       return -2;
26321 +#else
26322 +       return -1;
26323 +#endif /* CONFIG_VSERVER_IDLETIME */
26324 +#else
26325 +       return 0;
26326 +#endif /* CONFIG_VSERVER_HARDCPU */
26327 +}
26328 +
26329 +static inline unsigned long msec_to_ticks(unsigned long msec)
26330 +{
26331 +       return msecs_to_jiffies(msec);
26332 +}
26333 +
26334 +static inline unsigned long ticks_to_msec(unsigned long ticks)
26335 +{
26336 +       return jiffies_to_msecs(ticks);
26337 +}
26338 +
26339 +static inline unsigned long ticks_to_usec(unsigned long ticks)
26340 +{
26341 +       return jiffies_to_usecs(ticks);
26342 +}
26343 +
26344 +
26345 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
26346 +{
26347 +       unsigned int set_mask = data->mask;
26348 +       unsigned int update_mask;
26349 +       int i, cpu;
26350 +
26351 +       /* Sanity check data values */
26352 +       if (data->tokens_max <= 0)
26353 +               data->tokens_max = HZ;
26354 +       if (data->tokens_min < 0)
26355 +               data->tokens_min = HZ / 3;
26356 +       if (data->tokens_min >= data->tokens_max)
26357 +               data->tokens_min = data->tokens_max;
26358 +
26359 +       if (data->prio_bias > MAX_PRIO_BIAS)
26360 +               data->prio_bias = MAX_PRIO_BIAS;
26361 +       if (data->prio_bias < MIN_PRIO_BIAS)
26362 +               data->prio_bias = MIN_PRIO_BIAS;
26363 +
26364 +       spin_lock(&vxi->sched.tokens_lock);
26365 +
26366 +       /* sync up on delayed updates */
26367 +       for_each_cpu_mask(cpu, vxi->sched.update)
26368 +               vx_update_sched_param(&vxi->sched,
26369 +                       &vx_per_cpu(vxi, sched_pc, cpu));
26370 +
26371 +       if (set_mask & VXSM_FILL_RATE)
26372 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
26373 +       if (set_mask & VXSM_FILL_RATE2)
26374 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
26375 +       if (set_mask & VXSM_INTERVAL)
26376 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
26377 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
26378 +       if (set_mask & VXSM_INTERVAL2)
26379 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
26380 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
26381 +       if (set_mask & VXSM_TOKENS)
26382 +               vxi->sched.tokens = data->tokens;
26383 +       if (set_mask & VXSM_TOKENS_MIN)
26384 +               vxi->sched.tokens_min = data->tokens_min;
26385 +       if (set_mask & VXSM_TOKENS_MAX)
26386 +               vxi->sched.tokens_max = data->tokens_max;
26387 +       if (set_mask & VXSM_PRIO_BIAS)
26388 +               vxi->sched.prio_bias = data->prio_bias;
26389 +
26390 +       /* Sanity check rate/interval */
26391 +       for (i = 0; i < 2; i++) {
26392 +               if (data->fill_rate[i] < 0)
26393 +                       data->fill_rate[i] = 0;
26394 +               if (data->interval[i] <= 0)
26395 +                       data->interval[i] = HZ;
26396 +       }
26397 +
26398 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
26399 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
26400 +       vxi->sched.update_mask = update_mask;
26401 +
26402 +#ifdef CONFIG_SMP
26403 +       rmb();
26404 +       if (set_mask & VXSM_CPU_ID) {
26405 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
26406 +               cpus_and(vxi->sched.update, cpu_online_map,
26407 +                       vxi->sched.update);
26408 +       } else
26409 +               vxi->sched.update = cpu_online_map;
26410 +
26411 +       /* forced reload? */
26412 +       if (set_mask & VXSM_FORCE) {
26413 +               for_each_cpu_mask(cpu, vxi->sched.update)
26414 +                       vx_update_sched_param(&vxi->sched,
26415 +                               &vx_per_cpu(vxi, sched_pc, cpu));
26416 +               vxi->sched.update = CPU_MASK_NONE;
26417 +       }
26418 +#else
26419 +       /* on UP we update immediately */
26420 +       vx_update_sched_param(&vxi->sched,
26421 +               &vx_per_cpu(vxi, sched_pc, 0));
26422 +#endif
26423 +
26424 +       spin_unlock(&vxi->sched.tokens_lock);
26425 +       return 0;
26426 +}
26427 +
26428 +
26429 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
26430 +#define COPY_PRI(C) C(prio_bias)
26431 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26432 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
26433 +                   C(fill_rate[1]); C(interval[1]);
26434 +
26435 +#define COPY_VALUE(name) vc_data.name = data->name
26436 +
26437 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
26438 +{
26439 +       struct vcmd_sched_v5 vc_data;
26440 +
26441 +       vc_data.mask = data->set_mask;
26442 +       COPY_IDS(COPY_VALUE);
26443 +       COPY_PRI(COPY_VALUE);
26444 +       COPY_TOK(COPY_VALUE);
26445 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
26446 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
26447 +       return do_set_sched(vxi, &vc_data);
26448 +}
26449 +
26450 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
26451 +{
26452 +       struct vcmd_set_sched_v4 vc_data;
26453 +
26454 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26455 +               return -EFAULT;
26456 +
26457 +       return do_set_sched_v4(vxi, &vc_data);
26458 +}
26459 +
26460 +       /* latest interface is v5 */
26461 +
26462 +int vc_set_sched(struct vx_info *vxi, void __user *data)
26463 +{
26464 +       struct vcmd_sched_v5 vc_data;
26465 +
26466 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26467 +               return -EFAULT;
26468 +
26469 +       return do_set_sched(vxi, &vc_data);
26470 +}
26471 +
26472 +
26473 +#define COPY_PRI(C) C(prio_bias)
26474 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26475 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
26476 +                   C(fill_rate[1]); C(interval[1]);
26477 +
26478 +#define COPY_VALUE(name) vc_data.name = data->name
26479 +
26480 +
26481 +int vc_get_sched(struct vx_info *vxi, void __user *data)
26482 +{
26483 +       struct vcmd_sched_v5 vc_data;
26484 +
26485 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26486 +               return -EFAULT;
26487 +
26488 +       if (vc_data.mask & VXSM_CPU_ID) {
26489 +               int cpu = vc_data.cpu_id;
26490 +               struct _vx_sched_pc *data;
26491 +
26492 +               if (!cpu_possible(cpu))
26493 +                       return -EINVAL;
26494 +
26495 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
26496 +               COPY_TOK(COPY_VALUE);
26497 +               COPY_PRI(COPY_VALUE);
26498 +               COPY_FRI(COPY_VALUE);
26499 +
26500 +               if (data->flags & VXSF_IDLE_TIME)
26501 +                       vc_data.mask |= VXSM_IDLE_TIME;
26502 +       } else {
26503 +               struct _vx_sched *data = &vxi->sched;
26504 +
26505 +               COPY_TOK(COPY_VALUE);
26506 +               COPY_PRI(COPY_VALUE);
26507 +               COPY_FRI(COPY_VALUE);
26508 +       }
26509 +
26510 +       if (vc_data.mask & VXSM_MSEC) {
26511 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
26512 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
26513 +       }
26514 +
26515 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26516 +               return -EFAULT;
26517 +       return 0;
26518 +}
26519 +
26520 +
26521 +int vc_sched_info(struct vx_info *vxi, void __user *data)
26522 +{
26523 +       struct vcmd_sched_info vc_data;
26524 +       int cpu;
26525 +
26526 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26527 +               return -EFAULT;
26528 +
26529 +       cpu = vc_data.cpu_id;
26530 +       if (!cpu_possible(cpu))
26531 +               return -EINVAL;
26532 +
26533 +       if (vxi) {
26534 +               struct _vx_sched_pc *sched_pc =
26535 +                       &vx_per_cpu(vxi, sched_pc, cpu);
26536 +
26537 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
26538 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
26539 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
26540 +               vc_data.vavavoom = sched_pc->vavavoom;
26541 +       }
26542 +       vc_data.token_usec = ticks_to_usec(1);
26543 +
26544 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26545 +               return -EFAULT;
26546 +       return 0;
26547 +}
26548 +
26549 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/sched_init.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched_init.h
26550 --- linux-2.6.22.10/kernel/vserver/sched_init.h 1970-01-01 01:00:00 +0100
26551 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched_init.h      2007-08-05 20:53:13 +0200
26552 @@ -0,0 +1,50 @@
26553 +
26554 +static inline void vx_info_init_sched(struct _vx_sched *sched)
26555 +{
26556 +       static struct lock_class_key tokens_lock_key;
26557 +
26558 +       /* scheduling; hard code starting values as constants */
26559 +       sched->fill_rate[0]     = 1;
26560 +       sched->interval[0]      = 4;
26561 +       sched->fill_rate[1]     = 1;
26562 +       sched->interval[1]      = 8;
26563 +       sched->tokens           = HZ >> 2;
26564 +       sched->tokens_min       = HZ >> 4;
26565 +       sched->tokens_max       = HZ >> 1;
26566 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
26567 +       sched->prio_bias        = 0;
26568 +
26569 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
26570 +}
26571 +
26572 +static inline
26573 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26574 +{
26575 +       sched_pc->fill_rate[0]  = 1;
26576 +       sched_pc->interval[0]   = 4;
26577 +       sched_pc->fill_rate[1]  = 1;
26578 +       sched_pc->interval[1]   = 8;
26579 +       sched_pc->tokens        = HZ >> 2;
26580 +       sched_pc->tokens_min    = HZ >> 4;
26581 +       sched_pc->tokens_max    = HZ >> 1;
26582 +       sched_pc->prio_bias     = 0;
26583 +       sched_pc->vavavoom      = 0;
26584 +       sched_pc->token_time    = 0;
26585 +       sched_pc->idle_time     = 0;
26586 +       sched_pc->norm_time     = jiffies;
26587 +
26588 +       sched_pc->user_ticks = 0;
26589 +       sched_pc->sys_ticks = 0;
26590 +       sched_pc->hold_ticks = 0;
26591 +}
26592 +
26593 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
26594 +{
26595 +       return;
26596 +}
26597 +
26598 +static inline
26599 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26600 +{
26601 +       return;
26602 +}
26603 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/sched_proc.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched_proc.h
26604 --- linux-2.6.22.10/kernel/vserver/sched_proc.h 1970-01-01 01:00:00 +0100
26605 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched_proc.h      2007-08-05 20:53:13 +0200
26606 @@ -0,0 +1,57 @@
26607 +#ifndef _VX_SCHED_PROC_H
26608 +#define _VX_SCHED_PROC_H
26609 +
26610 +
26611 +static inline
26612 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
26613 +{
26614 +       int length = 0;
26615 +
26616 +       length += sprintf(buffer,
26617 +               "FillRate:\t%8d,%d\n"
26618 +               "Interval:\t%8d,%d\n"
26619 +               "TokensMin:\t%8d\n"
26620 +               "TokensMax:\t%8d\n"
26621 +               "PrioBias:\t%8d\n",
26622 +               sched->fill_rate[0],
26623 +               sched->fill_rate[1],
26624 +               sched->interval[0],
26625 +               sched->interval[1],
26626 +               sched->tokens_min,
26627 +               sched->tokens_max,
26628 +               sched->prio_bias);
26629 +       return length;
26630 +}
26631 +
26632 +static inline
26633 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
26634 +       char *buffer, int cpu)
26635 +{
26636 +       int length = 0;
26637 +
26638 +       length += sprintf(buffer + length,
26639 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
26640 +               (unsigned long long)sched_pc->user_ticks,
26641 +               (unsigned long long)sched_pc->sys_ticks,
26642 +               (unsigned long long)sched_pc->hold_ticks,
26643 +               sched_pc->token_time,
26644 +               sched_pc->idle_time);
26645 +       length += sprintf(buffer + length,
26646 +               " %c%c %d %d %d %d/%d %d/%d",
26647 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
26648 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
26649 +               sched_pc->tokens,
26650 +               sched_pc->tokens_min,
26651 +               sched_pc->tokens_max,
26652 +               sched_pc->fill_rate[0],
26653 +               sched_pc->interval[0],
26654 +               sched_pc->fill_rate[1],
26655 +               sched_pc->interval[1]);
26656 +       length += sprintf(buffer + length,
26657 +               " %d %d\n",
26658 +               sched_pc->prio_bias,
26659 +               sched_pc->vavavoom);
26660 +       return length;
26661 +}
26662 +
26663 +#endif /* _VX_SCHED_PROC_H */
26664 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/signal.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/signal.c
26665 --- linux-2.6.22.10/kernel/vserver/signal.c     1970-01-01 01:00:00 +0100
26666 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/signal.c  2007-08-15 23:34:41 +0200
26667 @@ -0,0 +1,131 @@
26668 +/*
26669 + *  linux/kernel/vserver/signal.c
26670 + *
26671 + *  Virtual Server: Signal Support
26672 + *
26673 + *  Copyright (C) 2003-2007  Herbert Pötzl
26674 + *
26675 + *  V0.01  broken out from vcontext V0.05
26676 + *  V0.02  changed vcmds to vxi arg
26677 + *  V0.03  adjusted siginfo for kill
26678 + *
26679 + */
26680 +
26681 +#include <asm/uaccess.h>
26682 +
26683 +#include <linux/vs_context.h>
26684 +#include <linux/vserver/signal_cmd.h>
26685 +
26686 +
26687 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
26688 +{
26689 +       int retval, count = 0;
26690 +       struct task_struct *p;
26691 +       struct siginfo *sip = SEND_SIG_PRIV;
26692 +
26693 +       retval = -ESRCH;
26694 +       vxdprintk(VXD_CBIT(misc, 4),
26695 +               "vx_info_kill(%p[#%d],%d,%d)*",
26696 +               vxi, vxi->vx_id, pid, sig);
26697 +       read_lock(&tasklist_lock);
26698 +       switch (pid) {
26699 +       case  0:
26700 +       case -1:
26701 +               for_each_process(p) {
26702 +                       int err = 0;
26703 +
26704 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
26705 +                               (pid && vxi->vx_initpid == p->pid))
26706 +                               continue;
26707 +
26708 +                       err = group_send_sig_info(sig, sip, p);
26709 +                       ++count;
26710 +                       if (err != -EPERM)
26711 +                               retval = err;
26712 +               }
26713 +               break;
26714 +
26715 +       case 1:
26716 +               if (vxi->vx_initpid) {
26717 +                       pid = vxi->vx_initpid;
26718 +                       /* for now, only SIGINT to private init ... */
26719 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26720 +                               /* ... as long as there are tasks left */
26721 +                               (atomic_read(&vxi->vx_tasks) > 1))
26722 +                               sig = SIGINT;
26723 +               }
26724 +               /* fallthrough */
26725 +       default:
26726 +               p = find_task_by_real_pid(pid);
26727 +               if (p) {
26728 +                       if (vx_task_xid(p) == vxi->vx_id)
26729 +                               retval = group_send_sig_info(sig, sip, p);
26730 +               }
26731 +               break;
26732 +       }
26733 +       read_unlock(&tasklist_lock);
26734 +       vxdprintk(VXD_CBIT(misc, 4),
26735 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
26736 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
26737 +       return retval;
26738 +}
26739 +
26740 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
26741 +{
26742 +       struct vcmd_ctx_kill_v0 vc_data;
26743 +
26744 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26745 +               return -EFAULT;
26746 +
26747 +       /* special check to allow guest shutdown */
26748 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26749 +               /* forbid killall pid=0 when init is present */
26750 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
26751 +               (vc_data.pid > 1)))
26752 +               return -EACCES;
26753 +
26754 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
26755 +}
26756 +
26757 +
26758 +static int __wait_exit(struct vx_info *vxi)
26759 +{
26760 +       DECLARE_WAITQUEUE(wait, current);
26761 +       int ret = 0;
26762 +
26763 +       add_wait_queue(&vxi->vx_wait, &wait);
26764 +       set_current_state(TASK_INTERRUPTIBLE);
26765 +
26766 +wait:
26767 +       if (vx_info_state(vxi,
26768 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
26769 +               goto out;
26770 +       if (signal_pending(current)) {
26771 +               ret = -ERESTARTSYS;
26772 +               goto out;
26773 +       }
26774 +       schedule();
26775 +       goto wait;
26776 +
26777 +out:
26778 +       set_current_state(TASK_RUNNING);
26779 +       remove_wait_queue(&vxi->vx_wait, &wait);
26780 +       return ret;
26781 +}
26782 +
26783 +
26784 +
26785 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
26786 +{
26787 +       struct vcmd_wait_exit_v0 vc_data;
26788 +       int ret;
26789 +
26790 +       ret = __wait_exit(vxi);
26791 +       vc_data.reboot_cmd = vxi->reboot_cmd;
26792 +       vc_data.exit_code = vxi->exit_code;
26793 +
26794 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26795 +               ret = -EFAULT;
26796 +       return ret;
26797 +}
26798 +
26799 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/space.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/space.c
26800 --- linux-2.6.22.10/kernel/vserver/space.c      1970-01-01 01:00:00 +0100
26801 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/space.c   2007-08-15 23:39:13 +0200
26802 @@ -0,0 +1,277 @@
26803 +/*
26804 + *  linux/kernel/vserver/space.c
26805 + *
26806 + *  Virtual Server: Context Space Support
26807 + *
26808 + *  Copyright (C) 2003-2007  Herbert Pötzl
26809 + *
26810 + *  V0.01  broken out from context.c 0.07
26811 + *  V0.02  added task locking for namespace
26812 + *  V0.03  broken out vx_enter_namespace
26813 + *  V0.04  added *space support and commands
26814 + *
26815 + */
26816 +
26817 +#include <linux/utsname.h>
26818 +#include <linux/nsproxy.h>
26819 +#include <linux/err.h>
26820 +#include <asm/uaccess.h>
26821 +
26822 +#include <linux/vs_context.h>
26823 +#include <linux/vserver/space.h>
26824 +#include <linux/vserver/space_cmd.h>
26825 +
26826 +
26827 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
26828 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
26829 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
26830 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
26831 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
26832 +
26833 +
26834 +/* namespace functions */
26835 +
26836 +#include <linux/mnt_namespace.h>
26837 +
26838 +const struct vcmd_space_mask space_mask = {
26839 +       .mask = CLONE_NEWNS |
26840 +               CLONE_NEWUTS |
26841 +               CLONE_NEWIPC |
26842 +               CLONE_FS
26843 +};
26844 +
26845 +
26846 +/*
26847 + *     build a new nsproxy mix
26848 + *      assumes that both proxies are 'const'
26849 + *     does not touch nsproxy refcounts
26850 + *     will hold a reference on the result.
26851 + */
26852 +
26853 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
26854 +       struct nsproxy *new_nsproxy, unsigned long mask)
26855 +{
26856 +       struct mnt_namespace *old_ns;
26857 +       struct uts_namespace *old_uts;
26858 +       struct ipc_namespace *old_ipc;
26859 +       struct nsproxy *nsproxy;
26860 +
26861 +       nsproxy = copy_nsproxy(old_nsproxy);
26862 +       if (!nsproxy)
26863 +               goto out;
26864 +
26865 +       if (mask & CLONE_NEWNS) {
26866 +               old_ns = nsproxy->mnt_ns;
26867 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
26868 +               if (nsproxy->mnt_ns)
26869 +                       get_mnt_ns(nsproxy->mnt_ns);
26870 +       } else
26871 +               old_ns = NULL;
26872 +
26873 +       if (mask & CLONE_NEWUTS) {
26874 +               old_uts = nsproxy->uts_ns;
26875 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
26876 +               if (nsproxy->uts_ns)
26877 +                       get_uts_ns(nsproxy->uts_ns);
26878 +       } else
26879 +               old_uts = NULL;
26880 +
26881 +       if (mask & CLONE_NEWIPC) {
26882 +               old_ipc = nsproxy->ipc_ns;
26883 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
26884 +               if (nsproxy->ipc_ns)
26885 +                       get_ipc_ns(nsproxy->ipc_ns);
26886 +       } else
26887 +               old_ipc = NULL;
26888 +
26889 +       if (old_ns)
26890 +               put_mnt_ns(old_ns);
26891 +       if (old_uts)
26892 +               put_uts_ns(old_uts);
26893 +       if (old_ipc)
26894 +               put_ipc_ns(old_ipc);
26895 +out:
26896 +       return nsproxy;
26897 +}
26898 +
26899 +
26900 +/*
26901 + *     merge two nsproxy structs into a new one.
26902 + *     will hold a reference on the result.
26903 + */
26904 +
26905 +static inline
26906 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
26907 +       struct nsproxy *proxy, unsigned long mask)
26908 +{
26909 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
26910 +
26911 +       if (!proxy)
26912 +               return NULL;
26913 +
26914 +       if (mask) {
26915 +               /* vs_mix_nsproxy returns with reference */
26916 +               return vs_mix_nsproxy(old ? old : &null_proxy,
26917 +                       proxy, mask);
26918 +       }
26919 +       get_nsproxy(proxy);
26920 +       return proxy;
26921 +}
26922 +
26923 +/*
26924 + *     merge two fs structs into a new one.
26925 + *     will take a reference on the result.
26926 + */
26927 +
26928 +static inline
26929 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
26930 +       struct fs_struct *fs, unsigned long mask)
26931 +{
26932 +       if (!(mask & CLONE_FS)) {
26933 +               if (old)
26934 +                       atomic_inc(&old->count);
26935 +               return old;
26936 +       }
26937 +
26938 +       if (!fs)
26939 +               return NULL;
26940 +
26941 +       return copy_fs_struct(fs);
26942 +}
26943 +
26944 +
26945 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
26946 +{
26947 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
26948 +       struct fs_struct *fs, *fs_cur, *fs_new;
26949 +       int ret;
26950 +
26951 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
26952 +               return -EACCES;
26953 +
26954 +       if (!mask)
26955 +               mask = vxi->vx_nsmask;
26956 +
26957 +       if ((mask & vxi->vx_nsmask) != mask)
26958 +               return -EINVAL;
26959 +
26960 +       proxy = vxi->vx_nsproxy;
26961 +       fs = vxi->vx_fs;
26962 +
26963 +       task_lock(current);
26964 +       fs_cur = current->fs;
26965 +       atomic_inc(&fs_cur->count);
26966 +       proxy_cur = current->nsproxy;
26967 +       get_nsproxy(proxy_cur);
26968 +       task_unlock(current);
26969 +
26970 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
26971 +       if (IS_ERR(fs_new)) {
26972 +               ret = PTR_ERR(fs_new);
26973 +               goto out_put;
26974 +       }
26975 +
26976 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
26977 +       if (IS_ERR(proxy_new)) {
26978 +               ret = PTR_ERR(proxy_new);
26979 +               goto out_put_fs;
26980 +       }
26981 +
26982 +       fs_new = xchg(&current->fs, fs_new);
26983 +       proxy_new = xchg(&current->nsproxy, proxy_new);
26984 +       ret = 0;
26985 +
26986 +       if (proxy_new)
26987 +               put_nsproxy(proxy_new);
26988 +out_put_fs:
26989 +       if (fs_new)
26990 +               put_fs_struct(fs_new);
26991 +out_put:
26992 +       if (proxy_cur)
26993 +               put_nsproxy(proxy_cur);
26994 +       if (fs_cur)
26995 +               put_fs_struct(fs_cur);
26996 +       return ret;
26997 +}
26998 +
26999 +
27000 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
27001 +{
27002 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
27003 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
27004 +       int ret;
27005 +
27006 +       if (!mask)
27007 +               mask = space_mask.mask;
27008 +
27009 +       if ((mask & space_mask.mask) != mask)
27010 +               return -EINVAL;
27011 +
27012 +       proxy_vxi = vxi->vx_nsproxy;
27013 +       fs_vxi = vxi->vx_fs;
27014 +
27015 +       task_lock(current);
27016 +       fs_cur = current->fs;
27017 +       atomic_inc(&fs_cur->count);
27018 +       proxy_cur = current->nsproxy;
27019 +       get_nsproxy(proxy_cur);
27020 +       task_unlock(current);
27021 +
27022 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
27023 +       if (IS_ERR(fs_new)) {
27024 +               ret = PTR_ERR(fs_new);
27025 +               goto out_put;
27026 +       }
27027 +
27028 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
27029 +       if (IS_ERR(proxy_new)) {
27030 +               ret = PTR_ERR(proxy_new);
27031 +               goto out_put_fs;
27032 +       }
27033 +
27034 +       fs_new = xchg(&vxi->vx_fs, fs_new);
27035 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
27036 +       vxi->vx_nsmask |= mask;
27037 +       ret = 0;
27038 +
27039 +       if (proxy_new)
27040 +               put_nsproxy(proxy_new);
27041 +out_put_fs:
27042 +       if (fs_new)
27043 +               put_fs_struct(fs_new);
27044 +out_put:
27045 +       if (proxy_cur)
27046 +               put_nsproxy(proxy_cur);
27047 +       if (fs_cur)
27048 +               put_fs_struct(fs_cur);
27049 +       return ret;
27050 +}
27051 +
27052 +
27053 +int vc_enter_space(struct vx_info *vxi, void __user *data)
27054 +{
27055 +       struct vcmd_space_mask vc_data = { .mask = 0 };
27056 +
27057 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
27058 +               return -EFAULT;
27059 +
27060 +       return vx_enter_space(vxi, vc_data.mask);
27061 +}
27062 +
27063 +int vc_set_space(struct vx_info *vxi, void __user *data)
27064 +{
27065 +       struct vcmd_space_mask vc_data = { .mask = 0 };
27066 +
27067 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
27068 +               return -EFAULT;
27069 +
27070 +       return vx_set_space(vxi, vc_data.mask);
27071 +}
27072 +
27073 +int vc_get_space_mask(struct vx_info *vxi, void __user *data)
27074 +{
27075 +       if (copy_to_user(data, &space_mask, sizeof(space_mask)))
27076 +               return -EFAULT;
27077 +       return 0;
27078 +}
27079 +
27080 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/switch.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/switch.c
27081 --- linux-2.6.22.10/kernel/vserver/switch.c     1970-01-01 01:00:00 +0100
27082 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/switch.c  2007-10-25 17:05:55 +0200
27083 @@ -0,0 +1,529 @@
27084 +/*
27085 + *  linux/kernel/vserver/switch.c
27086 + *
27087 + *  Virtual Server: Syscall Switch
27088 + *
27089 + *  Copyright (C) 2003-2007  Herbert Pötzl
27090 + *
27091 + *  V0.01  syscall switch
27092 + *  V0.02  added signal to context
27093 + *  V0.03  added rlimit functions
27094 + *  V0.04  added iattr, task/xid functions
27095 + *  V0.05  added debug/history stuff
27096 + *  V0.06  added compat32 layer
27097 + *  V0.07  vcmd args and perms
27098 + *  V0.08  added status commands
27099 + *  V0.09  added tag commands
27100 + *  V0.10  added oom bias
27101 + *  V0.11  added device commands
27102 + *
27103 + */
27104 +
27105 +#include <linux/vs_context.h>
27106 +#include <linux/vs_network.h>
27107 +#include <linux/vserver/switch.h>
27108 +
27109 +#include "vci_config.h"
27110 +
27111 +
27112 +static inline
27113 +int vc_get_version(uint32_t id)
27114 +{
27115 +       return VCI_VERSION;
27116 +}
27117 +
27118 +static inline
27119 +int vc_get_vci(uint32_t id)
27120 +{
27121 +       return vci_kernel_config();
27122 +}
27123 +
27124 +#include <linux/vserver/context_cmd.h>
27125 +#include <linux/vserver/cvirt_cmd.h>
27126 +#include <linux/vserver/cacct_cmd.h>
27127 +#include <linux/vserver/limit_cmd.h>
27128 +#include <linux/vserver/network_cmd.h>
27129 +#include <linux/vserver/sched_cmd.h>
27130 +#include <linux/vserver/debug_cmd.h>
27131 +#include <linux/vserver/inode_cmd.h>
27132 +#include <linux/vserver/dlimit_cmd.h>
27133 +#include <linux/vserver/signal_cmd.h>
27134 +#include <linux/vserver/space_cmd.h>
27135 +#include <linux/vserver/tag_cmd.h>
27136 +#include <linux/vserver/device_cmd.h>
27137 +
27138 +#include <linux/vserver/inode.h>
27139 +#include <linux/vserver/dlimit.h>
27140 +
27141 +
27142 +#ifdef CONFIG_COMPAT
27143 +#define __COMPAT(name, id, data, compat)       \
27144 +       (compat) ? name ## _x32(id, data) : name(id, data)
27145 +#define __COMPAT_NO_ID(name, data, compat)     \
27146 +       (compat) ? name ## _x32(data) : name(data)
27147 +#else
27148 +#define __COMPAT(name, id, data, compat)       \
27149 +       name(id, data)
27150 +#define __COMPAT_NO_ID(name, data, compat)     \
27151 +       name(data)
27152 +#endif
27153 +
27154 +
27155 +static inline
27156 +long do_vcmd(uint32_t cmd, uint32_t id,
27157 +       struct vx_info *vxi, struct nx_info *nxi,
27158 +       void __user *data, int compat)
27159 +{
27160 +       switch (cmd) {
27161 +
27162 +       case VCMD_get_version:
27163 +               return vc_get_version(id);
27164 +       case VCMD_get_vci:
27165 +               return vc_get_vci(id);
27166 +
27167 +       case VCMD_task_xid:
27168 +               return vc_task_xid(id);
27169 +       case VCMD_vx_info:
27170 +               return vc_vx_info(vxi, data);
27171 +
27172 +       case VCMD_task_nid:
27173 +               return vc_task_nid(id);
27174 +       case VCMD_nx_info:
27175 +               return vc_nx_info(nxi, data);
27176 +
27177 +       case VCMD_task_tag:
27178 +               return vc_task_tag(id);
27179 +
27180 +       /* this is version 1 */
27181 +       case VCMD_set_space:
27182 +               return vc_set_space(vxi, data);
27183 +
27184 +       case VCMD_get_space_mask:
27185 +               return vc_get_space_mask(vxi, data);
27186 +
27187 +#ifdef CONFIG_IA32_EMULATION
27188 +       case VCMD_get_rlimit:
27189 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
27190 +       case VCMD_set_rlimit:
27191 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
27192 +#else
27193 +       case VCMD_get_rlimit:
27194 +               return vc_get_rlimit(vxi, data);
27195 +       case VCMD_set_rlimit:
27196 +               return vc_set_rlimit(vxi, data);
27197 +#endif
27198 +       case VCMD_get_rlimit_mask:
27199 +               return vc_get_rlimit_mask(id, data);
27200 +       case VCMD_reset_minmax:
27201 +               return vc_reset_minmax(vxi, data);
27202 +
27203 +       case VCMD_get_vhi_name:
27204 +               return vc_get_vhi_name(vxi, data);
27205 +       case VCMD_set_vhi_name:
27206 +               return vc_set_vhi_name(vxi, data);
27207 +
27208 +       case VCMD_ctx_stat:
27209 +               return vc_ctx_stat(vxi, data);
27210 +       case VCMD_virt_stat:
27211 +               return vc_virt_stat(vxi, data);
27212 +       case VCMD_sock_stat:
27213 +               return vc_sock_stat(vxi, data);
27214 +       case VCMD_rlimit_stat:
27215 +               return vc_rlimit_stat(vxi, data);
27216 +
27217 +       case VCMD_set_cflags:
27218 +               return vc_set_cflags(vxi, data);
27219 +       case VCMD_get_cflags:
27220 +               return vc_get_cflags(vxi, data);
27221 +
27222 +       /* this is version 1 */
27223 +       case VCMD_set_ccaps:
27224 +               return vc_set_ccaps(vxi, data);
27225 +       /* this is version 1 */
27226 +       case VCMD_get_ccaps:
27227 +               return vc_get_ccaps(vxi, data);
27228 +       case VCMD_set_bcaps:
27229 +               return vc_set_bcaps(vxi, data);
27230 +       case VCMD_get_bcaps:
27231 +               return vc_get_bcaps(vxi, data);
27232 +
27233 +       case VCMD_set_badness:
27234 +               return vc_set_badness(vxi, data);
27235 +       case VCMD_get_badness:
27236 +               return vc_get_badness(vxi, data);
27237 +
27238 +       case VCMD_set_nflags:
27239 +               return vc_set_nflags(nxi, data);
27240 +       case VCMD_get_nflags:
27241 +               return vc_get_nflags(nxi, data);
27242 +
27243 +       case VCMD_set_ncaps:
27244 +               return vc_set_ncaps(nxi, data);
27245 +       case VCMD_get_ncaps:
27246 +               return vc_get_ncaps(nxi, data);
27247 +
27248 +       case VCMD_set_sched_v4:
27249 +               return vc_set_sched_v4(vxi, data);
27250 +       /* this is version 5 */
27251 +       case VCMD_set_sched:
27252 +               return vc_set_sched(vxi, data);
27253 +       case VCMD_get_sched:
27254 +               return vc_get_sched(vxi, data);
27255 +       case VCMD_sched_info:
27256 +               return vc_sched_info(vxi, data);
27257 +
27258 +       case VCMD_add_dlimit:
27259 +               return __COMPAT(vc_add_dlimit, id, data, compat);
27260 +       case VCMD_rem_dlimit:
27261 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
27262 +       case VCMD_set_dlimit:
27263 +               return __COMPAT(vc_set_dlimit, id, data, compat);
27264 +       case VCMD_get_dlimit:
27265 +               return __COMPAT(vc_get_dlimit, id, data, compat);
27266 +
27267 +       case VCMD_ctx_kill:
27268 +               return vc_ctx_kill(vxi, data);
27269 +
27270 +       case VCMD_wait_exit:
27271 +               return vc_wait_exit(vxi, data);
27272 +
27273 +       case VCMD_get_iattr:
27274 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
27275 +       case VCMD_set_iattr:
27276 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
27277 +
27278 +       case VCMD_fget_iattr:
27279 +               return vc_fget_iattr(id, data);
27280 +       case VCMD_fset_iattr:
27281 +               return vc_fset_iattr(id, data);
27282 +
27283 +       case VCMD_enter_space_v0:
27284 +               return vc_enter_space(vxi, NULL);
27285 +       /* this is version 1 */
27286 +       case VCMD_enter_space:
27287 +               return vc_enter_space(vxi, data);
27288 +
27289 +       case VCMD_ctx_create_v0:
27290 +               return vc_ctx_create(id, NULL);
27291 +       case VCMD_ctx_create:
27292 +               return vc_ctx_create(id, data);
27293 +       case VCMD_ctx_migrate_v0:
27294 +               return vc_ctx_migrate(vxi, NULL);
27295 +       case VCMD_ctx_migrate:
27296 +               return vc_ctx_migrate(vxi, data);
27297 +
27298 +       case VCMD_net_create_v0:
27299 +               return vc_net_create(id, NULL);
27300 +       case VCMD_net_create:
27301 +               return vc_net_create(id, data);
27302 +       case VCMD_net_migrate:
27303 +               return vc_net_migrate(nxi, data);
27304 +
27305 +       case VCMD_tag_migrate:
27306 +               return vc_tag_migrate(id);
27307 +
27308 +       case VCMD_net_add:
27309 +               return vc_net_add(nxi, data);
27310 +       case VCMD_net_remove:
27311 +               return vc_net_remove(nxi, data);
27312 +
27313 +       case VCMD_net_add_ipv4:
27314 +               return vc_net_add_ipv4(nxi, data);
27315 +       case VCMD_net_remove_ipv4:
27316 +               return vc_net_remove_ipv4(nxi, data);
27317 +#ifdef CONFIG_IPV6
27318 +       case VCMD_net_add_ipv6:
27319 +               return vc_net_add_ipv6(nxi, data);
27320 +       case VCMD_net_remove_ipv6:
27321 +               return vc_net_remove_ipv6(nxi, data);
27322 +#endif
27323 +/*     case VCMD_add_match_ipv4:
27324 +               return vc_add_match_ipv4(nxi, data);
27325 +       case VCMD_get_match_ipv4:
27326 +               return vc_get_match_ipv4(nxi, data);
27327 +#ifdef CONFIG_IPV6
27328 +       case VCMD_add_match_ipv6:
27329 +               return vc_add_match_ipv6(nxi, data);
27330 +       case VCMD_get_match_ipv6:
27331 +               return vc_get_match_ipv6(nxi, data);
27332 +#endif */
27333 +
27334 +#ifdef CONFIG_VSERVER_DEVICE
27335 +       case VCMD_set_mapping:
27336 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
27337 +       case VCMD_unset_mapping:
27338 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
27339 +#endif
27340 +#ifdef CONFIG_VSERVER_HISTORY
27341 +       case VCMD_dump_history:
27342 +               return vc_dump_history(id);
27343 +       case VCMD_read_history:
27344 +               return __COMPAT(vc_read_history, id, data, compat);
27345 +#endif
27346 +#ifdef CONFIG_VSERVER_MONITOR
27347 +       case VCMD_read_monitor:
27348 +               return __COMPAT(vc_read_monitor, id, data, compat);
27349 +#endif
27350 +       default:
27351 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
27352 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
27353 +       }
27354 +       return -ENOSYS;
27355 +}
27356 +
27357 +
27358 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
27359 +       case VCMD_ ## vcmd: perm = _perm;               \
27360 +               args = _args; flags = _flags; break
27361 +
27362 +
27363 +#define VCA_NONE       0x00
27364 +#define VCA_VXI                0x01
27365 +#define VCA_NXI                0x02
27366 +
27367 +#define VCF_NONE       0x00
27368 +#define VCF_INFO       0x01
27369 +#define VCF_ADMIN      0x02
27370 +#define VCF_ARES       0x06    /* includes admin */
27371 +#define VCF_SETUP      0x08
27372 +
27373 +#define VCF_ZIDOK      0x10    /* zero id okay */
27374 +
27375 +
27376 +static inline
27377 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
27378 +{
27379 +       long ret;
27380 +       int permit = -1, state = 0;
27381 +       int perm = -1, args = 0, flags = 0;
27382 +       struct vx_info *vxi = NULL;
27383 +       struct nx_info *nxi = NULL;
27384 +
27385 +       switch (cmd) {
27386 +       /* unpriviledged commands */
27387 +       __VCMD(get_version,      0, VCA_NONE,   0);
27388 +       __VCMD(get_vci,          0, VCA_NONE,   0);
27389 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
27390 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
27391 +
27392 +       /* info commands */
27393 +       __VCMD(task_xid,         2, VCA_NONE,   0);
27394 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
27395 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
27396 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
27397 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
27398 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
27399 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
27400 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
27401 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
27402 +
27403 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
27404 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
27405 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
27406 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
27407 +
27408 +       __VCMD(task_nid,         2, VCA_NONE,   0);
27409 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
27410 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
27411 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
27412 +
27413 +       __VCMD(task_tag,         2, VCA_NONE,   0);
27414 +
27415 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
27416 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
27417 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
27418 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
27419 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
27420 +
27421 +       /* lower admin commands */
27422 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
27423 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
27424 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
27425 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
27426 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
27427 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
27428 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
27429 +
27430 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
27431 +       __VCMD(net_create,       5, VCA_NONE,   0);
27432 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
27433 +
27434 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
27435 +
27436 +       /* higher admin commands */
27437 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
27438 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27439 +
27440 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27441 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27442 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27443 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27444 +
27445 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27446 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27447 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27448 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27449 +
27450 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27451 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27452 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27453 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27454 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27455 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27456 +#ifdef CONFIG_IPV6
27457 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27458 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27459 +#endif
27460 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
27461 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
27462 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
27463 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
27464 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
27465 +
27466 +#ifdef CONFIG_VSERVER_DEVICE
27467 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27468 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27469 +#endif
27470 +       /* debug level admin commands */
27471 +#ifdef CONFIG_VSERVER_HISTORY
27472 +       __VCMD(dump_history,     9, VCA_NONE,   0);
27473 +       __VCMD(read_history,     9, VCA_NONE,   0);
27474 +#endif
27475 +#ifdef CONFIG_VSERVER_MONITOR
27476 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
27477 +#endif
27478 +
27479 +       default:
27480 +               perm = -1;
27481 +       }
27482 +
27483 +       vxdprintk(VXD_CBIT(switch, 0),
27484 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
27485 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27486 +               VC_VERSION(cmd), id, data, compat,
27487 +               perm, args, flags);
27488 +
27489 +       ret = -ENOSYS;
27490 +       if (perm < 0)
27491 +               goto out;
27492 +
27493 +       state = 1;
27494 +       if (!capable(CAP_CONTEXT))
27495 +               goto out;
27496 +
27497 +       state = 2;
27498 +       /* moved here from the individual commands */
27499 +       ret = -EPERM;
27500 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
27501 +               goto out;
27502 +
27503 +       state = 3;
27504 +       /* vcmd involves resource management  */
27505 +       ret = -EPERM;
27506 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
27507 +               goto out;
27508 +
27509 +       state = 4;
27510 +       /* various legacy exceptions */
27511 +       switch (cmd) {
27512 +       /* will go away when spectator is a cap */
27513 +       case VCMD_ctx_migrate_v0:
27514 +       case VCMD_ctx_migrate:
27515 +               if (id == 1) {
27516 +                       current->xid = 1;
27517 +                       ret = 1;
27518 +                       goto out;
27519 +               }
27520 +               break;
27521 +
27522 +       /* will go away when spectator is a cap */
27523 +       case VCMD_net_migrate:
27524 +               if (id == 1) {
27525 +                       current->nid = 1;
27526 +                       ret = 1;
27527 +                       goto out;
27528 +               }
27529 +               break;
27530 +       }
27531 +
27532 +       /* vcmds are fine by default */
27533 +       permit = 1;
27534 +
27535 +       /* admin type vcmds require admin ... */
27536 +       if (flags & VCF_ADMIN)
27537 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
27538 +
27539 +       /* ... but setup type vcmds override that */
27540 +       if (!permit && (flags & VCF_SETUP))
27541 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
27542 +
27543 +       state = 5;
27544 +       ret = -EPERM;
27545 +       if (!permit)
27546 +               goto out;
27547 +
27548 +       state = 6;
27549 +       if (!id && (flags & VCF_ZIDOK))
27550 +               goto skip_id;
27551 +
27552 +       ret = -ESRCH;
27553 +       if (args & VCA_VXI) {
27554 +               vxi = lookup_vx_info(id);
27555 +               if (!vxi)
27556 +                       goto out;
27557 +
27558 +               if ((flags & VCF_ADMIN) &&
27559 +                       /* special case kill for shutdown */
27560 +                       (cmd != VCMD_ctx_kill) &&
27561 +                       /* can context be administrated? */
27562 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
27563 +                       ret = -EACCES;
27564 +                       goto out_vxi;
27565 +               }
27566 +       }
27567 +       state = 7;
27568 +       if (args & VCA_NXI) {
27569 +               nxi = lookup_nx_info(id);
27570 +               if (!nxi)
27571 +                       goto out_vxi;
27572 +
27573 +               if ((flags & VCF_ADMIN) &&
27574 +                       /* can context be administrated? */
27575 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
27576 +                       ret = -EACCES;
27577 +                       goto out_nxi;
27578 +               }
27579 +       }
27580 +skip_id:
27581 +       state = 8;
27582 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
27583 +
27584 +out_nxi:
27585 +       if ((args & VCA_NXI) && nxi)
27586 +               put_nx_info(nxi);
27587 +out_vxi:
27588 +       if ((args & VCA_VXI) && vxi)
27589 +               put_vx_info(vxi);
27590 +out:
27591 +       vxdprintk(VXD_CBIT(switch, 1),
27592 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
27593 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27594 +               VC_VERSION(cmd), ret, ret, state, permit);
27595 +       return ret;
27596 +}
27597 +
27598 +asmlinkage long
27599 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
27600 +{
27601 +       return do_vserver(cmd, id, data, 0);
27602 +}
27603 +
27604 +#ifdef CONFIG_COMPAT
27605 +
27606 +asmlinkage long
27607 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
27608 +{
27609 +       return do_vserver(cmd, id, data, 1);
27610 +}
27611 +
27612 +#endif /* CONFIG_COMPAT */
27613 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/sysctl.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sysctl.c
27614 --- linux-2.6.22.10/kernel/vserver/sysctl.c     1970-01-01 01:00:00 +0100
27615 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sysctl.c  2007-08-15 23:42:57 +0200
27616 @@ -0,0 +1,243 @@
27617 +/*
27618 + *  kernel/vserver/sysctl.c
27619 + *
27620 + *  Virtual Context Support
27621 + *
27622 + *  Copyright (C) 2004-2007  Herbert Pötzl
27623 + *
27624 + *  V0.01  basic structure
27625 + *
27626 + */
27627 +
27628 +#include <linux/module.h>
27629 +#include <linux/ctype.h>
27630 +#include <linux/sysctl.h>
27631 +#include <linux/parser.h>
27632 +#include <asm/uaccess.h>
27633 +
27634 +
27635 +#define CTL_VSERVER    4242    /* unused? */
27636 +
27637 +enum {
27638 +       CTL_DEBUG_ERROR         = 0,
27639 +       CTL_DEBUG_SWITCH        = 1,
27640 +       CTL_DEBUG_XID,
27641 +       CTL_DEBUG_NID,
27642 +       CTL_DEBUG_TAG,
27643 +       CTL_DEBUG_NET,
27644 +       CTL_DEBUG_LIMIT,
27645 +       CTL_DEBUG_CRES,
27646 +       CTL_DEBUG_DLIM,
27647 +       CTL_DEBUG_QUOTA,
27648 +       CTL_DEBUG_CVIRT,
27649 +       CTL_DEBUG_SPACE,
27650 +       CTL_DEBUG_MISC,
27651 +};
27652 +
27653 +
27654 +unsigned int vx_debug_switch   = 0;
27655 +unsigned int vx_debug_xid      = 0;
27656 +unsigned int vx_debug_nid      = 0;
27657 +unsigned int vx_debug_tag      = 0;
27658 +unsigned int vx_debug_net      = 0;
27659 +unsigned int vx_debug_limit    = 0;
27660 +unsigned int vx_debug_cres     = 0;
27661 +unsigned int vx_debug_dlim     = 0;
27662 +unsigned int vx_debug_quota    = 0;
27663 +unsigned int vx_debug_cvirt    = 0;
27664 +unsigned int vx_debug_space    = 0;
27665 +unsigned int vx_debug_misc     = 0;
27666 +
27667 +
27668 +static struct ctl_table_header *vserver_table_header;
27669 +static ctl_table vserver_table[];
27670 +
27671 +
27672 +void vserver_register_sysctl(void)
27673 +{
27674 +       if (!vserver_table_header) {
27675 +               vserver_table_header = register_sysctl_table(vserver_table);
27676 +       }
27677 +
27678 +}
27679 +
27680 +void vserver_unregister_sysctl(void)
27681 +{
27682 +       if (vserver_table_header) {
27683 +               unregister_sysctl_table(vserver_table_header);
27684 +               vserver_table_header = NULL;
27685 +       }
27686 +}
27687 +
27688 +
27689 +static int proc_dodebug(ctl_table *table, int write,
27690 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
27691 +{
27692 +       char            tmpbuf[20], *p, c;
27693 +       unsigned int    value;
27694 +       size_t          left, len;
27695 +
27696 +       if ((*ppos && !write) || !*lenp) {
27697 +               *lenp = 0;
27698 +               return 0;
27699 +       }
27700 +
27701 +       left = *lenp;
27702 +
27703 +       if (write) {
27704 +               if (!access_ok(VERIFY_READ, buffer, left))
27705 +                       return -EFAULT;
27706 +               p = (char *)buffer;
27707 +               while (left && __get_user(c, p) >= 0 && isspace(c))
27708 +                       left--, p++;
27709 +               if (!left)
27710 +                       goto done;
27711 +
27712 +               if (left > sizeof(tmpbuf) - 1)
27713 +                       return -EINVAL;
27714 +               if (copy_from_user(tmpbuf, p, left))
27715 +                       return -EFAULT;
27716 +               tmpbuf[left] = '\0';
27717 +
27718 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
27719 +                       value = 10 * value + (*p - '0');
27720 +               if (*p && !isspace(*p))
27721 +                       return -EINVAL;
27722 +               while (left && isspace(*p))
27723 +                       left--, p++;
27724 +               *(unsigned int *)table->data = value;
27725 +       } else {
27726 +               if (!access_ok(VERIFY_WRITE, buffer, left))
27727 +                       return -EFAULT;
27728 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
27729 +               if (len > left)
27730 +                       len = left;
27731 +               if (__copy_to_user(buffer, tmpbuf, len))
27732 +                       return -EFAULT;
27733 +               if ((left -= len) > 0) {
27734 +                       if (put_user('\n', (char *)buffer + len))
27735 +                               return -EFAULT;
27736 +                       left--;
27737 +               }
27738 +       }
27739 +
27740 +done:
27741 +       *lenp -= left;
27742 +       *ppos += *lenp;
27743 +       return 0;
27744 +}
27745 +
27746 +
27747 +#define        CTL_ENTRY(ctl, name)                            \
27748 +       {                                               \
27749 +               .ctl_name       = ctl,                  \
27750 +               .procname       = #name,                \
27751 +               .data           = &vx_ ## name,         \
27752 +               .maxlen         = sizeof(int),          \
27753 +               .mode           = 0644,                 \
27754 +               .proc_handler   = &proc_dodebug         \
27755 +       }
27756 +
27757 +static ctl_table debug_table[] = {
27758 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
27759 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
27760 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
27761 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
27762 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
27763 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
27764 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
27765 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
27766 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
27767 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
27768 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
27769 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
27770 +       { .ctl_name = 0 }
27771 +};
27772 +
27773 +static ctl_table vserver_table[] = {
27774 +       {
27775 +               .ctl_name       = CTL_VSERVER,
27776 +               .procname       = "vserver",
27777 +               .mode           = 0555,
27778 +               .child          = debug_table
27779 +       },
27780 +       { .ctl_name = 0 }
27781 +};
27782 +
27783 +
27784 +static match_table_t tokens = {
27785 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
27786 +       { CTL_DEBUG_XID,        "xid=%x"        },
27787 +       { CTL_DEBUG_NID,        "nid=%x"        },
27788 +       { CTL_DEBUG_TAG,        "tag=%x"        },
27789 +       { CTL_DEBUG_NET,        "net=%x"        },
27790 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
27791 +       { CTL_DEBUG_CRES,       "cres=%x"       },
27792 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
27793 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
27794 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
27795 +       { CTL_DEBUG_SPACE,      "space=%x"      },
27796 +       { CTL_DEBUG_MISC,       "misc=%x"       },
27797 +       { CTL_DEBUG_ERROR,      NULL            }
27798 +};
27799 +
27800 +#define        HANDLE_CASE(id, name, val)                              \
27801 +       case CTL_DEBUG_ ## id:                                  \
27802 +               vx_debug_ ## name = val;                        \
27803 +               printk("vs_debug_" #name "=0x%x\n", val);       \
27804 +               break
27805 +
27806 +
27807 +static int __init vs_debug_setup(char *str)
27808 +{
27809 +       char *p;
27810 +       int token;
27811 +
27812 +       printk("vs_debug_setup(%s)\n", str);
27813 +       while ((p = strsep(&str, ",")) != NULL) {
27814 +               substring_t args[MAX_OPT_ARGS];
27815 +               unsigned int value;
27816 +
27817 +               if (!*p)
27818 +                       continue;
27819 +
27820 +               token = match_token(p, tokens, args);
27821 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
27822 +
27823 +               switch (token) {
27824 +               HANDLE_CASE(SWITCH, switch, value);
27825 +               HANDLE_CASE(XID,    xid,    value);
27826 +               HANDLE_CASE(NID,    nid,    value);
27827 +               HANDLE_CASE(TAG,    tag,    value);
27828 +               HANDLE_CASE(NET,    net,    value);
27829 +               HANDLE_CASE(LIMIT,  limit,  value);
27830 +               HANDLE_CASE(CRES,   cres,   value);
27831 +               HANDLE_CASE(DLIM,   dlim,   value);
27832 +               HANDLE_CASE(QUOTA,  quota,  value);
27833 +               HANDLE_CASE(CVIRT,  cvirt,  value);
27834 +               HANDLE_CASE(SPACE,  space,  value);
27835 +               HANDLE_CASE(MISC,   misc,   value);
27836 +               default:
27837 +                       return -EINVAL;
27838 +                       break;
27839 +               }
27840 +       }
27841 +       return 1;
27842 +}
27843 +
27844 +__setup("vsdebug=", vs_debug_setup);
27845 +
27846 +
27847 +
27848 +EXPORT_SYMBOL_GPL(vx_debug_switch);
27849 +EXPORT_SYMBOL_GPL(vx_debug_xid);
27850 +EXPORT_SYMBOL_GPL(vx_debug_nid);
27851 +EXPORT_SYMBOL_GPL(vx_debug_net);
27852 +EXPORT_SYMBOL_GPL(vx_debug_limit);
27853 +EXPORT_SYMBOL_GPL(vx_debug_cres);
27854 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
27855 +EXPORT_SYMBOL_GPL(vx_debug_quota);
27856 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
27857 +EXPORT_SYMBOL_GPL(vx_debug_space);
27858 +EXPORT_SYMBOL_GPL(vx_debug_misc);
27859 +
27860 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/tag.c linux-2.6.22.10-vs2.3.0.29/kernel/vserver/tag.c
27861 --- linux-2.6.22.10/kernel/vserver/tag.c        1970-01-01 01:00:00 +0100
27862 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/tag.c     2007-10-05 14:54:36 +0200
27863 @@ -0,0 +1,62 @@
27864 +/*
27865 + *  linux/kernel/vserver/tag.c
27866 + *
27867 + *  Virtual Server: Shallow Tag Space
27868 + *
27869 + *  Copyright (C) 2007  Herbert Pötzl
27870 + *
27871 + *  V0.01  basic implementation
27872 + *
27873 + */
27874 +
27875 +#include <linux/sched.h>
27876 +#include <linux/vserver/debug.h>
27877 +#include <linux/vs_tag.h>
27878 +
27879 +#include <linux/vserver/tag_cmd.h>
27880 +
27881 +
27882 +int dx_migrate_task(struct task_struct *p, tag_t tag)
27883 +{
27884 +       if (!p)
27885 +               BUG();
27886 +
27887 +       vxdprintk(VXD_CBIT(tag, 5),
27888 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
27889 +
27890 +       task_lock(p);
27891 +       p->tag = tag;
27892 +       task_unlock(p);
27893 +
27894 +       vxdprintk(VXD_CBIT(tag, 5),
27895 +               "moved task %p into [#%d]", p, tag);
27896 +       return 0;
27897 +}
27898 +
27899 +/* vserver syscall commands below here */
27900 +
27901 +/* taks xid and vx_info functions */
27902 +
27903 +
27904 +int vc_task_tag(uint32_t id)
27905 +{
27906 +       tag_t tag;
27907 +
27908 +       if (id) {
27909 +               struct task_struct *tsk;
27910 +               read_lock(&tasklist_lock);
27911 +               tsk = find_task_by_real_pid(id);
27912 +               tag = (tsk) ? tsk->tag : -ESRCH;
27913 +               read_unlock(&tasklist_lock);
27914 +       } else
27915 +               tag = dx_current_tag();
27916 +       return tag;
27917 +}
27918 +
27919 +
27920 +int vc_tag_migrate(uint32_t tag)
27921 +{
27922 +       return dx_migrate_task(current, tag & 0xFFFF);
27923 +}
27924 +
27925 +
27926 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/vci_config.h linux-2.6.22.10-vs2.3.0.29/kernel/vserver/vci_config.h
27927 --- linux-2.6.22.10/kernel/vserver/vci_config.h 1970-01-01 01:00:00 +0100
27928 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/vci_config.h      2007-08-16 03:56:22 +0200
27929 @@ -0,0 +1,81 @@
27930 +
27931 +/*  interface version */
27932 +
27933 +#define VCI_VERSION            0x00020302
27934 +
27935 +
27936 +enum {
27937 +       VCI_KCBIT_NO_DYNAMIC = 0,
27938 +
27939 +       VCI_KCBIT_PROC_SECURE = 4,
27940 +       VCI_KCBIT_HARDCPU = 5,
27941 +       VCI_KCBIT_IDLELIMIT = 6,
27942 +       VCI_KCBIT_IDLETIME = 7,
27943 +
27944 +       VCI_KCBIT_COWBL = 8,
27945 +       VCI_KCBIT_FULLCOWBL = 9,
27946 +       VCI_KCBIT_SPACES = 10,
27947 +       VCI_KCBIT_NETV2 = 11,
27948 +
27949 +       VCI_KCBIT_DEBUG = 16,
27950 +       VCI_KCBIT_HISTORY = 20,
27951 +       VCI_KCBIT_TAGGED = 24,
27952 +       VCI_KCBIT_PPTAG = 28,
27953 +
27954 +       VCI_KCBIT_MORE = 31,
27955 +};
27956 +
27957 +
27958 +static inline uint32_t vci_kernel_config(void)
27959 +{
27960 +       return
27961 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
27962 +
27963 +       /* configured features */
27964 +#ifdef CONFIG_VSERVER_PROC_SECURE
27965 +       (1 << VCI_KCBIT_PROC_SECURE) |
27966 +#endif
27967 +#ifdef CONFIG_VSERVER_HARDCPU
27968 +       (1 << VCI_KCBIT_HARDCPU) |
27969 +#endif
27970 +#ifdef CONFIG_VSERVER_IDLELIMIT
27971 +       (1 << VCI_KCBIT_IDLELIMIT) |
27972 +#endif
27973 +#ifdef CONFIG_VSERVER_IDLETIME
27974 +       (1 << VCI_KCBIT_IDLETIME) |
27975 +#endif
27976 +#ifdef CONFIG_VSERVER_COWBL
27977 +       (1 << VCI_KCBIT_COWBL) |
27978 +       (1 << VCI_KCBIT_FULLCOWBL) |
27979 +#endif
27980 +       (1 << VCI_KCBIT_SPACES) |
27981 +       (1 << VCI_KCBIT_NETV2) |
27982 +
27983 +       /* debug options */
27984 +#ifdef CONFIG_VSERVER_DEBUG
27985 +       (1 << VCI_KCBIT_DEBUG) |
27986 +#endif
27987 +#ifdef CONFIG_VSERVER_HISTORY
27988 +       (1 << VCI_KCBIT_HISTORY) |
27989 +#endif
27990 +
27991 +       /* inode context tagging */
27992 +#if    defined(CONFIG_TAGGING_NONE)
27993 +       (0 << VCI_KCBIT_TAGGED) |
27994 +#elif  defined(CONFIG_TAGGING_UID16)
27995 +       (1 << VCI_KCBIT_TAGGED) |
27996 +#elif  defined(CONFIG_TAGGING_GID16)
27997 +       (2 << VCI_KCBIT_TAGGED) |
27998 +#elif  defined(CONFIG_TAGGING_ID24)
27999 +       (3 << VCI_KCBIT_TAGGED) |
28000 +#elif  defined(CONFIG_TAGGING_INTERN)
28001 +       (4 << VCI_KCBIT_TAGGED) |
28002 +#elif  defined(CONFIG_TAGGING_RUNTIME)
28003 +       (5 << VCI_KCBIT_TAGGED) |
28004 +#else
28005 +       (7 << VCI_KCBIT_TAGGED) |
28006 +#endif
28007 +       (1 << VCI_KCBIT_PPTAG) |
28008 +       0;
28009 +}
28010 +
28011 diff -NurpP --minimal linux-2.6.22.10/mm/filemap_xip.c linux-2.6.22.10-vs2.3.0.29/mm/filemap_xip.c
28012 --- linux-2.6.22.10/mm/filemap_xip.c    2007-07-09 13:20:04 +0200
28013 +++ linux-2.6.22.10-vs2.3.0.29/mm/filemap_xip.c 2007-08-05 20:53:13 +0200
28014 @@ -14,6 +14,7 @@
28015  #include <linux/uio.h>
28016  #include <linux/rmap.h>
28017  #include <linux/sched.h>
28018 +#include <linux/vs_memory.h>
28019  #include <asm/tlbflush.h>
28020  #include "filemap.h"
28021  
28022 diff -NurpP --minimal linux-2.6.22.10/mm/fremap.c linux-2.6.22.10-vs2.3.0.29/mm/fremap.c
28023 --- linux-2.6.22.10/mm/fremap.c 2007-02-06 03:01:56 +0100
28024 +++ linux-2.6.22.10-vs2.3.0.29/mm/fremap.c      2007-08-05 20:53:13 +0200
28025 @@ -15,6 +15,7 @@
28026  #include <linux/rmap.h>
28027  #include <linux/module.h>
28028  #include <linux/syscalls.h>
28029 +#include <linux/vs_memory.h>
28030  
28031  #include <asm/mmu_context.h>
28032  #include <asm/cacheflush.h>
28033 @@ -74,6 +75,8 @@ int install_page(struct mm_struct *mm, s
28034         err = -ENOMEM;
28035         if (page_mapcount(page) > INT_MAX/2)
28036                 goto unlock;
28037 +       if (!vx_rss_avail(mm, 1))
28038 +               goto unlock;
28039  
28040         if (pte_none(*pte) || !zap_pte(mm, vma, addr, pte))
28041                 inc_mm_counter(mm, file_rss);
28042 diff -NurpP --minimal linux-2.6.22.10/mm/hugetlb.c linux-2.6.22.10-vs2.3.0.29/mm/hugetlb.c
28043 --- linux-2.6.22.10/mm/hugetlb.c        2007-10-30 01:57:15 +0100
28044 +++ linux-2.6.22.10-vs2.3.0.29/mm/hugetlb.c     2007-08-11 22:41:51 +0200
28045 @@ -19,6 +19,7 @@
28046  #include <asm/pgtable.h>
28047  
28048  #include <linux/hugetlb.h>
28049 +#include <linux/vs_memory.h>
28050  #include "internal.h"
28051  
28052  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
28053 diff -NurpP --minimal linux-2.6.22.10/mm/memory.c linux-2.6.22.10-vs2.3.0.29/mm/memory.c
28054 --- linux-2.6.22.10/mm/memory.c 2007-07-09 13:20:04 +0200
28055 +++ linux-2.6.22.10-vs2.3.0.29/mm/memory.c      2007-08-05 20:53:13 +0200
28056 @@ -498,6 +498,9 @@ static int copy_pte_range(struct mm_stru
28057         int progress = 0;
28058         int rss[2];
28059  
28060 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
28061 +               return -ENOMEM;
28062 +
28063  again:
28064         rss[1] = rss[0] = 0;
28065         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
28066 @@ -2157,6 +2160,11 @@ static int do_swap_page(struct mm_struct
28067                 count_vm_event(PGMAJFAULT);
28068         }
28069  
28070 +       if (!vx_rss_avail(mm, 1)) {
28071 +               ret = VM_FAULT_OOM;
28072 +               goto out;
28073 +       }
28074 +
28075         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
28076         mark_page_accessed(page);
28077         lock_page(page);
28078 @@ -2229,6 +2237,8 @@ static int do_anonymous_page(struct mm_s
28079                 /* Allocate our own private page. */
28080                 pte_unmap(page_table);
28081  
28082 +               if (!vx_rss_avail(mm, 1))
28083 +                       goto oom;
28084                 if (unlikely(anon_vma_prepare(vma)))
28085                         goto oom;
28086                 page = alloc_zeroed_user_highpage(vma, address);
28087 @@ -2302,6 +2312,9 @@ static int do_no_page(struct mm_struct *
28088         pte_unmap(page_table);
28089         BUG_ON(vma->vm_flags & VM_PFNMAP);
28090  
28091 +       if (!vx_rss_avail(mm, 1))
28092 +               return VM_FAULT_OOM;
28093 +
28094         if (vma->vm_file) {
28095                 mapping = vma->vm_file->f_mapping;
28096                 sequence = mapping->truncate_count;
28097 @@ -2527,6 +2540,7 @@ static inline int handle_pte_fault(struc
28098  {
28099         pte_t entry;
28100         spinlock_t *ptl;
28101 +       int ret, type = VXPT_UNKNOWN;
28102  
28103         entry = *pte;
28104         if (!pte_present(entry)) {
28105 @@ -2555,9 +2569,12 @@ static inline int handle_pte_fault(struc
28106         if (unlikely(!pte_same(*pte, entry)))
28107                 goto unlock;
28108         if (write_access) {
28109 -               if (!pte_write(entry))
28110 -                       return do_wp_page(mm, vma, address,
28111 +               if (!pte_write(entry)) {
28112 +                       ret = do_wp_page(mm, vma, address,
28113                                         pte, pmd, ptl, entry);
28114 +                       type = VXPT_WRITE;
28115 +                       goto out;
28116 +               }
28117                 entry = pte_mkdirty(entry);
28118         }
28119         entry = pte_mkyoung(entry);
28120 @@ -2576,7 +2593,10 @@ static inline int handle_pte_fault(struc
28121         }
28122  unlock:
28123         pte_unmap_unlock(pte, ptl);
28124 -       return VM_FAULT_MINOR;
28125 +       ret = VM_FAULT_MINOR;
28126 +out:
28127 +       vx_page_fault(mm, vma, type, ret);
28128 +       return ret;
28129  }
28130  
28131  /*
28132 diff -NurpP --minimal linux-2.6.22.10/mm/mlock.c linux-2.6.22.10-vs2.3.0.29/mm/mlock.c
28133 --- linux-2.6.22.10/mm/mlock.c  2007-10-30 01:57:15 +0100
28134 +++ linux-2.6.22.10-vs2.3.0.29/mm/mlock.c       2007-08-11 22:41:51 +0200
28135 @@ -12,6 +12,7 @@
28136  #include <linux/syscalls.h>
28137  #include <linux/sched.h>
28138  #include <linux/module.h>
28139 +#include <linux/vs_memory.h>
28140  
28141  int can_do_mlock(void)
28142  {
28143 @@ -76,7 +77,7 @@ success:
28144                         ret = make_pages_present(start, end);
28145         }
28146  
28147 -       mm->locked_vm -= pages;
28148 +       vx_vmlocked_sub(mm, pages);
28149  out:
28150         if (ret == -ENOMEM)
28151                 ret = -EAGAIN;
28152 @@ -134,7 +135,7 @@ static int do_mlock(unsigned long start,
28153  
28154  asmlinkage long sys_mlock(unsigned long start, size_t len)
28155  {
28156 -       unsigned long locked;
28157 +       unsigned long locked, grow;
28158         unsigned long lock_limit;
28159         int error = -ENOMEM;
28160  
28161 @@ -145,8 +146,10 @@ asmlinkage long sys_mlock(unsigned long 
28162         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
28163         start &= PAGE_MASK;
28164  
28165 -       locked = len >> PAGE_SHIFT;
28166 -       locked += current->mm->locked_vm;
28167 +       grow = len >> PAGE_SHIFT;
28168 +       if (!vx_vmlocked_avail(current->mm, grow))
28169 +               goto out;
28170 +       locked = current->mm->locked_vm + grow;
28171  
28172         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
28173         lock_limit >>= PAGE_SHIFT;
28174 @@ -154,6 +157,7 @@ asmlinkage long sys_mlock(unsigned long 
28175         /* check against resource limits */
28176         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
28177                 error = do_mlock(start, len, 1);
28178 +out:
28179         up_write(&current->mm->mmap_sem);
28180         return error;
28181  }
28182 @@ -213,6 +217,8 @@ asmlinkage long sys_mlockall(int flags)
28183         lock_limit >>= PAGE_SHIFT;
28184  
28185         ret = -ENOMEM;
28186 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
28187 +               goto out;
28188         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
28189             capable(CAP_IPC_LOCK))
28190                 ret = do_mlockall(flags);
28191 diff -NurpP --minimal linux-2.6.22.10/mm/mmap.c linux-2.6.22.10-vs2.3.0.29/mm/mmap.c
28192 --- linux-2.6.22.10/mm/mmap.c   2007-07-09 13:20:04 +0200
28193 +++ linux-2.6.22.10-vs2.3.0.29/mm/mmap.c        2007-08-05 20:53:13 +0200
28194 @@ -1144,10 +1144,10 @@ munmap_back:
28195                 kmem_cache_free(vm_area_cachep, vma);
28196         }
28197  out:   
28198 -       mm->total_vm += len >> PAGE_SHIFT;
28199 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28200         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
28201         if (vm_flags & VM_LOCKED) {
28202 -               mm->locked_vm += len >> PAGE_SHIFT;
28203 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28204                 make_pages_present(addr, addr + len);
28205         }
28206         if (flags & MAP_POPULATE) {
28207 @@ -1502,9 +1502,9 @@ static int acct_stack_growth(struct vm_a
28208                 return -ENOMEM;
28209  
28210         /* Ok, everything looks good - let it rip */
28211 -       mm->total_vm += grow;
28212 +       vx_vmpages_add(mm, grow);
28213         if (vma->vm_flags & VM_LOCKED)
28214 -               mm->locked_vm += grow;
28215 +               vx_vmlocked_add(mm, grow);
28216         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
28217         return 0;
28218  }
28219 @@ -1662,9 +1662,9 @@ static void remove_vma_list(struct mm_st
28220         do {
28221                 long nrpages = vma_pages(vma);
28222  
28223 -               mm->total_vm -= nrpages;
28224 +               vx_vmpages_sub(mm, nrpages);
28225                 if (vma->vm_flags & VM_LOCKED)
28226 -                       mm->locked_vm -= nrpages;
28227 +                       vx_vmlocked_sub(mm, nrpages);
28228                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
28229                 vma = remove_vma(vma);
28230         } while (vma);
28231 @@ -1903,6 +1903,8 @@ unsigned long do_brk(unsigned long addr,
28232                 lock_limit >>= PAGE_SHIFT;
28233                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28234                         return -EAGAIN;
28235 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
28236 +                       return -ENOMEM;
28237         }
28238  
28239         /*
28240 @@ -1929,7 +1931,8 @@ unsigned long do_brk(unsigned long addr,
28241         if (mm->map_count > sysctl_max_map_count)
28242                 return -ENOMEM;
28243  
28244 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
28245 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
28246 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
28247                 return -ENOMEM;
28248  
28249         /* Can we just expand an old private anonymous mapping? */
28250 @@ -1955,9 +1958,9 @@ unsigned long do_brk(unsigned long addr,
28251                                 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
28252         vma_link(mm, vma, prev, rb_link, rb_parent);
28253  out:
28254 -       mm->total_vm += len >> PAGE_SHIFT;
28255 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28256         if (flags & VM_LOCKED) {
28257 -               mm->locked_vm += len >> PAGE_SHIFT;
28258 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28259                 make_pages_present(addr, addr + len);
28260         }
28261         return addr;
28262 @@ -1986,6 +1989,11 @@ void exit_mmap(struct mm_struct *mm)
28263         free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
28264         tlb_finish_mmu(tlb, 0, end);
28265  
28266 +       set_mm_counter(mm, file_rss, 0);
28267 +       set_mm_counter(mm, anon_rss, 0);
28268 +       vx_vmpages_sub(mm, mm->total_vm);
28269 +       vx_vmlocked_sub(mm, mm->locked_vm);
28270 +
28271         /*
28272          * Walk the list again, actually closing and freeing it,
28273          * with preemption enabled, without holding any MM locks.
28274 @@ -2025,7 +2033,8 @@ int insert_vm_struct(struct mm_struct * 
28275         if (__vma && __vma->vm_start < vma->vm_end)
28276                 return -ENOMEM;
28277         if ((vma->vm_flags & VM_ACCOUNT) &&
28278 -            security_vm_enough_memory(vma_pages(vma)))
28279 +               (security_vm_enough_memory(vma_pages(vma)) ||
28280 +               !vx_vmpages_avail(mm, vma_pages(vma))))
28281                 return -ENOMEM;
28282         vma_link(mm, vma, prev, rb_link, rb_parent);
28283         return 0;
28284 @@ -2098,6 +2107,8 @@ int may_expand_vm(struct mm_struct *mm, 
28285  
28286         if (cur + npages > lim)
28287                 return 0;
28288 +       if (!vx_vmpages_avail(mm, npages))
28289 +               return 0;
28290         return 1;
28291  }
28292  
28293 @@ -2168,7 +2179,6 @@ int install_special_mapping(struct mm_st
28294                 return -ENOMEM;
28295         }
28296  
28297 -       mm->total_vm += len >> PAGE_SHIFT;
28298 -
28299 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28300         return 0;
28301  }
28302 diff -NurpP --minimal linux-2.6.22.10/mm/mremap.c linux-2.6.22.10-vs2.3.0.29/mm/mremap.c
28303 --- linux-2.6.22.10/mm/mremap.c 2007-02-06 03:01:56 +0100
28304 +++ linux-2.6.22.10-vs2.3.0.29/mm/mremap.c      2007-08-05 20:53:13 +0200
28305 @@ -18,6 +18,7 @@
28306  #include <linux/highmem.h>
28307  #include <linux/security.h>
28308  #include <linux/syscalls.h>
28309 +#include <linux/vs_memory.h>
28310  
28311  #include <asm/uaccess.h>
28312  #include <asm/cacheflush.h>
28313 @@ -212,7 +213,7 @@ static unsigned long move_vma(struct vm_
28314          * If this were a serious issue, we'd add a flag to do_munmap().
28315          */
28316         hiwater_vm = mm->hiwater_vm;
28317 -       mm->total_vm += new_len >> PAGE_SHIFT;
28318 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
28319         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
28320  
28321         if (do_munmap(mm, old_addr, old_len) < 0) {
28322 @@ -230,7 +231,7 @@ static unsigned long move_vma(struct vm_
28323         }
28324  
28325         if (vm_flags & VM_LOCKED) {
28326 -               mm->locked_vm += new_len >> PAGE_SHIFT;
28327 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
28328                 if (new_len > old_len)
28329                         make_pages_present(new_addr + old_len,
28330                                            new_addr + new_len);
28331 @@ -337,6 +338,9 @@ unsigned long do_mremap(unsigned long ad
28332                 ret = -EAGAIN;
28333                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28334                         goto out;
28335 +               if (!vx_vmlocked_avail(current->mm,
28336 +                       (new_len - old_len) >> PAGE_SHIFT))
28337 +                       goto out;
28338         }
28339         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
28340                 ret = -ENOMEM;
28341 @@ -365,10 +369,10 @@ unsigned long do_mremap(unsigned long ad
28342                         vma_adjust(vma, vma->vm_start,
28343                                 addr + new_len, vma->vm_pgoff, NULL);
28344  
28345 -                       mm->total_vm += pages;
28346 +                       vx_vmpages_add(mm, pages);
28347                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
28348                         if (vma->vm_flags & VM_LOCKED) {
28349 -                               mm->locked_vm += pages;
28350 +                               vx_vmlocked_add(mm, pages);
28351                                 make_pages_present(addr + old_len,
28352                                                    addr + new_len);
28353                         }
28354 diff -NurpP --minimal linux-2.6.22.10/mm/nommu.c linux-2.6.22.10-vs2.3.0.29/mm/nommu.c
28355 --- linux-2.6.22.10/mm/nommu.c  2007-07-09 13:20:04 +0200
28356 +++ linux-2.6.22.10-vs2.3.0.29/mm/nommu.c       2007-08-05 20:53:13 +0200
28357 @@ -936,7 +936,7 @@ unsigned long do_mmap_pgoff(struct file 
28358         realalloc += kobjsize(vma);
28359         askedalloc += sizeof(*vma);
28360  
28361 -       current->mm->total_vm += len >> PAGE_SHIFT;
28362 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
28363  
28364         add_nommu_vma(vma);
28365  
28366 @@ -1061,7 +1061,7 @@ int do_munmap(struct mm_struct *mm, unsi
28367         kfree(vml);
28368  
28369         update_hiwater_vm(mm);
28370 -       mm->total_vm -= len >> PAGE_SHIFT;
28371 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
28372  
28373  #ifdef DEBUG
28374         show_process_blocks();
28375 @@ -1093,7 +1093,7 @@ void exit_mmap(struct mm_struct * mm)
28376                 printk("Exit_mmap:\n");
28377  #endif
28378  
28379 -               mm->total_vm = 0;
28380 +               vx_vmpages_sub(mm, mm->total_vm);
28381  
28382                 while ((tmp = mm->context.vmlist)) {
28383                         mm->context.vmlist = tmp->next;
28384 diff -NurpP --minimal linux-2.6.22.10/mm/oom_kill.c linux-2.6.22.10-vs2.3.0.29/mm/oom_kill.c
28385 --- linux-2.6.22.10/mm/oom_kill.c       2007-07-09 13:20:04 +0200
28386 +++ linux-2.6.22.10-vs2.3.0.29/mm/oom_kill.c    2007-08-05 20:53:13 +0200
28387 @@ -24,6 +24,7 @@
28388  #include <linux/cpuset.h>
28389  #include <linux/module.h>
28390  #include <linux/notifier.h>
28391 +#include <linux/vs_memory.h>
28392  
28393  int sysctl_panic_on_oom;
28394  /* #define DEBUG */
28395 @@ -66,6 +67,12 @@ unsigned long badness(struct task_struct
28396         points = mm->total_vm;
28397  
28398         /*
28399 +        * add points for context badness
28400 +        */
28401 +
28402 +       points += vx_badness(p, mm);
28403 +
28404 +       /*
28405          * After this unlock we can no longer dereference local variable `mm'
28406          */
28407         task_unlock(p);
28408 @@ -156,8 +163,8 @@ unsigned long badness(struct task_struct
28409         }
28410  
28411  #ifdef DEBUG
28412 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
28413 -       p->pid, p->comm, points);
28414 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
28415 +               p->pid, p->xid, p->comm, points);
28416  #endif
28417         return points;
28418  }
28419 @@ -288,7 +295,8 @@ static void __oom_kill_task(struct task_
28420         }
28421  
28422         if (verbose)
28423 -               printk(KERN_ERR "Killed process %d (%s)\n", p->pid, p->comm);
28424 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
28425 +                               p->pid, p->xid, p->comm);
28426  
28427         /*
28428          * We give our sacrificial lamb high priority and access to
28429 @@ -358,8 +366,8 @@ static int oom_kill_process(struct task_
28430                 return 0;
28431         }
28432  
28433 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
28434 -                                       message, p->pid, p->comm, points);
28435 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
28436 +                               message, p->pid, p->xid, p->comm, points);
28437  
28438         /* Try to kill a child first */
28439         list_for_each(tsk, &p->children) {
28440 diff -NurpP --minimal linux-2.6.22.10/mm/page_alloc.c linux-2.6.22.10-vs2.3.0.29/mm/page_alloc.c
28441 --- linux-2.6.22.10/mm/page_alloc.c     2007-07-09 13:20:04 +0200
28442 +++ linux-2.6.22.10-vs2.3.0.29/mm/page_alloc.c  2007-08-05 20:53:13 +0200
28443 @@ -41,6 +41,8 @@
28444  #include <linux/pfn.h>
28445  #include <linux/backing-dev.h>
28446  #include <linux/fault-inject.h>
28447 +#include <linux/vs_base.h>
28448 +#include <linux/vs_limit.h>
28449  
28450  #include <asm/tlbflush.h>
28451  #include <asm/div64.h>
28452 @@ -1488,6 +1490,9 @@ void si_meminfo(struct sysinfo *val)
28453         val->totalhigh = totalhigh_pages;
28454         val->freehigh = nr_free_highpages();
28455         val->mem_unit = PAGE_SIZE;
28456 +
28457 +       if (vx_flags(VXF_VIRT_MEM, 0))
28458 +               vx_vsi_meminfo(val);
28459  }
28460  
28461  EXPORT_SYMBOL(si_meminfo);
28462 @@ -1508,6 +1513,9 @@ void si_meminfo_node(struct sysinfo *val
28463         val->freehigh = 0;
28464  #endif
28465         val->mem_unit = PAGE_SIZE;
28466 +
28467 +       if (vx_flags(VXF_VIRT_MEM, 0))
28468 +               vx_vsi_meminfo(val);
28469  }
28470  #endif
28471  
28472 diff -NurpP --minimal linux-2.6.22.10/mm/rmap.c linux-2.6.22.10-vs2.3.0.29/mm/rmap.c
28473 --- linux-2.6.22.10/mm/rmap.c   2007-07-09 13:20:04 +0200
28474 +++ linux-2.6.22.10-vs2.3.0.29/mm/rmap.c        2007-08-05 20:53:13 +0200
28475 @@ -48,6 +48,7 @@
28476  #include <linux/rcupdate.h>
28477  #include <linux/module.h>
28478  #include <linux/kallsyms.h>
28479 +#include <linux/vs_memory.h>
28480  
28481  #include <asm/tlbflush.h>
28482  
28483 diff -NurpP --minimal linux-2.6.22.10/mm/shmem.c linux-2.6.22.10-vs2.3.0.29/mm/shmem.c
28484 --- linux-2.6.22.10/mm/shmem.c  2007-07-09 13:20:04 +0200
28485 +++ linux-2.6.22.10-vs2.3.0.29/mm/shmem.c       2007-08-05 20:53:13 +0200
28486 @@ -55,7 +55,6 @@
28487  #include <asm/pgtable.h>
28488  
28489  /* This magic number is used in glibc for posix shared memory */
28490 -#define TMPFS_MAGIC    0x01021994
28491  
28492  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
28493  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
28494 @@ -1734,7 +1733,7 @@ static int shmem_statfs(struct dentry *d
28495  {
28496         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
28497  
28498 -       buf->f_type = TMPFS_MAGIC;
28499 +       buf->f_type = TMPFS_SUPER_MAGIC;
28500         buf->f_bsize = PAGE_CACHE_SIZE;
28501         buf->f_namelen = NAME_MAX;
28502         spin_lock(&sbinfo->stat_lock);
28503 @@ -2308,7 +2307,7 @@ static int shmem_fill_super(struct super
28504         sb->s_maxbytes = SHMEM_MAX_BYTES;
28505         sb->s_blocksize = PAGE_CACHE_SIZE;
28506         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
28507 -       sb->s_magic = TMPFS_MAGIC;
28508 +       sb->s_magic = TMPFS_SUPER_MAGIC;
28509         sb->s_op = &shmem_ops;
28510         sb->s_time_gran = 1;
28511  #ifdef CONFIG_TMPFS_POSIX_ACL
28512 diff -NurpP --minimal linux-2.6.22.10/mm/slab.c linux-2.6.22.10-vs2.3.0.29/mm/slab.c
28513 --- linux-2.6.22.10/mm/slab.c   2007-07-09 13:20:04 +0200
28514 +++ linux-2.6.22.10-vs2.3.0.29/mm/slab.c        2007-08-05 20:53:13 +0200
28515 @@ -510,6 +510,8 @@ struct kmem_cache {
28516  #define STATS_INC_FREEMISS(x)  do { } while (0)
28517  #endif
28518  
28519 +#include "slab_vs.h"
28520 +
28521  #if DEBUG
28522  
28523  /*
28524 @@ -3314,6 +3316,7 @@ retry:
28525  
28526         obj = slab_get_obj(cachep, slabp, nodeid);
28527         check_slabp(cachep, slabp);
28528 +       vx_slab_alloc(cachep, flags);
28529         l3->free_objects--;
28530         /* move slabp to correct slabp list: */
28531         list_del(&slabp->list);
28532 @@ -3386,6 +3389,7 @@ __cache_alloc_node(struct kmem_cache *ca
28533         /* ___cache_alloc_node can fall back to other nodes */
28534         ptr = ____cache_alloc_node(cachep, flags, nodeid);
28535    out:
28536 +       vx_slab_alloc(cachep, flags);
28537         local_irq_restore(save_flags);
28538         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
28539  
28540 @@ -3551,6 +3555,7 @@ static inline void __cache_free(struct k
28541  
28542         check_irq_off();
28543         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
28544 +       vx_slab_free(cachep);
28545  
28546         if (cache_free_alien(cachep, objp))
28547                 return;
28548 diff -NurpP --minimal linux-2.6.22.10/mm/slab_vs.h linux-2.6.22.10-vs2.3.0.29/mm/slab_vs.h
28549 --- linux-2.6.22.10/mm/slab_vs.h        1970-01-01 01:00:00 +0100
28550 +++ linux-2.6.22.10-vs2.3.0.29/mm/slab_vs.h     2007-08-05 20:53:13 +0200
28551 @@ -0,0 +1,27 @@
28552 +
28553 +#include <linux/vserver/context.h>
28554 +
28555 +#include <linux/vs_context.h>
28556 +
28557 +static inline
28558 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
28559 +{
28560 +       int what = gfp_zone(cachep->gfpflags);
28561 +
28562 +       if (!current->vx_info)
28563 +               return;
28564 +
28565 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28566 +}
28567 +
28568 +static inline
28569 +void vx_slab_free(struct kmem_cache *cachep)
28570 +{
28571 +       int what = gfp_zone(cachep->gfpflags);
28572 +
28573 +       if (!current->vx_info)
28574 +               return;
28575 +
28576 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28577 +}
28578 +
28579 diff -NurpP --minimal linux-2.6.22.10/mm/swapfile.c linux-2.6.22.10-vs2.3.0.29/mm/swapfile.c
28580 --- linux-2.6.22.10/mm/swapfile.c       2007-07-09 13:20:04 +0200
28581 +++ linux-2.6.22.10-vs2.3.0.29/mm/swapfile.c    2007-08-05 20:53:13 +0200
28582 @@ -31,6 +31,8 @@
28583  #include <asm/pgtable.h>
28584  #include <asm/tlbflush.h>
28585  #include <linux/swapops.h>
28586 +#include <linux/vs_base.h>
28587 +#include <linux/vs_memory.h>
28588  
28589  DEFINE_SPINLOCK(swap_lock);
28590  unsigned int nr_swapfiles;
28591 @@ -1712,6 +1714,8 @@ void si_swapinfo(struct sysinfo *val)
28592         val->freeswap = nr_swap_pages + nr_to_be_unused;
28593         val->totalswap = total_swap_pages + nr_to_be_unused;
28594         spin_unlock(&swap_lock);
28595 +       if (vx_flags(VXF_VIRT_MEM, 0))
28596 +               vx_vsi_swapinfo(val);
28597  }
28598  
28599  /*
28600 diff -NurpP --minimal linux-2.6.22.10/net/core/dev.c linux-2.6.22.10-vs2.3.0.29/net/core/dev.c
28601 --- linux-2.6.22.10/net/core/dev.c      2007-10-30 01:57:15 +0100
28602 +++ linux-2.6.22.10-vs2.3.0.29/net/core/dev.c   2007-09-05 03:06:12 +0200
28603 @@ -117,6 +117,7 @@
28604  #include <linux/err.h>
28605  #include <linux/ctype.h>
28606  #include <linux/if_arp.h>
28607 +#include <linux/vs_inet.h>
28608  
28609  /*
28610   *     The list of packet types we will receive (as opposed to discard)
28611 @@ -2120,6 +2121,8 @@ static int dev_ifconf(char __user *arg)
28612  
28613         total = 0;
28614         for_each_netdev(dev) {
28615 +               if (!nx_dev_visible(current->nx_info, dev))
28616 +                       continue;
28617                 for (i = 0; i < NPROTO; i++) {
28618                         if (gifconf_list[i]) {
28619                                 int done;
28620 @@ -2184,6 +2187,9 @@ static void dev_seq_printf_stats(struct 
28621  {
28622         struct net_device_stats *stats = dev->get_stats(dev);
28623  
28624 +       if (!nx_dev_visible(current->nx_info, dev))
28625 +               return;
28626 +
28627         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
28628                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
28629                    dev->name, stats->rx_bytes, stats->rx_packets,
28630 diff -NurpP --minimal linux-2.6.22.10/net/core/rtnetlink.c linux-2.6.22.10-vs2.3.0.29/net/core/rtnetlink.c
28631 --- linux-2.6.22.10/net/core/rtnetlink.c        2007-07-09 13:20:05 +0200
28632 +++ linux-2.6.22.10-vs2.3.0.29/net/core/rtnetlink.c     2007-08-05 20:53:13 +0200
28633 @@ -537,6 +537,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
28634  
28635         idx = 0;
28636         for_each_netdev(dev) {
28637 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
28638 +                       continue;
28639                 if (idx < s_idx)
28640                         goto cont;
28641                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
28642 @@ -797,6 +799,9 @@ void rtmsg_ifinfo(int type, struct net_d
28643         struct sk_buff *skb;
28644         int err = -ENOBUFS;
28645  
28646 +       if (!nx_dev_visible(current->nx_info, dev))
28647 +               return;
28648 +
28649         skb = nlmsg_new(if_nlmsg_size(), GFP_KERNEL);
28650         if (skb == NULL)
28651                 goto errout;
28652 diff -NurpP --minimal linux-2.6.22.10/net/core/sock.c linux-2.6.22.10-vs2.3.0.29/net/core/sock.c
28653 --- linux-2.6.22.10/net/core/sock.c     2007-07-09 13:20:05 +0200
28654 +++ linux-2.6.22.10-vs2.3.0.29/net/core/sock.c  2007-10-01 14:57:43 +0200
28655 @@ -125,6 +125,10 @@
28656  #include <linux/ipsec.h>
28657  
28658  #include <linux/filter.h>
28659 +#include <linux/vs_socket.h>
28660 +#include <linux/vs_limit.h>
28661 +#include <linux/vs_context.h>
28662 +#include <linux/vs_network.h>
28663  
28664  #ifdef CONFIG_INET
28665  #include <net/tcp.h>
28666 @@ -812,6 +816,9 @@ int sock_getsockopt(struct socket *sock,
28667         case SO_PEERSEC:
28668                 return security_socket_getpeersec_stream(sock, optval, optlen, len);
28669  
28670 +               case SO_PEERTAG:
28671 +                       return vx_socket_peer_tag(sock, level, optval, optlen, len);
28672 +
28673         default:
28674                 return -ENOPROTOOPT;
28675         }
28676 @@ -869,6 +876,8 @@ struct sock *sk_alloc(int family, gfp_t 
28677                         sk->sk_prot = sk->sk_prot_creator = prot;
28678                         sock_lock_init(sk);
28679                 }
28680 +               sock_vx_init(sk);
28681 +               sock_nx_init(sk);
28682  
28683                 if (security_sk_alloc(sk, family, priority))
28684                         goto out_free;
28685 @@ -907,6 +916,11 @@ void sk_free(struct sock *sk)
28686                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
28687  
28688         security_sk_free(sk);
28689 +       vx_sock_dec(sk);
28690 +       clr_vx_info(&sk->sk_vx_info);
28691 +       sk->sk_xid = -1;
28692 +       clr_nx_info(&sk->sk_nx_info);
28693 +       sk->sk_nid = -1;
28694         if (sk->sk_prot_creator->slab != NULL)
28695                 kmem_cache_free(sk->sk_prot_creator->slab, sk);
28696         else
28697 @@ -924,6 +938,8 @@ struct sock *sk_clone(const struct sock 
28698                 sock_copy(newsk, sk);
28699  
28700                 /* SANITY */
28701 +               sock_vx_init(newsk);
28702 +               sock_nx_init(newsk);
28703                 sk_node_init(&newsk->sk_node);
28704                 sock_lock_init(newsk);
28705                 bh_lock_sock(newsk);
28706 @@ -969,6 +985,12 @@ struct sock *sk_clone(const struct sock 
28707                 newsk->sk_priority = 0;
28708                 atomic_set(&newsk->sk_refcnt, 2);
28709  
28710 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
28711 +               newsk->sk_xid = sk->sk_xid;
28712 +               vx_sock_inc(newsk);
28713 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
28714 +               newsk->sk_nid = sk->sk_nid;
28715 +
28716                 /*
28717                  * Increment the counter in the same struct proto as the master
28718                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
28719 @@ -1551,6 +1573,11 @@ void sock_init_data(struct socket *sock,
28720  
28721         sk->sk_stamp = ktime_set(-1L, -1L);
28722  
28723 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
28724 +       sk->sk_xid = vx_current_xid();
28725 +       vx_sock_inc(sk);
28726 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
28727 +       sk->sk_nid = nx_current_nid();
28728         atomic_set(&sk->sk_refcnt, 1);
28729  }
28730  
28731 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/af_inet.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/af_inet.c
28732 --- linux-2.6.22.10/net/ipv4/af_inet.c  2007-10-30 01:57:15 +0100
28733 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/af_inet.c       2007-10-05 14:54:36 +0200
28734 @@ -115,6 +115,7 @@
28735  #ifdef CONFIG_IP_MROUTE
28736  #include <linux/mroute.h>
28737  #endif
28738 +#include <linux/vs_limit.h>
28739  
28740  DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
28741  
28742 @@ -308,9 +309,12 @@ lookup_protocol:
28743         }
28744  
28745         err = -EPERM;
28746 +       if ((protocol == IPPROTO_ICMP) &&
28747 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28748 +               goto override;
28749         if (answer->capability > 0 && !capable(answer->capability))
28750                 goto out_rcu_unlock;
28751 -
28752 +override:
28753         sock->ops = answer->ops;
28754         answer_prot = answer->prot;
28755         answer_no_check = answer->no_check;
28756 @@ -424,6 +428,7 @@ int inet_bind(struct socket *sock, struc
28757         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
28758         struct sock *sk = sock->sk;
28759         struct inet_sock *inet = inet_sk(sk);
28760 +       struct nx_v4_sock_addr nsa;
28761         unsigned short snum;
28762         int chk_addr_ret;
28763         int err;
28764 @@ -437,7 +442,11 @@ int inet_bind(struct socket *sock, struc
28765         if (addr_len < sizeof(struct sockaddr_in))
28766                 goto out;
28767  
28768 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
28769 +       err = v4_map_sock_addr(inet, addr, &nsa);
28770 +       if (err)
28771 +               goto out;
28772 +
28773 +       chk_addr_ret = inet_addr_type(nsa.saddr);
28774  
28775         /* Not specified by any standard per-se, however it breaks too
28776          * many applications when removed.  It is unfortunate since
28777 @@ -449,7 +458,7 @@ int inet_bind(struct socket *sock, struc
28778         err = -EADDRNOTAVAIL;
28779         if (!sysctl_ip_nonlocal_bind &&
28780             !inet->freebind &&
28781 -           addr->sin_addr.s_addr != INADDR_ANY &&
28782 +           nsa.saddr != INADDR_ANY &&
28783             chk_addr_ret != RTN_LOCAL &&
28784             chk_addr_ret != RTN_MULTICAST &&
28785             chk_addr_ret != RTN_BROADCAST)
28786 @@ -474,7 +483,7 @@ int inet_bind(struct socket *sock, struc
28787         if (sk->sk_state != TCP_CLOSE || inet->num)
28788                 goto out_release_sock;
28789  
28790 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
28791 +       v4_set_sock_addr(inet, &nsa);
28792         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
28793                 inet->saddr = 0;  /* Use device */
28794  
28795 @@ -667,11 +676,13 @@ int inet_getname(struct socket *sock, st
28796                      peer == 1))
28797                         return -ENOTCONN;
28798                 sin->sin_port = inet->dport;
28799 -               sin->sin_addr.s_addr = inet->daddr;
28800 +               sin->sin_addr.s_addr =
28801 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28802         } else {
28803                 __be32 addr = inet->rcv_saddr;
28804                 if (!addr)
28805                         addr = inet->saddr;
28806 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
28807                 sin->sin_port = inet->sport;
28808                 sin->sin_addr.s_addr = addr;
28809         }
28810 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/devinet.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/devinet.c
28811 --- linux-2.6.22.10/net/ipv4/devinet.c  2007-10-30 01:57:15 +0100
28812 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/devinet.c       2007-09-30 14:58:01 +0200
28813 @@ -427,6 +427,7 @@ struct in_device *inetdev_by_index(int i
28814         return in_dev;
28815  }
28816  
28817 +
28818  /* Called only from RTNL semaphored context. No locks. */
28819  
28820  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
28821 @@ -676,6 +677,8 @@ int devinet_ioctl(unsigned int cmd, void
28822                 *colon = ':';
28823  
28824         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
28825 +               struct nx_info *nxi = current->nx_info;
28826 +
28827                 if (tryaddrmatch) {
28828                         /* Matthias Andree */
28829                         /* compare label and address (4.4BSD style) */
28830 @@ -684,6 +687,8 @@ int devinet_ioctl(unsigned int cmd, void
28831                            This is checked above. */
28832                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28833                              ifap = &ifa->ifa_next) {
28834 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28835 +                                       continue;
28836                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
28837                                     sin_orig.sin_addr.s_addr ==
28838                                                         ifa->ifa_address) {
28839 @@ -696,9 +701,12 @@ int devinet_ioctl(unsigned int cmd, void
28840                    comparing just the label */
28841                 if (!ifa) {
28842                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28843 -                            ifap = &ifa->ifa_next)
28844 +                            ifap = &ifa->ifa_next) {
28845 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28846 +                                       continue;
28847                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
28848                                         break;
28849 +                       }
28850                 }
28851         }
28852  
28853 @@ -849,6 +857,8 @@ static int inet_gifconf(struct net_devic
28854                 goto out;
28855  
28856         for (; ifa; ifa = ifa->ifa_next) {
28857 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
28858 +                       continue;
28859                 if (!buf) {
28860                         done += sizeof(ifr);
28861                         continue;
28862 @@ -1179,6 +1189,7 @@ static int inet_dump_ifaddr(struct sk_bu
28863         struct net_device *dev;
28864         struct in_device *in_dev;
28865         struct in_ifaddr *ifa;
28866 +       struct sock *sk = skb->sk;
28867         int s_ip_idx, s_idx = cb->args[0];
28868  
28869         s_ip_idx = ip_idx = cb->args[1];
28870 @@ -1193,6 +1204,8 @@ static int inet_dump_ifaddr(struct sk_bu
28871  
28872                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
28873                      ifa = ifa->ifa_next, ip_idx++) {
28874 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
28875 +                               continue;
28876                         if (ip_idx < s_ip_idx)
28877                                 continue;
28878                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
28879 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/fib_hash.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/fib_hash.c
28880 --- linux-2.6.22.10/net/ipv4/fib_hash.c 2007-07-09 13:20:05 +0200
28881 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/fib_hash.c      2007-08-05 20:53:13 +0200
28882 @@ -1012,7 +1012,7 @@ static int fib_seq_show(struct seq_file 
28883         prefix  = f->fn_key;
28884         mask    = FZ_MASK(iter->zone);
28885         flags   = fib_flag_trans(fa->fa_type, mask, fi);
28886 -       if (fi)
28887 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
28888                 snprintf(bf, sizeof(bf),
28889                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
28890                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
28891 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/inet_connection_sock.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_connection_sock.c
28892 --- linux-2.6.22.10/net/ipv4/inet_connection_sock.c     2007-07-09 13:20:05 +0200
28893 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_connection_sock.c  2007-10-18 01:28:12 +0200
28894 @@ -34,10 +34,40 @@ EXPORT_SYMBOL(inet_csk_timer_bug_msg);
28895   */
28896  int sysctl_local_port_range[2] = { 32768, 61000 };
28897  
28898 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
28899 +{
28900 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
28901 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
28902 +
28903 +       if (inet_v6_ipv6only(sk2))
28904 +               return 0;
28905 +
28906 +       if (sk1_rcv_saddr &&
28907 +           sk2_rcv_saddr &&
28908 +           sk1_rcv_saddr == sk2_rcv_saddr)
28909 +               return 1;
28910 +
28911 +       if (sk1_rcv_saddr &&
28912 +           !sk2_rcv_saddr &&
28913 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
28914 +               return 1;
28915 +
28916 +       if (sk2_rcv_saddr &&
28917 +           !sk1_rcv_saddr &&
28918 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
28919 +               return 1;
28920 +
28921 +       if (!sk1_rcv_saddr &&
28922 +           !sk2_rcv_saddr &&
28923 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
28924 +               return 1;
28925 +
28926 +       return 0;
28927 +}
28928 +
28929  int inet_csk_bind_conflict(const struct sock *sk,
28930                            const struct inet_bind_bucket *tb)
28931  {
28932 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
28933         struct sock *sk2;
28934         struct hlist_node *node;
28935         int reuse = sk->sk_reuse;
28936 @@ -50,9 +80,7 @@ int inet_csk_bind_conflict(const struct 
28937                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
28938                         if (!reuse || !sk2->sk_reuse ||
28939                             sk2->sk_state == TCP_LISTEN) {
28940 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
28941 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
28942 -                                   sk2_rcv_saddr == sk_rcv_saddr)
28943 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
28944                                         break;
28945                         }
28946                 }
28947 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/inet_diag.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_diag.c
28948 --- linux-2.6.22.10/net/ipv4/inet_diag.c        2007-10-30 01:57:15 +0100
28949 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_diag.c     2007-10-30 02:36:32 +0100
28950 @@ -98,8 +98,8 @@ static int inet_csk_diag_fill(struct soc
28951  
28952         r->id.idiag_sport = inet->sport;
28953         r->id.idiag_dport = inet->dport;
28954 -       r->id.idiag_src[0] = inet->rcv_saddr;
28955 -       r->id.idiag_dst[0] = inet->daddr;
28956 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
28957 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28958  
28959  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28960         if (r->idiag_family == AF_INET6) {
28961 @@ -186,8 +186,8 @@ static int inet_twsk_diag_fill(struct in
28962         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
28963         r->id.idiag_sport     = tw->tw_sport;
28964         r->id.idiag_dport     = tw->tw_dport;
28965 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
28966 -       r->id.idiag_dst[0]    = tw->tw_daddr;
28967 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
28968 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
28969         r->idiag_state        = tw->tw_substate;
28970         r->idiag_timer        = 3;
28971         r->idiag_expires      = (tmo * 1000 + HZ - 1) / HZ;
28972 @@ -239,6 +239,7 @@ static int inet_diag_get_exact(struct sk
28973         hashinfo = handler->idiag_hashinfo;
28974  
28975         if (req->idiag_family == AF_INET) {
28976 +               /* TODO: lback */
28977                 sk = inet_lookup(hashinfo, req->id.idiag_dst[0],
28978                                  req->id.idiag_dport, req->id.idiag_src[0],
28979                                  req->id.idiag_sport, req->id.idiag_if);
28980 @@ -478,6 +479,7 @@ static int inet_csk_diag_dump(struct soc
28981                 } else
28982  #endif
28983                 {
28984 +                       /* TODO: lback */
28985                         entry.saddr = &inet->rcv_saddr;
28986                         entry.daddr = &inet->daddr;
28987                 }
28988 @@ -514,6 +516,7 @@ static int inet_twsk_diag_dump(struct in
28989                 } else
28990  #endif
28991                 {
28992 +                       /* TODO: lback */
28993                         entry.saddr = &tw->tw_rcv_saddr;
28994                         entry.daddr = &tw->tw_daddr;
28995                 }
28996 @@ -560,8 +563,8 @@ static int inet_diag_fill_req(struct sk_
28997  
28998         r->id.idiag_sport = inet->sport;
28999         r->id.idiag_dport = ireq->rmt_port;
29000 -       r->id.idiag_src[0] = ireq->loc_addr;
29001 -       r->id.idiag_dst[0] = ireq->rmt_addr;
29002 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
29003 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
29004         r->idiag_expires = jiffies_to_msecs(tmo);
29005         r->idiag_rqueue = 0;
29006         r->idiag_wqueue = 0;
29007 @@ -631,6 +634,7 @@ static int inet_diag_dump_reqs(struct sk
29008                                 continue;
29009  
29010                         if (bc) {
29011 +                               /* TODO: lback */
29012                                 entry.saddr =
29013  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
29014                                         (entry.family == AF_INET6) ?
29015 @@ -697,6 +701,8 @@ static int inet_diag_dump(struct sk_buff
29016                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
29017                                 struct inet_sock *inet = inet_sk(sk);
29018  
29019 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29020 +                                       continue;
29021                                 if (num < s_num) {
29022                                         num++;
29023                                         continue;
29024 @@ -757,6 +763,8 @@ skip_listen_ht:
29025                 sk_for_each(sk, node, &head->chain) {
29026                         struct inet_sock *inet = inet_sk(sk);
29027  
29028 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29029 +                               continue;
29030                         if (num < s_num)
29031                                 goto next_normal;
29032                         if (!(r->idiag_states & (1 << sk->sk_state)))
29033 @@ -781,6 +789,8 @@ next_normal:
29034                         inet_twsk_for_each(tw, node,
29035                                     &head->twchain) {
29036  
29037 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
29038 +                                       continue;
29039                                 if (num < s_num)
29040                                         goto next_dying;
29041                                 if (r->id.idiag_sport != tw->tw_sport &&
29042 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/inet_hashtables.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_hashtables.c
29043 --- linux-2.6.22.10/net/ipv4/inet_hashtables.c  2007-05-02 19:25:40 +0200
29044 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_hashtables.c       2007-08-05 20:53:13 +0200
29045 @@ -140,11 +140,10 @@ static struct sock *inet_lookup_listener
29046                         const __be32 rcv_saddr = inet->rcv_saddr;
29047                         int score = sk->sk_family == PF_INET ? 1 : 0;
29048  
29049 -                       if (rcv_saddr) {
29050 -                               if (rcv_saddr != daddr)
29051 -                                       continue;
29052 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
29053                                 score += 2;
29054 -                       }
29055 +                       else
29056 +                               continue;
29057                         if (sk->sk_bound_dev_if) {
29058                                 if (sk->sk_bound_dev_if != dif)
29059                                         continue;
29060 @@ -175,7 +174,7 @@ struct sock *__inet_lookup_listener(stru
29061                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
29062  
29063                 if (inet->num == hnum && !sk->sk_node.next &&
29064 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
29065 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
29066                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
29067                     !sk->sk_bound_dev_if)
29068                         goto sherry_cache;
29069 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/raw.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/raw.c
29070 --- linux-2.6.22.10/net/ipv4/raw.c      2007-07-09 13:20:06 +0200
29071 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/raw.c   2007-10-05 12:29:05 +0200
29072 @@ -112,7 +112,7 @@ struct sock *__raw_v4_lookup(struct sock
29073  
29074                 if (inet->num == num                                    &&
29075                     !(inet->daddr && inet->daddr != raddr)              &&
29076 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
29077 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
29078                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
29079                         goto found; /* gotcha */
29080         }
29081 @@ -314,6 +314,12 @@ static int raw_send_hdrinc(struct sock *
29082                 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
29083         }
29084  
29085 +       err = -EPERM;
29086 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
29087 +               sk->sk_nx_info &&
29088 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
29089 +               goto error_free;
29090 +
29091         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
29092                       dst_output);
29093         if (err > 0)
29094 @@ -325,6 +331,7 @@ out:
29095  
29096  error_fault:
29097         err = -EFAULT;
29098 +error_free:
29099         kfree_skb(skb);
29100  error:
29101         IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
29102 @@ -491,6 +498,12 @@ static int raw_sendmsg(struct kiocb *ioc
29103                 }
29104  
29105                 security_sk_classify_flow(sk, &fl);
29106 +               if (sk->sk_nx_info) {
29107 +                       err = ip_v4_find_src(sk->sk_nx_info, &rt, &fl);
29108 +
29109 +                       if (err)
29110 +                               goto done;
29111 +               }
29112                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29113         }
29114         if (err)
29115 @@ -553,17 +566,19 @@ static int raw_bind(struct sock *sk, str
29116  {
29117         struct inet_sock *inet = inet_sk(sk);
29118         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
29119 +       struct nx_v4_sock_addr nsa = { 0 };
29120         int ret = -EINVAL;
29121         int chk_addr_ret;
29122  
29123         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
29124                 goto out;
29125 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
29126 +       v4_map_sock_addr(inet, addr, &nsa);
29127 +       chk_addr_ret = inet_addr_type(nsa.saddr);
29128         ret = -EADDRNOTAVAIL;
29129 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
29130 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
29131             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
29132                 goto out;
29133 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
29134 +       v4_set_sock_addr(inet, &nsa);
29135         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
29136                 inet->saddr = 0;  /* Use device */
29137         sk_dst_reset(sk);
29138 @@ -615,7 +630,8 @@ static int raw_recvmsg(struct kiocb *ioc
29139         /* Copy the address. */
29140         if (sin) {
29141                 sin->sin_family = AF_INET;
29142 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29143 +               sin->sin_addr.s_addr =
29144 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
29145                 sin->sin_port = 0;
29146                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
29147         }
29148 @@ -795,7 +811,8 @@ static struct sock *raw_get_first(struct
29149                 struct hlist_node *node;
29150  
29151                 sk_for_each(sk, node, &raw_v4_htable[state->bucket])
29152 -                       if (sk->sk_family == PF_INET)
29153 +                       if (sk->sk_family == PF_INET &&
29154 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29155                                 goto found;
29156         }
29157         sk = NULL;
29158 @@ -811,7 +828,8 @@ static struct sock *raw_get_next(struct 
29159                 sk = sk_next(sk);
29160  try_again:
29161                 ;
29162 -       } while (sk && sk->sk_family != PF_INET);
29163 +       } while (sk && (sk->sk_family != PF_INET ||
29164 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29165  
29166         if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
29167                 sk = sk_head(&raw_v4_htable[state->bucket]);
29168 @@ -863,7 +881,10 @@ static __inline__ char *get_raw_sock(str
29169  
29170         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29171                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29172 -               i, src, srcp, dest, destp, sp->sk_state,
29173 +               i,
29174 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29175 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29176 +               sp->sk_state,
29177                 atomic_read(&sp->sk_wmem_alloc),
29178                 atomic_read(&sp->sk_rmem_alloc),
29179                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29180 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/tcp.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp.c
29181 --- linux-2.6.22.10/net/ipv4/tcp.c      2007-10-30 01:57:15 +0100
29182 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp.c   2007-09-05 03:06:12 +0200
29183 @@ -258,6 +258,7 @@
29184  #include <linux/cache.h>
29185  #include <linux/err.h>
29186  #include <linux/crypto.h>
29187 +#include <linux/in.h>
29188  
29189  #include <net/icmp.h>
29190  #include <net/tcp.h>
29191 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/tcp_ipv4.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp_ipv4.c
29192 --- linux-2.6.22.10/net/ipv4/tcp_ipv4.c 2007-10-30 01:57:15 +0100
29193 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp_ipv4.c      2007-09-05 03:06:12 +0200
29194 @@ -1975,6 +1975,12 @@ static void *listening_get_next(struct s
29195                 req = req->dl_next;
29196                 while (1) {
29197                         while (req) {
29198 +                               vxdprintk(VXD_CBIT(net, 6),
29199 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
29200 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
29201 +                               if (req->sk &&
29202 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
29203 +                                       continue;
29204                                 if (req->rsk_ops->family == st->family) {
29205                                         cur = req;
29206                                         goto out;
29207 @@ -1999,6 +2005,10 @@ get_req:
29208         }
29209  get_sk:
29210         sk_for_each_from(sk, node) {
29211 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
29212 +                       sk, sk->sk_nid, nx_current_nid());
29213 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29214 +                       continue;
29215                 if (sk->sk_family == st->family) {
29216                         cur = sk;
29217                         goto out;
29218 @@ -2050,18 +2060,26 @@ static void *established_get_first(struc
29219  
29220                 read_lock(&tcp_hashinfo.ehash[st->bucket].lock);
29221                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
29222 -                       if (sk->sk_family != st->family) {
29223 +                       vxdprintk(VXD_CBIT(net, 6),
29224 +                               "sk,egf: %p [#%d] (from %d)",
29225 +                               sk, sk->sk_nid, nx_current_nid());
29226 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29227 +                               continue;
29228 +                       if (sk->sk_family != st->family)
29229                                 continue;
29230 -                       }
29231                         rc = sk;
29232                         goto out;
29233                 }
29234                 st->state = TCP_SEQ_STATE_TIME_WAIT;
29235                 inet_twsk_for_each(tw, node,
29236                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
29237 -                       if (tw->tw_family != st->family) {
29238 +                       vxdprintk(VXD_CBIT(net, 6),
29239 +                               "tw: %p [#%d] (from %d)",
29240 +                               tw, tw->tw_nid, nx_current_nid());
29241 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
29242 +                               continue;
29243 +                       if (tw->tw_family != st->family)
29244                                 continue;
29245 -                       }
29246                         rc = tw;
29247                         goto out;
29248                 }
29249 @@ -2085,7 +2103,8 @@ static void *established_get_next(struct
29250                 tw = cur;
29251                 tw = tw_next(tw);
29252  get_tw:
29253 -               while (tw && tw->tw_family != st->family) {
29254 +               while (tw && (tw->tw_family != st->family ||
29255 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
29256                         tw = tw_next(tw);
29257                 }
29258                 if (tw) {
29259 @@ -2109,6 +2128,11 @@ get_tw:
29260                 sk = sk_next(sk);
29261  
29262         sk_for_each_from(sk, node) {
29263 +               vxdprintk(VXD_CBIT(net, 6),
29264 +                       "sk,egn: %p [#%d] (from %d)",
29265 +                       sk, sk->sk_nid, nx_current_nid());
29266 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29267 +                       continue;
29268                 if (sk->sk_family == st->family)
29269                         goto found;
29270         }
29271 @@ -2284,9 +2308,9 @@ static void get_openreq4(struct sock *sk
29272         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29273                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p",
29274                 i,
29275 -               ireq->loc_addr,
29276 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
29277                 ntohs(inet_sk(sk)->sport),
29278 -               ireq->rmt_addr,
29279 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
29280                 ntohs(ireq->rmt_port),
29281                 TCP_SYN_RECV,
29282                 0, 0, /* could print option size, but that is af dependent. */
29283 @@ -2328,7 +2352,10 @@ static void get_tcp4_sock(struct sock *s
29284  
29285         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
29286                         "%08X %5d %8d %lu %d %p %u %u %u %u %d",
29287 -               i, src, srcp, dest, destp, sk->sk_state,
29288 +               i,
29289 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29290 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29291 +               sk->sk_state,
29292                 tp->write_seq - tp->snd_una,
29293                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
29294                                              (tp->rcv_nxt - tp->copied_seq),
29295 @@ -2363,7 +2390,10 @@ static void get_timewait4_sock(struct in
29296  
29297         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29298                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p",
29299 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
29300 +               i,
29301 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29302 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29303 +               tw->tw_substate, 0, 0,
29304                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
29305                 atomic_read(&tw->tw_refcnt), tw);
29306  }
29307 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/tcp_minisocks.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp_minisocks.c
29308 --- linux-2.6.22.10/net/ipv4/tcp_minisocks.c    2007-07-09 13:20:06 +0200
29309 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp_minisocks.c 2007-08-05 20:53:13 +0200
29310 @@ -28,6 +28,10 @@
29311  #include <net/inet_common.h>
29312  #include <net/xfrm.h>
29313  
29314 +#include <linux/vs_limit.h>
29315 +#include <linux/vs_socket.h>
29316 +#include <linux/vs_context.h>
29317 +
29318  #ifdef CONFIG_SYSCTL
29319  #define SYNC_INIT 0 /* let the user enable it */
29320  #else
29321 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
29322                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
29323                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
29324  
29325 +               tw->tw_xid              = sk->sk_xid;
29326 +               tw->tw_vx_info          = NULL;
29327 +               tw->tw_nid              = sk->sk_nid;
29328 +               tw->tw_nx_info          = NULL;
29329 +
29330  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
29331                 if (tw->tw_family == PF_INET6) {
29332                         struct ipv6_pinfo *np = inet6_sk(sk);
29333 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/udp.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/udp.c
29334 --- linux-2.6.22.10/net/ipv4/udp.c      2007-07-09 13:20:06 +0200
29335 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/udp.c   2007-10-09 14:09:19 +0200
29336 @@ -219,14 +219,7 @@ int udp_get_port(struct sock *sk, unsign
29337         return  __udp_lib_get_port(sk, snum, udp_hash, &udp_port_rover, scmp);
29338  }
29339  
29340 -int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
29341 -{
29342 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
29343 -
29344 -       return  ( !ipv6_only_sock(sk2)  &&
29345 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
29346 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
29347 -}
29348 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29349  
29350  static inline int udp_v4_get_port(struct sock *sk, unsigned short snum)
29351  {
29352 @@ -246,15 +239,22 @@ static struct sock *__udp4_lib_lookup(__
29353         int badness = -1;
29354  
29355         read_lock(&udp_hash_lock);
29356 +
29357         sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
29358                 struct inet_sock *inet = inet_sk(sk);
29359  
29360                 if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
29361                         int score = (sk->sk_family == PF_INET ? 1 : 0);
29362 +
29363                         if (inet->rcv_saddr) {
29364                                 if (inet->rcv_saddr != daddr)
29365                                         continue;
29366                                 score+=2;
29367 +                       } else {
29368 +                               /* block non nx_info ips */
29369 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
29370 +                                       daddr, NXA_MASK_BIND))
29371 +                                       continue;
29372                         }
29373                         if (inet->daddr) {
29374                                 if (inet->daddr != saddr)
29375 @@ -280,6 +280,7 @@ static struct sock *__udp4_lib_lookup(__
29376                         }
29377                 }
29378         }
29379 +
29380         if (result)
29381                 sock_hold(result);
29382         read_unlock(&udp_hash_lock);
29383 @@ -301,7 +302,7 @@ static inline struct sock *udp_v4_mcast_
29384                 if (s->sk_hash != hnum                                  ||
29385                     (inet->daddr && inet->daddr != rmt_addr)            ||
29386                     (inet->dport != rmt_port && inet->dport)            ||
29387 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
29388 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
29389                     ipv6_only_sock(s)                                   ||
29390                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
29391                         continue;
29392 @@ -631,7 +632,14 @@ int udp_sendmsg(struct kiocb *iocb, stru
29393                                     .uli_u = { .ports =
29394                                                { .sport = inet->sport,
29395                                                  .dport = dport } } };
29396 +               struct nx_info *nxi = sk->sk_nx_info;
29397 +
29398                 security_sk_classify_flow(sk, &fl);
29399 +
29400 +               err = ip_v4_find_src(nxi, &rt, &fl);
29401 +               if (err)
29402 +                       goto out;
29403 +
29404                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29405                 if (err) {
29406                         if (err == -ENETUNREACH)
29407 @@ -871,7 +879,8 @@ try_again:
29408         {
29409                 sin->sin_family = AF_INET;
29410                 sin->sin_port = udp_hdr(skb)->source;
29411 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29412 +               sin->sin_addr.s_addr = nx_map_sock_lback(
29413 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
29414                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
29415         }
29416         if (inet->cmsg_flags)
29417 @@ -1551,7 +1560,8 @@ static struct sock *udp_get_first(struct
29418         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
29419                 struct hlist_node *node;
29420                 sk_for_each(sk, node, state->hashtable + state->bucket) {
29421 -                       if (sk->sk_family == state->family)
29422 +                       if (sk->sk_family == state->family &&
29423 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29424                                 goto found;
29425                 }
29426         }
29427 @@ -1568,7 +1578,8 @@ static struct sock *udp_get_next(struct 
29428                 sk = sk_next(sk);
29429  try_again:
29430                 ;
29431 -       } while (sk && sk->sk_family != state->family);
29432 +       } while (sk && (sk->sk_family != state->family ||
29433 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29434  
29435         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
29436                 sk = sk_head(state->hashtable + state->bucket);
29437 @@ -1681,7 +1692,10 @@ static void udp4_format_sock(struct sock
29438  
29439         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29440                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29441 -               bucket, src, srcp, dest, destp, sp->sk_state,
29442 +               bucket,
29443 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29444 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29445 +               sp->sk_state,
29446                 atomic_read(&sp->sk_wmem_alloc),
29447                 atomic_read(&sp->sk_rmem_alloc),
29448                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29449 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/Kconfig linux-2.6.22.10-vs2.3.0.29/net/ipv6/Kconfig
29450 --- linux-2.6.22.10/net/ipv6/Kconfig    2007-07-09 13:20:06 +0200
29451 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/Kconfig 2007-08-05 20:53:13 +0200
29452 @@ -4,8 +4,8 @@
29453  
29454  #   IPv6 as module will cause a CRASH if you try to unload it
29455  config IPV6
29456 -       tristate "The IPv6 protocol"
29457 -       default m
29458 +       bool "The IPv6 protocol"
29459 +       default n
29460         ---help---
29461           This is complemental support for the IP version 6.
29462           You will still be able to do traditional IPv4 networking as well.
29463 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/addrconf.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/addrconf.c
29464 --- linux-2.6.22.10/net/ipv6/addrconf.c 2007-10-30 01:57:15 +0100
29465 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/addrconf.c      2007-10-05 14:54:36 +0200
29466 @@ -85,6 +85,7 @@
29467  
29468  #include <linux/proc_fs.h>
29469  #include <linux/seq_file.h>
29470 +#include <linux/vs_inet6.h>
29471  
29472  /* Set to 3 to get tracing... */
29473  #define ACONF_DEBUG 2
29474 @@ -897,7 +898,8 @@ static inline int ipv6_saddr_label(const
29475  }
29476  
29477  int ipv6_dev_get_saddr(struct net_device *daddr_dev,
29478 -                      struct in6_addr *daddr, struct in6_addr *saddr)
29479 +                      struct in6_addr *daddr, struct in6_addr *saddr,
29480 +                      struct nx_info *nxi)
29481  {
29482         struct ipv6_saddr_score hiscore;
29483         struct inet6_ifaddr *ifa_result = NULL;
29484 @@ -942,6 +944,10 @@ int ipv6_dev_get_saddr(struct net_device
29485  
29486                         score.addr_type = __ipv6_addr_type(&ifa->addr);
29487  
29488 +                       /* Use only addresses assigned to the context */
29489 +                       if (!v6_ifa_in_nx_info(ifa, nxi))
29490 +                               continue;
29491 +
29492                         /* Rule 0:
29493                          * - Tentative Address (RFC2462 section 5.4)
29494                          *  - A tentative address is not considered
29495 @@ -1155,9 +1161,10 @@ record_it:
29496  
29497  
29498  int ipv6_get_saddr(struct dst_entry *dst,
29499 -                  struct in6_addr *daddr, struct in6_addr *saddr)
29500 +                  struct in6_addr *daddr, struct in6_addr *saddr,
29501 +                  struct nx_info *nxi)
29502  {
29503 -       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
29504 +       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr, nxi);
29505  }
29506  
29507  EXPORT_SYMBOL(ipv6_get_saddr);
29508 @@ -1253,35 +1260,46 @@ struct inet6_ifaddr * ipv6_get_ifaddr(st
29509         return ifp;
29510  }
29511  
29512 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29513 +
29514  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
29515  {
29516         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
29517         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
29518 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
29519         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
29520         int sk_ipv6only = ipv6_only_sock(sk);
29521         int sk2_ipv6only = inet_v6_ipv6only(sk2);
29522         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
29523         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
29524  
29525 -       if (!sk2_rcv_saddr && !sk_ipv6only)
29526 +       /* FIXME: needs handling for v4 ANY */
29527 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
29528                 return 1;
29529  
29530         if (addr_type2 == IPV6_ADDR_ANY &&
29531 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
29532 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
29533 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
29534                 return 1;
29535  
29536         if (addr_type == IPV6_ADDR_ANY &&
29537 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
29538 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
29539 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
29540 +               return 1;
29541 +
29542 +       if (addr_type == IPV6_ADDR_ANY &&
29543 +           addr_type2 == IPV6_ADDR_ANY &&
29544 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
29545                 return 1;
29546  
29547         if (sk2_rcv_saddr6 &&
29548 +           addr_type != IPV6_ADDR_ANY &&
29549 +           addr_type != IPV6_ADDR_ANY &&
29550             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
29551                 return 1;
29552  
29553         if (addr_type == IPV6_ADDR_MAPPED &&
29554             !sk2_ipv6only &&
29555 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
29556 +           ipv4_rcv_saddr_equal(sk, sk2))
29557                 return 1;
29558  
29559         return 0;
29560 @@ -2772,7 +2790,10 @@ static void if6_seq_stop(struct seq_file
29561  static int if6_seq_show(struct seq_file *seq, void *v)
29562  {
29563         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
29564 -       seq_printf(seq,
29565 +
29566 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
29567 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
29568 +               seq_printf(seq,
29569                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
29570                    NIP6(ifp->addr),
29571                    ifp->idev->dev->ifindex,
29572 @@ -3254,6 +3275,11 @@ static int inet6_dump_addr(struct sk_buf
29573         struct inet6_ifaddr *ifa;
29574         struct ifmcaddr6 *ifmca;
29575         struct ifacaddr6 *ifaca;
29576 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29577 +
29578 +       /* disable ipv6 on non v6 guests */
29579 +       if (nxi && !nx_info_has_v6(nxi))
29580 +               return skb->len;
29581  
29582         s_idx = cb->args[0];
29583         s_ip_idx = ip_idx = cb->args[1];
29584 @@ -3275,6 +3301,8 @@ static int inet6_dump_addr(struct sk_buf
29585                              ifa = ifa->if_next, ip_idx++) {
29586                                 if (ip_idx < s_ip_idx)
29587                                         continue;
29588 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
29589 +                                       continue;
29590                                 if ((err = inet6_fill_ifaddr(skb, ifa,
29591                                     NETLINK_CB(cb->skb).pid,
29592                                     cb->nlh->nlmsg_seq, RTM_NEWADDR,
29593 @@ -3288,6 +3316,8 @@ static int inet6_dump_addr(struct sk_buf
29594                              ifmca = ifmca->next, ip_idx++) {
29595                                 if (ip_idx < s_ip_idx)
29596                                         continue;
29597 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
29598 +                                       continue;
29599                                 if ((err = inet6_fill_ifmcaddr(skb, ifmca,
29600                                     NETLINK_CB(cb->skb).pid,
29601                                     cb->nlh->nlmsg_seq, RTM_GETMULTICAST,
29602 @@ -3301,6 +3331,8 @@ static int inet6_dump_addr(struct sk_buf
29603                              ifaca = ifaca->aca_next, ip_idx++) {
29604                                 if (ip_idx < s_ip_idx)
29605                                         continue;
29606 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
29607 +                                       continue;
29608                                 if ((err = inet6_fill_ifacaddr(skb, ifaca,
29609                                     NETLINK_CB(cb->skb).pid,
29610                                     cb->nlh->nlmsg_seq, RTM_GETANYCAST,
29611 @@ -3577,12 +3609,19 @@ static int inet6_dump_ifinfo(struct sk_b
29612         int s_idx = cb->args[0];
29613         struct net_device *dev;
29614         struct inet6_dev *idev;
29615 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29616 +
29617 +       /* FIXME: maybe disable ipv6 on non v6 guests?
29618 +       if (skb->sk && skb->sk->sk_vx_info)
29619 +               return skb->len;        */
29620  
29621         read_lock(&dev_base_lock);
29622         idx = 0;
29623         for_each_netdev(dev) {
29624                 if (idx < s_idx)
29625                         goto cont;
29626 +               if (!v6_dev_in_nx_info(dev, nxi))
29627 +                       goto cont;
29628                 if ((idev = in6_dev_get(dev)) == NULL)
29629                         goto cont;
29630                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
29631 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/af_inet6.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/af_inet6.c
29632 --- linux-2.6.22.10/net/ipv6/af_inet6.c 2007-10-30 01:57:15 +0100
29633 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/af_inet6.c      2007-10-05 12:29:05 +0200
29634 @@ -43,6 +43,7 @@
29635  #include <linux/netdevice.h>
29636  #include <linux/icmpv6.h>
29637  #include <linux/netfilter_ipv6.h>
29638 +#include <linux/vs_inet6.h>
29639  
29640  #include <net/ip.h>
29641  #include <net/ipv6.h>
29642 @@ -150,9 +151,12 @@ lookup_protocol:
29643         }
29644  
29645         err = -EPERM;
29646 +       if ((protocol == IPPROTO_ICMPV6) &&
29647 +               nx_capable(answer->capability, NXC_RAW_ICMP))
29648 +               goto override;
29649         if (answer->capability > 0 && !capable(answer->capability))
29650                 goto out_rcu_unlock;
29651 -
29652 +override:
29653         sock->ops = answer->ops;
29654         answer_prot = answer->prot;
29655         answer_no_check = answer->no_check;
29656 @@ -250,6 +254,7 @@ int inet6_bind(struct socket *sock, stru
29657         struct sock *sk = sock->sk;
29658         struct inet_sock *inet = inet_sk(sk);
29659         struct ipv6_pinfo *np = inet6_sk(sk);
29660 +       struct nx_v6_sock_addr nsa;
29661         __be32 v4addr = 0;
29662         unsigned short snum;
29663         int addr_type = 0;
29664 @@ -261,6 +266,11 @@ int inet6_bind(struct socket *sock, stru
29665  
29666         if (addr_len < SIN6_LEN_RFC2133)
29667                 return -EINVAL;
29668 +
29669 +       err = v6_map_sock_addr(inet, addr, &nsa);
29670 +       if (err)
29671 +               return err;
29672 +
29673         addr_type = ipv6_addr_type(&addr->sin6_addr);
29674         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
29675                 return -EINVAL;
29676 @@ -284,6 +294,10 @@ int inet6_bind(struct socket *sock, stru
29677                         err = -EADDRNOTAVAIL;
29678                         goto out;
29679                 }
29680 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
29681 +                       err = -EADDRNOTAVAIL;
29682 +                       goto out;
29683 +               }
29684         } else {
29685                 if (addr_type != IPV6_ADDR_ANY) {
29686                         struct net_device *dev = NULL;
29687 @@ -309,6 +323,11 @@ int inet6_bind(struct socket *sock, stru
29688                                 }
29689                         }
29690  
29691 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
29692 +                               err = -EADDRNOTAVAIL;
29693 +                               goto out;
29694 +                       }
29695 +
29696                         /* ipv4 addr of the socket is invalid.  Only the
29697                          * unspecified and mapped address have a v4 equivalent.
29698                          */
29699 @@ -326,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
29700                 }
29701         }
29702  
29703 +       v6_set_sock_addr(inet, &nsa);
29704 +
29705         inet->rcv_saddr = v4addr;
29706         inet->saddr = v4addr;
29707  
29708 @@ -420,9 +441,11 @@ int inet6_getname(struct socket *sock, s
29709                         return -ENOTCONN;
29710                 sin->sin6_port = inet->dport;
29711                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
29712 +               /* FIXME: remap lback? */
29713                 if (np->sndflow)
29714                         sin->sin6_flowinfo = np->flow_label;
29715         } else {
29716 +               /* FIXME: remap lback? */
29717                 if (ipv6_addr_any(&np->rcv_saddr))
29718                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
29719                 else
29720 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/fib6_rules.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/fib6_rules.c
29721 --- linux-2.6.22.10/net/ipv6/fib6_rules.c       2007-07-09 13:20:06 +0200
29722 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/fib6_rules.c    2007-08-12 00:22:19 +0200
29723 @@ -107,7 +107,7 @@ static int fib6_rule_action(struct fib_r
29724                     r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
29725                         struct in6_addr saddr;
29726                         if (ipv6_get_saddr(&rt->u.dst, &flp->fl6_dst,
29727 -                                          &saddr))
29728 +                                          &saddr, NULL))
29729                                 goto again;
29730                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
29731                                                r->src.plen))
29732 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/inet6_hashtables.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/inet6_hashtables.c
29733 --- linux-2.6.22.10/net/ipv6/inet6_hashtables.c 2007-05-02 19:25:45 +0200
29734 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/inet6_hashtables.c      2007-08-05 20:53:13 +0200
29735 @@ -16,6 +16,7 @@
29736  
29737  #include <linux/module.h>
29738  #include <linux/random.h>
29739 +#include <linux/vs_inet6.h>
29740  
29741  #include <net/inet_connection_sock.h>
29742  #include <net/inet_hashtables.h>
29743 @@ -121,6 +122,9 @@ struct sock *inet6_lookup_listener(struc
29744                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29745                                         continue;
29746                                 score++;
29747 +                       } else {
29748 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29749 +                                       continue;
29750                         }
29751                         if (sk->sk_bound_dev_if) {
29752                                 if (sk->sk_bound_dev_if != dif)
29753 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/ip6_output.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/ip6_output.c
29754 --- linux-2.6.22.10/net/ipv6/ip6_output.c       2007-10-30 01:57:15 +0100
29755 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/ip6_output.c    2007-09-30 14:58:01 +0200
29756 @@ -884,7 +884,7 @@ static int ip6_dst_lookup_tail(struct so
29757                 goto out_err_release;
29758  
29759         if (ipv6_addr_any(&fl->fl6_src)) {
29760 -               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src);
29761 +               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src, sk->sk_nx_info);
29762                 if (err)
29763                         goto out_err_release;
29764         }
29765 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/ndisc.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/ndisc.c
29766 --- linux-2.6.22.10/net/ipv6/ndisc.c    2007-10-30 01:57:15 +0100
29767 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/ndisc.c 2007-09-30 14:58:01 +0200
29768 @@ -531,7 +531,7 @@ static void ndisc_send_na(struct net_dev
29769                         override = 0;
29770                 in6_ifa_put(ifp);
29771         } else {
29772 -               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr))
29773 +               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr, NULL))
29774                         return;
29775                 src_addr = &tmpaddr;
29776         }
29777 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/route.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/route.c
29778 --- linux-2.6.22.10/net/ipv6/route.c    2007-07-09 13:20:06 +0200
29779 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/route.c 2007-08-12 00:22:19 +0200
29780 @@ -2182,7 +2182,7 @@ static int rt6_fill_node(struct sk_buff 
29781                 NLA_PUT_U32(skb, RTA_IIF, iif);
29782         else if (dst) {
29783                 struct in6_addr saddr_buf;
29784 -               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0)
29785 +               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf, (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
29786                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
29787         }
29788  
29789 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/tcp_ipv6.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/tcp_ipv6.c
29790 --- linux-2.6.22.10/net/ipv6/tcp_ipv6.c 2007-10-30 01:57:15 +0100
29791 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/tcp_ipv6.c      2007-09-18 12:32:20 +0200
29792 @@ -68,6 +68,7 @@
29793  
29794  #include <linux/crypto.h>
29795  #include <linux/scatterlist.h>
29796 +#include <linux/vs_inet6.h>
29797  
29798  /* Socket used for sending RSTs and ACKs */
29799  static struct socket *tcp6_socket;
29800 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
29801          *      connect() to INADDR_ANY means loopback (BSD'ism).
29802          */
29803  
29804 -       if(ipv6_addr_any(&usin->sin6_addr))
29805 -               usin->sin6_addr.s6_addr[15] = 0x1;
29806 +       if(ipv6_addr_any(&usin->sin6_addr)) {
29807 +               struct nx_info *nxi =  sk->sk_nx_info;
29808 +
29809 +               if (nxi && nx_info_has_v6(nxi))
29810 +                       /* FIXME: remap lback? */
29811 +                       usin->sin6_addr = nxi->v6.ip;
29812 +               else
29813 +                       usin->sin6_addr.s6_addr[15] = 0x1;
29814 +       }
29815  
29816         addr_type = ipv6_addr_type(&usin->sin6_addr);
29817  
29818 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/udp.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/udp.c
29819 --- linux-2.6.22.10/net/ipv6/udp.c      2007-07-09 13:20:06 +0200
29820 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/udp.c   2007-08-12 03:34:32 +0200
29821 @@ -48,6 +48,7 @@
29822  
29823  #include <linux/proc_fs.h>
29824  #include <linux/seq_file.h>
29825 +#include <linux/vs_inet6.h>
29826  #include "udp_impl.h"
29827  
29828  DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
29829 @@ -82,6 +83,10 @@ static struct sock *__udp6_lib_lookup(st
29830                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29831                                         continue;
29832                                 score++;
29833 +                       } else {
29834 +                               /* block non nx_info ips */
29835 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29836 +                                       continue;
29837                         }
29838                         if (!ipv6_addr_any(&np->daddr)) {
29839                                 if (!ipv6_addr_equal(&np->daddr, saddr))
29840 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/xfrm6_policy.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/xfrm6_policy.c
29841 --- linux-2.6.22.10/net/ipv6/xfrm6_policy.c     2007-07-09 13:20:06 +0200
29842 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/xfrm6_policy.c  2007-08-12 00:22:19 +0200
29843 @@ -49,7 +49,7 @@ static int xfrm6_get_saddr(xfrm_address_
29844  
29845         if (!xfrm6_dst_lookup((struct xfrm_dst **)&rt, &fl_tunnel)) {
29846                 ipv6_get_saddr(&rt->u.dst, (struct in6_addr *)&daddr->a6,
29847 -                              (struct in6_addr *)&saddr->a6);
29848 +                              (struct in6_addr *)&saddr->a6, NULL);
29849                 dst_release(&rt->u.dst);
29850                 return 0;
29851         }
29852 diff -NurpP --minimal linux-2.6.22.10/net/netlink/af_netlink.c linux-2.6.22.10-vs2.3.0.29/net/netlink/af_netlink.c
29853 --- linux-2.6.22.10/net/netlink/af_netlink.c    2007-07-09 13:20:07 +0200
29854 +++ linux-2.6.22.10-vs2.3.0.29/net/netlink/af_netlink.c 2007-08-05 20:53:13 +0200
29855 @@ -56,6 +56,9 @@
29856  #include <linux/audit.h>
29857  #include <linux/selinux.h>
29858  #include <linux/mutex.h>
29859 +#include <linux/vs_context.h>
29860 +#include <linux/vs_network.h>
29861 +#include <linux/vs_limit.h>
29862  
29863  #include <net/sock.h>
29864  #include <net/scm.h>
29865 @@ -885,6 +888,10 @@ static inline int do_one_broadcast(struc
29866             !test_bit(p->group - 1, nlk->groups))
29867                 goto out;
29868  
29869 +       if (sk->sk_nx_info &&
29870 +           (p->group == RTNLGRP_IPV4_IFADDR || p->group == RTNLGRP_IPV6_IFADDR))
29871 +               goto out;
29872 +
29873         if (p->failure) {
29874                 netlink_overrun(sk);
29875                 goto out;
29876 diff -NurpP --minimal linux-2.6.22.16/net/rxrpc/Kconfig linux-2.6.22.16-vs2.3.0.32/net/rxrpc/Kconfig
29877 --- linux-2.6.22.16/net/rxrpc/Kconfig   2008-01-18 12:27:36 +0100
29878 +++ linux-2.6.22.16-vs2.3.0.32/net/rxrpc/Kconfig        2008-01-18 12:59:53 +0100
29879 @@ -4,6 +4,6 @@
29880  
29881  config AF_RXRPC
29882         tristate "RxRPC session sockets"
29883 -       depends on INET && EXPERIMENTAL
29884 +       depends on INET && EXPERIMENTAL && !VSERVER_SECURITY
29885         select KEYS
29886         help
29887 diff -NurpP --minimal linux-2.6.22.10/net/sctp/ipv6.c linux-2.6.22.10-vs2.3.0.29/net/sctp/ipv6.c
29888 --- linux-2.6.22.10/net/sctp/ipv6.c     2007-10-30 01:57:15 +0100
29889 +++ linux-2.6.22.10-vs2.3.0.29/net/sctp/ipv6.c  2007-08-12 00:22:19 +0200
29890 @@ -303,7 +303,7 @@ static void sctp_v6_get_saddr(struct sct
29891                           __FUNCTION__, asoc, dst, NIP6(daddr->v6.sin6_addr));
29892  
29893         if (!asoc) {
29894 -               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr);
29895 +               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr, asoc->base.sk->sk_nx_info);
29896                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
29897                                   NIP6(saddr->v6.sin6_addr));
29898                 return;
29899 diff -NurpP --minimal linux-2.6.22.10/net/socket.c linux-2.6.22.10-vs2.3.0.29/net/socket.c
29900 --- linux-2.6.22.10/net/socket.c        2007-10-30 01:57:15 +0100
29901 +++ linux-2.6.22.10-vs2.3.0.29/net/socket.c     2007-09-05 03:06:12 +0200
29902 @@ -92,6 +92,10 @@
29903  
29904  #include <net/sock.h>
29905  #include <linux/netfilter.h>
29906 +#include <linux/vs_base.h>
29907 +#include <linux/vs_socket.h>
29908 +#include <linux/vs_inet.h>
29909 +#include <linux/vs_inet6.h>
29910  
29911  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
29912  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
29913 @@ -543,7 +547,7 @@ static inline int __sock_sendmsg(struct 
29914                                  struct msghdr *msg, size_t size)
29915  {
29916         struct sock_iocb *si = kiocb_to_siocb(iocb);
29917 -       int err;
29918 +       int err, len;
29919  
29920         si->sock = sock;
29921         si->scm = NULL;
29922 @@ -554,7 +558,22 @@ static inline int __sock_sendmsg(struct 
29923         if (err)
29924                 return err;
29925  
29926 -       return sock->ops->sendmsg(iocb, sock, msg, size);
29927 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
29928 +       if (sock->sk) {
29929 +               if (len == size)
29930 +                       vx_sock_send(sock->sk, size);
29931 +               else
29932 +                       vx_sock_fail(sock->sk, size);
29933 +       }
29934 +       vxdprintk(VXD_CBIT(net, 7),
29935 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29936 +               sock, sock->sk,
29937 +               (sock->sk)?sock->sk->sk_nx_info:0,
29938 +               (sock->sk)?sock->sk->sk_vx_info:0,
29939 +               (sock->sk)?sock->sk->sk_xid:0,
29940 +               (sock->sk)?sock->sk->sk_nid:0,
29941 +               (unsigned int)size, len);
29942 +       return len;
29943  }
29944  
29945  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
29946 @@ -623,7 +642,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
29947  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
29948                                  struct msghdr *msg, size_t size, int flags)
29949  {
29950 -       int err;
29951 +       int err, len;
29952         struct sock_iocb *si = kiocb_to_siocb(iocb);
29953  
29954         si->sock = sock;
29955 @@ -636,7 +655,18 @@ static inline int __sock_recvmsg(struct 
29956         if (err)
29957                 return err;
29958  
29959 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
29960 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
29961 +       if ((len >= 0) && sock->sk)
29962 +               vx_sock_recv(sock->sk, len);
29963 +       vxdprintk(VXD_CBIT(net, 7),
29964 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29965 +               sock, sock->sk,
29966 +               (sock->sk)?sock->sk->sk_nx_info:0,
29967 +               (sock->sk)?sock->sk->sk_vx_info:0,
29968 +               (sock->sk)?sock->sk->sk_xid:0,
29969 +               (sock->sk)?sock->sk->sk_nid:0,
29970 +               (unsigned int)size, len);
29971 +       return len;
29972  }
29973  
29974  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
29975 @@ -1090,6 +1120,13 @@ static int __sock_create(int family, int
29976         if (type < 0 || type >= SOCK_MAX)
29977                 return -EINVAL;
29978  
29979 +       if (!nx_check(0, VS_ADMIN)) {
29980 +               if (family == PF_INET && !current_nx_info_has_v4())
29981 +                       return -EAFNOSUPPORT;
29982 +               if (family == PF_INET6 && !current_nx_info_has_v6())
29983 +                       return -EAFNOSUPPORT;
29984 +       }
29985 +
29986         /* Compatibility.
29987  
29988            This uglymoron is moved from INET layer to here to avoid
29989 @@ -1207,6 +1244,7 @@ asmlinkage long sys_socket(int family, i
29990         if (retval < 0)
29991                 goto out;
29992  
29993 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
29994         retval = sock_map_fd(sock);
29995         if (retval < 0)
29996                 goto out_release;
29997 @@ -1239,10 +1277,12 @@ asmlinkage long sys_socketpair(int famil
29998         err = sock_create(family, type, protocol, &sock1);
29999         if (err < 0)
30000                 goto out;
30001 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
30002  
30003         err = sock_create(family, type, protocol, &sock2);
30004         if (err < 0)
30005                 goto out_release_1;
30006 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
30007  
30008         err = sock1->ops->socketpair(sock1, sock2);
30009         if (err < 0)
30010 diff -NurpP --minimal linux-2.6.22.10/net/sunrpc/auth.c linux-2.6.22.10-vs2.3.0.29/net/sunrpc/auth.c
30011 --- linux-2.6.22.10/net/sunrpc/auth.c   2007-05-02 19:25:48 +0200
30012 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/auth.c        2007-08-05 20:53:13 +0200
30013 @@ -13,6 +13,7 @@
30014  #include <linux/errno.h>
30015  #include <linux/sunrpc/clnt.h>
30016  #include <linux/spinlock.h>
30017 +#include <linux/vs_tag.h>
30018  
30019  #ifdef RPC_DEBUG
30020  # define RPCDBG_FACILITY       RPCDBG_AUTH
30021 @@ -263,6 +264,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
30022         struct auth_cred acred = {
30023                 .uid = current->fsuid,
30024                 .gid = current->fsgid,
30025 +               .tag = dx_current_tag(),
30026                 .group_info = current->group_info,
30027         };
30028         struct rpc_cred *ret;
30029 @@ -282,6 +284,7 @@ rpcauth_bindcred(struct rpc_task *task)
30030         struct auth_cred acred = {
30031                 .uid = current->fsuid,
30032                 .gid = current->fsgid,
30033 +               .tag = dx_current_tag(),
30034                 .group_info = current->group_info,
30035         };
30036         struct rpc_cred *ret;
30037 diff -NurpP --minimal linux-2.6.22.10/net/sunrpc/auth_unix.c linux-2.6.22.10-vs2.3.0.29/net/sunrpc/auth_unix.c
30038 --- linux-2.6.22.10/net/sunrpc/auth_unix.c      2007-05-02 19:25:48 +0200
30039 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/auth_unix.c   2007-08-05 20:53:13 +0200
30040 @@ -11,12 +11,14 @@
30041  #include <linux/module.h>
30042  #include <linux/sunrpc/clnt.h>
30043  #include <linux/sunrpc/auth.h>
30044 +#include <linux/vs_tag.h>
30045  
30046  #define NFS_NGROUPS    16
30047  
30048  struct unx_cred {
30049         struct rpc_cred         uc_base;
30050         gid_t                   uc_gid;
30051 +       tag_t                   uc_tag;
30052         gid_t                   uc_gids[NFS_NGROUPS];
30053  };
30054  #define uc_uid                 uc_base.cr_uid
30055 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
30056         if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
30057                 cred->uc_uid = 0;
30058                 cred->uc_gid = 0;
30059 +               cred->uc_tag = dx_current_tag();
30060                 cred->uc_gids[0] = NOGROUP;
30061         } else {
30062                 int groups = acred->group_info->ngroups;
30063 @@ -87,6 +90,7 @@ unx_create_cred(struct rpc_auth *auth, s
30064  
30065                 cred->uc_uid = acred->uid;
30066                 cred->uc_gid = acred->gid;
30067 +               cred->uc_tag = acred->tag;
30068                 for (i = 0; i < groups; i++)
30069                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
30070                 if (i < NFS_NGROUPS)
30071 @@ -118,7 +122,8 @@ unx_match(struct auth_cred *acred, struc
30072                 int groups;
30073  
30074                 if (cred->uc_uid != acred->uid
30075 -                || cred->uc_gid != acred->gid)
30076 +                || cred->uc_gid != acred->gid
30077 +                || cred->uc_tag != acred->tag)
30078                         return 0;
30079  
30080                 groups = acred->group_info->ngroups;
30081 @@ -144,7 +149,7 @@ unx_marshal(struct rpc_task *task, __be3
30082         struct rpc_clnt *clnt = task->tk_client;
30083         struct unx_cred *cred = (struct unx_cred *) task->tk_msg.rpc_cred;
30084         __be32          *base, *hold;
30085 -       int             i;
30086 +       int             i, tag;
30087  
30088         *p++ = htonl(RPC_AUTH_UNIX);
30089         base = p++;
30090 @@ -154,9 +159,12 @@ unx_marshal(struct rpc_task *task, __be3
30091          * Copy the UTS nodename captured when the client was created.
30092          */
30093         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
30094 +       tag = task->tk_client->cl_tag;
30095  
30096 -       *p++ = htonl((u32) cred->uc_uid);
30097 -       *p++ = htonl((u32) cred->uc_gid);
30098 +       *p++ = htonl((u32) TAGINO_UID(tag,
30099 +               cred->uc_uid, cred->uc_tag));
30100 +       *p++ = htonl((u32) TAGINO_GID(tag,
30101 +               cred->uc_gid, cred->uc_tag));
30102         hold = p++;
30103         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
30104                 *p++ = htonl((u32) cred->uc_gids[i]);
30105 diff -NurpP --minimal linux-2.6.22.10/net/sunrpc/clnt.c linux-2.6.22.10-vs2.3.0.29/net/sunrpc/clnt.c
30106 --- linux-2.6.22.10/net/sunrpc/clnt.c   2007-07-09 13:20:13 +0200
30107 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/clnt.c        2007-08-05 20:53:13 +0200
30108 @@ -30,6 +30,7 @@
30109  #include <linux/smp_lock.h>
30110  #include <linux/utsname.h>
30111  #include <linux/workqueue.h>
30112 +#include <linux/vs_cvirt.h>
30113  
30114  #include <linux/sunrpc/clnt.h>
30115  #include <linux/sunrpc/rpc_pipe_fs.h>
30116 @@ -249,7 +250,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
30117                 clnt->cl_oneshot = 1;
30118         if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
30119                 clnt->cl_discrtry = 1;
30120 -
30121 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
30122 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
30123 +               clnt->cl_tag = 1; */
30124         return clnt;
30125  }
30126  EXPORT_SYMBOL_GPL(rpc_create);
30127 diff -NurpP --minimal linux-2.6.22.10/net/unix/af_unix.c linux-2.6.22.10-vs2.3.0.29/net/unix/af_unix.c
30128 --- linux-2.6.22.10/net/unix/af_unix.c  2007-07-09 13:20:13 +0200
30129 +++ linux-2.6.22.10-vs2.3.0.29/net/unix/af_unix.c       2007-08-05 20:53:13 +0200
30130 @@ -115,6 +115,8 @@
30131  #include <linux/mount.h>
30132  #include <net/checksum.h>
30133  #include <linux/security.h>
30134 +#include <linux/vs_context.h>
30135 +#include <linux/vs_limit.h>
30136  
30137  int sysctl_unix_max_dgram_qlen __read_mostly = 10;
30138  
30139 @@ -252,6 +254,8 @@ static struct sock *__unix_find_socket_b
30140         sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
30141                 struct unix_sock *u = unix_sk(s);
30142  
30143 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
30144 +                       continue;
30145                 if (u->addr->len == len &&
30146                     !memcmp(u->addr->name, sunname, len))
30147                         goto found;
30148 @@ -807,7 +811,7 @@ static int unix_bind(struct socket *sock
30149                  */
30150                 mode = S_IFSOCK |
30151                        (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
30152 -               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
30153 +               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0, NULL);
30154                 if (err)
30155                         goto out_mknod_dput;
30156                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
30157 diff -NurpP --minimal linux-2.6.22.10/net/x25/af_x25.c linux-2.6.22.10-vs2.3.0.29/net/x25/af_x25.c
30158 --- linux-2.6.22.10/net/x25/af_x25.c    2007-07-09 13:20:13 +0200
30159 +++ linux-2.6.22.10-vs2.3.0.29/net/x25/af_x25.c 2007-08-05 20:53:13 +0200
30160 @@ -500,7 +500,10 @@ static int x25_create(struct socket *soc
30161  
30162         x25 = x25_sk(sk);
30163  
30164 -       sock_init_data(sock, sk);
30165 +       sk->sk_socket = sock;
30166 +       sk->sk_type = sock->type;
30167 +       sk->sk_sleep = &sock->wait;
30168 +       sock->sk = sk;
30169  
30170         x25_init_timers(sk);
30171  
30172 diff -NurpP --minimal linux-2.6.22.10/security/Kconfig linux-2.6.22.10-vs2.3.0.29/security/Kconfig
30173 --- linux-2.6.22.10/security/Kconfig    2006-11-30 21:19:47 +0100
30174 +++ linux-2.6.22.10-vs2.3.0.29/security/Kconfig 2007-08-05 20:53:13 +0200
30175 @@ -6,6 +6,7 @@ menu "Security options"
30176  
30177  config KEYS
30178         bool "Enable access key retention support"
30179 +       depends on !VSERVER_SECURITY
30180         help
30181           This option provides support for retaining authentication tokens and
30182           access keys in the kernel.
30183 diff -NurpP --minimal linux-2.6.22.10/security/commoncap.c linux-2.6.22.10-vs2.3.0.29/security/commoncap.c
30184 --- linux-2.6.22.10/security/commoncap.c        2007-07-09 13:20:14 +0200
30185 +++ linux-2.6.22.10-vs2.3.0.29/security/commoncap.c     2007-08-05 20:53:13 +0200
30186 @@ -22,10 +22,11 @@
30187  #include <linux/ptrace.h>
30188  #include <linux/xattr.h>
30189  #include <linux/hugetlb.h>
30190 +#include <linux/vs_context.h>
30191  
30192  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
30193  {
30194 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30195 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30196         return 0;
30197  }
30198  
30199 @@ -43,7 +44,7 @@ EXPORT_SYMBOL(cap_netlink_recv);
30200  int cap_capable (struct task_struct *tsk, int cap)
30201  {
30202         /* Derived from include/linux/sched.h:capable. */
30203 -       if (cap_raised(tsk->cap_effective, cap))
30204 +       if (vx_cap_raised(tsk->vx_info, tsk->cap_effective, cap))
30205                 return 0;
30206         return -EPERM;
30207  }
30208 @@ -141,7 +142,8 @@ void cap_bprm_apply_creds (struct linux_
30209         /* Derived from fs/exec.c:compute_creds. */
30210         kernel_cap_t new_permitted, working;
30211  
30212 -       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
30213 +       new_permitted = cap_intersect (bprm->cap_permitted,
30214 +                                       vx_current_cap_bset());
30215         working = cap_intersect (bprm->cap_inheritable,
30216                                  current->cap_inheritable);
30217         new_permitted = cap_combine (new_permitted, working);
30218 @@ -310,7 +312,8 @@ void cap_task_reparent_to_init (struct t
30219  
30220  int cap_syslog (int type)
30221  {
30222 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
30223 +       if ((type != 3 && type != 10) &&
30224 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
30225                 return -EPERM;
30226         return 0;
30227  }
30228 diff -NurpP --minimal linux-2.6.22.10/security/dummy.c linux-2.6.22.10-vs2.3.0.29/security/dummy.c
30229 --- linux-2.6.22.10/security/dummy.c    2007-05-02 19:25:51 +0200
30230 +++ linux-2.6.22.10-vs2.3.0.29/security/dummy.c 2007-08-05 20:53:13 +0200
30231 @@ -28,6 +28,7 @@
30232  #include <linux/hugetlb.h>
30233  #include <linux/ptrace.h>
30234  #include <linux/file.h>
30235 +#include <linux/vs_context.h>
30236  
30237  static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
30238  {
30239 @@ -678,7 +679,7 @@ static int dummy_sem_semop (struct sem_a
30240  
30241  static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
30242  {
30243 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30244 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30245         return 0;
30246  }
30247  
30248 diff -NurpP --minimal linux-2.6.22.10/security/selinux/hooks.c linux-2.6.22.10-vs2.3.0.29/security/selinux/hooks.c
30249 --- linux-2.6.22.10/security/selinux/hooks.c    2007-10-30 01:57:15 +0100
30250 +++ linux-2.6.22.10-vs2.3.0.29/security/selinux/hooks.c 2007-10-30 01:21:54 +0100
30251 @@ -60,7 +60,6 @@
30252  #include <linux/dccp.h>
30253  #include <linux/quota.h>
30254  #include <linux/un.h>          /* for Unix socket types */
30255 -#include <net/af_unix.h>       /* for Unix socket types */
30256  #include <linux/parser.h>
30257  #include <linux/nfs_mount.h>
30258  #include <net/ipv6.h>