]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs2.3.patch
- kernel kvm module build disabled, it is provided by kvm.spec
[packages/kernel.git] / linux-2.6-vs2.3.patch
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 = .15
167 +EXTRAVERSION = .15-vs2.3.0.29
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.10/fs/attr.c linux-2.6.22.10-vs2.3.0.29/fs/attr.c
2791 --- linux-2.6.22.10/fs/attr.c   2007-07-09 13:19:22 +0200
2792 +++ linux-2.6.22.10-vs2.3.0.29/fs/attr.c        2007-10-25 17:05:55 +0200
2793 @@ -14,6 +14,9 @@
2794  #include <linux/fcntl.h>
2795  #include <linux/quotaops.h>
2796  #include <linux/security.h>
2797 +#include <linux/proc_fs.h>
2798 +#include <linux/devpts_fs.h>
2799 +#include <linux/vs_base.h>
2800  
2801  /* Taken over from the old code... */
2802  
2803 @@ -55,6 +58,27 @@ int inode_change_ok(struct inode *inode,
2804                 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
2805                         goto error;
2806         }
2807 +
2808 +       /* Check for evil vserver activity */
2809 +       if (vx_check(0, VS_ADMIN))
2810 +               goto fine;
2811 +
2812 +       if (IS_BARRIER(inode)) {
2813 +               vxwprintk_task(1, "messing with the barrier.");
2814 +               goto error;
2815 +       }
2816 +       switch (inode->i_sb->s_magic) {
2817 +               case PROC_SUPER_MAGIC:
2818 +                       /* maybe allow that in the future? */
2819 +                       vxwprintk_task(1, "messing with the procfs.");
2820 +                       goto error;
2821 +               case DEVPTS_SUPER_MAGIC:
2822 +                       /* devpts is xid tagged */
2823 +                       if (vx_check((xid_t)inode->i_tag, VS_IDENT))
2824 +                               goto fine;
2825 +                       vxwprintk_task(1, "messing with the devpts.");
2826 +                       goto error;
2827 +       }
2828  fine:
2829         retval = 0;
2830  error:
2831 @@ -78,6 +102,8 @@ int inode_setattr(struct inode * inode, 
2832                 inode->i_uid = attr->ia_uid;
2833         if (ia_valid & ATTR_GID)
2834                 inode->i_gid = attr->ia_gid;
2835 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2836 +               inode->i_tag = attr->ia_tag;
2837         if (ia_valid & ATTR_ATIME)
2838                 inode->i_atime = timespec_trunc(attr->ia_atime,
2839                                                 inode->i_sb->s_time_gran);
2840 @@ -152,7 +178,8 @@ int notify_change(struct dentry * dentry
2841                         error = security_inode_setattr(dentry, attr);
2842                 if (!error) {
2843                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2844 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2845 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2846 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2847                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2848                         if (!error)
2849                                 error = inode_setattr(inode, attr);
2850 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
2851 --- linux-2.6.22.10/fs/binfmt_aout.c    2007-02-06 03:01:16 +0100
2852 +++ linux-2.6.22.10-vs2.3.0.29/fs/binfmt_aout.c 2007-08-05 20:53:12 +0200
2853 @@ -24,6 +24,7 @@
2854  #include <linux/binfmts.h>
2855  #include <linux/personality.h>
2856  #include <linux/init.h>
2857 +#include <linux/vs_memory.h>
2858  
2859  #include <asm/system.h>
2860  #include <asm/uaccess.h>
2861 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
2862 --- linux-2.6.22.10/fs/binfmt_elf.c     2007-07-09 13:19:22 +0200
2863 +++ linux-2.6.22.10-vs2.3.0.29/fs/binfmt_elf.c  2007-08-05 20:53:12 +0200
2864 @@ -39,6 +39,7 @@
2865  #include <linux/random.h>
2866  #include <linux/elf.h>
2867  #include <linux/utsname.h>
2868 +#include <linux/vs_memory.h>
2869  #include <asm/uaccess.h>
2870  #include <asm/param.h>
2871  #include <asm/page.h>
2872 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
2873 --- linux-2.6.22.10/fs/binfmt_flat.c    2007-07-09 13:19:22 +0200
2874 +++ linux-2.6.22.10-vs2.3.0.29/fs/binfmt_flat.c 2007-08-05 20:53:12 +0200
2875 @@ -36,6 +36,7 @@
2876  #include <linux/init.h>
2877  #include <linux/flat.h>
2878  #include <linux/syscalls.h>
2879 +#include <linux/vs_memory.h>
2880  
2881  #include <asm/byteorder.h>
2882  #include <asm/system.h>
2883 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
2884 --- linux-2.6.22.10/fs/binfmt_som.c     2006-11-30 21:19:19 +0100
2885 +++ linux-2.6.22.10-vs2.3.0.29/fs/binfmt_som.c  2007-08-05 20:53:12 +0200
2886 @@ -28,6 +28,7 @@
2887  #include <linux/shm.h>
2888  #include <linux/personality.h>
2889  #include <linux/init.h>
2890 +#include <linux/vs_memory.h>
2891  
2892  #include <asm/a.out.h>
2893  #include <asm/uaccess.h>
2894 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
2895 --- linux-2.6.22.10/fs/block_dev.c      2007-07-09 13:19:22 +0200
2896 +++ linux-2.6.22.10-vs2.3.0.29/fs/block_dev.c   2007-10-11 01:10:22 +0200
2897 @@ -23,6 +23,7 @@
2898  #include <linux/uio.h>
2899  #include <linux/namei.h>
2900  #include <linux/log2.h>
2901 +#include <linux/vs_device.h>
2902  #include <asm/uaccess.h>
2903  #include "internal.h"
2904  
2905 @@ -572,6 +573,7 @@ struct block_device *bdget(dev_t dev)
2906                 bdev->bd_invalidated = 0;
2907                 inode->i_mode = S_IFBLK;
2908                 inode->i_rdev = dev;
2909 +               inode->i_mdev = dev;
2910                 inode->i_bdev = bdev;
2911                 inode->i_data.a_ops = &def_blk_aops;
2912                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2913 @@ -610,6 +612,11 @@ EXPORT_SYMBOL(bdput);
2914  static struct block_device *bd_acquire(struct inode *inode)
2915  {
2916         struct block_device *bdev;
2917 +       dev_t mdev;
2918 +
2919 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2920 +               return NULL;
2921 +       inode->i_mdev = mdev;
2922  
2923         spin_lock(&bdev_lock);
2924         bdev = inode->i_bdev;
2925 @@ -620,7 +627,7 @@ static struct block_device *bd_acquire(s
2926         }
2927         spin_unlock(&bdev_lock);
2928  
2929 -       bdev = bdget(inode->i_rdev);
2930 +       bdev = bdget(mdev);
2931         if (bdev) {
2932                 spin_lock(&bdev_lock);
2933                 if (!inode->i_bdev) {
2934 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
2935 --- linux-2.6.22.10/fs/char_dev.c       2007-05-02 19:25:16 +0200
2936 +++ linux-2.6.22.10-vs2.3.0.29/fs/char_dev.c    2007-10-11 01:10:22 +0200
2937 @@ -21,6 +21,7 @@
2938  #include <linux/cdev.h>
2939  #include <linux/mutex.h>
2940  #include <linux/backing-dev.h>
2941 +#include <linux/vs_device.h>
2942  
2943  #ifdef CONFIG_KMOD
2944  #include <linux/kmod.h>
2945 @@ -363,14 +364,21 @@ int chrdev_open(struct inode * inode, st
2946         struct cdev *p;
2947         struct cdev *new = NULL;
2948         int ret = 0;
2949 +       dev_t mdev;
2950 +
2951 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2952 +               return -EPERM;
2953 +       inode->i_mdev = mdev;
2954  
2955         spin_lock(&cdev_lock);
2956         p = inode->i_cdev;
2957         if (!p) {
2958                 struct kobject *kobj;
2959                 int idx;
2960 +
2961                 spin_unlock(&cdev_lock);
2962 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2963 +
2964 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2965                 if (!kobj)
2966                         return -ENXIO;
2967                 new = container_of(kobj, struct cdev, kobj);
2968 diff -NurpP --minimal linux-2.6.22.10/fs/dcache.c linux-2.6.22.10-vs2.3.0.29/fs/dcache.c
2969 --- linux-2.6.22.10/fs/dcache.c 2007-07-09 13:19:23 +0200
2970 +++ linux-2.6.22.10-vs2.3.0.29/fs/dcache.c      2007-08-05 20:53:12 +0200
2971 @@ -31,6 +31,7 @@
2972  #include <linux/seqlock.h>
2973  #include <linux/swap.h>
2974  #include <linux/bootmem.h>
2975 +#include <linux/vs_limit.h>
2976  #include "internal.h"
2977  
2978  
2979 @@ -176,6 +177,7 @@ void dput(struct dentry *dentry)
2980         if (!dentry)
2981                 return;
2982  
2983 +       vx_dentry_dec(dentry);
2984  repeat:
2985         if (atomic_read(&dentry->d_count) == 1)
2986                 might_sleep();
2987 @@ -189,6 +191,8 @@ repeat:
2988                 return;
2989         }
2990  
2991 +       vx_dentry_dec(dentry);
2992 +
2993         /*
2994          * AV: ->d_delete() is _NOT_ allowed to block now.
2995          */
2996 @@ -288,6 +292,7 @@ static inline struct dentry * __dget_loc
2997         if (!list_empty(&dentry->d_lru)) {
2998                 dentry_stat.nr_unused--;
2999                 list_del_init(&dentry->d_lru);
3000 +               vx_dentry_inc(dentry);
3001         }
3002         return dentry;
3003  }
3004 @@ -898,6 +903,9 @@ struct dentry *d_alloc(struct dentry * p
3005         struct dentry *dentry;
3006         char *dname;
3007  
3008 +       if (!vx_dentry_avail(1))
3009 +               return NULL;
3010 +
3011         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); 
3012         if (!dentry)
3013                 return NULL;
3014 @@ -946,6 +954,7 @@ struct dentry *d_alloc(struct dentry * p
3015         if (parent)
3016                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
3017         dentry_stat.nr_dentry++;
3018 +       vx_dentry_inc(dentry);
3019         spin_unlock(&dcache_lock);
3020  
3021         return dentry;
3022 @@ -1295,6 +1304,7 @@ struct dentry * __d_lookup(struct dentry
3023  
3024                 if (!d_unhashed(dentry)) {
3025                         atomic_inc(&dentry->d_count);
3026 +                       vx_dentry_inc(dentry);
3027                         found = dentry;
3028                 }
3029                 spin_unlock(&dentry->d_lock);
3030 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
3031 --- linux-2.6.22.10/fs/devpts/inode.c   2007-07-09 13:19:23 +0200
3032 +++ linux-2.6.22.10-vs2.3.0.29/fs/devpts/inode.c        2007-10-18 00:59:53 +0200
3033 @@ -17,11 +17,26 @@
3034  #include <linux/namei.h>
3035  #include <linux/mount.h>
3036  #include <linux/tty.h>
3037 +#include <linux/magic.h>
3038  #include <linux/devpts_fs.h>
3039  #include <linux/parser.h>
3040  #include <linux/fsnotify.h>
3041 +#include <linux/vs_base.h>
3042  
3043 -#define DEVPTS_SUPER_MAGIC 0x1cd1
3044 +
3045 +static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
3046 +{
3047 +       int ret = -EACCES;
3048 +
3049 +       /* devpts is xid tagged */
3050 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
3051 +               ret = generic_permission(inode, mask, NULL);
3052 +       return ret;
3053 +}
3054 +
3055 +static struct inode_operations devpts_file_inode_operations = {
3056 +       .permission     = devpts_permission,
3057 +};
3058  
3059  static struct vfsmount *devpts_mnt;
3060  static struct dentry *devpts_root;
3061 @@ -92,6 +107,25 @@ static int devpts_remount(struct super_b
3062         return 0;
3063  }
3064  
3065 +static int devpts_filter(struct dentry *de)
3066 +{
3067 +       /* devpts is xid tagged */
3068 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
3069 +}
3070 +
3071 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
3072 +{
3073 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
3074 +}
3075 +
3076 +static struct file_operations devpts_dir_operations = {
3077 +       .open           = dcache_dir_open,
3078 +       .release        = dcache_dir_close,
3079 +       .llseek         = dcache_dir_lseek,
3080 +       .read           = generic_read_dir,
3081 +       .readdir        = devpts_readdir,
3082 +};
3083 +
3084  static const struct super_operations devpts_sops = {
3085         .statfs         = simple_statfs,
3086         .remount_fs     = devpts_remount,
3087 @@ -117,8 +151,10 @@ devpts_fill_super(struct super_block *s,
3088         inode->i_uid = inode->i_gid = 0;
3089         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
3090         inode->i_op = &simple_dir_inode_operations;
3091 -       inode->i_fop = &simple_dir_operations;
3092 +       inode->i_fop = &devpts_dir_operations;
3093         inode->i_nlink = 2;
3094 +       /* devpts is xid tagged */
3095 +       inode->i_tag = (tag_t)vx_current_xid();
3096  
3097         devpts_root = s->s_root = d_alloc_root(inode);
3098         if (s->s_root)
3099 @@ -176,6 +212,9 @@ int devpts_pty_new(struct tty_struct *tt
3100         inode->i_gid = config.setgid ? config.gid : current->fsgid;
3101         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
3102         init_special_inode(inode, S_IFCHR|config.mode, device);
3103 +       /* devpts is xid tagged */
3104 +       inode->i_tag = (tag_t)vx_current_xid();
3105 +       inode->i_op = &devpts_file_inode_operations;
3106         inode->i_private = tty;
3107  
3108         dentry = get_node(number);
3109 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
3110 --- linux-2.6.22.10/fs/ecryptfs/inode.c 2007-10-30 01:57:14 +0100
3111 +++ linux-2.6.22.10-vs2.3.0.29/fs/ecryptfs/inode.c      2007-08-11 22:41:51 +0200
3112 @@ -423,7 +423,7 @@ static int ecryptfs_link(struct dentry *
3113         dget(lower_new_dentry);
3114         lower_dir_dentry = lock_parent(lower_new_dentry);
3115         rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
3116 -                     lower_new_dentry);
3117 +                     lower_new_dentry, NULL);
3118         if (rc || !lower_new_dentry->d_inode)
3119                 goto out_lock;
3120         rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
3121 @@ -451,7 +451,7 @@ static int ecryptfs_unlink(struct inode 
3122         struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
3123  
3124         lock_parent(lower_dentry);
3125 -       rc = vfs_unlink(lower_dir_inode, lower_dentry);
3126 +       rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
3127         if (rc) {
3128                 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
3129                 goto out_unlock;
3130 @@ -488,7 +488,7 @@ static int ecryptfs_symlink(struct inode
3131                 goto out_lock;
3132         }
3133         rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
3134 -                        encoded_symname, mode);
3135 +                        encoded_symname, mode, NULL);
3136         kfree(encoded_symname);
3137         if (rc || !lower_dentry->d_inode)
3138                 goto out_lock;
3139 @@ -513,7 +513,7 @@ static int ecryptfs_mkdir(struct inode *
3140  
3141         lower_dentry = ecryptfs_dentry_to_lower(dentry);
3142         lower_dir_dentry = lock_parent(lower_dentry);
3143 -       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
3144 +       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode, NULL);
3145         if (rc || !lower_dentry->d_inode)
3146                 goto out;
3147         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
3148 @@ -539,7 +539,7 @@ static int ecryptfs_rmdir(struct inode *
3149         dget(dentry);
3150         lower_dir_dentry = lock_parent(lower_dentry);
3151         dget(lower_dentry);
3152 -       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
3153 +       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry, NULL);
3154         dput(lower_dentry);
3155         if (!rc)
3156                 d_delete(lower_dentry);
3157 @@ -561,7 +561,7 @@ ecryptfs_mknod(struct inode *dir, struct
3158  
3159         lower_dentry = ecryptfs_dentry_to_lower(dentry);
3160         lower_dir_dentry = lock_parent(lower_dentry);
3161 -       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
3162 +       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev, NULL);
3163         if (rc || !lower_dentry->d_inode)
3164                 goto out;
3165         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
3166 diff -NurpP --minimal linux-2.6.22.10/fs/exec.c linux-2.6.22.10-vs2.3.0.29/fs/exec.c
3167 --- linux-2.6.22.10/fs/exec.c   2007-10-30 01:57:14 +0100
3168 +++ linux-2.6.22.10-vs2.3.0.29/fs/exec.c        2007-10-04 23:47:06 +0200
3169 @@ -51,6 +51,7 @@
3170  #include <linux/cn_proc.h>
3171  #include <linux/audit.h>
3172  #include <linux/signalfd.h>
3173 +#include <linux/vs_memory.h>
3174  
3175  #include <asm/uaccess.h>
3176  #include <asm/mmu_context.h>
3177 @@ -440,7 +441,8 @@ int setup_arg_pages(struct linux_binprm 
3178                         kmem_cache_free(vm_area_cachep, mpnt);
3179                         return ret;
3180                 }
3181 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
3182 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
3183 +               mm->stack_vm = mm->total_vm;
3184         }
3185  
3186         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
3187 @@ -1336,7 +1338,7 @@ static int format_corename(char *corenam
3188                         /* UNIX time of coredump */
3189                         case 't': {
3190                                 struct timeval tv;
3191 -                               do_gettimeofday(&tv);
3192 +                               vx_gettimeofday(&tv);
3193                                 rc = snprintf(out_ptr, out_end - out_ptr,
3194                                               "%lu", tv.tv_sec);
3195                                 if (rc > out_end - out_ptr)
3196 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
3197 --- linux-2.6.22.10/fs/ext2/balloc.c    2007-05-02 19:25:17 +0200
3198 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/balloc.c 2007-08-05 20:53:12 +0200
3199 @@ -16,6 +16,8 @@
3200  #include <linux/sched.h>
3201  #include <linux/buffer_head.h>
3202  #include <linux/capability.h>
3203 +#include <linux/vs_dlimit.h>
3204 +#include <linux/vs_tag.h>
3205  
3206  /*
3207   * balloc.c contains the blocks allocation and deallocation routines
3208 @@ -102,12 +104,13 @@ static int reserve_blocks(struct super_b
3209  {
3210         struct ext2_sb_info *sbi = EXT2_SB(sb);
3211         struct ext2_super_block *es = sbi->s_es;
3212 -       unsigned free_blocks;
3213 -       unsigned root_blocks;
3214 +       unsigned long long free_blocks, root_blocks;
3215  
3216         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3217         root_blocks = le32_to_cpu(es->s_r_blocks_count);
3218  
3219 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3220 +
3221         if (free_blocks < count)
3222                 count = free_blocks;
3223  
3224 @@ -258,6 +261,7 @@ do_more:
3225         }
3226  error_return:
3227         brelse(bitmap_bh);
3228 +       DLIMIT_FREE_BLOCK(inode, freed);
3229         release_blocks(sb, freed);
3230         DQUOT_FREE_BLOCK(inode, freed);
3231  }
3232 @@ -361,6 +365,10 @@ int ext2_new_block(struct inode *inode, 
3233                 *err = -ENOSPC;
3234                 goto out_dquot;
3235         }
3236 +       if (DLIMIT_ALLOC_BLOCK(inode, es_alloc)) {
3237 +               *err = -ENOSPC;
3238 +               goto out_dlimit;
3239 +       }
3240  
3241         ext2_debug ("goal=%lu.\n", goal);
3242  
3243 @@ -508,6 +516,8 @@ got_block:
3244         *err = 0;
3245  out_release:
3246         group_release_blocks(sb, group_no, desc, gdp_bh, group_alloc);
3247 +       DLIMIT_FREE_BLOCK(inode, es_alloc);
3248 +out_dlimit:
3249         release_blocks(sb, es_alloc);
3250  out_dquot:
3251         DQUOT_FREE_BLOCK(inode, dq_alloc);
3252 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
3253 --- linux-2.6.22.10/fs/ext2/ext2.h      2007-07-09 13:19:23 +0200
3254 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/ext2.h   2007-08-05 20:53:12 +0200
3255 @@ -167,6 +167,7 @@ extern const struct file_operations ext2
3256  extern const struct address_space_operations ext2_aops;
3257  extern const struct address_space_operations ext2_aops_xip;
3258  extern const struct address_space_operations ext2_nobh_aops;
3259 +extern int ext2_sync_flags(struct inode *inode);
3260  
3261  /* namei.c */
3262  extern const struct inode_operations ext2_dir_inode_operations;
3263 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
3264 --- linux-2.6.22.10/fs/ext2/file.c      2007-05-02 19:25:17 +0200
3265 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/file.c   2007-09-12 20:04:16 +0200
3266 @@ -85,4 +85,5 @@ const struct inode_operations ext2_file_
3267  #endif
3268         .setattr        = ext2_setattr,
3269         .permission     = ext2_permission,
3270 +       .sync_flags     = ext2_sync_flags,
3271  };
3272 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
3273 --- linux-2.6.22.10/fs/ext2/ialloc.c    2006-11-30 21:19:19 +0100
3274 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/ialloc.c 2007-08-05 20:53:12 +0200
3275 @@ -17,6 +17,8 @@
3276  #include <linux/backing-dev.h>
3277  #include <linux/buffer_head.h>
3278  #include <linux/random.h>
3279 +#include <linux/vs_dlimit.h>
3280 +#include <linux/vs_tag.h>
3281  #include "ext2.h"
3282  #include "xattr.h"
3283  #include "acl.h"
3284 @@ -125,6 +127,7 @@ void ext2_free_inode (struct inode * ino
3285                 ext2_xattr_delete_inode(inode);
3286                 DQUOT_FREE_INODE(inode);
3287                 DQUOT_DROP(inode);
3288 +               DLIMIT_FREE_INODE(inode);
3289         }
3290  
3291         es = EXT2_SB(sb)->s_es;
3292 @@ -464,6 +467,11 @@ struct inode *ext2_new_inode(struct inod
3293         if (!inode)
3294                 return ERR_PTR(-ENOMEM);
3295  
3296 +       inode->i_tag = dx_current_fstag(sb);
3297 +       if (DLIMIT_ALLOC_INODE(inode)) {
3298 +               err = -ENOSPC;
3299 +               goto fail_dlim;
3300 +       }
3301         ei = EXT2_I(inode);
3302         sbi = EXT2_SB(sb);
3303         es = sbi->s_es;
3304 @@ -577,7 +585,8 @@ got:
3305         inode->i_blocks = 0;
3306         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
3307         memset(ei->i_data, 0, sizeof(ei->i_data));
3308 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
3309 +       ei->i_flags = EXT2_I(dir)->i_flags &
3310 +               ~(EXT2_BTREE_FL|EXT2_IUNLINK_FL|EXT2_BARRIER_FL);
3311         if (S_ISLNK(mode))
3312                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
3313         /* dirsync is only applied to directories */
3314 @@ -625,12 +634,15 @@ fail_free_drop:
3315  
3316  fail_drop:
3317         DQUOT_DROP(inode);
3318 +       DLIMIT_FREE_INODE(inode);
3319         inode->i_flags |= S_NOQUOTA;
3320         inode->i_nlink = 0;
3321         iput(inode);
3322         return ERR_PTR(err);
3323  
3324  fail:
3325 +       DLIMIT_FREE_INODE(inode);
3326 +fail_dlim:
3327         make_bad_inode(inode);
3328         iput(inode);
3329         return ERR_PTR(err);
3330 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
3331 --- linux-2.6.22.10/fs/ext2/inode.c     2007-07-09 13:19:23 +0200
3332 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/inode.c  2007-08-18 02:52:34 +0200
3333 @@ -31,6 +31,7 @@
3334  #include <linux/writeback.h>
3335  #include <linux/buffer_head.h>
3336  #include <linux/mpage.h>
3337 +#include <linux/vs_tag.h>
3338  #include "ext2.h"
3339  #include "acl.h"
3340  #include "xip.h"
3341 @@ -913,7 +914,7 @@ void ext2_truncate (struct inode * inode
3342                 return;
3343         if (ext2_inode_is_fast_symlink(inode))
3344                 return;
3345 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3346 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3347                 return;
3348  
3349         ext2_discard_prealloc(inode);
3350 @@ -1042,13 +1043,20 @@ void ext2_set_inode_flags(struct inode *
3351  {
3352         unsigned int flags = EXT2_I(inode)->i_flags;
3353  
3354 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3355 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3356 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3357 +
3358 +       if (flags & EXT2_IMMUTABLE_FL)
3359 +               inode->i_flags |= S_IMMUTABLE;
3360 +       if (flags & EXT2_IUNLINK_FL)
3361 +               inode->i_flags |= S_IUNLINK;
3362 +       if (flags & EXT2_BARRIER_FL)
3363 +               inode->i_flags |= S_BARRIER;
3364 +
3365         if (flags & EXT2_SYNC_FL)
3366                 inode->i_flags |= S_SYNC;
3367         if (flags & EXT2_APPEND_FL)
3368                 inode->i_flags |= S_APPEND;
3369 -       if (flags & EXT2_IMMUTABLE_FL)
3370 -               inode->i_flags |= S_IMMUTABLE;
3371         if (flags & EXT2_NOATIME_FL)
3372                 inode->i_flags |= S_NOATIME;
3373         if (flags & EXT2_DIRSYNC_FL)
3374 @@ -1074,12 +1082,37 @@ void ext2_get_inode_flags(struct ext2_in
3375                 ei->i_flags |= EXT2_DIRSYNC_FL;
3376  }
3377  
3378 +int ext2_sync_flags(struct inode *inode)
3379 +{
3380 +       unsigned int oldflags, newflags;
3381 +
3382 +       oldflags = EXT2_I(inode)->i_flags;
3383 +       newflags = oldflags & ~(EXT2_IMMUTABLE_FL |
3384 +               EXT2_IUNLINK_FL | EXT2_BARRIER_FL);
3385 +
3386 +       if (IS_IMMUTABLE(inode))
3387 +               newflags |= EXT2_IMMUTABLE_FL;
3388 +       if (IS_IUNLINK(inode))
3389 +               newflags |= EXT2_IUNLINK_FL;
3390 +       if (IS_BARRIER(inode))
3391 +               newflags |= EXT2_BARRIER_FL;
3392 +
3393 +       if (oldflags ^ newflags) {
3394 +               EXT2_I(inode)->i_flags = newflags;
3395 +               inode->i_ctime = CURRENT_TIME;
3396 +               mark_inode_dirty(inode);
3397 +       }
3398 +       return 0;
3399 +}
3400 +
3401  void ext2_read_inode (struct inode * inode)
3402  {
3403         struct ext2_inode_info *ei = EXT2_I(inode);
3404         ino_t ino = inode->i_ino;
3405         struct buffer_head * bh;
3406         struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
3407 +       uid_t uid;
3408 +       gid_t gid;
3409         int n;
3410  
3411  #ifdef CONFIG_EXT2_FS_POSIX_ACL
3412 @@ -1090,12 +1123,17 @@ void ext2_read_inode (struct inode * ino
3413                 goto bad_inode;
3414  
3415         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3416 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3417 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3418 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3419 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3420         if (!(test_opt (inode->i_sb, NO_UID32))) {
3421 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3422 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3423 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3424 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3425         }
3426 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3427 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3428 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3429 +               le16_to_cpu(raw_inode->i_raw_tag));
3430 +
3431         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3432         inode->i_size = le32_to_cpu(raw_inode->i_size);
3433         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3434 @@ -1192,8 +1230,8 @@ static int ext2_update_inode(struct inod
3435         struct ext2_inode_info *ei = EXT2_I(inode);
3436         struct super_block *sb = inode->i_sb;
3437         ino_t ino = inode->i_ino;
3438 -       uid_t uid = inode->i_uid;
3439 -       gid_t gid = inode->i_gid;
3440 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3441 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3442         struct buffer_head * bh;
3443         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
3444         int n;
3445 @@ -1229,6 +1267,9 @@ static int ext2_update_inode(struct inod
3446                 raw_inode->i_uid_high = 0;
3447                 raw_inode->i_gid_high = 0;
3448         }
3449 +#ifdef CONFIG_TAGGING_INTERN
3450 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3451 +#endif
3452         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3453         raw_inode->i_size = cpu_to_le32(inode->i_size);
3454         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3455 @@ -1315,7 +1356,8 @@ int ext2_setattr(struct dentry *dentry, 
3456         if (error)
3457                 return error;
3458         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3459 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3460 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3461 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3462                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
3463                 if (error)
3464                         return error;
3465 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
3466 --- linux-2.6.22.10/fs/ext2/ioctl.c     2007-07-09 13:19:23 +0200
3467 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/ioctl.c  2007-08-05 20:53:12 +0200
3468 @@ -13,6 +13,7 @@
3469  #include <linux/sched.h>
3470  #include <linux/compat.h>
3471  #include <linux/smp_lock.h>
3472 +#include <linux/mount.h>
3473  #include <asm/current.h>
3474  #include <asm/uaccess.h>
3475  
3476 @@ -33,7 +34,8 @@ int ext2_ioctl (struct inode * inode, st
3477         case EXT2_IOC_SETFLAGS: {
3478                 unsigned int oldflags;
3479  
3480 -               if (IS_RDONLY(inode))
3481 +               if (IS_RDONLY(inode) ||
3482 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3483                         return -EROFS;
3484  
3485                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3486 @@ -54,7 +56,9 @@ int ext2_ioctl (struct inode * inode, st
3487                  *
3488                  * This test looks nicer. Thanks to Pauline Middelink
3489                  */
3490 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3491 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3492 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3493 +                       EXT2_IMMUTABLE_FL | EXT2_IUNLINK_FL))) {
3494                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3495                                 mutex_unlock(&inode->i_mutex);
3496                                 return -EPERM;
3497 @@ -76,7 +80,8 @@ int ext2_ioctl (struct inode * inode, st
3498         case EXT2_IOC_SETVERSION:
3499                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3500                         return -EPERM;
3501 -               if (IS_RDONLY(inode))
3502 +               if (IS_RDONLY(inode) ||
3503 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3504                         return -EROFS;
3505                 if (get_user(inode->i_generation, (int __user *) arg))
3506                         return -EFAULT; 
3507 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
3508 --- linux-2.6.22.10/fs/ext2/namei.c     2007-05-02 19:25:17 +0200
3509 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/namei.c  2007-08-05 20:53:12 +0200
3510 @@ -31,6 +31,7 @@
3511   */
3512  
3513  #include <linux/pagemap.h>
3514 +#include <linux/vs_tag.h>
3515  #include "ext2.h"
3516  #include "xattr.h"
3517  #include "acl.h"
3518 @@ -66,6 +67,7 @@ static struct dentry *ext2_lookup(struct
3519                 inode = iget(dir->i_sb, ino);
3520                 if (!inode)
3521                         return ERR_PTR(-EACCES);
3522 +               dx_propagate_tag(nd, inode);
3523         }
3524         return d_splice_alias(inode, dentry);
3525  }
3526 @@ -391,6 +393,7 @@ const struct inode_operations ext2_dir_i
3527  #endif
3528         .setattr        = ext2_setattr,
3529         .permission     = ext2_permission,
3530 +       .sync_flags     = ext2_sync_flags,
3531  };
3532  
3533  const struct inode_operations ext2_special_inode_operations = {
3534 @@ -402,4 +405,5 @@ const struct inode_operations ext2_speci
3535  #endif
3536         .setattr        = ext2_setattr,
3537         .permission     = ext2_permission,
3538 +       .sync_flags     = ext2_sync_flags,
3539  };
3540 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
3541 --- linux-2.6.22.10/fs/ext2/super.c     2007-07-09 13:19:23 +0200
3542 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/super.c  2007-08-05 20:53:12 +0200
3543 @@ -321,7 +321,7 @@ enum {
3544         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3545         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3546         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3547 -       Opt_usrquota, Opt_grpquota
3548 +       Opt_usrquota, Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3549  };
3550  
3551  static match_table_t tokens = {
3552 @@ -349,6 +349,9 @@ static match_table_t tokens = {
3553         {Opt_acl, "acl"},
3554         {Opt_noacl, "noacl"},
3555         {Opt_xip, "xip"},
3556 +       {Opt_tag, "tag"},
3557 +       {Opt_notag, "notag"},
3558 +       {Opt_tagid, "tagid=%u"},
3559         {Opt_grpquota, "grpquota"},
3560         {Opt_ignore, "noquota"},
3561         {Opt_quota, "quota"},
3562 @@ -417,6 +420,20 @@ static int parse_options (char * options
3563                 case Opt_nouid32:
3564                         set_opt (sbi->s_mount_opt, NO_UID32);
3565                         break;
3566 +#ifndef CONFIG_TAGGING_NONE
3567 +               case Opt_tag:
3568 +                       set_opt (sbi->s_mount_opt, TAGGED);
3569 +                       break;
3570 +               case Opt_notag:
3571 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3572 +                       break;
3573 +#endif
3574 +#ifdef CONFIG_PROPAGATE
3575 +               case Opt_tagid:
3576 +                       /* use args[0] */
3577 +                       set_opt (sbi->s_mount_opt, TAGGED);
3578 +                       break;
3579 +#endif
3580                 case Opt_nocheck:
3581                         clear_opt (sbi->s_mount_opt, CHECK);
3582                         break;
3583 @@ -727,6 +744,8 @@ static int ext2_fill_super(struct super_
3584         if (!parse_options ((char *) data, sbi))
3585                 goto failed_mount;
3586  
3587 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3588 +               sb->s_flags |= MS_TAGGED;
3589         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3590                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3591                  MS_POSIXACL : 0);
3592 @@ -1035,6 +1054,13 @@ static int ext2_remount (struct super_bl
3593                 goto restore_opts;
3594         }
3595  
3596 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3597 +               !(sb->s_flags & MS_TAGGED)) {
3598 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3599 +                      sb->s_id);
3600 +               return -EINVAL;
3601 +       }
3602 +
3603         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3604                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3605  
3606 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
3607 --- linux-2.6.22.10/fs/ext2/symlink.c   2007-05-02 19:25:17 +0200
3608 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/symlink.c        2007-08-05 20:53:12 +0200
3609 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
3610         .listxattr      = ext2_listxattr,
3611         .removexattr    = generic_removexattr,
3612  #endif
3613 +       .sync_flags     = ext2_sync_flags,
3614  };
3615   
3616  const struct inode_operations ext2_fast_symlink_inode_operations = {
3617 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
3618         .listxattr      = ext2_listxattr,
3619         .removexattr    = generic_removexattr,
3620  #endif
3621 +       .sync_flags     = ext2_sync_flags,
3622  };
3623 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
3624 --- linux-2.6.22.10/fs/ext2/xattr.c     2007-02-06 03:01:18 +0100
3625 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext2/xattr.c  2007-08-05 20:53:12 +0200
3626 @@ -60,6 +60,7 @@
3627  #include <linux/mbcache.h>
3628  #include <linux/quotaops.h>
3629  #include <linux/rwsem.h>
3630 +#include <linux/vs_dlimit.h>
3631  #include "ext2.h"
3632  #include "xattr.h"
3633  #include "acl.h"
3634 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
3635                                    the inode.  */
3636                                 ea_bdebug(new_bh, "reusing block");
3637  
3638 +                               error = -ENOSPC;
3639 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3640 +                                       goto cleanup;
3641                                 error = -EDQUOT;
3642                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
3643 +                                       DLIMIT_FREE_BLOCK(inode, 1);
3644                                         unlock_buffer(new_bh);
3645                                         goto cleanup;
3646                                 }
3647 @@ -736,6 +741,7 @@ ext2_xattr_set2(struct inode *inode, str
3648                                 le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
3649                         if (ce)
3650                                 mb_cache_entry_release(ce);
3651 +                       DLIMIT_FREE_BLOCK(inode, 1);
3652                         DQUOT_FREE_BLOCK(inode, 1);
3653                         mark_buffer_dirty(old_bh);
3654                         ea_bdebug(old_bh, "refcount now=%d",
3655 @@ -800,6 +806,7 @@ ext2_xattr_delete_inode(struct inode *in
3656                 mark_buffer_dirty(bh);
3657                 if (IS_SYNC(inode))
3658                         sync_dirty_buffer(bh);
3659 +               DLIMIT_FREE_BLOCK(inode, 1);
3660                 DQUOT_FREE_BLOCK(inode, 1);
3661         }
3662         EXT2_I(inode)->i_file_acl = 0;
3663 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
3664 --- linux-2.6.22.10/fs/ext3/balloc.c    2007-05-02 19:25:17 +0200
3665 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/balloc.c 2007-08-05 20:53:12 +0200
3666 @@ -19,6 +19,8 @@
3667  #include <linux/ext3_jbd.h>
3668  #include <linux/quotaops.h>
3669  #include <linux/buffer_head.h>
3670 +#include <linux/vs_dlimit.h>
3671 +#include <linux/vs_tag.h>
3672  
3673  /*
3674   * balloc.c contains the blocks allocation and deallocation routines
3675 @@ -613,8 +615,10 @@ void ext3_free_blocks(handle_t *handle, 
3676                 return;
3677         }
3678         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
3679 -       if (dquot_freed_blocks)
3680 +       if (dquot_freed_blocks) {
3681 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3682                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3683 +       }
3684         return;
3685  }
3686  
3687 @@ -1353,18 +1357,33 @@ out:
3688   *
3689   * Check if filesystem has at least 1 free block available for allocation.
3690   */
3691 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
3692 +static int ext3_has_free_blocks(struct super_block *sb)
3693  {
3694 -       ext3_fsblk_t free_blocks, root_blocks;
3695 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
3696 +       unsigned long long free_blocks, root_blocks;
3697 +       int cond;
3698  
3699         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3700         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
3701 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
3702 +
3703 +       vxdprintk(VXD_CBIT(dlim, 3),
3704 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
3705 +               sb, free_blocks, root_blocks);
3706 +
3707 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3708 +
3709 +       cond = (free_blocks < root_blocks + 1 &&
3710 +               !capable(CAP_SYS_RESOURCE) &&
3711                 sbi->s_resuid != current->fsuid &&
3712 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
3713 -               return 0;
3714 -       }
3715 -       return 1;
3716 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
3717 +
3718 +       vxdprintk(VXD_CBIT(dlim, 3),
3719 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
3720 +               sb, free_blocks, root_blocks,
3721 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
3722 +               sbi->s_resuid, current->fsuid, cond?0:1);
3723 +
3724 +       return (cond ? 0 : 1);
3725  }
3726  
3727  /**
3728 @@ -1381,7 +1400,7 @@ static int ext3_has_free_blocks(struct e
3729   */
3730  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
3731  {
3732 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
3733 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
3734                 return 0;
3735  
3736         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
3737 @@ -1444,6 +1463,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3738                 *errp = -EDQUOT;
3739                 return 0;
3740         }
3741 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3742 +           goto out_dlimit;
3743  
3744         sbi = EXT3_SB(sb);
3745         es = EXT3_SB(sb)->s_es;
3746 @@ -1460,7 +1481,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3747         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
3748                 my_rsv = &block_i->rsv_window_node;
3749  
3750 -       if (!ext3_has_free_blocks(sbi)) {
3751 +       if (!ext3_has_free_blocks(sb)) {
3752                 *errp = -ENOSPC;
3753                 goto out;
3754         }
3755 @@ -1647,12 +1668,16 @@ allocated:
3756         *errp = 0;
3757         brelse(bitmap_bh);
3758         DQUOT_FREE_BLOCK(inode, *count-num);
3759 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3760         *count = num;
3761         return ret_block;
3762  
3763  io_error:
3764         *errp = -EIO;
3765  out:
3766 +       if (!performed_allocation)
3767 +               DLIMIT_FREE_BLOCK(inode, *count);
3768 +out_dlimit:
3769         if (fatal) {
3770                 *errp = fatal;
3771                 ext3_std_error(sb, fatal);
3772 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
3773 --- linux-2.6.22.10/fs/ext3/file.c      2007-05-02 19:25:17 +0200
3774 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/file.c   2007-09-12 20:04:16 +0200
3775 @@ -135,5 +135,6 @@ const struct inode_operations ext3_file_
3776         .removexattr    = generic_removexattr,
3777  #endif
3778         .permission     = ext3_permission,
3779 +       .sync_flags     = ext3_sync_flags,
3780  };
3781  
3782 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
3783 --- linux-2.6.22.10/fs/ext3/ialloc.c    2006-11-30 21:19:19 +0100
3784 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/ialloc.c 2007-08-05 20:53:12 +0200
3785 @@ -23,6 +23,8 @@
3786  #include <linux/buffer_head.h>
3787  #include <linux/random.h>
3788  #include <linux/bitops.h>
3789 +#include <linux/vs_dlimit.h>
3790 +#include <linux/vs_tag.h>
3791  
3792  #include <asm/byteorder.h>
3793  
3794 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
3795         ext3_xattr_delete_inode(handle, inode);
3796         DQUOT_FREE_INODE(inode);
3797         DQUOT_DROP(inode);
3798 +       DLIMIT_FREE_INODE(inode);
3799  
3800         is_directory = S_ISDIR(inode->i_mode);
3801  
3802 @@ -445,6 +448,12 @@ struct inode *ext3_new_inode(handle_t *h
3803         inode = new_inode(sb);
3804         if (!inode)
3805                 return ERR_PTR(-ENOMEM);
3806 +
3807 +       inode->i_tag = dx_current_fstag(sb);
3808 +       if (DLIMIT_ALLOC_INODE(inode)) {
3809 +               err = -ENOSPC;
3810 +               goto out_dlimit;
3811 +       }
3812         ei = EXT3_I(inode);
3813  
3814         sbi = EXT3_SB(sb);
3815 @@ -566,7 +575,8 @@ got:
3816         ei->i_dir_start_lookup = 0;
3817         ei->i_disksize = 0;
3818  
3819 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
3820 +       ei->i_flags = EXT3_I(dir)->i_flags &
3821 +               ~(EXT3_INDEX_FL|EXT3_IUNLINK_FL|EXT3_BARRIER_FL);
3822         if (S_ISLNK(mode))
3823                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
3824         /* dirsync only applies to directories */
3825 @@ -621,6 +631,8 @@ got:
3826  fail:
3827         ext3_std_error(sb, err);
3828  out:
3829 +       DLIMIT_FREE_INODE(inode);
3830 +out_dlimit:
3831         iput(inode);
3832         ret = ERR_PTR(err);
3833  really_out:
3834 @@ -632,6 +644,7 @@ fail_free_drop:
3835  
3836  fail_drop:
3837         DQUOT_DROP(inode);
3838 +       DLIMIT_FREE_INODE(inode);
3839         inode->i_flags |= S_NOQUOTA;
3840         inode->i_nlink = 0;
3841         iput(inode);
3842 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
3843 --- linux-2.6.22.10/fs/ext3/inode.c     2007-07-09 13:19:23 +0200
3844 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/inode.c  2007-08-18 02:52:34 +0200
3845 @@ -36,6 +36,7 @@
3846  #include <linux/mpage.h>
3847  #include <linux/uio.h>
3848  #include <linux/bio.h>
3849 +#include <linux/vs_tag.h>
3850  #include "xattr.h"
3851  #include "acl.h"
3852  
3853 @@ -2237,7 +2238,7 @@ void ext3_truncate(struct inode *inode)
3854                 return;
3855         if (ext3_inode_is_fast_symlink(inode))
3856                 return;
3857 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3858 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3859                 return;
3860  
3861         /*
3862 @@ -2559,13 +2560,20 @@ void ext3_set_inode_flags(struct inode *
3863  {
3864         unsigned int flags = EXT3_I(inode)->i_flags;
3865  
3866 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3867 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3868 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3869 +
3870 +       if (flags & EXT3_IMMUTABLE_FL)
3871 +               inode->i_flags |= S_IMMUTABLE;
3872 +       if (flags & EXT3_IUNLINK_FL)
3873 +               inode->i_flags |= S_IUNLINK;
3874 +       if (flags & EXT3_BARRIER_FL)
3875 +               inode->i_flags |= S_BARRIER;
3876 +
3877         if (flags & EXT3_SYNC_FL)
3878                 inode->i_flags |= S_SYNC;
3879         if (flags & EXT3_APPEND_FL)
3880                 inode->i_flags |= S_APPEND;
3881 -       if (flags & EXT3_IMMUTABLE_FL)
3882 -               inode->i_flags |= S_IMMUTABLE;
3883         if (flags & EXT3_NOATIME_FL)
3884                 inode->i_flags |= S_NOATIME;
3885         if (flags & EXT3_DIRSYNC_FL)
3886 @@ -2591,6 +2599,45 @@ void ext3_get_inode_flags(struct ext3_in
3887                 ei->i_flags |= EXT3_DIRSYNC_FL;
3888  }
3889  
3890 +int ext3_sync_flags(struct inode *inode)
3891 +{
3892 +       unsigned int oldflags, newflags;
3893 +       int err = 0;
3894 +
3895 +       oldflags = EXT3_I(inode)->i_flags;
3896 +       newflags = oldflags & ~(EXT3_IMMUTABLE_FL |
3897 +               EXT3_IUNLINK_FL | EXT3_BARRIER_FL);
3898 +
3899 +       if (IS_IMMUTABLE(inode))
3900 +               newflags |= EXT3_IMMUTABLE_FL;
3901 +       if (IS_IUNLINK(inode))
3902 +               newflags |= EXT3_IUNLINK_FL;
3903 +       if (IS_BARRIER(inode))
3904 +               newflags |= EXT3_BARRIER_FL;
3905 +
3906 +       if (oldflags ^ newflags) {
3907 +               handle_t *handle;
3908 +               struct ext3_iloc iloc;
3909 +
3910 +               handle = ext3_journal_start(inode, 1);
3911 +               if (IS_ERR(handle))
3912 +                       return PTR_ERR(handle);
3913 +               if (IS_SYNC(inode))
3914 +                       handle->h_sync = 1;
3915 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3916 +               if (err)
3917 +                       goto flags_err;
3918 +
3919 +               EXT3_I(inode)->i_flags = newflags;
3920 +               inode->i_ctime = CURRENT_TIME;
3921 +
3922 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3923 +       flags_err:
3924 +               ext3_journal_stop(handle);
3925 +       }
3926 +       return err;
3927 +}
3928 +
3929  void ext3_read_inode(struct inode * inode)
3930  {
3931         struct ext3_iloc iloc;
3932 @@ -2598,6 +2645,8 @@ void ext3_read_inode(struct inode * inod
3933         struct ext3_inode_info *ei = EXT3_I(inode);
3934         struct buffer_head *bh;
3935         int block;
3936 +       uid_t uid;
3937 +       gid_t gid;
3938  
3939  #ifdef CONFIG_EXT3_FS_POSIX_ACL
3940         ei->i_acl = EXT3_ACL_NOT_CACHED;
3941 @@ -2610,12 +2659,17 @@ void ext3_read_inode(struct inode * inod
3942         bh = iloc.bh;
3943         raw_inode = ext3_raw_inode(&iloc);
3944         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3945 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3946 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3947 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3948 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3949         if(!(test_opt (inode->i_sb, NO_UID32))) {
3950 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3951 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3952 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3953 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3954         }
3955 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3956 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3957 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3958 +               le16_to_cpu(raw_inode->i_raw_tag));
3959 +
3960         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3961         inode->i_size = le32_to_cpu(raw_inode->i_size);
3962         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3963 @@ -2741,6 +2795,8 @@ static int ext3_do_update_inode(handle_t
3964         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3965         struct ext3_inode_info *ei = EXT3_I(inode);
3966         struct buffer_head *bh = iloc->bh;
3967 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3968 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3969         int err = 0, rc, block;
3970  
3971         /* For fields not not tracking in the in-memory inode,
3972 @@ -2751,29 +2807,32 @@ static int ext3_do_update_inode(handle_t
3973         ext3_get_inode_flags(ei);
3974         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3975         if(!(test_opt(inode->i_sb, NO_UID32))) {
3976 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3977 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3978 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3979 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3980  /*
3981   * Fix up interoperability with old kernels. Otherwise, old inodes get
3982   * re-used with the upper 16 bits of the uid/gid intact
3983   */
3984                 if(!ei->i_dtime) {
3985                         raw_inode->i_uid_high =
3986 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3987 +                               cpu_to_le16(high_16_bits(uid));
3988                         raw_inode->i_gid_high =
3989 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3990 +                               cpu_to_le16(high_16_bits(gid));
3991                 } else {
3992                         raw_inode->i_uid_high = 0;
3993                         raw_inode->i_gid_high = 0;
3994                 }
3995         } else {
3996                 raw_inode->i_uid_low =
3997 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3998 +                       cpu_to_le16(fs_high2lowuid(uid));
3999                 raw_inode->i_gid_low =
4000 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4001 +                       cpu_to_le16(fs_high2lowgid(gid));
4002                 raw_inode->i_uid_high = 0;
4003                 raw_inode->i_gid_high = 0;
4004         }
4005 +#ifdef CONFIG_TAGGING_INTERN
4006 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4007 +#endif
4008         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4009         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4010         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4011 @@ -2926,7 +2985,8 @@ int ext3_setattr(struct dentry *dentry, 
4012                 return error;
4013  
4014         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4015 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4016 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4017 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4018                 handle_t *handle;
4019  
4020                 /* (user+group)*(old+new) structure, inode write (sb,
4021 @@ -2948,6 +3008,8 @@ int ext3_setattr(struct dentry *dentry, 
4022                         inode->i_uid = attr->ia_uid;
4023                 if (attr->ia_valid & ATTR_GID)
4024                         inode->i_gid = attr->ia_gid;
4025 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4026 +                       inode->i_tag = attr->ia_tag;
4027                 error = ext3_mark_inode_dirty(handle, inode);
4028                 ext3_journal_stop(handle);
4029         }
4030 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
4031 --- linux-2.6.22.10/fs/ext3/ioctl.c     2007-07-09 13:19:23 +0200
4032 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/ioctl.c  2007-08-05 20:53:12 +0200
4033 @@ -8,6 +8,7 @@
4034   */
4035  
4036  #include <linux/fs.h>
4037 +#include <linux/mount.h>
4038  #include <linux/jbd.h>
4039  #include <linux/capability.h>
4040  #include <linux/ext3_fs.h>
4041 @@ -15,6 +16,7 @@
4042  #include <linux/time.h>
4043  #include <linux/compat.h>
4044  #include <linux/smp_lock.h>
4045 +#include <linux/vs_tag.h>
4046  #include <asm/uaccess.h>
4047  
4048  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
4049 @@ -38,7 +40,8 @@ int ext3_ioctl (struct inode * inode, st
4050                 unsigned int oldflags;
4051                 unsigned int jflag;
4052  
4053 -               if (IS_RDONLY(inode))
4054 +               if (IS_RDONLY(inode) ||
4055 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4056                         return -EROFS;
4057  
4058                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4059 @@ -62,7 +65,9 @@ int ext3_ioctl (struct inode * inode, st
4060                  *
4061                  * This test looks nicer. Thanks to Pauline Middelink
4062                  */
4063 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
4064 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
4065 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
4066 +                       EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL))) {
4067                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4068                                 mutex_unlock(&inode->i_mutex);
4069                                 return -EPERM;
4070 @@ -124,7 +129,8 @@ flags_err:
4071  
4072                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4073                         return -EPERM;
4074 -               if (IS_RDONLY(inode))
4075 +               if (IS_RDONLY(inode) ||
4076 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4077                         return -EROFS;
4078                 if (get_user(generation, (int __user *) arg))
4079                         return -EFAULT;
4080 @@ -178,7 +184,8 @@ flags_err:
4081                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4082                         return -ENOTTY;
4083  
4084 -               if (IS_RDONLY(inode))
4085 +               if (IS_RDONLY(inode) ||
4086 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4087                         return -EROFS;
4088  
4089                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4090 @@ -213,7 +220,8 @@ flags_err:
4091                 if (!capable(CAP_SYS_RESOURCE))
4092                         return -EPERM;
4093  
4094 -               if (IS_RDONLY(inode))
4095 +               if (IS_RDONLY(inode) ||
4096 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4097                         return -EROFS;
4098  
4099                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4100 @@ -234,7 +242,8 @@ flags_err:
4101                 if (!capable(CAP_SYS_RESOURCE))
4102                         return -EPERM;
4103  
4104 -               if (IS_RDONLY(inode))
4105 +               if (IS_RDONLY(inode) ||
4106 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4107                         return -EROFS;
4108  
4109                 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
4110 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
4111 --- linux-2.6.22.10/fs/ext3/namei.c     2007-10-30 01:57:14 +0100
4112 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/namei.c  2007-09-30 14:58:01 +0200
4113 @@ -36,6 +36,7 @@
4114  #include <linux/quotaops.h>
4115  #include <linux/buffer_head.h>
4116  #include <linux/bio.h>
4117 +#include <linux/vs_tag.h>
4118  
4119  #include "namei.h"
4120  #include "xattr.h"
4121 @@ -1052,6 +1053,7 @@ static struct dentry *ext3_lookup(struct
4122  
4123                 if (!inode)
4124                         return ERR_PTR(-EACCES);
4125 +               dx_propagate_tag(nd, inode);
4126         }
4127         return d_splice_alias(inode, dentry);
4128  }
4129 @@ -2443,6 +2445,7 @@ const struct inode_operations ext3_dir_i
4130         .removexattr    = generic_removexattr,
4131  #endif
4132         .permission     = ext3_permission,
4133 +       .sync_flags     = ext3_sync_flags,
4134  };
4135  
4136  const struct inode_operations ext3_special_inode_operations = {
4137 @@ -2454,4 +2457,5 @@ const struct inode_operations ext3_speci
4138         .removexattr    = generic_removexattr,
4139  #endif
4140         .permission     = ext3_permission,
4141 +       .sync_flags     = ext3_sync_flags,
4142  };
4143 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
4144 --- linux-2.6.22.10/fs/ext3/super.c     2007-07-09 13:19:23 +0200
4145 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/super.c  2007-08-05 20:53:12 +0200
4146 @@ -674,7 +674,7 @@ enum {
4147         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4148         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4149         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4150 -       Opt_grpquota
4151 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
4152  };
4153  
4154  static match_table_t tokens = {
4155 @@ -724,6 +724,9 @@ static match_table_t tokens = {
4156         {Opt_quota, "quota"},
4157         {Opt_usrquota, "usrquota"},
4158         {Opt_barrier, "barrier=%u"},
4159 +       {Opt_tag, "tag"},
4160 +       {Opt_notag, "notag"},
4161 +       {Opt_tagid, "tagid=%u"},
4162         {Opt_err, NULL},
4163         {Opt_resize, "resize"},
4164  };
4165 @@ -817,6 +820,20 @@ static int parse_options (char *options,
4166                 case Opt_nouid32:
4167                         set_opt (sbi->s_mount_opt, NO_UID32);
4168                         break;
4169 +#ifndef CONFIG_TAGGING_NONE
4170 +               case Opt_tag:
4171 +                       set_opt (sbi->s_mount_opt, TAGGED);
4172 +                       break;
4173 +               case Opt_notag:
4174 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4175 +                       break;
4176 +#endif
4177 +#ifdef CONFIG_PROPAGATE
4178 +               case Opt_tagid:
4179 +                       /* use args[0] */
4180 +                       set_opt (sbi->s_mount_opt, TAGGED);
4181 +                       break;
4182 +#endif
4183                 case Opt_nocheck:
4184                         clear_opt (sbi->s_mount_opt, CHECK);
4185                         break;
4186 @@ -1487,6 +1504,9 @@ static int ext3_fill_super (struct super
4187                             NULL, 0))
4188                 goto failed_mount;
4189  
4190 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
4191 +               sb->s_flags |= MS_TAGGED;
4192 +
4193         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4194                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4195  
4196 @@ -2302,6 +2322,12 @@ static int ext3_remount (struct super_bl
4197  
4198         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
4199                 ext3_abort(sb, __FUNCTION__, "Abort forced by user");
4200 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
4201 +               !(sb->s_flags & MS_TAGGED)) {
4202 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
4203 +                       sb->s_id);
4204 +               return -EINVAL;
4205 +       }
4206  
4207         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4208                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4209 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
4210 --- linux-2.6.22.10/fs/ext3/symlink.c   2007-05-02 19:25:17 +0200
4211 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/symlink.c        2007-08-05 20:53:12 +0200
4212 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
4213         .listxattr      = ext3_listxattr,
4214         .removexattr    = generic_removexattr,
4215  #endif
4216 +       .sync_flags     = ext3_sync_flags,
4217  };
4218  
4219  const struct inode_operations ext3_fast_symlink_inode_operations = {
4220 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
4221         .listxattr      = ext3_listxattr,
4222         .removexattr    = generic_removexattr,
4223  #endif
4224 +       .sync_flags     = ext3_sync_flags,
4225  };
4226 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
4227 --- linux-2.6.22.10/fs/ext3/xattr.c     2007-05-02 19:25:17 +0200
4228 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext3/xattr.c  2007-08-05 20:53:12 +0200
4229 @@ -58,6 +58,7 @@
4230  #include <linux/mbcache.h>
4231  #include <linux/quotaops.h>
4232  #include <linux/rwsem.h>
4233 +#include <linux/vs_dlimit.h>
4234  #include "xattr.h"
4235  #include "acl.h"
4236  
4237 @@ -497,6 +498,7 @@ ext3_xattr_release_block(handle_t *handl
4238                 error = ext3_journal_dirty_metadata(handle, bh);
4239                 if (IS_SYNC(inode))
4240                         handle->h_sync = 1;
4241 +                       DLIMIT_FREE_BLOCK(inode, 1);
4242                 DQUOT_FREE_BLOCK(inode, 1);
4243                 ea_bdebug(bh, "refcount now=%d; releasing",
4244                           le32_to_cpu(BHDR(bh)->h_refcount));
4245 @@ -771,11 +773,14 @@ inserted:
4246                         if (new_bh == bs->bh)
4247                                 ea_bdebug(new_bh, "keeping");
4248                         else {
4249 +                               error = -ENOSPC;
4250 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4251 +                                       goto cleanup;
4252                                 /* The old block is released after updating
4253                                    the inode. */
4254                                 error = -EDQUOT;
4255                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4256 -                                       goto cleanup;
4257 +                                       goto cleanup_dlimit;
4258                                 error = ext3_journal_get_write_access(handle,
4259                                                                       new_bh);
4260                                 if (error)
4261 @@ -852,6 +857,8 @@ cleanup:
4262  
4263  cleanup_dquot:
4264         DQUOT_FREE_BLOCK(inode, 1);
4265 +cleanup_dlimit:
4266 +       DLIMIT_FREE_BLOCK(inode, 1);
4267         goto cleanup;
4268  
4269  bad_block:
4270 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
4271 --- linux-2.6.22.10/fs/ext4/balloc.c    2007-07-09 13:19:23 +0200
4272 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/balloc.c 2007-08-05 20:53:12 +0200
4273 @@ -19,6 +19,8 @@
4274  #include <linux/ext4_jbd2.h>
4275  #include <linux/quotaops.h>
4276  #include <linux/buffer_head.h>
4277 +#include <linux/vs_dlimit.h>
4278 +#include <linux/vs_tag.h>
4279  
4280  /*
4281   * balloc.c contains the blocks allocation and deallocation routines
4282 @@ -630,8 +632,10 @@ void ext4_free_blocks(handle_t *handle, 
4283                 return;
4284         }
4285         ext4_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
4286 -       if (dquot_freed_blocks)
4287 +       if (dquot_freed_blocks) {
4288 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
4289                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
4290 +       }
4291         return;
4292  }
4293  
4294 @@ -1370,18 +1374,33 @@ out:
4295   *
4296   * Check if filesystem has at least 1 free block available for allocation.
4297   */
4298 -static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
4299 +static int ext4_has_free_blocks(struct super_block *sb)
4300  {
4301 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
4302         ext4_fsblk_t free_blocks, root_blocks;
4303 +       int cond;
4304  
4305         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
4306         root_blocks = ext4_r_blocks_count(sbi->s_es);
4307 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
4308 +
4309 +       vxdprintk(VXD_CBIT(dlim, 3),
4310 +               "ext4_has_free_blocks(%p): free=%llu, root=%llu",
4311 +               sb, free_blocks, root_blocks);
4312 +
4313 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
4314 +
4315 +       cond = (free_blocks < root_blocks + 1 &&
4316 +               !capable(CAP_SYS_RESOURCE) &&
4317                 sbi->s_resuid != current->fsuid &&
4318 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
4319 -               return 0;
4320 -       }
4321 -       return 1;
4322 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
4323 +
4324 +       vxdprintk(VXD_CBIT(dlim, 3),
4325 +               "ext4_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
4326 +               sb, free_blocks, root_blocks,
4327 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
4328 +               sbi->s_resuid, current->fsuid, cond?0:1);
4329 +
4330 +       return (cond ? 0 : 1);
4331  }
4332  
4333  /**
4334 @@ -1398,7 +1417,7 @@ static int ext4_has_free_blocks(struct e
4335   */
4336  int ext4_should_retry_alloc(struct super_block *sb, int *retries)
4337  {
4338 -       if (!ext4_has_free_blocks(EXT4_SB(sb)) || (*retries)++ > 3)
4339 +       if (!ext4_has_free_blocks(sb) || (*retries)++ > 3)
4340                 return 0;
4341  
4342         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
4343 @@ -1461,6 +1480,8 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
4344                 *errp = -EDQUOT;
4345                 return 0;
4346         }
4347 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
4348 +           goto out_dlimit;
4349  
4350         sbi = EXT4_SB(sb);
4351         es = EXT4_SB(sb)->s_es;
4352 @@ -1477,7 +1498,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
4353         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
4354                 my_rsv = &block_i->rsv_window_node;
4355  
4356 -       if (!ext4_has_free_blocks(sbi)) {
4357 +       if (!ext4_has_free_blocks(sb)) {
4358                 *errp = -ENOSPC;
4359                 goto out;
4360         }
4361 @@ -1661,12 +1682,16 @@ allocated:
4362         *errp = 0;
4363         brelse(bitmap_bh);
4364         DQUOT_FREE_BLOCK(inode, *count-num);
4365 +       DLIMIT_FREE_BLOCK(inode, *count-num);
4366         *count = num;
4367         return ret_block;
4368  
4369  io_error:
4370         *errp = -EIO;
4371  out:
4372 +       if (!performed_allocation)
4373 +               DLIMIT_FREE_BLOCK(inode, *count);
4374 +out_dlimit:
4375         if (fatal) {
4376                 *errp = fatal;
4377                 ext4_std_error(sb, fatal);
4378 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
4379 --- linux-2.6.22.10/fs/ext4/file.c      2007-05-02 19:25:17 +0200
4380 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/file.c   2007-09-12 20:04:16 +0200
4381 @@ -135,5 +135,6 @@ const struct inode_operations ext4_file_
4382         .removexattr    = generic_removexattr,
4383  #endif
4384         .permission     = ext4_permission,
4385 +       .sync_flags     = ext4_sync_flags,
4386  };
4387  
4388 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
4389 --- linux-2.6.22.10/fs/ext4/ialloc.c    2006-11-30 21:19:20 +0100
4390 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/ialloc.c 2007-08-05 20:53:12 +0200
4391 @@ -24,6 +24,8 @@
4392  #include <linux/random.h>
4393  #include <linux/bitops.h>
4394  #include <linux/blkdev.h>
4395 +#include <linux/vs_dlimit.h>
4396 +#include <linux/vs_tag.h>
4397  #include <asm/byteorder.h>
4398  
4399  #include "xattr.h"
4400 @@ -127,6 +129,7 @@ void ext4_free_inode (handle_t *handle, 
4401         ext4_xattr_delete_inode(handle, inode);
4402         DQUOT_FREE_INODE(inode);
4403         DQUOT_DROP(inode);
4404 +       DLIMIT_FREE_INODE(inode);
4405  
4406         is_directory = S_ISDIR(inode->i_mode);
4407  
4408 @@ -448,6 +451,12 @@ struct inode *ext4_new_inode(handle_t *h
4409         inode = new_inode(sb);
4410         if (!inode)
4411                 return ERR_PTR(-ENOMEM);
4412 +
4413 +       inode->i_tag = dx_current_fstag(sb);
4414 +       if (DLIMIT_ALLOC_INODE(inode)) {
4415 +               err = -ENOSPC;
4416 +               goto out_dlimit;
4417 +       }
4418         ei = EXT4_I(inode);
4419  
4420         sbi = EXT4_SB(sb);
4421 @@ -569,7 +578,8 @@ got:
4422         ei->i_dir_start_lookup = 0;
4423         ei->i_disksize = 0;
4424  
4425 -       ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
4426 +       ei->i_flags = EXT4_I(dir)->i_flags &
4427 +               ~(EXT4_INDEX_FL|EXT4_IUNLINK_FL|EXT4_BARRIER_FL);
4428         if (S_ISLNK(mode))
4429                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
4430         /* dirsync only applies to directories */
4431 @@ -635,6 +645,8 @@ got:
4432  fail:
4433         ext4_std_error(sb, err);
4434  out:
4435 +       DLIMIT_FREE_INODE(inode);
4436 +out_dlimit:
4437         iput(inode);
4438         ret = ERR_PTR(err);
4439  really_out:
4440 @@ -646,6 +658,7 @@ fail_free_drop:
4441  
4442  fail_drop:
4443         DQUOT_DROP(inode);
4444 +       DLIMIT_FREE_INODE(inode);
4445         inode->i_flags |= S_NOQUOTA;
4446         inode->i_nlink = 0;
4447         iput(inode);
4448 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
4449 --- linux-2.6.22.10/fs/ext4/inode.c     2007-07-09 13:19:23 +0200
4450 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/inode.c  2007-08-18 02:52:34 +0200
4451 @@ -36,6 +36,7 @@
4452  #include <linux/mpage.h>
4453  #include <linux/uio.h>
4454  #include <linux/bio.h>
4455 +#include <linux/vs_tag.h>
4456  #include "xattr.h"
4457  #include "acl.h"
4458  
4459 @@ -2244,7 +2245,7 @@ void ext4_truncate(struct inode *inode)
4460                 return;
4461         if (ext4_inode_is_fast_symlink(inode))
4462                 return;
4463 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4464 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4465                 return;
4466  
4467         /*
4468 @@ -2570,19 +2571,65 @@ void ext4_set_inode_flags(struct inode *
4469  {
4470         unsigned int flags = EXT4_I(inode)->i_flags;
4471  
4472 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4473 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
4474 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4475 +
4476 +       if (flags & EXT4_IMMUTABLE_FL)
4477 +               inode->i_flags |= S_IMMUTABLE;
4478 +       if (flags & EXT4_IUNLINK_FL)
4479 +               inode->i_flags |= S_IUNLINK;
4480 +       if (flags & EXT4_BARRIER_FL)
4481 +               inode->i_flags |= S_BARRIER;
4482 +
4483         if (flags & EXT4_SYNC_FL)
4484                 inode->i_flags |= S_SYNC;
4485         if (flags & EXT4_APPEND_FL)
4486                 inode->i_flags |= S_APPEND;
4487 -       if (flags & EXT4_IMMUTABLE_FL)
4488 -               inode->i_flags |= S_IMMUTABLE;
4489         if (flags & EXT4_NOATIME_FL)
4490                 inode->i_flags |= S_NOATIME;
4491         if (flags & EXT4_DIRSYNC_FL)
4492                 inode->i_flags |= S_DIRSYNC;
4493  }
4494  
4495 +int ext4_sync_flags(struct inode *inode)
4496 +{
4497 +       unsigned int oldflags, newflags;
4498 +       int err = 0;
4499 +
4500 +       oldflags = EXT4_I(inode)->i_flags;
4501 +       newflags = oldflags & ~(EXT4_IMMUTABLE_FL |
4502 +               EXT4_IUNLINK_FL | EXT4_BARRIER_FL);
4503 +
4504 +       if (IS_IMMUTABLE(inode))
4505 +               newflags |= EXT4_IMMUTABLE_FL;
4506 +       if (IS_IUNLINK(inode))
4507 +               newflags |= EXT4_IUNLINK_FL;
4508 +       if (IS_BARRIER(inode))
4509 +               newflags |= EXT4_BARRIER_FL;
4510 +
4511 +       if (oldflags ^ newflags) {
4512 +               handle_t *handle;
4513 +               struct ext4_iloc iloc;
4514 +
4515 +               handle = ext4_journal_start(inode, 1);
4516 +               if (IS_ERR(handle))
4517 +                       return PTR_ERR(handle);
4518 +               if (IS_SYNC(inode))
4519 +                       handle->h_sync = 1;
4520 +               err = ext4_reserve_inode_write(handle, inode, &iloc);
4521 +               if (err)
4522 +                       goto flags_err;
4523 +
4524 +               EXT4_I(inode)->i_flags = newflags;
4525 +               inode->i_ctime = CURRENT_TIME;
4526 +
4527 +               err = ext4_mark_iloc_dirty(handle, inode, &iloc);
4528 +       flags_err:
4529 +               ext4_journal_stop(handle);
4530 +       }
4531 +       return err;
4532 +}
4533 +
4534  void ext4_read_inode(struct inode * inode)
4535  {
4536         struct ext4_iloc iloc;
4537 @@ -2590,6 +2637,8 @@ void ext4_read_inode(struct inode * inod
4538         struct ext4_inode_info *ei = EXT4_I(inode);
4539         struct buffer_head *bh;
4540         int block;
4541 +       uid_t uid;
4542 +       gid_t gid;
4543  
4544  #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
4545         ei->i_acl = EXT4_ACL_NOT_CACHED;
4546 @@ -2602,12 +2651,17 @@ void ext4_read_inode(struct inode * inod
4547         bh = iloc.bh;
4548         raw_inode = ext4_raw_inode(&iloc);
4549         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4550 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4551 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4552 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4553 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4554         if(!(test_opt (inode->i_sb, NO_UID32))) {
4555 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4556 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4557 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4558 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4559         }
4560 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4561 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4562 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4563 +               le16_to_cpu(raw_inode->i_raw_tag));
4564 +
4565         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4566         inode->i_size = le32_to_cpu(raw_inode->i_size);
4567         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
4568 @@ -2737,6 +2791,8 @@ static int ext4_do_update_inode(handle_t
4569         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
4570         struct ext4_inode_info *ei = EXT4_I(inode);
4571         struct buffer_head *bh = iloc->bh;
4572 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4573 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4574         int err = 0, rc, block;
4575  
4576         /* For fields not not tracking in the in-memory inode,
4577 @@ -2746,29 +2802,32 @@ static int ext4_do_update_inode(handle_t
4578  
4579         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4580         if(!(test_opt(inode->i_sb, NO_UID32))) {
4581 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4582 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4583 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
4584 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
4585  /*
4586   * Fix up interoperability with old kernels. Otherwise, old inodes get
4587   * re-used with the upper 16 bits of the uid/gid intact
4588   */
4589                 if(!ei->i_dtime) {
4590                         raw_inode->i_uid_high =
4591 -                               cpu_to_le16(high_16_bits(inode->i_uid));
4592 +                               cpu_to_le16(high_16_bits(uid));
4593                         raw_inode->i_gid_high =
4594 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4595 +                               cpu_to_le16(high_16_bits(gid));
4596                 } else {
4597                         raw_inode->i_uid_high = 0;
4598                         raw_inode->i_gid_high = 0;
4599                 }
4600         } else {
4601                 raw_inode->i_uid_low =
4602 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4603 +                       cpu_to_le16(fs_high2lowuid(uid));
4604                 raw_inode->i_gid_low =
4605 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4606 +                       cpu_to_le16(fs_high2lowgid(gid));
4607                 raw_inode->i_uid_high = 0;
4608                 raw_inode->i_gid_high = 0;
4609         }
4610 +#ifdef CONFIG_TAGGING_INTERN
4611 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4612 +#endif
4613         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4614         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4615         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4616 @@ -2925,7 +2984,8 @@ int ext4_setattr(struct dentry *dentry, 
4617                 return error;
4618  
4619         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4620 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4621 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4622 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4623                 handle_t *handle;
4624  
4625                 /* (user+group)*(old+new) structure, inode write (sb,
4626 @@ -2947,6 +3007,8 @@ int ext4_setattr(struct dentry *dentry, 
4627                         inode->i_uid = attr->ia_uid;
4628                 if (attr->ia_valid & ATTR_GID)
4629                         inode->i_gid = attr->ia_gid;
4630 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4631 +                       inode->i_tag = attr->ia_tag;
4632                 error = ext4_mark_inode_dirty(handle, inode);
4633                 ext4_journal_stop(handle);
4634         }
4635 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
4636 --- linux-2.6.22.10/fs/ext4/ioctl.c     2007-02-06 03:01:18 +0100
4637 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/ioctl.c  2007-08-05 20:53:12 +0200
4638 @@ -8,6 +8,7 @@
4639   */
4640  
4641  #include <linux/fs.h>
4642 +#include <linux/mount.h>
4643  #include <linux/jbd2.h>
4644  #include <linux/capability.h>
4645  #include <linux/ext4_fs.h>
4646 @@ -15,6 +16,7 @@
4647  #include <linux/time.h>
4648  #include <linux/compat.h>
4649  #include <linux/smp_lock.h>
4650 +#include <linux/vs_tag.h>
4651  #include <asm/uaccess.h>
4652  
4653  int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
4654 @@ -37,7 +39,8 @@ int ext4_ioctl (struct inode * inode, st
4655                 unsigned int oldflags;
4656                 unsigned int jflag;
4657  
4658 -               if (IS_RDONLY(inode))
4659 +               if (IS_RDONLY(inode) ||
4660 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4661                         return -EROFS;
4662  
4663                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4664 @@ -61,7 +64,9 @@ int ext4_ioctl (struct inode * inode, st
4665                  *
4666                  * This test looks nicer. Thanks to Pauline Middelink
4667                  */
4668 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
4669 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
4670 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
4671 +                       EXT4_IMMUTABLE_FL | EXT4_IUNLINK_FL))) {
4672                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4673                                 mutex_unlock(&inode->i_mutex);
4674                                 return -EPERM;
4675 @@ -123,7 +128,8 @@ flags_err:
4676  
4677                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4678                         return -EPERM;
4679 -               if (IS_RDONLY(inode))
4680 +               if (IS_RDONLY(inode) ||
4681 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4682                         return -EROFS;
4683                 if (get_user(generation, (int __user *) arg))
4684                         return -EFAULT;
4685 @@ -177,7 +183,8 @@ flags_err:
4686                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4687                         return -ENOTTY;
4688  
4689 -               if (IS_RDONLY(inode))
4690 +               if (IS_RDONLY(inode) ||
4691 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4692                         return -EROFS;
4693  
4694                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4695 @@ -212,7 +219,8 @@ flags_err:
4696                 if (!capable(CAP_SYS_RESOURCE))
4697                         return -EPERM;
4698  
4699 -               if (IS_RDONLY(inode))
4700 +               if (IS_RDONLY(inode) ||
4701 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4702                         return -EROFS;
4703  
4704                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4705 @@ -233,7 +241,8 @@ flags_err:
4706                 if (!capable(CAP_SYS_RESOURCE))
4707                         return -EPERM;
4708  
4709 -               if (IS_RDONLY(inode))
4710 +               if (IS_RDONLY(inode) ||
4711 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4712                         return -EROFS;
4713  
4714                 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
4715 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
4716 --- linux-2.6.22.10/fs/ext4/namei.c     2007-10-30 01:57:14 +0100
4717 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/namei.c  2007-09-30 14:58:01 +0200
4718 @@ -36,6 +36,7 @@
4719  #include <linux/quotaops.h>
4720  #include <linux/buffer_head.h>
4721  #include <linux/bio.h>
4722 +#include <linux/vs_tag.h>
4723  
4724  #include "namei.h"
4725  #include "xattr.h"
4726 @@ -1050,6 +1051,7 @@ static struct dentry *ext4_lookup(struct
4727  
4728                 if (!inode)
4729                         return ERR_PTR(-EACCES);
4730 +               dx_propagate_tag(nd, inode);
4731         }
4732         return d_splice_alias(inode, dentry);
4733  }
4734 @@ -2441,6 +2443,7 @@ const struct inode_operations ext4_dir_i
4735         .removexattr    = generic_removexattr,
4736  #endif
4737         .permission     = ext4_permission,
4738 +       .sync_flags     = ext4_sync_flags,
4739  };
4740  
4741  const struct inode_operations ext4_special_inode_operations = {
4742 @@ -2452,4 +2455,5 @@ const struct inode_operations ext4_speci
4743         .removexattr    = generic_removexattr,
4744  #endif
4745         .permission     = ext4_permission,
4746 +       .sync_flags     = ext4_sync_flags,
4747  };
4748 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
4749 --- linux-2.6.22.10/fs/ext4/super.c     2007-07-09 13:19:23 +0200
4750 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/super.c  2007-08-05 20:53:12 +0200
4751 @@ -725,7 +725,7 @@ enum {
4752         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4753         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4754         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4755 -       Opt_grpquota, Opt_extents,
4756 +       Opt_grpquota, Opt_extents, Opt_tag, Opt_notag, Opt_tagid
4757  };
4758  
4759  static match_table_t tokens = {
4760 @@ -776,6 +776,9 @@ static match_table_t tokens = {
4761         {Opt_usrquota, "usrquota"},
4762         {Opt_barrier, "barrier=%u"},
4763         {Opt_extents, "extents"},
4764 +       {Opt_tag, "tag"},
4765 +       {Opt_notag, "notag"},
4766 +       {Opt_tagid, "tagid=%u"},
4767         {Opt_err, NULL},
4768         {Opt_resize, "resize"},
4769  };
4770 @@ -869,6 +872,20 @@ static int parse_options (char *options,
4771                 case Opt_nouid32:
4772                         set_opt (sbi->s_mount_opt, NO_UID32);
4773                         break;
4774 +#ifndef CONFIG_TAGGING_NONE
4775 +               case Opt_tag:
4776 +                       set_opt (sbi->s_mount_opt, TAGGED);
4777 +                       break;
4778 +               case Opt_notag:
4779 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4780 +                       break;
4781 +#endif
4782 +#ifdef CONFIG_PROPAGATE
4783 +               case Opt_tagid:
4784 +                       /* use args[0] */
4785 +                       set_opt (sbi->s_mount_opt, TAGGED);
4786 +                       break;
4787 +#endif
4788                 case Opt_nocheck:
4789                         clear_opt (sbi->s_mount_opt, CHECK);
4790                         break;
4791 @@ -1546,6 +1563,9 @@ static int ext4_fill_super (struct super
4792                             NULL, 0))
4793                 goto failed_mount;
4794  
4795 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
4796 +               sb->s_flags |= MS_TAGGED;
4797 +
4798         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4799                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4800  
4801 @@ -2377,6 +2397,12 @@ static int ext4_remount (struct super_bl
4802  
4803         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
4804                 ext4_abort(sb, __FUNCTION__, "Abort forced by user");
4805 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
4806 +               !(sb->s_flags & MS_TAGGED)) {
4807 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
4808 +                       sb->s_id);
4809 +               return -EINVAL;
4810 +       }
4811  
4812         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4813                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4814 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
4815 --- linux-2.6.22.10/fs/ext4/symlink.c   2007-05-02 19:25:17 +0200
4816 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/symlink.c        2007-08-05 20:53:12 +0200
4817 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
4818         .listxattr      = ext4_listxattr,
4819         .removexattr    = generic_removexattr,
4820  #endif
4821 +       .sync_flags     = ext4_sync_flags,
4822  };
4823  
4824  const struct inode_operations ext4_fast_symlink_inode_operations = {
4825 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
4826         .listxattr      = ext4_listxattr,
4827         .removexattr    = generic_removexattr,
4828  #endif
4829 +       .sync_flags     = ext4_sync_flags,
4830  };
4831 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
4832 --- linux-2.6.22.10/fs/ext4/xattr.c     2007-05-02 19:25:17 +0200
4833 +++ linux-2.6.22.10-vs2.3.0.29/fs/ext4/xattr.c  2007-08-05 20:53:12 +0200
4834 @@ -58,6 +58,7 @@
4835  #include <linux/mbcache.h>
4836  #include <linux/quotaops.h>
4837  #include <linux/rwsem.h>
4838 +#include <linux/vs_dlimit.h>
4839  #include "xattr.h"
4840  #include "acl.h"
4841  
4842 @@ -496,6 +497,7 @@ ext4_xattr_release_block(handle_t *handl
4843                 error = ext4_journal_dirty_metadata(handle, bh);
4844                 if (IS_SYNC(inode))
4845                         handle->h_sync = 1;
4846 +                       DLIMIT_FREE_BLOCK(inode, 1);
4847                 DQUOT_FREE_BLOCK(inode, 1);
4848                 ea_bdebug(bh, "refcount now=%d; releasing",
4849                           le32_to_cpu(BHDR(bh)->h_refcount));
4850 @@ -769,11 +771,14 @@ inserted:
4851                         if (new_bh == bs->bh)
4852                                 ea_bdebug(new_bh, "keeping");
4853                         else {
4854 +                               error = -ENOSPC;
4855 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4856 +                                       goto cleanup;
4857                                 /* The old block is released after updating
4858                                    the inode. */
4859                                 error = -EDQUOT;
4860                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4861 -                                       goto cleanup;
4862 +                                       goto cleanup_dlimit;
4863                                 error = ext4_journal_get_write_access(handle,
4864                                                                       new_bh);
4865                                 if (error)
4866 @@ -850,6 +855,8 @@ cleanup:
4867  
4868  cleanup_dquot:
4869         DQUOT_FREE_BLOCK(inode, 1);
4870 +cleanup_dlimit:
4871 +       DLIMIT_FREE_BLOCK(inode, 1);
4872         goto cleanup;
4873  
4874  bad_block:
4875 diff -NurpP --minimal linux-2.6.22.10/fs/fcntl.c linux-2.6.22.10-vs2.3.0.29/fs/fcntl.c
4876 --- linux-2.6.22.10/fs/fcntl.c  2007-02-06 03:01:18 +0100
4877 +++ linux-2.6.22.10-vs2.3.0.29/fs/fcntl.c       2007-08-05 20:53:12 +0200
4878 @@ -18,6 +18,7 @@
4879  #include <linux/ptrace.h>
4880  #include <linux/signal.h>
4881  #include <linux/rcupdate.h>
4882 +#include <linux/vs_limit.h>
4883  
4884  #include <asm/poll.h>
4885  #include <asm/siginfo.h>
4886 @@ -84,6 +85,8 @@ repeat:
4887         error = -EMFILE;
4888         if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
4889                 goto out;
4890 +       if (!vx_files_avail(1))
4891 +               goto out;
4892  
4893         error = expand_files(files, newfd);
4894         if (error < 0)
4895 @@ -124,6 +127,7 @@ static int dupfd(struct file *file, unsi
4896                 FD_SET(fd, fdt->open_fds);
4897                 FD_CLR(fd, fdt->close_on_exec);
4898                 spin_unlock(&files->file_lock);
4899 +               vx_openfd_inc(fd);
4900                 fd_install(fd, file);
4901         } else {
4902                 spin_unlock(&files->file_lock);
4903 @@ -176,6 +180,9 @@ asmlinkage long sys_dup2(unsigned int ol
4904  
4905         if (tofree)
4906                 filp_close(tofree, files);
4907 +       else
4908 +               vx_openfd_inc(newfd);   /* fd was unused */
4909 +
4910         err = newfd;
4911  out:
4912         return err;
4913 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
4914 --- linux-2.6.22.10/fs/file_table.c     2007-07-09 13:19:23 +0200
4915 +++ linux-2.6.22.10-vs2.3.0.29/fs/file_table.c  2007-08-05 20:53:12 +0200
4916 @@ -20,6 +20,8 @@
4917  #include <linux/fsnotify.h>
4918  #include <linux/sysctl.h>
4919  #include <linux/percpu_counter.h>
4920 +#include <linux/vs_limit.h>
4921 +#include <linux/vs_context.h>
4922  
4923  #include <asm/atomic.h>
4924  
4925 @@ -119,6 +121,8 @@ struct file *get_empty_filp(void)
4926         f->f_gid = tsk->fsgid;
4927         eventpoll_init_file(f);
4928         /* f->f_version: 0 */
4929 +       f->f_xid = vx_current_xid();
4930 +       vx_files_inc(f);
4931         return f;
4932  
4933  over:
4934 @@ -174,6 +178,8 @@ void fastcall __fput(struct file *file)
4935         if (file->f_mode & FMODE_WRITE)
4936                 put_write_access(inode);
4937         put_pid(file->f_owner.pid);
4938 +       vx_files_dec(file);
4939 +       file->f_xid = 0;
4940         file_kill(file);
4941         file->f_path.dentry = NULL;
4942         file->f_path.mnt = NULL;
4943 @@ -239,6 +245,8 @@ void put_filp(struct file *file)
4944  {
4945         if (atomic_dec_and_test(&file->f_count)) {
4946                 security_file_free(file);
4947 +               vx_files_dec(file);
4948 +               file->f_xid = 0;
4949                 file_kill(file);
4950                 file_free(file);
4951         }
4952 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
4953 --- linux-2.6.22.10/fs/hfsplus/ioctl.c  2006-11-30 21:19:25 +0100
4954 +++ linux-2.6.22.10-vs2.3.0.29/fs/hfsplus/ioctl.c       2007-08-05 20:53:12 +0200
4955 @@ -16,6 +16,7 @@
4956  #include <linux/fs.h>
4957  #include <linux/sched.h>
4958  #include <linux/xattr.h>
4959 +#include <linux/mount.h>
4960  #include <asm/uaccess.h>
4961  #include "hfsplus_fs.h"
4962  
4963 @@ -35,7 +36,8 @@ int hfsplus_ioctl(struct inode *inode, s
4964                         flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
4965                 return put_user(flags, (int __user *)arg);
4966         case HFSPLUS_IOC_EXT2_SETFLAGS: {
4967 -               if (IS_RDONLY(inode))
4968 +               if (IS_RDONLY(inode) ||
4969 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4970                         return -EROFS;
4971  
4972                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4973 diff -NurpP --minimal linux-2.6.22.10/fs/inode.c linux-2.6.22.10-vs2.3.0.29/fs/inode.c
4974 --- linux-2.6.22.10/fs/inode.c  2007-07-09 13:19:24 +0200
4975 +++ linux-2.6.22.10-vs2.3.0.29/fs/inode.c       2007-10-11 01:10:22 +0200
4976 @@ -115,6 +115,9 @@ static struct inode *alloc_inode(struct 
4977                 struct address_space * const mapping = &inode->i_data;
4978  
4979                 inode->i_sb = sb;
4980 +
4981 +               /* essential because of inode slab reuse */
4982 +               inode->i_tag = 0;
4983                 inode->i_blkbits = sb->s_blocksize_bits;
4984                 inode->i_flags = 0;
4985                 atomic_set(&inode->i_count, 1);
4986 @@ -133,6 +136,7 @@ static struct inode *alloc_inode(struct 
4987                 inode->i_bdev = NULL;
4988                 inode->i_cdev = NULL;
4989                 inode->i_rdev = 0;
4990 +               inode->i_mdev = 0;
4991                 inode->dirtied_when = 0;
4992                 if (security_inode_alloc(inode)) {
4993                         if (inode->i_sb->s_op->destroy_inode)
4994 @@ -231,6 +235,8 @@ void __iget(struct inode * inode)
4995         inodes_stat.nr_unused--;
4996  }
4997  
4998 +EXPORT_SYMBOL_GPL(__iget);
4999 +
5000  /**
5001   * clear_inode - clear an inode
5002   * @inode: inode to clear
5003 @@ -1405,9 +1411,11 @@ void init_special_inode(struct inode *in
5004         if (S_ISCHR(mode)) {
5005                 inode->i_fop = &def_chr_fops;
5006                 inode->i_rdev = rdev;
5007 +               inode->i_mdev = rdev;
5008         } else if (S_ISBLK(mode)) {
5009                 inode->i_fop = &def_blk_fops;
5010                 inode->i_rdev = rdev;
5011 +               inode->i_mdev = rdev;
5012         } else if (S_ISFIFO(mode))
5013                 inode->i_fop = &def_fifo_fops;
5014         else if (S_ISSOCK(mode))
5015 diff -NurpP --minimal linux-2.6.22.10/fs/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/ioctl.c
5016 --- linux-2.6.22.10/fs/ioctl.c  2007-07-09 13:19:24 +0200
5017 +++ linux-2.6.22.10-vs2.3.0.29/fs/ioctl.c       2007-08-05 20:53:12 +0200
5018 @@ -13,6 +13,9 @@
5019  #include <linux/security.h>
5020  #include <linux/module.h>
5021  #include <linux/kallsyms.h>
5022 +#include <linux/proc_fs.h>
5023 +#include <linux/vserver/inode.h>
5024 +#include <linux/vs_tag.h>
5025  
5026  #include <asm/uaccess.h>
5027  #include <asm/ioctls.h>
5028 diff -NurpP --minimal linux-2.6.22.10/fs/ioprio.c linux-2.6.22.10-vs2.3.0.29/fs/ioprio.c
5029 --- linux-2.6.22.10/fs/ioprio.c 2007-05-02 19:25:18 +0200
5030 +++ linux-2.6.22.10-vs2.3.0.29/fs/ioprio.c      2007-08-05 20:53:12 +0200
5031 @@ -25,6 +25,7 @@
5032  #include <linux/capability.h>
5033  #include <linux/syscalls.h>
5034  #include <linux/security.h>
5035 +#include <linux/vs_base.h>
5036  
5037  static int set_task_ioprio(struct task_struct *task, int ioprio)
5038  {
5039 @@ -103,6 +104,8 @@ asmlinkage long sys_ioprio_set(int which
5040                         else
5041                                 pgrp = find_pid(who);
5042                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
5043 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5044 +                                       continue;
5045                                 ret = set_task_ioprio(p, ioprio);
5046                                 if (ret)
5047                                         break;
5048 @@ -112,7 +115,7 @@ asmlinkage long sys_ioprio_set(int which
5049                         if (!who)
5050                                 user = current->user;
5051                         else
5052 -                               user = find_user(who);
5053 +                               user = find_user(vx_current_xid(), who);
5054  
5055                         if (!user)
5056                                 break;
5057 @@ -190,6 +193,8 @@ asmlinkage long sys_ioprio_get(int which
5058                         else
5059                                 pgrp = find_pid(who);
5060                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
5061 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5062 +                                       continue;
5063                                 tmpio = get_task_ioprio(p);
5064                                 if (tmpio < 0)
5065                                         continue;
5066 @@ -203,7 +208,7 @@ asmlinkage long sys_ioprio_get(int which
5067                         if (!who)
5068                                 user = current->user;
5069                         else
5070 -                               user = find_user(who);
5071 +                               user = find_user(vx_current_xid(), who);
5072  
5073                         if (!user)
5074                                 break;
5075 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
5076 --- linux-2.6.22.10/fs/jffs2/dir.c      2007-07-09 13:19:26 +0200
5077 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/dir.c   2007-10-05 15:07:22 +0200
5078 @@ -32,7 +32,9 @@ static int jffs2_mkdir (struct inode *,s
5079  static int jffs2_rmdir (struct inode *,struct dentry *);
5080  static int jffs2_mknod (struct inode *,struct dentry *,int,dev_t);
5081  static int jffs2_rename (struct inode *, struct dentry *,
5082 -                        struct inode *, struct dentry *);
5083 +                        struct inode *, struct dentry *);
5084 +
5085 +extern int jffs2_sync_flags(struct inode *);
5086  
5087  const struct file_operations jffs2_dir_operations =
5088  {
5089 @@ -56,6 +58,7 @@ const struct inode_operations jffs2_dir_
5090         .rename =       jffs2_rename,
5091         .permission =   jffs2_permission,
5092         .setattr =      jffs2_setattr,
5093 +       .sync_flags =   jffs2_sync_flags,
5094         .setxattr =     jffs2_setxattr,
5095         .getxattr =     jffs2_getxattr,
5096         .listxattr =    jffs2_listxattr,
5097 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
5098 --- linux-2.6.22.10/fs/jffs2/file.c     2007-07-09 13:19:26 +0200
5099 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/file.c  2007-10-01 20:52:25 +0200
5100 @@ -17,6 +17,7 @@
5101  #include <linux/highmem.h>
5102  #include <linux/crc32.h>
5103  #include <linux/jffs2.h>
5104 +#include <linux/vs_tag.h>
5105  #include "nodelist.h"
5106  
5107  static int jffs2_commit_write (struct file *filp, struct page *pg,
5108 @@ -25,6 +26,9 @@ static int jffs2_prepare_write (struct f
5109                                 unsigned start, unsigned end);
5110  static int jffs2_readpage (struct file *filp, struct page *pg);
5111  
5112 +extern int jffs2_sync_flags(struct inode *);
5113 +
5114 +
5115  int jffs2_fsync(struct file *filp, struct dentry *dentry, int datasync)
5116  {
5117         struct inode *inode = dentry->d_inode;
5118 @@ -47,7 +51,9 @@ const struct file_operations jffs2_file_
5119         .ioctl =        jffs2_ioctl,
5120         .mmap =         generic_file_readonly_mmap,
5121         .fsync =        jffs2_fsync,
5122 -       .sendfile =     generic_file_sendfile
5123 +       .sendfile =     generic_file_sendfile,
5124 +       .splice_read =  generic_file_splice_read,
5125 +       .splice_write = generic_file_splice_write
5126  };
5127  
5128  /* jffs2_file_inode_operations */
5129 @@ -56,6 +62,7 @@ const struct inode_operations jffs2_file
5130  {
5131         .permission =   jffs2_permission,
5132         .setattr =      jffs2_setattr,
5133 +       .sync_flags =   jffs2_sync_flags,
5134         .setxattr =     jffs2_setxattr,
5135         .getxattr =     jffs2_getxattr,
5136         .listxattr =    jffs2_listxattr,
5137 @@ -157,12 +164,14 @@ static int jffs2_prepare_write (struct f
5138                 ri.mode = cpu_to_jemode(inode->i_mode);
5139                 ri.uid = cpu_to_je16(inode->i_uid);
5140                 ri.gid = cpu_to_je16(inode->i_gid);
5141 +               ri.tag = cpu_to_je16(TAGINO_TAG(DX_TAG(inode), inode->i_tag));
5142                 ri.isize = cpu_to_je32(max((uint32_t)inode->i_size, pageofs));
5143                 ri.atime = ri.ctime = ri.mtime = cpu_to_je32(get_seconds());
5144                 ri.offset = cpu_to_je32(inode->i_size);
5145                 ri.dsize = cpu_to_je32(pageofs - inode->i_size);
5146                 ri.csize = cpu_to_je32(0);
5147                 ri.compr = JFFS2_COMPR_ZERO;
5148 +               ri.flags = cpu_to_je16(f->flags);
5149                 ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
5150                 ri.data_crc = cpu_to_je32(0);
5151  
5152 @@ -248,8 +257,10 @@ static int jffs2_commit_write (struct fi
5153         ri->mode = cpu_to_jemode(inode->i_mode);
5154         ri->uid = cpu_to_je16(inode->i_uid);
5155         ri->gid = cpu_to_je16(inode->i_gid);
5156 +       ri->tag = cpu_to_je16(TAGINO_TAG(DX_TAG(inode), inode->i_tag));
5157         ri->isize = cpu_to_je32((uint32_t)inode->i_size);
5158         ri->atime = ri->ctime = ri->mtime = cpu_to_je32(get_seconds());
5159 +       ri->flags = cpu_to_je16(f->flags);
5160  
5161         /* In 2.4, it was already kmapped by generic_file_write(). Doesn't
5162            hurt to do it again. The alternative is ifdefs, which are ugly. */
5163 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
5164 --- linux-2.6.22.10/fs/jffs2/fs.c       2007-10-30 01:57:14 +0100
5165 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/fs.c    2007-09-30 14:58:01 +0200
5166 @@ -20,6 +20,7 @@
5167  #include <linux/vmalloc.h>
5168  #include <linux/vfs.h>
5169  #include <linux/crc32.h>
5170 +#include <linux/vs_tag.h>
5171  #include "nodelist.h"
5172  
5173  static int jffs2_flash_setup(struct jffs2_sb_info *c);
5174 @@ -97,6 +98,7 @@ static int jffs2_do_setattr (struct inod
5175  
5176         ri->uid = cpu_to_je16((ivalid & ATTR_UID)?iattr->ia_uid:inode->i_uid);
5177         ri->gid = cpu_to_je16((ivalid & ATTR_GID)?iattr->ia_gid:inode->i_gid);
5178 +       ri->tag = cpu_to_je16((ivalid & ATTR_TAG)?iattr->ia_tag:inode->i_tag);
5179  
5180         if (ivalid & ATTR_MODE)
5181                 if (iattr->ia_mode & S_ISGID &&
5182 @@ -116,6 +118,8 @@ static int jffs2_do_setattr (struct inod
5183         ri->offset = cpu_to_je32(0);
5184         ri->csize = ri->dsize = cpu_to_je32(mdatalen);
5185         ri->compr = JFFS2_COMPR_NONE;
5186 +       ri->flags = cpu_to_je16(f->flags);
5187 +
5188         if (ivalid & ATTR_SIZE && inode->i_size < iattr->ia_size) {
5189                 /* It's an extension. Make it a hole node */
5190                 ri->compr = JFFS2_COMPR_ZERO;
5191 @@ -145,6 +149,7 @@ static int jffs2_do_setattr (struct inod
5192         inode->i_mode = jemode_to_cpu(ri->mode);
5193         inode->i_uid = je16_to_cpu(ri->uid);
5194         inode->i_gid = je16_to_cpu(ri->gid);
5195 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0, je16_to_cpu(ri->tag));
5196  
5197  
5198         old_metadata = f->metadata;
5199 @@ -179,6 +184,48 @@ static int jffs2_do_setattr (struct inod
5200         return 0;
5201  }
5202  
5203 +void jffs2_set_inode_flags(struct inode *inode)
5204 +{
5205 +       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
5206 +       unsigned int flags = f->flags;
5207 +
5208 +       inode->i_flags &= ~(JFFS2_INO_FLAG_IMMUTABLE |
5209 +               JFFS2_INO_FLAG_IUNLINK | JFFS2_INO_FLAG_BARRIER);
5210 +
5211 +       if (flags & JFFS2_INO_FLAG_IMMUTABLE)
5212 +               inode->i_flags |= S_IMMUTABLE;
5213 +       if (flags & JFFS2_INO_FLAG_IUNLINK)
5214 +               inode->i_flags |= S_IUNLINK;
5215 +       if (flags & JFFS2_INO_FLAG_BARRIER)
5216 +               inode->i_flags |= S_BARRIER;
5217 +}
5218 +
5219 +int jffs2_sync_flags(struct inode *inode)
5220 +{
5221 +       struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
5222 +       unsigned int oldflags, newflags;
5223 +
5224 +       oldflags = f->flags;
5225 +       newflags = oldflags & ~(JFFS2_INO_FLAG_IMMUTABLE |
5226 +               JFFS2_INO_FLAG_IUNLINK | JFFS2_INO_FLAG_BARRIER);
5227 +
5228 +       if (IS_IMMUTABLE(inode))
5229 +               newflags |= JFFS2_INO_FLAG_IMMUTABLE;
5230 +       if (IS_IUNLINK(inode))
5231 +               newflags |= JFFS2_INO_FLAG_IUNLINK;
5232 +       if (IS_BARRIER(inode))
5233 +               newflags |= JFFS2_INO_FLAG_BARRIER;
5234 +
5235 +       if (oldflags ^ newflags) {
5236 +               f->flags = newflags;
5237 +               inode->i_ctime = CURRENT_TIME;
5238 +               /* strange requirement, see jffs2_dirty_inode() */
5239 +               inode->i_state |= I_DIRTY_DATASYNC;
5240 +               mark_inode_dirty(inode);
5241 +       }
5242 +       return 0;
5243 +}
5244 +
5245  int jffs2_setattr(struct dentry *dentry, struct iattr *iattr)
5246  {
5247         int rc;
5248 @@ -254,6 +301,8 @@ void jffs2_read_inode (struct inode *ino
5249         inode->i_mode = jemode_to_cpu(latest_node.mode);
5250         inode->i_uid = je16_to_cpu(latest_node.uid);
5251         inode->i_gid = je16_to_cpu(latest_node.gid);
5252 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0,
5253 +               je16_to_cpu(latest_node.tag));
5254         inode->i_size = je32_to_cpu(latest_node.isize);
5255         inode->i_atime = ITIME(je32_to_cpu(latest_node.atime));
5256         inode->i_mtime = ITIME(je32_to_cpu(latest_node.mtime));
5257 @@ -285,6 +334,7 @@ void jffs2_read_inode (struct inode *ino
5258  
5259                 inode->i_op = &jffs2_dir_inode_operations;
5260                 inode->i_fop = &jffs2_dir_operations;
5261 +               f->flags = je16_to_cpu(latest_node.flags);
5262                 break;
5263         }
5264         case S_IFREG:
5265 @@ -292,6 +342,7 @@ void jffs2_read_inode (struct inode *ino
5266                 inode->i_fop = &jffs2_file_operations;
5267                 inode->i_mapping->a_ops = &jffs2_file_address_operations;
5268                 inode->i_mapping->nrpages = 0;
5269 +               f->flags = je16_to_cpu(latest_node.flags);
5270                 break;
5271  
5272         case S_IFBLK:
5273 @@ -328,7 +379,7 @@ void jffs2_read_inode (struct inode *ino
5274         default:
5275                 printk(KERN_WARNING "jffs2_read_inode(): Bogus imode %o for ino %lu\n", inode->i_mode, (unsigned long)inode->i_ino);
5276         }
5277 -
5278 +       jffs2_set_inode_flags(inode);
5279         up(&f->sem);
5280  
5281         D1(printk(KERN_DEBUG "jffs2_read_inode() returning\n"));
5282 @@ -345,10 +396,11 @@ void jffs2_dirty_inode(struct inode *ino
5283  
5284         D1(printk(KERN_DEBUG "jffs2_dirty_inode() calling setattr() for ino #%lu\n", inode->i_ino));
5285  
5286 -       iattr.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_MTIME|ATTR_CTIME;
5287 +       iattr.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_ATIME|ATTR_MTIME|ATTR_CTIME|ATTR_TAG;
5288         iattr.ia_mode = inode->i_mode;
5289         iattr.ia_uid = inode->i_uid;
5290         iattr.ia_gid = inode->i_gid;
5291 +       iattr.ia_tag = inode->i_tag;
5292         iattr.ia_atime = inode->i_atime;
5293         iattr.ia_mtime = inode->i_mtime;
5294         iattr.ia_ctime = inode->i_ctime;
5295 @@ -422,6 +474,7 @@ struct inode *jffs2_new_inode (struct in
5296  
5297         memset(ri, 0, sizeof(*ri));
5298         /* Set OS-specific defaults for new inodes */
5299 +       ri->tag = cpu_to_je16(dx_current_tag());
5300         ri->uid = cpu_to_je16(current->fsuid);
5301  
5302         if (dir_i->i_mode & S_ISGID) {
5303 @@ -443,14 +496,16 @@ struct inode *jffs2_new_inode (struct in
5304         inode->i_mode = jemode_to_cpu(ri->mode);
5305         inode->i_gid = je16_to_cpu(ri->gid);
5306         inode->i_uid = je16_to_cpu(ri->uid);
5307 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), 0, 0, je16_to_cpu(ri->tag));
5308         inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
5309         ri->atime = ri->mtime = ri->ctime = cpu_to_je32(I_SEC(inode->i_mtime));
5310  
5311         inode->i_blocks = 0;
5312         inode->i_size = 0;
5313  
5314 +       f->flags = je16_to_cpu(ri->flags);
5315 +       jffs2_set_inode_flags(inode);
5316         insert_inode_hash(inode);
5317 -
5318         return inode;
5319  }
5320  
5321 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
5322 --- linux-2.6.22.10/fs/jffs2/gc.c       2007-07-09 13:19:26 +0200
5323 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/gc.c    2007-08-05 20:53:12 +0200
5324 @@ -735,6 +735,7 @@ static int jffs2_garbage_collect_metadat
5325         ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5326         ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5327         ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5328 +       ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5329         ri.isize = cpu_to_je32(ilen);
5330         ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5331         ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5332 @@ -998,6 +999,7 @@ static int jffs2_garbage_collect_hole(st
5333         ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5334         ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5335         ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5336 +       ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5337         ri.isize = cpu_to_je32(ilen);
5338         ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5339         ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5340 @@ -1256,6 +1258,7 @@ static int jffs2_garbage_collect_dnode(s
5341                 ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f));
5342                 ri.uid = cpu_to_je16(JFFS2_F_I_UID(f));
5343                 ri.gid = cpu_to_je16(JFFS2_F_I_GID(f));
5344 +               ri.tag = cpu_to_je16(JFFS2_F_I_TAG(f));
5345                 ri.isize = cpu_to_je32(JFFS2_F_I_SIZE(f));
5346                 ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f));
5347                 ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f));
5348 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
5349 --- linux-2.6.22.10/fs/jffs2/ioctl.c    2007-07-09 13:19:26 +0200
5350 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/ioctl.c 2007-08-05 20:53:12 +0200
5351 @@ -10,12 +10,67 @@
5352   */
5353  
5354  #include <linux/fs.h>
5355 +#include <linux/types.h>
5356 +#include <linux/mount.h>
5357 +#include <linux/jffs2.h>
5358 +#include <linux/uaccess.h>
5359 +#include <linux/vs_base.h>
5360 +#include "jffs2_fs_sb.h"
5361 +#include "jffs2_fs_i.h"
5362 +#include "acl.h"
5363 +#include "os-linux.h"
5364 +
5365 +extern void jffs2_set_inode_flags(struct inode *);
5366  
5367  int jffs2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
5368                 unsigned long arg)
5369  {
5370 -       /* Later, this will provide for lsattr.jffs2 and chattr.jffs2, which
5371 -          will include compression support etc. */
5372 -       return -ENOTTY;
5373 +       struct jffs2_inode_info *j = JFFS2_INODE_INFO(inode);
5374 +       unsigned int flags, oldflags, newflags;
5375 +
5376 +       switch (cmd) {
5377 +       case JFFS2_IOC_GETFLAGS:
5378 +               flags = j->flags & JFFS2_USER_VISIBLE;
5379 +               return put_user(flags, (int __user *) arg);
5380 +
5381 +       case JFFS2_IOC_SETFLAGS:
5382 +               if (IS_RDONLY(inode) ||
5383 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
5384 +                       return -EROFS;
5385 +
5386 +               if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
5387 +                       return -EACCES;
5388 +
5389 +               if (get_user(flags, (int __user *) arg))
5390 +                       return -EFAULT;
5391 +
5392 +               oldflags = j->flags;
5393 +               newflags = flags & JFFS2_USER_MODIFIABLE;
5394 +               newflags |= oldflags & ~JFFS2_USER_MODIFIABLE;
5395 +
5396 +               /*
5397 +                * The IMMUTABLE flags can only be changed by
5398 +                * the relevant capability.
5399 +                */
5400 +               if (((oldflags ^ newflags) &
5401 +                       (JFFS2_INO_FLAG_IMMUTABLE | JFFS2_INO_FLAG_IUNLINK)) ||
5402 +                       (oldflags & JFFS2_INO_FLAG_IMMUTABLE)) {
5403 +                       if (!capable(CAP_LINUX_IMMUTABLE))
5404 +                               return -EPERM;
5405 +               }
5406 +
5407 +               if (oldflags ^ newflags) {
5408 +                       j->flags = newflags;
5409 +                       inode->i_ctime = CURRENT_TIME;
5410 +                       /* strange requirement, see jffs2_dirty_inode() */
5411 +                       inode->i_state |= I_DIRTY_DATASYNC;
5412 +                       mark_inode_dirty(inode);
5413 +                       jffs2_set_inode_flags(inode);
5414 +               }
5415 +               return 0;
5416 +
5417 +       default:
5418 +               return -ENOTTY;
5419 +       }
5420  }
5421  
5422 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
5423 --- linux-2.6.22.10/fs/jffs2/jffs2_fs_sb.h      2007-07-09 13:19:26 +0200
5424 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/jffs2_fs_sb.h   2007-08-05 20:53:12 +0200
5425 @@ -39,6 +39,7 @@ struct jffs2_sb_info {
5426         uint32_t checked_ino;
5427  
5428         unsigned int flags;
5429 +       unsigned int s_mount_opt;
5430  
5431         struct task_struct *gc_task;    /* GC task struct */
5432         struct completion gc_thread_start; /* GC thread start completion */
5433 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
5434 --- linux-2.6.22.10/fs/jffs2/nodelist.h 2007-07-09 13:19:26 +0200
5435 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/nodelist.h      2007-08-05 20:53:12 +0200
5436 @@ -47,25 +47,25 @@
5437  #elif defined(JFFS2_BIG_ENDIAN)
5438  #define cpu_to_je16(x) ((jint16_t){cpu_to_be16(x)})
5439  #define cpu_to_je32(x) ((jint32_t){cpu_to_be32(x)})
5440 -#define cpu_to_jemode(x) ((jmode_t){cpu_to_be32(os_to_jffs2_mode(x))})
5441 +#define cpu_to_jemode(x) ((jmode_t){cpu_to_be16(os_to_jffs2_mode(x))})
5442  
5443  #define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_be16(x)})
5444  #define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_be32(x)})
5445  
5446  #define je16_to_cpu(x) (be16_to_cpu(x.v16))
5447  #define je32_to_cpu(x) (be32_to_cpu(x.v32))
5448 -#define jemode_to_cpu(x) (be32_to_cpu(jffs2_to_os_mode((x).m)))
5449 +#define jemode_to_cpu(x) (be16_to_cpu(jffs2_to_os_mode((x).m)))
5450  #elif defined(JFFS2_LITTLE_ENDIAN)
5451  #define cpu_to_je16(x) ((jint16_t){cpu_to_le16(x)})
5452  #define cpu_to_je32(x) ((jint32_t){cpu_to_le32(x)})
5453 -#define cpu_to_jemode(x) ((jmode_t){cpu_to_le32(os_to_jffs2_mode(x))})
5454 +#define cpu_to_jemode(x) ((jmode_t){cpu_to_le16(os_to_jffs2_mode(x))})
5455  
5456  #define constant_cpu_to_je16(x) ((jint16_t){__constant_cpu_to_le16(x)})
5457  #define constant_cpu_to_je32(x) ((jint32_t){__constant_cpu_to_le32(x)})
5458  
5459  #define je16_to_cpu(x) (le16_to_cpu(x.v16))
5460  #define je32_to_cpu(x) (le32_to_cpu(x.v32))
5461 -#define jemode_to_cpu(x) (le32_to_cpu(jffs2_to_os_mode((x).m)))
5462 +#define jemode_to_cpu(x) (le16_to_cpu(jffs2_to_os_mode((x).m)))
5463  #else
5464  #error wibble
5465  #endif
5466 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
5467 --- linux-2.6.22.10/fs/jffs2/os-linux.h 2007-07-09 13:19:26 +0200
5468 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/os-linux.h      2007-08-05 20:53:12 +0200
5469 @@ -29,6 +29,7 @@ struct kvec;
5470  #define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
5471  #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
5472  #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
5473 +#define JFFS2_F_I_TAG(f) (OFNI_EDONI_2SFFJ(f)->i_tag)
5474  #define JFFS2_F_I_RDEV(f) (OFNI_EDONI_2SFFJ(f)->i_rdev)
5475  
5476  #define ITIME(sec) ((struct timespec){sec, 0})
5477 @@ -204,6 +205,9 @@ int jffs2_flash_direct_writev(struct jff
5478  int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
5479                         size_t *retlen, const u_char *buf);
5480  
5481 +#define JFFS2_IOC_GETFLAGS             FS_IOC_GETFLAGS
5482 +#define JFFS2_IOC_SETFLAGS             FS_IOC_SETFLAGS
5483 +
5484  #endif /* __JFFS2_OS_LINUX_H__ */
5485  
5486  
5487 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
5488 --- linux-2.6.22.10/fs/jffs2/readinode.c        2007-07-09 13:19:26 +0200
5489 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/readinode.c     2007-08-05 20:53:12 +0200
5490 @@ -1182,6 +1182,8 @@ static int jffs2_do_read_inode_internal(
5491                 latest_node->isize = cpu_to_je32(0);
5492                 latest_node->gid = cpu_to_je16(0);
5493                 latest_node->uid = cpu_to_je16(0);
5494 +               latest_node->tag = cpu_to_je16(0);
5495 +               latest_node->flags = cpu_to_je16(0);
5496                 if (f->inocache->state == INO_STATE_READING)
5497                         jffs2_set_inocache_state(c, f->inocache, INO_STATE_PRESENT);
5498                 return 0;
5499 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
5500 --- linux-2.6.22.10/fs/jffs2/super.c    2007-07-09 13:19:26 +0200
5501 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/super.c 2007-08-05 20:53:12 +0200
5502 @@ -22,6 +22,7 @@
5503  #include <linux/mtd/super.h>
5504  #include <linux/ctype.h>
5505  #include <linux/namei.h>
5506 +#include <linux/parser.h>
5507  #include "compr.h"
5508  #include "nodelist.h"
5509  
5510 @@ -75,6 +76,49 @@ static const struct super_operations jff
5511         .sync_fs =      jffs2_sync_fs,
5512  };
5513  
5514 +enum {
5515 +       Opt_tag, Opt_notag, Opt_ignore, Opt_err
5516 +};
5517 +
5518 +static match_table_t tokens = {
5519 +       {Opt_tag, "tag"},
5520 +       {Opt_notag, "notag"},
5521 +       {Opt_err, NULL}
5522 +};
5523 +
5524 +static int parse_options (char * options,
5525 +                         struct jffs2_sb_info *sbi)
5526 +{
5527 +       char * p;
5528 +       substring_t args[MAX_OPT_ARGS];
5529 +
5530 +       if (!options)
5531 +               return 1;
5532 +
5533 +       while ((p = strsep (&options, ",")) != NULL) {
5534 +               int token;
5535 +               if (!*p)
5536 +                       continue;
5537 +
5538 +               token = match_token(p, tokens, args);
5539 +               switch (token) {
5540 +#ifndef CONFIG_TAGGING_NONE
5541 +               case Opt_tag:
5542 +                       set_opt (sbi->s_mount_opt, TAGGED);
5543 +                       break;
5544 +               case Opt_notag:
5545 +                       clear_opt (sbi->s_mount_opt, TAGGED);
5546 +                       break;
5547 +#endif
5548 +               case Opt_ignore:
5549 +                       break;
5550 +               default:
5551 +                       return 0;
5552 +               }
5553 +       }
5554 +       return 1;
5555 +}
5556 +
5557  /*
5558   * fill in the superblock
5559   */
5560 @@ -109,6 +153,12 @@ static int jffs2_fill_super(struct super
5561  #ifdef CONFIG_JFFS2_FS_POSIX_ACL
5562         sb->s_flags |= MS_POSIXACL;
5563  #endif
5564 +       if (!parse_options ((char *) data, c))
5565 +               return -EINVAL;
5566 +
5567 +       if (c->s_mount_opt & JFFS2_MOUNT_TAGGED)
5568 +               sb->s_flags |= MS_TAGGED;
5569 +
5570         return jffs2_do_fill_super(sb, data, silent);
5571  }
5572  
5573 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
5574 --- linux-2.6.22.10/fs/jffs2/write.c    2007-10-30 01:57:14 +0100
5575 +++ linux-2.6.22.10-vs2.3.0.29/fs/jffs2/write.c 2007-09-05 03:06:11 +0200
5576 @@ -44,6 +44,7 @@ int jffs2_do_new_inode(struct jffs2_sb_i
5577         ri->totlen = cpu_to_je32(PAD(sizeof(*ri)));
5578         ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
5579         ri->mode = cpu_to_jemode(mode);
5580 +       ri->flags = cpu_to_je16(0);
5581  
5582         f->highest_version = 1;
5583         ri->version = cpu_to_je32(f->highest_version);
5584 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
5585 --- linux-2.6.22.10/fs/jfs/acl.c        2006-11-30 21:19:25 +0100
5586 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/acl.c     2007-08-05 20:53:12 +0200
5587 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
5588                 return rc;
5589  
5590         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
5591 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
5592 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
5593 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
5594                 if (DQUOT_TRANSFER(inode, iattr))
5595                         return -EDQUOT;
5596         }
5597 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
5598 --- linux-2.6.22.10/fs/jfs/file.c       2007-05-02 19:25:18 +0200
5599 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/file.c    2007-09-12 20:04:16 +0200
5600 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
5601         .setattr        = jfs_setattr,
5602         .permission     = jfs_permission,
5603  #endif
5604 +       .sync_flags     = jfs_sync_flags,
5605  };
5606  
5607  const struct file_operations jfs_file_operations = {
5608 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
5609 --- linux-2.6.22.10/fs/jfs/inode.c      2007-07-09 13:19:26 +0200
5610 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/inode.c   2007-08-05 20:53:12 +0200
5611 @@ -22,6 +22,7 @@
5612  #include <linux/buffer_head.h>
5613  #include <linux/pagemap.h>
5614  #include <linux/quotaops.h>
5615 +#include <linux/vs_dlimit.h>
5616  #include "jfs_incore.h"
5617  #include "jfs_inode.h"
5618  #include "jfs_filsys.h"
5619 @@ -143,6 +144,7 @@ void jfs_delete_inode(struct inode *inod
5620                 DQUOT_INIT(inode);
5621                 DQUOT_FREE_INODE(inode);
5622                 DQUOT_DROP(inode);
5623 +               DLIMIT_FREE_INODE(inode);
5624         }
5625  
5626         clear_inode(inode);
5627 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
5628 --- linux-2.6.22.10/fs/jfs/ioctl.c      2007-07-09 13:19:27 +0200
5629 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/ioctl.c   2007-08-05 20:53:12 +0200
5630 @@ -10,6 +10,7 @@
5631  #include <linux/capability.h>
5632  #include <linux/time.h>
5633  #include <linux/sched.h>
5634 +#include <linux/mount.h>
5635  #include <asm/current.h>
5636  #include <asm/uaccess.h>
5637  
5638 @@ -66,7 +67,8 @@ int jfs_ioctl(struct inode * inode, stru
5639         case JFS_IOC_SETFLAGS: {
5640                 unsigned int oldflags;
5641  
5642 -               if (IS_RDONLY(inode))
5643 +               if (IS_RDONLY(inode) ||
5644 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
5645                         return -EROFS;
5646  
5647                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
5648 @@ -87,8 +89,8 @@ int jfs_ioctl(struct inode * inode, stru
5649                  * the relevant capability.
5650                  */
5651                 if ((oldflags & JFS_IMMUTABLE_FL) ||
5652 -                       ((flags ^ oldflags) &
5653 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
5654 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
5655 +                       JFS_IMMUTABLE_FL | JFS_IUNLINK_FL))) {
5656                         if (!capable(CAP_LINUX_IMMUTABLE))
5657                                 return -EPERM;
5658                 }
5659 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
5660 --- linux-2.6.22.10/fs/jfs/jfs_dinode.h 2006-11-30 21:19:25 +0100
5661 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_dinode.h      2007-08-05 20:53:12 +0200
5662 @@ -162,9 +162,12 @@ struct dinode {
5663  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
5664  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
5665  
5666 -#define JFS_FL_USER_VISIBLE    0x03F80000
5667 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
5668 +#define JFS_IUNLINK_FL         0x08000000 /* Immutable unlink */
5669 +
5670 +#define JFS_FL_USER_VISIBLE    0x0FF80000
5671  #define JFS_FL_USER_MODIFIABLE 0x03F80000
5672 -#define JFS_FL_INHERIT         0x03C80000
5673 +#define JFS_FL_INHERIT         0x0BC80000
5674  
5675  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
5676  #define JFS_IOC_GETFLAGS       _IOR('f', 1, long)
5677 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
5678 --- linux-2.6.22.10/fs/jfs/jfs_dtree.c  2007-02-06 03:01:24 +0100
5679 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_dtree.c       2007-08-05 20:53:12 +0200
5680 @@ -102,6 +102,7 @@
5681  
5682  #include <linux/fs.h>
5683  #include <linux/quotaops.h>
5684 +#include <linux/vs_dlimit.h>
5685  #include "jfs_incore.h"
5686  #include "jfs_superblock.h"
5687  #include "jfs_filsys.h"
5688 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
5689                  */
5690                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
5691                         goto clean_up;
5692 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
5693 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
5694 -                       goto clean_up;
5695 -               }
5696 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
5697 +                       goto clean_up_dquot;
5698 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
5699 +                       goto clean_up_dlimit;
5700  
5701                 /*
5702                  * Save the table, we're going to overwrite it with the
5703 @@ -479,6 +480,12 @@ static u32 add_index(tid_t tid, struct i
5704  
5705         return index;
5706  
5707 +      clean_up_dlimit:
5708 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
5709 +
5710 +      clean_up_dquot:
5711 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
5712 +
5713        clean_up:
5714  
5715         jfs_ip->next_index--;
5716 @@ -952,6 +959,7 @@ static int dtSplitUp(tid_t tid,
5717         struct tlock *tlck;
5718         struct lv *lv;
5719         int quota_allocation = 0;
5720 +       int dlimit_allocation = 0;
5721  
5722         /* get split page */
5723         smp = split->mp;
5724 @@ -1036,6 +1044,12 @@ static int dtSplitUp(tid_t tid,
5725                 }
5726                 quota_allocation += n;
5727  
5728 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
5729 +                       rc = -ENOSPC;
5730 +                       goto extendOut;
5731 +               }
5732 +               dlimit_allocation += n;
5733 +
5734                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
5735                                     (s64) n, &nxaddr)))
5736                         goto extendOut;
5737 @@ -1309,6 +1323,9 @@ static int dtSplitUp(tid_t tid,
5738        freeKeyName:
5739         kfree(key.name);
5740  
5741 +       /* Rollback dlimit allocation */
5742 +       if (rc && dlimit_allocation)
5743 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
5744         /* Rollback quota allocation */
5745         if (rc && quota_allocation)
5746                 DQUOT_FREE_BLOCK(ip, quota_allocation);
5747 @@ -1376,6 +1393,12 @@ static int dtSplitPage(tid_t tid, struct
5748                 release_metapage(rmp);
5749                 return -EDQUOT;
5750         }
5751 +       /* Allocate blocks to dlimit. */
5752 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5753 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5754 +               release_metapage(rmp);
5755 +               return -ENOSPC;
5756 +       }
5757  
5758         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
5759  
5760 @@ -1926,6 +1949,12 @@ static int dtSplitRoot(tid_t tid,
5761                 release_metapage(rmp);
5762                 return -EDQUOT;
5763         }
5764 +       /* Allocate blocks to dlimit. */
5765 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5766 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5767 +               release_metapage(rmp);
5768 +               return -ENOSPC;
5769 +       }
5770  
5771         BT_MARK_DIRTY(rmp, ip);
5772         /*
5773 @@ -2292,6 +2321,8 @@ static int dtDeleteUp(tid_t tid, struct 
5774  
5775         xlen = lengthPXD(&fp->header.self);
5776  
5777 +       /* Free dlimit allocation. */
5778 +       DLIMIT_FREE_BLOCK(ip, xlen);
5779         /* Free quota allocation. */
5780         DQUOT_FREE_BLOCK(ip, xlen);
5781  
5782 @@ -2368,6 +2399,8 @@ static int dtDeleteUp(tid_t tid, struct 
5783  
5784                                 xlen = lengthPXD(&p->header.self);
5785  
5786 +                               /* Free dlimit allocation */
5787 +                               DLIMIT_FREE_BLOCK(ip, xlen);
5788                                 /* Free quota allocation */
5789                                 DQUOT_FREE_BLOCK(ip, xlen);
5790  
5791 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
5792 --- linux-2.6.22.10/fs/jfs/jfs_extent.c 2006-11-30 21:19:25 +0100
5793 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_extent.c      2007-08-05 20:53:12 +0200
5794 @@ -18,6 +18,7 @@
5795  
5796  #include <linux/fs.h>
5797  #include <linux/quotaops.h>
5798 +#include <linux/vs_dlimit.h>
5799  #include "jfs_incore.h"
5800  #include "jfs_inode.h"
5801  #include "jfs_superblock.h"
5802 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
5803                 return -EDQUOT;
5804         }
5805  
5806 +       /* Allocate blocks to dlimit. */
5807 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
5808 +               DQUOT_FREE_BLOCK(ip, nxlen);
5809 +               dbFree(ip, nxaddr, (s64) nxlen);
5810 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
5811 +               return -ENOSPC;
5812 +       }
5813 +
5814         /* determine the value of the extent flag */
5815         xflag = abnr ? XAD_NOTRECORDED : 0;
5816  
5817 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
5818          */
5819         if (rc) {
5820                 dbFree(ip, nxaddr, nxlen);
5821 +               DLIMIT_FREE_BLOCK(ip, nxlen);
5822                 DQUOT_FREE_BLOCK(ip, nxlen);
5823                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
5824                 return (rc);
5825 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
5826                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
5827                 return -EDQUOT;
5828         }
5829 +       /* Allocate blocks to dlimit. */
5830 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
5831 +               DQUOT_FREE_BLOCK(ip, nxlen);
5832 +               dbFree(ip, nxaddr, (s64) nxlen);
5833 +               up(&JFS_IP(ip)->commit_sem);
5834 +               return -ENOSPC;
5835 +       }
5836  
5837         delta = nxlen - xlen;
5838  
5839 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
5840                 /* extend the extent */
5841                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
5842                         dbFree(ip, xaddr + xlen, delta);
5843 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
5844                         DQUOT_FREE_BLOCK(ip, nxlen);
5845                         goto exit;
5846                 }
5847 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
5848                  */
5849                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
5850                         dbFree(ip, nxaddr, nxlen);
5851 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
5852                         DQUOT_FREE_BLOCK(ip, nxlen);
5853                         goto exit;
5854                 }
5855 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
5856 --- linux-2.6.22.10/fs/jfs/jfs_filsys.h 2007-02-06 03:01:24 +0100
5857 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_filsys.h      2007-08-05 20:53:12 +0200
5858 @@ -264,6 +264,7 @@
5859  #define JFS_NAME_MAX   255
5860  #define JFS_PATH_MAX   BPSIZE
5861  
5862 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
5863  
5864  /*
5865   *     file system state (superblock state)
5866 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
5867 --- linux-2.6.22.10/fs/jfs/jfs_imap.c   2007-07-09 13:19:27 +0200
5868 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_imap.c        2007-08-05 20:53:12 +0200
5869 @@ -45,6 +45,7 @@
5870  #include <linux/buffer_head.h>
5871  #include <linux/pagemap.h>
5872  #include <linux/quotaops.h>
5873 +#include <linux/vs_tag.h>
5874  
5875  #include "jfs_incore.h"
5876  #include "jfs_inode.h"
5877 @@ -3075,6 +3076,8 @@ static int copy_from_dinode(struct dinod
5878  {
5879         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
5880         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
5881 +       uid_t uid;
5882 +       gid_t gid;
5883  
5884         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
5885         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
5886 @@ -3095,14 +3098,18 @@ static int copy_from_dinode(struct dinod
5887         }
5888         ip->i_nlink = le32_to_cpu(dip->di_nlink);
5889  
5890 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
5891 +       uid = le32_to_cpu(dip->di_uid);
5892 +       gid = le32_to_cpu(dip->di_gid);
5893 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
5894 +
5895 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
5896         if (sbi->uid == -1)
5897                 ip->i_uid = jfs_ip->saved_uid;
5898         else {
5899                 ip->i_uid = sbi->uid;
5900         }
5901  
5902 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
5903 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
5904         if (sbi->gid == -1)
5905                 ip->i_gid = jfs_ip->saved_gid;
5906         else {
5907 @@ -3167,14 +3174,12 @@ static void copy_to_dinode(struct dinode
5908         dip->di_size = cpu_to_le64(ip->i_size);
5909         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
5910         dip->di_nlink = cpu_to_le32(ip->i_nlink);
5911 -       if (sbi->uid == -1)
5912 -               dip->di_uid = cpu_to_le32(ip->i_uid);
5913 -       else
5914 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
5915 -       if (sbi->gid == -1)
5916 -               dip->di_gid = cpu_to_le32(ip->i_gid);
5917 -       else
5918 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
5919 +
5920 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
5921 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
5922 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
5923 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
5924 +
5925         jfs_get_inode_flags(jfs_ip);
5926         /*
5927          * mode2 is only needed for storing the higher order bits.
5928 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
5929 --- linux-2.6.22.10/fs/jfs/jfs_inode.c  2007-07-09 13:19:27 +0200
5930 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_inode.c       2007-08-05 20:53:12 +0200
5931 @@ -18,6 +18,8 @@
5932  
5933  #include <linux/fs.h>
5934  #include <linux/quotaops.h>
5935 +#include <linux/vs_dlimit.h>
5936 +#include <linux/vs_tag.h>
5937  #include "jfs_incore.h"
5938  #include "jfs_inode.h"
5939  #include "jfs_filsys.h"
5940 @@ -30,19 +32,47 @@ void jfs_set_inode_flags(struct inode *i
5941  {
5942         unsigned int flags = JFS_IP(inode)->mode2;
5943  
5944 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
5945 -               S_NOATIME | S_DIRSYNC | S_SYNC);
5946 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
5947 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5948  
5949         if (flags & JFS_IMMUTABLE_FL)
5950                 inode->i_flags |= S_IMMUTABLE;
5951 +       if (flags & JFS_IUNLINK_FL)
5952 +               inode->i_flags |= S_IUNLINK;
5953 +       if (flags & JFS_BARRIER_FL)
5954 +               inode->i_flags |= S_BARRIER;
5955 +
5956 +       if (flags & JFS_SYNC_FL)
5957 +               inode->i_flags |= S_SYNC;
5958         if (flags & JFS_APPEND_FL)
5959                 inode->i_flags |= S_APPEND;
5960         if (flags & JFS_NOATIME_FL)
5961                 inode->i_flags |= S_NOATIME;
5962         if (flags & JFS_DIRSYNC_FL)
5963                 inode->i_flags |= S_DIRSYNC;
5964 -       if (flags & JFS_SYNC_FL)
5965 -               inode->i_flags |= S_SYNC;
5966 +}
5967 +
5968 +int jfs_sync_flags(struct inode *inode)
5969 +{
5970 +       unsigned int oldflags, newflags;
5971 +
5972 +       oldflags = JFS_IP(inode)->mode2;
5973 +       newflags = oldflags & ~(JFS_IMMUTABLE_FL |
5974 +               JFS_IUNLINK_FL | JFS_BARRIER_FL);
5975 +
5976 +       if (IS_IMMUTABLE(inode))
5977 +               newflags |= JFS_IMMUTABLE_FL;
5978 +       if (IS_IUNLINK(inode))
5979 +               newflags |= JFS_IUNLINK_FL;
5980 +       if (IS_BARRIER(inode))
5981 +               newflags |= JFS_BARRIER_FL;
5982 +
5983 +       if (oldflags ^ newflags) {
5984 +               JFS_IP(inode)->mode2 = newflags;
5985 +               inode->i_ctime = CURRENT_TIME;
5986 +               mark_inode_dirty(inode);
5987 +       }
5988 +       return 0;
5989  }
5990  
5991  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
5992 @@ -108,10 +138,17 @@ struct inode *ialloc(struct inode *paren
5993         jfs_inode->saved_uid = inode->i_uid;
5994         jfs_inode->saved_gid = inode->i_gid;
5995  
5996 +       inode->i_tag = dx_current_fstag(sb);
5997 +       if (DLIMIT_ALLOC_INODE(inode)) {
5998 +               iput(inode);
5999 +               return ERR_PTR(-ENOSPC);
6000 +       }
6001 +
6002         /*
6003          * Allocate inode to quota.
6004          */
6005         if (DQUOT_ALLOC_INODE(inode)) {
6006 +               DLIMIT_FREE_INODE(inode);
6007                 DQUOT_DROP(inode);
6008                 inode->i_flags |= S_NOQUOTA;
6009                 inode->i_nlink = 0;
6010 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
6011 --- linux-2.6.22.10/fs/jfs/jfs_inode.h  2007-07-09 13:19:27 +0200
6012 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_inode.h       2007-08-05 20:53:12 +0200
6013 @@ -33,6 +33,7 @@ extern void jfs_free_zero_link(struct in
6014  extern struct dentry *jfs_get_parent(struct dentry *dentry);
6015  extern void jfs_get_inode_flags(struct jfs_inode_info *);
6016  extern void jfs_set_inode_flags(struct inode *);
6017 +extern int jfs_sync_flags(struct inode *);
6018  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
6019  
6020  extern const struct address_space_operations jfs_aops;
6021 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
6022 --- linux-2.6.22.10/fs/jfs/jfs_xtree.c  2007-05-02 19:25:18 +0200
6023 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/jfs_xtree.c       2007-08-05 20:53:12 +0200
6024 @@ -21,6 +21,7 @@
6025  
6026  #include <linux/fs.h>
6027  #include <linux/quotaops.h>
6028 +#include <linux/vs_dlimit.h>
6029  #include "jfs_incore.h"
6030  #include "jfs_filsys.h"
6031  #include "jfs_metapage.h"
6032 @@ -846,7 +847,12 @@ int xtInsert(tid_t tid,            /* transaction 
6033                         hint = 0;
6034                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
6035                         goto out;
6036 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
6037 +                       DQUOT_FREE_BLOCK(ip, xlen);
6038 +                       goto out;
6039 +               }
6040                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
6041 +                       DLIMIT_FREE_BLOCK(ip, xlen);
6042                         DQUOT_FREE_BLOCK(ip, xlen);
6043                         goto out;
6044                 }
6045 @@ -876,6 +882,7 @@ int xtInsert(tid_t tid,             /* transaction 
6046                         /* undo data extent allocation */
6047                         if (*xaddrp == 0) {
6048                                 dbFree(ip, xaddr, (s64) xlen);
6049 +                               DLIMIT_FREE_BLOCK(ip, xlen);
6050                                 DQUOT_FREE_BLOCK(ip, xlen);
6051                         }
6052                         return rc;
6053 @@ -1236,6 +1243,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
6054         struct tlock *tlck;
6055         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
6056         int quota_allocation = 0;
6057 +       int dlimit_allocation = 0;
6058  
6059         smp = split->mp;
6060         sp = XT_PAGE(ip, smp);
6061 @@ -1255,6 +1263,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
6062  
6063         quota_allocation += lengthPXD(pxd);
6064  
6065 +       /* Allocate blocks to dlimit. */
6066 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
6067 +              rc = -ENOSPC;
6068 +              goto clean_up;
6069 +       }
6070 +       dlimit_allocation += lengthPXD(pxd);
6071 +
6072         /*
6073          * allocate the new right page for the split
6074          */
6075 @@ -1456,6 +1471,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
6076  
6077        clean_up:
6078  
6079 +       /* Rollback dlimit allocation. */
6080 +       if (dlimit_allocation)
6081 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
6082         /* Rollback quota allocation. */
6083         if (quota_allocation)
6084                 DQUOT_FREE_BLOCK(ip, quota_allocation);
6085 @@ -1520,6 +1538,12 @@ xtSplitRoot(tid_t tid,
6086                 release_metapage(rmp);
6087                 return -EDQUOT;
6088         }
6089 +       /* Allocate blocks to dlimit. */
6090 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
6091 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
6092 +               release_metapage(rmp);
6093 +               return -ENOSPC;
6094 +       }
6095  
6096         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
6097  
6098 @@ -3951,6 +3975,8 @@ s64 xtTruncate(tid_t tid, struct inode *
6099         else
6100                 ip->i_size = newsize;
6101  
6102 +       /* update dlimit allocation to reflect freed blocks */
6103 +       DLIMIT_FREE_BLOCK(ip, nfreed);
6104         /* update quota allocation to reflect freed blocks */
6105         DQUOT_FREE_BLOCK(ip, nfreed);
6106  
6107 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
6108 --- linux-2.6.22.10/fs/jfs/namei.c      2007-05-02 19:25:18 +0200
6109 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/namei.c   2007-08-05 20:53:12 +0200
6110 @@ -20,6 +20,7 @@
6111  #include <linux/fs.h>
6112  #include <linux/ctype.h>
6113  #include <linux/quotaops.h>
6114 +#include <linux/vs_tag.h>
6115  #include "jfs_incore.h"
6116  #include "jfs_superblock.h"
6117  #include "jfs_inode.h"
6118 @@ -1469,6 +1470,7 @@ static struct dentry *jfs_lookup(struct 
6119                 return ERR_PTR(-EACCES);
6120         }
6121  
6122 +       dx_propagate_tag(nd, ip);
6123         dentry = d_splice_alias(ip, dentry);
6124  
6125         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
6126 @@ -1521,6 +1523,7 @@ const struct inode_operations jfs_dir_in
6127         .setattr        = jfs_setattr,
6128         .permission     = jfs_permission,
6129  #endif
6130 +       .sync_flags     = jfs_sync_flags,
6131  };
6132  
6133  const struct file_operations jfs_dir_operations = {
6134 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
6135 --- linux-2.6.22.10/fs/jfs/super.c      2007-07-09 13:19:27 +0200
6136 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/super.c   2007-08-05 20:53:12 +0200
6137 @@ -194,7 +194,8 @@ static void jfs_put_super(struct super_b
6138  enum {
6139         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
6140         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
6141 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
6142 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
6143 +       Opt_tag, Opt_notag, Opt_tagid
6144  };
6145  
6146  static match_table_t tokens = {
6147 @@ -204,6 +205,10 @@ static match_table_t tokens = {
6148         {Opt_resize, "resize=%u"},
6149         {Opt_resize_nosize, "resize"},
6150         {Opt_errors, "errors=%s"},
6151 +       {Opt_tag, "tag"},
6152 +       {Opt_notag, "notag"},
6153 +       {Opt_tagid, "tagid=%u"},
6154 +       {Opt_tag, "tagxid"},
6155         {Opt_ignore, "noquota"},
6156         {Opt_ignore, "quota"},
6157         {Opt_usrquota, "usrquota"},
6158 @@ -338,6 +343,20 @@ static int parse_options(char *options, 
6159                         }
6160                         break;
6161                 }
6162 +#ifndef CONFIG_TAGGING_NONE
6163 +               case Opt_tag:
6164 +                       *flag |= JFS_TAGGED;
6165 +                       break;
6166 +               case Opt_notag:
6167 +                       *flag &= JFS_TAGGED;
6168 +                       break;
6169 +#endif
6170 +#ifdef CONFIG_PROPAGATE
6171 +               case Opt_tagid:
6172 +                       /* use args[0] */
6173 +                       *flag |= JFS_TAGGED;
6174 +                       break;
6175 +#endif
6176                 default:
6177                         printk("jfs: Unrecognized mount option \"%s\" "
6178                                         " or missing value\n", p);
6179 @@ -368,6 +387,13 @@ static int jfs_remount(struct super_bloc
6180         if (!parse_options(data, sb, &newLVSize, &flag)) {
6181                 return -EINVAL;
6182         }
6183 +
6184 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
6185 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
6186 +                       sb->s_id);
6187 +               return -EINVAL;
6188 +       }
6189 +
6190         if (newLVSize) {
6191                 if (sb->s_flags & MS_RDONLY) {
6192                         printk(KERN_ERR
6193 @@ -439,6 +465,9 @@ static int jfs_fill_super(struct super_b
6194  #ifdef CONFIG_JFS_POSIX_ACL
6195         sb->s_flags |= MS_POSIXACL;
6196  #endif
6197 +       /* map mount option tagxid */
6198 +       if (sbi->flag & JFS_TAGGED)
6199 +               sb->s_flags |= MS_TAGGED;
6200  
6201         if (newLVSize) {
6202                 printk(KERN_ERR "resize option for remount only\n");
6203 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
6204 --- linux-2.6.22.10/fs/jfs/xattr.c      2006-11-30 21:19:26 +0100
6205 +++ linux-2.6.22.10-vs2.3.0.29/fs/jfs/xattr.c   2007-08-05 20:53:12 +0200
6206 @@ -23,6 +23,7 @@
6207  #include <linux/posix_acl_xattr.h>
6208  #include <linux/quotaops.h>
6209  #include <linux/security.h>
6210 +#include <linux/vs_dlimit.h>
6211  #include "jfs_incore.h"
6212  #include "jfs_superblock.h"
6213  #include "jfs_dmap.h"
6214 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
6215         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
6216                 return -EDQUOT;
6217         }
6218 +       /* Allocate new blocks to dlimit. */
6219 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
6220 +               DQUOT_FREE_BLOCK(ip, nblocks);
6221 +               return -ENOSPC;
6222 +       }
6223  
6224         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
6225         if (rc) {
6226 +               /*Rollback dlimit allocation. */
6227 +               DLIMIT_FREE_BLOCK(ip, nblocks);
6228                 /*Rollback quota allocation. */
6229                 DQUOT_FREE_BLOCK(ip, nblocks);
6230                 return rc;
6231 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
6232  
6233        failed:
6234         /* Rollback quota allocation. */
6235 +       DLIMIT_FREE_BLOCK(ip, nblocks);
6236 +       /* Rollback quota allocation. */
6237         DQUOT_FREE_BLOCK(ip, nblocks);
6238  
6239         dbFree(ip, blkno, nblocks);
6240 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
6241         s64 blkno;
6242         int rc;
6243         int quota_allocation = 0;
6244 +       int dlimit_allocation = 0;
6245  
6246         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
6247         if (ji->ea.flag == 0)
6248 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
6249  
6250                 quota_allocation = blocks_needed;
6251  
6252 +               /* Allocate new blocks to dlimit. */
6253 +               rc = -ENOSPC;
6254 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
6255 +                       goto clean_up;
6256 +               dlimit_allocation = blocks_needed;
6257 +
6258                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
6259                              &blkno);
6260                 if (rc)
6261 @@ -599,6 +616,9 @@ static int ea_get(struct inode *inode, s
6262         return ea_size;
6263  
6264        clean_up:
6265 +       /* Rollback dlimit allocation */
6266 +       if (dlimit_allocation)
6267 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
6268         /* Rollback quota allocation */
6269         if (quota_allocation)
6270                 DQUOT_FREE_BLOCK(inode, quota_allocation);
6271 @@ -675,8 +695,10 @@ static int ea_put(tid_t tid, struct inod
6272         }
6273  
6274         /* If old blocks exist, they must be removed from quota allocation. */
6275 -       if (old_blocks)
6276 +       if (old_blocks) {
6277 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
6278                 DQUOT_FREE_BLOCK(inode, old_blocks);
6279 +       }
6280  
6281         inode->i_ctime = CURRENT_TIME;
6282  
6283 diff -NurpP --minimal linux-2.6.22.10/fs/libfs.c linux-2.6.22.10-vs2.3.0.29/fs/libfs.c
6284 --- linux-2.6.22.10/fs/libfs.c  2007-07-09 13:19:27 +0200
6285 +++ linux-2.6.22.10-vs2.3.0.29/fs/libfs.c       2007-08-05 20:53:12 +0200
6286 @@ -124,7 +124,8 @@ static inline unsigned char dt_type(stru
6287   * both impossible due to the lock on directory.
6288   */
6289  
6290 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
6291 +static inline int do_dcache_readdir_filter(struct file *filp,
6292 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
6293  {
6294         struct dentry *dentry = filp->f_path.dentry;
6295         struct dentry *cursor = filp->private_data;
6296 @@ -157,6 +158,8 @@ int dcache_readdir(struct file * filp, v
6297                                 next = list_entry(p, struct dentry, d_u.d_child);
6298                                 if (d_unhashed(next) || !next->d_inode)
6299                                         continue;
6300 +                               if (filter && !filter(next))
6301 +                                       continue;
6302  
6303                                 spin_unlock(&dcache_lock);
6304                                 if (filldir(dirent, next->d_name.name, 
6305 @@ -175,6 +178,18 @@ int dcache_readdir(struct file * filp, v
6306         return 0;
6307  }
6308  
6309 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
6310 +{
6311 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
6312 +}
6313 +
6314 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
6315 +       int (*filter)(struct dentry *))
6316 +{
6317 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
6318 +}
6319 +
6320 +
6321  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
6322  {
6323         return -EISDIR;
6324 @@ -640,6 +655,7 @@ EXPORT_SYMBOL(dcache_dir_close);
6325  EXPORT_SYMBOL(dcache_dir_lseek);
6326  EXPORT_SYMBOL(dcache_dir_open);
6327  EXPORT_SYMBOL(dcache_readdir);
6328 +EXPORT_SYMBOL(dcache_readdir_filter);
6329  EXPORT_SYMBOL(generic_read_dir);
6330  EXPORT_SYMBOL(get_sb_pseudo);
6331  EXPORT_SYMBOL(simple_commit_write);
6332 diff -NurpP --minimal linux-2.6.22.10/fs/locks.c linux-2.6.22.10-vs2.3.0.29/fs/locks.c
6333 --- linux-2.6.22.10/fs/locks.c  2007-10-30 01:57:14 +0100
6334 +++ linux-2.6.22.10-vs2.3.0.29/fs/locks.c       2007-10-05 15:07:22 +0200
6335 @@ -125,6 +125,8 @@
6336  #include <linux/syscalls.h>
6337  #include <linux/time.h>
6338  #include <linux/rcupdate.h>
6339 +#include <linux/vs_base.h>
6340 +#include <linux/vs_limit.h>
6341  
6342  #include <asm/semaphore.h>
6343  #include <asm/uaccess.h>
6344 @@ -147,6 +149,8 @@ static struct kmem_cache *filelock_cache
6345  /* Allocate an empty lock structure. */
6346  static struct file_lock *locks_alloc_lock(void)
6347  {
6348 +       if (!vx_locks_avail(1))
6349 +               return NULL;
6350         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
6351  }
6352  
6353 @@ -172,6 +176,7 @@ static void locks_free_lock(struct file_
6354         BUG_ON(!list_empty(&fl->fl_block));
6355         BUG_ON(!list_empty(&fl->fl_link));
6356  
6357 +       vx_locks_dec(fl);
6358         locks_release_private(fl);
6359         kmem_cache_free(filelock_cache, fl);
6360  }
6361 @@ -191,6 +196,7 @@ void locks_init_lock(struct file_lock *f
6362         fl->fl_start = fl->fl_end = 0;
6363         fl->fl_ops = NULL;
6364         fl->fl_lmops = NULL;
6365 +       fl->fl_xid = -1;
6366  }
6367  
6368  EXPORT_SYMBOL(locks_init_lock);
6369 @@ -244,6 +250,7 @@ void locks_copy_lock(struct file_lock *n
6370         new->fl_file = fl->fl_file;
6371         new->fl_ops = fl->fl_ops;
6372         new->fl_lmops = fl->fl_lmops;
6373 +       new->fl_xid = fl->fl_xid;
6374  
6375         locks_copy_private(new, fl);
6376  }
6377 @@ -282,6 +289,11 @@ static int flock_make_lock(struct file *
6378         fl->fl_flags = FL_FLOCK;
6379         fl->fl_type = type;
6380         fl->fl_end = OFFSET_MAX;
6381 +
6382 +       vxd_assert(filp->f_xid == vx_current_xid(),
6383 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6384 +       fl->fl_xid = filp->f_xid;
6385 +       vx_locks_inc(fl);
6386         
6387         *lock = fl;
6388         return 0;
6389 @@ -447,6 +459,7 @@ static int lease_init(struct file *filp,
6390  
6391         fl->fl_owner = current->files;
6392         fl->fl_pid = current->tgid;
6393 +       fl->fl_xid = vx_current_xid();
6394  
6395         fl->fl_file = filp;
6396         fl->fl_flags = FL_LEASE;
6397 @@ -466,6 +479,11 @@ static int lease_alloc(struct file *filp
6398         if (fl == NULL)
6399                 goto out;
6400  
6401 +       fl->fl_xid = vx_current_xid();
6402 +       if (filp)
6403 +               vxd_assert(filp->f_xid == fl->fl_xid,
6404 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
6405 +       vx_locks_inc(fl);
6406         error = lease_init(filp, type, fl);
6407         if (error) {
6408                 locks_free_lock(fl);
6409 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
6410         if (found)
6411                 cond_resched();
6412  
6413 +       new_fl->fl_xid = -1;
6414  find_conflict:
6415         for_each_lock(inode, before) {
6416                 struct file_lock *fl = *before;
6417 @@ -787,6 +806,7 @@ find_conflict:
6418                 goto out;
6419         locks_copy_lock(new_fl, request);
6420         locks_insert_lock(before, new_fl);
6421 +       vx_locks_inc(new_fl);
6422         new_fl = NULL;
6423         error = 0;
6424  
6425 @@ -797,7 +817,8 @@ out:
6426         return error;
6427  }
6428  
6429 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
6430 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
6431 +       struct file_lock *conflock, xid_t xid)
6432  {
6433         struct file_lock *fl;
6434         struct file_lock *new_fl = NULL;
6435 @@ -807,6 +828,8 @@ static int __posix_lock_file(struct inod
6436         struct file_lock **before;
6437         int error, added = 0;
6438  
6439 +       vxd_assert(xid == vx_current_xid(),
6440 +               "xid(%d) == current(%d)", xid, vx_current_xid());
6441         /*
6442          * We may need two file_lock structures for this operation,
6443          * so we get them in advance to avoid races.
6444 @@ -817,7 +840,11 @@ static int __posix_lock_file(struct inod
6445             (request->fl_type != F_UNLCK ||
6446              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
6447                 new_fl = locks_alloc_lock();
6448 +               new_fl->fl_xid = xid;
6449 +               vx_locks_inc(new_fl);
6450                 new_fl2 = locks_alloc_lock();
6451 +               new_fl2->fl_xid = xid;
6452 +               vx_locks_inc(new_fl2);
6453         }
6454  
6455         lock_kernel();
6456 @@ -1016,7 +1043,8 @@ static int __posix_lock_file(struct inod
6457  int posix_lock_file(struct file *filp, struct file_lock *fl,
6458                         struct file_lock *conflock)
6459  {
6460 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
6461 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
6462 +               fl, conflock, filp->f_xid);
6463  }
6464  EXPORT_SYMBOL(posix_lock_file);
6465  
6466 @@ -1106,7 +1134,7 @@ int locks_mandatory_area(int read_write,
6467         fl.fl_end = offset + count - 1;
6468  
6469         for (;;) {
6470 -               error = __posix_lock_file(inode, &fl, NULL);
6471 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
6472                 if (error != -EAGAIN)
6473                         break;
6474                 if (!(fl.fl_flags & FL_SLEEP))
6475 @@ -1410,8 +1438,8 @@ static int __setlease(struct file *filp,
6476                 goto out;
6477  
6478         locks_copy_lock(fl, lease);
6479 -
6480         locks_insert_lock(before, fl);
6481 +       vx_locks_inc(fl);
6482  
6483         *flp = fl;
6484         error = 0;
6485 @@ -1738,6 +1766,11 @@ int fcntl_setlk(unsigned int fd, struct 
6486         if (file_lock == NULL)
6487                 return -ENOLCK;
6488  
6489 +       vxd_assert(filp->f_xid == vx_current_xid(),
6490 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
6491 +       file_lock->fl_xid = filp->f_xid;
6492 +       vx_locks_inc(file_lock);
6493 +
6494         /*
6495          * This might block, so we do it before checking the inode.
6496          */
6497 @@ -1864,6 +1897,11 @@ int fcntl_setlk64(unsigned int fd, struc
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 @@ -2168,6 +2206,10 @@ int get_locks_status(char *buffer, char 
6510         list_for_each(tmp, &file_lock_list) {
6511                 struct list_head *btmp;
6512                 struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link);
6513 +
6514 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
6515 +                       continue;
6516 +
6517                 lock_get_status(q, fl, ++i, "");
6518                 move_lock_status(&q, &pos, offset);
6519  
6520 diff -NurpP --minimal linux-2.6.22.10/fs/namei.c linux-2.6.22.10-vs2.3.0.29/fs/namei.c
6521 --- linux-2.6.22.10/fs/namei.c  2007-07-09 13:19:27 +0200
6522 +++ linux-2.6.22.10-vs2.3.0.29/fs/namei.c       2007-10-29 23:41:56 +0100
6523 @@ -31,6 +31,13 @@
6524  #include <linux/file.h>
6525  #include <linux/fcntl.h>
6526  #include <linux/namei.h>
6527 +#include <linux/proc_fs.h>
6528 +#include <linux/vserver/inode.h>
6529 +#include <linux/vs_base.h>
6530 +#include <linux/vs_tag.h>
6531 +#include <linux/vs_cowbl.h>
6532 +#include <linux/vs_device.h>
6533 +#include <linux/vs_context.h>
6534  #include <asm/namei.h>
6535  #include <asm/uaccess.h>
6536  
6537 @@ -224,6 +231,28 @@ int generic_permission(struct inode *ino
6538         return -EACCES;
6539  }
6540  
6541 +static inline int dx_barrier(struct inode *inode)
6542 +{
6543 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
6544 +               vxwprintk_task(1, "did hit the barrier.");
6545 +               return 1;
6546 +       }
6547 +       return 0;
6548 +}
6549 +
6550 +static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
6551 +{
6552 +       if (dx_barrier(inode))
6553 +               return -EACCES;
6554 +       if (dx_notagcheck(nd) ||
6555 +           dx_check(inode->i_tag, DX_HOSTID|DX_ADMIN|DX_WATCH|DX_IDENT))
6556 +               return 0;
6557 +
6558 +       vxwprintk_task(1, "denied access to %p[#%d,%lu] »%s«.",
6559 +               inode, inode->i_tag, inode->i_ino, vxd_cond_path(nd));
6560 +       return -EACCES;
6561 +}
6562 +
6563  int permission(struct inode *inode, int mask, struct nameidata *nd)
6564  {
6565         umode_t mode = inode->i_mode;
6566 @@ -234,14 +263,14 @@ int permission(struct inode *inode, int 
6567                 /*
6568                  * Nobody gets write access to a read-only fs.
6569                  */
6570 -               if (IS_RDONLY(inode) &&
6571 +               if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->mnt))) &&
6572                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
6573                         return -EROFS;
6574  
6575                 /*
6576                  * Nobody gets write access to an immutable file.
6577                  */
6578 -               if (IS_IMMUTABLE(inode))
6579 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
6580                         return -EACCES;
6581         }
6582  
6583 @@ -257,6 +286,12 @@ int permission(struct inode *inode, int 
6584  
6585         /* Ordinary permission routines do not understand MAY_APPEND. */
6586         submask = mask & ~MAY_APPEND;
6587 +
6588 +       if ((inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC) &&
6589 +               (inode->i_sb->s_magic != PROC_SUPER_MAGIC) &&
6590 +               (retval = dx_permission(inode, mask, nd)))
6591 +               return retval;
6592 +
6593         if (inode->i_op && inode->i_op->permission)
6594                 retval = inode->i_op->permission(inode, submask, nd);
6595         else
6596 @@ -432,6 +467,8 @@ static int exec_permission_lite(struct i
6597  {
6598         umode_t mode = inode->i_mode;
6599  
6600 +       if (dx_barrier(inode))
6601 +               return -EACCES;
6602         if (inode->i_op && inode->i_op->permission)
6603                 return -EAGAIN;
6604  
6605 @@ -732,7 +769,8 @@ static __always_inline void follow_dotdo
6606                 if (nd->dentry == fs->root &&
6607                     nd->mnt == fs->rootmnt) {
6608                          read_unlock(&fs->lock);
6609 -                       break;
6610 +                       /* for sane '/' avoid follow_mount() */
6611 +                       return;
6612                 }
6613                  read_unlock(&fs->lock);
6614                 spin_lock(&dcache_lock);
6615 @@ -769,16 +807,39 @@ static int do_lookup(struct nameidata *n
6616  {
6617         struct vfsmount *mnt = nd->mnt;
6618         struct dentry *dentry = __d_lookup(nd->dentry, name);
6619 +       struct inode *inode;
6620  
6621         if (!dentry)
6622                 goto need_lookup;
6623         if (dentry->d_op && dentry->d_op->d_revalidate)
6624                 goto need_revalidate;
6625 +       inode = dentry->d_inode;
6626 +       if (!inode)
6627 +               goto done;
6628 +
6629 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
6630 +               struct proc_dir_entry *de = PDE(inode);
6631 +
6632 +               if (de && !vx_hide_check(0, de->vx_flags))
6633 +                       goto hidden;
6634 +       } else if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
6635 +               if (!vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
6636 +                       goto hidden;
6637 +       } else {
6638 +               if (!dx_notagcheck(nd) && !dx_check(inode->i_tag,
6639 +                       DX_WATCH | DX_ADMIN | DX_HOSTID | DX_IDENT))
6640 +                       goto hidden;
6641 +       }
6642  done:
6643         path->mnt = mnt;
6644         path->dentry = dentry;
6645         __follow_mount(path);
6646         return 0;
6647 +hidden:
6648 +       vxwprintk_task(1, "did lookup hidden %p[#%d,%lu] »%s«.",
6649 +               inode, inode->i_tag, inode->i_ino, vxd_path(dentry, mnt));
6650 +       dput(dentry);
6651 +       return -ENOENT;
6652  
6653  need_lookup:
6654         dentry = real_lookup(nd->dentry, name, nd);
6655 @@ -1399,7 +1460,8 @@ static inline int check_sticky(struct in
6656   * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
6657   *     nfs_async_unlink().
6658   */
6659 -static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
6660 +static int may_delete(struct inode *dir, struct dentry *victim,
6661 +       int isdir, struct nameidata *nd)
6662  {
6663         int error;
6664  
6665 @@ -1409,13 +1471,13 @@ static int may_delete(struct inode *dir,
6666         BUG_ON(victim->d_parent->d_inode != dir);
6667         audit_inode_child(victim->d_name.name, victim->d_inode, dir);
6668  
6669 -       error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
6670 +       error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
6671         if (error)
6672                 return error;
6673         if (IS_APPEND(dir))
6674                 return -EPERM;
6675         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
6676 -           IS_IMMUTABLE(victim->d_inode))
6677 +               IS_IXORUNLINK(victim->d_inode))
6678                 return -EPERM;
6679         if (isdir) {
6680                 if (!S_ISDIR(victim->d_inode->i_mode))
6681 @@ -1546,6 +1608,14 @@ int may_open(struct nameidata *nd, int a
6682         if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
6683                 return -EISDIR;
6684  
6685 +#ifdef CONFIG_VSERVER_COWBL
6686 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
6687 +               if (IS_COW_LINK(inode))
6688 +                       return -EMLINK;
6689 +               inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
6690 +               mark_inode_dirty(inode);
6691 +       }
6692 +#endif
6693         error = vfs_permission(nd, acc_mode);
6694         if (error)
6695                 return error;
6696 @@ -1562,7 +1632,8 @@ int may_open(struct nameidata *nd, int a
6697                         return -EACCES;
6698  
6699                 flag &= ~O_TRUNC;
6700 -       } else if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
6701 +       } else if ((IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
6702 +               && (flag & FMODE_WRITE))
6703                 return -EROFS;
6704         /*
6705          * An append-only file must be opened in append mode for writing.
6706 @@ -1650,6 +1721,11 @@ int open_namei(int dfd, const char *path
6707         struct dentry *dir;
6708         int count = 0;
6709  
6710 +#ifdef CONFIG_VSERVER_COWBL
6711 +       int rflag = flag;
6712 +       int rmode = mode;
6713 +restart:
6714 +#endif
6715         acc_mode = ACC_MODE(flag);
6716  
6717         /* O_TRUNC implies we need access checks for write permissions */
6718 @@ -1743,6 +1819,22 @@ do_last:
6719                 goto exit;
6720  ok:
6721         error = may_open(nd, acc_mode, flag);
6722 +#ifdef CONFIG_VSERVER_COWBL
6723 +       if (error == -EMLINK) {
6724 +               struct dentry *dentry;
6725 +               dentry = cow_break_link(pathname);
6726 +               if (IS_ERR(dentry)) {
6727 +                       error = PTR_ERR(dentry);
6728 +                       goto exit;
6729 +               }
6730 +               dput(dentry);
6731 +               release_open_intent(nd);
6732 +               path_release(nd);
6733 +               flag = rflag;
6734 +               mode = rmode;
6735 +               goto restart;
6736 +       }
6737 +#endif
6738         if (error)
6739                 goto exit;
6740         return 0;
6741 @@ -1854,16 +1946,25 @@ fail:
6742  }
6743  EXPORT_SYMBOL_GPL(lookup_create);
6744  
6745 -int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
6746 +int vfs_mknod(struct inode *dir, struct dentry *dentry,
6747 +       int mode, dev_t dev, struct nameidata *nd)
6748  {
6749 -       int error = may_create(dir, dentry, NULL);
6750 +       int error = may_create(dir, dentry, nd);
6751  
6752         if (error)
6753                 return error;
6754  
6755 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
6756 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
6757 +               goto okay;
6758 +
6759 +       if (!capable(CAP_MKNOD))
6760                 return -EPERM;
6761  
6762 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
6763 +               return -EPERM;
6764 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
6765 +               return -EPERM;
6766 +okay:
6767         if (!dir->i_op || !dir->i_op->mknod)
6768                 return -EPERM;
6769  
6770 @@ -1906,11 +2007,12 @@ asmlinkage long sys_mknodat(int dfd, con
6771                         error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
6772                         break;
6773                 case S_IFCHR: case S_IFBLK:
6774 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
6775 -                                       new_decode_dev(dev));
6776 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6777 +                                       new_decode_dev(dev), &nd);
6778                         break;
6779                 case S_IFIFO: case S_IFSOCK:
6780 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
6781 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6782 +                                       0, &nd);
6783                         break;
6784                 case S_IFDIR:
6785                         error = -EPERM;
6786 @@ -1933,9 +2035,10 @@ asmlinkage long sys_mknod(const char __u
6787         return sys_mknodat(AT_FDCWD, filename, mode, dev);
6788  }
6789  
6790 -int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
6791 +int vfs_mkdir(struct inode *dir, struct dentry *dentry,
6792 +       int mode, struct nameidata *nd)
6793  {
6794 -       int error = may_create(dir, dentry, NULL);
6795 +       int error = may_create(dir, dentry, nd);
6796  
6797         if (error)
6798                 return error;
6799 @@ -1977,7 +2080,7 @@ asmlinkage long sys_mkdirat(int dfd, con
6800  
6801         if (!IS_POSIXACL(nd.dentry->d_inode))
6802                 mode &= ~current->fs->umask;
6803 -       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
6804 +       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode, &nd);
6805         dput(dentry);
6806  out_unlock:
6807         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6808 @@ -2020,9 +2123,10 @@ void dentry_unhash(struct dentry *dentry
6809         spin_unlock(&dcache_lock);
6810  }
6811  
6812 -int vfs_rmdir(struct inode *dir, struct dentry *dentry)
6813 +int vfs_rmdir(struct inode *dir, struct dentry *dentry,
6814 +       struct nameidata *nd)
6815  {
6816 -       int error = may_delete(dir, dentry, 1);
6817 +       int error = may_delete(dir, dentry, 1, nd);
6818  
6819         if (error)
6820                 return error;
6821 @@ -2084,7 +2188,7 @@ static long do_rmdir(int dfd, const char
6822         error = PTR_ERR(dentry);
6823         if (IS_ERR(dentry))
6824                 goto exit2;
6825 -       error = vfs_rmdir(nd.dentry->d_inode, dentry);
6826 +       error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
6827         dput(dentry);
6828  exit2:
6829         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6830 @@ -2100,9 +2204,10 @@ asmlinkage long sys_rmdir(const char __u
6831         return do_rmdir(AT_FDCWD, pathname);
6832  }
6833  
6834 -int vfs_unlink(struct inode *dir, struct dentry *dentry)
6835 +int vfs_unlink(struct inode *dir, struct dentry *dentry,
6836 +       struct nameidata *nd)
6837  {
6838 -       int error = may_delete(dir, dentry, 0);
6839 +       int error = may_delete(dir, dentry, 0, nd);
6840  
6841         if (error)
6842                 return error;
6843 @@ -2164,7 +2269,7 @@ static long do_unlinkat(int dfd, const c
6844                 inode = dentry->d_inode;
6845                 if (inode)
6846                         atomic_inc(&inode->i_count);
6847 -               error = vfs_unlink(nd.dentry->d_inode, dentry);
6848 +               error = vfs_unlink(nd.dentry->d_inode, dentry, &nd);
6849         exit2:
6850                 dput(dentry);
6851         }
6852 @@ -2199,9 +2304,10 @@ asmlinkage long sys_unlink(const char __
6853         return do_unlinkat(AT_FDCWD, pathname);
6854  }
6855  
6856 -int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
6857 +int vfs_symlink(struct inode *dir, struct dentry *dentry,
6858 +       const char *oldname, int mode, struct nameidata *nd)
6859  {
6860 -       int error = may_create(dir, dentry, NULL);
6861 +       int error = may_create(dir, dentry, nd);
6862  
6863         if (error)
6864                 return error;
6865 @@ -2245,7 +2351,7 @@ asmlinkage long sys_symlinkat(const char
6866         if (IS_ERR(dentry))
6867                 goto out_unlock;
6868  
6869 -       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
6870 +       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO, &nd);
6871         dput(dentry);
6872  out_unlock:
6873         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6874 @@ -2262,7 +2368,8 @@ asmlinkage long sys_symlink(const char _
6875         return sys_symlinkat(oldname, AT_FDCWD, newname);
6876  }
6877  
6878 -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
6879 +int vfs_link(struct dentry *old_dentry, struct inode *dir,
6880 +       struct dentry *new_dentry, struct nameidata *nd)
6881  {
6882         struct inode *inode = old_dentry->d_inode;
6883         int error;
6884 @@ -2270,7 +2377,7 @@ int vfs_link(struct dentry *old_dentry, 
6885         if (!inode)
6886                 return -ENOENT;
6887  
6888 -       error = may_create(dir, new_dentry, NULL);
6889 +       error = may_create(dir, new_dentry, nd);
6890         if (error)
6891                 return error;
6892  
6893 @@ -2280,7 +2387,7 @@ int vfs_link(struct dentry *old_dentry, 
6894         /*
6895          * A link to an append-only or immutable file cannot be created.
6896          */
6897 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
6898 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
6899                 return -EPERM;
6900         if (!dir->i_op || !dir->i_op->link)
6901                 return -EPERM;
6902 @@ -2340,7 +2447,7 @@ asmlinkage long sys_linkat(int olddfd, c
6903         error = PTR_ERR(new_dentry);
6904         if (IS_ERR(new_dentry))
6905                 goto out_unlock;
6906 -       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
6907 +       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
6908         dput(new_dentry);
6909  out_unlock:
6910         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6911 @@ -2472,14 +2579,14 @@ int vfs_rename(struct inode *old_dir, st
6912         if (old_dentry->d_inode == new_dentry->d_inode)
6913                 return 0;
6914   
6915 -       error = may_delete(old_dir, old_dentry, is_dir);
6916 +       error = may_delete(old_dir, old_dentry, is_dir, NULL);
6917         if (error)
6918                 return error;
6919  
6920         if (!new_dentry->d_inode)
6921                 error = may_create(new_dir, new_dentry, NULL);
6922         else
6923 -               error = may_delete(new_dir, new_dentry, is_dir);
6924 +               error = may_delete(new_dir, new_dentry, is_dir, NULL);
6925         if (error)
6926                 return error;
6927  
6928 @@ -2557,6 +2664,9 @@ static int do_rename(int olddfd, const c
6929         error = -EINVAL;
6930         if (old_dentry == trap)
6931                 goto exit4;
6932 +       error = -EROFS;
6933 +       if (MNT_IS_RDONLY(newnd.mnt))
6934 +               goto exit4;
6935         new_dentry = lookup_hash(&newnd);
6936         error = PTR_ERR(new_dentry);
6937         if (IS_ERR(new_dentry))
6938 @@ -2650,6 +2760,216 @@ int vfs_follow_link(struct nameidata *nd
6939         return __vfs_follow_link(nd, link);
6940  }
6941  
6942 +
6943 +#ifdef CONFIG_VSERVER_COWBL
6944 +
6945 +#include <linux/file.h>
6946 +
6947 +static inline
6948 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6949 +{
6950 +       loff_t ppos = 0;
6951 +
6952 +       return do_splice_direct(in, &ppos, out, len, 0);
6953 +}
6954 +
6955 +struct dentry *cow_break_link(const char *pathname)
6956 +{
6957 +       int ret, mode, pathlen, redo = 0;
6958 +       struct nameidata old_nd, dir_nd;
6959 +       struct dentry *old_dentry, *new_dentry;
6960 +       struct dentry *dir, *res = NULL;
6961 +       struct vfsmount *old_mnt, *new_mnt;
6962 +       struct file *old_file;
6963 +       struct file *new_file;
6964 +       char *to, *path, pad='\251';
6965 +       loff_t size;
6966 +
6967 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
6968 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6969 +       ret = -ENOMEM;
6970 +       if (!path)
6971 +               goto out;
6972 +
6973 +       /* old_nd will have refs to dentry and mnt */
6974 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
6975 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
6976 +       if (ret < 0)
6977 +               goto out_free_path;
6978 +
6979 +       old_dentry = old_nd.dentry;
6980 +       old_mnt = old_nd.mnt;
6981 +       mode = old_dentry->d_inode->i_mode;
6982 +
6983 +       to = d_path(old_dentry, old_mnt, path, PATH_MAX-2);
6984 +       pathlen = strlen(to);
6985 +       vxdprintk(VXD_CBIT(misc, 2), "old path »%s« [»%.*s«:%d]", to,
6986 +               old_dentry->d_name.len, old_dentry->d_name.name,
6987 +               old_dentry->d_name.len);
6988 +
6989 +       to[pathlen + 1] = 0;
6990 +retry:
6991 +       to[pathlen] = pad--;
6992 +       ret = -EMLINK;
6993 +       if (pad <= '\240')
6994 +               goto out_rel_old;
6995 +
6996 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
6997 +       /* dir_nd will have refs to dentry and mnt */
6998 +       ret = path_lookup(to,
6999 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
7000 +       vxdprintk(VXD_CBIT(misc, 2),
7001 +               "path_lookup(new): %d", ret);
7002 +       if (ret < 0)
7003 +               goto retry;
7004 +
7005 +       /* this puppy downs the inode mutex */
7006 +       new_dentry = lookup_create(&dir_nd, 0);
7007 +       vxdprintk(VXD_CBIT(misc, 2),
7008 +               "lookup_create(new): %p [»%.*s«:%d]", new_dentry,
7009 +               new_dentry->d_name.len, new_dentry->d_name.name,
7010 +               new_dentry->d_name.len);
7011 +       if (!new_dentry || IS_ERR(new_dentry)) {
7012 +               path_release(&dir_nd);
7013 +               goto retry;
7014 +       }
7015 +       dir = dir_nd.dentry;
7016 +
7017 +       ret = vfs_create(dir_nd.dentry->d_inode, new_dentry, mode, &dir_nd);
7018 +       vxdprintk(VXD_CBIT(misc, 2),
7019 +               "vfs_create(new): %d", ret);
7020 +       if (ret == -EEXIST) {
7021 +               mutex_unlock(&dir->d_inode->i_mutex);
7022 +               dput(new_dentry);
7023 +               path_release(&dir_nd);
7024 +               goto retry;
7025 +       }
7026 +       else if (ret < 0)
7027 +               goto out_unlock_new;
7028 +
7029 +       /* drop out early, ret passes ENOENT */
7030 +       ret = -ENOENT;
7031 +       if ((redo = d_unhashed(old_dentry)))
7032 +               goto out_unlock_new;
7033 +
7034 +       new_mnt = dir_nd.mnt;
7035 +       dget(old_dentry);
7036 +       mntget(old_mnt);
7037 +       /* this one cleans up the dentry/mnt in case of failure */
7038 +       old_file = dentry_open(old_dentry, old_mnt, O_RDONLY);
7039 +       vxdprintk(VXD_CBIT(misc, 2),
7040 +               "dentry_open(old): %p", old_file);
7041 +       if (!old_file || IS_ERR(old_file)) {
7042 +               res = IS_ERR(old_file) ? (void *) old_file : res;
7043 +               goto out_unlock_new;
7044 +       }
7045 +
7046 +       dget(new_dentry);
7047 +       mntget(new_mnt);
7048 +       /* this one cleans up the dentry/mnt in case of failure */
7049 +       new_file = dentry_open(new_dentry, new_mnt, O_WRONLY);
7050 +       vxdprintk(VXD_CBIT(misc, 2),
7051 +               "dentry_open(new): %p", new_file);
7052 +
7053 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
7054 +       if (!new_file || IS_ERR(new_file))
7055 +               goto out_fput_old;
7056 +
7057 +       size = i_size_read(old_file->f_dentry->d_inode);
7058 +       ret = do_cow_splice(old_file, new_file, size);
7059 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
7060 +       if (ret < 0) {
7061 +               goto out_fput_both;
7062 +       } else if (ret < size) {
7063 +               ret = -ENOSPC;
7064 +               goto out_fput_both;
7065 +       } else {
7066 +               struct inode *old_inode = old_dentry->d_inode;
7067 +               struct inode *new_inode = new_dentry->d_inode;
7068 +               struct iattr attr = {
7069 +                       .ia_uid = old_inode->i_uid,
7070 +                       .ia_gid = old_inode->i_gid,
7071 +                       .ia_valid = ATTR_UID | ATTR_GID
7072 +                       };
7073 +
7074 +               ret = inode_setattr(new_inode, &attr);
7075 +               if (ret)
7076 +                       goto out_fput_both;
7077 +       }
7078 +
7079 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
7080 +
7081 +       /* drop out late */
7082 +       ret = -ENOENT;
7083 +       if ((redo = d_unhashed(old_dentry)))
7084 +               goto out_unlock;
7085 +
7086 +       vxdprintk(VXD_CBIT(misc, 2),
7087 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
7088 +               new_dentry->d_name.len, new_dentry->d_name.name,
7089 +               new_dentry->d_name.len,
7090 +               old_dentry->d_name.len, old_dentry->d_name.name,
7091 +               old_dentry->d_name.len);
7092 +       ret = vfs_rename(dir_nd.dentry->d_inode, new_dentry,
7093 +               old_nd.dentry->d_parent->d_inode, old_dentry);
7094 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
7095 +       res = new_dentry;
7096 +
7097 +out_unlock:
7098 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
7099 +
7100 +out_fput_both:
7101 +       vxdprintk(VXD_CBIT(misc, 3),
7102 +               "fput(new_file=%p[#%d])", new_file,
7103 +               atomic_read(&new_file->f_count));
7104 +       fput(new_file);
7105 +
7106 +out_fput_old:
7107 +       vxdprintk(VXD_CBIT(misc, 3),
7108 +               "fput(old_file=%p[#%d])", old_file,
7109 +               atomic_read(&old_file->f_count));
7110 +       fput(old_file);
7111 +
7112 +out_unlock_new:
7113 +       mutex_unlock(&dir->d_inode->i_mutex);
7114 +       if (!ret)
7115 +               goto out_redo;
7116 +
7117 +       /* error path cleanup */
7118 +       vfs_unlink(dir->d_inode, new_dentry, &dir_nd);
7119 +       dput(new_dentry);
7120 +
7121 +out_redo:
7122 +       if (!redo)
7123 +               goto out_rel_both;
7124 +       /* lookup dentry once again */
7125 +       path_release(&old_nd);
7126 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
7127 +       if (ret)
7128 +               goto out_rel_both;
7129 +
7130 +       new_dentry = old_nd.dentry;
7131 +       vxdprintk(VXD_CBIT(misc, 2),
7132 +               "path_lookup(redo): %p [»%.*s«:%d]", new_dentry,
7133 +               new_dentry->d_name.len, new_dentry->d_name.name,
7134 +               new_dentry->d_name.len);
7135 +       dget(new_dentry);
7136 +       res = new_dentry;
7137 +
7138 +out_rel_both:
7139 +       path_release(&dir_nd);
7140 +out_rel_old:
7141 +       path_release(&old_nd);
7142 +out_free_path:
7143 +       kfree(path);
7144 +out:
7145 +       if (ret)
7146 +               res = ERR_PTR(ret);
7147 +       return res;
7148 +}
7149 +
7150 +#endif
7151 +
7152  /* get the link contents into pagecache */
7153  static char *page_getlink(struct dentry * dentry, struct page **ppage)
7154  {
7155 diff -NurpP --minimal linux-2.6.22.10/fs/namespace.c linux-2.6.22.10-vs2.3.0.29/fs/namespace.c
7156 --- linux-2.6.22.10/fs/namespace.c      2007-07-09 13:19:27 +0200
7157 +++ linux-2.6.22.10-vs2.3.0.29/fs/namespace.c   2007-09-05 02:29:17 +0200
7158 @@ -25,6 +25,11 @@
7159  #include <linux/security.h>
7160  #include <linux/mount.h>
7161  #include <linux/ramfs.h>
7162 +#include <linux/vs_base.h>
7163 +#include <linux/vs_context.h>
7164 +#include <linux/vs_tag.h>
7165 +#include <linux/vserver/space.h>
7166 +#include <linux/vserver/global.h>
7167  #include <asm/uaccess.h>
7168  #include <asm/unistd.h>
7169  #include "pnode.h"
7170 @@ -240,6 +245,7 @@ static struct vfsmount *clone_mnt(struct
7171                 mnt->mnt_root = dget(root);
7172                 mnt->mnt_mountpoint = mnt->mnt_root;
7173                 mnt->mnt_parent = mnt;
7174 +               mnt->mnt_tag = old->mnt_tag;
7175  
7176                 if (flag & CL_SLAVE) {
7177                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
7178 @@ -348,48 +354,91 @@ static inline void mangle(struct seq_fil
7179         seq_escape(m, s, " \t\n\\");
7180  }
7181  
7182 +static int mnt_is_reachable(struct vfsmount *mnt)
7183 +{
7184 +       struct vfsmount *root_mnt;
7185 +       struct dentry *root, *point;
7186 +       int ret;
7187 +
7188 +       if (mnt == mnt->mnt_ns->root)
7189 +               return 1;
7190 +
7191 +       spin_lock(&vfsmount_lock);
7192 +       root_mnt = current->fs->rootmnt;
7193 +       root = current->fs->root;
7194 +       point = root;
7195 +
7196 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
7197 +               point = mnt->mnt_mountpoint;
7198 +               mnt = mnt->mnt_parent;
7199 +       }
7200 +
7201 +       ret = (mnt == root_mnt) && is_subdir(point, root);
7202 +
7203 +       spin_unlock(&vfsmount_lock);
7204 +
7205 +       return ret;
7206 +}
7207 +
7208  static int show_vfsmnt(struct seq_file *m, void *v)
7209  {
7210         struct vfsmount *mnt = v;
7211         int err = 0;
7212         static struct proc_fs_info {
7213 -               int flag;
7214 -               char *str;
7215 +               int s_flag;
7216 +               int mnt_flag;
7217 +               char *set_str;
7218 +               char *unset_str;
7219         } fs_info[] = {
7220 -               { MS_SYNCHRONOUS, ",sync" },
7221 -               { MS_DIRSYNC, ",dirsync" },
7222 -               { MS_MANDLOCK, ",mand" },
7223 -               { 0, NULL }
7224 -       };
7225 -       static struct proc_fs_info mnt_info[] = {
7226 -               { MNT_NOSUID, ",nosuid" },
7227 -               { MNT_NODEV, ",nodev" },
7228 -               { MNT_NOEXEC, ",noexec" },
7229 -               { MNT_NOATIME, ",noatime" },
7230 -               { MNT_NODIRATIME, ",nodiratime" },
7231 -               { MNT_RELATIME, ",relatime" },
7232 -               { 0, NULL }
7233 +               { MS_RDONLY, MNT_RDONLY, "ro", "rw" },
7234 +               { MS_SYNCHRONOUS, 0, ",sync", NULL },
7235 +               { MS_DIRSYNC, 0, ",dirsync", NULL },
7236 +               { MS_MANDLOCK, 0, ",mand", NULL },
7237 +               { MS_TAGGED, 0, ",tag", NULL },
7238 +               { MS_NOATIME, MNT_NOATIME, ",noatime", NULL },
7239 +               { MS_NODIRATIME, MNT_NODIRATIME, ",nodiratime", NULL },
7240 +               { MS_RELATIME, MNT_RELATIME, ",relatime", NULL },
7241 +               { 0, MNT_NOSUID, ",nosuid", NULL },
7242 +               { 0, MNT_NODEV, ",nodev", NULL },
7243 +               { 0, MNT_NOEXEC, ",noexec", NULL },
7244 +               { 0, 0, NULL, NULL }
7245         };
7246 -       struct proc_fs_info *fs_infop;
7247 +       struct proc_fs_info *p;
7248 +       unsigned long s_flags = mnt->mnt_sb->s_flags;
7249 +       int mnt_flags = mnt->mnt_flags;
7250  
7251 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
7252 -       seq_putc(m, ' ');
7253 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7254 -       seq_putc(m, ' ');
7255 -       mangle(m, mnt->mnt_sb->s_type->name);
7256 -       if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
7257 -               seq_putc(m, '.');
7258 -               mangle(m, mnt->mnt_sb->s_subtype);
7259 -       }
7260 -       seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
7261 -       for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
7262 -               if (mnt->mnt_sb->s_flags & fs_infop->flag)
7263 -                       seq_puts(m, fs_infop->str);
7264 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7265 +               return 0;
7266 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7267 +               return 0;
7268 +
7269 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7270 +               mnt == current->fs->rootmnt) {
7271 +               seq_puts(m, "/dev/root / ");
7272 +       } else {
7273 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
7274 +               seq_putc(m, ' ');
7275 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7276 +               seq_putc(m, ' ');
7277 +
7278 +               if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
7279 +                       seq_putc(m, '.');
7280 +                       mangle(m, mnt->mnt_sb->s_subtype);
7281 +               }
7282         }
7283 -       for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
7284 -               if (mnt->mnt_flags & fs_infop->flag)
7285 -                       seq_puts(m, fs_infop->str);
7286 +       mangle(m, mnt->mnt_sb->s_type->name);
7287 +       seq_putc(m, ' ');
7288 +       for (p = fs_info; (p->s_flag | p->mnt_flag) ; p++) {
7289 +               if ((s_flags & p->s_flag) || (mnt_flags & p->mnt_flag)) {
7290 +                       if (p->set_str)
7291 +                               seq_puts(m, p->set_str);
7292 +               } else {
7293 +                       if (p->unset_str)
7294 +                               seq_puts(m, p->unset_str);
7295 +               }
7296         }
7297 +       if (mnt->mnt_flags & MNT_TAGID)
7298 +               seq_printf(m, ",tag=%d", mnt->mnt_tag);
7299         if (mnt->mnt_sb->s_op->show_options)
7300                 err = mnt->mnt_sb->s_op->show_options(m, mnt);
7301         seq_puts(m, " 0 0\n");
7302 @@ -408,17 +457,27 @@ static int show_vfsstat(struct seq_file 
7303         struct vfsmount *mnt = v;
7304         int err = 0;
7305  
7306 -       /* device */
7307 -       if (mnt->mnt_devname) {
7308 -               seq_puts(m, "device ");
7309 -               mangle(m, mnt->mnt_devname);
7310 -       } else
7311 -               seq_puts(m, "no device");
7312 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
7313 +               return 0;
7314 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
7315 +               return 0;
7316  
7317 -       /* mount point */
7318 -       seq_puts(m, " mounted on ");
7319 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7320 -       seq_putc(m, ' ');
7321 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
7322 +               mnt == current->fs->rootmnt) {
7323 +               seq_puts(m, "device /dev/root mounted on / ");
7324 +       } else {
7325 +               /* device */
7326 +               if (mnt->mnt_devname) {
7327 +                       seq_puts(m, "device ");
7328 +                       mangle(m, mnt->mnt_devname);
7329 +               } else
7330 +                       seq_puts(m, "no device");
7331 +
7332 +               /* mount point */
7333 +               seq_puts(m, " mounted on ");
7334 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
7335 +               seq_putc(m, ' ');
7336 +       }
7337  
7338         /* file system type */
7339         seq_puts(m, "with fstype ");
7340 @@ -648,7 +707,7 @@ asmlinkage long sys_umount(char __user *
7341                 goto dput_and_out;
7342  
7343         retval = -EPERM;
7344 -       if (!capable(CAP_SYS_ADMIN))
7345 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7346                 goto dput_and_out;
7347  
7348         retval = do_umount(nd.mnt, flags);
7349 @@ -672,7 +731,7 @@ asmlinkage long sys_oldumount(char __use
7350  
7351  static int mount_is_safe(struct nameidata *nd)
7352  {
7353 -       if (capable(CAP_SYS_ADMIN))
7354 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7355                 return 0;
7356         return -EPERM;
7357  #ifdef notyet
7358 @@ -904,11 +963,13 @@ static int do_change_type(struct nameida
7359  /*
7360   * do loopback mount.
7361   */
7362 -static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
7363 +static int do_loopback(struct nameidata *nd, char *old_name, tag_t tag,
7364 +       unsigned long flags, int mnt_flags)
7365  {
7366         struct nameidata old_nd;
7367         struct vfsmount *mnt = NULL;
7368         int err = mount_is_safe(nd);
7369 +       int recurse = flags & MS_REC;
7370         if (err)
7371                 return err;
7372         if (!old_name || !*old_name)
7373 @@ -934,6 +995,12 @@ static int do_loopback(struct nameidata 
7374         if (!mnt)
7375                 goto out;
7376  
7377 +       mnt->mnt_flags = mnt_flags;
7378 +       if (flags & MS_TAGID) {
7379 +               mnt->mnt_tag = tag;
7380 +               mnt->mnt_flags |= MNT_TAGID;
7381 +       }
7382 +
7383         err = graft_tree(mnt, nd);
7384         if (err) {
7385                 LIST_HEAD(umount_list);
7386 @@ -942,6 +1009,7 @@ static int do_loopback(struct nameidata 
7387                 spin_unlock(&vfsmount_lock);
7388                 release_mounts(&umount_list);
7389         }
7390 +       mnt->mnt_flags = mnt_flags;
7391  
7392  out:
7393         up_write(&namespace_sem);
7394 @@ -955,12 +1023,12 @@ out:
7395   * on it - tough luck.
7396   */
7397  static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
7398 -                     void *data)
7399 +                     void *data, xid_t xid)
7400  {
7401         int err;
7402         struct super_block *sb = nd->mnt->mnt_sb;
7403  
7404 -       if (!capable(CAP_SYS_ADMIN))
7405 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
7406                 return -EPERM;
7407  
7408         if (!check_mnt(nd->mnt))
7409 @@ -994,7 +1062,7 @@ static int do_move_mount(struct nameidat
7410         struct nameidata old_nd, parent_nd;
7411         struct vfsmount *p;
7412         int err = 0;
7413 -       if (!capable(CAP_SYS_ADMIN))
7414 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7415                 return -EPERM;
7416         if (!old_name || !*old_name)
7417                 return -EINVAL;
7418 @@ -1074,7 +1142,7 @@ static int do_new_mount(struct nameidata
7419                 return -EINVAL;
7420  
7421         /* we need capabilities... */
7422 -       if (!capable(CAP_SYS_ADMIN))
7423 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
7424                 return -EPERM;
7425  
7426         mnt = do_kern_mount(type, flags, name, data);
7427 @@ -1386,6 +1454,7 @@ long do_mount(char *dev_name, char *dir_
7428         struct nameidata nd;
7429         int retval = 0;
7430         int mnt_flags = 0;
7431 +       tag_t tag = 0;
7432  
7433         /* Discard magic */
7434         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
7435 @@ -1401,7 +1470,17 @@ long do_mount(char *dev_name, char *dir_
7436         if (data_page)
7437                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
7438  
7439 +       retval = dx_parse_tag(data_page, &tag, 1);
7440 +       if (retval) {
7441 +               mnt_flags |= retval;
7442 +               /* FIXME: bind and re-mounts get the tag flag? */
7443 +               if (flags & (MS_BIND|MS_REMOUNT))
7444 +                       flags |= MS_TAGID;
7445 +       }
7446 +
7447         /* Separate the per-mountpoint flags */
7448 +       if (flags & MS_RDONLY)
7449 +               mnt_flags |= MNT_RDONLY;
7450         if (flags & MS_NOSUID)
7451                 mnt_flags |= MNT_NOSUID;
7452         if (flags & MS_NODEV)
7453 @@ -1415,6 +1494,8 @@ long do_mount(char *dev_name, char *dir_
7454         if (flags & MS_RELATIME)
7455                 mnt_flags |= MNT_RELATIME;
7456  
7457 +       if (!capable(CAP_SYS_ADMIN))
7458 +               mnt_flags |= MNT_NODEV;
7459         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
7460                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME);
7461  
7462 @@ -1429,9 +1510,9 @@ long do_mount(char *dev_name, char *dir_
7463  
7464         if (flags & MS_REMOUNT)
7465                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
7466 -                                   data_page);
7467 +                                   data_page, tag);
7468         else if (flags & MS_BIND)
7469 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
7470 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
7471         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
7472                 retval = do_change_type(&nd, flags);
7473         else if (flags & MS_MOVE)
7474 @@ -1504,6 +1585,7 @@ static struct mnt_namespace *dup_mnt_ns(
7475                 q = next_mnt(q, new_ns->root);
7476         }
7477         up_write(&namespace_sem);
7478 +       atomic_inc(&vs_global_mnt_ns);
7479  
7480         if (rootmnt)
7481                 mntput(rootmnt);
7482 @@ -1866,5 +1948,6 @@ void __put_mnt_ns(struct mnt_namespace *
7483         spin_unlock(&vfsmount_lock);
7484         up_write(&namespace_sem);
7485         release_mounts(&umount_list);
7486 +       atomic_dec(&vs_global_mnt_ns);
7487         kfree(ns);
7488  }
7489 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/client.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/client.c
7490 --- linux-2.6.22.10/fs/nfs/client.c     2007-07-09 13:19:27 +0200
7491 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/client.c  2007-08-05 20:53:13 +0200
7492 @@ -521,6 +521,9 @@ static int nfs_init_server_rpcclient(str
7493         if (server->flags & NFS4_MOUNT_INTR)
7494                 server->client->cl_intr = 1;
7495  
7496 +       server->client->cl_tag = 0;
7497 +       if (server->flags & NFS_MOUNT_TAGGED)
7498 +               server->client->cl_tag = 1;
7499         return 0;
7500  }
7501  
7502 @@ -678,6 +681,10 @@ static void nfs_server_set_fsinfo(struct
7503                 server->acdirmin = server->acdirmax = 0;
7504         }
7505  
7506 +       /* FIXME: needs fsinfo
7507 +       if (server->flags & NFS_MOUNT_TAGGED)
7508 +               sb->s_flags |= MS_TAGGED;       */
7509 +
7510         server->maxfilesize = fsinfo->maxfilesize;
7511  
7512         /* We're airborne Set socket buffersize */
7513 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/dir.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/dir.c
7514 --- linux-2.6.22.10/fs/nfs/dir.c        2007-07-09 13:19:27 +0200
7515 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/dir.c     2007-08-05 20:53:13 +0200
7516 @@ -34,6 +34,7 @@
7517  #include <linux/namei.h>
7518  #include <linux/mount.h>
7519  #include <linux/sched.h>
7520 +#include <linux/vs_tag.h>
7521  
7522  #include "nfs4_fs.h"
7523  #include "delegation.h"
7524 @@ -956,6 +957,7 @@ static struct dentry *nfs_lookup(struct 
7525         if (IS_ERR(res))
7526                 goto out_unlock;
7527  
7528 +       dx_propagate_tag(nd, inode);
7529  no_entry:
7530         res = d_materialise_unique(dentry, inode);
7531         if (res != NULL) {
7532 @@ -998,7 +1000,8 @@ static int is_atomic_open(struct inode *
7533         if (nd->flags & LOOKUP_DIRECTORY)
7534                 return 0;
7535         /* Are we trying to write to a read only partition? */
7536 -       if (IS_RDONLY(dir) && (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7537 +       if ((IS_RDONLY(dir) || MNT_IS_RDONLY(nd->mnt)) &&
7538 +               (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7539                 return 0;
7540         return 1;
7541  }
7542 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/inode.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/inode.c
7543 --- linux-2.6.22.10/fs/nfs/inode.c      2007-07-09 13:19:27 +0200
7544 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/inode.c   2007-08-05 20:53:13 +0200
7545 @@ -37,6 +37,7 @@
7546  #include <linux/vfs.h>
7547  #include <linux/inet.h>
7548  #include <linux/nfs_xdr.h>
7549 +#include <linux/vs_tag.h>
7550  
7551  #include <asm/system.h>
7552  #include <asm/uaccess.h>
7553 @@ -285,8 +286,10 @@ nfs_fhget(struct super_block *sb, struct
7554                         nfsi->change_attr = fattr->change_attr;
7555                 inode->i_size = nfs_size_to_loff_t(fattr->size);
7556                 inode->i_nlink = fattr->nlink;
7557 -               inode->i_uid = fattr->uid;
7558 -               inode->i_gid = fattr->gid;
7559 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7560 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7561 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7562 +                                        /* maybe fattr->xid someday */
7563                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7564                         /*
7565                          * report the blocks in 512byte units
7566 @@ -377,6 +380,8 @@ void nfs_setattr_update_inode(struct ino
7567                         inode->i_uid = attr->ia_uid;
7568                 if ((attr->ia_valid & ATTR_GID) != 0)
7569                         inode->i_gid = attr->ia_gid;
7570 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
7571 +                       inode->i_tag = attr->ia_tag;
7572                 spin_lock(&inode->i_lock);
7573                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7574                 spin_unlock(&inode->i_lock);
7575 @@ -825,6 +830,9 @@ static int nfs_check_inode_attributes(st
7576         struct nfs_inode *nfsi = NFS_I(inode);
7577         loff_t cur_size, new_isize;
7578         int data_unstable;
7579 +       uid_t uid;
7580 +       gid_t gid;
7581 +       tag_t tag;
7582  
7583  
7584         /* Has the inode gone and changed behind our back? */
7585 @@ -852,10 +860,15 @@ static int nfs_check_inode_attributes(st
7586         if (cur_size != new_isize && nfsi->npages == 0)
7587                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
7588  
7589 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7590 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7591 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7592 +
7593         /* Have any file permissions changed? */
7594         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
7595 -                       || inode->i_uid != fattr->uid
7596 -                       || inode->i_gid != fattr->gid)
7597 +                       || inode->i_uid != uid
7598 +                       || inode->i_gid != gid
7599 +                       || inode->i_tag != tag)
7600                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7601  
7602         /* Has the link count changed? */
7603 @@ -946,6 +959,9 @@ static int nfs_update_inode(struct inode
7604         unsigned int    invalid = 0;
7605         unsigned long now = jiffies;
7606         int data_stable;
7607 +       uid_t uid;
7608 +       gid_t gid;
7609 +       tag_t tag;
7610  
7611         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
7612                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
7613 @@ -1022,15 +1038,21 @@ static int nfs_update_inode(struct inode
7614         }
7615         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
7616  
7617 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7618 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7619 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7620 +
7621         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
7622 -           inode->i_uid != fattr->uid ||
7623 -           inode->i_gid != fattr->gid)
7624 +           inode->i_uid != uid ||
7625 +           inode->i_gid != gid ||
7626 +           inode->i_tag != tag)
7627                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7628  
7629         inode->i_mode = fattr->mode;
7630         inode->i_nlink = fattr->nlink;
7631 -       inode->i_uid = fattr->uid;
7632 -       inode->i_gid = fattr->gid;
7633 +       inode->i_uid = uid;
7634 +       inode->i_gid = gid;
7635 +       inode->i_tag = tag;
7636  
7637         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7638                 /*
7639 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/nfs3xdr.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/nfs3xdr.c
7640 --- linux-2.6.22.10/fs/nfs/nfs3xdr.c    2007-07-09 13:19:27 +0200
7641 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/nfs3xdr.c 2007-08-05 20:53:13 +0200
7642 @@ -22,6 +22,7 @@
7643  #include <linux/nfs3.h>
7644  #include <linux/nfs_fs.h>
7645  #include <linux/nfsacl.h>
7646 +#include <linux/vs_tag.h>
7647  #include "internal.h"
7648  
7649  #define NFSDBG_FACILITY                NFSDBG_XDR
7650 @@ -178,7 +179,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
7651  }
7652  
7653  static inline __be32 *
7654 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
7655 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
7656  {
7657         if (attr->ia_valid & ATTR_MODE) {
7658                 *p++ = xdr_one;
7659 @@ -186,15 +187,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
7660         } else {
7661                 *p++ = xdr_zero;
7662         }
7663 -       if (attr->ia_valid & ATTR_UID) {
7664 +       if (attr->ia_valid & ATTR_UID ||
7665 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7666                 *p++ = xdr_one;
7667 -               *p++ = htonl(attr->ia_uid);
7668 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
7669         } else {
7670                 *p++ = xdr_zero;
7671         }
7672 -       if (attr->ia_valid & ATTR_GID) {
7673 +       if (attr->ia_valid & ATTR_GID ||
7674 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7675                 *p++ = xdr_one;
7676 -               *p++ = htonl(attr->ia_gid);
7677 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
7678         } else {
7679                 *p++ = xdr_zero;
7680         }
7681 @@ -279,7 +282,8 @@ static int
7682  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
7683  {
7684         p = xdr_encode_fhandle(p, args->fh);
7685 -       p = xdr_encode_sattr(p, args->sattr);
7686 +       p = xdr_encode_sattr(p, args->sattr,
7687 +               req->rq_task->tk_client->cl_tag);
7688         *p++ = htonl(args->guard);
7689         if (args->guard)
7690                 p = xdr_encode_time3(p, &args->guardtime);
7691 @@ -370,7 +374,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
7692                 *p++ = args->verifier[0];
7693                 *p++ = args->verifier[1];
7694         } else
7695 -               p = xdr_encode_sattr(p, args->sattr);
7696 +               p = xdr_encode_sattr(p, args->sattr,
7697 +                       req->rq_task->tk_client->cl_tag);
7698  
7699         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7700         return 0;
7701 @@ -384,7 +389,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
7702  {
7703         p = xdr_encode_fhandle(p, args->fh);
7704         p = xdr_encode_array(p, args->name, args->len);
7705 -       p = xdr_encode_sattr(p, args->sattr);
7706 +       p = xdr_encode_sattr(p, args->sattr,
7707 +               req->rq_task->tk_client->cl_tag);
7708         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7709         return 0;
7710  }
7711 @@ -397,7 +403,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
7712  {
7713         p = xdr_encode_fhandle(p, args->fromfh);
7714         p = xdr_encode_array(p, args->fromname, args->fromlen);
7715 -       p = xdr_encode_sattr(p, args->sattr);
7716 +       p = xdr_encode_sattr(p, args->sattr,
7717 +               req->rq_task->tk_client->cl_tag);
7718         *p++ = htonl(args->pathlen);
7719         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7720  
7721 @@ -415,7 +422,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
7722         p = xdr_encode_fhandle(p, args->fh);
7723         p = xdr_encode_array(p, args->name, args->len);
7724         *p++ = htonl(args->type);
7725 -       p = xdr_encode_sattr(p, args->sattr);
7726 +       p = xdr_encode_sattr(p, args->sattr,
7727 +               req->rq_task->tk_client->cl_tag);
7728         if (args->type == NF3CHR || args->type == NF3BLK) {
7729                 *p++ = htonl(MAJOR(args->rdev));
7730                 *p++ = htonl(MINOR(args->rdev));
7731 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/nfsroot.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/nfsroot.c
7732 --- linux-2.6.22.10/fs/nfs/nfsroot.c    2007-07-09 13:19:27 +0200
7733 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/nfsroot.c 2007-08-05 20:53:13 +0200
7734 @@ -118,12 +118,12 @@ static int mount_port __initdata = 0;             /
7735  enum {
7736         /* Options that take integer arguments */
7737         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
7738 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
7739 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
7740         /* Options that take no arguments */
7741         Opt_soft, Opt_hard, Opt_intr,
7742         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
7743         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
7744 -       Opt_acl, Opt_noacl,
7745 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
7746         /* Error token */
7747         Opt_err
7748  };
7749 @@ -160,6 +160,9 @@ static match_table_t __initdata tokens =
7750         {Opt_tcp, "tcp"},
7751         {Opt_acl, "acl"},
7752         {Opt_noacl, "noacl"},
7753 +       {Opt_tag, "tag"},
7754 +       {Opt_notag, "notag"},
7755 +       {Opt_tagid, "tagid=%u"},
7756         {Opt_err, NULL}
7757         
7758  };
7759 @@ -274,6 +277,20 @@ static int __init root_nfs_parse(char *n
7760                         case Opt_noacl:
7761                                 nfs_data.flags |= NFS_MOUNT_NOACL;
7762                                 break;
7763 +#ifndef CONFIG_TAGGING_NONE
7764 +                       case Opt_tag:
7765 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7766 +                               break;
7767 +                       case Opt_notag:
7768 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
7769 +                               break;
7770 +#endif
7771 +#ifdef CONFIG_PROPAGATE
7772 +                       case Opt_tagid:
7773 +                               /* use args[0] */
7774 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7775 +                               break;
7776 +#endif
7777                         default:
7778                                 printk(KERN_WARNING "Root-NFS: unknown "
7779                                         "option: %s\n", p);
7780 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/super.c linux-2.6.22.10-vs2.3.0.29/fs/nfs/super.c
7781 --- linux-2.6.22.10/fs/nfs/super.c      2007-10-30 01:57:14 +0100
7782 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfs/super.c   2007-09-30 14:58:01 +0200
7783 @@ -45,6 +45,7 @@
7784  #include <linux/nfs_xdr.h>
7785  #include <linux/magic.h>
7786  #include <linux/parser.h>
7787 +#include <linux/vs_tag.h>
7788  
7789  #include <asm/system.h>
7790  #include <asm/uaccess.h>
7791 @@ -291,6 +292,7 @@ static void nfs_show_mount_options(struc
7792                 { NFS_MOUNT_NOACL, ",noacl", "" },
7793                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
7794                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
7795 +               { NFS_MOUNT_TAGGED, ",tag", "" },
7796                 { 0, NULL, NULL }
7797         };
7798         const struct proc_nfs_info *nfs_infop;
7799 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
7800 --- linux-2.6.22.10/fs/nfsd/auth.c      2006-06-18 04:54:42 +0200
7801 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/auth.c   2007-08-05 20:53:13 +0200
7802 @@ -9,6 +9,7 @@
7803  #include <linux/sunrpc/svc.h>
7804  #include <linux/sunrpc/svcauth.h>
7805  #include <linux/nfsd/nfsd.h>
7806 +#include <linux/vs_tag.h>
7807  
7808  #define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
7809  
7810 @@ -41,19 +42,22 @@ int nfsd_setuser(struct svc_rqst *rqstp,
7811                 get_group_info(cred.cr_group_info);
7812  
7813         if (cred.cr_uid != (uid_t) -1)
7814 -               current->fsuid = cred.cr_uid;
7815 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7816         else
7817                 current->fsuid = exp->ex_anon_uid;
7818         if (cred.cr_gid != (gid_t) -1)
7819 -               current->fsgid = cred.cr_gid;
7820 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7821         else
7822                 current->fsgid = exp->ex_anon_gid;
7823  
7824 +       /* this desperately needs a tag :) */
7825 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
7826 +
7827         if (!cred.cr_group_info)
7828                 return -ENOMEM;
7829         ret = set_current_groups(cred.cr_group_info);
7830         put_group_info(cred.cr_group_info);
7831 -       if ((cred.cr_uid)) {
7832 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
7833                 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
7834         } else {
7835                 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
7836 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs3xdr.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs3xdr.c
7837 --- linux-2.6.22.10/fs/nfsd/nfs3xdr.c   2007-07-09 13:19:27 +0200
7838 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs3xdr.c        2007-08-05 20:53:13 +0200
7839 @@ -21,6 +21,7 @@
7840  #include <linux/sunrpc/svc.h>
7841  #include <linux/nfsd/nfsd.h>
7842  #include <linux/nfsd/xdr3.h>
7843 +#include <linux/vs_tag.h>
7844  
7845  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7846  
7847 @@ -107,6 +108,8 @@ static __be32 *
7848  decode_sattr3(__be32 *p, struct iattr *iap)
7849  {
7850         u32     tmp;
7851 +       uid_t   uid = 0;
7852 +       gid_t   gid = 0;
7853  
7854         iap->ia_valid = 0;
7855  
7856 @@ -116,12 +119,15 @@ decode_sattr3(__be32 *p, struct iattr *i
7857         }
7858         if (*p++) {
7859                 iap->ia_valid |= ATTR_UID;
7860 -               iap->ia_uid = ntohl(*p++);
7861 +               uid = ntohl(*p++);
7862         }
7863         if (*p++) {
7864                 iap->ia_valid |= ATTR_GID;
7865 -               iap->ia_gid = ntohl(*p++);
7866 +               gid = ntohl(*p++);
7867         }
7868 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7869 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7870 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7871         if (*p++) {
7872                 u64     newsize;
7873  
7874 @@ -180,8 +186,10 @@ encode_fattr3(struct svc_rqst *rqstp, __
7875         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
7876         *p++ = htonl((u32) stat->mode);
7877         *p++ = htonl((u32) stat->nlink);
7878 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7879 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7880 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7881 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7882 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7883 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7884         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
7885                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
7886         } else {
7887 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs4recover.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs4recover.c
7888 --- linux-2.6.22.10/fs/nfsd/nfs4recover.c       2007-07-09 13:19:27 +0200
7889 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs4recover.c    2007-08-05 20:53:13 +0200
7890 @@ -156,7 +156,7 @@ nfsd4_create_clid_dir(struct nfs4_client
7891                 dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
7892                 goto out_put;
7893         }
7894 -       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU);
7895 +       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU, NULL);
7896  out_put:
7897         dput(dentry);
7898  out_unlock:
7899 @@ -260,7 +260,7 @@ nfsd4_remove_clid_file(struct dentry *di
7900                 return -EINVAL;
7901         }
7902         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7903 -       status = vfs_unlink(dir->d_inode, dentry);
7904 +       status = vfs_unlink(dir->d_inode, dentry, NULL);
7905         mutex_unlock(&dir->d_inode->i_mutex);
7906         return status;
7907  }
7908 @@ -275,7 +275,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,
7909          * a kernel from the future.... */
7910         nfsd4_list_rec_dir(dentry, nfsd4_remove_clid_file);
7911         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7912 -       status = vfs_rmdir(dir->d_inode, dentry);
7913 +       status = vfs_rmdir(dir->d_inode, dentry, NULL);
7914         mutex_unlock(&dir->d_inode->i_mutex);
7915         return status;
7916  }
7917 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs4xdr.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs4xdr.c
7918 --- linux-2.6.22.10/fs/nfsd/nfs4xdr.c   2007-07-09 13:19:27 +0200
7919 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfs4xdr.c        2007-08-05 20:53:13 +0200
7920 @@ -56,6 +56,7 @@
7921  #include <linux/nfs4_acl.h>
7922  #include <linux/sunrpc/gss_api.h>
7923  #include <linux/sunrpc/svcauth_gss.h>
7924 +#include <linux/vs_tag.h>
7925  
7926  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7927  
7928 @@ -1727,14 +1728,18 @@ out_acl:
7929                 WRITE32(stat.nlink);
7930         }
7931         if (bmval1 & FATTR4_WORD1_OWNER) {
7932 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7933 +               status = nfsd4_encode_user(rqstp,
7934 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7935 +                       stat.uid, stat.tag), &p, &buflen);
7936                 if (status == nfserr_resource)
7937                         goto out_resource;
7938                 if (status)
7939                         goto out;
7940         }
7941         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7942 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7943 +               status = nfsd4_encode_group(rqstp,
7944 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7945 +                       stat.gid, stat.tag), &p, &buflen);
7946                 if (status == nfserr_resource)
7947                         goto out_resource;
7948                 if (status)
7949 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfsxdr.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfsxdr.c
7950 --- linux-2.6.22.10/fs/nfsd/nfsxdr.c    2007-07-09 13:19:27 +0200
7951 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/nfsxdr.c 2007-08-05 20:53:13 +0200
7952 @@ -15,6 +15,7 @@
7953  #include <linux/nfsd/nfsd.h>
7954  #include <linux/nfsd/xdr.h>
7955  #include <linux/mm.h>
7956 +#include <linux/vs_tag.h>
7957  
7958  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7959  
7960 @@ -97,6 +98,8 @@ static __be32 *
7961  decode_sattr(__be32 *p, struct iattr *iap)
7962  {
7963         u32     tmp, tmp1;
7964 +       uid_t   uid = 0;
7965 +       gid_t   gid = 0;
7966  
7967         iap->ia_valid = 0;
7968  
7969 @@ -110,12 +113,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7970         }
7971         if ((tmp = ntohl(*p++)) != (u32)-1) {
7972                 iap->ia_valid |= ATTR_UID;
7973 -               iap->ia_uid = tmp;
7974 +               uid = tmp;
7975         }
7976         if ((tmp = ntohl(*p++)) != (u32)-1) {
7977                 iap->ia_valid |= ATTR_GID;
7978 -               iap->ia_gid = tmp;
7979 +               gid = tmp;
7980         }
7981 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7982 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7983 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7984         if ((tmp = ntohl(*p++)) != (u32)-1) {
7985                 iap->ia_valid |= ATTR_SIZE;
7986                 iap->ia_size = tmp;
7987 @@ -160,8 +166,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
7988         *p++ = htonl(nfs_ftypes[type >> 12]);
7989         *p++ = htonl((u32) stat->mode);
7990         *p++ = htonl((u32) stat->nlink);
7991 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7992 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7993 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7994 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7995 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7996 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7997  
7998         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
7999                 *p++ = htonl(NFS_MAXPATHLEN);
8000 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/vfs.c linux-2.6.22.10-vs2.3.0.29/fs/nfsd/vfs.c
8001 --- linux-2.6.22.10/fs/nfsd/vfs.c       2007-10-30 01:57:14 +0100
8002 +++ linux-2.6.22.10-vs2.3.0.29/fs/nfsd/vfs.c    2007-08-11 22:41:51 +0200
8003 @@ -1186,13 +1186,13 @@ nfsd_create(struct svc_rqst *rqstp, stru
8004                 host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
8005                 break;
8006         case S_IFDIR:
8007 -               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
8008 +               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode, NULL);
8009                 break;
8010         case S_IFCHR:
8011         case S_IFBLK:
8012         case S_IFIFO:
8013         case S_IFSOCK:
8014 -               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
8015 +               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev, NULL);
8016                 break;
8017         default:
8018                 printk("nfsd: bad file type %o in nfsd_create\n", type);
8019 @@ -1466,11 +1466,13 @@ nfsd_symlink(struct svc_rqst *rqstp, str
8020                 else {
8021                         strncpy(path_alloced, path, plen);
8022                         path_alloced[plen] = 0;
8023 -                       host_err = vfs_symlink(dentry->d_inode, dnew, path_alloced, mode);
8024 +                       host_err = vfs_symlink(dentry->d_inode, dnew,
8025 +                               path_alloced, mode, NULL);
8026                         kfree(path_alloced);
8027                 }
8028         } else
8029 -               host_err = vfs_symlink(dentry->d_inode, dnew, path, mode);
8030 +               host_err = vfs_symlink(dentry->d_inode, dnew,
8031 +                       path, mode, NULL);
8032  
8033         if (!host_err) {
8034                 if (EX_ISSYNC(fhp->fh_export))
8035 @@ -1529,7 +1531,7 @@ nfsd_link(struct svc_rqst *rqstp, struct
8036         dold = tfhp->fh_dentry;
8037         dest = dold->d_inode;
8038  
8039 -       host_err = vfs_link(dold, dirp, dnew);
8040 +       host_err = vfs_link(dold, dirp, dnew, NULL);
8041         if (!host_err) {
8042                 if (EX_ISSYNC(ffhp->fh_export)) {
8043                         err = nfserrno(nfsd_sync_dir(ddir));
8044 @@ -1694,9 +1696,9 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
8045                         host_err = -EPERM;
8046                 } else
8047  #endif
8048 -               host_err = vfs_unlink(dirp, rdentry);
8049 +               host_err = vfs_unlink(dirp, rdentry, NULL);
8050         } else { /* It's RMDIR */
8051 -               host_err = vfs_rmdir(dirp, rdentry);
8052 +               host_err = vfs_rmdir(dirp, rdentry, NULL);
8053         }
8054  
8055         dput(rdentry);
8056 @@ -1807,7 +1809,8 @@ nfsd_permission(struct svc_export *exp, 
8057          */
8058         if (!(acc & MAY_LOCAL_ACCESS))
8059                 if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
8060 -                       if (EX_RDONLY(exp, rqstp) || IS_RDONLY(inode))
8061 +                       if (EX_RDONLY(exp, rqstp) || IS_RDONLY(inode)
8062 +                               || MNT_IS_RDONLY(exp->ex_mnt))
8063                                 return nfserr_rofs;
8064                         if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
8065                                 return nfserr_perm;
8066 diff -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
8067 --- linux-2.6.22.10/fs/ocfs2/dlm/dlmfs.c        2007-07-09 13:19:28 +0200
8068 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlm/dlmfs.c     2007-08-05 20:53:13 +0200
8069 @@ -43,6 +43,7 @@
8070  #include <linux/init.h>
8071  #include <linux/string.h>
8072  #include <linux/backing-dev.h>
8073 +#include <linux/vs_tag.h>
8074  
8075  #include <asm/uaccess.h>
8076  
8077 @@ -331,6 +332,7 @@ static struct inode *dlmfs_get_root_inod
8078                 inode->i_mode = mode;
8079                 inode->i_uid = current->fsuid;
8080                 inode->i_gid = current->fsgid;
8081 +               inode->i_tag = dx_current_fstag(sb);
8082                 inode->i_blocks = 0;
8083                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
8084                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
8085 @@ -357,6 +359,7 @@ static struct inode *dlmfs_get_inode(str
8086         inode->i_mode = mode;
8087         inode->i_uid = current->fsuid;
8088         inode->i_gid = current->fsgid;
8089 +       inode->i_tag = dx_current_fstag(sb);
8090         inode->i_blocks = 0;
8091         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
8092         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
8093 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/dlmglue.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlmglue.c
8094 --- linux-2.6.22.10/fs/ocfs2/dlmglue.c  2007-07-09 13:19:28 +0200
8095 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlmglue.c       2007-08-05 20:53:13 +0200
8096 @@ -1475,6 +1475,7 @@ static void __ocfs2_stuff_meta_lvb(struc
8097         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
8098         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
8099         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
8100 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
8101         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
8102         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
8103         lvb->lvb_iatime_packed  =
8104 @@ -1527,6 +1528,7 @@ static void ocfs2_refresh_inode_from_lvb
8105  
8106         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
8107         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
8108 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
8109         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
8110         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
8111         ocfs2_unpack_timespec(&inode->i_atime,
8112 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/dlmglue.h linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlmglue.h
8113 --- linux-2.6.22.10/fs/ocfs2/dlmglue.h  2007-07-09 13:19:28 +0200
8114 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/dlmglue.h       2007-08-05 20:53:13 +0200
8115 @@ -34,7 +34,7 @@
8116  struct ocfs2_meta_lvb {
8117         __u8         lvb_version;
8118         __u8         lvb_reserved0;
8119 -       __be16       lvb_reserved1;
8120 +       __be16       lvb_itag;
8121         __be32       lvb_iclusters;
8122         __be32       lvb_iuid;
8123         __be32       lvb_igid;
8124 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/file.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/file.c
8125 --- linux-2.6.22.10/fs/ocfs2/file.c     2007-10-30 01:57:14 +0100
8126 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/file.c  2007-09-05 03:06:11 +0200
8127 @@ -943,13 +943,15 @@ int ocfs2_setattr(struct dentry *dentry,
8128                 mlog(0, "uid change: %d\n", attr->ia_uid);
8129         if (attr->ia_valid & ATTR_GID)
8130                 mlog(0, "gid change: %d\n", attr->ia_gid);
8131 +       if (attr->ia_valid & ATTR_TAG)
8132 +               mlog(0, "tag change: %d\n", attr->ia_tag);
8133         if (attr->ia_valid & ATTR_SIZE)
8134                 mlog(0, "size change...\n");
8135         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
8136                 mlog(0, "time change...\n");
8137  
8138  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
8139 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
8140 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
8141         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
8142                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
8143                 return 0;
8144 @@ -1805,6 +1807,7 @@ bail:
8145  const struct inode_operations ocfs2_file_iops = {
8146         .setattr        = ocfs2_setattr,
8147         .getattr        = ocfs2_getattr,
8148 +       .sync_flags     = ocfs2_sync_flags,
8149         .permission     = ocfs2_permission,
8150  };
8151  
8152 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/inode.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/inode.c
8153 --- linux-2.6.22.10/fs/ocfs2/inode.c    2007-07-09 13:19:28 +0200
8154 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/inode.c 2007-08-05 20:53:13 +0200
8155 @@ -28,6 +28,7 @@
8156  #include <linux/slab.h>
8157  #include <linux/highmem.h>
8158  #include <linux/pagemap.h>
8159 +#include <linux/vs_tag.h>
8160  
8161  #include <asm/byteorder.h>
8162  
8163 @@ -42,6 +43,7 @@
8164  #include "file.h"
8165  #include "heartbeat.h"
8166  #include "inode.h"
8167 +#include "ioctl.h"
8168  #include "journal.h"
8169  #include "namei.h"
8170  #include "suballoc.h"
8171 @@ -77,6 +79,10 @@ void ocfs2_set_inode_flags(struct inode 
8172  
8173         if (flags & OCFS2_IMMUTABLE_FL)
8174                 inode->i_flags |= S_IMMUTABLE;
8175 +       if (flags & OCFS2_IUNLINK_FL)
8176 +               inode->i_flags |= S_IUNLINK;
8177 +       if (flags & OCFS2_BARRIER_FL)
8178 +               inode->i_flags |= S_BARRIER;
8179  
8180         if (flags & OCFS2_SYNC_FL)
8181                 inode->i_flags |= S_SYNC;
8182 @@ -107,6 +113,27 @@ void ocfs2_get_inode_flags(struct ocfs2_
8183                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
8184  }
8185  
8186 +int ocfs2_sync_flags(struct inode *inode)
8187 +{
8188 +       unsigned int oldflags, newflags;
8189 +
8190 +       oldflags = OCFS2_I(inode)->ip_flags;
8191 +       newflags = oldflags & ~(OCFS2_IMMUTABLE_FL |
8192 +               OCFS2_IUNLINK_FL | OCFS2_BARRIER_FL);
8193 +
8194 +       if (IS_IMMUTABLE(inode))
8195 +               newflags |= OCFS2_IMMUTABLE_FL;
8196 +       if (IS_IUNLINK(inode))
8197 +               newflags |= OCFS2_IUNLINK_FL;
8198 +       if (IS_BARRIER(inode))
8199 +               newflags |= OCFS2_BARRIER_FL;
8200 +
8201 +       if (oldflags ^ newflags)
8202 +               return ocfs2_set_inode_attr(inode,
8203 +                       newflags, OCFS2_FL_MASK);
8204 +       return 0;
8205 +}
8206 +
8207  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
8208  {
8209         struct inode *inode = NULL;
8210 @@ -212,6 +239,8 @@ int ocfs2_populate_inode(struct inode *i
8211         struct super_block *sb;
8212         struct ocfs2_super *osb;
8213         int status = -EINVAL;
8214 +       uid_t uid;
8215 +       gid_t gid;
8216  
8217         mlog_entry("(0x%p, size:%llu)\n", inode,
8218                    (unsigned long long)le64_to_cpu(fe->i_size));
8219 @@ -246,8 +275,12 @@ int ocfs2_populate_inode(struct inode *i
8220         inode->i_generation = le32_to_cpu(fe->i_generation);
8221         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
8222         inode->i_mode = le16_to_cpu(fe->i_mode);
8223 -       inode->i_uid = le32_to_cpu(fe->i_uid);
8224 -       inode->i_gid = le32_to_cpu(fe->i_gid);
8225 +       uid = le32_to_cpu(fe->i_uid);
8226 +       gid = le32_to_cpu(fe->i_gid);
8227 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8228 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8229 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
8230 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
8231  
8232         /* Fast symlinks will have i_size but no allocated clusters. */
8233         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
8234 @@ -1224,8 +1257,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
8235  
8236         fe->i_size = cpu_to_le64(i_size_read(inode));
8237         fe->i_links_count = cpu_to_le16(inode->i_nlink);
8238 -       fe->i_uid = cpu_to_le32(inode->i_uid);
8239 -       fe->i_gid = cpu_to_le32(inode->i_gid);
8240 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
8241 +               inode->i_uid, inode->i_tag));
8242 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
8243 +               inode->i_gid, inode->i_tag));
8244 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
8245         fe->i_mode = cpu_to_le16(inode->i_mode);
8246         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
8247         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
8248 @@ -1253,15 +1289,24 @@ leave:
8249  void ocfs2_refresh_inode(struct inode *inode,
8250                          struct ocfs2_dinode *fe)
8251  {
8252 +       uid_t uid;
8253 +       gid_t gid;
8254 +
8255         spin_lock(&OCFS2_I(inode)->ip_lock);
8256  
8257         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
8258         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
8259 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
8260 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
8261         ocfs2_set_inode_flags(inode);
8262         i_size_write(inode, le64_to_cpu(fe->i_size));
8263         inode->i_nlink = le16_to_cpu(fe->i_links_count);
8264 -       inode->i_uid = le32_to_cpu(fe->i_uid);
8265 -       inode->i_gid = le32_to_cpu(fe->i_gid);
8266 +       uid = le32_to_cpu(fe->i_uid);
8267 +       gid = le32_to_cpu(fe->i_gid);
8268 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8269 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8270 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
8271 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
8272         inode->i_mode = le16_to_cpu(fe->i_mode);
8273         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
8274                 inode->i_blocks = 0;
8275 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/inode.h linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/inode.h
8276 --- linux-2.6.22.10/fs/ocfs2/inode.h    2007-07-09 13:19:28 +0200
8277 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/inode.h 2007-08-05 20:53:13 +0200
8278 @@ -142,6 +142,7 @@ int ocfs2_aio_write(struct file *file, s
8279  
8280  void ocfs2_set_inode_flags(struct inode *inode);
8281  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
8282 +int ocfs2_sync_flags(struct inode *inode);
8283  
8284  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
8285  {
8286 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ioctl.c linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ioctl.c
8287 --- linux-2.6.22.10/fs/ocfs2/ioctl.c    2007-07-09 13:19:28 +0200
8288 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ioctl.c 2007-08-05 20:53:13 +0200
8289 @@ -39,7 +39,7 @@ static int ocfs2_get_inode_attr(struct i
8290         return status;
8291  }
8292  
8293 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8294 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8295                                 unsigned mask)
8296  {
8297         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
8298 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
8299 --- linux-2.6.22.10/fs/ocfs2/ioctl.h    2007-07-09 13:19:28 +0200
8300 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ioctl.h 2007-08-05 20:53:13 +0200
8301 @@ -10,6 +10,9 @@
8302  #ifndef OCFS2_IOCTL_H
8303  #define OCFS2_IOCTL_H
8304  
8305 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
8306 +                               unsigned mask);
8307 +
8308  int ocfs2_ioctl(struct inode * inode, struct file * filp,
8309         unsigned int cmd, unsigned long arg);
8310  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
8311 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
8312 --- linux-2.6.22.10/fs/ocfs2/namei.c    2007-07-09 13:19:28 +0200
8313 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/namei.c 2007-08-05 20:53:13 +0200
8314 @@ -40,6 +40,7 @@
8315  #include <linux/types.h>
8316  #include <linux/slab.h>
8317  #include <linux/highmem.h>
8318 +#include <linux/vs_tag.h>
8319  
8320  #define MLOG_MASK_PREFIX ML_NAMEI
8321  #include <cluster/masklog.h>
8322 @@ -483,6 +484,9 @@ static int ocfs2_mknod_locked(struct ocf
8323         u64 fe_blkno = 0;
8324         u16 suballoc_bit;
8325         struct inode *inode = NULL;
8326 +       uid_t uid;
8327 +       gid_t gid;
8328 +       tag_t tag;
8329  
8330         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
8331                    (unsigned long)dev, dentry->d_name.len,
8332 @@ -542,13 +546,19 @@ static int ocfs2_mknod_locked(struct ocf
8333         fe->i_blkno = cpu_to_le64(fe_blkno);
8334         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
8335         fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
8336 -       fe->i_uid = cpu_to_le32(current->fsuid);
8337 +
8338 +       tag = dx_current_fstag(osb->sb);
8339 +       uid = current->fsuid;
8340         if (dir->i_mode & S_ISGID) {
8341 -               fe->i_gid = cpu_to_le32(dir->i_gid);
8342 +               gid = dir->i_gid;
8343                 if (S_ISDIR(mode))
8344                         mode |= S_ISGID;
8345         } else
8346 -               fe->i_gid = cpu_to_le32(current->fsgid);
8347 +               gid = current->fsgid;
8348 +
8349 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
8350 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
8351 +       inode->i_tag = tag;
8352         fe->i_mode = cpu_to_le16(mode);
8353         if (S_ISCHR(mode) || S_ISBLK(mode))
8354                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
8355 @@ -2316,5 +2326,6 @@ const struct inode_operations ocfs2_dir_
8356         .rename         = ocfs2_rename,
8357         .setattr        = ocfs2_setattr,
8358         .getattr        = ocfs2_getattr,
8359 +       .sync_flags     = ocfs2_sync_flags,
8360         .permission     = ocfs2_permission,
8361  };
8362 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
8363 --- linux-2.6.22.10/fs/ocfs2/ocfs2.h    2007-07-09 13:19:28 +0200
8364 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ocfs2.h 2007-08-05 20:53:13 +0200
8365 @@ -170,6 +170,7 @@ enum ocfs2_mount_options
8366         OCFS2_MOUNT_NOINTR  = 1 << 2,   /* Don't catch signals */
8367         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
8368         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
8369 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
8370  };
8371  
8372  #define OCFS2_OSB_SOFT_RO      0x0001
8373 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
8374 --- linux-2.6.22.10/fs/ocfs2/ocfs2_fs.h 2007-07-09 13:19:28 +0200
8375 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/ocfs2_fs.h      2007-08-05 20:53:13 +0200
8376 @@ -152,8 +152,12 @@
8377  #define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
8378  #define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
8379  
8380 +#define OCFS2_BARRIER_FL       (0x04000000)    /* Barrier for chroot() */
8381 +#define OCFS2_IUNLINK_FL       (0x08000000)    /* Immutable unlink */
8382 +
8383  #define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
8384  #define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
8385 +#define OCFS2_FL_MASK          (0x0F0100FF)
8386  
8387  /*
8388   * Extent record flags (e_node.leaf.flags)
8389 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
8390 --- linux-2.6.22.10/fs/ocfs2/super.c    2007-07-09 13:19:28 +0200
8391 +++ linux-2.6.22.10-vs2.3.0.29/fs/ocfs2/super.c 2007-08-05 20:53:13 +0200
8392 @@ -140,6 +140,7 @@ enum {
8393         Opt_data_ordered,
8394         Opt_data_writeback,
8395         Opt_atime_quantum,
8396 +       Opt_tag, Opt_notag, Opt_tagid,
8397         Opt_err,
8398  };
8399  
8400 @@ -154,6 +155,9 @@ static match_table_t tokens = {
8401         {Opt_data_ordered, "data=ordered"},
8402         {Opt_data_writeback, "data=writeback"},
8403         {Opt_atime_quantum, "atime_quantum=%u"},
8404 +       {Opt_tag, "tag"},
8405 +       {Opt_notag, "notag"},
8406 +       {Opt_tagid, "tagid=%u"},
8407         {Opt_err, NULL}
8408  };
8409  
8410 @@ -362,6 +366,13 @@ static int ocfs2_remount(struct super_bl
8411                 goto out;
8412         }
8413  
8414 +       if ((parsed_options & OCFS2_MOUNT_TAGGED) &&
8415 +               !(sb->s_flags & MS_TAGGED)) {
8416 +               ret = -EINVAL;
8417 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
8418 +               goto out;
8419 +       }
8420 +
8421         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
8422             (parsed_options & OCFS2_MOUNT_HB_LOCAL)) {
8423                 ret = -EINVAL;
8424 @@ -654,6 +665,9 @@ static int ocfs2_fill_super(struct super
8425  
8426         ocfs2_complete_mount_recovery(osb);
8427  
8428 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
8429 +               sb->s_flags |= MS_TAGGED;
8430 +
8431         if (ocfs2_mount_local(osb))
8432                 snprintf(nodestr, sizeof(nodestr), "local");
8433         else
8434 @@ -782,6 +796,20 @@ static int ocfs2_parse_options(struct su
8435                         else
8436                                 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
8437                         break;
8438 +#ifndef CONFIG_TAGGING_NONE
8439 +               case Opt_tag:
8440 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
8441 +                       break;
8442 +               case Opt_notag:
8443 +                       *mount_opt &= ~OCFS2_MOUNT_TAGGED;
8444 +                       break;
8445 +#endif
8446 +#ifdef CONFIG_PROPAGATE
8447 +               case Opt_tagid:
8448 +                       /* use args[0] */
8449 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
8450 +                       break;
8451 +#endif
8452                 default:
8453                         mlog(ML_ERROR,
8454                              "Unrecognized mount option \"%s\" "
8455 diff -NurpP --minimal linux-2.6.22.10/fs/open.c linux-2.6.22.10-vs2.3.0.29/fs/open.c
8456 --- linux-2.6.22.10/fs/open.c   2007-07-09 13:19:28 +0200
8457 +++ linux-2.6.22.10-vs2.3.0.29/fs/open.c        2007-08-05 20:53:13 +0200
8458 @@ -26,22 +26,31 @@
8459  #include <linux/syscalls.h>
8460  #include <linux/rcupdate.h>
8461  #include <linux/audit.h>
8462 +#include <linux/vs_base.h>
8463 +#include <linux/vs_limit.h>
8464 +#include <linux/vs_dlimit.h>
8465 +#include <linux/vs_tag.h>
8466 +#include <linux/vs_cowbl.h>
8467  
8468  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
8469  {
8470         int retval = -ENODEV;
8471  
8472         if (dentry) {
8473 +               struct super_block *sb = dentry->d_sb;
8474 +
8475                 retval = -ENOSYS;
8476 -               if (dentry->d_sb->s_op->statfs) {
8477 +               if (sb->s_op->statfs) {
8478                         memset(buf, 0, sizeof(*buf));
8479                         retval = security_sb_statfs(dentry);
8480                         if (retval)
8481                                 return retval;
8482 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
8483 +                       retval = sb->s_op->statfs(dentry, buf);
8484                         if (retval == 0 && buf->f_frsize == 0)
8485                                 buf->f_frsize = buf->f_bsize;
8486                 }
8487 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
8488 +                       vx_vsi_statfs(sb, buf);
8489         }
8490         return retval;
8491  }
8492 @@ -248,7 +257,7 @@ static long do_sys_truncate(const char _
8493                 goto dput_and_out;
8494  
8495         error = -EROFS;
8496 -       if (IS_RDONLY(inode))
8497 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
8498                 goto dput_and_out;
8499  
8500         error = -EPERM;
8501 @@ -397,7 +406,7 @@ asmlinkage long sys_faccessat(int dfd, c
8502            special_file(nd.dentry->d_inode->i_mode))
8503                 goto out_path_release;
8504  
8505 -       if(IS_RDONLY(nd.dentry->d_inode))
8506 +       if(IS_RDONLY(nd.dentry->d_inode) || MNT_IS_RDONLY(nd.mnt))
8507                 res = -EROFS;
8508  
8509  out_path_release:
8510 @@ -511,7 +520,7 @@ asmlinkage long sys_fchmod(unsigned int 
8511         audit_inode(NULL, inode);
8512  
8513         err = -EROFS;
8514 -       if (IS_RDONLY(inode))
8515 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(file->f_vfsmnt))
8516                 goto out_putf;
8517         err = -EPERM;
8518         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8519 @@ -541,11 +550,11 @@ asmlinkage long sys_fchmodat(int dfd, co
8520         error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
8521         if (error)
8522                 goto out;
8523 -       inode = nd.dentry->d_inode;
8524  
8525 -       error = -EROFS;
8526 -       if (IS_RDONLY(inode))
8527 +       error = cow_check_and_break(&nd);
8528 +       if (error)
8529                 goto dput_and_out;
8530 +       inode = nd.dentry->d_inode;
8531  
8532         error = -EPERM;
8533         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8534 @@ -570,7 +579,8 @@ asmlinkage long sys_chmod(const char __u
8535         return sys_fchmodat(AT_FDCWD, filename, mode);
8536  }
8537  
8538 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
8539 +static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
8540 +       uid_t user, gid_t group)
8541  {
8542         struct inode * inode;
8543         int error;
8544 @@ -582,7 +592,7 @@ static int chown_common(struct dentry * 
8545                 goto out;
8546         }
8547         error = -EROFS;
8548 -       if (IS_RDONLY(inode))
8549 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt))
8550                 goto out;
8551         error = -EPERM;
8552         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8553 @@ -590,11 +600,11 @@ static int chown_common(struct dentry * 
8554         newattrs.ia_valid =  ATTR_CTIME;
8555         if (user != (uid_t) -1) {
8556                 newattrs.ia_valid |= ATTR_UID;
8557 -               newattrs.ia_uid = user;
8558 +               newattrs.ia_uid = dx_map_uid(user);
8559         }
8560         if (group != (gid_t) -1) {
8561                 newattrs.ia_valid |= ATTR_GID;
8562 -               newattrs.ia_gid = group;
8563 +               newattrs.ia_gid = dx_map_gid(group);
8564         }
8565         if (!S_ISDIR(inode->i_mode))
8566                 newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID;
8567 @@ -613,7 +623,11 @@ asmlinkage long sys_chown(const char __u
8568         error = user_path_walk(filename, &nd);
8569         if (error)
8570                 goto out;
8571 -       error = chown_common(nd.dentry, user, group);
8572 +#ifdef CONFIG_VSERVER_COWBL
8573 +       error = cow_check_and_break(&nd);
8574 +       if (!error)
8575 +#endif
8576 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8577         path_release(&nd);
8578  out:
8579         return error;
8580 @@ -633,7 +647,11 @@ asmlinkage long sys_fchownat(int dfd, co
8581         error = __user_walk_fd(dfd, filename, follow, &nd);
8582         if (error)
8583                 goto out;
8584 -       error = chown_common(nd.dentry, user, group);
8585 +#ifdef CONFIG_VSERVER_COWBL
8586 +       error = cow_check_and_break(&nd);
8587 +       if (!error)
8588 +#endif
8589 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8590         path_release(&nd);
8591  out:
8592         return error;
8593 @@ -647,7 +665,11 @@ asmlinkage long sys_lchown(const char __
8594         error = user_path_walk_link(filename, &nd);
8595         if (error)
8596                 goto out;
8597 -       error = chown_common(nd.dentry, user, group);
8598 +#ifdef CONFIG_VSERVER_COWBL
8599 +       error = cow_check_and_break(&nd);
8600 +       if (!error)
8601 +#endif
8602 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8603         path_release(&nd);
8604  out:
8605         return error;
8606 @@ -666,7 +688,7 @@ asmlinkage long sys_fchown(unsigned int 
8607  
8608         dentry = file->f_path.dentry;
8609         audit_inode(NULL, dentry->d_inode);
8610 -       error = chown_common(dentry, user, group);
8611 +       error = chown_common(dentry, file->f_vfsmnt, user, group);
8612         fput(file);
8613  out:
8614         return error;
8615 @@ -893,6 +915,7 @@ repeat:
8616         FD_SET(fd, fdt->open_fds);
8617         FD_CLR(fd, fdt->close_on_exec);
8618         files->next_fd = fd + 1;
8619 +       vx_openfd_inc(fd);
8620  #if 1
8621         /* Sanity check */
8622         if (fdt->fd[fd] != NULL) {
8623 @@ -915,6 +938,7 @@ static void __put_unused_fd(struct files
8624         __FD_CLR(fd, fdt->open_fds);
8625         if (fd < files->next_fd)
8626                 files->next_fd = fd;
8627 +       vx_openfd_dec(fd);
8628  }
8629  
8630  void fastcall put_unused_fd(unsigned int fd)
8631 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
8632 --- linux-2.6.22.10/fs/proc/array.c     2007-07-09 13:19:28 +0200
8633 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/array.c  2007-10-05 15:07:22 +0200
8634 @@ -75,6 +75,8 @@
8635  #include <linux/cpuset.h>
8636  #include <linux/rcupdate.h>
8637  #include <linux/delayacct.h>
8638 +#include <linux/vs_context.h>
8639 +#include <linux/vs_network.h>
8640  
8641  #include <asm/uaccess.h>
8642  #include <asm/pgtable.h>
8643 @@ -134,8 +136,9 @@ static const char *task_state_array[] = 
8644         "D (disk sleep)",       /*  2 */
8645         "T (stopped)",          /*  4 */
8646         "T (tracing stop)",     /*  8 */
8647 -       "Z (zombie)",           /* 16 */
8648 -       "X (dead)"              /* 32 */
8649 +       "H (on hold)",          /* 16 */
8650 +       "Z (zombie)",           /* 32 */
8651 +       "X (dead)",             /* 64 */
8652  };
8653  
8654  static inline const char * get_task_state(struct task_struct *tsk)
8655 @@ -144,7 +147,8 @@ static inline const char * get_task_stat
8656                                             TASK_INTERRUPTIBLE |
8657                                             TASK_UNINTERRUPTIBLE |
8658                                             TASK_STOPPED |
8659 -                                           TASK_TRACED)) |
8660 +                                          TASK_TRACED |
8661 +                                          TASK_ONHOLD)) |
8662                         (tsk->exit_state & (EXIT_ZOMBIE |
8663                                             EXIT_DEAD));
8664         const char **p = &task_state_array[0];
8665 @@ -161,8 +165,16 @@ static inline char * task_state(struct t
8666         struct group_info *group_info;
8667         int g;
8668         struct fdtable *fdt = NULL;
8669 +       pid_t pid, ptgid, tppid, tgid;
8670  
8671         rcu_read_lock();
8672 +       tgid = vx_map_tgid(p->tgid);
8673 +       pid = vx_map_pid(p->pid);
8674 +       ptgid = vx_map_pid(pid_alive(p) ?
8675 +               rcu_dereference(p->real_parent)->tgid : 0);
8676 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
8677 +               rcu_dereference(p->parent)->pid : 0);
8678 +
8679         buffer += sprintf(buffer,
8680                 "State:\t%s\n"
8681                 "SleepAVG:\t%lu%%\n"
8682 @@ -174,9 +186,7 @@ static inline char * task_state(struct t
8683                 "Gid:\t%d\t%d\t%d\t%d\n",
8684                 get_task_state(p),
8685                 (p->sleep_avg/1024)*100/(1020000000/1024),
8686 -               p->tgid, p->pid,
8687 -               pid_alive(p) ? rcu_dereference(p->real_parent)->tgid : 0,
8688 -               pid_alive(p) && p->ptrace ? rcu_dereference(p->parent)->pid : 0,
8689 +               tgid, pid, (pid > 1) ? ptgid : 0, tppid,
8690                 p->uid, p->euid, p->suid, p->fsuid,
8691                 p->gid, p->egid, p->sgid, p->fsgid);
8692  
8693 @@ -283,12 +293,15 @@ static inline char * task_sig(struct tas
8694  
8695  static inline char *task_cap(struct task_struct *p, char *buffer)
8696  {
8697 -    return buffer + sprintf(buffer, "CapInh:\t%016x\n"
8698 -                           "CapPrm:\t%016x\n"
8699 -                           "CapEff:\t%016x\n",
8700 -                           cap_t(p->cap_inheritable),
8701 -                           cap_t(p->cap_permitted),
8702 -                           cap_t(p->cap_effective));
8703 +       struct vx_info *vxi = p->vx_info;
8704 +
8705 +       return buffer + sprintf(buffer,
8706 +               "CapInh:\t%016x\n"
8707 +               "CapPrm:\t%016x\n"
8708 +               "CapEff:\t%016x\n",
8709 +               (unsigned)vx_info_mbcap(vxi, p->cap_inheritable),
8710 +               (unsigned)vx_info_mbcap(vxi, p->cap_permitted),
8711 +               (unsigned)vx_info_mbcap(vxi, p->cap_effective));
8712  }
8713  
8714  int proc_pid_status(struct task_struct *task, char * buffer)
8715 @@ -306,6 +319,12 @@ int proc_pid_status(struct task_struct *
8716         buffer = task_sig(task, buffer);
8717         buffer = task_cap(task, buffer);
8718         buffer = cpuset_task_status_allowed(task, buffer);
8719 +
8720 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
8721 +               goto skip;
8722 +       buffer += sprintf (buffer,"VxID: %d\n", vx_task_xid(task));
8723 +       buffer += sprintf (buffer,"NxID: %d\n", nx_task_nid(task));
8724 +skip:
8725  #if defined(CONFIG_S390)
8726         buffer = task_show_regs(task, buffer);
8727  #endif
8728 @@ -320,7 +339,7 @@ static int do_task_stat(struct task_stru
8729         sigset_t sigign, sigcatch;
8730         char state;
8731         int res;
8732 -       pid_t ppid = 0, pgid = -1, sid = -1;
8733 +       pid_t pid = 0, ppid = 0, pgid = -1, sid = -1;
8734         int num_threads = 0;
8735         struct mm_struct *mm;
8736         unsigned long long start_time;
8737 @@ -382,8 +401,10 @@ static int do_task_stat(struct task_stru
8738                 }
8739  
8740                 sid = signal_session(sig);
8741 -               pgid = process_group(task);
8742 -               ppid = rcu_dereference(task->real_parent)->tgid;
8743 +               pid = vx_info_map_pid(task->vx_info, task->pid);
8744 +               pgid = vx_info_map_pid(task->vx_info, process_group(task));
8745 +               ppid = (pid > 1) ? vx_info_map_tgid(task->vx_info,
8746 +                       rcu_dereference(task->real_parent)->tgid) : 0;
8747  
8748                 unlock_task_sighand(task, &flags);
8749         }
8750 @@ -410,10 +431,21 @@ static int do_task_stat(struct task_stru
8751         /* convert nsec -> ticks */
8752         start_time = nsec_to_clock_t(start_time);
8753  
8754 +       /* fixup start time for virt uptime */
8755 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
8756 +               unsigned long long bias =
8757 +                       current->vx_info->cvirt.bias_clock;
8758 +
8759 +               if (start_time > bias)
8760 +                       start_time -= bias;
8761 +               else
8762 +                       start_time = 0;
8763 +       }
8764 +
8765         res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %u %lu \
8766  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
8767  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu\n",
8768 -               task->pid,
8769 +               pid,
8770                 tcomm,
8771                 state,
8772                 ppid,
8773 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
8774 --- linux-2.6.22.10/fs/proc/base.c      2007-07-09 13:19:28 +0200
8775 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/base.c   2007-09-05 02:49:29 +0200
8776 @@ -73,6 +73,9 @@
8777  #include <linux/poll.h>
8778  #include <linux/nsproxy.h>
8779  #include <linux/oom.h>
8780 +#include <linux/vs_context.h>
8781 +#include <linux/vs_network.h>
8782 +
8783  #include "internal.h"
8784  
8785  /* NOTE:
8786 @@ -1049,6 +1052,8 @@ static struct inode *proc_pid_make_inode
8787                 inode->i_uid = task->euid;
8788                 inode->i_gid = task->egid;
8789         }
8790 +       /* procfs is xid tagged */
8791 +       inode->i_tag = (tag_t)vx_task_xid(task);
8792         security_task_to_inode(task, inode);
8793  
8794  out:
8795 @@ -1082,6 +1087,8 @@ static int pid_getattr(struct vfsmount *
8796  
8797  /* dentry stuff */
8798  
8799 +static unsigned name_to_int(struct dentry *dentry);
8800 +
8801  /*
8802   *     Exceptional case: normally we are not allowed to unhash a busy
8803   * directory. In this case, however, we can do it - no aliasing problems
8804 @@ -1102,6 +1109,12 @@ static int pid_revalidate(struct dentry 
8805         struct inode *inode = dentry->d_inode;
8806         struct task_struct *task = get_proc_task(inode);
8807         if (task) {
8808 +               unsigned pid = name_to_int(dentry);
8809 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
8810 +                       put_task_struct(task);
8811 +                       goto drop;
8812 +               }
8813 +
8814                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
8815                     task_dumpable(task)) {
8816                         inode->i_uid = task->euid;
8817 @@ -1115,6 +1128,7 @@ static int pid_revalidate(struct dentry 
8818                 put_task_struct(task);
8819                 return 1;
8820         }
8821 +drop:
8822         d_drop(dentry);
8823         return 0;
8824  }
8825 @@ -1595,6 +1609,13 @@ static struct dentry *proc_pident_lookup
8826         if (!task)
8827                 goto out_no_task;
8828  
8829 +       /* TODO: maybe we can come up with a generic approach? */
8830 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
8831 +               (dentry->d_name.len == 5) &&
8832 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
8833 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
8834 +               goto out;
8835 +
8836         /*
8837          * Yes, it does not scale. And it should not. Don't add
8838          * new entries into /proc/<tgid>/ without very good reasons.
8839 @@ -1790,14 +1811,14 @@ static int proc_self_readlink(struct den
8840                               int buflen)
8841  {
8842         char tmp[PROC_NUMBUF];
8843 -       sprintf(tmp, "%d", current->tgid);
8844 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8845         return vfs_readlink(dentry,buffer,buflen,tmp);
8846  }
8847  
8848  static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
8849  {
8850         char tmp[PROC_NUMBUF];
8851 -       sprintf(tmp, "%d", current->tgid);
8852 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8853         return ERR_PTR(vfs_follow_link(nd,tmp));
8854  }
8855  
8856 @@ -1891,7 +1912,7 @@ out_iput:
8857  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
8858  {
8859         struct dentry *error;
8860 -       struct task_struct *task = get_proc_task(dir);
8861 +       struct task_struct *task = get_proc_task_real(dir);
8862         const struct pid_entry *p, *last;
8863  
8864         error = ERR_PTR(-ENOENT);
8865 @@ -1956,6 +1977,9 @@ static int proc_pid_io_accounting(struct
8866  static const struct file_operations proc_task_operations;
8867  static const struct inode_operations proc_task_inode_operations;
8868  
8869 +extern int proc_pid_vx_info(struct task_struct *, char *);
8870 +extern int proc_pid_nx_info(struct task_struct *, char *);
8871 +
8872  static const struct pid_entry tgid_base_stuff[] = {
8873         DIR("task",       S_IRUGO|S_IXUGO, task),
8874         DIR("fd",         S_IRUSR|S_IXUSR, fd),
8875 @@ -1995,6 +2019,8 @@ static const struct pid_entry tgid_base_
8876  #ifdef CONFIG_CPUSETS
8877         REG("cpuset",     S_IRUGO, cpuset),
8878  #endif
8879 +       INF("vinfo",      S_IRUGO, pid_vx_info),
8880 +       INF("ninfo",      S_IRUGO, pid_nx_info),
8881         INF("oom_score",  S_IRUGO, oom_score),
8882         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
8883  #ifdef CONFIG_AUDITSYSCALL
8884 @@ -2141,9 +2167,11 @@ struct dentry *proc_pid_lookup(struct in
8885         tgid = name_to_int(dentry);
8886         if (tgid == ~0U)
8887                 goto out;
8888 +       if (vx_current_initpid(tgid))
8889 +               goto out;
8890  
8891         rcu_read_lock();
8892 -       task = find_task_by_pid(tgid);
8893 +       task = vx_find_proc_task_by_pid(tgid);
8894         if (task)
8895                 get_task_struct(task);
8896         rcu_read_unlock();
8897 @@ -2198,7 +2226,7 @@ static int proc_pid_fill_cache(struct fi
8898         struct task_struct *task, int tgid)
8899  {
8900         char name[PROC_NUMBUF];
8901 -       int len = snprintf(name, sizeof(name), "%d", tgid);
8902 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(tgid));
8903         return proc_fill_cache(filp, dirent, filldir, name, len,
8904                                 proc_pid_instantiate, task, NULL);
8905  }
8906 @@ -2207,7 +2235,7 @@ static int proc_pid_fill_cache(struct fi
8907  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
8908  {
8909         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
8910 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
8911 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
8912         struct task_struct *task;
8913         int tgid;
8914  
8915 @@ -2226,6 +2254,8 @@ int proc_pid_readdir(struct file * filp,
8916              put_task_struct(task), task = next_tgid(tgid + 1)) {
8917                 tgid = task->pid;
8918                 filp->f_pos = tgid + TGID_OFFSET;
8919 +               if (!vx_proc_task_visible(task))
8920 +                       continue;
8921                 if (proc_pid_fill_cache(filp, dirent, filldir, task, tgid) < 0) {
8922                         put_task_struct(task);
8923                         goto out;
8924 @@ -2352,9 +2382,11 @@ static struct dentry *proc_task_lookup(s
8925         tid = name_to_int(dentry);
8926         if (tid == ~0U)
8927                 goto out;
8928 +       if (vx_current_initpid(tid))
8929 +               goto out;
8930  
8931         rcu_read_lock();
8932 -       task = find_task_by_pid(tid);
8933 +       task = vx_find_proc_task_by_pid(tid);
8934         if (task)
8935                 get_task_struct(task);
8936         rcu_read_unlock();
8937 @@ -2499,7 +2531,7 @@ static int proc_task_readdir(struct file
8938         for (task = first_tid(leader, tid, pos - 2);
8939              task;
8940              task = next_tid(task), pos++) {
8941 -               tid = task->pid;
8942 +               tid = vx_map_pid(task->pid);
8943                 if (proc_task_fill_cache(filp, dirent, filldir, task, tid) < 0) {
8944                         /* returning this tgid failed, save it as the first
8945                          * pid for the next readir call */
8946 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
8947 --- linux-2.6.22.10/fs/proc/generic.c   2007-07-09 13:19:28 +0200
8948 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/generic.c        2007-08-05 20:53:13 +0200
8949 @@ -20,6 +20,7 @@
8950  #include <linux/namei.h>
8951  #include <linux/bitops.h>
8952  #include <linux/spinlock.h>
8953 +#include <linux/vserver/inode.h>
8954  #include <asm/uaccess.h>
8955  
8956  #include "internal.h"
8957 @@ -395,6 +396,8 @@ struct dentry *proc_lookup(struct inode 
8958                 for (de = de->subdir; de ; de = de->next) {
8959                         if (de->namelen != dentry->d_name.len)
8960                                 continue;
8961 +                       if (!vx_hide_check(0, de->vx_flags))
8962 +                               continue;
8963                         if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
8964                                 unsigned int ino = de->low_ino;
8965  
8966 @@ -402,6 +405,8 @@ struct dentry *proc_lookup(struct inode 
8967                                 spin_unlock(&proc_subdir_lock);
8968                                 error = -EINVAL;
8969                                 inode = proc_get_inode(dir->i_sb, ino, de);
8970 +                               /* generic proc entries belong to the host */
8971 +                               inode->i_tag = 0;
8972                                 spin_lock(&proc_subdir_lock);
8973                                 break;
8974                         }
8975 @@ -482,6 +487,8 @@ int proc_readdir(struct file * filp,
8976  
8977                                 /* filldir passes info to user space */
8978                                 de_get(de);
8979 +                               if (!vx_hide_check(0, de->vx_flags))
8980 +                                       goto skip;
8981                                 spin_unlock(&proc_subdir_lock);
8982                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
8983                                             de->low_ino, de->mode >> 12) < 0) {
8984 @@ -489,6 +496,7 @@ int proc_readdir(struct file * filp,
8985                                         goto out;
8986                                 }
8987                                 spin_lock(&proc_subdir_lock);
8988 +                       skip:
8989                                 filp->f_pos++;
8990                                 next = de->next;
8991                                 de_put(de);
8992 @@ -613,6 +621,7 @@ static struct proc_dir_entry *proc_creat
8993         ent->namelen = len;
8994         ent->mode = mode;
8995         ent->nlink = nlink;
8996 +       ent->vx_flags = IATTR_PROC_DEFAULT;
8997   out:
8998         return ent;
8999  }
9000 @@ -633,7 +642,8 @@ struct proc_dir_entry *proc_symlink(cons
9001                                 kfree(ent->data);
9002                                 kfree(ent);
9003                                 ent = NULL;
9004 -                       }
9005 +                       } else
9006 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
9007                 } else {
9008                         kfree(ent);
9009                         ent = NULL;
9010 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
9011 --- linux-2.6.22.10/fs/proc/inode.c     2007-07-09 13:19:28 +0200
9012 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/inode.c  2007-08-05 20:53:13 +0200
9013 @@ -160,6 +160,8 @@ struct inode *proc_get_inode(struct supe
9014                         inode->i_uid = de->uid;
9015                         inode->i_gid = de->gid;
9016                 }
9017 +               if (de->vx_flags)
9018 +                       PROC_I(inode)->vx_flags = de->vx_flags;
9019                 if (de->size)
9020                         inode->i_size = de->size;
9021                 if (de->nlink)
9022 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
9023 --- linux-2.6.22.10/fs/proc/internal.h  2007-07-09 13:19:28 +0200
9024 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/internal.h       2007-08-05 20:53:13 +0200
9025 @@ -10,6 +10,7 @@
9026   */
9027  
9028  #include <linux/proc_fs.h>
9029 +#include <linux/vs_pid.h>
9030  
9031  #ifdef CONFIG_PROC_SYSCTL
9032  extern int proc_sys_init(void);
9033 @@ -64,11 +65,16 @@ static inline struct pid *proc_pid(struc
9034         return PROC_I(inode)->pid;
9035  }
9036  
9037 -static inline struct task_struct *get_proc_task(struct inode *inode)
9038 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
9039  {
9040         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
9041  }
9042  
9043 +static inline struct task_struct *get_proc_task(struct inode *inode)
9044 +{
9045 +       return vx_get_proc_task(inode, proc_pid(inode));
9046 +}
9047 +
9048  static inline int proc_fd(struct inode *inode)
9049  {
9050         return PROC_I(inode)->fd;
9051 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
9052 --- linux-2.6.22.10/fs/proc/proc_misc.c 2007-07-09 13:19:28 +0200
9053 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/proc_misc.c      2007-08-05 20:53:13 +0200
9054 @@ -53,6 +53,8 @@
9055  #include <asm/div64.h>
9056  #include "internal.h"
9057  
9058 +#include <linux/vs_cvirt.h>
9059 +
9060  #define LOAD_INT(x) ((x) >> FSHIFT)
9061  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
9062  /*
9063 @@ -82,17 +84,32 @@ static int proc_calc_metrics(char *page,
9064  static int loadavg_read_proc(char *page, char **start, off_t off,
9065                                  int count, int *eof, void *data)
9066  {
9067 +       unsigned int running, threads;
9068         int a, b, c;
9069         int len;
9070  
9071 -       a = avenrun[0] + (FIXED_1/200);
9072 -       b = avenrun[1] + (FIXED_1/200);
9073 -       c = avenrun[2] + (FIXED_1/200);
9074 -       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
9075 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
9076 +               struct vx_info *vxi = current->vx_info;
9077 +
9078 +               a = vxi->cvirt.load[0] + (FIXED_1/200);
9079 +               b = vxi->cvirt.load[1] + (FIXED_1/200);
9080 +               c = vxi->cvirt.load[2] + (FIXED_1/200);
9081 +
9082 +               running = atomic_read(&vxi->cvirt.nr_running);
9083 +               threads = atomic_read(&vxi->cvirt.nr_threads);
9084 +       } else {
9085 +               a = avenrun[0] + (FIXED_1/200);
9086 +               b = avenrun[1] + (FIXED_1/200);
9087 +               c = avenrun[2] + (FIXED_1/200);
9088 +
9089 +               running = nr_running();
9090 +               threads = nr_threads;
9091 +       }
9092 +       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",
9093                 LOAD_INT(a), LOAD_FRAC(a),
9094                 LOAD_INT(b), LOAD_FRAC(b),
9095                 LOAD_INT(c), LOAD_FRAC(c),
9096 -               nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);
9097 +               running, threads, current->nsproxy->pid_ns->last_pid);
9098         return proc_calc_metrics(page, start, off, count, eof, len);
9099  }
9100  
9101 @@ -106,6 +123,9 @@ static int uptime_read_proc(char *page, 
9102  
9103         do_posix_clock_monotonic_gettime(&uptime);
9104         cputime_to_timespec(idletime, &idle);
9105 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
9106 +               vx_vsi_uptime(&uptime, &idle);
9107 +
9108         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
9109                         (unsigned long) uptime.tv_sec,
9110                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
9111 @@ -137,7 +157,7 @@ static int meminfo_read_proc(char *page,
9112  
9113         cached = global_page_state(NR_FILE_PAGES) -
9114                         total_swapcache_pages - i.bufferram;
9115 -       if (cached < 0)
9116 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
9117                 cached = 0;
9118  
9119         get_vmalloc_info(&vmi);
9120 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
9121 --- linux-2.6.22.10/fs/proc/root.c      2007-05-02 19:25:21 +0200
9122 +++ linux-2.6.22.10-vs2.3.0.29/fs/proc/root.c   2007-08-05 20:53:13 +0200
9123 @@ -22,6 +22,9 @@
9124  #include "internal.h"
9125  
9126  struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver;
9127 +struct proc_dir_entry *proc_virtual;
9128 +
9129 +extern void proc_vx_init(void);
9130  
9131  static int proc_get_sb(struct file_system_type *fs_type,
9132         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
9133 @@ -79,6 +82,7 @@ void __init proc_root_init(void)
9134         proc_device_tree_init();
9135  #endif
9136         proc_bus = proc_mkdir("bus", NULL);
9137 +       proc_vx_init();
9138         proc_sys_init();
9139  }
9140  
9141 diff -NurpP --minimal linux-2.6.22.10/fs/quota.c linux-2.6.22.10-vs2.3.0.29/fs/quota.c
9142 --- linux-2.6.22.10/fs/quota.c  2007-07-09 13:19:28 +0200
9143 +++ linux-2.6.22.10-vs2.3.0.29/fs/quota.c       2007-08-05 20:53:13 +0200
9144 @@ -16,6 +16,7 @@
9145  #include <linux/buffer_head.h>
9146  #include <linux/capability.h>
9147  #include <linux/quotaops.h>
9148 +#include <linux/vs_context.h>
9149  
9150  /* Check validity of generic quotactl commands */
9151  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
9152 @@ -80,11 +81,11 @@ static int generic_quotactl_valid(struct
9153         if (cmd == Q_GETQUOTA) {
9154                 if (((type == USRQUOTA && current->euid != id) ||
9155                      (type == GRPQUOTA && !in_egroup_p(id))) &&
9156 -                   !capable(CAP_SYS_ADMIN))
9157 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9158                         return -EPERM;
9159         }
9160         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
9161 -               if (!capable(CAP_SYS_ADMIN))
9162 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9163                         return -EPERM;
9164  
9165         return 0;
9166 @@ -131,10 +132,10 @@ static int xqm_quotactl_valid(struct sup
9167         if (cmd == Q_XGETQUOTA) {
9168                 if (((type == XQM_USRQUOTA && current->euid != id) ||
9169                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
9170 -                    !capable(CAP_SYS_ADMIN))
9171 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9172                         return -EPERM;
9173         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
9174 -               if (!capable(CAP_SYS_ADMIN))
9175 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9176                         return -EPERM;
9177         }
9178  
9179 @@ -327,6 +328,46 @@ static int do_quotactl(struct super_bloc
9180         return 0;
9181  }
9182  
9183 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
9184 +
9185 +#include <linux/vroot.h>
9186 +#include <linux/major.h>
9187 +#include <linux/module.h>
9188 +#include <linux/kallsyms.h>
9189 +#include <linux/vserver/debug.h>
9190 +
9191 +static vroot_grb_func *vroot_get_real_bdev = NULL;
9192 +
9193 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
9194 +
9195 +int register_vroot_grb(vroot_grb_func *func) {
9196 +       int ret = -EBUSY;
9197 +
9198 +       spin_lock(&vroot_grb_lock);
9199 +       if (!vroot_get_real_bdev) {
9200 +               vroot_get_real_bdev = func;
9201 +               ret = 0;
9202 +       }
9203 +       spin_unlock(&vroot_grb_lock);
9204 +       return ret;
9205 +}
9206 +EXPORT_SYMBOL(register_vroot_grb);
9207 +
9208 +int unregister_vroot_grb(vroot_grb_func *func) {
9209 +       int ret = -EINVAL;
9210 +
9211 +       spin_lock(&vroot_grb_lock);
9212 +       if (vroot_get_real_bdev) {
9213 +               vroot_get_real_bdev = NULL;
9214 +               ret = 0;
9215 +       }
9216 +       spin_unlock(&vroot_grb_lock);
9217 +       return ret;
9218 +}
9219 +EXPORT_SYMBOL(unregister_vroot_grb);
9220 +
9221 +#endif
9222 +
9223  /*
9224   * look up a superblock on which quota ops will be performed
9225   * - use the name of a block device to find the superblock thereon
9226 @@ -344,6 +385,22 @@ static inline struct super_block *quotac
9227         putname(tmp);
9228         if (IS_ERR(bdev))
9229                 return ERR_PTR(PTR_ERR(bdev));
9230 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
9231 +       if (bdev && bdev->bd_inode &&
9232 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
9233 +               struct block_device *bdnew = (void *)-EINVAL;
9234 +
9235 +               if (vroot_get_real_bdev)
9236 +                       bdnew = vroot_get_real_bdev(bdev);
9237 +               else
9238 +                       vxdprintk(VXD_CBIT(misc, 0),
9239 +                                       "vroot_get_real_bdev not set");
9240 +               bdput(bdev);
9241 +               if (IS_ERR(bdnew))
9242 +                       return ERR_PTR(PTR_ERR(bdnew));
9243 +               bdev = bdnew;
9244 +       }
9245 +#endif
9246         sb = get_super(bdev);
9247         bdput(bdev);
9248         if (!sb)
9249 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
9250 --- linux-2.6.22.10/fs/reiserfs/bitmap.c        2007-02-06 03:01:29 +0100
9251 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/bitmap.c     2007-10-05 15:07:22 +0200
9252 @@ -13,6 +13,7 @@
9253  #include <linux/reiserfs_fs_sb.h>
9254  #include <linux/reiserfs_fs_i.h>
9255  #include <linux/quotaops.h>
9256 +#include <linux/vs_dlimit.h>
9257  
9258  #define PREALLOCATION_SIZE 9
9259  
9260 @@ -425,8 +426,10 @@ static void _reiserfs_free_block(struct 
9261         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
9262  
9263         journal_mark_dirty(th, s, sbh);
9264 -       if (for_unformatted)
9265 +       if (for_unformatted) {
9266 +               DLIMIT_FREE_BLOCK(inode, 1);
9267                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
9268 +       }
9269  }
9270  
9271  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
9272 @@ -1034,6 +1037,7 @@ static inline int blocknrs_and_prealloc_
9273         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
9274         int passno = 0;
9275         int nr_allocated = 0;
9276 +       int blocks;
9277  
9278         determine_prealloc_size(hint);
9279         if (!hint->formatted_node) {
9280 @@ -1043,19 +1047,30 @@ static inline int blocknrs_and_prealloc_
9281                                "reiserquota: allocating %d blocks id=%u",
9282                                amount_needed, hint->inode->i_uid);
9283  #endif
9284 -               quota_ret =
9285 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
9286 -               if (quota_ret)  /* Quota exceeded? */
9287 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
9288 +                       amount_needed);
9289 +               if (quota_ret)
9290                         return QUOTA_EXCEEDED;
9291 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
9292 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
9293 +                               amount_needed);
9294 +                       return NO_DISK_SPACE;
9295 +               }
9296 +
9297                 if (hint->preallocate && hint->prealloc_size) {
9298  #ifdef REISERQUOTA_DEBUG
9299                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
9300                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
9301                                        hint->prealloc_size, hint->inode->i_uid);
9302  #endif
9303 -                       quota_ret =
9304 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
9305 -                                                        hint->prealloc_size);
9306 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
9307 +                               hint->prealloc_size);
9308 +                       if (!quota_ret &&
9309 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
9310 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
9311 +                                       hint->prealloc_size);
9312 +                               quota_ret = 1;
9313 +                       }
9314                         if (quota_ret)
9315                                 hint->preallocate = hint->prealloc_size = 0;
9316                 }
9317 @@ -1087,7 +1102,10 @@ static inline int blocknrs_and_prealloc_
9318                                                nr_allocated,
9319                                                hint->inode->i_uid);
9320  #endif
9321 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
9322 +                               /* Free not allocated blocks */
9323 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
9324 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
9325 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
9326                         }
9327                         while (nr_allocated--)
9328                                 reiserfs_free_block(hint->th, hint->inode,
9329 @@ -1118,10 +1136,10 @@ static inline int blocknrs_and_prealloc_
9330                                REISERFS_I(hint->inode)->i_prealloc_count,
9331                                hint->inode->i_uid);
9332  #endif
9333 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
9334 -                                        hint->prealloc_size - nr_allocated -
9335 -                                        REISERFS_I(hint->inode)->
9336 -                                        i_prealloc_count);
9337 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
9338 +                       REISERFS_I(hint->inode)->i_prealloc_count;
9339 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
9340 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
9341         }
9342  
9343         return CARRY_ON;
9344 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
9345 --- linux-2.6.22.10/fs/reiserfs/file.c  2007-07-09 13:19:28 +0200
9346 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/file.c       2007-09-12 20:04:16 +0200
9347 @@ -1546,4 +1546,5 @@ const struct inode_operations reiserfs_f
9348         .listxattr = reiserfs_listxattr,
9349         .removexattr = reiserfs_removexattr,
9350         .permission = reiserfs_permission,
9351 +       .sync_flags = reiserfs_sync_flags,
9352  };
9353 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
9354 --- linux-2.6.22.10/fs/reiserfs/inode.c 2007-07-09 13:19:28 +0200
9355 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/inode.c      2007-08-05 20:53:13 +0200
9356 @@ -16,6 +16,8 @@
9357  #include <linux/mpage.h>
9358  #include <linux/writeback.h>
9359  #include <linux/quotaops.h>
9360 +#include <linux/vs_dlimit.h>
9361 +#include <linux/vs_tag.h>
9362  
9363  static int reiserfs_commit_write(struct file *f, struct page *page,
9364                                  unsigned from, unsigned to);
9365 @@ -50,6 +52,7 @@ void reiserfs_delete_inode(struct inode 
9366                  * stat data deletion */
9367                 if (!err) 
9368                         DQUOT_FREE_INODE(inode);
9369 +               DLIMIT_FREE_INODE(inode);
9370  
9371                 if (journal_end(&th, inode->i_sb, jbegin_count))
9372                         goto out;
9373 @@ -1112,6 +1115,8 @@ static void init_inode(struct inode *ino
9374         struct buffer_head *bh;
9375         struct item_head *ih;
9376         __u32 rdev;
9377 +       uid_t uid;
9378 +       gid_t gid;
9379         //int version = ITEM_VERSION_1;
9380  
9381         bh = PATH_PLAST_BUFFER(path);
9382 @@ -1135,12 +1140,13 @@ static void init_inode(struct inode *ino
9383                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
9384                 unsigned long blocks;
9385  
9386 +               uid = sd_v1_uid(sd);
9387 +               gid = sd_v1_gid(sd);
9388 +
9389                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
9390                 set_inode_sd_version(inode, STAT_DATA_V1);
9391                 inode->i_mode = sd_v1_mode(sd);
9392                 inode->i_nlink = sd_v1_nlink(sd);
9393 -               inode->i_uid = sd_v1_uid(sd);
9394 -               inode->i_gid = sd_v1_gid(sd);
9395                 inode->i_size = sd_v1_size(sd);
9396                 inode->i_atime.tv_sec = sd_v1_atime(sd);
9397                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
9398 @@ -1182,11 +1188,12 @@ static void init_inode(struct inode *ino
9399                 // (directories and symlinks)
9400                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
9401  
9402 +               uid    = sd_v2_uid(sd);
9403 +               gid    = sd_v2_gid(sd);
9404 +
9405                 inode->i_mode = sd_v2_mode(sd);
9406                 inode->i_nlink = sd_v2_nlink(sd);
9407 -               inode->i_uid = sd_v2_uid(sd);
9408                 inode->i_size = sd_v2_size(sd);
9409 -               inode->i_gid = sd_v2_gid(sd);
9410                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
9411                 inode->i_atime.tv_sec = sd_v2_atime(sd);
9412                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
9413 @@ -1216,6 +1223,10 @@ static void init_inode(struct inode *ino
9414                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
9415         }
9416  
9417 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
9418 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
9419 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
9420 +
9421         pathrelse(path);
9422         if (S_ISREG(inode->i_mode)) {
9423                 inode->i_op = &reiserfs_file_inode_operations;
9424 @@ -1238,13 +1249,15 @@ static void init_inode(struct inode *ino
9425  static void inode2sd(void *sd, struct inode *inode, loff_t size)
9426  {
9427         struct stat_data *sd_v2 = (struct stat_data *)sd;
9428 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
9429 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
9430         __u16 flags;
9431  
9432 +       set_sd_v2_uid(sd_v2, uid);
9433 +       set_sd_v2_gid(sd_v2, gid);
9434         set_sd_v2_mode(sd_v2, inode->i_mode);
9435         set_sd_v2_nlink(sd_v2, inode->i_nlink);
9436 -       set_sd_v2_uid(sd_v2, inode->i_uid);
9437         set_sd_v2_size(sd_v2, size);
9438 -       set_sd_v2_gid(sd_v2, inode->i_gid);
9439         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
9440         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
9441         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
9442 @@ -1775,6 +1788,10 @@ int reiserfs_new_inode(struct reiserfs_t
9443  
9444         BUG_ON(!th->t_trans_id);
9445  
9446 +       if (DLIMIT_ALLOC_INODE(inode)) {
9447 +               err = -ENOSPC;
9448 +               goto out_bad_dlimit;
9449 +       }
9450         if (DQUOT_ALLOC_INODE(inode)) {
9451                 err = -EDQUOT;
9452                 goto out_end_trans;
9453 @@ -1960,6 +1977,9 @@ int reiserfs_new_inode(struct reiserfs_t
9454         DQUOT_FREE_INODE(inode);
9455  
9456        out_end_trans:
9457 +       DLIMIT_FREE_INODE(inode);
9458 +
9459 +      out_bad_dlimit:
9460         journal_end(th, th->t_super, th->t_blocks_allocated);
9461         /* Drop can be outside and it needs more credits so it's better to have it outside */
9462         DQUOT_DROP(inode);
9463 @@ -2690,6 +2710,14 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
9464                         inode->i_flags |= S_IMMUTABLE;
9465                 else
9466                         inode->i_flags &= ~S_IMMUTABLE;
9467 +               if (sd_attrs & REISERFS_IUNLINK_FL)
9468 +                       inode->i_flags |= S_IUNLINK;
9469 +               else
9470 +                       inode->i_flags &= ~S_IUNLINK;
9471 +               if (sd_attrs & REISERFS_BARRIER_FL)
9472 +                       inode->i_flags |= S_BARRIER;
9473 +               else
9474 +                       inode->i_flags &= ~S_BARRIER;
9475                 if (sd_attrs & REISERFS_APPEND_FL)
9476                         inode->i_flags |= S_APPEND;
9477                 else
9478 @@ -2712,6 +2740,14 @@ void i_attrs_to_sd_attrs(struct inode *i
9479                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
9480                 else
9481                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
9482 +               if (inode->i_flags & S_IUNLINK)
9483 +                       *sd_attrs |= REISERFS_IUNLINK_FL;
9484 +               else
9485 +                       *sd_attrs &= ~REISERFS_IUNLINK_FL;
9486 +               if (inode->i_flags & S_BARRIER)
9487 +                       *sd_attrs |= REISERFS_BARRIER_FL;
9488 +               else
9489 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
9490                 if (inode->i_flags & S_SYNC)
9491                         *sd_attrs |= REISERFS_SYNC_FL;
9492                 else
9493 @@ -2891,6 +2927,22 @@ static ssize_t reiserfs_direct_IO(int rw
9494                                   reiserfs_get_blocks_direct_io, NULL);
9495  }
9496  
9497 +int reiserfs_sync_flags(struct inode *inode)
9498 +{
9499 +       u16 oldflags, newflags;
9500 +
9501 +       oldflags = REISERFS_I(inode)->i_attrs;
9502 +       newflags = oldflags;
9503 +       i_attrs_to_sd_attrs(inode, &newflags);
9504 +
9505 +       if (oldflags ^ newflags) {
9506 +               REISERFS_I(inode)->i_attrs = newflags;
9507 +               inode->i_ctime = CURRENT_TIME_SEC;
9508 +               mark_inode_dirty(inode);
9509 +       }
9510 +       return 0;
9511 +}
9512 +
9513  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
9514  {
9515         struct inode *inode = dentry->d_inode;
9516 @@ -2940,9 +2992,11 @@ int reiserfs_setattr(struct dentry *dent
9517         }
9518  
9519         error = inode_change_ok(inode, attr);
9520 +
9521         if (!error) {
9522                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
9523 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
9524 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
9525 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
9526                         error = reiserfs_chown_xattrs(inode, attr);
9527  
9528                         if (!error) {
9529 @@ -2972,6 +3026,9 @@ int reiserfs_setattr(struct dentry *dent
9530                                         inode->i_uid = attr->ia_uid;
9531                                 if (attr->ia_valid & ATTR_GID)
9532                                         inode->i_gid = attr->ia_gid;
9533 +                               if ((attr->ia_valid & ATTR_TAG) &&
9534 +                                       IS_TAGGED(inode))
9535 +                                       inode->i_tag = attr->ia_tag;
9536                                 mark_inode_dirty(inode);
9537                                 error =
9538                                     journal_end(&th, inode->i_sb, jbegin_count);
9539 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
9540 --- linux-2.6.22.10/fs/reiserfs/ioctl.c 2007-02-06 03:01:29 +0100
9541 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/ioctl.c      2007-08-05 20:53:13 +0200
9542 @@ -6,6 +6,7 @@
9543  #include <linux/fs.h>
9544  #include <linux/reiserfs_fs.h>
9545  #include <linux/time.h>
9546 +#include <linux/mount.h>
9547  #include <asm/uaccess.h>
9548  #include <linux/pagemap.h>
9549  #include <linux/smp_lock.h>
9550 @@ -24,7 +25,7 @@ static int reiserfs_unpack(struct inode 
9551  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
9552                    unsigned long arg)
9553  {
9554 -       unsigned int flags;
9555 +       unsigned int flags, oldflags;
9556  
9557         switch (cmd) {
9558         case REISERFS_IOC_UNPACK:
9559 @@ -43,12 +44,14 @@ int reiserfs_ioctl(struct inode *inode, 
9560  
9561                 flags = REISERFS_I(inode)->i_attrs;
9562                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
9563 +               flags &= REISERFS_FL_USER_VISIBLE;
9564                 return put_user(flags, (int __user *)arg);
9565         case REISERFS_IOC_SETFLAGS:{
9566                         if (!reiserfs_attrs(inode->i_sb))
9567                                 return -ENOTTY;
9568  
9569 -                       if (IS_RDONLY(inode))
9570 +                       if (IS_RDONLY(inode) ||
9571 +                               (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9572                                 return -EROFS;
9573  
9574                         if ((current->fsuid != inode->i_uid)
9575 @@ -58,10 +61,12 @@ int reiserfs_ioctl(struct inode *inode, 
9576                         if (get_user(flags, (int __user *)arg))
9577                                 return -EFAULT;
9578  
9579 -                       if (((flags ^ REISERFS_I(inode)->
9580 -                             i_attrs) & (REISERFS_IMMUTABLE_FL |
9581 -                                         REISERFS_APPEND_FL))
9582 -                           && !capable(CAP_LINUX_IMMUTABLE))
9583 +                       oldflags = REISERFS_I(inode) -> i_attrs;
9584 +                       if (((oldflags & REISERFS_IMMUTABLE_FL) ||
9585 +                               ((flags ^ oldflags) &
9586 +                               (REISERFS_IMMUTABLE_FL | REISERFS_IUNLINK_FL |
9587 +                                REISERFS_APPEND_FL))) &&
9588 +                               !capable(CAP_LINUX_IMMUTABLE))
9589                                 return -EPERM;
9590  
9591                         if ((flags & REISERFS_NOTAIL_FL) &&
9592 @@ -72,6 +77,9 @@ int reiserfs_ioctl(struct inode *inode, 
9593                                 if (result)
9594                                         return result;
9595                         }
9596 +
9597 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
9598 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
9599                         sd_attrs_to_i_attrs(flags, inode);
9600                         REISERFS_I(inode)->i_attrs = flags;
9601                         inode->i_ctime = CURRENT_TIME_SEC;
9602 @@ -83,7 +91,8 @@ int reiserfs_ioctl(struct inode *inode, 
9603         case REISERFS_IOC_SETVERSION:
9604                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
9605                         return -EPERM;
9606 -               if (IS_RDONLY(inode))
9607 +               if (IS_RDONLY(inode) ||
9608 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9609                         return -EROFS;
9610                 if (get_user(inode->i_generation, (int __user *)arg))
9611                         return -EFAULT;
9612 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
9613 --- linux-2.6.22.10/fs/reiserfs/namei.c 2007-07-09 13:19:28 +0200
9614 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/namei.c      2007-08-05 20:53:13 +0200
9615 @@ -17,6 +17,7 @@
9616  #include <linux/reiserfs_acl.h>
9617  #include <linux/reiserfs_xattr.h>
9618  #include <linux/quotaops.h>
9619 +#include <linux/vs_tag.h>
9620  
9621  #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; }
9622  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
9623 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
9624                         reiserfs_write_unlock(dir->i_sb);
9625                         return ERR_PTR(-EACCES);
9626                 }
9627 +               dx_propagate_tag(nd, inode);
9628  
9629                 /* Propogate the priv_object flag so we know we're in the priv tree */
9630                 if (is_reiserfs_priv_object(dir))
9631 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
9632         } else {
9633                 inode->i_gid = current->fsgid;
9634         }
9635 +       inode->i_tag = dx_current_fstag(inode->i_sb);
9636         DQUOT_INIT(inode);
9637         return 0;
9638  }
9639 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
9640         .listxattr = reiserfs_listxattr,
9641         .removexattr = reiserfs_removexattr,
9642         .permission = reiserfs_permission,
9643 +       .sync_flags = reiserfs_sync_flags,
9644  };
9645  
9646  /*
9647 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
9648         .listxattr = reiserfs_listxattr,
9649         .removexattr = reiserfs_removexattr,
9650         .permission = reiserfs_permission,
9651 +       .sync_flags = reiserfs_sync_flags,
9652  
9653  };
9654  
9655 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
9656         .listxattr = reiserfs_listxattr,
9657         .removexattr = reiserfs_removexattr,
9658         .permission = reiserfs_permission,
9659 +       .sync_flags = reiserfs_sync_flags,
9660  
9661  };
9662 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
9663 --- linux-2.6.22.10/fs/reiserfs/stree.c 2007-07-09 13:19:28 +0200
9664 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/stree.c      2007-08-05 20:53:13 +0200
9665 @@ -55,6 +55,7 @@
9666  #include <linux/reiserfs_fs.h>
9667  #include <linux/buffer_head.h>
9668  #include <linux/quotaops.h>
9669 +#include <linux/vs_dlimit.h>
9670  
9671  /* Does the buffer contain a disk block which is in the tree. */
9672  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
9673 @@ -1296,6 +1297,7 @@ int reiserfs_delete_item(struct reiserfs
9674                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
9675                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
9676  #endif
9677 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9678         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9679  
9680         /* Return deleted body length */
9681 @@ -1384,6 +1386,7 @@ void reiserfs_delete_solid_item(struct r
9682  #endif
9683                                 DQUOT_FREE_SPACE_NODIRTY(inode,
9684                                                          quota_cut_bytes);
9685 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
9686                         }
9687                         break;
9688                 }
9689 @@ -1737,6 +1740,7 @@ int reiserfs_cut_from_item(struct reiser
9690                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
9691                        quota_cut_bytes, p_s_inode->i_uid, '?');
9692  #endif
9693 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9694         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9695         return n_ret_value;
9696  }
9697 @@ -1978,6 +1982,11 @@ int reiserfs_paste_into_item(struct reis
9698                 pathrelse(p_s_search_path);
9699                 return -EDQUOT;
9700         }
9701 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
9702 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9703 +               pathrelse(p_s_search_path);
9704 +               return -ENOSPC;
9705 +       }
9706         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
9707                        n_pasted_size);
9708  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
9709 @@ -2030,6 +2039,7 @@ int reiserfs_paste_into_item(struct reis
9710                        n_pasted_size, inode->i_uid,
9711                        key2type(&(p_s_key->on_disk_key)));
9712  #endif
9713 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
9714         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9715         return retval;
9716  }
9717 @@ -2067,6 +2077,11 @@ int reiserfs_insert_item(struct reiserfs
9718                         pathrelse(p_s_path);
9719                         return -EDQUOT;
9720                 }
9721 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
9722 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9723 +                       pathrelse(p_s_path);
9724 +                       return -ENOSPC;
9725 +               }
9726         }
9727         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
9728                        IH_SIZE + ih_item_len(p_s_ih));
9729 @@ -2114,7 +2129,9 @@ int reiserfs_insert_item(struct reiserfs
9730                        "reiserquota insert_item(): freeing %u id=%u type=%c",
9731                        quota_bytes, inode->i_uid, head2type(p_s_ih));
9732  #endif
9733 -       if (inode)
9734 +       if (inode) {
9735 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
9736                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9737 +       }
9738         return retval;
9739  }
9740 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
9741 --- linux-2.6.22.10/fs/reiserfs/super.c 2007-07-09 13:19:28 +0200
9742 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/super.c      2007-08-05 20:53:13 +0200
9743 @@ -882,6 +882,14 @@ static int reiserfs_parse_options(struct
9744                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
9745                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
9746  #endif
9747 +#ifndef CONFIG_TAGGING_NONE
9748 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
9749 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
9750 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
9751 +#endif
9752 +#ifdef CONFIG_PROPAGATE
9753 +               {"tag",.arg_required = 'T',.values = NULL},
9754 +#endif
9755  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
9756                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
9757                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
9758 @@ -1143,6 +1151,12 @@ static int reiserfs_remount(struct super
9759                 return -EINVAL;
9760         }
9761  
9762 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
9763 +               !(s->s_flags & MS_TAGGED)) {
9764 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
9765 +               return -EINVAL;
9766 +       }
9767 +
9768         handle_attrs(s);
9769  
9770         /* Add options that are safe here */
9771 @@ -1591,6 +1605,10 @@ static int reiserfs_fill_super(struct su
9772                 goto error;
9773         }
9774  
9775 +       /* map mount option tagxid */
9776 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
9777 +               s->s_flags |= MS_TAGGED;
9778 +
9779         rs = SB_DISK_SUPER_BLOCK(s);
9780         /* Let's do basic sanity check to verify that underlying device is not
9781            smaller than the filesystem. If the check fails then abort and scream,
9782 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
9783 --- linux-2.6.22.10/fs/reiserfs/xattr.c 2007-07-09 13:19:28 +0200
9784 +++ linux-2.6.22.10-vs2.3.0.29/fs/reiserfs/xattr.c      2007-08-05 20:53:13 +0200
9785 @@ -35,6 +35,7 @@
9786  #include <linux/namei.h>
9787  #include <linux/errno.h>
9788  #include <linux/fs.h>
9789 +#include <linux/mount.h>
9790  #include <linux/file.h>
9791  #include <linux/pagemap.h>
9792  #include <linux/xattr.h>
9793 @@ -775,7 +776,7 @@ int reiserfs_delete_xattrs(struct inode 
9794         if (dir->d_inode->i_nlink <= 2) {
9795                 root = get_xa_root(inode->i_sb, XATTR_REPLACE);
9796                 reiserfs_write_lock_xattrs(inode->i_sb);
9797 -               err = vfs_rmdir(root->d_inode, dir);
9798 +               err = vfs_rmdir(root->d_inode, dir, NULL);
9799                 reiserfs_write_unlock_xattrs(inode->i_sb);
9800                 dput(root);
9801         } else {
9802 diff -NurpP --minimal linux-2.6.22.10/fs/stat.c linux-2.6.22.10-vs2.3.0.29/fs/stat.c
9803 --- linux-2.6.22.10/fs/stat.c   2007-07-09 13:19:28 +0200
9804 +++ linux-2.6.22.10-vs2.3.0.29/fs/stat.c        2007-08-05 20:53:13 +0200
9805 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
9806         stat->nlink = inode->i_nlink;
9807         stat->uid = inode->i_uid;
9808         stat->gid = inode->i_gid;
9809 +       stat->tag = inode->i_tag;
9810         stat->rdev = inode->i_rdev;
9811         stat->atime = inode->i_atime;
9812         stat->mtime = inode->i_mtime;
9813 diff -NurpP --minimal linux-2.6.22.10/fs/super.c linux-2.6.22.10-vs2.3.0.29/fs/super.c
9814 --- linux-2.6.22.10/fs/super.c  2007-07-09 13:19:28 +0200
9815 +++ linux-2.6.22.10-vs2.3.0.29/fs/super.c       2007-10-20 00:00:59 +0200
9816 @@ -37,6 +37,9 @@
9817  #include <linux/idr.h>
9818  #include <linux/kobject.h>
9819  #include <linux/mutex.h>
9820 +#include <linux/devpts_fs.h>
9821 +#include <linux/proc_fs.h>
9822 +#include <linux/vs_context.h>
9823  #include <asm/uaccess.h>
9824  
9825  
9826 @@ -860,12 +863,18 @@ struct vfsmount *
9827  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
9828  {
9829         struct vfsmount *mnt;
9830 +       struct super_block *sb;
9831         char *secdata = NULL;
9832         int error;
9833  
9834         if (!type)
9835                 return ERR_PTR(-ENODEV);
9836  
9837 +       error = -EPERM;
9838 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
9839 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
9840 +               goto out;
9841 +
9842         error = -ENOMEM;
9843         mnt = alloc_vfsmnt(name);
9844         if (!mnt)
9845 @@ -885,7 +894,14 @@ vfs_kern_mount(struct file_system_type *
9846         if (error < 0)
9847                 goto out_free_secdata;
9848  
9849 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
9850 +       sb = mnt->mnt_sb;
9851 +       error = -EPERM;
9852 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
9853 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
9854 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
9855 +               goto out_sb;
9856 +
9857 +       error = security_sb_kern_mount(sb, secdata);
9858         if (error)
9859                 goto out_sb;
9860  
9861 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
9862 --- linux-2.6.22.10/fs/sysfs/mount.c    2007-07-09 13:19:28 +0200
9863 +++ linux-2.6.22.10-vs2.3.0.29/fs/sysfs/mount.c 2007-08-05 20:53:13 +0200
9864 @@ -12,8 +12,6 @@
9865  
9866  #include "sysfs.h"
9867  
9868 -/* Random magic number */
9869 -#define SYSFS_MAGIC 0x62656572
9870  
9871  struct vfsmount *sysfs_mount;
9872  struct super_block * sysfs_sb = NULL;
9873 @@ -48,7 +46,7 @@ static int sysfs_fill_super(struct super
9874  
9875         sb->s_blocksize = PAGE_CACHE_SIZE;
9876         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
9877 -       sb->s_magic = SYSFS_MAGIC;
9878 +       sb->s_magic = SYSFS_SUPER_MAGIC;
9879         sb->s_op = &sysfs_ops;
9880         sb->s_time_gran = 1;
9881         sysfs_sb = sb;
9882 diff -NurpP --minimal linux-2.6.22.10/fs/utimes.c linux-2.6.22.10-vs2.3.0.29/fs/utimes.c
9883 --- linux-2.6.22.10/fs/utimes.c 2007-07-09 13:19:29 +0200
9884 +++ linux-2.6.22.10-vs2.3.0.29/fs/utimes.c      2007-08-05 20:53:13 +0200
9885 @@ -6,6 +6,8 @@
9886  #include <linux/sched.h>
9887  #include <linux/stat.h>
9888  #include <linux/utime.h>
9889 +#include <linux/mount.h>
9890 +#include <linux/vs_cowbl.h>
9891  #include <asm/uaccess.h>
9892  #include <asm/unistd.h>
9893  
9894 @@ -70,11 +72,13 @@ long do_utimes(int dfd, char __user *fil
9895                 if (error)
9896                         goto out;
9897  
9898 +               error = cow_check_and_break(&nd);
9899 +               if (error)
9900 +                       goto dput_and_out;
9901                 dentry = nd.dentry;
9902         }
9903  
9904         inode = dentry->d_inode;
9905 -
9906         error = -EROFS;
9907         if (IS_RDONLY(inode))
9908                 goto dput_and_out;
9909 diff -NurpP --minimal linux-2.6.22.10/fs/xattr.c linux-2.6.22.10-vs2.3.0.29/fs/xattr.c
9910 --- linux-2.6.22.10/fs/xattr.c  2007-07-09 13:19:29 +0200
9911 +++ linux-2.6.22.10-vs2.3.0.29/fs/xattr.c       2007-08-05 20:53:13 +0200
9912 @@ -17,6 +17,7 @@
9913  #include <linux/module.h>
9914  #include <linux/fsnotify.h>
9915  #include <linux/audit.h>
9916 +#include <linux/mount.h>
9917  #include <asm/uaccess.h>
9918  
9919  
9920 @@ -194,7 +195,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
9921   */
9922  static long
9923  setxattr(struct dentry *d, char __user *name, void __user *value,
9924 -        size_t size, int flags)
9925 +        size_t size, int flags, struct vfsmount *mnt)
9926  {
9927         int error;
9928         void *kvalue = NULL;
9929 @@ -221,6 +222,9 @@ setxattr(struct dentry *d, char __user *
9930                 }
9931         }
9932  
9933 +       if (MNT_IS_RDONLY(mnt))
9934 +               return -EROFS;
9935 +
9936         error = vfs_setxattr(d, kname, kvalue, size, flags);
9937         kfree(kvalue);
9938         return error;
9939 @@ -236,7 +240,7 @@ sys_setxattr(char __user *path, char __u
9940         error = user_path_walk(path, &nd);
9941         if (error)
9942                 return error;
9943 -       error = setxattr(nd.dentry, name, value, size, flags);
9944 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
9945         path_release(&nd);
9946         return error;
9947  }
9948 @@ -251,7 +255,7 @@ sys_lsetxattr(char __user *path, char __
9949         error = user_path_walk_link(path, &nd);
9950         if (error)
9951                 return error;
9952 -       error = setxattr(nd.dentry, name, value, size, flags);
9953 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
9954         path_release(&nd);
9955         return error;
9956  }
9957 @@ -269,7 +273,7 @@ sys_fsetxattr(int fd, char __user *name,
9958                 return error;
9959         dentry = f->f_path.dentry;
9960         audit_inode(NULL, dentry->d_inode);
9961 -       error = setxattr(dentry, name, value, size, flags);
9962 +       error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt);
9963         fput(f);
9964         return error;
9965  }
9966 @@ -433,7 +437,7 @@ sys_flistxattr(int fd, char __user *list
9967   * Extended attribute REMOVE operations
9968   */
9969  static long
9970 -removexattr(struct dentry *d, char __user *name)
9971 +removexattr(struct dentry *d, char __user *name, struct vfsmount *mnt)
9972  {
9973         int error;
9974         char kname[XATTR_NAME_MAX + 1];
9975 @@ -444,6 +448,9 @@ removexattr(struct dentry *d, char __use
9976         if (error < 0)
9977                 return error;
9978  
9979 +       if (MNT_IS_RDONLY(mnt))
9980 +               return -EROFS;
9981 +
9982         return vfs_removexattr(d, kname);
9983  }
9984  
9985 @@ -456,7 +463,7 @@ sys_removexattr(char __user *path, char 
9986         error = user_path_walk(path, &nd);
9987         if (error)
9988                 return error;
9989 -       error = removexattr(nd.dentry, name);
9990 +       error = removexattr(nd.dentry, name, nd.mnt);
9991         path_release(&nd);
9992         return error;
9993  }
9994 @@ -470,7 +477,7 @@ sys_lremovexattr(char __user *path, char
9995         error = user_path_walk_link(path, &nd);
9996         if (error)
9997                 return error;
9998 -       error = removexattr(nd.dentry, name);
9999 +       error = removexattr(nd.dentry, name, nd.mnt);
10000         path_release(&nd);
10001         return error;
10002  }
10003 @@ -487,7 +494,7 @@ sys_fremovexattr(int fd, char __user *na
10004                 return error;
10005         dentry = f->f_path.dentry;
10006         audit_inode(NULL, dentry->d_inode);
10007 -       error = removexattr(dentry, name);
10008 +       error = removexattr(dentry, name, f->f_vfsmnt);
10009         fput(f);
10010         return error;
10011  }
10012 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
10013 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_ioctl.c        2007-05-02 19:25:22 +0200
10014 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_ioctl.c     2007-08-05 20:53:13 +0200
10015 @@ -1128,6 +1128,10 @@ xfs_di2lxflags(
10016  
10017         if (di_flags & XFS_DIFLAG_IMMUTABLE)
10018                 flags |= FS_IMMUTABLE_FL;
10019 +       if (di_flags & XFS_DIFLAG_IUNLINK)
10020 +               flags |= FS_IUNLINK_FL;
10021 +       if (di_flags & XFS_DIFLAG_BARRIER)
10022 +               flags |= FS_BARRIER_FL;
10023         if (di_flags & XFS_DIFLAG_APPEND)
10024                 flags |= FS_APPEND_FL;
10025         if (di_flags & XFS_DIFLAG_SYNC)
10026 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
10027 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_iops.c 2007-05-02 19:25:22 +0200
10028 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_iops.c      2007-08-05 20:53:13 +0200
10029 @@ -51,6 +51,7 @@
10030  #include <linux/xattr.h>
10031  #include <linux/namei.h>
10032  #include <linux/security.h>
10033 +#include <linux/vs_tag.h>
10034  
10035  /*
10036   * Get a XFS inode from a given vnode.
10037 @@ -400,6 +401,7 @@ xfs_vn_lookup(
10038                 d_add(dentry, NULL);
10039                 return NULL;
10040         }
10041 +       dx_propagate_tag(nd, vn_to_inode(cvp));
10042  
10043         return d_splice_alias(vn_to_inode(cvp), dentry);
10044  }
10045 @@ -657,6 +659,10 @@ xfs_vn_setattr(
10046         int             flags = 0;
10047         int             error;
10048  
10049 +       error = inode_change_ok(inode, attr);
10050 +       if (error)
10051 +               return error;
10052 +
10053         if (ia_valid & ATTR_UID) {
10054                 vattr.va_mask |= XFS_AT_UID;
10055                 vattr.va_uid = attr->ia_uid;
10056 @@ -665,6 +671,10 @@ xfs_vn_setattr(
10057                 vattr.va_mask |= XFS_AT_GID;
10058                 vattr.va_gid = attr->ia_gid;
10059         }
10060 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode)) {
10061 +               vattr.va_mask |= XFS_AT_TAG;
10062 +               vattr.va_tag = attr->ia_tag;
10063 +       }
10064         if (ia_valid & ATTR_SIZE) {
10065                 vattr.va_mask |= XFS_AT_SIZE;
10066                 vattr.va_size = attr->ia_size;
10067 @@ -710,6 +720,42 @@ xfs_vn_truncate(
10068  }
10069  
10070  STATIC int
10071 +xfs_vn_sync_flags(struct inode *inode)
10072 +{
10073 +       unsigned int oldflags, newflags;
10074 +       int             flags = 0;
10075 +       int             error;
10076 +       bhv_vattr_t     vattr;
10077 +       bhv_vnode_t     *vp = vn_from_inode(inode);
10078 +
10079 +       memset(&vattr, 0, sizeof vattr);
10080 +
10081 +       vattr.va_mask = XFS_AT_XFLAGS;
10082 +       error = bhv_vop_getattr(vp, &vattr, 0, NULL);
10083 +
10084 +       if (error)
10085 +               return error;
10086 +       oldflags = vattr.va_xflags;
10087 +       newflags = oldflags & ~(XFS_XFLAG_IMMUTABLE |
10088 +               XFS_XFLAG_IUNLINK | XFS_XFLAG_BARRIER);
10089 +
10090 +       if (IS_IMMUTABLE(inode))
10091 +               newflags |= XFS_XFLAG_IMMUTABLE;
10092 +       if (IS_IUNLINK(inode))
10093 +               newflags |= XFS_XFLAG_IUNLINK;
10094 +       if (IS_BARRIER(inode))
10095 +               newflags |= XFS_XFLAG_BARRIER;
10096 +
10097 +       if (oldflags ^ newflags) {
10098 +               vattr.va_xflags = newflags;
10099 +               vattr.va_mask |= XFS_AT_XFLAGS;
10100 +               error = bhv_vop_setattr(vp, &vattr, flags, NULL);
10101 +       }
10102 +       vn_revalidate(vp);
10103 +       return error;
10104 +}
10105 +
10106 +STATIC int
10107  xfs_vn_setxattr(
10108         struct dentry   *dentry,
10109         const char      *name,
10110 @@ -822,6 +868,7 @@ const struct inode_operations xfs_inode_
10111         .getxattr               = xfs_vn_getxattr,
10112         .listxattr              = xfs_vn_listxattr,
10113         .removexattr            = xfs_vn_removexattr,
10114 +       .sync_flags             = xfs_vn_sync_flags,
10115  };
10116  
10117  const struct inode_operations xfs_dir_inode_operations = {
10118 @@ -841,6 +888,7 @@ const struct inode_operations xfs_dir_in
10119         .getxattr               = xfs_vn_getxattr,
10120         .listxattr              = xfs_vn_listxattr,
10121         .removexattr            = xfs_vn_removexattr,
10122 +       .sync_flags             = xfs_vn_sync_flags,
10123  };
10124  
10125  const struct inode_operations xfs_symlink_inode_operations = {
10126 @@ -854,4 +902,5 @@ const struct inode_operations xfs_symlin
10127         .getxattr               = xfs_vn_getxattr,
10128         .listxattr              = xfs_vn_listxattr,
10129         .removexattr            = xfs_vn_removexattr,
10130 +       .sync_flags             = xfs_vn_sync_flags,
10131  };
10132 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
10133 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_linux.h        2007-05-02 19:25:22 +0200
10134 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_linux.h     2007-08-05 20:53:13 +0200
10135 @@ -129,6 +129,7 @@
10136  #define current_pid()          (current->pid)
10137  #define current_fsuid(cred)    (current->fsuid)
10138  #define current_fsgid(cred)    (current->fsgid)
10139 +#define current_fstag(cred,vp) (dx_current_fstag(vn_to_inode(vp)->i_sb))
10140  #define current_test_flags(f)  (current->flags & (f))
10141  #define current_set_flags_nested(sp, f)                \
10142                 (*(sp) = current->flags, current->flags |= (f))
10143 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
10144 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_super.c        2007-07-09 13:19:29 +0200
10145 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_super.c     2007-08-05 20:53:13 +0200
10146 @@ -157,6 +157,7 @@ xfs_revalidate_inode(
10147         inode->i_nlink  = ip->i_d.di_nlink;
10148         inode->i_uid    = ip->i_d.di_uid;
10149         inode->i_gid    = ip->i_d.di_gid;
10150 +       inode->i_tag    = ip->i_d.di_tag;
10151  
10152         switch (inode->i_mode & S_IFMT) {
10153         case S_IFBLK:
10154 @@ -184,6 +185,14 @@ xfs_revalidate_inode(
10155                 inode->i_flags |= S_IMMUTABLE;
10156         else
10157                 inode->i_flags &= ~S_IMMUTABLE;
10158 +       if (ip->i_d.di_flags & XFS_DIFLAG_IUNLINK)
10159 +               inode->i_flags |= S_IUNLINK;
10160 +       else
10161 +               inode->i_flags &= ~S_IUNLINK;
10162 +       if (ip->i_d.di_flags & XFS_DIFLAG_BARRIER)
10163 +               inode->i_flags |= S_BARRIER;
10164 +       else
10165 +               inode->i_flags &= ~S_BARRIER;
10166         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
10167                 inode->i_flags |= S_APPEND;
10168         else
10169 @@ -712,6 +721,12 @@ xfs_fs_remount(
10170         int                     error;
10171  
10172         error = bhv_vfs_parseargs(vfsp, options, args, 1);
10173 +       if ((args->flags2 & XFSMNT2_TAGGED) &&
10174 +               !(sb->s_flags & MS_TAGGED)) {
10175 +               printk("XFS: %s: tagging not permitted on remount.\n",
10176 +                       sb->s_id);
10177 +               error = EINVAL;
10178 +       }
10179         if (!error)
10180                 error = bhv_vfs_mntupdate(vfsp, flags, args);
10181         kmem_free(args, sizeof(*args));
10182 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
10183 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.c        2007-05-02 19:25:22 +0200
10184 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_vnode.c     2007-08-05 20:53:13 +0200
10185 @@ -119,6 +119,7 @@ vn_revalidate_core(
10186         inode->i_nlink      = vap->va_nlink;
10187         inode->i_uid        = vap->va_uid;
10188         inode->i_gid        = vap->va_gid;
10189 +       inode->i_tag        = vap->va_tag;
10190         inode->i_blocks     = vap->va_nblocks;
10191         inode->i_mtime      = vap->va_mtime;
10192         inode->i_ctime      = vap->va_ctime;
10193 @@ -126,6 +127,14 @@ vn_revalidate_core(
10194                 inode->i_flags |= S_IMMUTABLE;
10195         else
10196                 inode->i_flags &= ~S_IMMUTABLE;
10197 +       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10198 +               inode->i_flags |= S_IUNLINK;
10199 +       else
10200 +               inode->i_flags &= ~S_IUNLINK;
10201 +       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10202 +               inode->i_flags |= S_BARRIER;
10203 +       else
10204 +               inode->i_flags &= ~S_BARRIER;
10205         if (vap->va_xflags & XFS_XFLAG_APPEND)
10206                 inode->i_flags |= S_APPEND;
10207         else
10208 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
10209 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.h        2007-07-09 13:19:29 +0200
10210 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/linux-2.6/xfs_vnode.h     2007-08-05 20:53:13 +0200
10211 @@ -350,6 +350,7 @@ typedef struct bhv_vattr {
10212         xfs_nlink_t     va_nlink;       /* number of references to file */
10213         uid_t           va_uid;         /* owner user id */
10214         gid_t           va_gid;         /* owner group id */
10215 +       tag_t           va_tag;         /* owner group id */
10216         xfs_ino_t       va_nodeid;      /* file id */
10217         xfs_off_t       va_size;        /* file size in bytes */
10218         u_long          va_blocksize;   /* blocksize preferred for i/o */
10219 @@ -398,13 +399,15 @@ typedef struct bhv_vattr {
10220  #define XFS_AT_PROJID          0x04000000
10221  #define XFS_AT_SIZE_NOPERM     0x08000000
10222  #define XFS_AT_GENCOUNT                0x10000000
10223 +#define XFS_AT_TAG             0x20000000
10224  
10225  #define XFS_AT_ALL     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
10226                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
10227                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
10228                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
10229                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
10230 -               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
10231 +               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT\
10232 +               XFS_AT_TAG)
10233  
10234  #define XFS_AT_STAT    (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
10235                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
10236 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
10237 --- linux-2.6.22.10/fs/xfs/quota/xfs_qm_syscalls.c      2007-07-09 13:19:29 +0200
10238 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/quota/xfs_qm_syscalls.c   2007-08-05 20:53:13 +0200
10239 @@ -17,6 +17,7 @@
10240   */
10241  
10242  #include <linux/capability.h>
10243 +#include <linux/vs_context.h>
10244  
10245  #include "xfs.h"
10246  #include "xfs_fs.h"
10247 @@ -211,7 +212,7 @@ xfs_qm_scall_quotaoff(
10248         xfs_qoff_logitem_t      *qoffstart;
10249         int                     nculprits;
10250  
10251 -       if (!force && !capable(CAP_SYS_ADMIN))
10252 +       if (!force && !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10253                 return XFS_ERROR(EPERM);
10254         /*
10255          * No file system can have quotas enabled on disk but not in core.
10256 @@ -380,7 +381,7 @@ xfs_qm_scall_trunc_qfiles(
10257         int             error;
10258         xfs_inode_t     *qip;
10259  
10260 -       if (!capable(CAP_SYS_ADMIN))
10261 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10262                 return XFS_ERROR(EPERM);
10263         error = 0;
10264         if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) {
10265 @@ -425,7 +426,7 @@ xfs_qm_scall_quotaon(
10266         uint            accflags;
10267         __int64_t       sbflags;
10268  
10269 -       if (!capable(CAP_SYS_ADMIN))
10270 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10271                 return XFS_ERROR(EPERM);
10272  
10273         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
10274 @@ -594,7 +595,7 @@ xfs_qm_scall_setqlim(
10275         int                     error;
10276         xfs_qcnt_t              hard, soft;
10277  
10278 -       if (!capable(CAP_SYS_ADMIN))
10279 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
10280                 return XFS_ERROR(EPERM);
10281  
10282         if ((newlim->d_fieldmask &
10283 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
10284 --- linux-2.6.22.10/fs/xfs/xfs_clnt.h   2006-06-18 04:54:50 +0200
10285 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_clnt.h        2007-08-05 20:53:13 +0200
10286 @@ -99,5 +99,7 @@ struct xfs_mount_args {
10287   */
10288  #define XFSMNT2_COMPAT_IOSIZE  0x00000001      /* don't report large preferred
10289                                                  * I/O size in stat(2) */
10290 +#define XFSMNT2_TAGGED         0x80000000      /* context tagging */
10291 +
10292  
10293  #endif /* __XFS_CLNT_H__ */
10294 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
10295 --- linux-2.6.22.10/fs/xfs/xfs_dinode.h 2006-09-20 16:58:40 +0200
10296 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_dinode.h      2007-08-05 20:53:13 +0200
10297 @@ -53,7 +53,8 @@ typedef struct xfs_dinode_core
10298         __uint32_t      di_gid;         /* owner's group id */
10299         __uint32_t      di_nlink;       /* number of links to file */
10300         __uint16_t      di_projid;      /* owner's project id */
10301 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
10302 +       __uint16_t      di_tag;         /* context tagging */
10303 +       __uint8_t       di_pad[6];      /* unused, zeroed space */
10304         __uint16_t      di_flushiter;   /* incremented on flush */
10305         xfs_timestamp_t di_atime;       /* time last accessed */
10306         xfs_timestamp_t di_mtime;       /* time last modified */
10307 @@ -257,6 +258,9 @@ typedef enum xfs_dinode_fmt
10308  #define XFS_DIFLAG_EXTSIZE_BIT      11 /* inode extent size allocator hint */
10309  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
10310  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
10311 +#define XFS_DIFLAG_BARRIER_BIT 14      /* chroot() barrier */
10312 +#define XFS_DIFLAG_IUNLINK_BIT 15      /* immutable unlink */
10313 +
10314  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
10315  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
10316  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
10317 @@ -271,12 +275,15 @@ typedef enum xfs_dinode_fmt
10318  #define XFS_DIFLAG_EXTSIZE       (1 << XFS_DIFLAG_EXTSIZE_BIT)
10319  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
10320  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
10321 +#define XFS_DIFLAG_BARRIER      (1 << XFS_DIFLAG_BARRIER_BIT)
10322 +#define XFS_DIFLAG_IUNLINK      (1 << XFS_DIFLAG_IUNLINK_BIT)
10323  
10324  #define XFS_DIFLAG_ANY \
10325         (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
10326          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
10327          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
10328          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
10329 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG)
10330 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_BARRIER | \
10331 +        XFS_DIFLAG_IUNLINK)
10332  
10333  #endif /* __XFS_DINODE_H__ */
10334 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
10335 --- linux-2.6.22.10/fs/xfs/xfs_fs.h     2006-11-30 21:19:29 +0100
10336 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_fs.h  2007-08-05 20:53:13 +0200
10337 @@ -66,6 +66,8 @@ struct fsxattr {
10338  #define XFS_XFLAG_EXTSIZE      0x00000800      /* extent size allocator hint */
10339  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
10340  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
10341 +#define XFS_XFLAG_BARRIER      0x00004000      /* chroot() barrier */
10342 +#define XFS_XFLAG_IUNLINK      0x00008000      /* immutable unlink */
10343  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
10344  
10345  /*
10346 @@ -294,7 +296,8 @@ typedef struct xfs_bstat {
10347         __s32           bs_extents;     /* number of extents            */
10348         __u32           bs_gen;         /* generation count             */
10349         __u16           bs_projid;      /* project id                   */
10350 -       unsigned char   bs_pad[14];     /* pad space, unused            */
10351 +       __u16           bs_tag;         /* context tagging              */
10352 +       unsigned char   bs_pad[12];     /* pad space, unused            */
10353         __u32           bs_dmevmask;    /* DMIG event mask              */
10354         __u16           bs_dmstate;     /* DMIG state info              */
10355         __u16           bs_aextents;    /* attribute number of extents  */
10356 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
10357 --- linux-2.6.22.10/fs/xfs/xfs_inode.c  2007-07-09 13:19:34 +0200
10358 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_inode.c       2007-08-05 20:53:13 +0200
10359 @@ -49,6 +49,7 @@
10360  #include "xfs_quota.h"
10361  #include "xfs_acl.h"
10362  
10363 +#include <linux/vs_tag.h>
10364  
10365  kmem_zone_t *xfs_ifork_zone;
10366  kmem_zone_t *xfs_inode_zone;
10367 @@ -736,20 +737,35 @@ xfs_xlate_dinode_core(
10368         xfs_dinode_core_t       *buf_core = (xfs_dinode_core_t *)buf;
10369         xfs_dinode_core_t       *mem_core = (xfs_dinode_core_t *)dip;
10370         xfs_arch_t              arch = ARCH_CONVERT;
10371 +       uint32_t                uid = 0, gid = 0;
10372 +       uint16_t                tag = 0;
10373  
10374         ASSERT(dir);
10375  
10376 +       if (dir < 0) {
10377 +               tag = mem_core->di_tag;
10378 +               /* FIXME: supposed to use superblock flag */
10379 +               uid = TAGINO_UID(1, mem_core->di_uid, tag);
10380 +               gid = TAGINO_GID(1, mem_core->di_gid, tag);
10381 +               tag = TAGINO_TAG(1, tag);
10382 +       }
10383 +
10384         INT_XLATE(buf_core->di_magic, mem_core->di_magic, dir, arch);
10385         INT_XLATE(buf_core->di_mode, mem_core->di_mode, dir, arch);
10386         INT_XLATE(buf_core->di_version, mem_core->di_version, dir, arch);
10387         INT_XLATE(buf_core->di_format, mem_core->di_format, dir, arch);
10388         INT_XLATE(buf_core->di_onlink, mem_core->di_onlink, dir, arch);
10389 -       INT_XLATE(buf_core->di_uid, mem_core->di_uid, dir, arch);
10390 -       INT_XLATE(buf_core->di_gid, mem_core->di_gid, dir, arch);
10391 +       INT_XLATE(buf_core->di_uid, uid, dir, arch);
10392 +       INT_XLATE(buf_core->di_gid, gid, dir, arch);
10393 +       INT_XLATE(buf_core->di_tag, tag, dir, arch);
10394         INT_XLATE(buf_core->di_nlink, mem_core->di_nlink, dir, arch);
10395         INT_XLATE(buf_core->di_projid, mem_core->di_projid, dir, arch);
10396  
10397         if (dir > 0) {
10398 +               /* FIXME: supposed to use superblock flag */
10399 +               mem_core->di_uid = INOTAG_UID(1, uid, gid);
10400 +               mem_core->di_gid = INOTAG_GID(1, uid, gid);
10401 +               mem_core->di_tag = INOTAG_TAG(1, uid, gid, tag);
10402                 memcpy(mem_core->di_pad, buf_core->di_pad,
10403                         sizeof(buf_core->di_pad));
10404         } else {
10405 @@ -797,6 +813,10 @@ _xfs_dic2xflags(
10406                         flags |= XFS_XFLAG_PREALLOC;
10407                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
10408                         flags |= XFS_XFLAG_IMMUTABLE;
10409 +               if (di_flags & XFS_DIFLAG_IUNLINK)
10410 +                       flags |= XFS_XFLAG_IUNLINK;
10411 +               if (di_flags & XFS_DIFLAG_BARRIER)
10412 +                       flags |= XFS_XFLAG_BARRIER;
10413                 if (di_flags & XFS_DIFLAG_APPEND)
10414                         flags |= XFS_XFLAG_APPEND;
10415                 if (di_flags & XFS_DIFLAG_SYNC)
10416 @@ -1129,6 +1149,7 @@ xfs_ialloc(
10417         ASSERT(ip->i_d.di_nlink == nlink);
10418         ip->i_d.di_uid = current_fsuid(cr);
10419         ip->i_d.di_gid = current_fsgid(cr);
10420 +       ip->i_d.di_tag = current_fstag(cr, vp);
10421         ip->i_d.di_projid = prid;
10422         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
10423  
10424 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
10425 --- linux-2.6.22.10/fs/xfs/xfs_itable.c 2007-07-09 13:19:34 +0200
10426 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_itable.c      2007-08-05 20:53:13 +0200
10427 @@ -89,6 +89,7 @@ xfs_bulkstat_one_iget(
10428         buf->bs_mode = dic->di_mode;
10429         buf->bs_uid = dic->di_uid;
10430         buf->bs_gid = dic->di_gid;
10431 +       buf->bs_tag = dic->di_tag;
10432         buf->bs_size = dic->di_size;
10433         vn_atime_to_bstime(vp, &buf->bs_atime);
10434         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
10435 @@ -163,6 +164,7 @@ xfs_bulkstat_one_dinode(
10436         buf->bs_mode = INT_GET(dic->di_mode, ARCH_CONVERT);
10437         buf->bs_uid = INT_GET(dic->di_uid, ARCH_CONVERT);
10438         buf->bs_gid = INT_GET(dic->di_gid, ARCH_CONVERT);
10439 +       buf->bs_tag = INT_GET(dic->di_tag, ARCH_CONVERT);
10440         buf->bs_size = INT_GET(dic->di_size, ARCH_CONVERT);
10441         buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
10442         buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
10443 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
10444 --- linux-2.6.22.10/fs/xfs/xfs_mount.h  2007-05-02 19:25:23 +0200
10445 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_mount.h       2007-08-05 20:53:13 +0200
10446 @@ -464,6 +464,7 @@ typedef struct xfs_mount {
10447  #define XFS_MOUNT_NO_PERCPU_SB (1ULL << 23)    /* don't use per-cpu superblock
10448                                                    counters */
10449  
10450 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
10451  
10452  /*
10453   * Default minimum read and write sizes.
10454 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
10455 --- linux-2.6.22.10/fs/xfs/xfs_vfsops.c 2007-07-09 13:19:34 +0200
10456 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_vfsops.c      2007-08-05 20:53:13 +0200
10457 @@ -300,6 +300,8 @@ xfs_start_flags(
10458  
10459         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
10460                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
10461 +       if (ap->flags2 & XFSMNT2_TAGGED)
10462 +               mp->m_flags |= XFS_MOUNT_TAGGED;
10463  
10464         /*
10465          * no recovery flag requires a read-only mount
10466 @@ -394,6 +396,8 @@ xfs_finish_flags(
10467                         return XFS_ERROR(EINVAL);
10468         }
10469  
10470 +       if (ap->flags2 & XFSMNT2_TAGGED)
10471 +               vfs->vfs_super->s_flags |= MS_TAGGED;
10472         return 0;
10473  }
10474  
10475 @@ -1645,6 +1649,9 @@ xfs_vget(
10476                                          * in stat(). */
10477  #define MNTOPT_ATTR2   "attr2"         /* do use attr2 attribute format */
10478  #define MNTOPT_NOATTR2 "noattr2"       /* do not use attr2 attribute format */
10479 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
10480 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
10481 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
10482  
10483  STATIC unsigned long
10484  suffix_strtoul(char *s, char **endp, unsigned int base)
10485 @@ -1831,6 +1838,19 @@ xfs_parseargs(
10486                         args->flags |= XFSMNT_ATTR2;
10487                 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
10488                         args->flags &= ~XFSMNT_ATTR2;
10489 +#ifndef CONFIG_TAGGING_NONE
10490 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
10491 +                       args->flags2 |= XFSMNT2_TAGGED;
10492 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
10493 +                       args->flags2 &= ~XFSMNT2_TAGGED;
10494 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
10495 +                       args->flags2 |= XFSMNT2_TAGGED;
10496 +#endif
10497 +#ifdef CONFIG_PROPAGATE
10498 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
10499 +                       /* use value */
10500 +                       args->flags2 |= XFSMNT2_TAGGED;
10501 +#endif
10502                 } else if (!strcmp(this_char, "osyncisdsync")) {
10503                         /* no-op, this is now the default */
10504                         cmn_err(CE_WARN,
10505 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
10506 --- linux-2.6.22.10/fs/xfs/xfs_vnodeops.c       2007-07-09 13:19:34 +0200
10507 +++ linux-2.6.22.10-vs2.3.0.29/fs/xfs/xfs_vnodeops.c    2007-08-05 20:53:13 +0200
10508 @@ -159,6 +159,7 @@ xfs_getattr(
10509         vap->va_mode = ip->i_d.di_mode;
10510         vap->va_uid = ip->i_d.di_uid;
10511         vap->va_gid = ip->i_d.di_gid;
10512 +       vap->va_tag = ip->i_d.di_tag;
10513         vap->va_projid = ip->i_d.di_projid;
10514  
10515         /*
10516 @@ -259,6 +260,7 @@ xfs_setattr(
10517         uint                    commit_flags=0;
10518         uid_t                   uid=0, iuid=0;
10519         gid_t                   gid=0, igid=0;
10520 +       tag_t                   tag=0, itag=0;
10521         int                     timeflags = 0;
10522         bhv_vnode_t             *vp;
10523         xfs_prid_t              projid=0, iprojid=0;
10524 @@ -315,6 +317,7 @@ xfs_setattr(
10525             (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID))) {
10526                 uint    qflags = 0;
10527  
10528 +               /* TODO: handle tagging? */
10529                 if ((mask & XFS_AT_UID) && XFS_IS_UQUOTA_ON(mp)) {
10530                         uid = vap->va_uid;
10531                         qflags |= XFS_QMOPT_UQUOTA;
10532 @@ -394,6 +397,8 @@ xfs_setattr(
10533         if (mask &
10534             (XFS_AT_MODE|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_UID|
10535              XFS_AT_GID|XFS_AT_PROJID)) {
10536 +               /* TODO: handle tagging? */
10537 +
10538                 /*
10539                  * CAP_FOWNER overrides the following restrictions:
10540                  *
10541 @@ -442,7 +447,7 @@ xfs_setattr(
10542          * and can change the group id only to a group of which he
10543          * or she is a member.
10544          */
10545 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10546 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10547                 /*
10548                  * These IDs could have changed since we last looked at them.
10549                  * But, we're assured that if the ownership did change
10550 @@ -450,10 +455,12 @@ xfs_setattr(
10551                  * would have changed also.
10552                  */
10553                 iuid = ip->i_d.di_uid;
10554 -               iprojid = ip->i_d.di_projid;
10555                 igid = ip->i_d.di_gid;
10556 -               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10557 +               itag = ip->i_d.di_tag;
10558 +               iprojid = ip->i_d.di_projid;
10559                 uid = (mask & XFS_AT_UID) ? vap->va_uid : iuid;
10560 +               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10561 +               tag = (mask & XFS_AT_TAG) ? vap->va_tag : itag;
10562                 projid = (mask & XFS_AT_PROJID) ? (xfs_prid_t)vap->va_projid :
10563                          iprojid;
10564  
10565 @@ -481,6 +488,7 @@ xfs_setattr(
10566                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
10567                     (XFS_IS_PQUOTA_ON(mp) && iprojid != projid) ||
10568                     (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
10569 +                       /* TODO: handle tagging? */
10570                         ASSERT(tp);
10571                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
10572                                                 capable(CAP_FOWNER) ?
10573 @@ -706,7 +714,7 @@ xfs_setattr(
10574          * and can change the group id only to a group of which he
10575          * or she is a member.
10576          */
10577 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10578 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10579                 /*
10580                  * CAP_FSETID overrides the following restrictions:
10581                  *
10582 @@ -722,6 +730,9 @@ xfs_setattr(
10583                  * Change the ownerships and register quota modifications
10584                  * in the transaction.
10585                  */
10586 +               if (itag != tag) {
10587 +                       ip->i_d.di_tag = tag;
10588 +               }
10589                 if (iuid != uid) {
10590                         if (XFS_IS_UQUOTA_ON(mp)) {
10591                                 ASSERT(mask & XFS_AT_UID);
10592 @@ -802,6 +813,10 @@ xfs_setattr(
10593                         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
10594                         if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
10595                                 di_flags |= XFS_DIFLAG_IMMUTABLE;
10596 +                       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10597 +                               di_flags |= XFS_DIFLAG_IUNLINK;
10598 +                       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10599 +                               di_flags |= XFS_DIFLAG_BARRIER;
10600                         if (vap->va_xflags & XFS_XFLAG_APPEND)
10601                                 di_flags |= XFS_DIFLAG_APPEND;
10602                         if (vap->va_xflags & XFS_XFLAG_SYNC)
10603 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
10604 --- linux-2.6.22.10/include/asm-alpha/socket.h  2007-07-09 13:19:35 +0200
10605 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-alpha/socket.h       2007-08-05 20:53:13 +0200
10606 @@ -55,6 +55,8 @@
10607  #define SO_TIMESTAMPNS         35
10608  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10609  
10610 +#define SO_PEERTAG             36
10611 +
10612  /* Security levels - as per NRL IPv6 - don't actually do anything */
10613  #define SO_SECURITY_AUTHENTICATION             19
10614  #define SO_SECURITY_ENCRYPTION_TRANSPORT       20
10615 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
10616 --- linux-2.6.22.10/include/asm-arm/socket.h    2007-07-09 13:19:39 +0200
10617 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-arm/socket.h 2007-08-05 20:53:13 +0200
10618 @@ -52,4 +52,6 @@
10619  #define SO_TIMESTAMPNS         35
10620  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10621  
10622 +#define SO_PEERTAG             36
10623 +
10624  #endif /* _ASM_SOCKET_H */
10625 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
10626 --- linux-2.6.22.10/include/asm-arm/tlb.h       2006-06-18 04:54:58 +0200
10627 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-arm/tlb.h    2007-08-05 20:53:13 +0200
10628 @@ -28,6 +28,7 @@
10629  #else /* !CONFIG_MMU */
10630  
10631  #include <asm/pgalloc.h>
10632 +#include <linux/vs_memory.h>
10633  
10634  /*
10635   * TLB handling.  This allows us to remove pages from the page
10636 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
10637 --- linux-2.6.22.10/include/asm-arm26/tlb.h     2006-01-03 17:30:02 +0100
10638 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-arm26/tlb.h  2007-08-05 20:53:13 +0200
10639 @@ -3,6 +3,7 @@
10640  
10641  #include <asm/pgalloc.h>
10642  #include <asm/tlbflush.h>
10643 +#include <linux/vs_memory.h>
10644  
10645  /*
10646   * TLB handling.  This allows us to remove pages from the page
10647 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
10648 --- linux-2.6.22.10/include/asm-arm26/unistd.h  2007-02-06 03:01:35 +0100
10649 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-arm26/unistd.h       2007-08-05 20:53:13 +0200
10650 @@ -302,6 +302,8 @@
10651  #define __NR_mq_getsetattr             (__NR_SYSCALL_BASE+279)
10652  #define __NR_waitid                    (__NR_SYSCALL_BASE+280)
10653  
10654 +#define __NR_vserver                   (__NR_SYSCALL_BASE+313)
10655 +
10656  /*
10657   * The following SWIs are ARM private. FIXME - make appropriate for arm26
10658   */
10659 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
10660 --- linux-2.6.22.10/include/asm-cris/socket.h   2007-07-09 13:19:40 +0200
10661 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-cris/socket.h        2007-08-05 20:53:13 +0200
10662 @@ -54,6 +54,8 @@
10663  #define SO_TIMESTAMPNS         35
10664  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10665  
10666 +#define SO_PEERTAG             36
10667 +
10668  #endif /* _ASM_SOCKET_H */
10669  
10670  
10671 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
10672 --- linux-2.6.22.10/include/asm-frv/socket.h    2007-07-09 13:19:40 +0200
10673 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-frv/socket.h 2007-08-05 20:53:13 +0200
10674 @@ -52,5 +52,7 @@
10675  #define SO_TIMESTAMPNS         35
10676  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10677  
10678 +#define SO_PEERTAG             36
10679 +
10680  #endif /* _ASM_SOCKET_H */
10681  
10682 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
10683 --- linux-2.6.22.10/include/asm-generic/tlb.h   2006-11-30 21:19:31 +0100
10684 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-generic/tlb.h        2007-08-05 20:53:13 +0200
10685 @@ -14,6 +14,7 @@
10686  #define _ASM_GENERIC__TLB_H
10687  
10688  #include <linux/swap.h>
10689 +#include <linux/vs_memory.h>
10690  #include <asm/pgalloc.h>
10691  #include <asm/tlbflush.h>
10692  
10693 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
10694 --- linux-2.6.22.10/include/asm-h8300/socket.h  2007-07-09 13:19:40 +0200
10695 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-h8300/socket.h       2007-08-05 20:53:13 +0200
10696 @@ -52,4 +52,6 @@
10697  #define SO_TIMESTAMPNS         35
10698  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10699  
10700 +#define SO_PEERTAG             36
10701 +
10702  #endif /* _ASM_SOCKET_H */
10703 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
10704 --- linux-2.6.22.10/include/asm-i386/socket.h   2007-07-09 13:19:42 +0200
10705 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-i386/socket.h        2007-08-05 20:53:13 +0200
10706 @@ -52,4 +52,6 @@
10707  #define SO_TIMESTAMPNS         35
10708  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10709  
10710 +#define SO_PEERTAG             36
10711 +
10712  #endif /* _ASM_SOCKET_H */
10713 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
10714 --- linux-2.6.22.10/include/asm-ia64/socket.h   2007-07-09 13:19:43 +0200
10715 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-ia64/socket.h        2007-08-05 20:53:13 +0200
10716 @@ -61,4 +61,6 @@
10717  #define SO_TIMESTAMPNS         35
10718  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10719  
10720 +#define SO_PEERTAG             36
10721 +
10722  #endif /* _ASM_IA64_SOCKET_H */
10723 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
10724 --- linux-2.6.22.10/include/asm-ia64/tlb.h      2006-09-20 16:58:40 +0200
10725 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-ia64/tlb.h   2007-08-05 20:53:13 +0200
10726 @@ -40,6 +40,7 @@
10727  #include <linux/mm.h>
10728  #include <linux/pagemap.h>
10729  #include <linux/swap.h>
10730 +#include <linux/vs_memory.h>
10731  
10732  #include <asm/pgalloc.h>
10733  #include <asm/processor.h>
10734 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
10735 --- linux-2.6.22.10/include/asm-m32r/socket.h   2007-07-09 13:19:43 +0200
10736 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-m32r/socket.h        2007-08-05 20:53:13 +0200
10737 @@ -52,4 +52,6 @@
10738  #define SO_TIMESTAMPNS         35
10739  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10740  
10741 +#define SO_PEERTAG             36
10742 +
10743  #endif /* _ASM_M32R_SOCKET_H */
10744 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
10745 --- linux-2.6.22.10/include/asm-mips/socket.h   2007-07-09 13:19:44 +0200
10746 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-mips/socket.h        2007-08-05 20:53:13 +0200
10747 @@ -73,6 +73,8 @@ To add: #define SO_REUSEPORT 0x0200   /* A
10748  #define SO_TIMESTAMPNS         35
10749  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10750  
10751 +#define SO_PEERTAG             36
10752 +
10753  #ifdef __KERNEL__
10754  
10755  /** sock_type - Socket types
10756 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
10757 --- linux-2.6.22.10/include/asm-parisc/socket.h 2007-07-09 13:19:44 +0200
10758 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-parisc/socket.h      2007-08-05 20:53:13 +0200
10759 @@ -51,5 +51,6 @@
10760  
10761  #define SO_PEERSEC             0x401d
10762  #define SO_PASSSEC             0x401e
10763 +#define SO_PEERTAG             0x401f
10764  
10765  #endif /* _ASM_SOCKET_H */
10766 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
10767 --- linux-2.6.22.10/include/asm-powerpc/socket.h        2007-07-09 13:19:44 +0200
10768 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/socket.h     2007-08-05 20:53:13 +0200
10769 @@ -59,4 +59,6 @@
10770  #define SO_TIMESTAMPNS         35
10771  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10772  
10773 +#define SO_PEERTAG             36
10774 +
10775  #endif /* _ASM_POWERPC_SOCKET_H */
10776 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
10777 --- linux-2.6.22.10/include/asm-powerpc/systbl.h        2007-07-09 13:19:44 +0200
10778 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/systbl.h     2007-08-05 20:53:13 +0200
10779 @@ -260,7 +260,7 @@ COMPAT_SYS_SPU(fstatfs64)
10780  SYSX(sys_ni_syscall, ppc_fadvise64_64, ppc_fadvise64_64)
10781  PPC_SYS_SPU(rtas)
10782  OLDSYS(debug_setcontext)
10783 -SYSCALL(ni_syscall)
10784 +SYSX(sys_vserver, sys32_vserver, sys_vserver)
10785  COMPAT_SYS(migrate_pages)
10786  COMPAT_SYS(mbind)
10787  COMPAT_SYS(get_mempolicy)
10788 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
10789 --- linux-2.6.22.10/include/asm-powerpc/unistd.h        2007-07-09 13:19:45 +0200
10790 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-powerpc/unistd.h     2007-08-05 20:53:13 +0200
10791 @@ -275,7 +275,7 @@
10792  #endif
10793  #define __NR_rtas              255
10794  #define __NR_sys_debug_setcontext 256
10795 -/* Number 257 is reserved for vserver */
10796 +#define __NR_vserver           257
10797  #define __NR_migrate_pages     258
10798  #define __NR_mbind             259
10799  #define __NR_get_mempolicy     260
10800 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
10801 --- linux-2.6.22.10/include/asm-s390/socket.h   2007-07-09 13:19:45 +0200
10802 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-s390/socket.h        2007-08-05 20:53:13 +0200
10803 @@ -60,4 +60,6 @@
10804  #define SO_TIMESTAMPNS         35
10805  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10806  
10807 +#define SO_PEERTAG             36
10808 +
10809  #endif /* _ASM_SOCKET_H */
10810 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
10811 --- linux-2.6.22.10/include/asm-s390/unistd.h   2007-07-09 13:19:45 +0200
10812 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-s390/unistd.h        2007-08-05 20:53:13 +0200
10813 @@ -202,7 +202,7 @@
10814  #define __NR_clock_gettime     (__NR_timer_create+6)
10815  #define __NR_clock_getres      (__NR_timer_create+7)
10816  #define __NR_clock_nanosleep   (__NR_timer_create+8)
10817 -/* Number 263 is reserved for vserver */
10818 +#define __NR_vserver           263
10819  #define __NR_statfs64          265
10820  #define __NR_fstatfs64         266
10821  #define __NR_remap_file_pages  267
10822 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
10823 --- linux-2.6.22.10/include/asm-sh/socket.h     2007-07-09 13:19:45 +0200
10824 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sh/socket.h  2007-08-05 20:53:13 +0200
10825 @@ -52,4 +52,6 @@
10826  #define SO_TIMESTAMPNS         35
10827  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10828  
10829 +#define SO_PEERTAG             36
10830 +
10831  #endif /* __ASM_SH_SOCKET_H */
10832 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
10833 --- linux-2.6.22.10/include/asm-sparc/socket.h  2007-07-09 13:19:54 +0200
10834 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc/socket.h       2007-08-05 20:53:13 +0200
10835 @@ -52,6 +52,8 @@
10836  #define SO_TIMESTAMPNS         0x0021
10837  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10838  
10839 +#define SO_PEERTAG             36
10840 +
10841  /* Security levels - as per NRL IPv6 - don't actually do anything */
10842  #define SO_SECURITY_AUTHENTICATION             0x5001
10843  #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
10844 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
10845 --- linux-2.6.22.10/include/asm-sparc/unistd.h  2007-07-09 13:19:54 +0200
10846 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc/unistd.h       2007-08-05 20:53:13 +0200
10847 @@ -283,7 +283,7 @@
10848  #define __NR_timer_getoverrun  264
10849  #define __NR_timer_delete      265
10850  #define __NR_timer_create      266
10851 -/* #define __NR_vserver                267 Reserved for VSERVER */
10852 +#define __NR_vserver           267
10853  #define __NR_io_setup          268
10854  #define __NR_io_destroy                269
10855  #define __NR_io_submit         270
10856 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
10857 --- linux-2.6.22.10/include/asm-sparc64/socket.h        2007-07-09 13:19:54 +0200
10858 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/socket.h     2007-08-05 20:53:13 +0200
10859 @@ -52,6 +52,8 @@
10860  #define SO_TIMESTAMPNS         0x0021
10861  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10862  
10863 +#define SO_PEERTAG             0x0022
10864 +
10865  /* Security levels - as per NRL IPv6 - don't actually do anything */
10866  #define SO_SECURITY_AUTHENTICATION             0x5001
10867  #define SO_SECURITY_ENCRYPTION_TRANSPORT       0x5002
10868 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
10869 --- linux-2.6.22.10/include/asm-sparc64/tlb.h   2007-07-09 13:19:54 +0200
10870 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/tlb.h        2007-08-05 20:53:13 +0200
10871 @@ -3,6 +3,7 @@
10872  
10873  #include <linux/swap.h>
10874  #include <linux/pagemap.h>
10875 +#include <linux/vs_memory.h>
10876  #include <asm/pgalloc.h>
10877  #include <asm/tlbflush.h>
10878  #include <asm/mmu_context.h>
10879 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
10880 --- linux-2.6.22.10/include/asm-sparc64/unistd.h        2007-07-09 13:19:54 +0200
10881 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-sparc64/unistd.h     2007-08-05 20:53:13 +0200
10882 @@ -285,7 +285,7 @@
10883  #define __NR_timer_getoverrun  264
10884  #define __NR_timer_delete      265
10885  #define __NR_timer_create      266
10886 -/* #define __NR_vserver                267 Reserved for VSERVER */
10887 +#define __NR_vserver           267
10888  #define __NR_io_setup          268
10889  #define __NR_io_destroy                269
10890  #define __NR_io_submit         270
10891 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
10892 --- linux-2.6.22.10/include/asm-v850/socket.h   2007-07-09 13:19:55 +0200
10893 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-v850/socket.h        2007-08-05 20:53:13 +0200
10894 @@ -52,4 +52,6 @@
10895  #define SO_TIMESTAMPNS         35
10896  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10897  
10898 +#define SO_PEERTAG             36
10899 +
10900  #endif /* __V850_SOCKET_H__ */
10901 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
10902 --- linux-2.6.22.10/include/asm-x86_64/socket.h 2007-07-09 13:19:55 +0200
10903 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-x86_64/socket.h      2007-08-05 20:53:13 +0200
10904 @@ -52,4 +52,6 @@
10905  #define SO_TIMESTAMPNS         35
10906  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10907  
10908 +#define SO_PEERTAG             36
10909 +
10910  #endif /* _ASM_SOCKET_H */
10911 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
10912 --- linux-2.6.22.10/include/asm-x86_64/unistd.h 2007-07-09 13:19:55 +0200
10913 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-x86_64/unistd.h      2007-08-05 20:53:13 +0200
10914 @@ -532,7 +532,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
10915  #define __NR_utimes            235
10916  __SYSCALL(__NR_utimes, sys_utimes)
10917  #define __NR_vserver           236
10918 -__SYSCALL(__NR_vserver, sys_ni_syscall)
10919 +__SYSCALL(__NR_vserver, sys_vserver)
10920  #define __NR_mbind             237
10921  __SYSCALL(__NR_mbind, sys_mbind)
10922  #define __NR_set_mempolicy     238
10923 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
10924 --- linux-2.6.22.10/include/asm-xtensa/socket.h 2007-07-09 13:19:55 +0200
10925 +++ linux-2.6.22.10-vs2.3.0.29/include/asm-xtensa/socket.h      2007-08-05 20:53:13 +0200
10926 @@ -63,4 +63,6 @@
10927  #define SO_TIMESTAMPNS         35
10928  #define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
10929  
10930 +#define SO_PEERTAG             36
10931 +
10932  #endif /* _XTENSA_SOCKET_H */
10933 diff -NurpP --minimal linux-2.6.22.10/include/linux/Kbuild linux-2.6.22.10-vs2.3.0.29/include/linux/Kbuild
10934 --- linux-2.6.22.10/include/linux/Kbuild        2007-10-30 01:57:14 +0100
10935 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/Kbuild     2007-09-30 14:58:01 +0200
10936 @@ -351,3 +351,6 @@ unifdef-y += xattr.h
10937  unifdef-y += xfrm.h
10938  
10939  objhdr-y += version.h
10940 +
10941 +header-y += vserver/
10942 +
10943 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
10944 --- linux-2.6.22.10/include/linux/capability.h  2007-07-09 13:19:55 +0200
10945 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/capability.h       2007-08-05 20:53:13 +0200
10946 @@ -237,6 +237,7 @@ typedef __u32 kernel_cap_t;
10947     arbitrary SCSI commands */
10948  /* Allow setting encryption key on loopback filesystem */
10949  /* Allow setting zone reclaim policy */
10950 +/* Allow the selection of a security context */
10951  
10952  #define CAP_SYS_ADMIN        21
10953  
10954 @@ -290,6 +291,11 @@ typedef __u32 kernel_cap_t;
10955  
10956  #define CAP_AUDIT_CONTROL    30
10957  
10958 +/* Allow context manipulations */
10959 +/* Allow changing context info on files */
10960 +
10961 +#define CAP_CONTEXT         31
10962 +
10963  #ifdef __KERNEL__
10964  /* 
10965   * Bounding set
10966 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
10967 --- linux-2.6.22.10/include/linux/devpts_fs.h   2004-08-14 12:55:59 +0200
10968 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/devpts_fs.h        2007-10-06 18:19:52 +0200
10969 @@ -30,5 +30,4 @@ static inline void devpts_pty_kill(int n
10970  
10971  #endif
10972  
10973 -
10974  #endif /* _LINUX_DEVPTS_FS_H */
10975 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
10976 --- linux-2.6.22.10/include/linux/ext2_fs.h     2006-11-30 21:19:37 +0100
10977 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/ext2_fs.h  2007-10-05 15:07:22 +0200
10978 @@ -188,6 +188,8 @@ struct ext2_group_desc
10979  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
10980  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
10981  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
10982 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
10983 +#define EXT2_IUNLINK_FL                        FS_IUNLINK_FL   /* Immutable unlink */
10984  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
10985  
10986  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
10987 @@ -244,7 +246,7 @@ struct ext2_inode {
10988                 struct {
10989                         __u8    l_i_frag;       /* Fragment number */
10990                         __u8    l_i_fsize;      /* Fragment size */
10991 -                       __u16   i_pad1;
10992 +                       __u16   l_i_tag;        /* Context Tag */
10993                         __le16  l_i_uid_high;   /* these 2 fields    */
10994                         __le16  l_i_gid_high;   /* were reserved2[0] */
10995                         __u32   l_i_reserved2;
10996 @@ -276,6 +278,7 @@ struct ext2_inode {
10997  #define i_gid_low      i_gid
10998  #define i_uid_high     osd2.linux2.l_i_uid_high
10999  #define i_gid_high     osd2.linux2.l_i_gid_high
11000 +#define i_raw_tag      osd2.linux2.l_i_tag
11001  #define i_reserved2    osd2.linux2.l_i_reserved2
11002  #endif
11003  
11004 @@ -317,8 +320,9 @@ struct ext2_inode {
11005  #define EXT2_MOUNT_XATTR_USER          0x004000  /* Extended user attributes */
11006  #define EXT2_MOUNT_POSIX_ACL           0x008000  /* POSIX Access Control Lists */
11007  #define EXT2_MOUNT_XIP                 0x010000  /* Execute in place */
11008 -#define EXT2_MOUNT_USRQUOTA            0x020000 /* user quota */
11009 -#define EXT2_MOUNT_GRPQUOTA            0x040000 /* group quota */
11010 +#define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
11011 +#define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
11012 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
11013  
11014  
11015  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
11016 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
11017 --- linux-2.6.22.10/include/linux/ext3_fs.h     2007-07-09 13:19:56 +0200
11018 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/ext3_fs.h  2007-08-05 20:53:13 +0200
11019 @@ -177,6 +177,8 @@ struct ext3_group_desc
11020  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
11021  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
11022  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
11023 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
11024 +#define EXT3_IUNLINK_FL                        0x08000000 /* Immutable unlink */
11025  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
11026  
11027  #define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
11028 @@ -296,7 +298,7 @@ struct ext3_inode {
11029                 struct {
11030                         __u8    l_i_frag;       /* Fragment number */
11031                         __u8    l_i_fsize;      /* Fragment size */
11032 -                       __u16   i_pad1;
11033 +                       __u16   l_i_tag;        /* Context Tag */
11034                         __le16  l_i_uid_high;   /* these 2 fields    */
11035                         __le16  l_i_gid_high;   /* were reserved2[0] */
11036                         __u32   l_i_reserved2;
11037 @@ -330,6 +332,7 @@ struct ext3_inode {
11038  #define i_gid_low      i_gid
11039  #define i_uid_high     osd2.linux2.l_i_uid_high
11040  #define i_gid_high     osd2.linux2.l_i_gid_high
11041 +#define i_raw_tag      osd2.linux2.l_i_tag
11042  #define i_reserved2    osd2.linux2.l_i_reserved2
11043  
11044  #elif defined(__GNU__)
11045 @@ -384,6 +387,7 @@ struct ext3_inode {
11046  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
11047  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
11048  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
11049 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
11050  
11051  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
11052  #ifndef _LINUX_EXT2_FS_H
11053 @@ -812,6 +816,7 @@ struct buffer_head * ext3_bread (handle_
11054  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
11055         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
11056         int create, int extend_disksize);
11057 +extern int ext3_sync_flags(struct inode *inode);
11058  
11059  extern void ext3_read_inode (struct inode *);
11060  extern int  ext3_write_inode (struct inode *, int);
11061 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
11062 --- linux-2.6.22.10/include/linux/ext4_fs.h     2007-07-09 13:19:56 +0200
11063 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/ext4_fs.h  2007-08-05 20:53:13 +0200
11064 @@ -189,8 +189,10 @@ struct ext4_group_desc
11065  #define EXT4_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
11066  #define EXT4_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
11067  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
11068 -#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
11069  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
11070 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
11071 +#define EXT4_IUNLINK_FL                        0x08000000 /* Immutable unlink */
11072 +#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
11073  
11074  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
11075  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
11076 @@ -312,7 +314,8 @@ struct ext4_inode {
11077                         __le16  l_i_file_acl_high;
11078                         __le16  l_i_uid_high;   /* these 2 fields */
11079                         __le16  l_i_gid_high;   /* were reserved2[0] */
11080 -                       __u32   l_i_reserved2;
11081 +                       __u16   l_i_tag;        /* Context Tag */
11082 +                       __u16   l_i_reserved2;
11083                 } linux2;
11084                 struct {
11085                         __u8    h_i_frag;       /* Fragment number */
11086 @@ -344,6 +347,7 @@ struct ext4_inode {
11087  #define i_gid_low      i_gid
11088  #define i_uid_high     osd2.linux2.l_i_uid_high
11089  #define i_gid_high     osd2.linux2.l_i_gid_high
11090 +#define i_raw_tag      osd2.linux2.l_i_tag
11091  #define i_reserved2    osd2.linux2.l_i_reserved2
11092  
11093  #elif defined(__GNU__)
11094 @@ -400,6 +404,7 @@ struct ext4_inode {
11095  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
11096  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
11097  #define EXT4_MOUNT_EXTENTS             0x400000 /* Extents support */
11098 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
11099  
11100  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
11101  #ifndef _LINUX_EXT2_FS_H
11102 @@ -850,6 +855,7 @@ struct buffer_head * ext4_bread (handle_
11103  int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
11104         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
11105         int create, int extend_disksize);
11106 +extern int ext4_sync_flags(struct inode *inode);
11107  
11108  extern void ext4_read_inode (struct inode *);
11109  extern int  ext4_write_inode (struct inode *, int);
11110 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
11111 --- linux-2.6.22.10/include/linux/fs.h  2007-07-09 13:19:56 +0200
11112 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/fs.h       2007-10-20 00:01:05 +0200
11113 @@ -123,6 +123,8 @@ extern int dir_notify_enable;
11114  #define MS_SLAVE       (1<<19) /* change to slave */
11115  #define MS_SHARED      (1<<20) /* change to shared */
11116  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
11117 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
11118 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11119  #define MS_ACTIVE      (1<<30)
11120  #define MS_NOUSER      (1<<31)
11121  
11122 @@ -149,6 +151,8 @@ extern int dir_notify_enable;
11123  #define S_NOCMTIME     128     /* Do not update file c/mtime */
11124  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
11125  #define S_PRIVATE      512     /* Inode is fs-internal */
11126 +#define S_BARRIER      1024    /* Barrier for chroot() */
11127 +#define S_IUNLINK      2048    /* Immutable unlink */
11128  
11129  /*
11130   * Note that nosuid etc flags are inode-specific: setting some file-system
11131 @@ -165,24 +169,36 @@ extern int dir_notify_enable;
11132   */
11133  #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
11134  
11135 -#define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
11136 +#define IS_RDONLY(inode)       __IS_FLG(inode, MS_RDONLY)
11137  #define IS_SYNC(inode)         (__IS_FLG(inode, MS_SYNCHRONOUS) || \
11138                                         ((inode)->i_flags & S_SYNC))
11139  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
11140                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
11141  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
11142 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
11143 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
11144 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
11145  
11146  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
11147  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
11148  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
11149 +#define IS_IUNLINK(inode)      ((inode)->i_flags & S_IUNLINK)
11150 +#define IS_IXORUNLINK(inode)   ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
11151  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
11152  
11153 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
11154  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
11155  #define IS_NOCMTIME(inode)     ((inode)->i_flags & S_NOCMTIME)
11156  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
11157  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
11158  
11159 +#ifdef CONFIG_VSERVER_COWBL
11160 +#  define IS_COW(inode)                (IS_IUNLINK(inode) && IS_IMMUTABLE(inode))
11161 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
11162 +#else
11163 +#  define IS_COW(inode)                (0)
11164 +#  define IS_COW_LINK(inode)   (0)
11165 +#endif
11166 +
11167  /* the read-only stuff doesn't really belong here, but any other place is
11168     probably as bad and I don't want to create yet another include file. */
11169  
11170 @@ -256,12 +272,13 @@ extern int dir_notify_enable;
11171  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
11172  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11173  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11174 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11175 +#define FS_IUNLINK_FL                  0x08000000 /* Immutable unlink */
11176  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11177  
11178  #define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11179  #define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11180  
11181 -
11182  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11183  #define SYNC_FILE_RANGE_WRITE          2
11184  #define SYNC_FILE_RANGE_WAIT_AFTER     4
11185 @@ -327,6 +344,7 @@ typedef void (dio_iodone_t)(struct kiocb
11186  #define ATTR_KILL_SUID 2048
11187  #define ATTR_KILL_SGID 4096
11188  #define ATTR_FILE      8192
11189 +#define ATTR_TAG       16384
11190  
11191  /*
11192   * This is the Inode Attributes structure, used for notify_change().  It
11193 @@ -342,6 +360,7 @@ struct iattr {
11194         umode_t         ia_mode;
11195         uid_t           ia_uid;
11196         gid_t           ia_gid;
11197 +       tag_t           ia_tag;
11198         loff_t          ia_size;
11199         struct timespec ia_atime;
11200         struct timespec ia_mtime;
11201 @@ -355,6 +374,9 @@ struct iattr {
11202         struct file     *ia_file;
11203  };
11204  
11205 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
11206 +#define ATTR_FLAG_IUNLINK      1024    /* Immutable unlink */
11207 +
11208  /*
11209   * Includes for diskquotas.
11210   */
11211 @@ -537,7 +559,9 @@ struct inode {
11212         unsigned int            i_nlink;
11213         uid_t                   i_uid;
11214         gid_t                   i_gid;
11215 +       tag_t                   i_tag;
11216         dev_t                   i_rdev;
11217 +       dev_t                   i_mdev;
11218         unsigned long           i_version;
11219         loff_t                  i_size;
11220  #ifdef __NEED_I_SIZE_ORDERED
11221 @@ -672,12 +696,12 @@ static inline void i_size_write(struct i
11222  
11223  static inline unsigned iminor(const struct inode *inode)
11224  {
11225 -       return MINOR(inode->i_rdev);
11226 +       return MINOR(inode->i_mdev);
11227  }
11228  
11229  static inline unsigned imajor(const struct inode *inode)
11230  {
11231 -       return MAJOR(inode->i_rdev);
11232 +       return MAJOR(inode->i_mdev);
11233  }
11234  
11235  extern struct block_device *I_BDEV(struct inode *inode);
11236 @@ -728,6 +752,7 @@ struct file {
11237         loff_t                  f_pos;
11238         struct fown_struct      f_owner;
11239         unsigned int            f_uid, f_gid;
11240 +       xid_t                   f_xid;
11241         struct file_ra_state    f_ra;
11242  
11243         unsigned long           f_version;
11244 @@ -811,6 +836,7 @@ struct file_lock {
11245         unsigned char fl_type;
11246         loff_t fl_start;
11247         loff_t fl_end;
11248 +       xid_t fl_xid;
11249  
11250         struct fasync_struct *  fl_fasync; /* for lease break notifications */
11251         unsigned long fl_break_time;    /* for nonblocking lease breaks */
11252 @@ -993,12 +1019,12 @@ extern void unlock_super(struct super_bl
11253   */
11254  extern int vfs_permission(struct nameidata *, int);
11255  extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
11256 -extern int vfs_mkdir(struct inode *, struct dentry *, int);
11257 -extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
11258 -extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
11259 -extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
11260 -extern int vfs_rmdir(struct inode *, struct dentry *);
11261 -extern int vfs_unlink(struct inode *, struct dentry *);
11262 +extern int vfs_mkdir(struct inode *, struct dentry *, int, struct nameidata *);
11263 +extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t, struct nameidata *);
11264 +extern int vfs_symlink(struct inode *, struct dentry *, const char *, int, struct nameidata *);
11265 +extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct nameidata *);
11266 +extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *);
11267 +extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *);
11268  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
11269  
11270  /*
11271 @@ -1138,6 +1164,7 @@ struct inode_operations {
11272         ssize_t (*listxattr) (struct dentry *, char *, size_t);
11273         int (*removexattr) (struct dentry *, const char *);
11274         void (*truncate_range)(struct inode *, loff_t, loff_t);
11275 +       int (*sync_flags) (struct inode *);
11276  };
11277  
11278  struct seq_file;
11279 @@ -1153,6 +1180,7 @@ extern ssize_t vfs_readv(struct file *, 
11280                 unsigned long, loff_t *);
11281  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
11282                 unsigned long, loff_t *);
11283 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
11284  
11285  /*
11286   * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
11287 @@ -1898,6 +1926,7 @@ extern int dcache_dir_open(struct inode 
11288  extern int dcache_dir_close(struct inode *, struct file *);
11289  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
11290  extern int dcache_readdir(struct file *, void *, filldir_t);
11291 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
11292  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
11293  extern int simple_statfs(struct dentry *, struct kstatfs *);
11294  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
11295 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
11296 --- linux-2.6.22.10/include/linux/init_task.h   2007-07-09 13:19:56 +0200
11297 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/init_task.h        2007-08-05 20:53:13 +0200
11298 @@ -169,6 +169,10 @@ extern struct group_info init_groups;
11299         },                                                              \
11300         INIT_TRACE_IRQFLAGS                                             \
11301         INIT_LOCKDEP                                                    \
11302 +       .xid            = 0,                                            \
11303 +       .vx_info        = NULL,                                         \
11304 +       .nid            = 0,                                            \
11305 +       .nx_info        = NULL,                                         \
11306  }
11307  
11308  
11309 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
11310 --- linux-2.6.22.10/include/linux/ipc.h 2007-07-09 13:19:56 +0200
11311 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/ipc.h      2007-08-05 20:53:13 +0200
11312 @@ -63,6 +63,7 @@ struct kern_ipc_perm
11313         key_t           key;
11314         uid_t           uid;
11315         gid_t           gid;
11316 +       xid_t           xid;
11317         uid_t           cuid;
11318         gid_t           cgid;
11319         mode_t          mode; 
11320 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
11321 --- linux-2.6.22.10/include/linux/jffs2.h       2006-11-30 21:19:38 +0100
11322 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/jffs2.h    2007-10-05 15:07:22 +0200
11323 @@ -82,12 +82,36 @@
11324  //#define JFFS2_NODETYPE_OPTIONS (JFFS2_FEATURE_RWCOMPAT_COPY | JFFS2_NODE_ACCURATE | 4)
11325  
11326  
11327 -#define JFFS2_INO_FLAG_PREREAD   1     /* Do read_inode() for this one at
11328 +#define JFFS2_INO_FLAG_PREREAD   0x01  /* Do read_inode() for this one at
11329                                            mount time, don't wait for it to
11330                                            happen later */
11331 -#define JFFS2_INO_FLAG_USERCOMPR  2    /* User has requested a specific
11332 +#define JFFS2_INO_FLAG_USERCOMPR 0x02  /* User has requested a specific
11333                                            compression type */
11334  
11335 +#define JFFS2_INO_FLAG_IMMUTABLE 0x10  /* immutable node */
11336 +#define JFFS2_INO_FLAG_IUNLINK   0x20  /* immutable unlink */
11337 +#define JFFS2_INO_FLAG_BARRIER   0x40  /* barrier */
11338 +
11339 +#define JFFS2_USER_VISIBLE       0x10
11340 +#define JFFS2_USER_MODIFIABLE    0x10
11341 +
11342 +/*
11343 + * Mount flags
11344 + */
11345 +#define JFFS2_MOUNT_TAGGED     (1<<24)   /* Enable Context Tags */
11346 +
11347 +#define clear_opt(o, opt)      o &= ~JFFS2_MOUNT_##opt
11348 +#define set_opt(o, opt)                o |= JFFS2_MOUNT_##opt
11349 +
11350 +/*
11351 + * Maximal mount counts between two filesystem checks
11352 + */
11353 +#define EXT2_DFL_MAX_MNT_COUNT         20      /* Allow 20 mounts */
11354 +#define EXT2_DFL_CHECKINTERVAL         0       /* Don't use interval check */
11355 +
11356 +/*
11357 + * Behaviour when detecting errors
11358 + */
11359  
11360  /* These can go once we've made sure we've caught all uses without
11361     byteswapping */
11362 @@ -97,7 +121,7 @@ typedef struct {
11363  } __attribute__((packed)) jint32_t;
11364  
11365  typedef struct {
11366 -       uint32_t m;
11367 +       uint16_t m;
11368  } __attribute__((packed)) jmode_t;
11369  
11370  typedef struct {
11371 @@ -145,7 +169,8 @@ struct jffs2_raw_inode
11372         jint32_t hdr_crc;
11373         jint32_t ino;        /* Inode number.  */
11374         jint32_t version;    /* Version number.  */
11375 -       jmode_t mode;       /* The file's type or mode.  */
11376 +       jmode_t mode;        /* The file's type or mode.  */
11377 +       jint16_t tag;        /* context tagging */
11378         jint16_t uid;        /* The file's owner.  */
11379         jint16_t gid;        /* The file's group.  */
11380         jint32_t isize;      /* Total resultant size of this inode (used for truncations)  */
11381 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
11382 --- linux-2.6.22.10/include/linux/loop.h        2007-07-09 13:19:56 +0200
11383 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/loop.h     2007-08-05 20:53:13 +0200
11384 @@ -45,6 +45,7 @@ struct loop_device {
11385         struct loop_func_table *lo_encryption;
11386         __u32           lo_init[2];
11387         uid_t           lo_key_owner;   /* Who set the key */
11388 +       xid_t           lo_xid;
11389         int             (*ioctl)(struct loop_device *, int cmd, 
11390                                  unsigned long arg); 
11391  
11392 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
11393 --- linux-2.6.22.10/include/linux/magic.h       2007-07-09 13:19:56 +0200
11394 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/magic.h    2007-10-06 18:19:33 +0200
11395 @@ -3,7 +3,7 @@
11396  
11397  #define ADFS_SUPER_MAGIC       0xadf5
11398  #define AFFS_SUPER_MAGIC       0xadff
11399 -#define AFS_SUPER_MAGIC                0x5346414F
11400 +#define AFS_SUPER_MAGIC                0x5346414F
11401  #define AUTOFS_SUPER_MAGIC     0x0187
11402  #define CODA_SUPER_MAGIC       0x73757245
11403  #define EFS_SUPER_MAGIC                0x414A53
11404 @@ -27,6 +27,7 @@
11405  #define NFS_SUPER_MAGIC                0x6969
11406  #define OPENPROM_SUPER_MAGIC   0x9fa1
11407  #define PROC_SUPER_MAGIC       0x9fa0
11408 +#define DEVPTS_SUPER_MAGIC     0x1cd1
11409  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
11410  
11411  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
11412 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
11413 --- linux-2.6.22.10/include/linux/major.h       2007-07-09 13:19:56 +0200
11414 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/major.h    2007-08-05 20:53:13 +0200
11415 @@ -15,6 +15,7 @@
11416  #define HD_MAJOR               IDE0_MAJOR
11417  #define PTY_SLAVE_MAJOR                3
11418  #define TTY_MAJOR              4
11419 +#define VROOT_MAJOR            4
11420  #define TTYAUX_MAJOR           5
11421  #define LP_MAJOR               6
11422  #define VCS_MAJOR              7
11423 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
11424 --- linux-2.6.22.10/include/linux/mount.h       2007-07-09 13:19:56 +0200
11425 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/mount.h    2007-09-05 02:29:04 +0200
11426 @@ -28,6 +28,9 @@ struct mnt_namespace;
11427  #define MNT_NOATIME    0x08
11428  #define MNT_NODIRATIME 0x10
11429  #define MNT_RELATIME   0x20
11430 +#define MNT_RDONLY     0x40
11431 +
11432 +#define MNT_IS_RDONLY(m)       ((m) && ((m)->mnt_flags & MNT_RDONLY))
11433  
11434  #define MNT_SHRINKABLE 0x100
11435  
11436 @@ -35,6 +38,10 @@ struct mnt_namespace;
11437  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
11438  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
11439  
11440 +#define MNT_TAGID      0x10000
11441 +#define MNT_NOTAG      0x20000
11442 +#define MNT_NOTAGCHECK 0x40000
11443 +
11444  struct vfsmount {
11445         struct list_head mnt_hash;
11446         struct vfsmount *mnt_parent;    /* fs we are mounted on */
11447 @@ -61,6 +68,7 @@ struct vfsmount {
11448         atomic_t mnt_count;
11449         int mnt_expiry_mark;            /* true if marked for expiry */
11450         int mnt_pinned;
11451 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
11452  };
11453  
11454  static inline struct vfsmount *mntget(struct vfsmount *mnt)
11455 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
11456 --- linux-2.6.22.10/include/linux/net.h 2007-07-09 13:19:56 +0200
11457 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/net.h      2007-08-05 20:53:13 +0200
11458 @@ -63,6 +63,7 @@ typedef enum {
11459  #define SOCK_NOSPACE           2
11460  #define SOCK_PASSCRED          3
11461  #define SOCK_PASSSEC           4
11462 +#define SOCK_USER_SOCKET       5
11463  
11464  #ifndef ARCH_HAS_SOCKET_TYPES
11465  /**
11466 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
11467 --- linux-2.6.22.10/include/linux/nfs_mount.h   2007-07-09 13:20:00 +0200
11468 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/nfs_mount.h        2007-08-05 20:53:13 +0200
11469 @@ -62,6 +62,7 @@ struct nfs_mount_data {
11470  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
11471  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11472  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11473 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11474 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11475 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11476  
11477  #endif
11478 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
11479 --- linux-2.6.22.10/include/linux/nsproxy.h     2007-07-09 13:20:00 +0200
11480 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/nsproxy.h  2007-08-05 20:53:13 +0200
11481 @@ -3,6 +3,7 @@
11482  
11483  #include <linux/spinlock.h>
11484  #include <linux/sched.h>
11485 +#include <linux/vserver/debug.h>
11486  
11487  struct mnt_namespace;
11488  struct uts_namespace;
11489 @@ -32,26 +33,46 @@ struct nsproxy {
11490  extern struct nsproxy init_nsproxy;
11491  
11492  int copy_namespaces(int flags, struct task_struct *tsk);
11493 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
11494  void get_task_namespaces(struct task_struct *tsk);
11495  void free_nsproxy(struct nsproxy *ns);
11496  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
11497         struct fs_struct *);
11498  
11499 -static inline void put_nsproxy(struct nsproxy *ns)
11500 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
11501 +
11502 +static inline void __get_nsproxy(struct nsproxy *ns,
11503 +       const char *_file, int _line)
11504  {
11505 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
11506 +               ns, atomic_read(&ns->count), _file, _line);
11507 +       atomic_inc(&ns->count);
11508 +}
11509 +
11510 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
11511 +
11512 +static inline void __put_nsproxy(struct nsproxy *ns,
11513 +       const char *_file, int _line)
11514 +{
11515 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
11516 +               ns, atomic_read(&ns->count), _file, _line);
11517         if (atomic_dec_and_test(&ns->count)) {
11518                 free_nsproxy(ns);
11519         }
11520  }
11521  
11522 -static inline void exit_task_namespaces(struct task_struct *p)
11523 +#define        exit_task_namespaces(p) __exit_task_namespaces(p, __FILE__, __LINE__)
11524 +
11525 +static inline void __exit_task_namespaces(struct task_struct *p,
11526 +       const char *_file, int _line)
11527  {
11528         struct nsproxy *ns = p->nsproxy;
11529         if (ns) {
11530                 task_lock(p);
11531                 p->nsproxy = NULL;
11532                 task_unlock(p);
11533 -               put_nsproxy(ns);
11534 +               __put_nsproxy(ns, _file, _line);
11535         }
11536  }
11537 +
11538  #endif
11539 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
11540 --- linux-2.6.22.10/include/linux/pid.h 2007-07-09 13:20:00 +0200
11541 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/pid.h      2007-08-05 20:53:13 +0200
11542 @@ -8,7 +8,8 @@ enum pid_type
11543         PIDTYPE_PID,
11544         PIDTYPE_PGID,
11545         PIDTYPE_SID,
11546 -       PIDTYPE_MAX
11547 +       PIDTYPE_MAX,
11548 +       PIDTYPE_REALPID
11549  };
11550  
11551  /*
11552 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
11553 --- linux-2.6.22.10/include/linux/proc_fs.h     2007-07-09 13:20:00 +0200
11554 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/proc_fs.h  2007-08-05 20:53:13 +0200
11555 @@ -54,6 +54,7 @@ struct proc_dir_entry {
11556         nlink_t nlink;
11557         uid_t uid;
11558         gid_t gid;
11559 +       int vx_flags;
11560         loff_t size;
11561         const struct inode_operations *proc_iops;
11562         const struct file_operations *proc_fops;
11563 @@ -246,13 +247,20 @@ static inline void kclist_add(struct kco
11564  extern void kclist_add(struct kcore_list *, void *, size_t);
11565  #endif
11566  
11567 +struct vx_info;
11568 +struct nx_info;
11569 +
11570  union proc_op {
11571         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
11572         int (*proc_read)(struct task_struct *task, char *page);
11573 +       int (*proc_vs_read)(char *page);
11574 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
11575 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
11576  };
11577  
11578  struct proc_inode {
11579         struct pid *pid;
11580 +       int vx_flags;
11581         int fd;
11582         union proc_op op;
11583         struct proc_dir_entry *pde;
11584 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
11585 --- linux-2.6.22.10/include/linux/reiserfs_fs.h 2007-05-02 19:25:34 +0200
11586 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/reiserfs_fs.h      2007-08-05 20:53:13 +0200
11587 @@ -821,6 +821,10 @@ struct stat_data_v1 {
11588  #define REISERFS_COMPR_FL     FS_COMPR_FL
11589  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
11590  
11591 +/* unfortunately reiserfs sdattr is only 16 bit */
11592 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
11593 +#define REISERFS_IUNLINK_FL   (FS_IUNLINK_FL >> 16)
11594 +
11595  /* persistent flags that file inherits from the parent directory */
11596  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
11597                                 REISERFS_SYNC_FL |      \
11598 @@ -830,6 +834,9 @@ struct stat_data_v1 {
11599                                 REISERFS_COMPR_FL |     \
11600                                 REISERFS_NOTAIL_FL )
11601  
11602 +#define REISERFS_FL_USER_VISIBLE       0x80FF
11603 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
11604 +
11605  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
11606     address blocks) */
11607  struct stat_data {
11608 @@ -1901,6 +1908,7 @@ static inline void reiserfs_update_sd(st
11609  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
11610  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
11611  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
11612 +int reiserfs_sync_flags(struct inode *inode);
11613  
11614  /* namei.c */
11615  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
11616 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
11617 --- linux-2.6.22.10/include/linux/reiserfs_fs_sb.h      2007-07-09 13:20:00 +0200
11618 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/reiserfs_fs_sb.h   2007-08-05 20:53:13 +0200
11619 @@ -458,6 +458,7 @@ enum reiserfs_mount_options {
11620         REISERFS_POSIXACL,
11621         REISERFS_BARRIER_NONE,
11622         REISERFS_BARRIER_FLUSH,
11623 +       REISERFS_TAGGED,
11624  
11625         /* Actions on error */
11626         REISERFS_ERROR_PANIC,
11627 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
11628 --- linux-2.6.22.10/include/linux/sched.h       2007-07-09 13:20:01 +0200
11629 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sched.h    2007-10-04 23:47:06 +0200
11630 @@ -26,6 +26,7 @@
11631  #define CLONE_STOPPED          0x02000000      /* Start in stopped state */
11632  #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
11633  #define CLONE_NEWIPC           0x08000000      /* New ipcs */
11634 +#define CLONE_KTHREAD          0x10000000      /* clone a kernel thread */
11635  
11636  /*
11637   * Scheduling policies
11638 @@ -94,7 +95,7 @@ struct bio;
11639   * List of flags we want to share for kernel threads,
11640   * if only because they are not used by them anyway.
11641   */
11642 -#define CLONE_KERNEL   (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
11643 +#define CLONE_KERNEL   (CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_KTHREAD)
11644  
11645  /*
11646   * These are the constant used to fake the fixed-point load-average
11647 @@ -146,12 +147,13 @@ extern unsigned long weighted_cpuload(co
11648  #define TASK_UNINTERRUPTIBLE   2
11649  #define TASK_STOPPED           4
11650  #define TASK_TRACED            8
11651 +#define TASK_ONHOLD            16
11652  /* in tsk->exit_state */
11653 -#define EXIT_ZOMBIE            16
11654 -#define EXIT_DEAD              32
11655 +#define EXIT_ZOMBIE            32
11656 +#define EXIT_DEAD              64
11657  /* in tsk->state again */
11658 -#define TASK_NONINTERACTIVE    64
11659 -#define TASK_DEAD              128
11660 +#define TASK_NONINTERACTIVE    128
11661 +#define TASK_DEAD              256
11662  
11663  #define __set_task_state(tsk, state_value)             \
11664         do { (tsk)->state = (state_value); } while (0)
11665 @@ -287,27 +289,30 @@ extern void arch_unmap_area_topdown(stru
11666   * The mm counters are not protected by its page_table_lock,
11667   * so must be incremented atomically.
11668   */
11669 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
11670 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
11671 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
11672 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
11673 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
11674  typedef atomic_long_t mm_counter_t;
11675 +#define __set_mm_counter(mm, member, value) \
11676 +       atomic_long_set(&(mm)->_##member, value)
11677 +#define get_mm_counter(mm, member) \
11678 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
11679  
11680  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11681  /*
11682   * The mm counters are protected by its page_table_lock,
11683   * so can be incremented directly.
11684   */
11685 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
11686 -#define get_mm_counter(mm, member) ((mm)->_##member)
11687 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
11688 -#define inc_mm_counter(mm, member) (mm)->_##member++
11689 -#define dec_mm_counter(mm, member) (mm)->_##member--
11690  typedef unsigned long mm_counter_t;
11691 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
11692 +#define get_mm_counter(mm, member) ((mm)->_##member)
11693  
11694  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11695  
11696 +#define set_mm_counter(mm, member, value) \
11697 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
11698 +#define add_mm_counter(mm, member, value) \
11699 +       vx_ ## member ## pages_add((mm), (value))
11700 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
11701 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
11702 +
11703  #define get_mm_rss(mm)                                 \
11704         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
11705  #define update_hiwater_rss(mm) do {                    \
11706 @@ -365,6 +370,7 @@ struct mm_struct {
11707  
11708         /* Architecture-specific MM context */
11709         mm_context_t context;
11710 +       struct vx_info *mm_vx_info;
11711  
11712         /* Swap token stuff */
11713         /*
11714 @@ -570,9 +576,10 @@ struct user_struct {
11715         /* Hash table maintenance information */
11716         struct list_head uidhash_list;
11717         uid_t uid;
11718 +       xid_t xid;
11719  };
11720  
11721 -extern struct user_struct *find_user(uid_t);
11722 +extern struct user_struct *find_user(xid_t, uid_t);
11723  
11724  extern struct user_struct root_user;
11725  #define INIT_USER (&root_user)
11726 @@ -969,6 +976,15 @@ struct task_struct {
11727         
11728         void *security;
11729         struct audit_context *audit_context;
11730 +
11731 +/* vserver context data */
11732 +       struct vx_info *vx_info;
11733 +       struct nx_info *nx_info;
11734 +
11735 +       xid_t xid;
11736 +       nid_t nid;
11737 +       tag_t tag;
11738 +
11739         seccomp_t seccomp;
11740  
11741  /* Thread group tracking */
11742 @@ -1290,12 +1306,16 @@ extern struct task_struct init_task;
11743  
11744  extern struct   mm_struct init_mm;
11745  
11746 -#define find_task_by_pid(nr)   find_task_by_pid_type(PIDTYPE_PID, nr)
11747 +#define find_task_by_real_pid(nr) \
11748 +       find_task_by_pid_type(PIDTYPE_REALPID, nr)
11749 +#define find_task_by_pid(nr) \
11750 +       find_task_by_pid_type(PIDTYPE_PID, nr)
11751 +
11752  extern struct task_struct *find_task_by_pid_type(int type, int pid);
11753  extern void __set_special_pids(pid_t session, pid_t pgrp);
11754  
11755  /* per-UID process charging. */
11756 -extern struct user_struct * alloc_uid(uid_t);
11757 +extern struct user_struct * alloc_uid(xid_t, uid_t);
11758  static inline struct user_struct *get_uid(struct user_struct *u)
11759  {
11760         atomic_inc(&u->__count);
11761 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
11762 --- linux-2.6.22.10/include/linux/shmem_fs.h    2006-11-30 21:19:39 +0100
11763 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/shmem_fs.h 2007-08-05 20:53:13 +0200
11764 @@ -8,6 +8,9 @@
11765  
11766  #define SHMEM_NR_DIRECT 16
11767  
11768 +#define TMPFS_SUPER_MAGIC      0x01021994
11769 +
11770 +
11771  struct shmem_inode_info {
11772         spinlock_t              lock;
11773         unsigned long           flags;
11774 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
11775 --- linux-2.6.22.10/include/linux/stat.h        2007-07-09 13:20:01 +0200
11776 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/stat.h     2007-08-05 20:53:13 +0200
11777 @@ -66,6 +66,7 @@ struct kstat {
11778         unsigned int    nlink;
11779         uid_t           uid;
11780         gid_t           gid;
11781 +       tag_t           tag;
11782         dev_t           rdev;
11783         loff_t          size;
11784         struct timespec  atime;
11785 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
11786 --- linux-2.6.22.10/include/linux/sunrpc/auth.h 2006-11-30 21:19:40 +0100
11787 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sunrpc/auth.h      2007-08-05 20:53:13 +0200
11788 @@ -24,6 +24,7 @@
11789  struct auth_cred {
11790         uid_t   uid;
11791         gid_t   gid;
11792 +       tag_t   tag;
11793         struct group_info *group_info;
11794  };
11795  
11796 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
11797 --- linux-2.6.22.10/include/linux/sunrpc/clnt.h 2007-07-09 13:20:01 +0200
11798 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sunrpc/clnt.h      2007-08-05 20:53:13 +0200
11799 @@ -43,7 +43,8 @@ struct rpc_clnt {
11800         unsigned int            cl_softrtry : 1,/* soft timeouts */
11801                                 cl_intr     : 1,/* interruptible */
11802                                 cl_discrtry : 1,/* disconnect before retry */
11803 -                               cl_autobind : 1;/* use getport() */
11804 +                               cl_autobind : 1,/* use getport() */
11805 +                               cl_tag      : 1;/* context tagging */
11806  
11807         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
11808  
11809 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
11810 --- linux-2.6.22.10/include/linux/syscalls.h    2007-07-09 13:20:01 +0200
11811 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/syscalls.h 2007-08-05 20:53:13 +0200
11812 @@ -294,6 +294,8 @@ asmlinkage long sys_symlink(const char _
11813  asmlinkage long sys_unlink(const char __user *pathname);
11814  asmlinkage long sys_rename(const char __user *oldname,
11815                                 const char __user *newname);
11816 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
11817 +                               umode_t mode);
11818  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
11819  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
11820  
11821 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
11822 --- linux-2.6.22.10/include/linux/sysctl.h      2007-07-09 13:20:01 +0200
11823 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sysctl.h   2007-08-05 20:53:13 +0200
11824 @@ -106,6 +106,7 @@ enum
11825         KERN_CAP_BSET=14,       /* int: capability bounding set */
11826         KERN_PANIC=15,          /* int: panic timeout */
11827         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11828 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11829  
11830         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11831         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11832 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
11833 --- linux-2.6.22.10/include/linux/sysfs.h       2007-07-09 13:20:01 +0200
11834 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sysfs.h    2007-08-05 20:53:13 +0200
11835 @@ -15,6 +15,8 @@
11836  #include <linux/list.h>
11837  #include <asm/atomic.h>
11838  
11839 +#define SYSFS_SUPER_MAGIC      0x62656572
11840 +
11841  struct kobject;
11842  struct module;
11843  struct nameidata;
11844 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
11845 --- linux-2.6.22.10/include/linux/time.h        2007-07-09 13:20:01 +0200
11846 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/time.h     2007-08-05 20:53:13 +0200
11847 @@ -176,6 +176,9 @@ static inline void timespec_add_ns(struc
11848         }
11849         a->tv_nsec = ns;
11850  }
11851 +
11852 +#include <linux/vs_time.h>
11853 +
11854  #endif /* __KERNEL__ */
11855  
11856  #define NFDBITS                        __NFDBITS
11857 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
11858 --- linux-2.6.22.10/include/linux/types.h       2007-02-06 03:01:52 +0100
11859 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/types.h    2007-08-05 20:53:13 +0200
11860 @@ -39,6 +39,9 @@ typedef __kernel_uid32_t      uid_t;
11861  typedef __kernel_gid32_t       gid_t;
11862  typedef __kernel_uid16_t        uid16_t;
11863  typedef __kernel_gid16_t        gid16_t;
11864 +typedef unsigned int           xid_t;
11865 +typedef unsigned int           nid_t;
11866 +typedef unsigned int           tag_t;
11867  
11868  #ifdef CONFIG_UID16
11869  /* This is defined by include/asm-{arch}/posix_types.h */
11870 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
11871 --- linux-2.6.22.10/include/linux/vroot.h       1970-01-01 01:00:00 +0100
11872 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vroot.h    2007-08-05 20:53:13 +0200
11873 @@ -0,0 +1,51 @@
11874 +
11875 +/*
11876 + * include/linux/vroot.h
11877 + *
11878 + * written by Herbert Pötzl, 9/11/2002
11879 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
11880 + *
11881 + * Copyright (C) 2002-2007 by Herbert Pötzl.
11882 + * Redistribution of this file is permitted under the
11883 + * GNU General Public License.
11884 + */
11885 +
11886 +#ifndef _LINUX_VROOT_H
11887 +#define _LINUX_VROOT_H
11888 +
11889 +
11890 +#ifdef __KERNEL__
11891 +
11892 +/* Possible states of device */
11893 +enum {
11894 +       Vr_unbound,
11895 +       Vr_bound,
11896 +};
11897 +
11898 +struct vroot_device {
11899 +       int             vr_number;
11900 +       int             vr_refcnt;
11901 +
11902 +       struct semaphore        vr_ctl_mutex;
11903 +       struct block_device    *vr_device;
11904 +       int                     vr_state;
11905 +};
11906 +
11907 +
11908 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
11909 +
11910 +extern int register_vroot_grb(vroot_grb_func *);
11911 +extern int unregister_vroot_grb(vroot_grb_func *);
11912 +
11913 +#endif /* __KERNEL__ */
11914 +
11915 +#define MAX_VROOT_DEFAULT      8
11916 +
11917 +/*
11918 + * IOCTL commands --- we will commandeer 0x56 ('V')
11919 + */
11920 +
11921 +#define VROOT_SET_DEV          0x5600
11922 +#define VROOT_CLR_DEV          0x5601
11923 +
11924 +#endif /* _LINUX_VROOT_H */
11925 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
11926 --- linux-2.6.22.10/include/linux/vs_base.h     1970-01-01 01:00:00 +0100
11927 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_base.h  2007-08-05 20:53:13 +0200
11928 @@ -0,0 +1,9 @@
11929 +#ifndef _VS_BASE_H
11930 +#define _VS_BASE_H
11931 +
11932 +#include "vserver/base.h"
11933 +#include "vserver/debug.h"
11934 +
11935 +#else
11936 +#warning duplicate inclusion
11937 +#endif
11938 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
11939 --- linux-2.6.22.10/include/linux/vs_context.h  1970-01-01 01:00:00 +0100
11940 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_context.h       2007-10-01 14:57:41 +0200
11941 @@ -0,0 +1,224 @@
11942 +#ifndef _VS_CONTEXT_H
11943 +#define _VS_CONTEXT_H
11944 +
11945 +#include "vserver/base.h"
11946 +#include "vserver/context.h"
11947 +#include "vserver/history.h"
11948 +#include "vserver/debug.h"
11949 +
11950 +
11951 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
11952 +
11953 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
11954 +       const char *_file, int _line, void *_here)
11955 +{
11956 +       if (!vxi)
11957 +               return NULL;
11958 +
11959 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
11960 +               vxi, vxi ? vxi->vx_id : 0,
11961 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11962 +               _file, _line);
11963 +       __vxh_get_vx_info(vxi, _here);
11964 +
11965 +       atomic_inc(&vxi->vx_usecnt);
11966 +       return vxi;
11967 +}
11968 +
11969 +
11970 +extern void free_vx_info(struct vx_info *);
11971 +
11972 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
11973 +
11974 +static inline void __put_vx_info(struct vx_info *vxi,
11975 +       const char *_file, int _line, void *_here)
11976 +{
11977 +       if (!vxi)
11978 +               return;
11979 +
11980 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
11981 +               vxi, vxi ? vxi->vx_id : 0,
11982 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11983 +               _file, _line);
11984 +       __vxh_put_vx_info(vxi, _here);
11985 +
11986 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
11987 +               free_vx_info(vxi);
11988 +}
11989 +
11990 +
11991 +#define init_vx_info(p, i) \
11992 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11993 +
11994 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11995 +       const char *_file, int _line, void *_here)
11996 +{
11997 +       if (vxi) {
11998 +               vxlprintk(VXD_CBIT(xid, 3),
11999 +                       "init_vx_info(%p[#%d.%d])",
12000 +                       vxi, vxi ? vxi->vx_id : 0,
12001 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12002 +                       _file, _line);
12003 +               __vxh_init_vx_info(vxi, vxp, _here);
12004 +
12005 +               atomic_inc(&vxi->vx_usecnt);
12006 +       }
12007 +       *vxp = vxi;
12008 +}
12009 +
12010 +
12011 +#define set_vx_info(p, i) \
12012 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
12013 +
12014 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
12015 +       const char *_file, int _line, void *_here)
12016 +{
12017 +       struct vx_info *vxo;
12018 +
12019 +       if (!vxi)
12020 +               return;
12021 +
12022 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
12023 +               vxi, vxi ? vxi->vx_id : 0,
12024 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12025 +               _file, _line);
12026 +       __vxh_set_vx_info(vxi, vxp, _here);
12027 +
12028 +       atomic_inc(&vxi->vx_usecnt);
12029 +       vxo = xchg(vxp, vxi);
12030 +       BUG_ON(vxo);
12031 +}
12032 +
12033 +
12034 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
12035 +
12036 +static inline void __clr_vx_info(struct vx_info **vxp,
12037 +       const char *_file, int _line, void *_here)
12038 +{
12039 +       struct vx_info *vxo;
12040 +
12041 +       vxo = xchg(vxp, NULL);
12042 +       if (!vxo)
12043 +               return;
12044 +
12045 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
12046 +               vxo, vxo ? vxo->vx_id : 0,
12047 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
12048 +               _file, _line);
12049 +       __vxh_clr_vx_info(vxo, vxp, _here);
12050 +
12051 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
12052 +               free_vx_info(vxo);
12053 +}
12054 +
12055 +
12056 +#define claim_vx_info(v, p) \
12057 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12058 +
12059 +static inline void __claim_vx_info(struct vx_info *vxi,
12060 +       struct task_struct *task,
12061 +       const char *_file, int _line, void *_here)
12062 +{
12063 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
12064 +               vxi, vxi ? vxi->vx_id : 0,
12065 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12066 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12067 +               task, _file, _line);
12068 +       __vxh_claim_vx_info(vxi, task, _here);
12069 +
12070 +       atomic_inc(&vxi->vx_tasks);
12071 +}
12072 +
12073 +
12074 +extern void unhash_vx_info(struct vx_info *);
12075 +
12076 +#define release_vx_info(v, p) \
12077 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12078 +
12079 +static inline void __release_vx_info(struct vx_info *vxi,
12080 +       struct task_struct *task,
12081 +       const char *_file, int _line, void *_here)
12082 +{
12083 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
12084 +               vxi, vxi ? vxi->vx_id : 0,
12085 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12086 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12087 +               task, _file, _line);
12088 +       __vxh_release_vx_info(vxi, task, _here);
12089 +
12090 +       might_sleep();
12091 +
12092 +       if (atomic_dec_and_test(&vxi->vx_tasks))
12093 +               unhash_vx_info(vxi);
12094 +}
12095 +
12096 +
12097 +#define task_get_vx_info(p) \
12098 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
12099 +
12100 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
12101 +       const char *_file, int _line, void *_here)
12102 +{
12103 +       struct vx_info *vxi;
12104 +
12105 +       task_lock(p);
12106 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
12107 +               p, _file, _line);
12108 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
12109 +       task_unlock(p);
12110 +       return vxi;
12111 +}
12112 +
12113 +
12114 +static inline void __wakeup_vx_info(struct vx_info *vxi)
12115 +{
12116 +       if (waitqueue_active(&vxi->vx_wait))
12117 +               wake_up_interruptible(&vxi->vx_wait);
12118 +}
12119 +
12120 +
12121 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
12122 +
12123 +static inline void __enter_vx_info(struct vx_info *vxi,
12124 +       struct vx_info_save *vxis, const char *_file, int _line)
12125 +{
12126 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
12127 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
12128 +               current->xid, current->vx_info, _file, _line);
12129 +       vxis->vxi = xchg(&current->vx_info, vxi);
12130 +       vxis->xid = current->xid;
12131 +       current->xid = vxi ? vxi->vx_id : 0;
12132 +}
12133 +
12134 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
12135 +
12136 +static inline void __leave_vx_info(struct vx_info_save *vxis,
12137 +       const char *_file, int _line)
12138 +{
12139 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
12140 +               vxis, vxis->xid, vxis->vxi, current,
12141 +               current->xid, current->vx_info, _file, _line);
12142 +       (void)xchg(&current->vx_info, vxis->vxi);
12143 +       current->xid = vxis->xid;
12144 +}
12145 +
12146 +
12147 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
12148 +{
12149 +       vxis->vxi = xchg(&current->vx_info, NULL);
12150 +       vxis->xid = xchg(&current->xid, (xid_t)0);
12151 +}
12152 +
12153 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
12154 +{
12155 +       (void)xchg(&current->xid, vxis->xid);
12156 +       (void)xchg(&current->vx_info, vxis->vxi);
12157 +}
12158 +
12159 +extern void exit_vx_info(struct task_struct *, int);
12160 +extern void exit_vx_info_early(struct task_struct *, int);
12161 +
12162 +
12163 +#else
12164 +#warning duplicate inclusion
12165 +#endif
12166 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
12167 --- linux-2.6.22.10/include/linux/vs_cowbl.h    1970-01-01 01:00:00 +0100
12168 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_cowbl.h 2007-08-05 20:53:13 +0200
12169 @@ -0,0 +1,44 @@
12170 +#ifndef _VS_COWBL_H
12171 +#define _VS_COWBL_H
12172 +
12173 +#include <linux/fs.h>
12174 +#include <linux/dcache.h>
12175 +#include <linux/namei.h>
12176 +
12177 +extern struct dentry *cow_break_link(const char *pathname);
12178 +
12179 +static inline int cow_check_and_break(struct nameidata *nd)
12180 +{
12181 +       struct inode *inode = nd->dentry->d_inode;
12182 +       int error = 0;
12183 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
12184 +               return -EROFS;
12185 +       if (IS_COW(inode)) {
12186 +               if (IS_COW_LINK(inode)) {
12187 +                       struct dentry *new_dentry, *old_dentry = nd->dentry;
12188 +                       char *path, *buf;
12189 +
12190 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
12191 +                       if (!buf) {
12192 +                               return -ENOMEM;
12193 +                       }
12194 +                       path = d_path(nd->dentry, nd->mnt, buf, PATH_MAX);
12195 +                       new_dentry = cow_break_link(path);
12196 +                       kfree(buf);
12197 +                       if (!IS_ERR(new_dentry)) {
12198 +                               nd->dentry = new_dentry;
12199 +                               dput(old_dentry);
12200 +                       } else
12201 +                               error = PTR_ERR(new_dentry);
12202 +               } else {
12203 +                       inode->i_flags &= ~(S_IUNLINK | S_IMMUTABLE);
12204 +                       inode->i_ctime = CURRENT_TIME;
12205 +                       mark_inode_dirty(inode);
12206 +               }
12207 +       }
12208 +       return error;
12209 +}
12210 +
12211 +#else
12212 +#warning duplicate inclusion
12213 +#endif
12214 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
12215 --- linux-2.6.22.10/include/linux/vs_cvirt.h    1970-01-01 01:00:00 +0100
12216 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_cvirt.h 2007-08-05 20:53:13 +0200
12217 @@ -0,0 +1,49 @@
12218 +#ifndef _VS_CVIRT_H
12219 +#define _VS_CVIRT_H
12220 +
12221 +#include "vserver/cvirt.h"
12222 +#include "vserver/context.h"
12223 +#include "vserver/base.h"
12224 +#include "vserver/debug.h"
12225 +
12226 +
12227 +static inline void vx_activate_task(struct task_struct *p)
12228 +{
12229 +       struct vx_info *vxi;
12230 +
12231 +       if ((vxi = p->vx_info)) {
12232 +               vx_update_load(vxi);
12233 +               atomic_inc(&vxi->cvirt.nr_running);
12234 +       }
12235 +}
12236 +
12237 +static inline void vx_deactivate_task(struct task_struct *p)
12238 +{
12239 +       struct vx_info *vxi;
12240 +
12241 +       if ((vxi = p->vx_info)) {
12242 +               vx_update_load(vxi);
12243 +               atomic_dec(&vxi->cvirt.nr_running);
12244 +       }
12245 +}
12246 +
12247 +static inline void vx_uninterruptible_inc(struct task_struct *p)
12248 +{
12249 +       struct vx_info *vxi;
12250 +
12251 +       if ((vxi = p->vx_info))
12252 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
12253 +}
12254 +
12255 +static inline void vx_uninterruptible_dec(struct task_struct *p)
12256 +{
12257 +       struct vx_info *vxi;
12258 +
12259 +       if ((vxi = p->vx_info))
12260 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
12261 +}
12262 +
12263 +
12264 +#else
12265 +#warning duplicate inclusion
12266 +#endif
12267 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
12268 --- linux-2.6.22.10/include/linux/vs_device.h   1970-01-01 01:00:00 +0100
12269 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_device.h        2007-10-11 01:10:22 +0200
12270 @@ -0,0 +1,45 @@
12271 +#ifndef _VS_DEVICE_H
12272 +#define _VS_DEVICE_H
12273 +
12274 +#include "vserver/base.h"
12275 +#include "vserver/device.h"
12276 +#include "vserver/debug.h"
12277 +
12278 +
12279 +#ifdef CONFIG_VSERVER_DEVICE
12280 +
12281 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
12282 +
12283 +#define vs_device_perm(v, d, m, p) \
12284 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
12285 +
12286 +#else
12287 +
12288 +static inline
12289 +int vs_map_device(struct vx_info *vxi,
12290 +       dev_t device, dev_t *target, umode_t mode)
12291 +{
12292 +       if (target)
12293 +               *target = device;
12294 +       return ~0;
12295 +}
12296 +
12297 +#define vs_device_perm(v, d, m, p) ((p) == (p))
12298 +
12299 +#endif
12300 +
12301 +
12302 +#define vs_map_chrdev(d, t, p) \
12303 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
12304 +#define vs_map_blkdev(d, t, p) \
12305 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
12306 +
12307 +#define vs_chrdev_perm(d, p) \
12308 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
12309 +#define vs_blkdev_perm(d, p) \
12310 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
12311 +
12312 +
12313 +#else
12314 +#warning duplicate inclusion
12315 +#endif
12316 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
12317 --- linux-2.6.22.10/include/linux/vs_dlimit.h   1970-01-01 01:00:00 +0100
12318 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_dlimit.h        2007-08-15 22:04:43 +0200
12319 @@ -0,0 +1,211 @@
12320 +#ifndef _VS_DLIMIT_H
12321 +#define _VS_DLIMIT_H
12322 +
12323 +#include <linux/fs.h>
12324 +
12325 +#include "vserver/dlimit.h"
12326 +#include "vserver/base.h"
12327 +#include "vserver/debug.h"
12328 +
12329 +
12330 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
12331 +
12332 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
12333 +       const char *_file, int _line)
12334 +{
12335 +       if (!dli)
12336 +               return NULL;
12337 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
12338 +               dli, dli ? dli->dl_tag : 0,
12339 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12340 +               _file, _line);
12341 +       atomic_inc(&dli->dl_usecnt);
12342 +       return dli;
12343 +}
12344 +
12345 +
12346 +#define free_dl_info(i) \
12347 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
12348 +
12349 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
12350 +
12351 +static inline void __put_dl_info(struct dl_info *dli,
12352 +       const char *_file, int _line)
12353 +{
12354 +       if (!dli)
12355 +               return;
12356 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
12357 +               dli, dli ? dli->dl_tag : 0,
12358 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12359 +               _file, _line);
12360 +       if (atomic_dec_and_test(&dli->dl_usecnt))
12361 +               free_dl_info(dli);
12362 +}
12363 +
12364 +
12365 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
12366 +
12367 +static inline int __dl_alloc_space(struct super_block *sb,
12368 +       tag_t tag, dlsize_t nr, const char *file, int line)
12369 +{
12370 +       struct dl_info *dli = NULL;
12371 +       int ret = 0;
12372 +
12373 +       if (nr == 0)
12374 +               goto out;
12375 +       dli = locate_dl_info(sb, tag);
12376 +       if (!dli)
12377 +               goto out;
12378 +
12379 +       spin_lock(&dli->dl_lock);
12380 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
12381 +       if (!ret)
12382 +               dli->dl_space_used += nr;
12383 +       spin_unlock(&dli->dl_lock);
12384 +       put_dl_info(dli);
12385 +out:
12386 +       vxlprintk(VXD_CBIT(dlim, 1),
12387 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
12388 +               sb, tag, __dlimit_char(dli), (long long)nr,
12389 +               ret, file, line);
12390 +       return ret;
12391 +}
12392 +
12393 +static inline void __dl_free_space(struct super_block *sb,
12394 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
12395 +{
12396 +       struct dl_info *dli = NULL;
12397 +
12398 +       if (nr == 0)
12399 +               goto out;
12400 +       dli = locate_dl_info(sb, tag);
12401 +       if (!dli)
12402 +               goto out;
12403 +
12404 +       spin_lock(&dli->dl_lock);
12405 +       if (dli->dl_space_used > nr)
12406 +               dli->dl_space_used -= nr;
12407 +       else
12408 +               dli->dl_space_used = 0;
12409 +       spin_unlock(&dli->dl_lock);
12410 +       put_dl_info(dli);
12411 +out:
12412 +       vxlprintk(VXD_CBIT(dlim, 1),
12413 +               "FREE  (%p,#%d)%c %lld bytes",
12414 +               sb, tag, __dlimit_char(dli), (long long)nr,
12415 +               _file, _line);
12416 +}
12417 +
12418 +static inline int __dl_alloc_inode(struct super_block *sb,
12419 +       tag_t tag, const char *_file, int _line)
12420 +{
12421 +       struct dl_info *dli;
12422 +       int ret = 0;
12423 +
12424 +       dli = locate_dl_info(sb, tag);
12425 +       if (!dli)
12426 +               goto out;
12427 +
12428 +       spin_lock(&dli->dl_lock);
12429 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
12430 +       if (!ret)
12431 +               dli->dl_inodes_used++;
12432 +       spin_unlock(&dli->dl_lock);
12433 +       put_dl_info(dli);
12434 +out:
12435 +       vxlprintk(VXD_CBIT(dlim, 0),
12436 +               "ALLOC (%p,#%d)%c inode (%d)",
12437 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
12438 +       return ret;
12439 +}
12440 +
12441 +static inline void __dl_free_inode(struct super_block *sb,
12442 +       tag_t tag, const char *_file, int _line)
12443 +{
12444 +       struct dl_info *dli;
12445 +
12446 +       dli = locate_dl_info(sb, tag);
12447 +       if (!dli)
12448 +               goto out;
12449 +
12450 +       spin_lock(&dli->dl_lock);
12451 +       if (dli->dl_inodes_used > 1)
12452 +               dli->dl_inodes_used--;
12453 +       else
12454 +               dli->dl_inodes_used = 0;
12455 +       spin_unlock(&dli->dl_lock);
12456 +       put_dl_info(dli);
12457 +out:
12458 +       vxlprintk(VXD_CBIT(dlim, 0),
12459 +               "FREE  (%p,#%d)%c inode",
12460 +               sb, tag, __dlimit_char(dli), _file, _line);
12461 +}
12462 +
12463 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
12464 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
12465 +       const char *_file, int _line)
12466 +{
12467 +       struct dl_info *dli;
12468 +       uint64_t broot, bfree;
12469 +
12470 +       dli = locate_dl_info(sb, tag);
12471 +       if (!dli)
12472 +               return;
12473 +
12474 +       spin_lock(&dli->dl_lock);
12475 +       broot = (dli->dl_space_total -
12476 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
12477 +               >> sb->s_blocksize_bits;
12478 +       bfree = (dli->dl_space_total - dli->dl_space_used)
12479 +                       >> sb->s_blocksize_bits;
12480 +       spin_unlock(&dli->dl_lock);
12481 +
12482 +       vxlprintk(VXD_CBIT(dlim, 2),
12483 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
12484 +               (long long)bfree, (long long)broot,
12485 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
12486 +               _file, _line);
12487 +       if (free_blocks) {
12488 +               if (*free_blocks > bfree)
12489 +                       *free_blocks = bfree;
12490 +       }
12491 +       if (root_blocks) {
12492 +               if (*root_blocks > broot)
12493 +                       *root_blocks = broot;
12494 +       }
12495 +       put_dl_info(dli);
12496 +}
12497 +
12498 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
12499 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12500 +               __FILE__, __LINE__ )
12501 +
12502 +#define DLIMIT_FREE_SPACE(in, bytes) \
12503 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12504 +               __FILE__, __LINE__ )
12505 +
12506 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
12507 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
12508 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12509 +               __FILE__, __LINE__ )
12510 +
12511 +#define DLIMIT_FREE_BLOCK(in, nr) \
12512 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
12513 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12514 +               __FILE__, __LINE__ )
12515 +
12516 +
12517 +#define DLIMIT_ALLOC_INODE(in) \
12518 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12519 +
12520 +#define DLIMIT_FREE_INODE(in) \
12521 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12522 +
12523 +
12524 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
12525 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
12526 +
12527 +
12528 +#else
12529 +#warning duplicate inclusion
12530 +#endif
12531 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
12532 --- linux-2.6.22.10/include/linux/vs_inet.h     1970-01-01 01:00:00 +0100
12533 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_inet.h  2007-10-05 15:07:22 +0200
12534 @@ -0,0 +1,341 @@
12535 +#ifndef _VS_INET_H
12536 +#define _VS_INET_H
12537 +
12538 +#include "vserver/base.h"
12539 +#include "vserver/network.h"
12540 +#include "vserver/debug.h"
12541 +
12542 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
12543 +
12544 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
12545 +                       NIPQUAD((a)->mask), (a)->type
12546 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
12547 +
12548 +
12549 +static inline
12550 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
12551 +{
12552 +       __be32 ip = nxa->ip[0].s_addr;
12553 +       __be32 mask = nxa->mask.s_addr;
12554 +       __be32 bcast = ip | ~mask;
12555 +       int ret = 0;
12556 +
12557 +       switch (nxa->type & tmask) {
12558 +       case NXA_TYPE_MASK:
12559 +               ret = (ip == (addr & mask));
12560 +               break;
12561 +       case NXA_TYPE_ADDR:
12562 +               ret = 3;
12563 +               if (addr == ip)
12564 +                       break;
12565 +               /* fall through to broadcast */
12566 +       case NXA_MOD_BCAST:
12567 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
12568 +               break;
12569 +       case NXA_TYPE_RANGE:
12570 +               ret = ((nxa->ip[0].s_addr <= addr) &&
12571 +                       (nxa->ip[1].s_addr > addr));
12572 +               break;
12573 +       case NXA_TYPE_ANY:
12574 +               ret = 2;
12575 +               break;
12576 +       }
12577 +
12578 +       vxdprintk(VXD_CBIT(net, 0),
12579 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
12580 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
12581 +       return ret;
12582 +}
12583 +
12584 +static inline
12585 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
12586 +{
12587 +       struct nx_addr_v4 *nxa;
12588 +       int ret = 1;
12589 +
12590 +       if (!nxi)
12591 +               goto out;
12592 +
12593 +       ret = 2;
12594 +       /* allow 127.0.0.1 when remapping lback */
12595 +       if ((tmask & NXA_LOOPBACK) &&
12596 +               (addr == IPI_LOOPBACK) &&
12597 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12598 +               goto out;
12599 +       ret = 3;
12600 +       /* check for lback address */
12601 +       if ((tmask & NXA_MOD_LBACK) &&
12602 +               (nxi->v4_lback.s_addr == addr))
12603 +               goto out;
12604 +       ret = 4;
12605 +       /* check for broadcast address */
12606 +       if ((tmask & NXA_MOD_BCAST) &&
12607 +               (nxi->v4_bcast.s_addr == addr))
12608 +               goto out;
12609 +       ret = 5;
12610 +       /* check for v4 addresses */
12611 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
12612 +               if (v4_addr_match(nxa, addr, tmask))
12613 +                       goto out;
12614 +       ret = 0;
12615 +out:
12616 +       vxdprintk(VXD_CBIT(net, 0),
12617 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
12618 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
12619 +       return ret;
12620 +}
12621 +
12622 +static inline
12623 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
12624 +{
12625 +       /* FIXME: needs full range checks */
12626 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
12627 +}
12628 +
12629 +static inline
12630 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
12631 +{
12632 +       struct nx_addr_v4 *ptr;
12633 +
12634 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
12635 +               if (v4_nx_addr_match(ptr, nxa, mask))
12636 +                       return 1;
12637 +       return 0;
12638 +}
12639 +
12640 +#include <net/inet_sock.h>
12641 +
12642 +/*
12643 + *     Check if a given address matches for a socket
12644 + *
12645 + *     nxi:            the socket's nx_info if any
12646 + *     addr:           to be verified address
12647 + */
12648 +static inline
12649 +int v4_sock_addr_match (
12650 +       struct nx_info *nxi,
12651 +       struct inet_sock *inet,
12652 +       __be32 addr)
12653 +{
12654 +       __be32 saddr = inet->rcv_saddr;
12655 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
12656 +
12657 +       if (addr && (saddr == addr || bcast == addr))
12658 +               return 1;
12659 +       if (!saddr)
12660 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
12661 +       return 0;
12662 +}
12663 +
12664 +
12665 +/* inet related checks and helpers */
12666 +
12667 +
12668 +struct in_ifaddr;
12669 +struct net_device;
12670 +struct sock;
12671 +
12672 +#ifdef CONFIG_INET
12673 +
12674 +#include <linux/netdevice.h>
12675 +#include <linux/inetdevice.h>
12676 +#include <net/inet_timewait_sock.h>
12677 +
12678 +
12679 +int dev_in_nx_info(struct net_device *, struct nx_info *);
12680 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
12681 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
12682 +
12683 +
12684 +/*
12685 + *     check if address is covered by socket
12686 + *
12687 + *     sk:     the socket to check against
12688 + *     addr:   the address in question (must be != 0)
12689 + */
12690 +
12691 +static inline
12692 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
12693 +{
12694 +       struct nx_info *nxi = sk->sk_nx_info;
12695 +       __be32 saddr = inet_rcv_saddr(sk);
12696 +
12697 +       vxdprintk(VXD_CBIT(net, 5),
12698 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
12699 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
12700 +               (sk->sk_socket?sk->sk_socket->flags:0));
12701 +
12702 +       if (saddr) {            /* direct address match */
12703 +               return v4_addr_match(nxa, saddr, -1);
12704 +       } else if (nxi) {       /* match against nx_info */
12705 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
12706 +       } else {                /* unrestricted any socket */
12707 +               return 1;
12708 +       }
12709 +}
12710 +
12711 +
12712 +
12713 +static inline
12714 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
12715 +{
12716 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p »%s«) %d",
12717 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
12718 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
12719 +
12720 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12721 +               return 1;
12722 +       if (dev_in_nx_info(dev, nxi))
12723 +               return 1;
12724 +       return 0;
12725 +}
12726 +
12727 +
12728 +static inline
12729 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
12730 +{
12731 +       if (!nxi)
12732 +               return 1;
12733 +       if (!ifa)
12734 +               return 0;
12735 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
12736 +}
12737 +
12738 +static inline
12739 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
12740 +{
12741 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
12742 +               nxi, nxi ? nxi->nx_id : 0, ifa,
12743 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
12744 +
12745 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12746 +               return 1;
12747 +       if (v4_ifa_in_nx_info(ifa, nxi))
12748 +               return 1;
12749 +       return 0;
12750 +}
12751 +
12752 +
12753 +struct nx_v4_sock_addr {
12754 +       __be32 saddr;   /* Address used for validation */
12755 +       __be32 baddr;   /* Address used for socket bind */
12756 +};
12757 +
12758 +static inline
12759 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
12760 +       struct nx_v4_sock_addr *nsa)
12761 +{
12762 +       struct sock *sk = &inet->sk;
12763 +       struct nx_info *nxi = sk->sk_nx_info;
12764 +       __be32 saddr = addr->sin_addr.s_addr;
12765 +       __be32 baddr = saddr;
12766 +
12767 +       vxdprintk(VXD_CBIT(net, 3),
12768 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
12769 +               sk, sk->sk_nx_info, sk->sk_socket,
12770 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
12771 +               NIPQUAD(saddr));
12772 +
12773 +       if (nxi) {
12774 +               if (saddr == INADDR_ANY) {
12775 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
12776 +                               baddr = nxi->v4.ip[0].s_addr;
12777 +               } else if (saddr == IPI_LOOPBACK) {
12778 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12779 +                               baddr = nxi->v4_lback.s_addr;
12780 +               } else {        /* normal address bind */
12781 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
12782 +                               return -EADDRNOTAVAIL;
12783 +               }
12784 +       }
12785 +
12786 +       vxdprintk(VXD_CBIT(net, 3),
12787 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
12788 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
12789 +
12790 +       nsa->saddr = saddr;
12791 +       nsa->baddr = baddr;
12792 +       return 0;
12793 +}
12794 +
12795 +static inline
12796 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
12797 +{
12798 +       inet->saddr = nsa->baddr;
12799 +       inet->rcv_saddr = nsa->baddr;
12800 +}
12801 +
12802 +
12803 +/*
12804 + *      helper to simplify inet_lookup_listener
12805 + *
12806 + *      nxi:   the socket's nx_info if any
12807 + *      addr:  to be verified address
12808 + *      saddr: socket address
12809 + */
12810 +static inline int v4_inet_addr_match (
12811 +       struct nx_info *nxi,
12812 +       __be32 addr,
12813 +       __be32 saddr)
12814 +{
12815 +       if (addr && (saddr == addr))
12816 +               return 1;
12817 +       if (!saddr)
12818 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
12819 +       return 0;
12820 +}
12821 +
12822 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
12823 +{
12824 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
12825 +               (addr == nxi->v4_lback.s_addr))
12826 +               return IPI_LOOPBACK;
12827 +       return addr;
12828 +}
12829 +
12830 +static inline
12831 +int nx_info_has_v4(struct nx_info *nxi)
12832 +{
12833 +       if (!nxi)
12834 +               return 1;
12835 +       if (NX_IPV4(nxi))
12836 +               return 1;
12837 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12838 +               return 1;
12839 +       return 0;
12840 +}
12841 +
12842 +#else /* CONFIG_INET */
12843 +
12844 +static inline
12845 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
12846 +{
12847 +       return 1;
12848 +}
12849 +
12850 +static inline
12851 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
12852 +{
12853 +       return 1;
12854 +}
12855 +
12856 +static inline
12857 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
12858 +{
12859 +       return 1;
12860 +}
12861 +
12862 +static inline
12863 +int nx_info_has_v4(struct nx_info *nxi)
12864 +{
12865 +       return 0;
12866 +}
12867 +
12868 +#endif /* CONFIG_INET */
12869 +
12870 +#define current_nx_info_has_v4() \
12871 +       nx_info_has_v4(current_nx_info())
12872 +
12873 +#else
12874 +#warning duplicate inclusion
12875 +#endif
12876 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
12877 --- linux-2.6.22.10/include/linux/vs_inet6.h    1970-01-01 01:00:00 +0100
12878 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_inet6.h 2007-10-05 14:54:36 +0200
12879 @@ -0,0 +1,228 @@
12880 +#ifndef _VS_INET6_H
12881 +#define _VS_INET6_H
12882 +
12883 +#include <net/ipv6.h>
12884 +#include "vserver/base.h"
12885 +#include "vserver/network.h"
12886 +#include "vserver/debug.h"
12887 +
12888 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
12889 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
12890 +
12891 +
12892 +#ifdef CONFIG_IPV6
12893 +
12894 +static inline
12895 +int v6_addr_match(struct nx_addr_v6 *nxa,
12896 +       const struct in6_addr *addr, uint16_t mask)
12897 +{
12898 +       switch (nxa->type & mask) {
12899 +       case NXA_TYPE_MASK:
12900 +               return ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
12901 +       case NXA_TYPE_ADDR:
12902 +               return ipv6_addr_equal(&nxa->ip, addr);
12903 +       case NXA_TYPE_ANY:
12904 +               return 1;
12905 +       default:
12906 +               return 0;
12907 +       }
12908 +}
12909 +
12910 +static inline
12911 +int v6_addr_in_nx_info(struct nx_info *nxi,
12912 +       const struct in6_addr *addr, uint16_t mask)
12913 +{
12914 +       struct nx_addr_v6 *nxa;
12915 +
12916 +       if (!nxi)
12917 +               return 1;
12918 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
12919 +               if (v6_addr_match(nxa, addr, mask))
12920 +                       return 1;
12921 +       return 0;
12922 +}
12923 +
12924 +static inline
12925 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
12926 +{
12927 +       /* FIXME: needs full range checks */
12928 +       return v6_addr_match(nxa, &addr->ip, mask);
12929 +}
12930 +
12931 +static inline
12932 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
12933 +{
12934 +       struct nx_addr_v6 *ptr;
12935 +
12936 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
12937 +               if (v6_nx_addr_match(ptr, nxa, mask))
12938 +                       return 1;
12939 +       return 0;
12940 +}
12941 +
12942 +
12943 +/*
12944 + *     Check if a given address matches for a socket
12945 + *
12946 + *     nxi:            the socket's nx_info if any
12947 + *     addr:           to be verified address
12948 + */
12949 +static inline
12950 +int v6_sock_addr_match (
12951 +       struct nx_info *nxi,
12952 +       struct inet_sock *inet,
12953 +       struct in6_addr *addr)
12954 +{
12955 +       struct sock *sk = &inet->sk;
12956 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12957 +
12958 +       if (!ipv6_addr_any(addr) &&
12959 +               ipv6_addr_equal(saddr, addr))
12960 +               return 1;
12961 +       if (ipv6_addr_any(saddr))
12962 +               return v6_addr_in_nx_info(nxi, addr, -1);
12963 +       return 0;
12964 +}
12965 +
12966 +/*
12967 + *     check if address is covered by socket
12968 + *
12969 + *     sk:     the socket to check against
12970 + *     addr:   the address in question (must be != 0)
12971 + */
12972 +
12973 +static inline
12974 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
12975 +{
12976 +       struct nx_info *nxi = sk->sk_nx_info;
12977 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12978 +
12979 +       vxdprintk(VXD_CBIT(net, 5),
12980 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
12981 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
12982 +               (sk->sk_socket?sk->sk_socket->flags:0));
12983 +
12984 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
12985 +               return v6_addr_match(nxa, saddr, -1);
12986 +       } else if (nxi) {               /* match against nx_info */
12987 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
12988 +       } else {                        /* unrestricted any socket */
12989 +               return 1;
12990 +       }
12991 +}
12992 +
12993 +
12994 +/* inet related checks and helpers */
12995 +
12996 +
12997 +struct in_ifaddr;
12998 +struct net_device;
12999 +struct sock;
13000 +
13001 +
13002 +#include <linux/netdevice.h>
13003 +#include <linux/inetdevice.h>
13004 +#include <net/inet_timewait_sock.h>
13005 +
13006 +
13007 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13008 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13009 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13010 +
13011 +
13012 +
13013 +static inline
13014 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13015 +{
13016 +       if (!nxi)
13017 +               return 1;
13018 +       if (!ifa)
13019 +               return 0;
13020 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13021 +}
13022 +
13023 +static inline
13024 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13025 +{
13026 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13027 +               return 1;
13028 +       if (v6_ifa_in_nx_info(ifa, nxi))
13029 +               return 1;
13030 +       return 0;
13031 +}
13032 +
13033 +
13034 +struct nx_v6_sock_addr {
13035 +       struct in6_addr saddr;  /* Address used for validation */
13036 +       struct in6_addr baddr;  /* Address used for socket bind */
13037 +};
13038 +
13039 +static inline
13040 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13041 +       struct nx_v6_sock_addr *nsa)
13042 +{
13043 +       // struct sock *sk = &inet->sk;
13044 +       // struct nx_info *nxi = sk->sk_nx_info;
13045 +       struct in6_addr saddr = addr->sin6_addr;
13046 +       struct in6_addr baddr = saddr;
13047 +
13048 +       nsa->saddr = saddr;
13049 +       nsa->baddr = baddr;
13050 +       return 0;
13051 +}
13052 +
13053 +static inline
13054 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13055 +{
13056 +       // struct sock *sk = &inet->sk;
13057 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13058 +
13059 +       // *saddr = nsa->baddr;
13060 +       // inet->saddr = nsa->baddr;
13061 +}
13062 +
13063 +static inline
13064 +int nx_info_has_v6(struct nx_info *nxi)
13065 +{
13066 +       if (!nxi)
13067 +               return 1;
13068 +       if (NX_IPV6(nxi))
13069 +               return 1;
13070 +       return 0;
13071 +}
13072 +
13073 +#else /* CONFIG_IPV6 */
13074 +
13075 +static inline
13076 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13077 +{
13078 +       return 1;
13079 +}
13080 +
13081 +
13082 +static inline
13083 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13084 +{
13085 +       return 1;
13086 +}
13087 +
13088 +static inline
13089 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13090 +{
13091 +       return 1;
13092 +}
13093 +
13094 +static inline
13095 +int nx_info_has_v6(struct nx_info *nxi)
13096 +{
13097 +       return 0;
13098 +}
13099 +
13100 +#endif /* CONFIG_IPV6 */
13101 +
13102 +#define current_nx_info_has_v6() \
13103 +       nx_info_has_v6(current_nx_info())
13104 +
13105 +#else
13106 +#warning duplicate inclusion
13107 +#endif
13108 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
13109 --- linux-2.6.22.10/include/linux/vs_limit.h    1970-01-01 01:00:00 +0100
13110 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_limit.h 2007-08-05 20:53:13 +0200
13111 @@ -0,0 +1,140 @@
13112 +#ifndef _VS_LIMIT_H
13113 +#define _VS_LIMIT_H
13114 +
13115 +#include "vserver/limit.h"
13116 +#include "vserver/base.h"
13117 +#include "vserver/context.h"
13118 +#include "vserver/debug.h"
13119 +#include "vserver/context.h"
13120 +#include "vserver/limit_int.h"
13121 +
13122 +
13123 +#define vx_acc_cres(v, d, p, r) \
13124 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13125 +
13126 +#define vx_acc_cres_cond(x, d, p, r) \
13127 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13128 +       r, d, p, __FILE__, __LINE__)
13129 +
13130 +
13131 +#define vx_add_cres(v, a, p, r) \
13132 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13133 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13134 +
13135 +#define vx_add_cres_cond(x, a, p, r) \
13136 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13137 +       r, a, p, __FILE__, __LINE__)
13138 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13139 +
13140 +
13141 +/* process and file limits */
13142 +
13143 +#define vx_nproc_inc(p) \
13144 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13145 +
13146 +#define vx_nproc_dec(p) \
13147 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13148 +
13149 +#define vx_files_inc(f) \
13150 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13151 +
13152 +#define vx_files_dec(f) \
13153 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13154 +
13155 +#define vx_locks_inc(l) \
13156 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13157 +
13158 +#define vx_locks_dec(l) \
13159 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13160 +
13161 +#define vx_openfd_inc(f) \
13162 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
13163 +
13164 +#define vx_openfd_dec(f) \
13165 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
13166 +
13167 +
13168 +#define vx_cres_avail(v, n, r) \
13169 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13170 +
13171 +
13172 +#define vx_nproc_avail(n) \
13173 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
13174 +
13175 +#define vx_files_avail(n) \
13176 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
13177 +
13178 +#define vx_locks_avail(n) \
13179 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
13180 +
13181 +#define vx_openfd_avail(n) \
13182 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
13183 +
13184 +
13185 +/* dentry limits */
13186 +
13187 +#define vx_dentry_inc(d) do {                                          \
13188 +       if (atomic_read(&d->d_count) == 1)                              \
13189 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
13190 +       } while (0)
13191 +
13192 +#define vx_dentry_dec(d) do {                                          \
13193 +       if (atomic_read(&d->d_count) == 0)                              \
13194 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
13195 +       } while (0)
13196 +
13197 +#define vx_dentry_avail(n) \
13198 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
13199 +
13200 +
13201 +/* socket limits */
13202 +
13203 +#define vx_sock_inc(s) \
13204 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13205 +
13206 +#define vx_sock_dec(s) \
13207 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13208 +
13209 +#define vx_sock_avail(n) \
13210 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
13211 +
13212 +
13213 +/* ipc resource limits */
13214 +
13215 +#define vx_ipcmsg_add(v, u, a) \
13216 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13217 +
13218 +#define vx_ipcmsg_sub(v, u, a) \
13219 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13220 +
13221 +#define vx_ipcmsg_avail(v, a) \
13222 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13223 +
13224 +
13225 +#define vx_ipcshm_add(v, k, a) \
13226 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13227 +
13228 +#define vx_ipcshm_sub(v, k, a) \
13229 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13230 +
13231 +#define vx_ipcshm_avail(v, a) \
13232 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13233 +
13234 +
13235 +#define vx_semary_inc(a) \
13236 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
13237 +
13238 +#define vx_semary_dec(a) \
13239 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
13240 +
13241 +
13242 +#define vx_nsems_add(a,n) \
13243 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13244 +
13245 +#define vx_nsems_sub(a,n) \
13246 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13247 +
13248 +
13249 +#else
13250 +#warning duplicate inclusion
13251 +#endif
13252 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
13253 --- linux-2.6.22.10/include/linux/vs_memory.h   1970-01-01 01:00:00 +0100
13254 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_memory.h        2007-08-05 20:53:13 +0200
13255 @@ -0,0 +1,159 @@
13256 +#ifndef _VS_MEMORY_H
13257 +#define _VS_MEMORY_H
13258 +
13259 +#include "vserver/limit.h"
13260 +#include "vserver/base.h"
13261 +#include "vserver/context.h"
13262 +#include "vserver/debug.h"
13263 +#include "vserver/context.h"
13264 +#include "vserver/limit_int.h"
13265 +
13266 +
13267 +#define __acc_add_long(a, v)   (*(v) += (a))
13268 +#define __acc_inc_long(v)      (++*(v))
13269 +#define __acc_dec_long(v)      (--*(v))
13270 +
13271 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
13272 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
13273 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
13274 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
13275 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13276 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
13277 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
13278 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
13279 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13280 +
13281 +
13282 +#define vx_acc_page(m, d, v, r) do {                                   \
13283 +       if ((d) > 0)                                                    \
13284 +               __acc_inc_long(&(m)->v);                                \
13285 +       else                                                            \
13286 +               __acc_dec_long(&(m)->v);                                \
13287 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13288 +} while (0)
13289 +
13290 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
13291 +       if ((d) > 0)                                                    \
13292 +               __acc_inc_atomic(&(m)->v);                              \
13293 +       else                                                            \
13294 +               __acc_dec_atomic(&(m)->v);                              \
13295 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13296 +} while (0)
13297 +
13298 +
13299 +#define vx_acc_pages(m, p, v, r) do {                                  \
13300 +       unsigned long __p = (p);                                        \
13301 +       __acc_add_long(__p, &(m)->v);                                   \
13302 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13303 +} while (0)
13304 +
13305 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
13306 +       unsigned long __p = (p);                                        \
13307 +       __acc_add_atomic(__p, &(m)->v);                                 \
13308 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13309 +} while (0)
13310 +
13311 +
13312 +
13313 +#define vx_acc_vmpage(m, d) \
13314 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
13315 +#define vx_acc_vmlpage(m, d) \
13316 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
13317 +#define vx_acc_file_rsspage(m, d) \
13318 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
13319 +#define vx_acc_anon_rsspage(m, d) \
13320 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
13321 +
13322 +#define vx_acc_vmpages(m, p) \
13323 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
13324 +#define vx_acc_vmlpages(m, p) \
13325 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
13326 +#define vx_acc_file_rsspages(m, p) \
13327 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
13328 +#define vx_acc_anon_rsspages(m, p) \
13329 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
13330 +
13331 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
13332 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
13333 +
13334 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
13335 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
13336 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
13337 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
13338 +
13339 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
13340 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
13341 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
13342 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
13343 +
13344 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
13345 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
13346 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
13347 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
13348 +
13349 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
13350 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
13351 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
13352 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
13353 +
13354 +
13355 +#define vx_pages_avail(m, p, r) \
13356 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
13357 +
13358 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
13359 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
13360 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
13361 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
13362 +
13363 +#define vx_rss_avail(m, p) \
13364 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
13365 +
13366 +
13367 +enum {
13368 +       VXPT_UNKNOWN = 0,
13369 +       VXPT_ANON,
13370 +       VXPT_NONE,
13371 +       VXPT_FILE,
13372 +       VXPT_SWAP,
13373 +       VXPT_WRITE
13374 +};
13375 +
13376 +#if 0
13377 +#define        vx_page_fault(mm, vma, type, ret)
13378 +#else
13379 +
13380 +static inline
13381 +void __vx_page_fault(struct mm_struct *mm,
13382 +       struct vm_area_struct *vma, int type, int ret)
13383 +{
13384 +       struct vx_info *vxi = mm->mm_vx_info;
13385 +       int what;
13386 +/*
13387 +       static char *page_type[6] =
13388 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
13389 +       static char *page_what[4] =
13390 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
13391 +*/
13392 +
13393 +       if (!vxi)
13394 +               return;
13395 +
13396 +       what = (ret & 0x3);
13397 +
13398 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
13399 +               type, what, ret, page_type[type], page_what[what]);
13400 +*/
13401 +       if (ret & VM_FAULT_WRITE)
13402 +               what |= 0x4;
13403 +       atomic_inc(&vxi->cacct.page[type][what]);
13404 +}
13405 +
13406 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
13407 +#endif
13408 +
13409 +
13410 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
13411 +
13412 +#else
13413 +#warning duplicate inclusion
13414 +#endif
13415 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
13416 --- linux-2.6.22.10/include/linux/vs_network.h  1970-01-01 01:00:00 +0100
13417 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_network.h       2007-08-05 20:53:13 +0200
13418 @@ -0,0 +1,166 @@
13419 +#ifndef _NX_VS_NETWORK_H
13420 +#define _NX_VS_NETWORK_H
13421 +
13422 +#include "vserver/context.h"
13423 +#include "vserver/network.h"
13424 +#include "vserver/base.h"
13425 +#include "vserver/debug.h"
13426 +
13427 +
13428 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
13429 +
13430 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
13431 +       const char *_file, int _line)
13432 +{
13433 +       if (!nxi)
13434 +               return NULL;
13435 +
13436 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
13437 +               nxi, nxi ? nxi->nx_id : 0,
13438 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13439 +               _file, _line);
13440 +
13441 +       atomic_inc(&nxi->nx_usecnt);
13442 +       return nxi;
13443 +}
13444 +
13445 +
13446 +extern void free_nx_info(struct nx_info *);
13447 +
13448 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
13449 +
13450 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
13451 +{
13452 +       if (!nxi)
13453 +               return;
13454 +
13455 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
13456 +               nxi, nxi ? nxi->nx_id : 0,
13457 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13458 +               _file, _line);
13459 +
13460 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
13461 +               free_nx_info(nxi);
13462 +}
13463 +
13464 +
13465 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
13466 +
13467 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
13468 +               const char *_file, int _line)
13469 +{
13470 +       if (nxi) {
13471 +               vxlprintk(VXD_CBIT(nid, 3),
13472 +                       "init_nx_info(%p[#%d.%d])",
13473 +                       nxi, nxi ? nxi->nx_id : 0,
13474 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13475 +                       _file, _line);
13476 +
13477 +               atomic_inc(&nxi->nx_usecnt);
13478 +       }
13479 +       *nxp = nxi;
13480 +}
13481 +
13482 +
13483 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
13484 +
13485 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
13486 +       const char *_file, int _line)
13487 +{
13488 +       struct nx_info *nxo;
13489 +
13490 +       if (!nxi)
13491 +               return;
13492 +
13493 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
13494 +               nxi, nxi ? nxi->nx_id : 0,
13495 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13496 +               _file, _line);
13497 +
13498 +       atomic_inc(&nxi->nx_usecnt);
13499 +       nxo = xchg(nxp, nxi);
13500 +       BUG_ON(nxo);
13501 +}
13502 +
13503 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
13504 +
13505 +static inline void __clr_nx_info(struct nx_info **nxp,
13506 +       const char *_file, int _line)
13507 +{
13508 +       struct nx_info *nxo;
13509 +
13510 +       nxo = xchg(nxp, NULL);
13511 +       if (!nxo)
13512 +               return;
13513 +
13514 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
13515 +               nxo, nxo ? nxo->nx_id : 0,
13516 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
13517 +               _file, _line);
13518 +
13519 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
13520 +               free_nx_info(nxo);
13521 +}
13522 +
13523 +
13524 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
13525 +
13526 +static inline void __claim_nx_info(struct nx_info *nxi,
13527 +       struct task_struct *task, const char *_file, int _line)
13528 +{
13529 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
13530 +               nxi, nxi ? nxi->nx_id : 0,
13531 +               nxi?atomic_read(&nxi->nx_usecnt):0,
13532 +               nxi?atomic_read(&nxi->nx_tasks):0,
13533 +               task, _file, _line);
13534 +
13535 +       atomic_inc(&nxi->nx_tasks);
13536 +}
13537 +
13538 +
13539 +extern void unhash_nx_info(struct nx_info *);
13540 +
13541 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
13542 +
13543 +static inline void __release_nx_info(struct nx_info *nxi,
13544 +       struct task_struct *task, const char *_file, int _line)
13545 +{
13546 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
13547 +               nxi, nxi ? nxi->nx_id : 0,
13548 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13549 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
13550 +               task, _file, _line);
13551 +
13552 +       might_sleep();
13553 +
13554 +       if (atomic_dec_and_test(&nxi->nx_tasks))
13555 +               unhash_nx_info(nxi);
13556 +}
13557 +
13558 +
13559 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
13560 +
13561 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
13562 +       const char *_file, int _line)
13563 +{
13564 +       struct nx_info *nxi;
13565 +
13566 +       task_lock(p);
13567 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
13568 +               p, _file, _line);
13569 +       nxi = __get_nx_info(p->nx_info, _file, _line);
13570 +       task_unlock(p);
13571 +       return nxi;
13572 +}
13573 +
13574 +
13575 +static inline void exit_nx_info(struct task_struct *p)
13576 +{
13577 +       if (p->nx_info)
13578 +               release_nx_info(p->nx_info, p);
13579 +}
13580 +
13581 +
13582 +#else
13583 +#warning duplicate inclusion
13584 +#endif
13585 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
13586 --- linux-2.6.22.10/include/linux/vs_pid.h      1970-01-01 01:00:00 +0100
13587 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_pid.h   2007-09-05 02:49:29 +0200
13588 @@ -0,0 +1,133 @@
13589 +#ifndef _VS_PID_H
13590 +#define _VS_PID_H
13591 +
13592 +#include "vserver/base.h"
13593 +#include "vserver/context.h"
13594 +#include "vserver/debug.h"
13595 +#include <linux/pid_namespace.h>
13596 +
13597 +
13598 +/* pid faking stuff */
13599 +
13600 +
13601 +#define vx_info_map_pid(v, p) \
13602 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
13603 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13604 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
13605 +#define vx_map_tgid(p) vx_map_pid(p)
13606 +
13607 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13608 +       const char *func, const char *file, int line)
13609 +{
13610 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13611 +               vxfprintk(VXD_CBIT(cvirt, 2),
13612 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13613 +                       vxi, (long long)vxi->vx_flags, pid,
13614 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13615 +                       func, file, line);
13616 +               if (pid == 0)
13617 +                       return 0;
13618 +               if (pid == vxi->vx_initpid)
13619 +                       return 1;
13620 +       }
13621 +       return pid;
13622 +}
13623 +
13624 +#define vx_info_rmap_pid(v, p) \
13625 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
13626 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
13627 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13628 +
13629 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13630 +       const char *func, const char *file, int line)
13631 +{
13632 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13633 +               vxfprintk(VXD_CBIT(cvirt, 2),
13634 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13635 +                       vxi, (long long)vxi->vx_flags, pid,
13636 +                       (pid == 1) ? vxi->vx_initpid : pid,
13637 +                       func, file, line);
13638 +               if ((pid == 1) && vxi->vx_initpid)
13639 +                       return vxi->vx_initpid;
13640 +               if (pid == vxi->vx_initpid)
13641 +                       return ~0U;
13642 +       }
13643 +       return pid;
13644 +}
13645 +
13646 +
13647 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
13648 +
13649 +static inline
13650 +int vx_proc_task_visible(struct task_struct *task)
13651 +{
13652 +       if ((task->pid == 1) &&
13653 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
13654 +               /* show a blend through init */
13655 +               goto visible;
13656 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
13657 +               goto visible;
13658 +       return 0;
13659 +visible:
13660 +       return 1;
13661 +}
13662 +
13663 +static inline
13664 +struct task_struct *vx_find_proc_task_by_pid(int pid)
13665 +{
13666 +       struct task_struct *task = find_task_by_pid(pid);
13667 +
13668 +       if (task && !vx_proc_task_visible(task)) {
13669 +               vxdprintk(VXD_CBIT(misc, 6),
13670 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
13671 +                       task, task->xid, task->pid,
13672 +                       current, current->xid, current->pid);
13673 +               task = NULL;
13674 +       }
13675 +       return task;
13676 +}
13677 +
13678 +static inline
13679 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
13680 +{
13681 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
13682 +
13683 +       if (task && !vx_proc_task_visible(task)) {
13684 +               vxdprintk(VXD_CBIT(misc, 6),
13685 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
13686 +                       task, task->xid, task->pid,
13687 +                       current, current->xid, current->pid);
13688 +               put_task_struct(task);
13689 +               task = NULL;
13690 +       }
13691 +       return task;
13692 +}
13693 +
13694 +
13695 +static inline
13696 +struct task_struct *vx_child_reaper(struct task_struct *p)
13697 +{
13698 +       struct vx_info *vxi = p->vx_info;
13699 +       struct task_struct *reaper = child_reaper(p);
13700 +
13701 +       if (!vxi)
13702 +               goto out;
13703 +
13704 +       BUG_ON(!p->vx_info->vx_reaper);
13705 +
13706 +       /* child reaper for the guest reaper */
13707 +       if (vxi->vx_reaper == p)
13708 +               goto out;
13709 +
13710 +       reaper = vxi->vx_reaper;
13711 +out:
13712 +       vxdprintk(VXD_CBIT(xid, 7),
13713 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
13714 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
13715 +       return reaper;
13716 +}
13717 +
13718 +
13719 +#else
13720 +#warning duplicate inclusion
13721 +#endif
13722 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
13723 --- linux-2.6.22.10/include/linux/vs_sched.h    1970-01-01 01:00:00 +0100
13724 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_sched.h 2007-08-05 20:53:13 +0200
13725 @@ -0,0 +1,110 @@
13726 +#ifndef _VS_SCHED_H
13727 +#define _VS_SCHED_H
13728 +
13729 +#include "vserver/base.h"
13730 +#include "vserver/context.h"
13731 +#include "vserver/sched.h"
13732 +
13733 +
13734 +#define VAVAVOOM_RATIO          50
13735 +
13736 +#define MAX_PRIO_BIAS           20
13737 +#define MIN_PRIO_BIAS          -20
13738 +
13739 +
13740 +#ifdef CONFIG_VSERVER_HARDCPU
13741 +
13742 +/*
13743 + * effective_prio - return the priority that is based on the static
13744 + * priority but is modified by bonuses/penalties.
13745 + *
13746 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
13747 + * into a -4 ... 0 ... +4 bonus/penalty range.
13748 + *
13749 + * Additionally, we scale another amount based on the number of
13750 + * CPU tokens currently held by the context, if the process is
13751 + * part of a context (and the appropriate SCHED flag is set).
13752 + * This ranges from -5 ... 0 ... +15, quadratically.
13753 + *
13754 + * So, the total bonus is -9 .. 0 .. +19
13755 + * We use ~50% of the full 0...39 priority range so that:
13756 + *
13757 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
13758 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
13759 + *    unless that context is far exceeding its CPU allocation.
13760 + *
13761 + * Both properties are important to certain workloads.
13762 + */
13763 +static inline
13764 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
13765 +{
13766 +       int vavavoom, max;
13767 +
13768 +       /* lots of tokens = lots of vavavoom
13769 +        *      no tokens = no vavavoom      */
13770 +       if ((vavavoom = sched_pc->tokens) >= 0) {
13771 +               max = sched_pc->tokens_max;
13772 +               vavavoom = max - vavavoom;
13773 +               max = max * max;
13774 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
13775 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
13776 +               return vavavoom;
13777 +       }
13778 +       return 0;
13779 +}
13780 +
13781 +
13782 +static inline
13783 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
13784 +{
13785 +       struct vx_info *vxi = p->vx_info;
13786 +       struct _vx_sched_pc *sched_pc;
13787 +
13788 +       if (!vxi)
13789 +               return prio;
13790 +
13791 +       sched_pc = &vx_cpu(vxi, sched_pc);
13792 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
13793 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
13794 +
13795 +               sched_pc->vavavoom = vavavoom;
13796 +               prio += vavavoom;
13797 +       }
13798 +       prio += sched_pc->prio_bias;
13799 +       return prio;
13800 +}
13801 +
13802 +#else /* !CONFIG_VSERVER_HARDCPU */
13803 +
13804 +static inline
13805 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
13806 +{
13807 +       struct vx_info *vxi = p->vx_info;
13808 +
13809 +       if (vxi)
13810 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
13811 +       return prio;
13812 +}
13813 +
13814 +#endif /* CONFIG_VSERVER_HARDCPU */
13815 +
13816 +
13817 +static inline void vx_account_user(struct vx_info *vxi,
13818 +       cputime_t cputime, int nice)
13819 +{
13820 +       if (!vxi)
13821 +               return;
13822 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
13823 +}
13824 +
13825 +static inline void vx_account_system(struct vx_info *vxi,
13826 +       cputime_t cputime, int idle)
13827 +{
13828 +       if (!vxi)
13829 +               return;
13830 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
13831 +}
13832 +
13833 +#else
13834 +#warning duplicate inclusion
13835 +#endif
13836 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
13837 --- linux-2.6.22.10/include/linux/vs_socket.h   1970-01-01 01:00:00 +0100
13838 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_socket.h        2007-08-05 20:53:13 +0200
13839 @@ -0,0 +1,80 @@
13840 +#ifndef _VS_SOCKET_H
13841 +#define _VS_SOCKET_H
13842 +
13843 +#include "vserver/debug.h"
13844 +#include "vserver/base.h"
13845 +#include "vserver/cacct.h"
13846 +#include "vserver/context.h"
13847 +#include "vserver/tag.h"
13848 +
13849 +
13850 +/* socket accounting */
13851 +
13852 +#include <linux/socket.h>
13853 +
13854 +static inline int vx_sock_type(int family)
13855 +{
13856 +       switch (family) {
13857 +       case PF_UNSPEC:
13858 +               return VXA_SOCK_UNSPEC;
13859 +       case PF_UNIX:
13860 +               return VXA_SOCK_UNIX;
13861 +       case PF_INET:
13862 +               return VXA_SOCK_INET;
13863 +       case PF_INET6:
13864 +               return VXA_SOCK_INET6;
13865 +       case PF_PACKET:
13866 +               return VXA_SOCK_PACKET;
13867 +       default:
13868 +               return VXA_SOCK_OTHER;
13869 +       }
13870 +}
13871 +
13872 +#define vx_acc_sock(v, f, p, s) \
13873 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
13874 +
13875 +static inline void __vx_acc_sock(struct vx_info *vxi,
13876 +       int family, int pos, int size, char *file, int line)
13877 +{
13878 +       if (vxi) {
13879 +               int type = vx_sock_type(family);
13880 +
13881 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
13882 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
13883 +       }
13884 +}
13885 +
13886 +#define vx_sock_recv(sk, s) \
13887 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
13888 +#define vx_sock_send(sk, s) \
13889 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
13890 +#define vx_sock_fail(sk, s) \
13891 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
13892 +
13893 +
13894 +#define sock_vx_init(s) do {           \
13895 +       (s)->sk_xid = 0;                \
13896 +       (s)->sk_vx_info = NULL;         \
13897 +       } while (0)
13898 +
13899 +#define sock_nx_init(s) do {           \
13900 +       (s)->sk_nid = 0;                \
13901 +       (s)->sk_nx_info = NULL;         \
13902 +       } while (0)
13903 +
13904 +static inline
13905 +int vx_socket_peer_tag(struct socket *sock, int level,
13906 +       char __user *optval, int __user *optlen, int len)
13907 +{
13908 +       struct peer_tag tag;
13909 +
13910 +       tag.xid = sock->sk->sk_xid;
13911 +       tag.nid = sock->sk->sk_nid;
13912 +       if (copy_to_user(optval, &tag, sizeof(tag)))
13913 +               return -EFAULT;
13914 +       return 0;
13915 +}
13916 +
13917 +#else
13918 +#warning duplicate inclusion
13919 +#endif
13920 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
13921 --- linux-2.6.22.10/include/linux/vs_tag.h      1970-01-01 01:00:00 +0100
13922 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_tag.h   2007-08-15 19:11:32 +0200
13923 @@ -0,0 +1,43 @@
13924 +#ifndef _VS_TAG_H
13925 +#define _VS_TAG_H
13926 +
13927 +#include <linux/vserver/tag.h>
13928 +
13929 +/* check conditions */
13930 +
13931 +#define DX_ADMIN       0x0001
13932 +#define DX_WATCH       0x0002
13933 +#define DX_HOSTID      0x0008
13934 +
13935 +#define DX_IDENT       0x0010
13936 +
13937 +#define DX_ARG_MASK    0x0010
13938 +
13939 +
13940 +#define dx_task_tag(t) ((t)->tag)
13941 +
13942 +#define dx_current_tag() dx_task_tag(current)
13943 +
13944 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
13945 +
13946 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
13947 +
13948 +
13949 +/*
13950 + * check current context for ADMIN/WATCH and
13951 + * optionally against supplied argument
13952 + */
13953 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
13954 +{
13955 +       if (mode & DX_ARG_MASK) {
13956 +               if ((mode & DX_IDENT) && (id == cid))
13957 +                       return 1;
13958 +       }
13959 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
13960 +               ((mode & DX_WATCH) && (cid == 1)) ||
13961 +               ((mode & DX_HOSTID) && (id == 0)));
13962 +}
13963 +
13964 +#else
13965 +#warning duplicate inclusion
13966 +#endif
13967 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
13968 --- linux-2.6.22.10/include/linux/vs_time.h     1970-01-01 01:00:00 +0100
13969 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_time.h  2007-08-05 20:53:13 +0200
13970 @@ -0,0 +1,19 @@
13971 +#ifndef _VS_TIME_H
13972 +#define _VS_TIME_H
13973 +
13974 +
13975 +/* time faking stuff */
13976 +
13977 +#ifdef CONFIG_VSERVER_VTIME
13978 +
13979 +extern void vx_gettimeofday(struct timeval *tv);
13980 +extern int vx_settimeofday(struct timespec *ts);
13981 +
13982 +#else
13983 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
13984 +#define        vx_settimeofday(t)      do_settimeofday(t)
13985 +#endif
13986 +
13987 +#else
13988 +#warning duplicate inclusion
13989 +#endif
13990 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
13991 --- linux-2.6.22.10/include/linux/vserver/Kbuild        1970-01-01 01:00:00 +0100
13992 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/Kbuild     2007-10-11 01:10:22 +0200
13993 @@ -0,0 +1,8 @@
13994 +
13995 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
13996 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
13997 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
13998 +       debug_cmd.h device_cmd.h
13999 +
14000 +unifdef-y += switch.h network.h monitor.h inode.h device.h
14001 +
14002 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
14003 --- linux-2.6.22.10/include/linux/vserver/base.h        1970-01-01 01:00:00 +0100
14004 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/base.h     2007-09-17 14:07:30 +0200
14005 @@ -0,0 +1,218 @@
14006 +#ifndef _VX_BASE_H
14007 +#define _VX_BASE_H
14008 +
14009 +
14010 +/* context state changes */
14011 +
14012 +enum {
14013 +       VSC_STARTUP = 1,
14014 +       VSC_SHUTDOWN,
14015 +
14016 +       VSC_NETUP,
14017 +       VSC_NETDOWN,
14018 +};
14019 +
14020 +
14021 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
14022 +
14023 +/* check conditions */
14024 +
14025 +#define VS_ADMIN       0x0001
14026 +#define VS_WATCH       0x0002
14027 +#define VS_HIDE                0x0004
14028 +#define VS_HOSTID      0x0008
14029 +
14030 +#define VS_IDENT       0x0010
14031 +#define VS_EQUIV       0x0020
14032 +#define VS_PARENT      0x0040
14033 +#define VS_CHILD       0x0080
14034 +
14035 +#define VS_ARG_MASK    0x00F0
14036 +
14037 +#ifdef CONFIG_VSERVER_PRIVACY
14038 +#define VS_ADMIN_P     (0)
14039 +#define VS_WATCH_P     (0)
14040 +#else
14041 +#define VS_ADMIN_P     VS_ADMIN
14042 +#define VS_WATCH_P     VS_WATCH
14043 +#endif
14044 +
14045 +#define VS_HARDIRQ     0x1000
14046 +#define VS_SOFTIRQ     0x2000
14047 +#define VS_IRQ         0x4000
14048 +
14049 +#define VS_IRQ_MASK    0xF000
14050 +
14051 +#include <linux/hardirq.h>
14052 +
14053 +/*
14054 + * check current context for ADMIN/WATCH and
14055 + * optionally against supplied argument
14056 + */
14057 +static inline int __vs_check(int cid, int id, unsigned int mode)
14058 +{
14059 +       if (mode & VS_ARG_MASK) {
14060 +               if ((mode & VS_IDENT) && (id == cid))
14061 +                       return 1;
14062 +       }
14063 +       if (mode & VS_IRQ_MASK) {
14064 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
14065 +                       return 1;
14066 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
14067 +                       return 1;
14068 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
14069 +                       return 1;
14070 +       }
14071 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
14072 +               ((mode & VS_WATCH) && (cid == 1)) ||
14073 +               ((mode & VS_HOSTID) && (id == 0)));
14074 +}
14075 +
14076 +#define vx_task_xid(t) ((t)->xid)
14077 +
14078 +#define vx_current_xid() vx_task_xid(current)
14079 +
14080 +#define current_vx_info() (current->vx_info)
14081 +
14082 +
14083 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
14084 +
14085 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
14086 +
14087 +
14088 +#define nx_task_nid(t) ((t)->nid)
14089 +
14090 +#define nx_current_nid() nx_task_nid(current)
14091 +
14092 +#define current_nx_info() (current->nx_info)
14093 +
14094 +
14095 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
14096 +
14097 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
14098 +
14099 +
14100 +
14101 +/* generic flag merging */
14102 +
14103 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
14104 +
14105 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
14106 +
14107 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
14108 +
14109 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
14110 +
14111 +
14112 +/* context flags */
14113 +
14114 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
14115 +
14116 +#define vx_current_flags()     __vx_flags(current->vx_info)
14117 +
14118 +#define vx_info_flags(v, m, f) \
14119 +       vs_check_flags(__vx_flags(v), m, f)
14120 +
14121 +#define task_vx_flags(t, m, f) \
14122 +       ((t) && vx_info_flags((t)->vx_info, m, f))
14123 +
14124 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
14125 +
14126 +
14127 +/* context caps */
14128 +
14129 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
14130 +
14131 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
14132 +
14133 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
14134 +
14135 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
14136 +
14137 +
14138 +
14139 +/* network flags */
14140 +
14141 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
14142 +
14143 +#define nx_current_flags()     __nx_flags(current->nx_info)
14144 +
14145 +#define nx_info_flags(n, m, f) \
14146 +       vs_check_flags(__nx_flags(n), m, f)
14147 +
14148 +#define task_nx_flags(t, m, f) \
14149 +       ((t) && nx_info_flags((t)->nx_info, m, f))
14150 +
14151 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
14152 +
14153 +
14154 +/* network caps */
14155 +
14156 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
14157 +
14158 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
14159 +
14160 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
14161 +
14162 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
14163 +
14164 +
14165 +/* context mask capabilities */
14166 +
14167 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
14168 +
14169 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
14170 +
14171 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
14172 +
14173 +
14174 +/* context bcap mask */
14175 +
14176 +#define __vx_bcaps(v)  ((v) ? (v)->vx_bcaps : ~0 )
14177 +
14178 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
14179 +
14180 +#define vx_info_bcaps(v, c)    (__vx_bcaps(v) & (c))
14181 +
14182 +#define vx_bcaps(c)    vx_info_bcaps(current->vx_info, c)
14183 +
14184 +
14185 +#define vx_info_cap_bset(v)    ((v) ? (v)->vx_cap_bset : cap_bset)
14186 +
14187 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
14188 +
14189 +
14190 +#define __vx_info_mbcap(v, b) \
14191 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
14192 +       vx_info_bcaps(v, b) : (b))
14193 +
14194 +#define vx_info_mbcap(v, b)    __vx_info_mbcap(v, cap_t(b))
14195 +
14196 +#define task_vx_mbcap(t, b) \
14197 +       vx_info_mbcap((t)->vx_info, (t)->b)
14198 +
14199 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
14200 +
14201 +#define vx_cap_raised(v, c, f) (vx_info_mbcap(v, c) & CAP_TO_MASK(f))
14202 +
14203 +#define vx_capable(b, c) (capable(b) || \
14204 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
14205 +
14206 +#define nx_capable(b, c) (capable(b) || \
14207 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
14208 +
14209 +#define vx_current_initpid(n) \
14210 +       (current->vx_info && \
14211 +       (current->vx_info->vx_initpid == (n)))
14212 +
14213 +
14214 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
14215 +
14216 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
14217 +
14218 +
14219 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
14220 +
14221 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
14222 +
14223 +#endif
14224 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
14225 --- linux-2.6.22.10/include/linux/vserver/cacct.h       1970-01-01 01:00:00 +0100
14226 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct.h    2007-08-05 20:53:13 +0200
14227 @@ -0,0 +1,15 @@
14228 +#ifndef _VX_CACCT_H
14229 +#define _VX_CACCT_H
14230 +
14231 +
14232 +enum sock_acc_field {
14233 +       VXA_SOCK_UNSPEC = 0,
14234 +       VXA_SOCK_UNIX,
14235 +       VXA_SOCK_INET,
14236 +       VXA_SOCK_INET6,
14237 +       VXA_SOCK_PACKET,
14238 +       VXA_SOCK_OTHER,
14239 +       VXA_SOCK_SIZE   /* array size */
14240 +};
14241 +
14242 +#endif /* _VX_CACCT_H */
14243 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
14244 --- linux-2.6.22.10/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00 +0100
14245 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_cmd.h        2007-08-05 20:53:13 +0200
14246 @@ -0,0 +1,23 @@
14247 +#ifndef _VX_CACCT_CMD_H
14248 +#define _VX_CACCT_CMD_H
14249 +
14250 +
14251 +/* virtual host info name commands */
14252 +
14253 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
14254 +
14255 +struct vcmd_sock_stat_v0 {
14256 +       uint32_t field;
14257 +       uint32_t count[3];
14258 +       uint64_t total[3];
14259 +};
14260 +
14261 +
14262 +#ifdef __KERNEL__
14263 +
14264 +#include <linux/compiler.h>
14265 +
14266 +extern int vc_sock_stat(struct vx_info *, void __user *);
14267 +
14268 +#endif /* __KERNEL__ */
14269 +#endif /* _VX_CACCT_CMD_H */
14270 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
14271 --- linux-2.6.22.10/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00 +0100
14272 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_def.h        2007-08-05 20:53:13 +0200
14273 @@ -0,0 +1,43 @@
14274 +#ifndef _VX_CACCT_DEF_H
14275 +#define _VX_CACCT_DEF_H
14276 +
14277 +#include <asm/atomic.h>
14278 +#include <linux/vserver/cacct.h>
14279 +
14280 +
14281 +struct _vx_sock_acc {
14282 +       atomic_long_t count;
14283 +       atomic_long_t total;
14284 +};
14285 +
14286 +/* context sub struct */
14287 +
14288 +struct _vx_cacct {
14289 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
14290 +       atomic_t slab[8];
14291 +       atomic_t page[6][8];
14292 +};
14293 +
14294 +#ifdef CONFIG_VSERVER_DEBUG
14295 +
14296 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
14297 +{
14298 +       int i, j;
14299 +
14300 +       printk("\t_vx_cacct:");
14301 +       for (i = 0; i < 6; i++) {
14302 +               struct _vx_sock_acc *ptr = cacct->sock[i];
14303 +
14304 +               printk("\t [%d] =", i);
14305 +               for (j = 0; j < 3; j++) {
14306 +                       printk(" [%d] = %8lu, %8lu", j,
14307 +                               atomic_long_read(&ptr[j].count),
14308 +                               atomic_long_read(&ptr[j].total));
14309 +               }
14310 +               printk("\n");
14311 +       }
14312 +}
14313 +
14314 +#endif
14315 +
14316 +#endif /* _VX_CACCT_DEF_H */
14317 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
14318 --- linux-2.6.22.10/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00 +0100
14319 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_int.h        2007-08-05 20:53:13 +0200
14320 @@ -0,0 +1,21 @@
14321 +#ifndef _VX_CACCT_INT_H
14322 +#define _VX_CACCT_INT_H
14323 +
14324 +
14325 +#ifdef __KERNEL__
14326 +
14327 +static inline
14328 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
14329 +{
14330 +       return atomic_long_read(&cacct->sock[type][pos].count);
14331 +}
14332 +
14333 +
14334 +static inline
14335 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
14336 +{
14337 +       return atomic_long_read(&cacct->sock[type][pos].total);
14338 +}
14339 +
14340 +#endif /* __KERNEL__ */
14341 +#endif /* _VX_CACCT_INT_H */
14342 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
14343 --- linux-2.6.22.10/include/linux/vserver/context.h     1970-01-01 01:00:00 +0100
14344 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/context.h  2007-10-11 01:10:22 +0200
14345 @@ -0,0 +1,176 @@
14346 +#ifndef _VX_CONTEXT_H
14347 +#define _VX_CONTEXT_H
14348 +
14349 +#include <linux/types.h>
14350 +#include <linux/capability.h>
14351 +
14352 +
14353 +/* context flags */
14354 +
14355 +#define VXF_INFO_SCHED         0x00000002
14356 +#define VXF_INFO_NPROC         0x00000004
14357 +#define VXF_INFO_PRIVATE       0x00000008
14358 +
14359 +#define VXF_INFO_INIT          0x00000010
14360 +#define VXF_INFO_HIDE          0x00000020
14361 +#define VXF_INFO_ULIMIT                0x00000040
14362 +#define VXF_INFO_NSPACE                0x00000080
14363 +
14364 +#define VXF_SCHED_HARD         0x00000100
14365 +#define VXF_SCHED_PRIO         0x00000200
14366 +#define VXF_SCHED_PAUSE                0x00000400
14367 +
14368 +#define VXF_VIRT_MEM           0x00010000
14369 +#define VXF_VIRT_UPTIME                0x00020000
14370 +#define VXF_VIRT_CPU           0x00040000
14371 +#define VXF_VIRT_LOAD          0x00080000
14372 +#define VXF_VIRT_TIME          0x00100000
14373 +
14374 +#define VXF_HIDE_MOUNT         0x01000000
14375 +/* was VXF_HIDE_NETIF          0x02000000 */
14376 +#define VXF_HIDE_VINFO         0x04000000
14377 +
14378 +#define VXF_STATE_SETUP                (1ULL << 32)
14379 +#define VXF_STATE_INIT         (1ULL << 33)
14380 +#define VXF_STATE_ADMIN                (1ULL << 34)
14381 +
14382 +#define VXF_SC_HELPER          (1ULL << 36)
14383 +#define VXF_REBOOT_KILL                (1ULL << 37)
14384 +#define VXF_PERSISTENT         (1ULL << 38)
14385 +
14386 +#define VXF_FORK_RSS           (1ULL << 48)
14387 +#define VXF_PROLIFIC           (1ULL << 49)
14388 +
14389 +#define VXF_IGNEG_NICE         (1ULL << 52)
14390 +
14391 +#define VXF_ONE_TIME           (0x0007ULL << 32)
14392 +
14393 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
14394 +
14395 +
14396 +/* context migration */
14397 +
14398 +#define VXM_SET_INIT           0x00000001
14399 +#define VXM_SET_REAPER         0x00000002
14400 +
14401 +/* context caps */
14402 +
14403 +#define VXC_CAP_MASK           0x00000000
14404 +
14405 +#define VXC_SET_UTSNAME                0x00000001
14406 +#define VXC_SET_RLIMIT         0x00000002
14407 +
14408 +/* was VXC_RAW_ICMP            0x00000100 */
14409 +#define VXC_SYSLOG             0x00001000
14410 +
14411 +#define VXC_SECURE_MOUNT       0x00010000
14412 +#define VXC_SECURE_REMOUNT     0x00020000
14413 +#define VXC_BINARY_MOUNT       0x00040000
14414 +
14415 +#define VXC_QUOTA_CTL          0x00100000
14416 +#define VXC_ADMIN_MAPPER       0x00200000
14417 +#define VXC_ADMIN_CLOOP                0x00400000
14418 +
14419 +#define VXC_KTHREAD            0x01000000
14420 +
14421 +
14422 +#ifdef __KERNEL__
14423 +
14424 +#include <linux/list.h>
14425 +#include <linux/spinlock.h>
14426 +#include <linux/rcupdate.h>
14427 +
14428 +#include "limit_def.h"
14429 +#include "sched_def.h"
14430 +#include "cvirt_def.h"
14431 +#include "cacct_def.h"
14432 +#include "device_def.h"
14433 +
14434 +struct _vx_info_pc {
14435 +       struct _vx_sched_pc sched_pc;
14436 +       struct _vx_cvirt_pc cvirt_pc;
14437 +};
14438 +
14439 +struct vx_info {
14440 +       struct hlist_node vx_hlist;             /* linked list of contexts */
14441 +       xid_t vx_id;                            /* context id */
14442 +       atomic_t vx_usecnt;                     /* usage count */
14443 +       atomic_t vx_tasks;                      /* tasks count */
14444 +       struct vx_info *vx_parent;              /* parent context */
14445 +       int vx_state;                           /* context state */
14446 +
14447 +       unsigned long vx_nsmask;                /* assignment mask */
14448 +       struct nsproxy *vx_nsproxy;             /* private namespace */
14449 +       struct fs_struct *vx_fs;                /* private namespace fs */
14450 +
14451 +       uint64_t vx_flags;                      /* context flags */
14452 +       uint64_t vx_bcaps;                      /* bounding caps (system) */
14453 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
14454 +       kernel_cap_t vx_cap_bset;               /* the guest's bset */
14455 +
14456 +       struct task_struct *vx_reaper;          /* guest reaper process */
14457 +       pid_t vx_initpid;                       /* PID of guest init */
14458 +       int64_t vx_badness_bias;                /* OOM points bias */
14459 +
14460 +       struct _vx_limit limit;                 /* vserver limits */
14461 +       struct _vx_sched sched;                 /* vserver scheduler */
14462 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
14463 +       struct _vx_cacct cacct;                 /* context accounting */
14464 +
14465 +       struct _vx_device dmap;                 /* default device map targets */
14466 +
14467 +#ifndef CONFIG_SMP
14468 +       struct _vx_info_pc info_pc;             /* per cpu data */
14469 +#else
14470 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
14471 +#endif
14472 +
14473 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
14474 +       int reboot_cmd;                         /* last sys_reboot() cmd */
14475 +       int exit_code;                          /* last process exit code */
14476 +
14477 +       char vx_name[65];                       /* vserver name */
14478 +};
14479 +
14480 +#ifndef CONFIG_SMP
14481 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
14482 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
14483 +#else
14484 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
14485 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
14486 +#endif
14487 +
14488 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
14489 +
14490 +
14491 +struct vx_info_save {
14492 +       struct vx_info *vxi;
14493 +       xid_t xid;
14494 +};
14495 +
14496 +
14497 +/* status flags */
14498 +
14499 +#define VXS_HASHED     0x0001
14500 +#define VXS_PAUSED     0x0010
14501 +#define VXS_SHUTDOWN   0x0100
14502 +#define VXS_HELPER     0x1000
14503 +#define VXS_RELEASED   0x8000
14504 +
14505 +
14506 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
14507 +extern void release_vx_info(struct vx_info *, struct task_struct *);
14508 +
14509 +extern struct vx_info *lookup_vx_info(int);
14510 +extern struct vx_info *lookup_or_create_vx_info(int);
14511 +
14512 +extern int get_xid_list(int, unsigned int *, int);
14513 +extern int xid_is_hashed(xid_t);
14514 +
14515 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
14516 +
14517 +extern long vs_state_change(struct vx_info *, unsigned int);
14518 +
14519 +
14520 +#endif /* __KERNEL__ */
14521 +#endif /* _VX_CONTEXT_H */
14522 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
14523 --- linux-2.6.22.10/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00 +0100
14524 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/context_cmd.h      2007-08-19 00:40:28 +0200
14525 @@ -0,0 +1,128 @@
14526 +#ifndef _VX_CONTEXT_CMD_H
14527 +#define _VX_CONTEXT_CMD_H
14528 +
14529 +
14530 +/* vinfo commands */
14531 +
14532 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
14533 +
14534 +#ifdef __KERNEL__
14535 +extern int vc_task_xid(uint32_t);
14536 +
14537 +#endif /* __KERNEL__ */
14538 +
14539 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
14540 +
14541 +struct vcmd_vx_info_v0 {
14542 +       uint32_t xid;
14543 +       uint32_t initpid;
14544 +       /* more to come */
14545 +};
14546 +
14547 +#ifdef __KERNEL__
14548 +extern int vc_vx_info(struct vx_info *, void __user *);
14549 +
14550 +#endif /* __KERNEL__ */
14551 +
14552 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
14553 +
14554 +struct vcmd_ctx_stat_v0 {
14555 +       uint32_t usecnt;
14556 +       uint32_t tasks;
14557 +       /* more to come */
14558 +};
14559 +
14560 +#ifdef __KERNEL__
14561 +extern int vc_ctx_stat(struct vx_info *, void __user *);
14562 +
14563 +#endif /* __KERNEL__ */
14564 +
14565 +/* context commands */
14566 +
14567 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
14568 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
14569 +
14570 +struct vcmd_ctx_create {
14571 +       uint64_t flagword;
14572 +};
14573 +
14574 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
14575 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
14576 +
14577 +struct vcmd_ctx_migrate {
14578 +       uint64_t flagword;
14579 +};
14580 +
14581 +#ifdef __KERNEL__
14582 +extern int vc_ctx_create(uint32_t, void __user *);
14583 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
14584 +
14585 +#endif /* __KERNEL__ */
14586 +
14587 +
14588 +/* flag commands */
14589 +
14590 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
14591 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
14592 +
14593 +struct vcmd_ctx_flags_v0 {
14594 +       uint64_t flagword;
14595 +       uint64_t mask;
14596 +};
14597 +
14598 +#ifdef __KERNEL__
14599 +extern int vc_get_cflags(struct vx_info *, void __user *);
14600 +extern int vc_set_cflags(struct vx_info *, void __user *);
14601 +
14602 +#endif /* __KERNEL__ */
14603 +
14604 +
14605 +/* context caps commands */
14606 +
14607 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
14608 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
14609 +
14610 +struct vcmd_ctx_caps_v1 {
14611 +       uint64_t ccaps;
14612 +       uint64_t cmask;
14613 +};
14614 +
14615 +#ifdef __KERNEL__
14616 +extern int vc_get_ccaps(struct vx_info *, void __user *);
14617 +extern int vc_set_ccaps(struct vx_info *, void __user *);
14618 +
14619 +#endif /* __KERNEL__ */
14620 +
14621 +
14622 +/* bcaps commands */
14623 +
14624 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
14625 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
14626 +
14627 +struct vcmd_bcaps {
14628 +       uint64_t bcaps;
14629 +       uint64_t bmask;
14630 +};
14631 +
14632 +#ifdef __KERNEL__
14633 +extern int vc_get_bcaps(struct vx_info *, void __user *);
14634 +extern int vc_set_bcaps(struct vx_info *, void __user *);
14635 +
14636 +#endif /* __KERNEL__ */
14637 +
14638 +
14639 +/* OOM badness */
14640 +
14641 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
14642 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
14643 +
14644 +struct vcmd_badness_v0 {
14645 +       int64_t bias;
14646 +};
14647 +
14648 +#ifdef __KERNEL__
14649 +extern int vc_get_badness(struct vx_info *, void __user *);
14650 +extern int vc_set_badness(struct vx_info *, void __user *);
14651 +
14652 +#endif /* __KERNEL__ */
14653 +#endif /* _VX_CONTEXT_CMD_H */
14654 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
14655 --- linux-2.6.22.10/include/linux/vserver/cvirt.h       1970-01-01 01:00:00 +0100
14656 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt.h    2007-08-05 20:53:13 +0200
14657 @@ -0,0 +1,20 @@
14658 +#ifndef _VX_CVIRT_H
14659 +#define _VX_CVIRT_H
14660 +
14661 +
14662 +#ifdef __KERNEL__
14663 +
14664 +struct timespec;
14665 +
14666 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14667 +
14668 +
14669 +struct vx_info;
14670 +
14671 +void vx_update_load(struct vx_info *);
14672 +
14673 +
14674 +int vx_do_syslog(int, char __user *, int);
14675 +
14676 +#endif /* __KERNEL__ */
14677 +#endif /* _VX_CVIRT_H */
14678 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
14679 --- linux-2.6.22.10/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00 +0100
14680 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt_cmd.h        2007-08-05 20:53:13 +0200
14681 @@ -0,0 +1,53 @@
14682 +#ifndef _VX_CVIRT_CMD_H
14683 +#define _VX_CVIRT_CMD_H
14684 +
14685 +
14686 +/* virtual host info name commands */
14687 +
14688 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
14689 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
14690 +
14691 +struct vcmd_vhi_name_v0 {
14692 +       uint32_t field;
14693 +       char name[65];
14694 +};
14695 +
14696 +
14697 +enum vhi_name_field {
14698 +       VHIN_CONTEXT = 0,
14699 +       VHIN_SYSNAME,
14700 +       VHIN_NODENAME,
14701 +       VHIN_RELEASE,
14702 +       VHIN_VERSION,
14703 +       VHIN_MACHINE,
14704 +       VHIN_DOMAINNAME,
14705 +};
14706 +
14707 +
14708 +#ifdef __KERNEL__
14709 +
14710 +#include <linux/compiler.h>
14711 +
14712 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
14713 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
14714 +
14715 +#endif /* __KERNEL__ */
14716 +
14717 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
14718 +
14719 +struct vcmd_virt_stat_v0 {
14720 +       uint64_t offset;
14721 +       uint64_t uptime;
14722 +       uint32_t nr_threads;
14723 +       uint32_t nr_running;
14724 +       uint32_t nr_uninterruptible;
14725 +       uint32_t nr_onhold;
14726 +       uint32_t nr_forks;
14727 +       uint32_t load[3];
14728 +};
14729 +
14730 +#ifdef __KERNEL__
14731 +extern int vc_virt_stat(struct vx_info *, void __user *);
14732 +
14733 +#endif /* __KERNEL__ */
14734 +#endif /* _VX_CVIRT_CMD_H */
14735 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
14736 --- linux-2.6.22.10/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00 +0100
14737 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt_def.h        2007-08-05 20:53:13 +0200
14738 @@ -0,0 +1,81 @@
14739 +#ifndef _VX_CVIRT_DEF_H
14740 +#define _VX_CVIRT_DEF_H
14741 +
14742 +#include <linux/jiffies.h>
14743 +#include <linux/spinlock.h>
14744 +#include <linux/wait.h>
14745 +#include <linux/time.h>
14746 +#include <linux/utsname.h>
14747 +#include <asm/atomic.h>
14748 +
14749 +
14750 +struct _vx_usage_stat {
14751 +       uint64_t user;
14752 +       uint64_t nice;
14753 +       uint64_t system;
14754 +       uint64_t softirq;
14755 +       uint64_t irq;
14756 +       uint64_t idle;
14757 +       uint64_t iowait;
14758 +};
14759 +
14760 +struct _vx_syslog {
14761 +       wait_queue_head_t log_wait;
14762 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
14763 +
14764 +       unsigned long log_start;        /* next char to be read by syslog() */
14765 +       unsigned long con_start;        /* next char to be sent to consoles */
14766 +       unsigned long log_end;  /* most-recently-written-char + 1 */
14767 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
14768 +
14769 +       char log_buf[1024];
14770 +};
14771 +
14772 +
14773 +/* context sub struct */
14774 +
14775 +struct _vx_cvirt {
14776 +       atomic_t nr_threads;            /* number of current threads */
14777 +       atomic_t nr_running;            /* number of running threads */
14778 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
14779 +
14780 +       atomic_t nr_onhold;             /* processes on hold */
14781 +       uint32_t onhold_last;           /* jiffies when put on hold */
14782 +
14783 +       struct timeval bias_tv;         /* time offset to the host */
14784 +       struct timespec bias_idle;
14785 +       struct timespec bias_uptime;    /* context creation point */
14786 +       uint64_t bias_clock;            /* offset in clock_t */
14787 +
14788 +       spinlock_t load_lock;           /* lock for the load averages */
14789 +       atomic_t load_updates;          /* nr of load updates done so far */
14790 +       uint32_t load_last;             /* last time load was calculated */
14791 +       uint32_t load[3];               /* load averages 1,5,15 */
14792 +
14793 +       atomic_t total_forks;           /* number of forks so far */
14794 +
14795 +       struct _vx_syslog syslog;
14796 +};
14797 +
14798 +struct _vx_cvirt_pc {
14799 +       struct _vx_usage_stat cpustat;
14800 +};
14801 +
14802 +
14803 +#ifdef CONFIG_VSERVER_DEBUG
14804 +
14805 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
14806 +{
14807 +       printk("\t_vx_cvirt:\n");
14808 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
14809 +               atomic_read(&cvirt->nr_threads),
14810 +               atomic_read(&cvirt->nr_running),
14811 +               atomic_read(&cvirt->nr_uninterruptible),
14812 +               atomic_read(&cvirt->nr_onhold));
14813 +       /* add rest here */
14814 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
14815 +}
14816 +
14817 +#endif
14818 +
14819 +#endif /* _VX_CVIRT_DEF_H */
14820 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
14821 --- linux-2.6.22.10/include/linux/vserver/debug.h       1970-01-01 01:00:00 +0100
14822 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/debug.h    2007-10-25 17:05:55 +0200
14823 @@ -0,0 +1,130 @@
14824 +#ifndef _VX_DEBUG_H
14825 +#define _VX_DEBUG_H
14826 +
14827 +
14828 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
14829 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
14830 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
14831 +
14832 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
14833 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
14834 +#define VXF_DEV                "%p[%lu,%d:%d]"
14835 +
14836 +
14837 +#define __FUNC__       __func__
14838 +
14839 +
14840 +#define vxd_path(d, m)                                         \
14841 +       ({ static char _buffer[PATH_MAX];                       \
14842 +          d_path(d, m, _buffer, sizeof(_buffer)); })
14843 +
14844 +#define vxd_cond_path(n)                                       \
14845 +       ((n) ? vxd_path((n)->dentry, (n)->mnt) : "<null>" )
14846 +
14847 +
14848 +#ifdef CONFIG_VSERVER_DEBUG
14849 +
14850 +extern unsigned int vx_debug_switch;
14851 +extern unsigned int vx_debug_xid;
14852 +extern unsigned int vx_debug_nid;
14853 +extern unsigned int vx_debug_tag;
14854 +extern unsigned int vx_debug_net;
14855 +extern unsigned int vx_debug_limit;
14856 +extern unsigned int vx_debug_cres;
14857 +extern unsigned int vx_debug_dlim;
14858 +extern unsigned int vx_debug_quota;
14859 +extern unsigned int vx_debug_cvirt;
14860 +extern unsigned int vx_debug_space;
14861 +extern unsigned int vx_debug_misc;
14862 +
14863 +
14864 +#define VX_LOGLEVEL    "vxD: "
14865 +#define VX_PROC_FMT    "%p: "
14866 +#define VX_PROCESS     current
14867 +
14868 +#define vxdprintk(c, f, x...)                                  \
14869 +       do {                                                    \
14870 +               if (c)                                          \
14871 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
14872 +                               VX_PROCESS , ##x);              \
14873 +       } while (0)
14874 +
14875 +#define vxlprintk(c, f, x...)                                  \
14876 +       do {                                                    \
14877 +               if (c)                                          \
14878 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
14879 +       } while (0)
14880 +
14881 +#define vxfprintk(c, f, x...)                                  \
14882 +       do {                                                    \
14883 +               if (c)                                          \
14884 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
14885 +       } while (0)
14886 +
14887 +
14888 +struct vx_info;
14889 +
14890 +void dump_vx_info(struct vx_info *, int);
14891 +void dump_vx_info_inactive(int);
14892 +
14893 +#else  /* CONFIG_VSERVER_DEBUG */
14894 +
14895 +#define vx_debug_switch 0
14896 +#define vx_debug_xid   0
14897 +#define vx_debug_nid   0
14898 +#define vx_debug_tag   0
14899 +#define vx_debug_net   0
14900 +#define vx_debug_limit 0
14901 +#define vx_debug_cres  0
14902 +#define vx_debug_dlim  0
14903 +#define vx_debug_cvirt 0
14904 +
14905 +#define vxdprintk(x...) do { } while (0)
14906 +#define vxlprintk(x...) do { } while (0)
14907 +#define vxfprintk(x...) do { } while (0)
14908 +
14909 +#endif /* CONFIG_VSERVER_DEBUG */
14910 +
14911 +
14912 +#ifdef CONFIG_VSERVER_WARN
14913 +
14914 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
14915 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
14916 +#define VX_WARN_XID    "[xid #%u] "
14917 +#define VX_WARN_NID    "[nid #%u] "
14918 +#define VX_WARN_TAG    "[tag #%u] "
14919 +
14920 +#define vxwprintk(c, f, x...)                                  \
14921 +       do {                                                    \
14922 +               if (c)                                          \
14923 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
14924 +       } while (0)
14925 +
14926 +#else  /* CONFIG_VSERVER_WARN */
14927 +
14928 +#define vxwprintk(x...) do { } while (0)
14929 +
14930 +#endif /* CONFIG_VSERVER_WARN */
14931 +
14932 +#define vxwprintk_task(c, f, x...)                             \
14933 +       vxwprintk(c, VX_WARN_TASK f,                            \
14934 +               current->comm, current->pid,                    \
14935 +               current->xid, current->nid, current->tag, ##x)
14936 +#define vxwprintk_xid(c, f, x...)                              \
14937 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
14938 +#define vxwprintk_nid(c, f, x...)                              \
14939 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
14940 +#define vxwprintk_tag(c, f, x...)                              \
14941 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
14942 +
14943 +#ifdef CONFIG_VSERVER_DEBUG
14944 +#define vxd_assert_lock(l)     assert_spin_locked(l)
14945 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
14946 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
14947 +#else
14948 +#define vxd_assert_lock(l)     do { } while (0)
14949 +#define vxd_assert(c, f, x...) do { } while (0)
14950 +#endif
14951 +
14952 +
14953 +#endif /* _VX_DEBUG_H */
14954 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
14955 --- linux-2.6.22.10/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00 +0100
14956 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/debug_cmd.h        2007-08-05 20:53:13 +0200
14957 @@ -0,0 +1,58 @@
14958 +#ifndef _VX_DEBUG_CMD_H
14959 +#define _VX_DEBUG_CMD_H
14960 +
14961 +
14962 +/* debug commands */
14963 +
14964 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
14965 +
14966 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
14967 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
14968 +
14969 +struct  vcmd_read_history_v0 {
14970 +       uint32_t index;
14971 +       uint32_t count;
14972 +       char __user *data;
14973 +};
14974 +
14975 +struct  vcmd_read_monitor_v0 {
14976 +       uint32_t index;
14977 +       uint32_t count;
14978 +       char __user *data;
14979 +};
14980 +
14981 +
14982 +#ifdef __KERNEL__
14983 +
14984 +#ifdef CONFIG_COMPAT
14985 +
14986 +#include <asm/compat.h>
14987 +
14988 +struct vcmd_read_history_v0_x32 {
14989 +       uint32_t index;
14990 +       uint32_t count;
14991 +       compat_uptr_t data_ptr;
14992 +};
14993 +
14994 +struct vcmd_read_monitor_v0_x32 {
14995 +       uint32_t index;
14996 +       uint32_t count;
14997 +       compat_uptr_t data_ptr;
14998 +};
14999 +
15000 +#endif  /* CONFIG_COMPAT */
15001 +
15002 +extern int vc_dump_history(uint32_t);
15003 +
15004 +extern int vc_read_history(uint32_t, void __user *);
15005 +extern int vc_read_monitor(uint32_t, void __user *);
15006 +
15007 +#ifdef CONFIG_COMPAT
15008 +
15009 +extern int vc_read_history_x32(uint32_t, void __user *);
15010 +extern int vc_read_monitor_x32(uint32_t, void __user *);
15011 +
15012 +#endif  /* CONFIG_COMPAT */
15013 +
15014 +#endif /* __KERNEL__ */
15015 +#endif /* _VX_DEBUG_CMD_H */
15016 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
15017 --- linux-2.6.22.10/include/linux/vserver/device.h      1970-01-01 01:00:00 +0100
15018 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device.h   2007-10-11 01:10:22 +0200
15019 @@ -0,0 +1,15 @@
15020 +#ifndef _VX_DEVICE_H
15021 +#define _VX_DEVICE_H
15022 +
15023 +
15024 +#define DATTR_CREATE   0x00000001
15025 +#define DATTR_OPEN     0x00000002
15026 +
15027 +#define DATTR_REMAP    0x00000010
15028 +
15029 +#define DATTR_MASK     0x00000013
15030 +
15031 +
15032 +#else  /* _VX_DEVICE_H */
15033 +#warning duplicate inclusion
15034 +#endif /* _VX_DEVICE_H */
15035 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
15036 --- linux-2.6.22.10/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00 +0100
15037 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device_cmd.h       2007-10-11 01:10:22 +0200
15038 @@ -0,0 +1,44 @@
15039 +#ifndef _VX_DEVICE_CMD_H
15040 +#define _VX_DEVICE_CMD_H
15041 +
15042 +
15043 +/*  device vserver commands */
15044 +
15045 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
15046 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
15047 +
15048 +struct vcmd_set_mapping_v0 {
15049 +       const char __user *device;
15050 +       const char __user *target;
15051 +       uint32_t flags;
15052 +};
15053 +
15054 +
15055 +#ifdef __KERNEL__
15056 +
15057 +#ifdef CONFIG_COMPAT
15058 +
15059 +#include <asm/compat.h>
15060 +
15061 +struct vcmd_set_mapping_v0_x32 {
15062 +       compat_uptr_t device_ptr;
15063 +       compat_uptr_t target_ptr;
15064 +       uint32_t flags;
15065 +};
15066 +
15067 +#endif /* CONFIG_COMPAT */
15068 +
15069 +#include <linux/compiler.h>
15070 +
15071 +extern int vc_set_mapping(struct vx_info *, void __user *);
15072 +extern int vc_unset_mapping(struct vx_info *, void __user *);
15073 +
15074 +#ifdef CONFIG_COMPAT
15075 +
15076 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
15077 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
15078 +
15079 +#endif /* CONFIG_COMPAT */
15080 +
15081 +#endif /* __KERNEL__ */
15082 +#endif /* _VX_DEVICE_CMD_H */
15083 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
15084 --- linux-2.6.22.10/include/linux/vserver/device_def.h  1970-01-01 01:00:00 +0100
15085 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device_def.h       2007-10-11 01:10:22 +0200
15086 @@ -0,0 +1,17 @@
15087 +#ifndef _VX_DEVICE_DEF_H
15088 +#define _VX_DEVICE_DEF_H
15089 +
15090 +#include <linux/types.h>
15091 +
15092 +struct vx_dmap_target {
15093 +       dev_t target;
15094 +       uint32_t flags;
15095 +};
15096 +
15097 +struct _vx_device {
15098 +#ifdef CONFIG_VSERVER_DEVICE
15099 +       struct vx_dmap_target targets[2];
15100 +#endif
15101 +};
15102 +
15103 +#endif /* _VX_DEVICE_DEF_H */
15104 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
15105 --- linux-2.6.22.10/include/linux/vserver/dlimit.h      1970-01-01 01:00:00 +0100
15106 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/dlimit.h   2007-08-15 22:03:58 +0200
15107 @@ -0,0 +1,54 @@
15108 +#ifndef _VX_DLIMIT_H
15109 +#define _VX_DLIMIT_H
15110 +
15111 +#include "switch.h"
15112 +
15113 +
15114 +#ifdef __KERNEL__
15115 +
15116 +/*      keep in sync with CDLIM_INFINITY       */
15117 +
15118 +#define DLIM_INFINITY          (~0ULL)
15119 +
15120 +#include <linux/spinlock.h>
15121 +#include <linux/rcupdate.h>
15122 +
15123 +struct super_block;
15124 +
15125 +struct dl_info {
15126 +       struct hlist_node dl_hlist;             /* linked list of contexts */
15127 +       struct rcu_head dl_rcu;                 /* the rcu head */
15128 +       tag_t dl_tag;                           /* context tag */
15129 +       atomic_t dl_usecnt;                     /* usage count */
15130 +       atomic_t dl_refcnt;                     /* reference count */
15131 +
15132 +       struct super_block *dl_sb;              /* associated superblock */
15133 +
15134 +       spinlock_t dl_lock;                     /* protect the values */
15135 +
15136 +       unsigned long long dl_space_used;       /* used space in bytes */
15137 +       unsigned long long dl_space_total;      /* maximum space in bytes */
15138 +       unsigned long dl_inodes_used;           /* used inodes */
15139 +       unsigned long dl_inodes_total;          /* maximum inodes */
15140 +
15141 +       unsigned int dl_nrlmult;                /* non root limit mult */
15142 +};
15143 +
15144 +struct rcu_head;
15145 +
15146 +extern void rcu_free_dl_info(struct rcu_head *);
15147 +extern void unhash_dl_info(struct dl_info *);
15148 +
15149 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
15150 +
15151 +
15152 +struct kstatfs;
15153 +
15154 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
15155 +
15156 +typedef uint64_t dlsize_t;
15157 +
15158 +#endif /* __KERNEL__ */
15159 +#else  /* _VX_DLIMIT_H */
15160 +#warning duplicate inclusion
15161 +#endif /* _VX_DLIMIT_H */
15162 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
15163 --- linux-2.6.22.10/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00 +0100
15164 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/dlimit_cmd.h       2007-08-05 20:53:13 +0200
15165 @@ -0,0 +1,74 @@
15166 +#ifndef _VX_DLIMIT_CMD_H
15167 +#define _VX_DLIMIT_CMD_H
15168 +
15169 +
15170 +/*  dlimit vserver commands */
15171 +
15172 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
15173 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
15174 +
15175 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
15176 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
15177 +
15178 +struct vcmd_ctx_dlimit_base_v0 {
15179 +       const char __user *name;
15180 +       uint32_t flags;
15181 +};
15182 +
15183 +struct vcmd_ctx_dlimit_v0 {
15184 +       const char __user *name;
15185 +       uint32_t space_used;                    /* used space in kbytes */
15186 +       uint32_t space_total;                   /* maximum space in kbytes */
15187 +       uint32_t inodes_used;                   /* used inodes */
15188 +       uint32_t inodes_total;                  /* maximum inodes */
15189 +       uint32_t reserved;                      /* reserved for root in % */
15190 +       uint32_t flags;
15191 +};
15192 +
15193 +#define CDLIM_UNSET            ((uint32_t)0UL)
15194 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
15195 +#define CDLIM_KEEP             ((uint32_t)~1UL)
15196 +
15197 +#ifdef __KERNEL__
15198 +
15199 +#ifdef CONFIG_COMPAT
15200 +
15201 +#include <asm/compat.h>
15202 +
15203 +struct vcmd_ctx_dlimit_base_v0_x32 {
15204 +       compat_uptr_t name_ptr;
15205 +       uint32_t flags;
15206 +};
15207 +
15208 +struct vcmd_ctx_dlimit_v0_x32 {
15209 +       compat_uptr_t name_ptr;
15210 +       uint32_t space_used;                    /* used space in kbytes */
15211 +       uint32_t space_total;                   /* maximum space in kbytes */
15212 +       uint32_t inodes_used;                   /* used inodes */
15213 +       uint32_t inodes_total;                  /* maximum inodes */
15214 +       uint32_t reserved;                      /* reserved for root in % */
15215 +       uint32_t flags;
15216 +};
15217 +
15218 +#endif /* CONFIG_COMPAT */
15219 +
15220 +#include <linux/compiler.h>
15221 +
15222 +extern int vc_add_dlimit(uint32_t, void __user *);
15223 +extern int vc_rem_dlimit(uint32_t, void __user *);
15224 +
15225 +extern int vc_set_dlimit(uint32_t, void __user *);
15226 +extern int vc_get_dlimit(uint32_t, void __user *);
15227 +
15228 +#ifdef CONFIG_COMPAT
15229 +
15230 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
15231 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
15232 +
15233 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
15234 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
15235 +
15236 +#endif /* CONFIG_COMPAT */
15237 +
15238 +#endif /* __KERNEL__ */
15239 +#endif /* _VX_DLIMIT_CMD_H */
15240 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
15241 --- linux-2.6.22.10/include/linux/vserver/global.h      1970-01-01 01:00:00 +0100
15242 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/global.h   2007-08-05 20:53:13 +0200
15243 @@ -0,0 +1,18 @@
15244 +#ifndef _VX_GLOBAL_H
15245 +#define _VX_GLOBAL_H
15246 +
15247 +
15248 +extern atomic_t vx_global_ctotal;
15249 +extern atomic_t vx_global_cactive;
15250 +
15251 +extern atomic_t nx_global_ctotal;
15252 +extern atomic_t nx_global_cactive;
15253 +
15254 +extern atomic_t vs_global_nsproxy;
15255 +extern atomic_t vs_global_fs;
15256 +extern atomic_t vs_global_mnt_ns;
15257 +extern atomic_t vs_global_uts_ns;
15258 +extern atomic_t vs_global_ipc_ns;
15259 +
15260 +
15261 +#endif /* _VX_GLOBAL_H */
15262 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
15263 --- linux-2.6.22.10/include/linux/vserver/history.h     1970-01-01 01:00:00 +0100
15264 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/history.h  2007-08-05 20:53:13 +0200
15265 @@ -0,0 +1,197 @@
15266 +#ifndef _VX_HISTORY_H
15267 +#define _VX_HISTORY_H
15268 +
15269 +
15270 +enum {
15271 +       VXH_UNUSED = 0,
15272 +       VXH_THROW_OOPS = 1,
15273 +
15274 +       VXH_GET_VX_INFO,
15275 +       VXH_PUT_VX_INFO,
15276 +       VXH_INIT_VX_INFO,
15277 +       VXH_SET_VX_INFO,
15278 +       VXH_CLR_VX_INFO,
15279 +       VXH_CLAIM_VX_INFO,
15280 +       VXH_RELEASE_VX_INFO,
15281 +       VXH_ALLOC_VX_INFO,
15282 +       VXH_DEALLOC_VX_INFO,
15283 +       VXH_HASH_VX_INFO,
15284 +       VXH_UNHASH_VX_INFO,
15285 +       VXH_LOC_VX_INFO,
15286 +       VXH_LOOKUP_VX_INFO,
15287 +       VXH_CREATE_VX_INFO,
15288 +};
15289 +
15290 +struct _vxhe_vxi {
15291 +       struct vx_info *ptr;
15292 +       unsigned xid;
15293 +       unsigned usecnt;
15294 +       unsigned tasks;
15295 +};
15296 +
15297 +struct _vxhe_set_clr {
15298 +       void *data;
15299 +};
15300 +
15301 +struct _vxhe_loc_lookup {
15302 +       unsigned arg;
15303 +};
15304 +
15305 +struct _vx_hist_entry {
15306 +       void *loc;
15307 +       unsigned short seq;
15308 +       unsigned short type;
15309 +       struct _vxhe_vxi vxi;
15310 +       union {
15311 +               struct _vxhe_set_clr sc;
15312 +               struct _vxhe_loc_lookup ll;
15313 +       };
15314 +};
15315 +
15316 +#ifdef CONFIG_VSERVER_HISTORY
15317 +
15318 +extern unsigned volatile int vxh_active;
15319 +
15320 +struct _vx_hist_entry *vxh_advance(void *loc);
15321 +
15322 +
15323 +static inline
15324 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
15325 +{
15326 +       entry->vxi.ptr = vxi;
15327 +       if (vxi) {
15328 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
15329 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
15330 +               entry->vxi.xid = vxi->vx_id;
15331 +       }
15332 +}
15333 +
15334 +
15335 +#define        __HERE__ current_text_addr()
15336 +
15337 +#define __VXH_BODY(__type, __data, __here)     \
15338 +       struct _vx_hist_entry *entry;           \
15339 +                                               \
15340 +       preempt_disable();                      \
15341 +       entry = vxh_advance(__here);            \
15342 +       __data;                                 \
15343 +       entry->type = __type;                   \
15344 +       preempt_enable();
15345 +
15346 +
15347 +       /* pass vxi only */
15348 +
15349 +#define __VXH_SMPL                             \
15350 +       __vxh_copy_vxi(entry, vxi)
15351 +
15352 +static inline
15353 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
15354 +{
15355 +       __VXH_BODY(__type, __VXH_SMPL, __here)
15356 +}
15357 +
15358 +       /* pass vxi and data (void *) */
15359 +
15360 +#define __VXH_DATA                             \
15361 +       __vxh_copy_vxi(entry, vxi);             \
15362 +       entry->sc.data = data
15363 +
15364 +static inline
15365 +void   __vxh_data(struct vx_info *vxi, void *data,
15366 +                       int __type, void *__here)
15367 +{
15368 +       __VXH_BODY(__type, __VXH_DATA, __here)
15369 +}
15370 +
15371 +       /* pass vxi and arg (long) */
15372 +
15373 +#define __VXH_LONG                             \
15374 +       __vxh_copy_vxi(entry, vxi);             \
15375 +       entry->ll.arg = arg
15376 +
15377 +static inline
15378 +void   __vxh_long(struct vx_info *vxi, long arg,
15379 +                       int __type, void *__here)
15380 +{
15381 +       __VXH_BODY(__type, __VXH_LONG, __here)
15382 +}
15383 +
15384 +
15385 +static inline
15386 +void   __vxh_throw_oops(void *__here)
15387 +{
15388 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
15389 +       /* prevent further acquisition */
15390 +       vxh_active = 0;
15391 +}
15392 +
15393 +
15394 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
15395 +
15396 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
15397 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
15398 +
15399 +#define __vxh_init_vx_info(v, d, h) \
15400 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
15401 +#define __vxh_set_vx_info(v, d, h) \
15402 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
15403 +#define __vxh_clr_vx_info(v, d, h) \
15404 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
15405 +
15406 +#define __vxh_claim_vx_info(v, d, h) \
15407 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
15408 +#define __vxh_release_vx_info(v, d, h) \
15409 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
15410 +
15411 +#define vxh_alloc_vx_info(v) \
15412 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
15413 +#define vxh_dealloc_vx_info(v) \
15414 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
15415 +
15416 +#define vxh_hash_vx_info(v) \
15417 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
15418 +#define vxh_unhash_vx_info(v) \
15419 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
15420 +
15421 +#define vxh_loc_vx_info(v, l) \
15422 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
15423 +#define vxh_lookup_vx_info(v, l) \
15424 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
15425 +#define vxh_create_vx_info(v, l) \
15426 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
15427 +
15428 +extern void vxh_dump_history(void);
15429 +
15430 +
15431 +#else  /* CONFIG_VSERVER_HISTORY */
15432 +
15433 +#define        __HERE__        0
15434 +
15435 +#define vxh_throw_oops()               do { } while (0)
15436 +
15437 +#define __vxh_get_vx_info(v, h)                do { } while (0)
15438 +#define __vxh_put_vx_info(v, h)                do { } while (0)
15439 +
15440 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
15441 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
15442 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
15443 +
15444 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
15445 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
15446 +
15447 +#define vxh_alloc_vx_info(v)           do { } while (0)
15448 +#define vxh_dealloc_vx_info(v)         do { } while (0)
15449 +
15450 +#define vxh_hash_vx_info(v)            do { } while (0)
15451 +#define vxh_unhash_vx_info(v)          do { } while (0)
15452 +
15453 +#define vxh_loc_vx_info(v, l)          do { } while (0)
15454 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
15455 +#define vxh_create_vx_info(v, l)       do { } while (0)
15456 +
15457 +#define vxh_dump_history()             do { } while (0)
15458 +
15459 +
15460 +#endif /* CONFIG_VSERVER_HISTORY */
15461 +
15462 +#endif /* _VX_HISTORY_H */
15463 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
15464 --- linux-2.6.22.10/include/linux/vserver/inode.h       1970-01-01 01:00:00 +0100
15465 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/inode.h    2007-08-05 20:53:13 +0200
15466 @@ -0,0 +1,38 @@
15467 +#ifndef _VX_INODE_H
15468 +#define _VX_INODE_H
15469 +
15470 +
15471 +#define IATTR_TAG      0x01000000
15472 +
15473 +#define IATTR_ADMIN    0x00000001
15474 +#define IATTR_WATCH    0x00000002
15475 +#define IATTR_HIDE     0x00000004
15476 +#define IATTR_FLAGS    0x00000007
15477 +
15478 +#define IATTR_BARRIER  0x00010000
15479 +#define IATTR_IUNLINK  0x00020000
15480 +#define IATTR_IMMUTABLE 0x00040000
15481 +
15482 +#ifdef __KERNEL__
15483 +
15484 +
15485 +#ifdef CONFIG_VSERVER_PROC_SECURE
15486 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
15487 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
15488 +#else
15489 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
15490 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
15491 +#endif
15492 +
15493 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
15494 +
15495 +#endif /* __KERNEL__ */
15496 +
15497 +/* inode ioctls */
15498 +
15499 +#define FIOC_GETXFLG   _IOR('x', 5, long)
15500 +#define FIOC_SETXFLG   _IOW('x', 6, long)
15501 +
15502 +#else  /* _VX_INODE_H */
15503 +#warning duplicate inclusion
15504 +#endif /* _VX_INODE_H */
15505 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
15506 --- linux-2.6.22.10/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00 +0100
15507 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/inode_cmd.h        2007-08-15 18:08:31 +0200
15508 @@ -0,0 +1,59 @@
15509 +#ifndef _VX_INODE_CMD_H
15510 +#define _VX_INODE_CMD_H
15511 +
15512 +
15513 +/*  inode vserver commands */
15514 +
15515 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
15516 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
15517 +
15518 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
15519 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
15520 +
15521 +struct vcmd_ctx_iattr_v1 {
15522 +       const char __user *name;
15523 +       uint32_t tag;
15524 +       uint32_t flags;
15525 +       uint32_t mask;
15526 +};
15527 +
15528 +struct vcmd_ctx_fiattr_v0 {
15529 +       uint32_t tag;
15530 +       uint32_t flags;
15531 +       uint32_t mask;
15532 +};
15533 +
15534 +
15535 +#ifdef __KERNEL__
15536 +
15537 +
15538 +#ifdef CONFIG_COMPAT
15539 +
15540 +#include <asm/compat.h>
15541 +
15542 +struct vcmd_ctx_iattr_v1_x32 {
15543 +       compat_uptr_t name_ptr;
15544 +       uint32_t tag;
15545 +       uint32_t flags;
15546 +       uint32_t mask;
15547 +};
15548 +
15549 +#endif /* CONFIG_COMPAT */
15550 +
15551 +#include <linux/compiler.h>
15552 +
15553 +extern int vc_get_iattr(void __user *);
15554 +extern int vc_set_iattr(void __user *);
15555 +
15556 +extern int vc_fget_iattr(uint32_t, void __user *);
15557 +extern int vc_fset_iattr(uint32_t, void __user *);
15558 +
15559 +#ifdef CONFIG_COMPAT
15560 +
15561 +extern int vc_get_iattr_x32(void __user *);
15562 +extern int vc_set_iattr_x32(void __user *);
15563 +
15564 +#endif /* CONFIG_COMPAT */
15565 +
15566 +#endif /* __KERNEL__ */
15567 +#endif /* _VX_INODE_CMD_H */
15568 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
15569 --- linux-2.6.22.10/include/linux/vserver/limit.h       1970-01-01 01:00:00 +0100
15570 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit.h    2007-08-15 22:27:29 +0200
15571 @@ -0,0 +1,70 @@
15572 +#ifndef _VX_LIMIT_H
15573 +#define _VX_LIMIT_H
15574 +
15575 +#define VLIMIT_NSOCK   16
15576 +#define VLIMIT_OPENFD  17
15577 +#define VLIMIT_ANON    18
15578 +#define VLIMIT_SHMEM   19
15579 +#define VLIMIT_SEMARY  20
15580 +#define VLIMIT_NSEMS   21
15581 +#define VLIMIT_DENTRY  22
15582 +#define VLIMIT_MAPPED  23
15583 +
15584 +
15585 +#ifdef __KERNEL__
15586 +
15587 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
15588 +
15589 +/*     keep in sync with CRLIM_INFINITY */
15590 +
15591 +#define        VLIM_INFINITY   (~0ULL)
15592 +
15593 +#include <asm/atomic.h>
15594 +#include <asm/resource.h>
15595 +
15596 +#ifndef RLIM_INFINITY
15597 +#warning RLIM_INFINITY is undefined
15598 +#endif
15599 +
15600 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
15601 +
15602 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
15603 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
15604 +
15605 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
15606 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
15607 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
15608 +
15609 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
15610 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
15611 +
15612 +typedef atomic_long_t rlim_atomic_t;
15613 +typedef unsigned long rlim_t;
15614 +
15615 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
15616 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
15617 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
15618 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
15619 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
15620 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
15621 +
15622 +
15623 +#if    (RLIM_INFINITY == VLIM_INFINITY)
15624 +#define        VX_VLIM(r) ((long long)(long)(r))
15625 +#define        VX_RLIM(v) ((rlim_t)(v))
15626 +#else
15627 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
15628 +               ? VLIM_INFINITY : (long long)(r))
15629 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
15630 +               ? RLIM_INFINITY : (rlim_t)(v))
15631 +#endif
15632 +
15633 +struct sysinfo;
15634 +
15635 +void vx_vsi_meminfo(struct sysinfo *);
15636 +void vx_vsi_swapinfo(struct sysinfo *);
15637 +
15638 +#define NUM_LIMITS     24
15639 +
15640 +#endif /* __KERNEL__ */
15641 +#endif /* _VX_LIMIT_H */
15642 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
15643 --- linux-2.6.22.10/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00 +0100
15644 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_cmd.h        2007-08-05 20:53:13 +0200
15645 @@ -0,0 +1,69 @@
15646 +#ifndef _VX_LIMIT_CMD_H
15647 +#define _VX_LIMIT_CMD_H
15648 +
15649 +
15650 +/*  rlimit vserver commands */
15651 +
15652 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
15653 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
15654 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
15655 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
15656 +
15657 +struct vcmd_ctx_rlimit_v0 {
15658 +       uint32_t id;
15659 +       uint64_t minimum;
15660 +       uint64_t softlimit;
15661 +       uint64_t maximum;
15662 +};
15663 +
15664 +struct vcmd_ctx_rlimit_mask_v0 {
15665 +       uint32_t minimum;
15666 +       uint32_t softlimit;
15667 +       uint32_t maximum;
15668 +};
15669 +
15670 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
15671 +
15672 +struct vcmd_rlimit_stat_v0 {
15673 +       uint32_t id;
15674 +       uint32_t hits;
15675 +       uint64_t value;
15676 +       uint64_t minimum;
15677 +       uint64_t maximum;
15678 +};
15679 +
15680 +#define CRLIM_UNSET            (0ULL)
15681 +#define CRLIM_INFINITY         (~0ULL)
15682 +#define CRLIM_KEEP             (~1ULL)
15683 +
15684 +#ifdef __KERNEL__
15685 +
15686 +#ifdef CONFIG_IA32_EMULATION
15687 +
15688 +struct vcmd_ctx_rlimit_v0_x32 {
15689 +       uint32_t id;
15690 +       uint64_t minimum;
15691 +       uint64_t softlimit;
15692 +       uint64_t maximum;
15693 +} __attribute__ ((aligned (4)));
15694 +
15695 +#endif /* CONFIG_IA32_EMULATION */
15696 +
15697 +#include <linux/compiler.h>
15698 +
15699 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
15700 +extern int vc_get_rlimit(struct vx_info *, void __user *);
15701 +extern int vc_set_rlimit(struct vx_info *, void __user *);
15702 +extern int vc_reset_minmax(struct vx_info *, void __user *);
15703 +
15704 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
15705 +
15706 +#ifdef CONFIG_IA32_EMULATION
15707 +
15708 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
15709 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
15710 +
15711 +#endif /* CONFIG_IA32_EMULATION */
15712 +
15713 +#endif /* __KERNEL__ */
15714 +#endif /* _VX_LIMIT_CMD_H */
15715 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
15716 --- linux-2.6.22.10/include/linux/vserver/limit_def.h   1970-01-01 01:00:00 +0100
15717 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_def.h        2007-08-05 20:53:13 +0200
15718 @@ -0,0 +1,47 @@
15719 +#ifndef _VX_LIMIT_DEF_H
15720 +#define _VX_LIMIT_DEF_H
15721 +
15722 +#include <asm/atomic.h>
15723 +#include <asm/resource.h>
15724 +
15725 +#include "limit.h"
15726 +
15727 +
15728 +struct _vx_res_limit {
15729 +       rlim_t soft;            /* Context soft limit */
15730 +       rlim_t hard;            /* Context hard limit */
15731 +
15732 +       rlim_atomic_t rcur;     /* Current value */
15733 +       rlim_t rmin;            /* Context minimum */
15734 +       rlim_t rmax;            /* Context maximum */
15735 +
15736 +       atomic_t lhit;          /* Limit hits */
15737 +};
15738 +
15739 +/* context sub struct */
15740 +
15741 +struct _vx_limit {
15742 +       struct _vx_res_limit res[NUM_LIMITS];
15743 +};
15744 +
15745 +#ifdef CONFIG_VSERVER_DEBUG
15746 +
15747 +static inline void __dump_vx_limit(struct _vx_limit *limit)
15748 +{
15749 +       int i;
15750 +
15751 +       printk("\t_vx_limit:");
15752 +       for (i = 0; i < NUM_LIMITS; i++) {
15753 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
15754 +                       i, (unsigned long)__rlim_get(limit, i),
15755 +                       (unsigned long)__rlim_rmin(limit, i),
15756 +                       (unsigned long)__rlim_rmax(limit, i),
15757 +                       (long)__rlim_soft(limit, i),
15758 +                       (long)__rlim_hard(limit, i),
15759 +                       atomic_read(&__rlim_lhit(limit, i)));
15760 +       }
15761 +}
15762 +
15763 +#endif
15764 +
15765 +#endif /* _VX_LIMIT_DEF_H */
15766 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
15767 --- linux-2.6.22.10/include/linux/vserver/limit_int.h   1970-01-01 01:00:00 +0100
15768 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_int.h        2007-08-05 20:53:13 +0200
15769 @@ -0,0 +1,198 @@
15770 +#ifndef _VX_LIMIT_INT_H
15771 +#define _VX_LIMIT_INT_H
15772 +
15773 +#include "context.h"
15774 +
15775 +#ifdef __KERNEL__
15776 +
15777 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
15778 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
15779 +
15780 +extern const char *vlimit_name[NUM_LIMITS];
15781 +
15782 +static inline void __vx_acc_cres(struct vx_info *vxi,
15783 +       int res, int dir, void *_data, char *_file, int _line)
15784 +{
15785 +       if (VXD_RCRES_COND(res))
15786 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
15787 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15788 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15789 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
15790 +       if (!vxi)
15791 +               return;
15792 +
15793 +       if (dir > 0)
15794 +               __rlim_inc(&vxi->limit, res);
15795 +       else
15796 +               __rlim_dec(&vxi->limit, res);
15797 +}
15798 +
15799 +static inline void __vx_add_cres(struct vx_info *vxi,
15800 +       int res, int amount, void *_data, char *_file, int _line)
15801 +{
15802 +       if (VXD_RCRES_COND(res))
15803 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
15804 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15805 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15806 +                       amount, _data, _file, _line);
15807 +       if (amount == 0)
15808 +               return;
15809 +       if (!vxi)
15810 +               return;
15811 +       __rlim_add(&vxi->limit, res, amount);
15812 +}
15813 +
15814 +static inline
15815 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
15816 +{
15817 +       int cond = (value > __rlim_rmax(limit, res));
15818 +
15819 +       if (cond)
15820 +               __rlim_rmax(limit, res) = value;
15821 +       return cond;
15822 +}
15823 +
15824 +static inline
15825 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
15826 +{
15827 +       int cond = (value < __rlim_rmin(limit, res));
15828 +
15829 +       if (cond)
15830 +               __rlim_rmin(limit, res) = value;
15831 +       return cond;
15832 +}
15833 +
15834 +static inline
15835 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
15836 +{
15837 +       if (!__vx_cres_adjust_max(limit, res, value))
15838 +               __vx_cres_adjust_min(limit, res, value);
15839 +}
15840 +
15841 +
15842 +/*     return values:
15843 +        +1 ... no limit hit
15844 +        -1 ... over soft limit
15845 +         0 ... over hard limit         */
15846 +
15847 +static inline int __vx_cres_avail(struct vx_info *vxi,
15848 +       int res, int num, char *_file, int _line)
15849 +{
15850 +       struct _vx_limit *limit;
15851 +       rlim_t value;
15852 +
15853 +       if (VXD_RLIMIT_COND(res))
15854 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
15855 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15856 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
15857 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
15858 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15859 +                       num, _file, _line);
15860 +       if (!vxi)
15861 +               return 1;
15862 +
15863 +       limit = &vxi->limit;
15864 +       value = __rlim_get(limit, res);
15865 +
15866 +       if (!__vx_cres_adjust_max(limit, res, value))
15867 +               __vx_cres_adjust_min(limit, res, value);
15868 +
15869 +       if (num == 0)
15870 +               return 1;
15871 +
15872 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
15873 +               return -1;
15874 +       if (value + num <= __rlim_soft(limit, res))
15875 +               return -1;
15876 +
15877 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
15878 +               return 1;
15879 +       if (value + num <= __rlim_hard(limit, res))
15880 +               return 1;
15881 +
15882 +       __rlim_hit(limit, res);
15883 +       return 0;
15884 +}
15885 +
15886 +
15887 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
15888 +
15889 +static inline
15890 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
15891 +{
15892 +       rlim_t value, sum = 0;
15893 +       int res;
15894 +
15895 +       while ((res = *array++)) {
15896 +               value = __rlim_get(limit, res);
15897 +               __vx_cres_fixup(limit, res, value);
15898 +               sum += value;
15899 +       }
15900 +       return sum;
15901 +}
15902 +
15903 +static inline
15904 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
15905 +{
15906 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
15907 +       int res = *array;
15908 +
15909 +       if (value == __rlim_get(limit, res))
15910 +               return value;
15911 +
15912 +       __rlim_set(limit, res, value);
15913 +       /* now adjust min/max */
15914 +       if (!__vx_cres_adjust_max(limit, res, value))
15915 +               __vx_cres_adjust_min(limit, res, value);
15916 +
15917 +       return value;
15918 +}
15919 +
15920 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
15921 +       const int *array, int num, char *_file, int _line)
15922 +{
15923 +       struct _vx_limit *limit;
15924 +       rlim_t value = 0;
15925 +       int res;
15926 +
15927 +       if (num == 0)
15928 +               return 1;
15929 +       if (!vxi)
15930 +               return 1;
15931 +
15932 +       limit = &vxi->limit;
15933 +       res = *array;
15934 +       value = __vx_cres_array_sum(limit, array + 1);
15935 +
15936 +       __rlim_set(limit, res, value);
15937 +       __vx_cres_fixup(limit, res, value);
15938 +
15939 +       return __vx_cres_avail(vxi, res, num, _file, _line);
15940 +}
15941 +
15942 +
15943 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
15944 +{
15945 +       rlim_t value;
15946 +       int res;
15947 +
15948 +       /* complex resources first */
15949 +       if ((id < 0) || (id == RLIMIT_RSS))
15950 +               __vx_cres_array_fixup(limit, VLA_RSS);
15951 +
15952 +       for (res = 0; res < NUM_LIMITS; res++) {
15953 +               if ((id > 0) && (res != id))
15954 +                       continue;
15955 +
15956 +               value = __rlim_get(limit, res);
15957 +               __vx_cres_fixup(limit, res, value);
15958 +
15959 +               /* not supposed to happen, maybe warn? */
15960 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
15961 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
15962 +       }
15963 +}
15964 +
15965 +
15966 +#endif /* __KERNEL__ */
15967 +#endif /* _VX_LIMIT_INT_H */
15968 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
15969 --- linux-2.6.22.10/include/linux/vserver/monitor.h     1970-01-01 01:00:00 +0100
15970 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/monitor.h  2007-08-15 23:16:12 +0200
15971 @@ -0,0 +1,96 @@
15972 +#ifndef _VX_MONITOR_H
15973 +#define _VX_MONITOR_H
15974 +
15975 +#include <linux/types.h>
15976 +
15977 +enum {
15978 +       VXM_UNUSED = 0,
15979 +
15980 +       VXM_SYNC = 0x10,
15981 +
15982 +       VXM_UPDATE = 0x20,
15983 +       VXM_UPDATE_1,
15984 +       VXM_UPDATE_2,
15985 +
15986 +       VXM_RQINFO_1 = 0x24,
15987 +       VXM_RQINFO_2,
15988 +
15989 +       VXM_ACTIVATE = 0x40,
15990 +       VXM_DEACTIVATE,
15991 +       VXM_IDLE,
15992 +
15993 +       VXM_HOLD = 0x44,
15994 +       VXM_UNHOLD,
15995 +
15996 +       VXM_MIGRATE = 0x48,
15997 +       VXM_RESCHED,
15998 +
15999 +       /* all other bits are flags */
16000 +       VXM_SCHED = 0x80,
16001 +};
16002 +
16003 +struct _vxm_update_1 {
16004 +       uint32_t tokens_max;
16005 +       uint32_t fill_rate;
16006 +       uint32_t interval;
16007 +};
16008 +
16009 +struct _vxm_update_2 {
16010 +       uint32_t tokens_min;
16011 +       uint32_t fill_rate;
16012 +       uint32_t interval;
16013 +};
16014 +
16015 +struct _vxm_rqinfo_1 {
16016 +       uint16_t running;
16017 +       uint16_t onhold;
16018 +       uint16_t iowait;
16019 +       uint16_t uintr;
16020 +       uint32_t idle_tokens;
16021 +};
16022 +
16023 +struct _vxm_rqinfo_2 {
16024 +       uint32_t norm_time;
16025 +       uint32_t idle_time;
16026 +       uint32_t idle_skip;
16027 +};
16028 +
16029 +struct _vxm_sched {
16030 +       uint32_t tokens;
16031 +       uint32_t norm_time;
16032 +       uint32_t idle_time;
16033 +};
16034 +
16035 +struct _vxm_task {
16036 +       uint16_t pid;
16037 +       uint16_t state;
16038 +};
16039 +
16040 +struct _vxm_event {
16041 +       uint32_t jif;
16042 +       union {
16043 +               uint32_t seq;
16044 +               uint32_t sec;
16045 +       };
16046 +       union {
16047 +               uint32_t tokens;
16048 +               uint32_t nsec;
16049 +               struct _vxm_task tsk;
16050 +       };
16051 +};
16052 +
16053 +struct _vx_mon_entry {
16054 +       uint16_t type;
16055 +       uint16_t xid;
16056 +       union {
16057 +               struct _vxm_event ev;
16058 +               struct _vxm_sched sd;
16059 +               struct _vxm_update_1 u1;
16060 +               struct _vxm_update_2 u2;
16061 +               struct _vxm_rqinfo_1 q1;
16062 +               struct _vxm_rqinfo_2 q2;
16063 +       };
16064 +};
16065 +
16066 +
16067 +#endif /* _VX_MONITOR_H */
16068 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
16069 --- linux-2.6.22.10/include/linux/vserver/network.h     1970-01-01 01:00:00 +0100
16070 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/network.h  2007-10-05 12:29:05 +0200
16071 @@ -0,0 +1,143 @@
16072 +#ifndef _VX_NETWORK_H
16073 +#define _VX_NETWORK_H
16074 +
16075 +#include <linux/types.h>
16076 +
16077 +
16078 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
16079 +
16080 +
16081 +/* network flags */
16082 +
16083 +#define NXF_INFO_PRIVATE       0x00000008
16084 +
16085 +#define NXF_SINGLE_IP          0x00000100
16086 +#define NXF_LBACK_REMAP                0x00000200
16087 +
16088 +#define NXF_HIDE_NETIF         0x02000000
16089 +#define NXF_HIDE_LBACK         0x04000000
16090 +
16091 +#define NXF_STATE_SETUP                (1ULL << 32)
16092 +#define NXF_STATE_ADMIN                (1ULL << 34)
16093 +
16094 +#define NXF_SC_HELPER          (1ULL << 36)
16095 +#define NXF_PERSISTENT         (1ULL << 38)
16096 +
16097 +#define NXF_ONE_TIME           (0x0005ULL << 32)
16098 +
16099 +
16100 +#define        NXF_INIT_SET            (__nxf_init_set())
16101 +
16102 +static inline uint64_t __nxf_init_set(void) {
16103 +       return    NXF_STATE_ADMIN
16104 +#ifdef CONFIG_VSERVER_AUTO_LBACK
16105 +               | NXF_LBACK_REMAP
16106 +               | NXF_HIDE_LBACK
16107 +#endif
16108 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
16109 +               | NXF_SINGLE_IP
16110 +#endif
16111 +               | NXF_HIDE_NETIF;
16112 +}
16113 +
16114 +
16115 +/* network caps */
16116 +
16117 +#define NXC_RAW_ICMP           0x00000100
16118 +
16119 +
16120 +/* address types */
16121 +
16122 +#define NXA_TYPE_IPV4          0x0001
16123 +#define NXA_TYPE_IPV6          0x0002
16124 +
16125 +#define NXA_TYPE_NONE          0x0000
16126 +#define NXA_TYPE_ANY           0x00FF
16127 +
16128 +#define NXA_TYPE_ADDR          0x0010
16129 +#define NXA_TYPE_MASK          0x0020
16130 +#define NXA_TYPE_RANGE         0x0040
16131 +
16132 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
16133 +
16134 +#define NXA_MOD_BCAST          0x0100
16135 +#define NXA_MOD_LBACK          0x0200
16136 +
16137 +#define NXA_LOOPBACK           0x1000
16138 +
16139 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
16140 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
16141 +
16142 +#ifdef __KERNEL__
16143 +
16144 +#include <linux/list.h>
16145 +#include <linux/spinlock.h>
16146 +#include <linux/rcupdate.h>
16147 +#include <linux/in.h>
16148 +#include <linux/in6.h>
16149 +#include <asm/atomic.h>
16150 +
16151 +struct nx_addr_v4 {
16152 +       struct nx_addr_v4 *next;
16153 +       struct in_addr ip[2];
16154 +       struct in_addr mask;
16155 +       uint16_t type;
16156 +       uint16_t flags;
16157 +};
16158 +
16159 +struct nx_addr_v6 {
16160 +       struct nx_addr_v6 *next;
16161 +       struct in6_addr ip;
16162 +       struct in6_addr mask;
16163 +       uint32_t prefix;
16164 +       uint16_t type;
16165 +       uint16_t flags;
16166 +};
16167 +
16168 +struct nx_info {
16169 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
16170 +       nid_t nx_id;                    /* vnet id */
16171 +       atomic_t nx_usecnt;             /* usage count */
16172 +       atomic_t nx_tasks;              /* tasks count */
16173 +       int nx_state;                   /* context state */
16174 +
16175 +       uint64_t nx_flags;              /* network flag word */
16176 +       uint64_t nx_ncaps;              /* network capabilities */
16177 +
16178 +       struct in_addr v4_lback;        /* Loopback address */
16179 +       struct in_addr v4_bcast;        /* Broadcast address */
16180 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
16181 +#ifdef CONFIG_IPV6
16182 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
16183 +#endif
16184 +       char nx_name[65];               /* network context name */
16185 +};
16186 +
16187 +
16188 +/* status flags */
16189 +
16190 +#define NXS_HASHED      0x0001
16191 +#define NXS_SHUTDOWN    0x0100
16192 +#define NXS_RELEASED    0x8000
16193 +
16194 +extern struct nx_info *lookup_nx_info(int);
16195 +
16196 +extern int get_nid_list(int, unsigned int *, int);
16197 +extern int nid_is_hashed(nid_t);
16198 +
16199 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
16200 +
16201 +extern long vs_net_change(struct nx_info *, unsigned int);
16202 +
16203 +struct sock;
16204 +
16205 +
16206 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
16207 +#ifdef  CONFIG_IPV6
16208 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
16209 +#else
16210 +#define NX_IPV6(n)     (0)
16211 +#endif
16212 +
16213 +#endif /* __KERNEL__ */
16214 +#endif /* _VX_NETWORK_H */
16215 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
16216 --- linux-2.6.22.10/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00 +0100
16217 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/network_cmd.h      2007-08-15 20:08:10 +0200
16218 @@ -0,0 +1,150 @@
16219 +#ifndef _VX_NETWORK_CMD_H
16220 +#define _VX_NETWORK_CMD_H
16221 +
16222 +
16223 +/* vinfo commands */
16224 +
16225 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
16226 +
16227 +#ifdef __KERNEL__
16228 +extern int vc_task_nid(uint32_t);
16229 +
16230 +#endif /* __KERNEL__ */
16231 +
16232 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
16233 +
16234 +struct vcmd_nx_info_v0 {
16235 +       uint32_t nid;
16236 +       /* more to come */
16237 +};
16238 +
16239 +#ifdef __KERNEL__
16240 +extern int vc_nx_info(struct nx_info *, void __user *);
16241 +
16242 +#endif /* __KERNEL__ */
16243 +
16244 +#include <linux/in.h>
16245 +#include <linux/in6.h>
16246 +
16247 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
16248 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
16249 +
16250 +struct  vcmd_net_create {
16251 +       uint64_t flagword;
16252 +};
16253 +
16254 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
16255 +
16256 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
16257 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
16258 +
16259 +struct vcmd_net_addr_v0 {
16260 +       uint16_t type;
16261 +       uint16_t count;
16262 +       struct in_addr ip[4];
16263 +       struct in_addr mask[4];
16264 +};
16265 +
16266 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
16267 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
16268 +
16269 +struct vcmd_net_addr_ipv4_v1 {
16270 +       uint16_t type;
16271 +       uint16_t flags;
16272 +       struct in_addr ip;
16273 +       struct in_addr mask;
16274 +};
16275 +
16276 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
16277 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
16278 +
16279 +struct vcmd_net_addr_ipv6_v1 {
16280 +       uint16_t type;
16281 +       uint16_t flags;
16282 +       uint32_t prefix;
16283 +       struct in6_addr ip;
16284 +       struct in6_addr mask;
16285 +};
16286 +
16287 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
16288 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
16289 +
16290 +struct vcmd_match_ipv4_v0 {
16291 +       uint16_t type;
16292 +       uint16_t flags;
16293 +       uint16_t parent;
16294 +       uint16_t prefix;
16295 +       struct in_addr ip;
16296 +       struct in_addr ip2;
16297 +       struct in_addr mask;
16298 +};
16299 +
16300 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
16301 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
16302 +
16303 +struct vcmd_match_ipv6_v0 {
16304 +       uint16_t type;
16305 +       uint16_t flags;
16306 +       uint16_t parent;
16307 +       uint16_t prefix;
16308 +       struct in6_addr ip;
16309 +       struct in6_addr ip2;
16310 +       struct in6_addr mask;
16311 +};
16312 +
16313 +
16314 +#ifdef __KERNEL__
16315 +extern int vc_net_create(uint32_t, void __user *);
16316 +extern int vc_net_migrate(struct nx_info *, void __user *);
16317 +
16318 +extern int vc_net_add(struct nx_info *, void __user *);
16319 +extern int vc_net_remove(struct nx_info *, void __user *);
16320 +
16321 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
16322 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
16323 +
16324 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
16325 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
16326 +
16327 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
16328 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
16329 +
16330 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
16331 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
16332 +
16333 +#endif /* __KERNEL__ */
16334 +
16335 +
16336 +/* flag commands */
16337 +
16338 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
16339 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
16340 +
16341 +struct vcmd_net_flags_v0 {
16342 +       uint64_t flagword;
16343 +       uint64_t mask;
16344 +};
16345 +
16346 +#ifdef __KERNEL__
16347 +extern int vc_get_nflags(struct nx_info *, void __user *);
16348 +extern int vc_set_nflags(struct nx_info *, void __user *);
16349 +
16350 +#endif /* __KERNEL__ */
16351 +
16352 +
16353 +/* network caps commands */
16354 +
16355 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
16356 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
16357 +
16358 +struct vcmd_net_caps_v0 {
16359 +       uint64_t ncaps;
16360 +       uint64_t cmask;
16361 +};
16362 +
16363 +#ifdef __KERNEL__
16364 +extern int vc_get_ncaps(struct nx_info *, void __user *);
16365 +extern int vc_set_ncaps(struct nx_info *, void __user *);
16366 +
16367 +#endif /* __KERNEL__ */
16368 +#endif /* _VX_CONTEXT_CMD_H */
16369 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
16370 --- linux-2.6.22.10/include/linux/vserver/percpu.h      1970-01-01 01:00:00 +0100
16371 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/percpu.h   2007-08-05 20:53:13 +0200
16372 @@ -0,0 +1,14 @@
16373 +#ifndef _VX_PERCPU_H
16374 +#define _VX_PERCPU_H
16375 +
16376 +#include "cvirt_def.h"
16377 +#include "sched_def.h"
16378 +
16379 +struct _vx_percpu {
16380 +       struct _vx_cvirt_pc cvirt;
16381 +       struct _vx_sched_pc sched;
16382 +};
16383 +
16384 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
16385 +
16386 +#endif /* _VX_PERCPU_H */
16387 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
16388 --- linux-2.6.22.10/include/linux/vserver/sched.h       1970-01-01 01:00:00 +0100
16389 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched.h    2007-08-05 20:53:13 +0200
16390 @@ -0,0 +1,26 @@
16391 +#ifndef _VX_SCHED_H
16392 +#define _VX_SCHED_H
16393 +
16394 +
16395 +#ifdef __KERNEL__
16396 +
16397 +struct timespec;
16398 +
16399 +void vx_vsi_uptime(struct timespec *, struct timespec *);
16400 +
16401 +
16402 +struct vx_info;
16403 +
16404 +void vx_update_load(struct vx_info *);
16405 +
16406 +
16407 +int vx_tokens_recalc(struct _vx_sched_pc *,
16408 +       unsigned long *, unsigned long *, int [2]);
16409 +
16410 +void vx_update_sched_param(struct _vx_sched *sched,
16411 +       struct _vx_sched_pc *sched_pc);
16412 +
16413 +#endif /* __KERNEL__ */
16414 +#else  /* _VX_SCHED_H */
16415 +#warning duplicate inclusion
16416 +#endif /* _VX_SCHED_H */
16417 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
16418 --- linux-2.6.22.10/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00 +0100
16419 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched_cmd.h        2007-08-05 20:53:13 +0200
16420 @@ -0,0 +1,108 @@
16421 +#ifndef _VX_SCHED_CMD_H
16422 +#define _VX_SCHED_CMD_H
16423 +
16424 +
16425 +/*  sched vserver commands */
16426 +
16427 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
16428 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
16429 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
16430 +
16431 +struct vcmd_set_sched_v2 {
16432 +       int32_t fill_rate;
16433 +       int32_t interval;
16434 +       int32_t tokens;
16435 +       int32_t tokens_min;
16436 +       int32_t tokens_max;
16437 +       uint64_t cpu_mask;
16438 +};
16439 +
16440 +struct vcmd_set_sched_v3 {
16441 +       uint32_t set_mask;
16442 +       int32_t fill_rate;
16443 +       int32_t interval;
16444 +       int32_t tokens;
16445 +       int32_t tokens_min;
16446 +       int32_t tokens_max;
16447 +       int32_t priority_bias;
16448 +};
16449 +
16450 +struct vcmd_set_sched_v4 {
16451 +       uint32_t set_mask;
16452 +       int32_t fill_rate;
16453 +       int32_t interval;
16454 +       int32_t tokens;
16455 +       int32_t tokens_min;
16456 +       int32_t tokens_max;
16457 +       int32_t prio_bias;
16458 +       int32_t cpu_id;
16459 +       int32_t bucket_id;
16460 +};
16461 +
16462 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
16463 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
16464 +
16465 +struct vcmd_sched_v5 {
16466 +       uint32_t mask;
16467 +       int32_t cpu_id;
16468 +       int32_t bucket_id;
16469 +       int32_t fill_rate[2];
16470 +       int32_t interval[2];
16471 +       int32_t tokens;
16472 +       int32_t tokens_min;
16473 +       int32_t tokens_max;
16474 +       int32_t prio_bias;
16475 +};
16476 +
16477 +#define VXSM_FILL_RATE         0x0001
16478 +#define VXSM_INTERVAL          0x0002
16479 +#define VXSM_FILL_RATE2                0x0004
16480 +#define VXSM_INTERVAL2         0x0008
16481 +#define VXSM_TOKENS            0x0010
16482 +#define VXSM_TOKENS_MIN                0x0020
16483 +#define VXSM_TOKENS_MAX                0x0040
16484 +#define VXSM_PRIO_BIAS         0x0100
16485 +
16486 +#define VXSM_IDLE_TIME         0x0200
16487 +#define VXSM_FORCE             0x0400
16488 +
16489 +#define        VXSM_V3_MASK            0x0173
16490 +#define        VXSM_SET_MASK           0x01FF
16491 +
16492 +#define VXSM_CPU_ID            0x1000
16493 +#define VXSM_BUCKET_ID         0x2000
16494 +
16495 +#define VXSM_MSEC              0x4000
16496 +
16497 +#define SCHED_KEEP             (-2)    /* only for v2 */
16498 +
16499 +#ifdef __KERNEL__
16500 +
16501 +#include <linux/compiler.h>
16502 +
16503 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
16504 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
16505 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
16506 +extern int vc_set_sched(struct vx_info *, void __user *);
16507 +extern int vc_get_sched(struct vx_info *, void __user *);
16508 +
16509 +#endif /* __KERNEL__ */
16510 +
16511 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
16512 +
16513 +struct vcmd_sched_info {
16514 +       int32_t cpu_id;
16515 +       int32_t bucket_id;
16516 +       uint64_t user_msec;
16517 +       uint64_t sys_msec;
16518 +       uint64_t hold_msec;
16519 +       uint32_t token_usec;
16520 +       int32_t vavavoom;
16521 +};
16522 +
16523 +#ifdef __KERNEL__
16524 +
16525 +extern int vc_sched_info(struct vx_info *, void __user *);
16526 +
16527 +#endif /* __KERNEL__ */
16528 +#endif /* _VX_SCHED_CMD_H */
16529 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
16530 --- linux-2.6.22.10/include/linux/vserver/sched_def.h   1970-01-01 01:00:00 +0100
16531 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched_def.h        2007-08-05 20:53:13 +0200
16532 @@ -0,0 +1,68 @@
16533 +#ifndef _VX_SCHED_DEF_H
16534 +#define _VX_SCHED_DEF_H
16535 +
16536 +#include <linux/spinlock.h>
16537 +#include <linux/jiffies.h>
16538 +#include <linux/cpumask.h>
16539 +#include <asm/atomic.h>
16540 +#include <asm/param.h>
16541 +
16542 +
16543 +/* context sub struct */
16544 +
16545 +struct _vx_sched {
16546 +       spinlock_t tokens_lock;         /* lock for token bucket */
16547 +
16548 +       int tokens;                     /* number of CPU tokens */
16549 +       int fill_rate[2];               /* Fill rate: add X tokens... */
16550 +       int interval[2];                /* Divisor:   per Y jiffies   */
16551 +       int tokens_min;                 /* Limit:     minimum for unhold */
16552 +       int tokens_max;                 /* Limit:     no more than N tokens */
16553 +
16554 +       int prio_bias;                  /* bias offset for priority */
16555 +
16556 +       unsigned update_mask;           /* which features should be updated */
16557 +       cpumask_t update;               /* CPUs which should update */
16558 +};
16559 +
16560 +struct _vx_sched_pc {
16561 +       int tokens;                     /* number of CPU tokens */
16562 +       int flags;                      /* bucket flags */
16563 +
16564 +       int fill_rate[2];               /* Fill rate: add X tokens... */
16565 +       int interval[2];                /* Divisor:   per Y jiffies   */
16566 +       int tokens_min;                 /* Limit:     minimum for unhold */
16567 +       int tokens_max;                 /* Limit:     no more than N tokens */
16568 +
16569 +       int prio_bias;                  /* bias offset for priority */
16570 +       int vavavoom;                   /* last calculated vavavoom */
16571 +
16572 +       unsigned long norm_time;        /* last time accounted */
16573 +       unsigned long idle_time;        /* non linear time for fair sched */
16574 +       unsigned long token_time;       /* token time for accounting */
16575 +       unsigned long onhold;           /* jiffies when put on hold */
16576 +
16577 +       uint64_t user_ticks;            /* token tick events */
16578 +       uint64_t sys_ticks;             /* token tick events */
16579 +       uint64_t hold_ticks;            /* token ticks paused */
16580 +};
16581 +
16582 +
16583 +#define VXSF_ONHOLD    0x0001
16584 +#define VXSF_IDLE_TIME 0x0100
16585 +
16586 +#ifdef CONFIG_VSERVER_DEBUG
16587 +
16588 +static inline void __dump_vx_sched(struct _vx_sched *sched)
16589 +{
16590 +       printk("\t_vx_sched:\n");
16591 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
16592 +               sched->fill_rate[0], sched->interval[0],
16593 +               sched->fill_rate[1], sched->interval[1],
16594 +               sched->tokens_min, sched->tokens_max);
16595 +       printk("\t priority = %4d\n", sched->prio_bias);
16596 +}
16597 +
16598 +#endif
16599 +
16600 +#endif /* _VX_SCHED_DEF_H */
16601 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
16602 --- linux-2.6.22.10/include/linux/vserver/signal.h      1970-01-01 01:00:00 +0100
16603 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/signal.h   2007-08-05 20:53:13 +0200
16604 @@ -0,0 +1,14 @@
16605 +#ifndef _VX_SIGNAL_H
16606 +#define _VX_SIGNAL_H
16607 +
16608 +
16609 +#ifdef __KERNEL__
16610 +
16611 +struct vx_info;
16612 +
16613 +int vx_info_kill(struct vx_info *, int, int);
16614 +
16615 +#endif /* __KERNEL__ */
16616 +#else  /* _VX_SIGNAL_H */
16617 +#warning duplicate inclusion
16618 +#endif /* _VX_SIGNAL_H */
16619 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
16620 --- linux-2.6.22.10/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00 +0100
16621 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/signal_cmd.h       2007-08-05 20:53:13 +0200
16622 @@ -0,0 +1,43 @@
16623 +#ifndef _VX_SIGNAL_CMD_H
16624 +#define _VX_SIGNAL_CMD_H
16625 +
16626 +
16627 +/*  signalling vserver commands */
16628 +
16629 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
16630 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
16631 +
16632 +struct vcmd_ctx_kill_v0 {
16633 +       int32_t pid;
16634 +       int32_t sig;
16635 +};
16636 +
16637 +struct vcmd_wait_exit_v0 {
16638 +       int32_t reboot_cmd;
16639 +       int32_t exit_code;
16640 +};
16641 +
16642 +#ifdef __KERNEL__
16643 +
16644 +extern int vc_ctx_kill(struct vx_info *, void __user *);
16645 +extern int vc_wait_exit(struct vx_info *, void __user *);
16646 +
16647 +#endif /* __KERNEL__ */
16648 +
16649 +/*  process alteration commands */
16650 +
16651 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
16652 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
16653 +
16654 +struct vcmd_pflags_v0 {
16655 +       uint32_t flagword;
16656 +       uint32_t mask;
16657 +};
16658 +
16659 +#ifdef __KERNEL__
16660 +
16661 +extern int vc_get_pflags(uint32_t pid, void __user *);
16662 +extern int vc_set_pflags(uint32_t pid, void __user *);
16663 +
16664 +#endif /* __KERNEL__ */
16665 +#endif /* _VX_SIGNAL_CMD_H */
16666 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
16667 --- linux-2.6.22.10/include/linux/vserver/space.h       1970-01-01 01:00:00 +0100
16668 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/space.h    2007-08-05 20:53:13 +0200
16669 @@ -0,0 +1,13 @@
16670 +#ifndef _VX_SPACE_H
16671 +#define _VX_SPACE_H
16672 +
16673 +
16674 +#include <linux/types.h>
16675 +
16676 +struct vx_info;
16677 +
16678 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
16679 +
16680 +#else  /* _VX_SPACE_H */
16681 +#warning duplicate inclusion
16682 +#endif /* _VX_SPACE_H */
16683 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
16684 --- linux-2.6.22.10/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00 +0100
16685 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/space_cmd.h        2007-08-05 20:53:13 +0200
16686 @@ -0,0 +1,26 @@
16687 +#ifndef _VX_SPACE_CMD_H
16688 +#define _VX_SPACE_CMD_H
16689 +
16690 +
16691 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
16692 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
16693 +
16694 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
16695 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
16696 +
16697 +#define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
16698 +
16699 +
16700 +struct vcmd_space_mask {
16701 +       uint64_t mask;
16702 +};
16703 +
16704 +
16705 +#ifdef __KERNEL__
16706 +
16707 +extern int vc_enter_space(struct vx_info *, void __user *);
16708 +extern int vc_set_space(struct vx_info *, void __user *);
16709 +extern int vc_get_space_mask(struct vx_info *, void __user *);
16710 +
16711 +#endif /* __KERNEL__ */
16712 +#endif /* _VX_SPACE_CMD_H */
16713 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
16714 --- linux-2.6.22.10/include/linux/vserver/switch.h      1970-01-01 01:00:00 +0100
16715 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/switch.h   2007-10-11 01:10:22 +0200
16716 @@ -0,0 +1,99 @@
16717 +#ifndef _VX_SWITCH_H
16718 +#define _VX_SWITCH_H
16719 +
16720 +#include <linux/types.h>
16721 +
16722 +
16723 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
16724 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
16725 +#define VC_VERSION(c)          ((c) & 0xFFF)
16726 +
16727 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
16728 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
16729 +
16730 +/*
16731 +
16732 +  Syscall Matrix V2.8
16733 +
16734 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
16735 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
16736 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
16737 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16738 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
16739 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
16740 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16741 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
16742 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
16743 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16744 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
16745 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
16746 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16747 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
16748 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
16749 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16750 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
16751 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
16752 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16753 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
16754 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
16755 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
16756 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
16757 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
16758 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16759 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
16760 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
16761 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16762 +
16763 +*/
16764 +
16765 +#define VC_CAT_VERSION         0
16766 +
16767 +#define VC_CAT_VSETUP          1
16768 +#define VC_CAT_VHOST           2
16769 +
16770 +#define VC_CAT_DEVICE          6
16771 +
16772 +#define VC_CAT_VPROC           9
16773 +#define VC_CAT_PROCALT         10
16774 +#define VC_CAT_PROCMIG         11
16775 +#define VC_CAT_PROCTRL         12
16776 +
16777 +#define VC_CAT_SCHED           14
16778 +#define VC_CAT_MEMCTRL         20
16779 +
16780 +#define VC_CAT_VNET            25
16781 +#define VC_CAT_NETALT          26
16782 +#define VC_CAT_NETMIG          27
16783 +#define VC_CAT_NETCTRL         28
16784 +
16785 +#define VC_CAT_TAGMIG          35
16786 +#define VC_CAT_DLIMIT          36
16787 +#define VC_CAT_INODE           38
16788 +
16789 +#define VC_CAT_VSTAT           40
16790 +#define VC_CAT_VINFO           46
16791 +#define VC_CAT_EVENT           48
16792 +
16793 +#define VC_CAT_FLAGS           52
16794 +#define VC_CAT_DEBUG           56
16795 +#define VC_CAT_RLIMIT          60
16796 +
16797 +#define VC_CAT_SYSTEST         61
16798 +#define VC_CAT_COMPAT          63
16799 +
16800 +/*  query version */
16801 +
16802 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
16803 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
16804 +
16805 +
16806 +#ifdef __KERNEL__
16807 +
16808 +#include <linux/errno.h>
16809 +
16810 +
16811 +#else  /* __KERNEL__ */
16812 +#define __user
16813 +#endif /* __KERNEL__ */
16814 +
16815 +#endif /* _VX_SWITCH_H */
16816 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
16817 --- linux-2.6.22.10/include/linux/vserver/tag.h 1970-01-01 01:00:00 +0100
16818 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/tag.h      2007-10-10 19:05:04 +0200
16819 @@ -0,0 +1,143 @@
16820 +#ifndef _DX_TAG_H
16821 +#define _DX_TAG_H
16822 +
16823 +#include <linux/types.h>
16824 +
16825 +
16826 +#define DX_TAG(in)     (IS_TAGGED(in))
16827 +
16828 +
16829 +#ifdef CONFIG_DX_TAG_NFSD
16830 +#define DX_TAG_NFSD    1
16831 +#else
16832 +#define DX_TAG_NFSD    0
16833 +#endif
16834 +
16835 +
16836 +#ifdef CONFIG_TAGGING_NONE
16837 +
16838 +#define MAX_UID                0xFFFFFFFF
16839 +#define MAX_GID                0xFFFFFFFF
16840 +
16841 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
16842 +
16843 +#define TAGINO_UID(cond, uid, tag)     (uid)
16844 +#define TAGINO_GID(cond, gid, tag)     (gid)
16845 +
16846 +#endif
16847 +
16848 +
16849 +#ifdef CONFIG_TAGGING_GID16
16850 +
16851 +#define MAX_UID                0xFFFFFFFF
16852 +#define MAX_GID                0x0000FFFF
16853 +
16854 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16855 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
16856 +
16857 +#define TAGINO_UID(cond, uid, tag)     (uid)
16858 +#define TAGINO_GID(cond, gid, tag)     \
16859 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
16860 +
16861 +#endif
16862 +
16863 +
16864 +#ifdef CONFIG_TAGGING_ID24
16865 +
16866 +#define MAX_UID                0x00FFFFFF
16867 +#define MAX_GID                0x00FFFFFF
16868 +
16869 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16870 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
16871 +
16872 +#define TAGINO_UID(cond, uid, tag)     \
16873 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
16874 +#define TAGINO_GID(cond, gid, tag)     \
16875 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
16876 +
16877 +#endif
16878 +
16879 +
16880 +#ifdef CONFIG_TAGGING_UID16
16881 +
16882 +#define MAX_UID                0x0000FFFF
16883 +#define MAX_GID                0xFFFFFFFF
16884 +
16885 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16886 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
16887 +
16888 +#define TAGINO_UID(cond, uid, tag)     \
16889 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
16890 +#define TAGINO_GID(cond, gid, tag)     (gid)
16891 +
16892 +#endif
16893 +
16894 +
16895 +#ifdef CONFIG_TAGGING_INTERN
16896 +
16897 +#define MAX_UID                0xFFFFFFFF
16898 +#define MAX_GID                0xFFFFFFFF
16899 +
16900 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16901 +       ((cond) ? (tag) : 0)
16902 +
16903 +#define TAGINO_UID(cond, uid, tag)     (uid)
16904 +#define TAGINO_GID(cond, gid, tag)     (gid)
16905 +
16906 +#endif
16907 +
16908 +
16909 +#ifndef CONFIG_TAGGING_NONE
16910 +#define dx_current_fstag(sb)   \
16911 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
16912 +#else
16913 +#define dx_current_fstag(sb)   (0)
16914 +#endif
16915 +
16916 +#ifndef CONFIG_TAGGING_INTERN
16917 +#define TAGINO_TAG(cond, tag)  (0)
16918 +#else
16919 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
16920 +#endif
16921 +
16922 +#define INOTAG_UID(cond, uid, gid)     \
16923 +       ((cond) ? ((uid) & MAX_UID) : (uid))
16924 +#define INOTAG_GID(cond, uid, gid)     \
16925 +       ((cond) ? ((gid) & MAX_GID) : (gid))
16926 +
16927 +
16928 +static inline uid_t dx_map_uid(uid_t uid)
16929 +{
16930 +       if ((uid > MAX_UID) && (uid != -1))
16931 +               uid = -2;
16932 +       return (uid & MAX_UID);
16933 +}
16934 +
16935 +static inline gid_t dx_map_gid(gid_t gid)
16936 +{
16937 +       if ((gid > MAX_GID) && (gid != -1))
16938 +               gid = -2;
16939 +       return (gid & MAX_GID);
16940 +}
16941 +
16942 +struct peer_tag {
16943 +       int32_t xid;
16944 +       int32_t nid;
16945 +};
16946 +
16947 +#define dx_notagcheck(nd) \
16948 +       ((nd) && (nd)->mnt && ((nd)->mnt->mnt_flags & MNT_NOTAGCHECK))
16949 +
16950 +int dx_parse_tag(char *string, tag_t *tag, int remove);
16951 +
16952 +#ifdef CONFIG_PROPAGATE
16953 +
16954 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
16955 +
16956 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
16957 +
16958 +#else
16959 +#define dx_propagate_tag(n, i) do { } while (0)
16960 +#endif
16961 +
16962 +#endif /* _DX_TAG_H */
16963 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
16964 --- linux-2.6.22.10/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00 +0100
16965 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/tag_cmd.h  2007-08-15 20:16:43 +0200
16966 @@ -0,0 +1,22 @@
16967 +#ifndef _VX_TAG_CMD_H
16968 +#define _VX_TAG_CMD_H
16969 +
16970 +
16971 +/* vinfo commands */
16972 +
16973 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
16974 +
16975 +#ifdef __KERNEL__
16976 +extern int vc_task_tag(uint32_t);
16977 +
16978 +#endif /* __KERNEL__ */
16979 +
16980 +/* context commands */
16981 +
16982 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
16983 +
16984 +#ifdef __KERNEL__
16985 +extern int vc_tag_migrate(uint32_t);
16986 +
16987 +#endif /* __KERNEL__ */
16988 +#endif /* _VX_TAG_CMD_H */
16989 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
16990 --- linux-2.6.22.10/include/net/addrconf.h      2007-07-09 13:20:01 +0200
16991 +++ linux-2.6.22.10-vs2.3.0.29/include/net/addrconf.h   2007-08-12 00:22:19 +0200
16992 @@ -69,10 +69,12 @@ extern struct inet6_ifaddr *        ipv6_get_if
16993                                                 int strict);
16994  extern int                     ipv6_get_saddr(struct dst_entry *dst, 
16995                                                struct in6_addr *daddr,
16996 -                                              struct in6_addr *saddr);
16997 +                                              struct in6_addr *saddr,
16998 +                                              struct nx_info *nxi);
16999  extern int                     ipv6_dev_get_saddr(struct net_device *dev, 
17000                                                struct in6_addr *daddr,
17001 -                                              struct in6_addr *saddr);
17002 +                                              struct in6_addr *saddr,
17003 +                                              struct nx_info *nxi);
17004  extern int                     ipv6_get_lladdr(struct net_device *dev,
17005                                                 struct in6_addr *addr,
17006                                                 unsigned char banned_flags);
17007 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
17008 --- linux-2.6.22.10/include/net/af_unix.h       2007-07-09 13:20:01 +0200
17009 +++ linux-2.6.22.10-vs2.3.0.29/include/net/af_unix.h    2007-08-05 20:53:13 +0200
17010 @@ -4,6 +4,7 @@
17011  #include <linux/socket.h>
17012  #include <linux/un.h>
17013  #include <linux/mutex.h>
17014 +#include <linux/vs_base.h>
17015  #include <net/sock.h>
17016  
17017  extern void unix_inflight(struct file *fp);
17018 @@ -17,9 +18,9 @@ extern spinlock_t unix_table_lock;
17019  
17020  extern atomic_t unix_tot_inflight;
17021  
17022 -static inline struct sock *first_unix_socket(int *i)
17023 +static inline struct sock *next_unix_socket_table(int *i)
17024  {
17025 -       for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
17026 +       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17027                 if (!hlist_empty(&unix_socket_table[*i]))
17028                         return __sk_head(&unix_socket_table[*i]);
17029         }
17030 @@ -28,16 +29,19 @@ static inline struct sock *first_unix_so
17031  
17032  static inline struct sock *next_unix_socket(int *i, struct sock *s)
17033  {
17034 -       struct sock *next = sk_next(s);
17035 -       /* More in this chain? */
17036 -       if (next)
17037 -               return next;
17038 -       /* Look for next non-empty chain. */
17039 -       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17040 -               if (!hlist_empty(&unix_socket_table[*i]))
17041 -                       return __sk_head(&unix_socket_table[*i]);
17042 -       }
17043 -       return NULL;
17044 +       do {
17045 +               if (s)
17046 +                       s = sk_next(s);
17047 +               if (!s)
17048 +                       s = next_unix_socket_table(i);
17049 +       } while (s && !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT));
17050 +       return s;
17051 +}
17052 +
17053 +static inline struct sock *first_unix_socket(int *i)
17054 +{
17055 +       *i = 0;
17056 +       return next_unix_socket(i, NULL);
17057  }
17058  
17059  #define forall_unix_sockets(i, s) \
17060 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
17061 --- linux-2.6.22.10/include/net/inet_timewait_sock.h    2007-05-02 19:25:35 +0200
17062 +++ linux-2.6.22.10-vs2.3.0.29/include/net/inet_timewait_sock.h 2007-08-05 20:53:13 +0200
17063 @@ -115,6 +115,10 @@ struct inet_timewait_sock {
17064  #define tw_refcnt              __tw_common.skc_refcnt
17065  #define tw_hash                        __tw_common.skc_hash
17066  #define tw_prot                        __tw_common.skc_prot
17067 +#define tw_xid         __tw_common.skc_xid
17068 +#define tw_vx_info             __tw_common.skc_vx_info
17069 +#define tw_nid         __tw_common.skc_nid
17070 +#define tw_nx_info             __tw_common.skc_nx_info
17071         volatile unsigned char  tw_substate;
17072         /* 3 bits hole, try to pack */
17073         unsigned char           tw_rcv_wscale;
17074 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
17075 --- linux-2.6.22.10/include/net/route.h 2007-05-02 19:25:35 +0200
17076 +++ linux-2.6.22.10-vs2.3.0.29/include/net/route.h      2007-09-18 03:52:05 +0200
17077 @@ -27,12 +27,16 @@
17078  #include <net/dst.h>
17079  #include <net/inetpeer.h>
17080  #include <net/flow.h>
17081 +#include <net/inet_sock.h>
17082  #include <linux/in_route.h>
17083  #include <linux/rtnetlink.h>
17084  #include <linux/route.h>
17085  #include <linux/ip.h>
17086  #include <linux/cache.h>
17087  #include <linux/security.h>
17088 +#include <linux/vs_base.h>
17089 +#include <linux/vs_inet.h>
17090 +#include <linux/in.h>
17091  
17092  #ifndef __KERNEL__
17093  #warning This file is not supposed to be used outside of kernel.
17094 @@ -143,6 +147,8 @@ static inline char rt_tos2priority(u8 to
17095         return ip_tos2prio[IPTOS_TOS(tos)>>1];
17096  }
17097  
17098 +extern int ip_v4_find_src(struct nx_info *, struct rtable **, struct flowi *);
17099 +
17100  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
17101                                    __be32 src, u32 tos, int oif, u8 protocol,
17102                                    __be16 sport, __be16 dport, struct sock *sk,
17103 @@ -158,7 +164,21 @@ static inline int ip_route_connect(struc
17104                                          .dport = dport } } };
17105  
17106         int err;
17107 -       if (!dst || !src) {
17108 +       struct nx_info *nx_info = current->nx_info;
17109 +
17110 +       if (sk)
17111 +               nx_info = sk->sk_nx_info;
17112 +
17113 +       vxdprintk(VXD_CBIT(net, 4),
17114 +               "ip_route_connect(%p) %p,%p;%lx",
17115 +               sk, nx_info, sk->sk_socket,
17116 +               (sk->sk_socket?sk->sk_socket->flags:0));
17117 +
17118 +       err = ip_v4_find_src(nx_info, rp, &fl);
17119 +       if (err)
17120 +               return err;
17121 +
17122 +       if (!fl.fl4_dst || !fl.fl4_src) {
17123                 err = __ip_route_output_key(rp, &fl);
17124                 if (err)
17125                         return err;
17126 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
17127 --- linux-2.6.22.10/include/net/sock.h  2007-07-09 13:20:02 +0200
17128 +++ linux-2.6.22.10-vs2.3.0.29/include/net/sock.h       2007-08-05 20:53:13 +0200
17129 @@ -119,6 +119,10 @@ struct sock_common {
17130         atomic_t                skc_refcnt;
17131         unsigned int            skc_hash;
17132         struct proto            *skc_prot;
17133 +       xid_t                   skc_xid;
17134 +       struct vx_info          *skc_vx_info;
17135 +       nid_t                   skc_nid;
17136 +       struct nx_info          *skc_nx_info;
17137  };
17138  
17139  /**
17140 @@ -195,6 +199,10 @@ struct sock {
17141  #define sk_refcnt              __sk_common.skc_refcnt
17142  #define sk_hash                        __sk_common.skc_hash
17143  #define sk_prot                        __sk_common.skc_prot
17144 +#define sk_xid                 __sk_common.skc_xid
17145 +#define sk_vx_info             __sk_common.skc_vx_info
17146 +#define sk_nid                 __sk_common.skc_nid
17147 +#define sk_nx_info             __sk_common.skc_nx_info
17148         unsigned char           sk_shutdown : 2,
17149                                 sk_no_check : 2,
17150                                 sk_userlocks : 4;
17151 diff -NurpP --minimal linux-2.6.22.10/init/main.c linux-2.6.22.10-vs2.3.0.29/init/main.c
17152 --- linux-2.6.22.10/init/main.c 2007-07-09 13:20:03 +0200
17153 +++ linux-2.6.22.10-vs2.3.0.29/init/main.c      2007-08-05 20:53:13 +0200
17154 @@ -55,6 +55,7 @@
17155  #include <linux/pid_namespace.h>
17156  #include <linux/device.h>
17157  #include <linux/kthread.h>
17158 +#include <linux/vserver/percpu.h>
17159  
17160  #include <asm/io.h>
17161  #include <asm/bugs.h>
17162 @@ -364,12 +365,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
17163  
17164  static void __init setup_per_cpu_areas(void)
17165  {
17166 -       unsigned long size, i;
17167 +       unsigned long size, vspc, i;
17168         char *ptr;
17169         unsigned long nr_possible_cpus = num_possible_cpus();
17170  
17171 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
17172 +
17173         /* Copy section for each CPU (we discard the original) */
17174 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
17175 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
17176         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
17177  
17178         for_each_possible_cpu(i) {
17179 diff -NurpP --minimal linux-2.6.22.10/ipc/mqueue.c linux-2.6.22.10-vs2.3.0.29/ipc/mqueue.c
17180 --- linux-2.6.22.10/ipc/mqueue.c        2007-07-09 13:20:03 +0200
17181 +++ linux-2.6.22.10-vs2.3.0.29/ipc/mqueue.c     2007-10-01 14:57:41 +0200
17182 @@ -29,6 +29,8 @@
17183  #include <linux/audit.h>
17184  #include <linux/signal.h>
17185  #include <linux/mutex.h>
17186 +#include <linux/vs_context.h>
17187 +#include <linux/vs_limit.h>
17188  
17189  #include <net/sock.h>
17190  #include "util.h"
17191 @@ -151,17 +153,20 @@ static struct inode *mqueue_get_inode(st
17192                         spin_lock(&mq_lock);
17193                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
17194                             u->mq_bytes + mq_bytes >
17195 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
17196 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
17197 +                           !vx_ipcmsg_avail(p->vx_info, mq_bytes)) {
17198                                 spin_unlock(&mq_lock);
17199                                 goto out_inode;
17200                         }
17201                         u->mq_bytes += mq_bytes;
17202 +                       vx_ipcmsg_add(p->vx_info, u, mq_bytes);
17203                         spin_unlock(&mq_lock);
17204  
17205                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
17206                         if (!info->messages) {
17207                                 spin_lock(&mq_lock);
17208                                 u->mq_bytes -= mq_bytes;
17209 +                               vx_ipcmsg_sub(p->vx_info, u, mq_bytes);
17210                                 spin_unlock(&mq_lock);
17211                                 goto out_inode;
17212                         }
17213 @@ -257,10 +262,14 @@ static void mqueue_delete_inode(struct i
17214                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
17215         user = info->user;
17216         if (user) {
17217 +               struct vx_info *vxi = lookup_vx_info(user->xid);
17218 +
17219                 spin_lock(&mq_lock);
17220                 user->mq_bytes -= mq_bytes;
17221 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
17222                 queues_count--;
17223                 spin_unlock(&mq_lock);
17224 +               put_vx_info(vxi);
17225                 free_uid(user);
17226         }
17227  }
17228 @@ -748,7 +757,7 @@ asmlinkage long sys_mq_unlink(const char
17229         if (inode)
17230                 atomic_inc(&inode->i_count);
17231  
17232 -       err = vfs_unlink(dentry->d_parent->d_inode, dentry);
17233 +       err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
17234  out_err:
17235         dput(dentry);
17236  
17237 diff -NurpP --minimal linux-2.6.22.10/ipc/msg.c linux-2.6.22.10-vs2.3.0.29/ipc/msg.c
17238 --- linux-2.6.22.10/ipc/msg.c   2007-02-06 03:01:55 +0100
17239 +++ linux-2.6.22.10-vs2.3.0.29/ipc/msg.c        2007-08-05 20:53:13 +0200
17240 @@ -36,6 +36,7 @@
17241  #include <linux/seq_file.h>
17242  #include <linux/mutex.h>
17243  #include <linux/nsproxy.h>
17244 +#include <linux/vs_base.h>
17245  
17246  #include <asm/current.h>
17247  #include <asm/uaccess.h>
17248 @@ -149,6 +150,7 @@ static int newque (struct ipc_namespace 
17249  
17250         msq->q_perm.mode = msgflg & S_IRWXUGO;
17251         msq->q_perm.key = key;
17252 +       msq->q_perm.xid = vx_current_xid();
17253  
17254         msq->q_perm.security = NULL;
17255         retval = security_msg_queue_alloc(msq);
17256 diff -NurpP --minimal linux-2.6.22.10/ipc/sem.c linux-2.6.22.10-vs2.3.0.29/ipc/sem.c
17257 --- linux-2.6.22.10/ipc/sem.c   2007-07-09 13:20:03 +0200
17258 +++ linux-2.6.22.10-vs2.3.0.29/ipc/sem.c        2007-08-05 20:53:13 +0200
17259 @@ -82,6 +82,8 @@
17260  #include <linux/seq_file.h>
17261  #include <linux/mutex.h>
17262  #include <linux/nsproxy.h>
17263 +#include <linux/vs_base.h>
17264 +#include <linux/vs_limit.h>
17265  
17266  #include <asm/uaccess.h>
17267  #include "util.h"
17268 @@ -229,6 +231,7 @@ static int newary (struct ipc_namespace 
17269  
17270         sma->sem_perm.mode = (semflg & S_IRWXUGO);
17271         sma->sem_perm.key = key;
17272 +       sma->sem_perm.xid = vx_current_xid();
17273  
17274         sma->sem_perm.security = NULL;
17275         retval = security_sem_alloc(sma);
17276 @@ -244,6 +247,9 @@ static int newary (struct ipc_namespace 
17277                 return -ENOSPC;
17278         }
17279         ns->used_sems += nsems;
17280 +       /* FIXME: obsoleted? */
17281 +       vx_semary_inc(sma);
17282 +       vx_nsems_add(sma, nsems);
17283  
17284         sma->sem_id = sem_buildid(ns, id, sma->sem_perm.seq);
17285         sma->sem_base = (struct sem *) &sma[1];
17286 @@ -525,6 +531,9 @@ static void freeary (struct ipc_namespac
17287         sem_unlock(sma);
17288  
17289         ns->used_sems -= sma->sem_nsems;
17290 +       /* FIXME: obsoleted? */
17291 +       vx_nsems_sub(sma, sma->sem_nsems);
17292 +       vx_semary_dec(sma);
17293         size = sizeof (*sma) + sma->sem_nsems * sizeof (struct sem);
17294         security_sem_free(sma);
17295         ipc_rcu_putref(sma);
17296 diff -NurpP --minimal linux-2.6.22.10/ipc/shm.c linux-2.6.22.10-vs2.3.0.29/ipc/shm.c
17297 --- linux-2.6.22.10/ipc/shm.c   2007-10-30 01:57:14 +0100
17298 +++ linux-2.6.22.10-vs2.3.0.29/ipc/shm.c        2007-10-01 14:57:41 +0200
17299 @@ -38,6 +38,8 @@
17300  #include <linux/mutex.h>
17301  #include <linux/nsproxy.h>
17302  #include <linux/mount.h>
17303 +#include <linux/vs_context.h>
17304 +#include <linux/vs_limit.h>
17305  
17306  #include <asm/uaccess.h>
17307  
17308 @@ -185,7 +187,12 @@ static void shm_open(struct vm_area_stru
17309   */
17310  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
17311  {
17312 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17313 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
17314 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17315 +
17316 +       vx_ipcshm_sub(vxi, shp, numpages);
17317 +       ns->shm_tot -= numpages;
17318 +
17319         shm_rmid(ns, shp->id);
17320         shm_unlock(shp);
17321         if (!is_file_hugepages(shp->shm_file))
17322 @@ -195,6 +202,7 @@ static void shm_destroy(struct ipc_names
17323                                                 shp->mlock_user);
17324         fput (shp->shm_file);
17325         security_shm_free(shp);
17326 +       put_vx_info(vxi);
17327         ipc_rcu_putref(shp);
17328  }
17329  
17330 @@ -351,11 +359,15 @@ static int newseg (struct ipc_namespace 
17331         if (ns->shm_tot + numpages > ns->shm_ctlall)
17332                 return -ENOSPC;
17333  
17334 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
17335 +               return -ENOSPC;
17336 +
17337         shp = ipc_rcu_alloc(sizeof(*shp));
17338         if (!shp)
17339                 return -ENOMEM;
17340  
17341         shp->shm_perm.key = key;
17342 +       shp->shm_perm.xid = vx_current_xid();
17343         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
17344         shp->mlock_user = NULL;
17345  
17346 @@ -406,6 +418,7 @@ static int newseg (struct ipc_namespace 
17347         file->f_dentry->d_inode->i_ino = shp->id;
17348  
17349         ns->shm_tot += numpages;
17350 +       vx_ipcshm_add(current->vx_info, key, numpages);
17351         shm_unlock(shp);
17352         return shp->id;
17353  
17354 diff -NurpP --minimal linux-2.6.22.10/ipc/util.c linux-2.6.22.10-vs2.3.0.29/ipc/util.c
17355 --- linux-2.6.22.10/ipc/util.c  2007-07-09 13:20:03 +0200
17356 +++ linux-2.6.22.10-vs2.3.0.29/ipc/util.c       2007-08-05 20:53:13 +0200
17357 @@ -32,6 +32,8 @@
17358  #include <linux/proc_fs.h>
17359  #include <linux/audit.h>
17360  #include <linux/nsproxy.h>
17361 +#include <linux/vs_base.h>
17362 +#include <linux/vserver/global.h>
17363  
17364  #include <asm/unistd.h>
17365  
17366 @@ -72,6 +74,7 @@ static struct ipc_namespace *clone_ipc_n
17367                 goto err_shm;
17368  
17369         kref_init(&ns->kref);
17370 +       atomic_inc(&vs_global_ipc_ns);
17371         return ns;
17372  
17373  err_shm:
17374 @@ -108,6 +111,7 @@ void free_ipc_ns(struct kref *kref)
17375         sem_exit_ns(ns);
17376         msg_exit_ns(ns);
17377         shm_exit_ns(ns);
17378 +       atomic_dec(&vs_global_ipc_ns);
17379         kfree(ns);
17380  }
17381  #else
17382 diff -NurpP --minimal linux-2.6.22.10/kernel/Makefile linux-2.6.22.10-vs2.3.0.29/kernel/Makefile
17383 --- linux-2.6.22.10/kernel/Makefile     2007-07-09 13:20:03 +0200
17384 +++ linux-2.6.22.10-vs2.3.0.29/kernel/Makefile  2007-08-05 20:53:13 +0200
17385 @@ -10,6 +10,8 @@ obj-y     = sched.o fork.o exec_domain.o
17386             kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
17387             hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o
17388  
17389 +obj-y    += vserver/
17390 +
17391  obj-$(CONFIG_STACKTRACE) += stacktrace.o
17392  obj-y += time/
17393  obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
17394 diff -NurpP --minimal linux-2.6.22.10/kernel/capability.c linux-2.6.22.10-vs2.3.0.29/kernel/capability.c
17395 --- linux-2.6.22.10/kernel/capability.c 2007-05-02 19:25:37 +0200
17396 +++ linux-2.6.22.10-vs2.3.0.29/kernel/capability.c      2007-08-05 20:53:13 +0200
17397 @@ -12,6 +12,7 @@
17398  #include <linux/module.h>
17399  #include <linux/security.h>
17400  #include <linux/syscalls.h>
17401 +#include <linux/vs_context.h>
17402  #include <asm/uaccess.h>
17403  
17404  unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
17405 @@ -103,6 +104,8 @@ static inline int cap_set_pg(int pgrp_nr
17406  
17407         pgrp = find_pid(pgrp_nr);
17408         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
17409 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
17410 +                       continue;
17411                 target = g;
17412                 while_each_thread(g, target) {
17413                         if (!security_capset_check(target, effective,
17414 @@ -246,8 +249,12 @@ int __capable(struct task_struct *t, int
17415  }
17416  EXPORT_SYMBOL(__capable);
17417  
17418 +#include <linux/vserver/base.h>
17419  int capable(int cap)
17420  {
17421 +       /* here for now so we don't require task locking */
17422 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
17423 +               return 0;
17424         return __capable(current, cap);
17425  }
17426  EXPORT_SYMBOL(capable);
17427 diff -NurpP --minimal linux-2.6.22.10/kernel/compat.c linux-2.6.22.10-vs2.3.0.29/kernel/compat.c
17428 --- linux-2.6.22.10/kernel/compat.c     2007-07-09 13:20:03 +0200
17429 +++ linux-2.6.22.10-vs2.3.0.29/kernel/compat.c  2007-08-05 20:53:13 +0200
17430 @@ -846,7 +846,7 @@ asmlinkage long compat_sys_time(compat_t
17431         compat_time_t i;
17432         struct timeval tv;
17433  
17434 -       do_gettimeofday(&tv);
17435 +       vx_gettimeofday(&tv);
17436         i = tv.tv_sec;
17437  
17438         if (tloc) {
17439 @@ -870,7 +870,7 @@ asmlinkage long compat_sys_stime(compat_
17440         if (err)
17441                 return err;
17442  
17443 -       do_settimeofday(&tv);
17444 +       vx_settimeofday(&tv);
17445         return 0;
17446  }
17447  
17448 diff -NurpP --minimal linux-2.6.22.10/kernel/exit.c linux-2.6.22.10-vs2.3.0.29/kernel/exit.c
17449 --- linux-2.6.22.10/kernel/exit.c       2007-07-09 13:20:03 +0200
17450 +++ linux-2.6.22.10-vs2.3.0.29/kernel/exit.c    2007-10-01 18:31:46 +0200
17451 @@ -44,6 +44,11 @@
17452  #include <linux/resource.h>
17453  #include <linux/blkdev.h>
17454  #include <linux/task_io_accounting_ops.h>
17455 +#include <linux/vs_limit.h>
17456 +#include <linux/vs_context.h>
17457 +#include <linux/vs_network.h>
17458 +#include <linux/vs_pid.h>
17459 +#include <linux/vserver/global.h>
17460  
17461  #include <asm/uaccess.h>
17462  #include <asm/unistd.h>
17463 @@ -443,9 +448,11 @@ static void close_files(struct files_str
17464                                         filp_close(file, files);
17465                                         cond_resched();
17466                                 }
17467 +                               vx_openfd_dec(i);
17468                         }
17469                         i++;
17470                         set >>= 1;
17471 +                       cond_resched();
17472                 }
17473         }
17474  }
17475 @@ -525,6 +532,7 @@ static inline void __put_fs_struct(struc
17476                         dput(fs->altroot);
17477                         mntput(fs->altrootmnt);
17478                 }
17479 +               atomic_dec(&vs_global_fs);
17480                 kmem_cache_free(fs_cachep, fs);
17481         }
17482  }
17483 @@ -596,6 +604,14 @@ static void exit_mm(struct task_struct *
17484  static inline void
17485  choose_new_parent(struct task_struct *p, struct task_struct *reaper)
17486  {
17487 +       /* check for reaper context */
17488 +       vxwprintk((p->xid != reaper->xid) && (reaper != child_reaper(p)),
17489 +               "rogue reaper: %p[%d,#%u] <> %p[%d,#%u]",
17490 +               p, p->pid, p->xid, reaper, reaper->pid, reaper->xid);
17491 +
17492 +       if (p == reaper)
17493 +               reaper = vx_child_reaper(p);
17494 +
17495         /*
17496          * Make sure we're not reparenting to ourselves and that
17497          * the parent is not a zombie.
17498 @@ -687,7 +703,7 @@ forget_original_parent(struct task_struc
17499         do {
17500                 reaper = next_thread(reaper);
17501                 if (reaper == father) {
17502 -                       reaper = child_reaper(father);
17503 +                       reaper = vx_child_reaper(father);
17504                         break;
17505                 }
17506         } while (reaper->exit_state);
17507 @@ -964,6 +980,8 @@ fastcall NORET_TYPE void do_exit(long co
17508         tsk->exit_code = code;
17509         proc_exit_connector(tsk);
17510         exit_task_namespaces(tsk);
17511 +       /* needs to stay before exit_notify() */
17512 +       exit_vx_info_early(tsk, code);
17513         exit_notify(tsk);
17514  #ifdef CONFIG_NUMA
17515         mpol_free(tsk->mempolicy);
17516 @@ -994,6 +1012,10 @@ fastcall NORET_TYPE void do_exit(long co
17517         if (tsk->splice_pipe)
17518                 __free_pipe_info(tsk->splice_pipe);
17519  
17520 +       /* needs to stay after exit_notify() */
17521 +       exit_vx_info(tsk, code);
17522 +       exit_nx_info(tsk);
17523 +
17524         preempt_disable();
17525         /* causes final put_task_struct in finish_task_switch(). */
17526         tsk->state = TASK_DEAD;
17527 diff -NurpP --minimal linux-2.6.22.10/kernel/fork.c linux-2.6.22.10-vs2.3.0.29/kernel/fork.c
17528 --- linux-2.6.22.10/kernel/fork.c       2007-07-09 13:20:03 +0200
17529 +++ linux-2.6.22.10-vs2.3.0.29/kernel/fork.c    2007-10-25 17:05:55 +0200
17530 @@ -49,6 +49,11 @@
17531  #include <linux/delayacct.h>
17532  #include <linux/taskstats_kern.h>
17533  #include <linux/random.h>
17534 +#include <linux/vs_context.h>
17535 +#include <linux/vs_network.h>
17536 +#include <linux/vs_limit.h>
17537 +#include <linux/vs_memory.h>
17538 +#include <linux/vserver/global.h>
17539  
17540  #include <asm/pgtable.h>
17541  #include <asm/pgalloc.h>
17542 @@ -108,6 +113,8 @@ void free_task(struct task_struct *tsk)
17543  {
17544         free_thread_info(tsk->stack);
17545         rt_mutex_debug_task_free(tsk);
17546 +       clr_vx_info(&tsk->vx_info);
17547 +       clr_nx_info(&tsk->nx_info);
17548         free_task_struct(tsk);
17549  }
17550  EXPORT_SYMBOL(free_task);
17551 @@ -215,6 +222,8 @@ static inline int dup_mmap(struct mm_str
17552         mm->free_area_cache = oldmm->mmap_base;
17553         mm->cached_hole_size = ~0UL;
17554         mm->map_count = 0;
17555 +       __set_mm_counter(mm, file_rss, 0);
17556 +       __set_mm_counter(mm, anon_rss, 0);
17557         cpus_clear(mm->cpu_vm_mask);
17558         mm->mm_rb = RB_ROOT;
17559         rb_link = &mm->mm_rb.rb_node;
17560 @@ -226,7 +235,7 @@ static inline int dup_mmap(struct mm_str
17561  
17562                 if (mpnt->vm_flags & VM_DONTCOPY) {
17563                         long pages = vma_pages(mpnt);
17564 -                       mm->total_vm -= pages;
17565 +                       vx_vmpages_sub(mm, pages);
17566                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
17567                                                                 -pages);
17568                         continue;
17569 @@ -327,7 +336,7 @@ static inline void mm_free_pgd(struct mm
17570  
17571  #include <linux/init_task.h>
17572  
17573 -static struct mm_struct * mm_init(struct mm_struct * mm)
17574 +static struct mm_struct * mm_init(struct mm_struct * mm, struct vx_info *vxi)
17575  {
17576         atomic_set(&mm->mm_users, 1);
17577         atomic_set(&mm->mm_count, 1);
17578 @@ -335,8 +344,8 @@ static struct mm_struct * mm_init(struct
17579         INIT_LIST_HEAD(&mm->mmlist);
17580         mm->core_waiters = 0;
17581         mm->nr_ptes = 0;
17582 -       set_mm_counter(mm, file_rss, 0);
17583 -       set_mm_counter(mm, anon_rss, 0);
17584 +       __set_mm_counter(mm, file_rss, 0);
17585 +       __set_mm_counter(mm, anon_rss, 0);
17586         spin_lock_init(&mm->page_table_lock);
17587         rwlock_init(&mm->ioctx_list_lock);
17588         mm->ioctx_list = NULL;
17589 @@ -345,6 +354,7 @@ static struct mm_struct * mm_init(struct
17590  
17591         if (likely(!mm_alloc_pgd(mm))) {
17592                 mm->def_flags = 0;
17593 +               set_vx_info(&mm->mm_vx_info, vxi);
17594                 return mm;
17595         }
17596         free_mm(mm);
17597 @@ -361,7 +371,7 @@ struct mm_struct * mm_alloc(void)
17598         mm = allocate_mm();
17599         if (mm) {
17600                 memset(mm, 0, sizeof(*mm));
17601 -               mm = mm_init(mm);
17602 +               mm = mm_init(mm, current->vx_info);
17603         }
17604         return mm;
17605  }
17606 @@ -376,6 +386,7 @@ void fastcall __mmdrop(struct mm_struct 
17607         BUG_ON(mm == &init_mm);
17608         mm_free_pgd(mm);
17609         destroy_context(mm);
17610 +       clr_vx_info(&mm->mm_vx_info);
17611         free_mm(mm);
17612  }
17613  
17614 @@ -490,12 +501,13 @@ static struct mm_struct *dup_mm(struct t
17615                 goto fail_nomem;
17616  
17617         memcpy(mm, oldmm, sizeof(*mm));
17618 +       mm->mm_vx_info = NULL;
17619  
17620         /* Initializing for Swap token stuff */
17621         mm->token_priority = 0;
17622         mm->last_interval = 0;
17623  
17624 -       if (!mm_init(mm))
17625 +       if (!mm_init(mm, oldmm->mm_vx_info))
17626                 goto fail_nomem;
17627  
17628         if (init_new_context(tsk, mm))
17629 @@ -521,6 +533,7 @@ fail_nocontext:
17630          * If init_new_context() failed, we cannot use mmput() to free the mm
17631          * because it calls destroy_context()
17632          */
17633 +       clr_vx_info(&mm->mm_vx_info);
17634         mm_free_pgd(mm);
17635         free_mm(mm);
17636         return NULL;
17637 @@ -591,6 +604,7 @@ static inline struct fs_struct *__copy_f
17638                         fs->altroot = NULL;
17639                 }
17640                 read_unlock(&old->lock);
17641 +               atomic_inc(&vs_global_fs);
17642         }
17643         return fs;
17644  }
17645 @@ -709,6 +723,8 @@ static struct files_struct *dup_fd(struc
17646                 struct file *f = *old_fds++;
17647                 if (f) {
17648                         get_file(f);
17649 +                       /* TODO: sum it first for check and performance */
17650 +                       vx_openfd_inc(open_files - i);
17651                 } else {
17652                         /*
17653                          * The fd may be claimed in the fd bitmap but not yet
17654 @@ -961,6 +977,8 @@ static struct task_struct *copy_process(
17655  {
17656         int retval;
17657         struct task_struct *p = NULL;
17658 +       struct vx_info *vxi;
17659 +       struct nx_info *nxi;
17660  
17661         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
17662                 return ERR_PTR(-EINVAL);
17663 @@ -995,12 +1013,30 @@ static struct task_struct *copy_process(
17664         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
17665         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
17666  #endif
17667 +       init_vx_info(&p->vx_info, current->vx_info);
17668 +       init_nx_info(&p->nx_info, current->nx_info);
17669 +
17670 +       /* check vserver memory */
17671 +       if (p->mm && !(clone_flags & CLONE_VM)) {
17672 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
17673 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17674 +               else
17675 +                       goto bad_fork_free;
17676 +       }
17677 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
17678 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
17679 +                       goto bad_fork_cleanup_vm;
17680 +       }
17681 +
17682         retval = -EAGAIN;
17683 +       if (!vx_nproc_avail(1))
17684 +               goto bad_fork_cleanup_vm;
17685 +
17686         if (atomic_read(&p->user->processes) >=
17687                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
17688                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
17689                                 p->user != &root_user)
17690 -                       goto bad_fork_free;
17691 +                       goto bad_fork_cleanup_vm;
17692         }
17693  
17694         atomic_inc(&p->user->__count);
17695 @@ -1265,6 +1301,18 @@ static struct task_struct *copy_process(
17696  
17697         total_forks++;
17698         spin_unlock(&current->sighand->siglock);
17699 +
17700 +       /* p is copy of current */
17701 +       vxi = p->vx_info;
17702 +       if (vxi) {
17703 +               claim_vx_info(vxi, p);
17704 +               atomic_inc(&vxi->cvirt.nr_threads);
17705 +               atomic_inc(&vxi->cvirt.total_forks);
17706 +               vx_nproc_inc(p);
17707 +       }
17708 +       nxi = p->nx_info;
17709 +       if (nxi)
17710 +               claim_nx_info(nxi, p);
17711         write_unlock_irq(&tasklist_lock);
17712         proc_fork_connector(p);
17713         return p;
17714 @@ -1306,6 +1354,9 @@ bad_fork_cleanup_count:
17715         put_group_info(p->group_info);
17716         atomic_dec(&p->user->processes);
17717         free_uid(p->user);
17718 +bad_fork_cleanup_vm:
17719 +       if (p->mm && !(clone_flags & CLONE_VM))
17720 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17721  bad_fork_free:
17722         free_task(p);
17723  fork_out:
17724 @@ -1367,6 +1418,15 @@ long do_fork(unsigned long clone_flags,
17725  
17726         if (!pid)
17727                 return -EAGAIN;
17728 +
17729 +       /* kernel threads are host only */
17730 +       if ((clone_flags & CLONE_KTHREAD) &&
17731 +               !vx_capable(CAP_SYS_ADMIN, VXC_KTHREAD)) {
17732 +               vxwprintk_task(1, "tried to spawn a kernel thread.");
17733 +               free_pid(pid);
17734 +               return -EPERM;
17735 +       }
17736 +
17737         nr = pid->nr;
17738         if (unlikely(current->ptrace)) {
17739                 trace = fork_traceflag (clone_flags);
17740 diff -NurpP --minimal linux-2.6.22.10/kernel/kthread.c linux-2.6.22.10-vs2.3.0.29/kernel/kthread.c
17741 --- linux-2.6.22.10/kernel/kthread.c    2007-07-09 13:20:03 +0200
17742 +++ linux-2.6.22.10-vs2.3.0.29/kernel/kthread.c 2007-08-05 20:53:13 +0200
17743 @@ -96,7 +96,7 @@ static void create_kthread(struct kthrea
17744         } else {
17745                 wait_for_completion(&create->started);
17746                 read_lock(&tasklist_lock);
17747 -               create->result = find_task_by_pid(pid);
17748 +               create->result = find_task_by_real_pid(pid);
17749                 read_unlock(&tasklist_lock);
17750         }
17751         complete(&create->done);
17752 diff -NurpP --minimal linux-2.6.22.10/kernel/nsproxy.c linux-2.6.22.10-vs2.3.0.29/kernel/nsproxy.c
17753 --- linux-2.6.22.10/kernel/nsproxy.c    2007-07-09 13:20:03 +0200
17754 +++ linux-2.6.22.10-vs2.3.0.29/kernel/nsproxy.c 2007-08-05 20:53:13 +0200
17755 @@ -20,14 +20,11 @@
17756  #include <linux/mnt_namespace.h>
17757  #include <linux/utsname.h>
17758  #include <linux/pid_namespace.h>
17759 +#include <linux/vserver/global.h>
17760 +#include <linux/vserver/debug.h>
17761  
17762  struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
17763  
17764 -static inline void get_nsproxy(struct nsproxy *ns)
17765 -{
17766 -       atomic_inc(&ns->count);
17767 -}
17768 -
17769  void get_task_namespaces(struct task_struct *tsk)
17770  {
17771         struct nsproxy *ns = tsk->nsproxy;
17772 @@ -46,6 +43,9 @@ static inline struct nsproxy *clone_nspr
17773         ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
17774         if (ns)
17775                 atomic_set(&ns->count, 1);
17776 +       vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
17777 +               orig, atomic_read(&orig->count), ns);
17778 +       atomic_inc(&vs_global_nsproxy);
17779         return ns;
17780  }
17781  
17782 @@ -54,28 +54,32 @@ static inline struct nsproxy *clone_nspr
17783   * Return the newly created nsproxy.  Do not attach this to the task,
17784   * leave it to the caller to do proper locking and attach it to task.
17785   */
17786 -static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17787 +static struct nsproxy *unshare_namespaces(int flags, struct nsproxy *orig,
17788                         struct fs_struct *new_fs)
17789  {
17790         struct nsproxy *new_nsp;
17791  
17792 -       new_nsp = clone_nsproxy(tsk->nsproxy);
17793 +       vxdprintk(VXD_CBIT(space, 4),
17794 +               "unshare_namespaces(0x%08x,%p,%p)",
17795 +               flags, orig, new_fs);
17796 +
17797 +       new_nsp = clone_nsproxy(orig);
17798         if (!new_nsp)
17799                 return ERR_PTR(-ENOMEM);
17800  
17801 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
17802 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
17803         if (IS_ERR(new_nsp->mnt_ns))
17804                 goto out_ns;
17805  
17806 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
17807 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
17808         if (IS_ERR(new_nsp->uts_ns))
17809                 goto out_uts;
17810  
17811 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
17812 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
17813         if (IS_ERR(new_nsp->ipc_ns))
17814                 goto out_ipc;
17815  
17816 -       new_nsp->pid_ns = copy_pid_ns(flags, tsk->nsproxy->pid_ns);
17817 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
17818         if (IS_ERR(new_nsp->pid_ns))
17819                 goto out_pid;
17820  
17821 @@ -95,6 +99,33 @@ out_ns:
17822         return ERR_PTR(-ENOMEM);
17823  }
17824  
17825 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17826 +                       struct fs_struct *new_fs)
17827 +{
17828 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
17829 +}
17830 +
17831 +/*
17832 + * copies the nsproxy, setting refcount to 1, and grabbing a
17833 + * reference to all contained namespaces.
17834 + */
17835 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
17836 +{
17837 +       struct nsproxy *ns = clone_nsproxy(orig);
17838 +
17839 +       if (ns) {
17840 +               if (ns->mnt_ns)
17841 +                       get_mnt_ns(ns->mnt_ns);
17842 +               if (ns->uts_ns)
17843 +                       get_uts_ns(ns->uts_ns);
17844 +               if (ns->ipc_ns)
17845 +                       get_ipc_ns(ns->ipc_ns);
17846 +               if (ns->pid_ns)
17847 +                       get_pid_ns(ns->pid_ns);
17848 +       }
17849 +       return ns;
17850 +}
17851 +
17852  /*
17853   * called from clone.  This now handles copy for nsproxy and all
17854   * namespaces therein.
17855 @@ -102,9 +133,12 @@ out_ns:
17856  int copy_namespaces(int flags, struct task_struct *tsk)
17857  {
17858         struct nsproxy *old_ns = tsk->nsproxy;
17859 -       struct nsproxy *new_ns;
17860 +       struct nsproxy *new_ns = NULL;
17861         int err = 0;
17862  
17863 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08x,%p[%p])",
17864 +               flags, tsk, old_ns);
17865 +
17866         if (!old_ns)
17867                 return 0;
17868  
17869 @@ -127,6 +161,9 @@ int copy_namespaces(int flags, struct ta
17870         tsk->nsproxy = new_ns;
17871  out:
17872         put_nsproxy(old_ns);
17873 +       vxdprintk(VXD_CBIT(space, 3),
17874 +               "copy_namespaces(0x%08x,%p[%p]) = %d [%p]",
17875 +               flags, tsk, old_ns, err, new_ns);
17876         return err;
17877  }
17878  
17879 @@ -140,6 +177,7 @@ void free_nsproxy(struct nsproxy *ns)
17880                 put_ipc_ns(ns->ipc_ns);
17881         if (ns->pid_ns)
17882                 put_pid_ns(ns->pid_ns);
17883 +       atomic_dec(&vs_global_nsproxy);
17884         kfree(ns);
17885  }
17886  
17887 @@ -152,6 +190,10 @@ int unshare_nsproxy_namespaces(unsigned 
17888  {
17889         int err = 0;
17890  
17891 +       vxdprintk(VXD_CBIT(space, 4),
17892 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
17893 +               unshare_flags, current->nsproxy);
17894 +
17895         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC)))
17896                 return 0;
17897  
17898 diff -NurpP --minimal linux-2.6.22.10/kernel/pid.c linux-2.6.22.10-vs2.3.0.29/kernel/pid.c
17899 --- linux-2.6.22.10/kernel/pid.c        2007-07-09 13:20:03 +0200
17900 +++ linux-2.6.22.10-vs2.3.0.29/kernel/pid.c     2007-08-05 20:53:13 +0200
17901 @@ -28,6 +28,7 @@
17902  #include <linux/hash.h>
17903  #include <linux/pid_namespace.h>
17904  #include <linux/init_task.h>
17905 +#include <linux/vs_pid.h>
17906  
17907  #define pid_hashfn(nr) hash_long((unsigned long)nr, pidhash_shift)
17908  static struct hlist_head *pid_hash;
17909 @@ -295,6 +296,9 @@ void fastcall transfer_pid(struct task_s
17910  struct task_struct * fastcall pid_task(struct pid *pid, enum pid_type type)
17911  {
17912         struct task_struct *result = NULL;
17913 +
17914 +       if (type == PIDTYPE_REALPID)
17915 +               type = PIDTYPE_PID;
17916         if (pid) {
17917                 struct hlist_node *first;
17918                 first = rcu_dereference(pid->tasks[type].first);
17919 @@ -309,7 +313,17 @@ struct task_struct * fastcall pid_task(s
17920   */
17921  struct task_struct *find_task_by_pid_type(int type, int nr)
17922  {
17923 -       return pid_task(find_pid(nr), type);
17924 +       struct task_struct *task;
17925 +
17926 +       if (type == PIDTYPE_PID)
17927 +               nr = vx_rmap_pid(nr);
17928 +
17929 +       task = pid_task(find_pid(nr), type);
17930 +       if (task && (type != PIDTYPE_REALPID) &&
17931 +               /* maybe VS_WATCH_P in the future? */
17932 +               !vx_check(task->xid, VS_WATCH|VS_IDENT))
17933 +               return NULL;
17934 +       return task;
17935  }
17936  
17937  EXPORT_SYMBOL(find_task_by_pid_type);
17938 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
17939 --- linux-2.6.22.10/kernel/posix-timers.c       2007-07-09 13:20:03 +0200
17940 +++ linux-2.6.22.10-vs2.3.0.29/kernel/posix-timers.c    2007-10-01 15:41:45 +0200
17941 @@ -47,6 +47,7 @@
17942  #include <linux/wait.h>
17943  #include <linux/workqueue.h>
17944  #include <linux/module.h>
17945 +#include <linux/vs_context.h>
17946  
17947  /*
17948   * Management arrays for POSIX timers.  Timers are kept in slab memory
17949 @@ -297,6 +298,12 @@ void do_schedule_next_timer(struct sigin
17950  
17951  int posix_timer_event(struct k_itimer *timr,int si_private)
17952  {
17953 +       struct vx_info_save vxis;
17954 +       struct vx_info *vxi;
17955 +       int ret;
17956 +
17957 +       vxi = task_get_vx_info(timr->it_process);
17958 +       enter_vx_info(vxi, &vxis);
17959         memset(&timr->sigq->info, 0, sizeof(siginfo_t));
17960         timr->sigq->info.si_sys_private = si_private;
17961         /* Send signal to the process that owns this timer.*/
17962 @@ -309,11 +316,11 @@ int posix_timer_event(struct k_itimer *t
17963  
17964         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
17965                 struct task_struct *leader;
17966 -               int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
17967 -                                       timr->it_process);
17968  
17969 +               ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
17970 +                                   timr->it_process);
17971                 if (likely(ret >= 0))
17972 -                       return ret;
17973 +                       goto out;
17974  
17975                 timr->it_sigev_notify = SIGEV_SIGNAL;
17976                 leader = timr->it_process->group_leader;
17977 @@ -321,8 +328,12 @@ int posix_timer_event(struct k_itimer *t
17978                 timr->it_process = leader;
17979         }
17980  
17981 -       return send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
17982 +       ret = send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
17983                                    timr->it_process);
17984 +out:
17985 +       leave_vx_info(&vxis);
17986 +       put_vx_info(vxi);
17987 +       return ret;
17988  }
17989  EXPORT_SYMBOL_GPL(posix_timer_event);
17990  
17991 @@ -402,7 +413,7 @@ static struct task_struct * good_sigeven
17992         struct task_struct *rtn = current->group_leader;
17993  
17994         if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
17995 -               (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
17996 +               (!(rtn = find_task_by_real_pid(event->sigev_notify_thread_id)) ||
17997                  rtn->tgid != current->tgid ||
17998                  (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
17999                 return NULL;
18000 diff -NurpP --minimal linux-2.6.22.10/kernel/printk.c linux-2.6.22.10-vs2.3.0.29/kernel/printk.c
18001 --- linux-2.6.22.10/kernel/printk.c     2007-07-09 13:20:03 +0200
18002 +++ linux-2.6.22.10-vs2.3.0.29/kernel/printk.c  2007-08-05 20:53:13 +0200
18003 @@ -31,6 +31,7 @@
18004  #include <linux/bootmem.h>
18005  #include <linux/syscalls.h>
18006  #include <linux/jiffies.h>
18007 +#include <linux/vs_cvirt.h>
18008  
18009  #include <asm/uaccess.h>
18010  
18011 @@ -182,18 +183,13 @@ int do_syslog(int type, char __user *buf
18012         unsigned long i, j, limit, count;
18013         int do_clear = 0;
18014         char c;
18015 -       int error = 0;
18016 +       int error;
18017  
18018         error = security_syslog(type);
18019         if (error)
18020                 return error;
18021  
18022 -       switch (type) {
18023 -       case 0:         /* Close log */
18024 -               break;
18025 -       case 1:         /* Open log */
18026 -               break;
18027 -       case 2:         /* Read from log */
18028 +       if ((type >= 2) && (type <= 4)) {
18029                 error = -EINVAL;
18030                 if (!buf || len < 0)
18031                         goto out;
18032 @@ -204,6 +200,16 @@ int do_syslog(int type, char __user *buf
18033                         error = -EFAULT;
18034                         goto out;
18035                 }
18036 +       }
18037 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
18038 +               return vx_do_syslog(type, buf, len);
18039 +
18040 +       switch (type) {
18041 +       case 0:         /* Close log */
18042 +               break;
18043 +       case 1:         /* Open log */
18044 +               break;
18045 +       case 2:         /* Read from log */
18046                 error = wait_event_interruptible(log_wait,
18047                                                         (log_start - log_end));
18048                 if (error)
18049 @@ -228,16 +234,6 @@ int do_syslog(int type, char __user *buf
18050                 do_clear = 1;
18051                 /* FALL THRU */
18052         case 3:         /* Read last kernel messages */
18053 -               error = -EINVAL;
18054 -               if (!buf || len < 0)
18055 -                       goto out;
18056 -               error = 0;
18057 -               if (!len)
18058 -                       goto out;
18059 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
18060 -                       error = -EFAULT;
18061 -                       goto out;
18062 -               }
18063                 count = len;
18064                 if (count > log_buf_len)
18065                         count = log_buf_len;
18066 diff -NurpP --minimal linux-2.6.22.10/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/kernel/ptrace.c
18067 --- linux-2.6.22.10/kernel/ptrace.c     2007-07-09 13:20:03 +0200
18068 +++ linux-2.6.22.10-vs2.3.0.29/kernel/ptrace.c  2007-08-05 20:53:13 +0200
18069 @@ -19,6 +19,7 @@
18070  #include <linux/security.h>
18071  #include <linux/signal.h>
18072  #include <linux/audit.h>
18073 +#include <linux/vs_context.h>
18074  
18075  #include <asm/pgtable.h>
18076  #include <asm/uaccess.h>
18077 @@ -145,6 +146,11 @@ static int may_attach(struct task_struct
18078                 dumpable = task->mm->dumpable;
18079         if (!dumpable && !capable(CAP_SYS_PTRACE))
18080                 return -EPERM;
18081 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
18082 +               return -EPERM;
18083 +       if (!vx_check(task->xid, VS_IDENT) &&
18084 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
18085 +               return -EACCES;
18086  
18087         return security_ptrace(current, task);
18088  }
18089 @@ -471,6 +477,10 @@ asmlinkage long sys_ptrace(long request,
18090                 goto out;
18091         }
18092  
18093 +       ret = -EPERM;
18094 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
18095 +               goto out_put_task_struct;
18096 +
18097         if (request == PTRACE_ATTACH) {
18098                 ret = ptrace_attach(child);
18099                 goto out_put_task_struct;
18100 diff -NurpP --minimal linux-2.6.22.10/kernel/sched.c linux-2.6.22.10-vs2.3.0.29/kernel/sched.c
18101 --- linux-2.6.22.10/kernel/sched.c      2007-07-09 13:20:03 +0200
18102 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched.c   2007-08-05 20:53:13 +0200
18103 @@ -56,6 +56,8 @@
18104  
18105  #include <asm/tlb.h>
18106  #include <asm/unistd.h>
18107 +#include <linux/vs_sched.h>
18108 +#include <linux/vs_cvirt.h>
18109  
18110  /*
18111   * Scheduler clock - returns current time in nanosec units.
18112 @@ -281,6 +283,16 @@ struct rq {
18113         struct task_struct *migration_thread;
18114         struct list_head migration_queue;
18115  #endif
18116 +       unsigned long norm_time;
18117 +       unsigned long idle_time;
18118 +#ifdef CONFIG_VSERVER_IDLETIME
18119 +       int idle_skip;
18120 +#endif
18121 +#ifdef CONFIG_VSERVER_HARDCPU
18122 +       struct list_head hold_queue;
18123 +       unsigned long nr_onhold;
18124 +       int idle_tokens;
18125 +#endif
18126  
18127  #ifdef CONFIG_SCHEDSTATS
18128         /* latency stats */
18129 @@ -714,6 +726,7 @@ sched_info_switch(struct task_struct *pr
18130   */
18131  static void dequeue_task(struct task_struct *p, struct prio_array *array)
18132  {
18133 +       BUG_ON(p->state & TASK_ONHOLD);
18134         array->nr_active--;
18135         list_del(&p->run_list);
18136         if (list_empty(array->queue + p->prio))
18137 @@ -722,6 +735,7 @@ static void dequeue_task(struct task_str
18138  
18139  static void enqueue_task(struct task_struct *p, struct prio_array *array)
18140  {
18141 +       BUG_ON(p->state & TASK_ONHOLD);
18142         sched_info_queued(p);
18143         list_add_tail(&p->run_list, array->queue + p->prio);
18144         __set_bit(p->prio, array->bitmap);
18145 @@ -735,12 +749,14 @@ static void enqueue_task(struct task_str
18146   */
18147  static void requeue_task(struct task_struct *p, struct prio_array *array)
18148  {
18149 +       BUG_ON(p->state & TASK_ONHOLD);
18150         list_move_tail(&p->run_list, array->queue + p->prio);
18151  }
18152  
18153  static inline void
18154  enqueue_task_head(struct task_struct *p, struct prio_array *array)
18155  {
18156 +       BUG_ON(p->state & TASK_ONHOLD);
18157         list_add(&p->run_list, array->queue + p->prio);
18158         __set_bit(p->prio, array->bitmap);
18159         array->nr_active++;
18160 @@ -769,6 +785,10 @@ static inline int __normal_prio(struct t
18161         bonus = CURRENT_BONUS(p) - MAX_BONUS / 2;
18162  
18163         prio = p->static_prio - bonus;
18164 +
18165 +       /* adjust effective priority */
18166 +       prio = vx_adjust_prio(p, prio, MAX_USER_PRIO);
18167 +
18168         if (prio < MAX_RT_PRIO)
18169                 prio = MAX_RT_PRIO;
18170         if (prio > MAX_PRIO-1)
18171 @@ -878,6 +898,9 @@ static int effective_prio(struct task_st
18172         return p->prio;
18173  }
18174  
18175 +#include "sched_mon.h"
18176 +
18177 +
18178  /*
18179   * __activate_task - move a task to the runqueue.
18180   */
18181 @@ -887,6 +910,7 @@ static void __activate_task(struct task_
18182  
18183         if (batch_task(p))
18184                 target = rq->expired;
18185 +       vxm_activate_task(p, rq);
18186         enqueue_task(p, target);
18187         inc_nr_running(p, rq);
18188  }
18189 @@ -896,6 +920,7 @@ static void __activate_task(struct task_
18190   */
18191  static inline void __activate_idle_task(struct task_struct *p, struct rq *rq)
18192  {
18193 +       vxm_activate_idle(p, rq);
18194         enqueue_task_head(p, rq->active);
18195         inc_nr_running(p, rq);
18196  }
18197 @@ -1030,19 +1055,30 @@ static void activate_task(struct task_st
18198         }
18199         p->timestamp = now;
18200  out:
18201 +       vx_activate_task(p);
18202         __activate_task(p, rq);
18203  }
18204  
18205  /*
18206 - * deactivate_task - remove a task from the runqueue.
18207 + * __deactivate_task - remove a task from the runqueue.
18208   */
18209 -static void deactivate_task(struct task_struct *p, struct rq *rq)
18210 +static void __deactivate_task(struct task_struct *p, struct rq *rq)
18211  {
18212         dec_nr_running(p, rq);
18213         dequeue_task(p, p->array);
18214 +       vxm_deactivate_task(p, rq);
18215         p->array = NULL;
18216  }
18217  
18218 +static inline
18219 +void deactivate_task(struct task_struct *p, struct rq *rq)
18220 +{
18221 +       vx_deactivate_task(p);
18222 +       __deactivate_task(p, rq);
18223 +}
18224 +
18225 +#include "sched_hard.h"
18226 +
18227  /*
18228   * resched_task - mark a task 'to be rescheduled now'.
18229   *
18230 @@ -1129,6 +1165,7 @@ migrate_task(struct task_struct *p, int 
18231  {
18232         struct rq *rq = task_rq(p);
18233  
18234 +       vxm_migrate_task(p, rq, dest_cpu);
18235         /*
18236          * If the task is not on a runqueue (and not running), then
18237          * it is sufficient to simply update the task's cpu field.
18238 @@ -1518,6 +1555,12 @@ static int try_to_wake_up(struct task_st
18239  
18240         rq = task_rq_lock(p, &flags);
18241         old_state = p->state;
18242 +
18243 +       /* we need to unhold suspended tasks */
18244 +       if (old_state & TASK_ONHOLD) {
18245 +               vx_unhold_task(p, rq);
18246 +               old_state = p->state;
18247 +       }
18248         if (!(old_state & state))
18249                 goto out;
18250  
18251 @@ -1625,6 +1668,7 @@ out_activate:
18252  #endif /* CONFIG_SMP */
18253         if (old_state == TASK_UNINTERRUPTIBLE) {
18254                 rq->nr_uninterruptible--;
18255 +               vx_uninterruptible_dec(p);
18256                 /*
18257                  * Tasks on involuntary sleep don't earn
18258                  * sleep_avg beyond just interactive state.
18259 @@ -1676,7 +1720,7 @@ int fastcall wake_up_state(struct task_s
18260         return try_to_wake_up(p, state, 0);
18261  }
18262  
18263 -static void task_running_tick(struct rq *rq, struct task_struct *p);
18264 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu);
18265  /*
18266   * Perform scheduler related setup for a newly forked process p.
18267   * p is forked by current.
18268 @@ -1737,7 +1781,7 @@ void fastcall sched_fork(struct task_str
18269                  * runqueue lock is not a problem.
18270                  */
18271                 current->time_slice = 1;
18272 -               task_running_tick(cpu_rq(cpu), current);
18273 +               task_running_tick(cpu_rq(cpu), current, cpu);
18274         }
18275         local_irq_enable();
18276         put_cpu();
18277 @@ -1772,6 +1816,7 @@ void fastcall wake_up_new_task(struct ta
18278  
18279         p->prio = effective_prio(p);
18280  
18281 +       vx_activate_task(p);
18282         if (likely(cpu == this_cpu)) {
18283                 if (!(clone_flags & CLONE_VM)) {
18284                         /*
18285 @@ -1783,6 +1828,7 @@ void fastcall wake_up_new_task(struct ta
18286                                 __activate_task(p, rq);
18287                         else {
18288                                 p->prio = current->prio;
18289 +                               BUG_ON(p->state & TASK_ONHOLD);
18290                                 p->normal_prio = current->normal_prio;
18291                                 list_add_tail(&p->run_list, &current->run_list);
18292                                 p->array = current->array;
18293 @@ -3351,13 +3397,16 @@ static inline int expired_starving(struc
18294  void account_user_time(struct task_struct *p, cputime_t cputime)
18295  {
18296         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18297 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18298         cputime64_t tmp;
18299 +       int nice = (TASK_NICE(p) > 0);
18300  
18301         p->utime = cputime_add(p->utime, cputime);
18302 +       vx_account_user(vxi, cputime, nice);
18303  
18304         /* Add user time to cpustat. */
18305         tmp = cputime_to_cputime64(cputime);
18306 -       if (TASK_NICE(p) > 0)
18307 +       if (nice)
18308                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
18309         else
18310                 cpustat->user = cputime64_add(cpustat->user, tmp);
18311 @@ -3373,10 +3422,12 @@ void account_system_time(struct task_str
18312                          cputime_t cputime)
18313  {
18314         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18315 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18316         struct rq *rq = this_rq();
18317         cputime64_t tmp;
18318  
18319         p->stime = cputime_add(p->stime, cputime);
18320 +       vx_account_system(vxi, cputime, (p == rq->idle));
18321  
18322         /* Add system time to cpustat. */
18323         tmp = cputime_to_cputime64(cputime);
18324 @@ -3415,7 +3466,7 @@ void account_steal_time(struct task_stru
18325                 cpustat->steal = cputime64_add(cpustat->steal, tmp);
18326  }
18327  
18328 -static void task_running_tick(struct rq *rq, struct task_struct *p)
18329 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu)
18330  {
18331         if (p->array != rq->active) {
18332                 /* Task has expired but was not scheduled yet */
18333 @@ -3445,7 +3496,7 @@ static void task_running_tick(struct rq 
18334                 }
18335                 goto out_unlock;
18336         }
18337 -       if (!--p->time_slice) {
18338 +       if (vx_need_resched(p, --p->time_slice, cpu)) {
18339                 dequeue_task(p, rq->active);
18340                 set_tsk_need_resched(p);
18341                 p->prio = effective_prio(p);
18342 @@ -3506,9 +3557,12 @@ void scheduler_tick(void)
18343         struct rq *rq = cpu_rq(cpu);
18344  
18345         update_cpu_clock(p, rq, now);
18346 +       vxm_sync(now, cpu);
18347  
18348 -       if (!idle_at_tick)
18349 -               task_running_tick(rq, p);
18350 +       if (idle_at_tick)
18351 +               vx_idle_resched(rq);
18352 +       else
18353 +               task_running_tick(rq, p, cpu);
18354  #ifdef CONFIG_SMP
18355         update_load(rq);
18356         rq->idle_at_tick = idle_at_tick;
18357 @@ -3630,14 +3684,25 @@ need_resched_nonpreemptible:
18358                                 unlikely(signal_pending(prev))))
18359                         prev->state = TASK_RUNNING;
18360                 else {
18361 -                       if (prev->state == TASK_UNINTERRUPTIBLE)
18362 +                       if (prev->state == TASK_UNINTERRUPTIBLE) {
18363                                 rq->nr_uninterruptible++;
18364 +                               vx_uninterruptible_inc(prev);
18365 +                       }
18366                         deactivate_task(prev, rq);
18367                 }
18368         }
18369  
18370         cpu = smp_processor_id();
18371 +       vx_set_rq_time(rq, jiffies);
18372 +try_unhold:
18373 +       vx_try_unhold(rq, cpu);
18374 +pick_next:
18375 +
18376         if (unlikely(!rq->nr_running)) {
18377 +               /* can we skip idle time? */
18378 +               if (vx_try_skip(rq, cpu))
18379 +                       goto try_unhold;
18380 +
18381                 idle_balance(cpu, rq);
18382                 if (!rq->nr_running) {
18383                         next = rq->idle;
18384 @@ -3663,6 +3728,10 @@ need_resched_nonpreemptible:
18385         queue = array->queue + idx;
18386         next = list_entry(queue->next, struct task_struct, run_list);
18387  
18388 +       /* check before we schedule this context */
18389 +       if (!vx_schedule(next, rq, cpu))
18390 +               goto pick_next;
18391 +
18392         if (!rt_task(next) && interactive_sleep(next->sleep_type)) {
18393                 unsigned long long delta = now - next->timestamp;
18394                 if (unlikely((long long)(now - next->timestamp) < 0))
18395 @@ -4263,7 +4332,7 @@ asmlinkage long sys_nice(int increment)
18396                 nice = 19;
18397  
18398         if (increment < 0 && !can_nice(current, nice))
18399 -               return -EPERM;
18400 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
18401  
18402         retval = security_task_setnice(current, nice);
18403         if (retval)
18404 @@ -4435,6 +4504,7 @@ recheck:
18405         oldprio = p->prio;
18406         __setscheduler(p, policy, param->sched_priority);
18407         if (array) {
18408 +               vx_activate_task(p);
18409                 __activate_task(p, rq);
18410                 /*
18411                  * Reschedule if we are currently running on this runqueue and
18412 @@ -5188,6 +5258,7 @@ static int __migrate_task(struct task_st
18413                 p->timestamp = p->timestamp - rq_src->most_recent_timestamp
18414                                 + rq_dest->most_recent_timestamp;
18415                 deactivate_task(p, rq_src);
18416 +               vx_activate_task(p);
18417                 __activate_task(p, rq_dest);
18418                 if (TASK_PREEMPTS_CURR(p, rq_dest))
18419                         resched_task(rq_dest->curr);
18420 @@ -7058,7 +7129,10 @@ void __init sched_init(void)
18421                 INIT_LIST_HEAD(&rq->migration_queue);
18422  #endif
18423                 atomic_set(&rq->nr_iowait, 0);
18424 -
18425 +#ifdef CONFIG_VSERVER_HARDCPU
18426 +               INIT_LIST_HEAD(&rq->hold_queue);
18427 +               rq->nr_onhold = 0;
18428 +#endif
18429                 for (j = 0; j < 2; j++) {
18430                         array = rq->arrays + j;
18431                         for (k = 0; k < MAX_PRIO; k++) {
18432 @@ -7144,6 +7218,7 @@ void normalize_rt_tasks(void)
18433                         deactivate_task(p, task_rq(p));
18434                 __setscheduler(p, SCHED_NORMAL, 0);
18435                 if (array) {
18436 +                       vx_activate_task(p);
18437                         __activate_task(p, task_rq(p));
18438                         resched_task(rq->curr);
18439                 }
18440 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
18441 --- linux-2.6.22.10/kernel/sched_hard.h 1970-01-01 01:00:00 +0100
18442 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched_hard.h      2007-08-05 20:53:13 +0200
18443 @@ -0,0 +1,324 @@
18444 +
18445 +#ifdef CONFIG_VSERVER_IDLELIMIT
18446 +
18447 +/*
18448 + * vx_idle_resched - reschedule after maxidle
18449 + */
18450 +static inline
18451 +void vx_idle_resched(struct rq *rq)
18452 +{
18453 +       /* maybe have a better criterion for paused */
18454 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
18455 +               set_need_resched();
18456 +}
18457 +
18458 +#else /* !CONFIG_VSERVER_IDLELIMIT */
18459 +
18460 +#define vx_idle_resched(rq)
18461 +
18462 +#endif /* CONFIG_VSERVER_IDLELIMIT */
18463 +
18464 +
18465 +
18466 +#ifdef CONFIG_VSERVER_IDLETIME
18467 +
18468 +#define vx_set_rq_min_skip(rq, min)            \
18469 +       (rq)->idle_skip = (min)
18470 +
18471 +#define vx_save_min_skip(ret, min, val)                \
18472 +       __vx_save_min_skip(ret, min, val)
18473 +
18474 +static inline
18475 +void __vx_save_min_skip(int ret, int *min, int val)
18476 +{
18477 +       if (ret > -2)
18478 +               return;
18479 +       if ((*min > val) || !*min)
18480 +               *min = val;
18481 +}
18482 +
18483 +static inline
18484 +int vx_try_skip(struct rq *rq, int cpu)
18485 +{
18486 +       /* artificially advance time */
18487 +       if (rq->idle_skip > 0) {
18488 +               vxdprintk(list_empty(&rq->hold_queue),
18489 +                       "hold queue empty on cpu %d", cpu);
18490 +               rq->idle_time += rq->idle_skip;
18491 +               vxm_idle_skip(rq, cpu);
18492 +               return 1;
18493 +       }
18494 +       return 0;
18495 +}
18496 +
18497 +#else /* !CONFIG_VSERVER_IDLETIME */
18498 +
18499 +#define vx_set_rq_min_skip(rq, min)            \
18500 +       ({ int dummy = (min); dummy; })
18501 +
18502 +#define vx_save_min_skip(ret, min, val)
18503 +
18504 +static inline
18505 +int vx_try_skip(struct rq *rq, int cpu)
18506 +{
18507 +       return 0;
18508 +}
18509 +
18510 +#endif /* CONFIG_VSERVER_IDLETIME */
18511 +
18512 +
18513 +
18514 +#ifdef CONFIG_VSERVER_HARDCPU
18515 +
18516 +#define vx_set_rq_max_idle(rq, max)            \
18517 +       (rq)->idle_tokens = (max)
18518 +
18519 +#define vx_save_max_idle(ret, min, val)                \
18520 +       __vx_save_max_idle(ret, min, val)
18521 +
18522 +static inline
18523 +void __vx_save_max_idle(int ret, int *min, int val)
18524 +{
18525 +       if (*min > val)
18526 +               *min = val;
18527 +}
18528 +
18529 +
18530 +/*
18531 + * vx_hold_task - put a task on the hold queue
18532 + */
18533 +static inline
18534 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18535 +{
18536 +       __deactivate_task(p, rq);
18537 +       p->state |= TASK_ONHOLD;
18538 +       /* a new one on hold */
18539 +       rq->nr_onhold++;
18540 +       vxm_hold_task(p, rq);
18541 +       list_add_tail(&p->run_list, &rq->hold_queue);
18542 +}
18543 +
18544 +/*
18545 + * vx_unhold_task - put a task back to the runqueue
18546 + */
18547 +static inline
18548 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18549 +{
18550 +       list_del(&p->run_list);
18551 +       /* one less waiting */
18552 +       rq->nr_onhold--;
18553 +       p->state &= ~TASK_ONHOLD;
18554 +       enqueue_task(p, rq->expired);
18555 +       inc_nr_running(p, rq);
18556 +       vxm_unhold_task(p, rq);
18557 +
18558 +       if (p->static_prio < rq->best_expired_prio)
18559 +               rq->best_expired_prio = p->static_prio;
18560 +}
18561 +
18562 +unsigned long nr_onhold(void)
18563 +{
18564 +       unsigned long i, sum = 0;
18565 +
18566 +       for_each_online_cpu(i)
18567 +               sum += cpu_rq(i)->nr_onhold;
18568 +
18569 +       return sum;
18570 +}
18571 +
18572 +
18573 +
18574 +static inline
18575 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
18576 +{
18577 +       return sched_pc->tokens;
18578 +}
18579 +
18580 +static inline
18581 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
18582 +{
18583 +       sched_pc->tokens--;
18584 +}
18585 +
18586 +static inline
18587 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18588 +{
18589 +       struct vx_info *vxi = p->vx_info;
18590 +
18591 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
18592 +               struct _vx_sched_pc *sched_pc =
18593 +                       &vx_per_cpu(vxi, sched_pc, cpu);
18594 +               int tokens;
18595 +
18596 +               /* maybe we can simplify that to decrement
18597 +                  the token counter unconditional? */
18598 +
18599 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
18600 +                       __vx_consume_token(sched_pc);
18601 +
18602 +               /* for tokens > 0, one token was consumed */
18603 +               if (tokens < 2)
18604 +                       slice = 0;
18605 +       }
18606 +       vxm_need_resched(p, slice, cpu);
18607 +       return (slice == 0);
18608 +}
18609 +
18610 +
18611 +#define vx_set_rq_time(rq, time) do {  \
18612 +       rq->norm_time = time;           \
18613 +} while (0)
18614 +
18615 +
18616 +static inline
18617 +void vx_try_unhold(struct rq *rq, int cpu)
18618 +{
18619 +       struct vx_info *vxi = NULL;
18620 +       struct list_head *l, *n;
18621 +       int maxidle = HZ;
18622 +       int minskip = 0;
18623 +
18624 +       /* nothing to do? what about pause? */
18625 +       if (list_empty(&rq->hold_queue))
18626 +               return;
18627 +
18628 +       list_for_each_safe(l, n, &rq->hold_queue) {
18629 +               int ret, delta_min[2];
18630 +               struct _vx_sched_pc *sched_pc;
18631 +               struct task_struct *p;
18632 +
18633 +               p = list_entry(l, struct task_struct, run_list);
18634 +               /* don't bother with same context */
18635 +               if (vxi == p->vx_info)
18636 +                       continue;
18637 +
18638 +               vxi = p->vx_info;
18639 +               /* ignore paused contexts */
18640 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
18641 +                       continue;
18642 +
18643 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18644 +
18645 +               /* recalc tokens */
18646 +               vxm_sched_info(sched_pc, vxi, cpu);
18647 +               ret = vx_tokens_recalc(sched_pc,
18648 +                       &rq->norm_time, &rq->idle_time, delta_min);
18649 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18650 +
18651 +               if (ret > 0) {
18652 +                       /* we found a runable context */
18653 +                       vx_unhold_task(p, rq);
18654 +                       break;
18655 +               }
18656 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
18657 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
18658 +       }
18659 +       vx_set_rq_max_idle(rq, maxidle);
18660 +       vx_set_rq_min_skip(rq, minskip);
18661 +       vxm_rq_max_min(rq, cpu);
18662 +}
18663 +
18664 +
18665 +static inline
18666 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18667 +{
18668 +       struct vx_info *vxi = next->vx_info;
18669 +       struct _vx_sched_pc *sched_pc;
18670 +       int delta_min[2];
18671 +       int flags, ret;
18672 +
18673 +       if (!vxi)
18674 +               return 1;
18675 +
18676 +       flags = vxi->vx_flags;
18677 +
18678 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
18679 +               goto put_on_hold;
18680 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
18681 +               return 1;
18682 +
18683 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18684 +#ifdef CONFIG_SMP
18685 +       /* update scheduler params */
18686 +       if (cpu_isset(cpu, vxi->sched.update)) {
18687 +               vx_update_sched_param(&vxi->sched, sched_pc);
18688 +               vxm_update_sched(sched_pc, vxi, cpu);
18689 +               cpu_clear(cpu, vxi->sched.update);
18690 +       }
18691 +#endif
18692 +       vxm_sched_info(sched_pc, vxi, cpu);
18693 +       ret  = vx_tokens_recalc(sched_pc,
18694 +               &rq->norm_time, &rq->idle_time, delta_min);
18695 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18696 +
18697 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
18698 +               return 1;
18699 +
18700 +       if (unlikely(ret < 0)) {
18701 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
18702 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
18703 +               vxm_rq_max_min(rq, cpu);
18704 +       put_on_hold:
18705 +               vx_hold_task(next, rq);
18706 +               return 0;
18707 +       }
18708 +       return 1;
18709 +}
18710 +
18711 +
18712 +#else /* CONFIG_VSERVER_HARDCPU */
18713 +
18714 +static inline
18715 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18716 +{
18717 +       return;
18718 +}
18719 +
18720 +static inline
18721 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18722 +{
18723 +       return;
18724 +}
18725 +
18726 +unsigned long nr_onhold(void)
18727 +{
18728 +       return 0;
18729 +}
18730 +
18731 +
18732 +static inline
18733 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18734 +{
18735 +       return (slice == 0);
18736 +}
18737 +
18738 +
18739 +#define vx_set_rq_time(rq, time)
18740 +
18741 +static inline
18742 +void vx_try_unhold(struct rq *rq, int cpu)
18743 +{
18744 +       return;
18745 +}
18746 +
18747 +static inline
18748 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18749 +{
18750 +       struct vx_info *vxi = next->vx_info;
18751 +       struct _vx_sched_pc *sched_pc;
18752 +       int delta_min[2];
18753 +       int ret;
18754 +
18755 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
18756 +               return 1;
18757 +
18758 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18759 +       vxm_sched_info(sched_pc, vxi, cpu);
18760 +       ret  = vx_tokens_recalc(sched_pc,
18761 +               &rq->norm_time, &rq->idle_time, delta_min);
18762 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18763 +       return 1;
18764 +}
18765 +
18766 +#endif /* CONFIG_VSERVER_HARDCPU */
18767 +
18768 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
18769 --- linux-2.6.22.10/kernel/sched_mon.h  1970-01-01 01:00:00 +0100
18770 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched_mon.h       2007-08-05 20:53:13 +0200
18771 @@ -0,0 +1,200 @@
18772 +
18773 +#include <linux/vserver/monitor.h>
18774 +
18775 +#ifdef  CONFIG_VSERVER_MONITOR
18776 +
18777 +#ifdef CONFIG_VSERVER_HARDCPU
18778 +#define HARDCPU(x) (x)
18779 +#else
18780 +#define HARDCPU(x) (0)
18781 +#endif
18782 +
18783 +#ifdef CONFIG_VSERVER_IDLETIME
18784 +#define IDLETIME(x) (x)
18785 +#else
18786 +#define IDLETIME(x) (0)
18787 +#endif
18788 +
18789 +struct _vx_mon_entry *vxm_advance(int cpu);
18790 +
18791 +
18792 +static inline
18793 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
18794 +{
18795 +       entry->type = type;
18796 +       entry->xid = xid;
18797 +}
18798 +
18799 +static inline
18800 +void   __vxm_sync(int cpu)
18801 +{
18802 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18803 +
18804 +       __vxm_basic(entry, 0, VXM_SYNC);
18805 +       entry->ev.sec = xtime.tv_sec;
18806 +       entry->ev.nsec = xtime.tv_nsec;
18807 +}
18808 +
18809 +static inline
18810 +void   __vxm_task(struct task_struct *p, int type)
18811 +{
18812 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
18813 +
18814 +       __vxm_basic(entry, p->xid, type);
18815 +       entry->ev.tsk.pid = p->pid;
18816 +       entry->ev.tsk.state = p->state;
18817 +}
18818 +
18819 +static inline
18820 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18821 +{
18822 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18823 +
18824 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
18825 +       entry->sd.tokens = s->tokens;
18826 +       entry->sd.norm_time = s->norm_time;
18827 +       entry->sd.idle_time = s->idle_time;
18828 +}
18829 +
18830 +static inline
18831 +void   __vxm_rqinfo1(struct rq *q, int cpu)
18832 +{
18833 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18834 +
18835 +       entry->type = VXM_RQINFO_1;
18836 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
18837 +       entry->q1.running = q->nr_running;
18838 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
18839 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
18840 +       entry->q1.uintr = q->nr_uninterruptible;
18841 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
18842 +}
18843 +
18844 +static inline
18845 +void   __vxm_rqinfo2(struct rq *q, int cpu)
18846 +{
18847 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18848 +
18849 +       entry->type = VXM_RQINFO_2;
18850 +       entry->xid = (unsigned long)q & 0xffff;
18851 +       entry->q2.norm_time = q->norm_time;
18852 +       entry->q2.idle_time = q->idle_time;
18853 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
18854 +}
18855 +
18856 +static inline
18857 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18858 +{
18859 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18860 +
18861 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
18862 +       entry->ev.tokens = s->tokens;
18863 +}
18864 +
18865 +static inline
18866 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18867 +{
18868 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18869 +
18870 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
18871 +       entry->u1.tokens_max = s->tokens_max;
18872 +       entry->u1.fill_rate = s->fill_rate[0];
18873 +       entry->u1.interval = s->interval[0];
18874 +}
18875 +
18876 +static inline
18877 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18878 +{
18879 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18880 +
18881 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
18882 +       entry->u2.tokens_min = s->tokens_min;
18883 +       entry->u2.fill_rate = s->fill_rate[1];
18884 +       entry->u2.interval = s->interval[1];
18885 +}
18886 +
18887 +
18888 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
18889 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
18890 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
18891 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
18892 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
18893 +
18894 +static inline
18895 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
18896 +{
18897 +       __vxm_task(p, VXM_MIGRATE);
18898 +       __vxm_rqinfo1(rq, task_cpu(p));
18899 +       __vxm_rqinfo2(rq, task_cpu(p));
18900 +}
18901 +
18902 +static inline
18903 +void   vxm_idle_skip(struct rq *rq, int cpu)
18904 +{
18905 +       __vxm_rqinfo1(rq, cpu);
18906 +       __vxm_rqinfo2(rq, cpu);
18907 +}
18908 +
18909 +static inline
18910 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
18911 +{
18912 +       if (slice)
18913 +               return;
18914 +
18915 +       __vxm_task(p, VXM_RESCHED);
18916 +}
18917 +
18918 +static inline
18919 +void   vxm_sync(unsigned long now, int cpu)
18920 +{
18921 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
18922 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
18923 +               return;
18924 +
18925 +       __vxm_sync(cpu);
18926 +}
18927 +
18928 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
18929 +
18930 +static inline
18931 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
18932 +       struct vx_info *vxi, int cpu)
18933 +{
18934 +       __vxm_sched(s, vxi, cpu);
18935 +       __vxm_rqinfo2(rq, cpu);
18936 +}
18937 +
18938 +static inline
18939 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18940 +{
18941 +       __vxm_sched(s, vxi, cpu);
18942 +       __vxm_update(s, vxi, cpu);
18943 +       __vxm_update1(s, vxi, cpu);
18944 +       __vxm_update2(s, vxi, cpu);
18945 +}
18946 +
18947 +static inline
18948 +void   vxm_rq_max_min(struct rq *rq, int cpu)
18949 +{
18950 +       __vxm_rqinfo1(rq, cpu);
18951 +       __vxm_rqinfo2(rq, cpu);
18952 +}
18953 +
18954 +#else  /* CONFIG_VSERVER_MONITOR */
18955 +
18956 +#define        vxm_activate_task(t,q)          do { } while (0)
18957 +#define        vxm_activate_idle(t,q)          do { } while (0)
18958 +#define        vxm_deactivate_task(t,q)        do { } while (0)
18959 +#define        vxm_hold_task(t,q)              do { } while (0)
18960 +#define        vxm_unhold_task(t,q)            do { } while (0)
18961 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
18962 +#define        vxm_idle_skip(q,c)              do { } while (0)
18963 +#define        vxm_need_resched(t,s,c)         do { } while (0)
18964 +#define        vxm_sync(s,c)                   do { } while (0)
18965 +#define        vxm_sched_info(s,v,c)           do { } while (0)
18966 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
18967 +#define        vxm_update_sched(s,v,c)         do { } while (0)
18968 +#define        vxm_rq_max_min(q,c)             do { } while (0)
18969 +
18970 +#endif /* CONFIG_VSERVER_MONITOR */
18971 +
18972 diff -NurpP --minimal linux-2.6.22.10/kernel/signal.c linux-2.6.22.10-vs2.3.0.29/kernel/signal.c
18973 --- linux-2.6.22.10/kernel/signal.c     2007-10-30 01:57:15 +0100
18974 +++ linux-2.6.22.10-vs2.3.0.29/kernel/signal.c  2007-09-30 14:58:01 +0200
18975 @@ -26,6 +26,8 @@
18976  #include <linux/freezer.h>
18977  #include <linux/pid_namespace.h>
18978  #include <linux/nsproxy.h>
18979 +#include <linux/vs_context.h>
18980 +#include <linux/vs_pid.h>
18981  
18982  #include <asm/param.h>
18983  #include <asm/uaccess.h>
18984 @@ -523,19 +525,34 @@ static int check_kill_permission(int sig
18985         if (!valid_signal(sig))
18986                 return error;
18987  
18988 +       if ((info != SEND_SIG_NOINFO) &&
18989 +               (is_si_special(info) || !SI_FROMUSER(info)))
18990 +               goto skip;
18991 +
18992 +       vxdprintk(VXD_CBIT(misc, 7),
18993 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
18994 +               sig, info, t, vx_task_xid(t), t->pid);
18995 +
18996         error = audit_signal_info(sig, t); /* Let audit system see the signal */
18997         if (error)
18998                 return error;
18999  
19000         error = -EPERM;
19001 -       if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
19002 -           && ((sig != SIGCONT) ||
19003 +       if (((sig != SIGCONT) ||
19004                 (process_session(current) != process_session(t)))
19005             && (current->euid ^ t->suid) && (current->euid ^ t->uid)
19006             && (current->uid ^ t->suid) && (current->uid ^ t->uid)
19007             && !capable(CAP_KILL))
19008                 return error;
19009  
19010 +       error = -ESRCH;
19011 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
19012 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
19013 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
19014 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
19015 +               return error;
19016 +       }
19017 +skip:
19018         return security_task_kill(t, info, sig, 0);
19019  }
19020  
19021 @@ -1043,7 +1060,7 @@ int kill_pid_info(int sig, struct siginf
19022  
19023         p = pid_task(pid, PIDTYPE_PID);
19024         error = -ESRCH;
19025 -       if (p)
19026 +       if (p && vx_check(vx_task_xid(p), VS_IDENT))
19027                 error = group_send_sig_info(sig, info, p);
19028  
19029         if (unlikely(sig_needs_tasklist(sig)))
19030 @@ -1057,7 +1074,7 @@ kill_proc_info(int sig, struct siginfo *
19031  {
19032         int error;
19033         rcu_read_lock();
19034 -       error = kill_pid_info(sig, info, find_pid(pid));
19035 +       error = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
19036         rcu_read_unlock();
19037         return error;
19038  }
19039 @@ -1118,7 +1135,8 @@ static int kill_something_info(int sig, 
19040  
19041                 read_lock(&tasklist_lock);
19042                 for_each_process(p) {
19043 -                       if (p->pid > 1 && p->tgid != current->tgid) {
19044 +                       if (vx_check(vx_task_xid(p), VS_ADMIN_P|VS_IDENT) &&
19045 +                               p->pid > 1 && p->tgid != current->tgid) {
19046                                 int err = group_send_sig_info(sig, info, p);
19047                                 ++count;
19048                                 if (err != -EPERM)
19049 @@ -1814,6 +1832,11 @@ relock:
19050                 if (current == child_reaper(current))
19051                         continue;
19052  
19053 +               /* virtual init is protected against user signals */
19054 +               if ((info->si_code == SI_USER) &&
19055 +                       vx_current_initpid(current->pid))
19056 +                       continue;
19057 +
19058                 if (sig_kernel_stop(signr)) {
19059                         /*
19060                          * The default action is to stop all threads in
19061 diff -NurpP --minimal linux-2.6.22.10/kernel/softirq.c linux-2.6.22.10-vs2.3.0.29/kernel/softirq.c
19062 --- linux-2.6.22.10/kernel/softirq.c    2007-07-09 13:20:03 +0200
19063 +++ linux-2.6.22.10-vs2.3.0.29/kernel/softirq.c 2007-08-05 20:53:13 +0200
19064 @@ -18,6 +18,7 @@
19065  #include <linux/rcupdate.h>
19066  #include <linux/smp.h>
19067  #include <linux/tick.h>
19068 +#include <linux/vs_context.h>
19069  
19070  #include <asm/irq.h>
19071  /*
19072 diff -NurpP --minimal linux-2.6.22.10/kernel/sys.c linux-2.6.22.10-vs2.3.0.29/kernel/sys.c
19073 --- linux-2.6.22.10/kernel/sys.c        2007-10-30 01:57:15 +0100
19074 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sys.c     2007-10-30 01:21:54 +0100
19075 @@ -36,6 +36,7 @@
19076  #include <linux/compat.h>
19077  #include <linux/syscalls.h>
19078  #include <linux/kprobes.h>
19079 +#include <linux/vs_pid.h>
19080  
19081  #include <asm/uaccess.h>
19082  #include <asm/io.h>
19083 @@ -639,7 +640,10 @@ static int set_one_prio(struct task_stru
19084                 goto out;
19085         }
19086         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
19087 -               error = -EACCES;
19088 +               if (vx_flags(VXF_IGNEG_NICE, 0))
19089 +                       error = 0;
19090 +               else
19091 +                       error = -EACCES;
19092                 goto out;
19093         }
19094         no_nice = security_task_setnice(p, niceval);
19095 @@ -687,6 +691,8 @@ asmlinkage long sys_setpriority(int whic
19096                         else
19097                                 pgrp = task_pgrp(current);
19098                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19099 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19100 +                                       continue;
19101                                 error = set_one_prio(p, niceval, error);
19102                         } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
19103                         break;
19104 @@ -695,7 +701,8 @@ asmlinkage long sys_setpriority(int whic
19105                         if (!who)
19106                                 who = current->uid;
19107                         else
19108 -                               if ((who != current->uid) && !(user = find_user(who)))
19109 +                               if ((who != current->uid) &&
19110 +                                       !(user = find_user(vx_current_xid(), who)))
19111                                         goto out_unlock;        /* No processes for this user */
19112  
19113                         do_each_thread(g, p)
19114 @@ -747,6 +754,8 @@ asmlinkage long sys_getpriority(int whic
19115                         else
19116                                 pgrp = task_pgrp(current);
19117                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19118 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19119 +                                       continue;
19120                                 niceval = 20 - task_nice(p);
19121                                 if (niceval > retval)
19122                                         retval = niceval;
19123 @@ -757,7 +766,8 @@ asmlinkage long sys_getpriority(int whic
19124                         if (!who)
19125                                 who = current->uid;
19126                         else
19127 -                               if ((who != current->uid) && !(user = find_user(who)))
19128 +                               if ((who != current->uid) &&
19129 +                                       !(user = find_user(vx_current_xid(), who)))
19130                                         goto out_unlock;        /* No processes for this user */
19131  
19132                         do_each_thread(g, p)
19133 @@ -871,6 +881,9 @@ void kernel_power_off(void)
19134         machine_power_off();
19135  }
19136  EXPORT_SYMBOL_GPL(kernel_power_off);
19137 +
19138 +long vs_reboot(unsigned int, void __user *);
19139 +
19140  /*
19141   * Reboot system call: for obvious reasons only root may call it,
19142   * and even root needs to set up some magic numbers in the registers
19143 @@ -901,6 +914,9 @@ asmlinkage long sys_reboot(int magic1, i
19144         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
19145                 cmd = LINUX_REBOOT_CMD_HALT;
19146  
19147 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
19148 +               return vs_reboot(cmd, arg);
19149 +
19150         lock_kernel();
19151         switch (cmd) {
19152         case LINUX_REBOOT_CMD_RESTART:
19153 @@ -1080,7 +1096,7 @@ static int set_user(uid_t new_ruid, int 
19154  {
19155         struct user_struct *new_user;
19156  
19157 -       new_user = alloc_uid(new_ruid);
19158 +       new_user = alloc_uid(vx_current_xid(), new_ruid);
19159         if (!new_user)
19160                 return -EAGAIN;
19161  
19162 @@ -1434,15 +1450,18 @@ asmlinkage long sys_setpgid(pid_t pid, p
19163  {
19164         struct task_struct *p;
19165         struct task_struct *group_leader = current->group_leader;
19166 +       pid_t rpgid;
19167         int err = -EINVAL;
19168  
19169         if (!pid)
19170 -               pid = group_leader->pid;
19171 +               pid = vx_map_pid(group_leader->pid);
19172         if (!pgid)
19173                 pgid = pid;
19174         if (pgid < 0)
19175                 return -EINVAL;
19176  
19177 +       rpgid = vx_rmap_pid(pgid);
19178 +
19179         /* From this point forward we keep holding onto the tasklist lock
19180          * so that our parent does not change from under us. -DaveM
19181          */
19182 @@ -1476,20 +1495,20 @@ asmlinkage long sys_setpgid(pid_t pid, p
19183  
19184         if (pgid != pid) {
19185                 struct task_struct *g =
19186 -                       find_task_by_pid_type(PIDTYPE_PGID, pgid);
19187 +                       find_task_by_pid_type(PIDTYPE_PGID, rpgid);
19188  
19189                 if (!g || task_session(g) != task_session(group_leader))
19190                         goto out;
19191         }
19192  
19193 -       err = security_task_setpgid(p, pgid);
19194 +       err = security_task_setpgid(p, rpgid);
19195         if (err)
19196                 goto out;
19197  
19198 -       if (process_group(p) != pgid) {
19199 +       if (process_group(p) != rpgid) {
19200                 detach_pid(p, PIDTYPE_PGID);
19201 -               p->signal->pgrp = pgid;
19202 -               attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
19203 +               p->signal->pgrp = rpgid;
19204 +               attach_pid(p, PIDTYPE_PGID, find_pid(rpgid));
19205         }
19206  
19207         err = 0;
19208 @@ -1502,7 +1521,7 @@ out:
19209  asmlinkage long sys_getpgid(pid_t pid)
19210  {
19211         if (!pid)
19212 -               return process_group(current);
19213 +               return vx_rmap_pid(process_group(current));
19214         else {
19215                 int retval;
19216                 struct task_struct *p;
19217 @@ -1514,7 +1533,7 @@ asmlinkage long sys_getpgid(pid_t pid)
19218                 if (p) {
19219                         retval = security_task_getpgid(p);
19220                         if (!retval)
19221 -                               retval = process_group(p);
19222 +                               retval = vx_rmap_pid(process_group(p));
19223                 }
19224                 read_unlock(&tasklist_lock);
19225                 return retval;
19226 @@ -1865,7 +1884,7 @@ asmlinkage long sys_sethostname(char __u
19227         int errno;
19228         char tmp[__NEW_UTS_LEN];
19229  
19230 -       if (!capable(CAP_SYS_ADMIN))
19231 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19232                 return -EPERM;
19233         if (len < 0 || len > __NEW_UTS_LEN)
19234                 return -EINVAL;
19235 @@ -1910,7 +1929,7 @@ asmlinkage long sys_setdomainname(char _
19236         int errno;
19237         char tmp[__NEW_UTS_LEN];
19238  
19239 -       if (!capable(CAP_SYS_ADMIN))
19240 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19241                 return -EPERM;
19242         if (len < 0 || len > __NEW_UTS_LEN)
19243                 return -EINVAL;
19244 @@ -1977,7 +1996,7 @@ asmlinkage long sys_setrlimit(unsigned i
19245                 return -EINVAL;
19246         old_rlim = current->signal->rlim + resource;
19247         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
19248 -           !capable(CAP_SYS_RESOURCE))
19249 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
19250                 return -EPERM;
19251         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
19252                 return -EPERM;
19253 diff -NurpP --minimal linux-2.6.22.10/kernel/sysctl.c linux-2.6.22.10-vs2.3.0.29/kernel/sysctl.c
19254 --- linux-2.6.22.10/kernel/sysctl.c     2007-07-09 13:20:03 +0200
19255 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sysctl.c  2007-08-05 20:53:13 +0200
19256 @@ -89,6 +89,7 @@ static int ngroups_max = NGROUPS_MAX;
19257  #ifdef CONFIG_KMOD
19258  extern char modprobe_path[];
19259  #endif
19260 +extern char vshelper_path[];
19261  #ifdef CONFIG_CHR_DEV_SG
19262  extern int sg_big_buff;
19263  #endif
19264 @@ -343,6 +344,15 @@ static ctl_table kern_table[] = {
19265                 .strategy       = &sysctl_string,
19266         },
19267  #endif
19268 +       {
19269 +               .ctl_name       = KERN_VSHELPER,
19270 +               .procname       = "vshelper",
19271 +               .data           = &vshelper_path,
19272 +               .maxlen         = 256,
19273 +               .mode           = 0644,
19274 +               .proc_handler   = &proc_dostring,
19275 +               .strategy       = &sysctl_string,
19276 +       },
19277  #ifdef CONFIG_CHR_DEV_SG
19278         {
19279                 .ctl_name       = KERN_SG_BIG_BUFF,
19280 diff -NurpP --minimal linux-2.6.22.10/kernel/time.c linux-2.6.22.10-vs2.3.0.29/kernel/time.c
19281 --- linux-2.6.22.10/kernel/time.c       2007-07-09 13:20:03 +0200
19282 +++ linux-2.6.22.10-vs2.3.0.29/kernel/time.c    2007-08-05 20:53:13 +0200
19283 @@ -60,7 +60,7 @@ asmlinkage long sys_time(time_t __user *
19284         time_t i;
19285         struct timeval tv;
19286  
19287 -       do_gettimeofday(&tv);
19288 +       vx_gettimeofday(&tv);
19289         i = tv.tv_sec;
19290  
19291         if (tloc) {
19292 @@ -91,7 +91,7 @@ asmlinkage long sys_stime(time_t __user 
19293         if (err)
19294                 return err;
19295  
19296 -       do_settimeofday(&tv);
19297 +       vx_settimeofday(&tv);
19298         return 0;
19299  }
19300  
19301 @@ -101,7 +101,7 @@ asmlinkage long sys_gettimeofday(struct 
19302  {
19303         if (likely(tv != NULL)) {
19304                 struct timeval ktv;
19305 -               do_gettimeofday(&ktv);
19306 +               vx_gettimeofday(&ktv);
19307                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
19308                         return -EFAULT;
19309         }
19310 @@ -175,7 +175,7 @@ int do_sys_settimeofday(struct timespec 
19311                 /* SMP safe, again the code in arch/foo/time.c should
19312                  * globally block out interrupts when it runs.
19313                  */
19314 -               return do_settimeofday(tv);
19315 +               return vx_settimeofday(tv);
19316         }
19317         return 0;
19318  }
19319 @@ -388,7 +388,7 @@ void getnstimeofday(struct timespec *tv)
19320  {
19321         struct timeval x;
19322  
19323 -       do_gettimeofday(&x);
19324 +       vx_gettimeofday(&x);
19325         tv->tv_sec = x.tv_sec;
19326         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
19327  }
19328 diff -NurpP --minimal linux-2.6.22.10/kernel/timer.c linux-2.6.22.10-vs2.3.0.29/kernel/timer.c
19329 --- linux-2.6.22.10/kernel/timer.c      2007-07-09 13:20:04 +0200
19330 +++ linux-2.6.22.10-vs2.3.0.29/kernel/timer.c   2007-08-05 20:53:13 +0200
19331 @@ -36,6 +36,10 @@
19332  #include <linux/delay.h>
19333  #include <linux/tick.h>
19334  #include <linux/kallsyms.h>
19335 +#include <linux/vs_base.h>
19336 +#include <linux/vs_cvirt.h>
19337 +#include <linux/vs_pid.h>
19338 +#include <linux/vserver/sched.h>
19339  
19340  #include <asm/uaccess.h>
19341  #include <asm/unistd.h>
19342 @@ -921,12 +925,6 @@ asmlinkage unsigned long sys_alarm(unsig
19343  
19344  #endif
19345  
19346 -#ifndef __alpha__
19347 -
19348 -/*
19349 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
19350 - * should be moved into arch/i386 instead?
19351 - */
19352  
19353  /**
19354   * sys_getpid - return the thread group id of the current process
19355 @@ -939,7 +937,7 @@ asmlinkage unsigned long sys_alarm(unsig
19356   */
19357  asmlinkage long sys_getpid(void)
19358  {
19359 -       return current->tgid;
19360 +       return vx_map_tgid(current->tgid);
19361  }
19362  
19363  /*
19364 @@ -955,10 +953,23 @@ asmlinkage long sys_getppid(void)
19365         rcu_read_lock();
19366         pid = rcu_dereference(current->real_parent)->tgid;
19367         rcu_read_unlock();
19368 +       return vx_map_pid(pid);
19369 +}
19370  
19371 -       return pid;
19372 +#ifdef __alpha__
19373 +
19374 +/*
19375 + * The Alpha uses getxpid, getxuid, and getxgid instead.
19376 + */
19377 +
19378 +asmlinkage long do_getxpid(long *ppid)
19379 +{
19380 +       *ppid = sys_getppid();
19381 +       return sys_getpid();
19382  }
19383  
19384 +#else /* _alpha_ */
19385 +
19386  asmlinkage long sys_getuid(void)
19387  {
19388         /* Only we change this so SMP safe */
19389 @@ -1118,6 +1129,8 @@ int do_sysinfo(struct sysinfo *info)
19390                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
19391                         tp.tv_sec++;
19392                 }
19393 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
19394 +                       vx_vsi_uptime(&tp, NULL);
19395                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
19396  
19397                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
19398 diff -NurpP --minimal linux-2.6.22.10/kernel/user.c linux-2.6.22.10-vs2.3.0.29/kernel/user.c
19399 --- linux-2.6.22.10/kernel/user.c       2007-02-06 03:01:56 +0100
19400 +++ linux-2.6.22.10-vs2.3.0.29/kernel/user.c    2007-08-05 20:53:13 +0200
19401 @@ -23,8 +23,8 @@
19402  #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
19403  #define UIDHASH_SZ             (1 << UIDHASH_BITS)
19404  #define UIDHASH_MASK           (UIDHASH_SZ - 1)
19405 -#define __uidhashfn(uid)       (((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
19406 -#define uidhashentry(uid)      (uidhash_table + __uidhashfn((uid)))
19407 +#define __uidhashfn(xid,uid)   ((((uid) >> UIDHASH_BITS) + ((uid)^(xid))) & UIDHASH_MASK)
19408 +#define uidhashentry(xid,uid)  (uidhash_table + __uidhashfn((xid),(uid)))
19409  
19410  static struct kmem_cache *uid_cachep;
19411  static struct list_head uidhash_table[UIDHASH_SZ];
19412 @@ -66,7 +66,7 @@ static inline void uid_hash_remove(struc
19413         list_del(&up->uidhash_list);
19414  }
19415  
19416 -static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *hashent)
19417 +static inline struct user_struct *uid_hash_find(xid_t xid, uid_t uid, struct list_head *hashent)
19418  {
19419         struct list_head *up;
19420  
19421 @@ -75,7 +75,7 @@ static inline struct user_struct *uid_ha
19422  
19423                 user = list_entry(up, struct user_struct, uidhash_list);
19424  
19425 -               if(user->uid == uid) {
19426 +               if(user->uid == uid && user->xid == xid) {
19427                         atomic_inc(&user->__count);
19428                         return user;
19429                 }
19430 @@ -90,13 +90,13 @@ static inline struct user_struct *uid_ha
19431   *
19432   * If the user_struct could not be found, return NULL.
19433   */
19434 -struct user_struct *find_user(uid_t uid)
19435 +struct user_struct *find_user(xid_t xid, uid_t uid)
19436  {
19437         struct user_struct *ret;
19438         unsigned long flags;
19439  
19440         spin_lock_irqsave(&uidhash_lock, flags);
19441 -       ret = uid_hash_find(uid, uidhashentry(uid));
19442 +       ret = uid_hash_find(xid, uid, uidhashentry(xid, uid));
19443         spin_unlock_irqrestore(&uidhash_lock, flags);
19444         return ret;
19445  }
19446 @@ -120,13 +120,13 @@ void free_uid(struct user_struct *up)
19447         }
19448  }
19449  
19450 -struct user_struct * alloc_uid(uid_t uid)
19451 +struct user_struct * alloc_uid(xid_t xid, uid_t uid)
19452  {
19453 -       struct list_head *hashent = uidhashentry(uid);
19454 +       struct list_head *hashent = uidhashentry(xid, uid);
19455         struct user_struct *up;
19456  
19457         spin_lock_irq(&uidhash_lock);
19458 -       up = uid_hash_find(uid, hashent);
19459 +       up = uid_hash_find(xid, uid, hashent);
19460         spin_unlock_irq(&uidhash_lock);
19461  
19462         if (!up) {
19463 @@ -136,6 +136,7 @@ struct user_struct * alloc_uid(uid_t uid
19464                 if (!new)
19465                         return NULL;
19466                 new->uid = uid;
19467 +               new->xid = xid;
19468                 atomic_set(&new->__count, 1);
19469                 atomic_set(&new->processes, 0);
19470                 atomic_set(&new->files, 0);
19471 @@ -158,7 +159,7 @@ struct user_struct * alloc_uid(uid_t uid
19472                  * on adding the same user already..
19473                  */
19474                 spin_lock_irq(&uidhash_lock);
19475 -               up = uid_hash_find(uid, hashent);
19476 +               up = uid_hash_find(xid, uid, hashent);
19477                 if (up) {
19478                         key_put(new->uid_keyring);
19479                         key_put(new->session_keyring);
19480 @@ -215,7 +216,7 @@ static int __init uid_cache_init(void)
19481  
19482         /* Insert the root user immediately (init already runs as root) */
19483         spin_lock_irq(&uidhash_lock);
19484 -       uid_hash_insert(&root_user, uidhashentry(0));
19485 +       uid_hash_insert(&root_user, uidhashentry(0,0));
19486         spin_unlock_irq(&uidhash_lock);
19487  
19488         return 0;
19489 diff -NurpP --minimal linux-2.6.22.10/kernel/utsname.c linux-2.6.22.10-vs2.3.0.29/kernel/utsname.c
19490 --- linux-2.6.22.10/kernel/utsname.c    2007-07-09 13:20:04 +0200
19491 +++ linux-2.6.22.10-vs2.3.0.29/kernel/utsname.c 2007-08-05 20:53:13 +0200
19492 @@ -13,6 +13,7 @@
19493  #include <linux/uts.h>
19494  #include <linux/utsname.h>
19495  #include <linux/version.h>
19496 +#include <linux/vserver/global.h>
19497  
19498  /*
19499   * Clone a new ns copying an original utsname, setting refcount to 1
19500 @@ -27,6 +28,7 @@ static struct uts_namespace *clone_uts_n
19501         if (ns) {
19502                 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
19503                 kref_init(&ns->kref);
19504 +               atomic_inc(&vs_global_uts_ns);
19505         }
19506         return ns;
19507  }
19508 @@ -58,5 +60,6 @@ void free_uts_ns(struct kref *kref)
19509         struct uts_namespace *ns;
19510  
19511         ns = container_of(kref, struct uts_namespace, kref);
19512 +       atomic_dec(&vs_global_uts_ns);
19513         kfree(ns);
19514  }
19515 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/Kconfig linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Kconfig
19516 --- linux-2.6.22.10/kernel/vserver/Kconfig      1970-01-01 01:00:00 +0100
19517 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Kconfig   2007-10-11 01:10:22 +0200
19518 @@ -0,0 +1,249 @@
19519 +#
19520 +# Linux VServer configuration
19521 +#
19522 +
19523 +menu "Linux VServer"
19524 +
19525 +config VSERVER_AUTO_LBACK
19526 +       bool    "Automatically Assign Loopback IP"
19527 +       default y
19528 +       help
19529 +         Automatically assign a guest specific loopback
19530 +         IP and add it to the kernel network stack on
19531 +         startup.
19532 +
19533 +config VSERVER_AUTO_SINGLE
19534 +       bool    "Automatic Single IP Special Casing"
19535 +       depends on EXPERIMENTAL
19536 +       default y
19537 +       help
19538 +         This allows network contexts with a single IP to
19539 +         automatically remap 0.0.0.0 bindings to that IP,
19540 +         avoiding further network checks and improving
19541 +         performance.
19542 +
19543 +         (note: such guests do not allow to change the ip
19544 +          on the fly and do not show loopback addresses)
19545 +
19546 +config VSERVER_COWBL
19547 +       bool    "Enable COW Immutable Link Breaking"
19548 +       default y
19549 +       help
19550 +         This enables the COW (Copy-On-Write) link break code.
19551 +         It allows you to treat unified files like normal files
19552 +         when writing to them (which will implicitely break the
19553 +         link and create a copy of the unified file)
19554 +
19555 +config VSERVER_VTIME
19556 +       bool    "Enable Virtualized Guest Time"
19557 +       depends on EXPERIMENTAL
19558 +       default n
19559 +       help
19560 +         This enables per guest time offsets to allow for
19561 +         adjusting the system clock individually per guest.
19562 +         this adds some overhead to the time functions and
19563 +         therefore should not be enabled without good reason.
19564 +
19565 +config VSERVER_DEVICE
19566 +       bool    "Enable Guest Device Mapping"
19567 +       depends on EXPERIMENTAL
19568 +       default n
19569 +       help
19570 +         This enables generic device remapping.
19571 +
19572 +config VSERVER_PROC_SECURE
19573 +       bool    "Enable Proc Security"
19574 +       depends on PROC_FS
19575 +       default y
19576 +       help
19577 +         This configures ProcFS security to initially hide
19578 +         non-process entries for all contexts except the main and
19579 +         spectator context (i.e. for all guests), which is a secure
19580 +         default.
19581 +
19582 +         (note: on 1.2x the entries were visible by default)
19583 +
19584 +config VSERVER_HARDCPU
19585 +       bool    "Enable Hard CPU Limits"
19586 +       default y
19587 +       help
19588 +         Activate the Hard CPU Limits
19589 +
19590 +         This will compile in code that allows the Token Bucket
19591 +         Scheduler to put processes on hold when a context's
19592 +         tokens are depleted (provided that its per-context
19593 +         sched_hard flag is set).
19594 +
19595 +         Processes belonging to that context will not be able
19596 +         to consume CPU resources again until a per-context
19597 +         configured minimum of tokens has been reached.
19598 +
19599 +config VSERVER_IDLETIME
19600 +       bool    "Avoid idle CPUs by skipping Time"
19601 +       depends on VSERVER_HARDCPU
19602 +       default y
19603 +       help
19604 +         This option allows the scheduler to artificially
19605 +         advance time (per cpu) when otherwise the idle
19606 +         task would be scheduled, thus keeping the cpu
19607 +         busy and sharing the available resources among
19608 +         certain contexts.
19609 +
19610 +config VSERVER_IDLELIMIT
19611 +       bool    "Limit the IDLE task"
19612 +       depends on VSERVER_HARDCPU
19613 +       default n
19614 +       help
19615 +         Limit the idle slices, so the the next context
19616 +         will be scheduled as soon as possible.
19617 +
19618 +         This might improve interactivity and latency, but
19619 +         will also marginally increase scheduling overhead.
19620 +
19621 +choice
19622 +       prompt  "Persistent Inode Tagging"
19623 +       default TAGGING_ID24
19624 +       help
19625 +         This adds persistent context information to filesystems
19626 +         mounted with the tagxid option. Tagging is a requirement
19627 +         for per-context disk limits and per-context quota.
19628 +
19629 +
19630 +config TAGGING_NONE
19631 +       bool    "Disabled"
19632 +       help
19633 +         do not store per-context information in inodes.
19634 +
19635 +config TAGGING_UID16
19636 +       bool    "UID16/GID32"
19637 +       help
19638 +         reduces UID to 16 bit, but leaves GID at 32 bit.
19639 +
19640 +config TAGGING_GID16
19641 +       bool    "UID32/GID16"
19642 +       help
19643 +         reduces GID to 16 bit, but leaves UID at 32 bit.
19644 +
19645 +config TAGGING_ID24
19646 +       bool    "UID24/GID24"
19647 +       help
19648 +         uses the upper 8bit from UID and GID for XID tagging
19649 +         which leaves 24bit for UID/GID each, which should be
19650 +         more than sufficient for normal use.
19651 +
19652 +config TAGGING_INTERN
19653 +       bool    "UID32/GID32"
19654 +       help
19655 +         this uses otherwise reserved inode fields in the on
19656 +         disk representation, which limits the use to a few
19657 +         filesystems (currently ext2 and ext3)
19658 +
19659 +endchoice
19660 +
19661 +config TAG_NFSD
19662 +       bool    "Tag NFSD User Auth and Files"
19663 +       default n
19664 +       help
19665 +         Enable this if you do want the in-kernel NFS
19666 +         Server to use the tagging specified above.
19667 +         (will require patched clients too)
19668 +
19669 +config VSERVER_PRIVACY
19670 +       bool    "Honor Privacy Aspects of Guests"
19671 +       default n
19672 +       help
19673 +         When enabled, most context checks will disallow
19674 +         access to structures assigned to a specific context,
19675 +         like ptys or loop devices.
19676 +
19677 +config VSERVER_CONTEXTS
19678 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
19679 +       range 1 65533
19680 +       default "768"   if 64BIT
19681 +       default "256"
19682 +       help
19683 +         This setting will optimize certain data structures
19684 +         and memory allocations according to the expected
19685 +         maximum.
19686 +
19687 +         note: this is not a strict upper limit.
19688 +
19689 +config VSERVER_WARN
19690 +       bool    "VServer Warnings"
19691 +       default y
19692 +       help
19693 +         This enables various runtime warnings, which will
19694 +         notify about potential manipulation attempts or
19695 +         resource shortage. It is generally considered to
19696 +         be a good idea to have that enabled.
19697 +
19698 +config VSERVER_DEBUG
19699 +       bool    "VServer Debugging Code"
19700 +       default n
19701 +       help
19702 +         Set this to yes if you want to be able to activate
19703 +         debugging output at runtime. It adds a very small
19704 +         overhead to all vserver related functions and
19705 +         increases the kernel size by about 20k.
19706 +
19707 +config VSERVER_HISTORY
19708 +       bool    "VServer History Tracing"
19709 +       depends on VSERVER_DEBUG
19710 +       default n
19711 +       help
19712 +         Set this to yes if you want to record the history of
19713 +         linux-vserver activities, so they can be replayed in
19714 +         the event of a kernel panic or oops.
19715 +
19716 +config VSERVER_HISTORY_SIZE
19717 +       int     "Per-CPU History Size (32-65536)"
19718 +       depends on VSERVER_HISTORY
19719 +       range 32 65536
19720 +       default 64
19721 +       help
19722 +         This allows you to specify the number of entries in
19723 +         the per-CPU history buffer.
19724 +
19725 +config VSERVER_MONITOR
19726 +       bool    "VServer Scheduling Monitor"
19727 +       depends on VSERVER_DEBUG
19728 +       default n
19729 +       help
19730 +         Set this to yes if you want to record the scheduling
19731 +         decisions, so that they can be relayed to userspace
19732 +         for detailed analysis.
19733 +
19734 +config VSERVER_MONITOR_SIZE
19735 +       int     "Per-CPU Monitor Queue Size (32-65536)"
19736 +       depends on VSERVER_MONITOR
19737 +       range 32 65536
19738 +       default 1024
19739 +       help
19740 +         This allows you to specify the number of entries in
19741 +         the per-CPU scheduling monitor buffer.
19742 +
19743 +config VSERVER_MONITOR_SYNC
19744 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
19745 +       depends on VSERVER_MONITOR
19746 +       range 0 65536
19747 +       default 256
19748 +       help
19749 +         This allows you to specify the interval in ticks
19750 +         when a time sync entry is inserted.
19751 +
19752 +endmenu
19753 +
19754 +
19755 +config VSERVER
19756 +       bool
19757 +       default y
19758 +       select UTS_NS
19759 +       select SYSVIPC
19760 +       select IPC_NS
19761 +
19762 +config VSERVER_SECURITY
19763 +       bool
19764 +       depends on SECURITY
19765 +       default y
19766 +       select SECURITY_CAPABILITIES
19767 +
19768 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/Makefile linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Makefile
19769 --- linux-2.6.22.10/kernel/vserver/Makefile     1970-01-01 01:00:00 +0100
19770 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Makefile  2007-10-11 01:10:22 +0200
19771 @@ -0,0 +1,18 @@
19772 +#
19773 +# Makefile for the Linux vserver routines.
19774 +#
19775 +
19776 +
19777 +obj-y          += vserver.o
19778 +
19779 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
19780 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
19781 +                  dlimit.o tag.o
19782 +
19783 +vserver-$(CONFIG_INET) += inet.o
19784 +vserver-$(CONFIG_PROC_FS) += proc.o
19785 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
19786 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
19787 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
19788 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
19789 +
19790 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
19791 --- linux-2.6.22.10/kernel/vserver/cacct.c      1970-01-01 01:00:00 +0100
19792 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct.c   2007-08-15 21:54:31 +0200
19793 @@ -0,0 +1,42 @@
19794 +/*
19795 + *  linux/kernel/vserver/cacct.c
19796 + *
19797 + *  Virtual Server: Context Accounting
19798 + *
19799 + *  Copyright (C) 2006-2007 Herbert Pötzl
19800 + *
19801 + *  V0.01  added accounting stats
19802 + *
19803 + */
19804 +
19805 +#include <linux/types.h>
19806 +#include <linux/vs_context.h>
19807 +#include <linux/vserver/cacct_cmd.h>
19808 +#include <linux/vserver/cacct_int.h>
19809 +
19810 +#include <asm/errno.h>
19811 +#include <asm/uaccess.h>
19812 +
19813 +
19814 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
19815 +{
19816 +       struct vcmd_sock_stat_v0 vc_data;
19817 +       int j, field;
19818 +
19819 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19820 +               return -EFAULT;
19821 +
19822 +       field = vc_data.field;
19823 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
19824 +               return -EINVAL;
19825 +
19826 +       for (j = 0; j < 3; j++) {
19827 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
19828 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
19829 +       }
19830 +
19831 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19832 +               return -EFAULT;
19833 +       return 0;
19834 +}
19835 +
19836 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
19837 --- linux-2.6.22.10/kernel/vserver/cacct_init.h 1970-01-01 01:00:00 +0100
19838 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct_init.h      2007-08-05 20:53:13 +0200
19839 @@ -0,0 +1,25 @@
19840 +
19841 +
19842 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
19843 +{
19844 +       int i, j;
19845 +
19846 +
19847 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19848 +               for (j = 0; j < 3; j++) {
19849 +                       atomic_set(&cacct->sock[i][j].count, 0);
19850 +                       atomic_set(&cacct->sock[i][j].total, 0);
19851 +               }
19852 +       }
19853 +       for (i = 0; i < 8; i++)
19854 +               atomic_set(&cacct->slab[i], 0);
19855 +       for (i = 0; i < 5; i++)
19856 +               for (j = 0; j < 4; j++)
19857 +                       atomic_set(&cacct->page[i][j], 0);
19858 +}
19859 +
19860 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
19861 +{
19862 +       return;
19863 +}
19864 +
19865 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
19866 --- linux-2.6.22.10/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00 +0100
19867 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct_proc.h      2007-08-05 20:53:13 +0200
19868 @@ -0,0 +1,53 @@
19869 +#ifndef _VX_CACCT_PROC_H
19870 +#define _VX_CACCT_PROC_H
19871 +
19872 +#include <linux/vserver/cacct_int.h>
19873 +
19874 +
19875 +#define VX_SOCKA_TOP   \
19876 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
19877 +
19878 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
19879 +{
19880 +       int i, j, length = 0;
19881 +       static char *type[VXA_SOCK_SIZE] = {
19882 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
19883 +       };
19884 +
19885 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
19886 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19887 +               length += sprintf(buffer + length, "%s:", type[i]);
19888 +               for (j = 0; j < 3; j++) {
19889 +                       length += sprintf(buffer + length,
19890 +                               "\t%10lu/%-10lu",
19891 +                               vx_sock_count(cacct, i, j),
19892 +                               vx_sock_total(cacct, i, j));
19893 +               }
19894 +               buffer[length++] = '\n';
19895 +       }
19896 +
19897 +       length += sprintf(buffer + length, "\n");
19898 +       length += sprintf(buffer + length,
19899 +               "slab:\t %8u %8u %8u %8u\n",
19900 +               atomic_read(&cacct->slab[1]),
19901 +               atomic_read(&cacct->slab[4]),
19902 +               atomic_read(&cacct->slab[0]),
19903 +               atomic_read(&cacct->slab[2]));
19904 +
19905 +       length += sprintf(buffer + length, "\n");
19906 +       for (i = 0; i < 5; i++) {
19907 +               length += sprintf(buffer + length,
19908 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
19909 +                       atomic_read(&cacct->page[i][0]),
19910 +                       atomic_read(&cacct->page[i][1]),
19911 +                       atomic_read(&cacct->page[i][2]),
19912 +                       atomic_read(&cacct->page[i][3]),
19913 +                       atomic_read(&cacct->page[i][4]),
19914 +                       atomic_read(&cacct->page[i][5]),
19915 +                       atomic_read(&cacct->page[i][6]),
19916 +                       atomic_read(&cacct->page[i][7]));
19917 +       }
19918 +       return length;
19919 +}
19920 +
19921 +#endif /* _VX_CACCT_PROC_H */
19922 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
19923 --- linux-2.6.22.10/kernel/vserver/context.c    1970-01-01 01:00:00 +0100
19924 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/context.c 2007-10-05 14:54:36 +0200
19925 @@ -0,0 +1,966 @@
19926 +/*
19927 + *  linux/kernel/vserver/context.c
19928 + *
19929 + *  Virtual Server: Context Support
19930 + *
19931 + *  Copyright (C) 2003-2007  Herbert Pötzl
19932 + *
19933 + *  V0.01  context helper
19934 + *  V0.02  vx_ctx_kill syscall command
19935 + *  V0.03  replaced context_info calls
19936 + *  V0.04  redesign of struct (de)alloc
19937 + *  V0.05  rlimit basic implementation
19938 + *  V0.06  task_xid and info commands
19939 + *  V0.07  context flags and caps
19940 + *  V0.08  switch to RCU based hash
19941 + *  V0.09  revert to non RCU for now
19942 + *  V0.10  and back to working RCU hash
19943 + *  V0.11  and back to locking again
19944 + *  V0.12  referenced context store
19945 + *  V0.13  separate per cpu data
19946 + *  V0.14  changed vcmds to vxi arg
19947 + *  V0.15  added context stat
19948 + *  V0.16  have __create claim() the vxi
19949 + *  V0.17  removed older and legacy stuff
19950 + *
19951 + */
19952 +
19953 +#include <linux/slab.h>
19954 +#include <linux/types.h>
19955 +#include <linux/pid_namespace.h>
19956 +
19957 +#include <linux/vserver/context.h>
19958 +#include <linux/vserver/network.h>
19959 +#include <linux/vserver/debug.h>
19960 +#include <linux/vserver/limit.h>
19961 +#include <linux/vserver/limit_int.h>
19962 +#include <linux/vserver/space.h>
19963 +
19964 +#include <linux/vs_context.h>
19965 +#include <linux/vs_limit.h>
19966 +#include <linux/vserver/context_cmd.h>
19967 +
19968 +#include "cvirt_init.h"
19969 +#include "cacct_init.h"
19970 +#include "limit_init.h"
19971 +#include "sched_init.h"
19972 +
19973 +
19974 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
19975 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
19976 +
19977 +
19978 +/*     now inactive context structures */
19979 +
19980 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
19981 +
19982 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
19983 +
19984 +
19985 +/*     __alloc_vx_info()
19986 +
19987 +       * allocate an initialized vx_info struct
19988 +       * doesn't make it visible (hash)                        */
19989 +
19990 +static struct vx_info *__alloc_vx_info(xid_t xid)
19991 +{
19992 +       struct vx_info *new = NULL;
19993 +       int cpu;
19994 +
19995 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
19996 +
19997 +       /* would this benefit from a slab cache? */
19998 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
19999 +       if (!new)
20000 +               return 0;
20001 +
20002 +       memset(new, 0, sizeof(struct vx_info));
20003 +#ifdef CONFIG_SMP
20004 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
20005 +       if (!new->ptr_pc)
20006 +               goto error;
20007 +#endif
20008 +       new->vx_id = xid;
20009 +       INIT_HLIST_NODE(&new->vx_hlist);
20010 +       atomic_set(&new->vx_usecnt, 0);
20011 +       atomic_set(&new->vx_tasks, 0);
20012 +       new->vx_parent = NULL;
20013 +       new->vx_state = 0;
20014 +       init_waitqueue_head(&new->vx_wait);
20015 +
20016 +       /* prepare reaper */
20017 +       get_task_struct(init_pid_ns.child_reaper);
20018 +       new->vx_reaper = init_pid_ns.child_reaper;
20019 +       new->vx_badness_bias = 0;
20020 +
20021 +       /* rest of init goes here */
20022 +       vx_info_init_limit(&new->limit);
20023 +       vx_info_init_sched(&new->sched);
20024 +       vx_info_init_cvirt(&new->cvirt);
20025 +       vx_info_init_cacct(&new->cacct);
20026 +
20027 +       /* per cpu data structures */
20028 +       for_each_possible_cpu(cpu) {
20029 +               vx_info_init_sched_pc(
20030 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
20031 +               vx_info_init_cvirt_pc(
20032 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
20033 +       }
20034 +
20035 +       new->vx_flags = VXF_INIT_SET;
20036 +       new->vx_bcaps = CAP_INIT_EFF_SET;
20037 +       new->vx_ccaps = 0;
20038 +       new->vx_cap_bset = cap_bset;
20039 +
20040 +       new->reboot_cmd = 0;
20041 +       new->exit_code = 0;
20042 +
20043 +       new->vx_nsproxy = copy_nsproxy(current->nsproxy);
20044 +
20045 +       vxdprintk(VXD_CBIT(xid, 0),
20046 +               "alloc_vx_info(%d) = %p", xid, new);
20047 +       vxh_alloc_vx_info(new);
20048 +       atomic_inc(&vx_global_ctotal);
20049 +       return new;
20050 +#ifdef CONFIG_SMP
20051 +error:
20052 +       kfree(new);
20053 +       return 0;
20054 +#endif
20055 +}
20056 +
20057 +/*     __dealloc_vx_info()
20058 +
20059 +       * final disposal of vx_info                             */
20060 +
20061 +static void __dealloc_vx_info(struct vx_info *vxi)
20062 +{
20063 +       int cpu;
20064 +
20065 +       vxdprintk(VXD_CBIT(xid, 0),
20066 +               "dealloc_vx_info(%p)", vxi);
20067 +       vxh_dealloc_vx_info(vxi);
20068 +
20069 +       vxi->vx_id = -1;
20070 +
20071 +       vx_info_exit_limit(&vxi->limit);
20072 +       vx_info_exit_sched(&vxi->sched);
20073 +       vx_info_exit_cvirt(&vxi->cvirt);
20074 +       vx_info_exit_cacct(&vxi->cacct);
20075 +
20076 +       for_each_possible_cpu(cpu) {
20077 +               vx_info_exit_sched_pc(
20078 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
20079 +               vx_info_exit_cvirt_pc(
20080 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
20081 +       }
20082 +
20083 +       vxi->vx_state |= VXS_RELEASED;
20084 +
20085 +#ifdef CONFIG_SMP
20086 +       free_percpu(vxi->ptr_pc);
20087 +#endif
20088 +       kfree(vxi);
20089 +       atomic_dec(&vx_global_ctotal);
20090 +}
20091 +
20092 +static void __shutdown_vx_info(struct vx_info *vxi)
20093 +{
20094 +       struct nsproxy *nsproxy;
20095 +       struct fs_struct *fs;
20096 +
20097 +       might_sleep();
20098 +
20099 +       vxi->vx_state |= VXS_SHUTDOWN;
20100 +       vs_state_change(vxi, VSC_SHUTDOWN);
20101 +
20102 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
20103 +       fs = xchg(&vxi->vx_fs, NULL);
20104 +
20105 +       if (nsproxy)
20106 +               put_nsproxy(nsproxy);
20107 +       if (fs)
20108 +               put_fs_struct(fs);
20109 +}
20110 +
20111 +/* exported stuff */
20112 +
20113 +void free_vx_info(struct vx_info *vxi)
20114 +{
20115 +       unsigned long flags;
20116 +
20117 +       /* check for reference counts first */
20118 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
20119 +       BUG_ON(atomic_read(&vxi->vx_tasks));
20120 +
20121 +       /* context must not be hashed */
20122 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
20123 +
20124 +       /* context shutdown is mandatory */
20125 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
20126 +
20127 +       BUG_ON(vxi->vx_nsproxy);
20128 +       BUG_ON(vxi->vx_fs);
20129 +
20130 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
20131 +       hlist_del(&vxi->vx_hlist);
20132 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
20133 +
20134 +       __dealloc_vx_info(vxi);
20135 +}
20136 +
20137 +
20138 +/*     hash table for vx_info hash */
20139 +
20140 +#define VX_HASH_SIZE   13
20141 +
20142 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
20143 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
20144 +
20145 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20146 +
20147 +
20148 +static inline unsigned int __hashval(xid_t xid)
20149 +{
20150 +       return (xid % VX_HASH_SIZE);
20151 +}
20152 +
20153 +
20154 +
20155 +/*     __hash_vx_info()
20156 +
20157 +       * add the vxi to the global hash table
20158 +       * requires the hash_lock to be held                     */
20159 +
20160 +static inline void __hash_vx_info(struct vx_info *vxi)
20161 +{
20162 +       struct hlist_head *head;
20163 +
20164 +       vxd_assert_lock(&vx_info_hash_lock);
20165 +       vxdprintk(VXD_CBIT(xid, 4),
20166 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
20167 +       vxh_hash_vx_info(vxi);
20168 +
20169 +       /* context must not be hashed */
20170 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
20171 +
20172 +       vxi->vx_state |= VXS_HASHED;
20173 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
20174 +       hlist_add_head(&vxi->vx_hlist, head);
20175 +       atomic_inc(&vx_global_cactive);
20176 +}
20177 +
20178 +/*     __unhash_vx_info()
20179 +
20180 +       * remove the vxi from the global hash table
20181 +       * requires the hash_lock to be held                     */
20182 +
20183 +static inline void __unhash_vx_info(struct vx_info *vxi)
20184 +{
20185 +       unsigned long flags;
20186 +
20187 +       vxd_assert_lock(&vx_info_hash_lock);
20188 +       vxdprintk(VXD_CBIT(xid, 4),
20189 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
20190 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
20191 +       vxh_unhash_vx_info(vxi);
20192 +
20193 +       /* context must be hashed */
20194 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
20195 +       /* but without tasks */
20196 +       BUG_ON(atomic_read(&vxi->vx_tasks));
20197 +
20198 +       vxi->vx_state &= ~VXS_HASHED;
20199 +       hlist_del_init(&vxi->vx_hlist);
20200 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
20201 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
20202 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
20203 +       atomic_dec(&vx_global_cactive);
20204 +}
20205 +
20206 +
20207 +/*     __lookup_vx_info()
20208 +
20209 +       * requires the hash_lock to be held
20210 +       * doesn't increment the vx_refcnt                       */
20211 +
20212 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
20213 +{
20214 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
20215 +       struct hlist_node *pos;
20216 +       struct vx_info *vxi;
20217 +
20218 +       vxd_assert_lock(&vx_info_hash_lock);
20219 +       hlist_for_each(pos, head) {
20220 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20221 +
20222 +               if (vxi->vx_id == xid)
20223 +                       goto found;
20224 +       }
20225 +       vxi = NULL;
20226 +found:
20227 +       vxdprintk(VXD_CBIT(xid, 0),
20228 +               "__lookup_vx_info(#%u): %p[#%u]",
20229 +               xid, vxi, vxi ? vxi->vx_id : 0);
20230 +       vxh_lookup_vx_info(vxi, xid);
20231 +       return vxi;
20232 +}
20233 +
20234 +
20235 +/*     __create_vx_info()
20236 +
20237 +       * create the requested context
20238 +       * get(), claim() and hash it                            */
20239 +
20240 +static struct vx_info *__create_vx_info(int id)
20241 +{
20242 +       struct vx_info *new, *vxi = NULL;
20243 +
20244 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
20245 +
20246 +       if (!(new = __alloc_vx_info(id)))
20247 +               return ERR_PTR(-ENOMEM);
20248 +
20249 +       /* required to make dynamic xids unique */
20250 +       spin_lock(&vx_info_hash_lock);
20251 +
20252 +       /* static context requested */
20253 +       if ((vxi = __lookup_vx_info(id))) {
20254 +               vxdprintk(VXD_CBIT(xid, 0),
20255 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
20256 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20257 +                       vxi = ERR_PTR(-EBUSY);
20258 +               else
20259 +                       vxi = ERR_PTR(-EEXIST);
20260 +               goto out_unlock;
20261 +       }
20262 +       /* new context */
20263 +       vxdprintk(VXD_CBIT(xid, 0),
20264 +               "create_vx_info(%d) = %p (new)", id, new);
20265 +       claim_vx_info(new, NULL);
20266 +       __hash_vx_info(get_vx_info(new));
20267 +       vxi = new, new = NULL;
20268 +
20269 +out_unlock:
20270 +       spin_unlock(&vx_info_hash_lock);
20271 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
20272 +       if (new)
20273 +               __dealloc_vx_info(new);
20274 +       return vxi;
20275 +}
20276 +
20277 +
20278 +/*     exported stuff                                          */
20279 +
20280 +
20281 +void unhash_vx_info(struct vx_info *vxi)
20282 +{
20283 +       __shutdown_vx_info(vxi);
20284 +       spin_lock(&vx_info_hash_lock);
20285 +       __unhash_vx_info(vxi);
20286 +       spin_unlock(&vx_info_hash_lock);
20287 +       __wakeup_vx_info(vxi);
20288 +}
20289 +
20290 +
20291 +/*     lookup_vx_info()
20292 +
20293 +       * search for a vx_info and get() it
20294 +       * negative id means current                             */
20295 +
20296 +struct vx_info *lookup_vx_info(int id)
20297 +{
20298 +       struct vx_info *vxi = NULL;
20299 +
20300 +       if (id < 0) {
20301 +               vxi = get_vx_info(current->vx_info);
20302 +       } else if (id > 1) {
20303 +               spin_lock(&vx_info_hash_lock);
20304 +               vxi = get_vx_info(__lookup_vx_info(id));
20305 +               spin_unlock(&vx_info_hash_lock);
20306 +       }
20307 +       return vxi;
20308 +}
20309 +
20310 +/*     xid_is_hashed()
20311 +
20312 +       * verify that xid is still hashed                       */
20313 +
20314 +int xid_is_hashed(xid_t xid)
20315 +{
20316 +       int hashed;
20317 +
20318 +       spin_lock(&vx_info_hash_lock);
20319 +       hashed = (__lookup_vx_info(xid) != NULL);
20320 +       spin_unlock(&vx_info_hash_lock);
20321 +       return hashed;
20322 +}
20323 +
20324 +#ifdef CONFIG_PROC_FS
20325 +
20326 +/*     get_xid_list()
20327 +
20328 +       * get a subset of hashed xids for proc
20329 +       * assumes size is at least one                          */
20330 +
20331 +int get_xid_list(int index, unsigned int *xids, int size)
20332 +{
20333 +       int hindex, nr_xids = 0;
20334 +
20335 +       /* only show current and children */
20336 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
20337 +               if (index > 0)
20338 +                       return 0;
20339 +               xids[nr_xids] = vx_current_xid();
20340 +               return 1;
20341 +       }
20342 +
20343 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
20344 +               struct hlist_head *head = &vx_info_hash[hindex];
20345 +               struct hlist_node *pos;
20346 +
20347 +               spin_lock(&vx_info_hash_lock);
20348 +               hlist_for_each(pos, head) {
20349 +                       struct vx_info *vxi;
20350 +
20351 +                       if (--index > 0)
20352 +                               continue;
20353 +
20354 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20355 +                       xids[nr_xids] = vxi->vx_id;
20356 +                       if (++nr_xids >= size) {
20357 +                               spin_unlock(&vx_info_hash_lock);
20358 +                               goto out;
20359 +                       }
20360 +               }
20361 +               /* keep the lock time short */
20362 +               spin_unlock(&vx_info_hash_lock);
20363 +       }
20364 +out:
20365 +       return nr_xids;
20366 +}
20367 +#endif
20368 +
20369 +#ifdef CONFIG_VSERVER_DEBUG
20370 +
20371 +void   dump_vx_info_inactive(int level)
20372 +{
20373 +       struct hlist_node *entry, *next;
20374 +
20375 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
20376 +               struct vx_info *vxi =
20377 +                       list_entry(entry, struct vx_info, vx_hlist);
20378 +
20379 +               dump_vx_info(vxi, level);
20380 +       }
20381 +}
20382 +
20383 +#endif
20384 +
20385 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
20386 +{
20387 +       struct user_struct *new_user, *old_user;
20388 +
20389 +       if (!p || !vxi)
20390 +               BUG();
20391 +
20392 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
20393 +               return -EACCES;
20394 +
20395 +       new_user = alloc_uid(vxi->vx_id, p->uid);
20396 +       if (!new_user)
20397 +               return -ENOMEM;
20398 +
20399 +       old_user = p->user;
20400 +       if (new_user != old_user) {
20401 +               atomic_inc(&new_user->processes);
20402 +               atomic_dec(&old_user->processes);
20403 +               p->user = new_user;
20404 +       }
20405 +       free_uid(old_user);
20406 +       return 0;
20407 +}
20408 +
20409 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
20410 +{
20411 +       p->cap_effective &= vxi->vx_cap_bset;
20412 +       p->cap_inheritable &= vxi->vx_cap_bset;
20413 +       p->cap_permitted &= vxi->vx_cap_bset;
20414 +}
20415 +
20416 +
20417 +#include <linux/file.h>
20418 +
20419 +static int vx_openfd_task(struct task_struct *tsk)
20420 +{
20421 +       struct files_struct *files = tsk->files;
20422 +       struct fdtable *fdt;
20423 +       const unsigned long *bptr;
20424 +       int count, total;
20425 +
20426 +       /* no rcu_read_lock() because of spin_lock() */
20427 +       spin_lock(&files->file_lock);
20428 +       fdt = files_fdtable(files);
20429 +       bptr = fdt->open_fds->fds_bits;
20430 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
20431 +       for (total = 0; count > 0; count--) {
20432 +               if (*bptr)
20433 +                       total += hweight_long(*bptr);
20434 +               bptr++;
20435 +       }
20436 +       spin_unlock(&files->file_lock);
20437 +       return total;
20438 +}
20439 +
20440 +
20441 +/*     for *space compatibility */
20442 +
20443 +asmlinkage long sys_unshare(unsigned long);
20444 +
20445 +/*
20446 + *     migrate task to new context
20447 + *     gets vxi, puts old_vxi on change
20448 + *     optionally unshares namespaces (hack)
20449 + */
20450 +
20451 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
20452 +{
20453 +       struct vx_info *old_vxi;
20454 +       int ret = 0;
20455 +
20456 +       if (!p || !vxi)
20457 +               BUG();
20458 +
20459 +       vxdprintk(VXD_CBIT(xid, 5),
20460 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
20461 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
20462 +
20463 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
20464 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20465 +               return -EACCES;
20466 +
20467 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
20468 +               return -EFAULT;
20469 +
20470 +       old_vxi = task_get_vx_info(p);
20471 +       if (old_vxi == vxi)
20472 +               goto out;
20473 +
20474 +       if (!(ret = vx_migrate_user(p, vxi))) {
20475 +               int openfd;
20476 +
20477 +               task_lock(p);
20478 +               openfd = vx_openfd_task(p);
20479 +
20480 +               if (old_vxi) {
20481 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
20482 +                       atomic_dec(&old_vxi->cvirt.nr_running);
20483 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
20484 +                       /* FIXME: what about the struct files here? */
20485 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
20486 +                       /* account for the executable */
20487 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
20488 +               }
20489 +               atomic_inc(&vxi->cvirt.nr_threads);
20490 +               atomic_inc(&vxi->cvirt.nr_running);
20491 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
20492 +               /* FIXME: what about the struct files here? */
20493 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
20494 +               /* account for the executable */
20495 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
20496 +
20497 +               if (old_vxi) {
20498 +                       release_vx_info(old_vxi, p);
20499 +                       clr_vx_info(&p->vx_info);
20500 +               }
20501 +               claim_vx_info(vxi, p);
20502 +               set_vx_info(&p->vx_info, vxi);
20503 +               p->xid = vxi->vx_id;
20504 +
20505 +               vxdprintk(VXD_CBIT(xid, 5),
20506 +                       "moved task %p into vxi:%p[#%d]",
20507 +                       p, vxi, vxi->vx_id);
20508 +
20509 +               vx_mask_cap_bset(vxi, p);
20510 +               task_unlock(p);
20511 +
20512 +               /* hack for *spaces to provide compatibility */
20513 +               if (unshare) {
20514 +                       struct nsproxy *old_nsp, *new_nsp;
20515 +
20516 +                       ret = unshare_nsproxy_namespaces(
20517 +                               CLONE_NEWUTS | CLONE_NEWIPC,
20518 +                               &new_nsp, NULL);
20519 +                       if (ret)
20520 +                               goto out;
20521 +
20522 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
20523 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC);
20524 +                       put_nsproxy(old_nsp);
20525 +               }
20526 +       }
20527 +out:
20528 +       put_vx_info(old_vxi);
20529 +       return ret;
20530 +}
20531 +
20532 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
20533 +{
20534 +       struct task_struct *old_reaper;
20535 +
20536 +       if (!vxi)
20537 +               return -EINVAL;
20538 +
20539 +       vxdprintk(VXD_CBIT(xid, 6),
20540 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
20541 +               vxi, vxi->vx_id, p, p->xid, p->pid);
20542 +
20543 +       old_reaper = vxi->vx_reaper;
20544 +       if (old_reaper == p)
20545 +               return 0;
20546 +
20547 +       /* set new child reaper */
20548 +       get_task_struct(p);
20549 +       vxi->vx_reaper = p;
20550 +       put_task_struct(old_reaper);
20551 +       return 0;
20552 +}
20553 +
20554 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
20555 +{
20556 +       if (!vxi)
20557 +               return -EINVAL;
20558 +
20559 +       vxdprintk(VXD_CBIT(xid, 6),
20560 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
20561 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20562 +
20563 +       vxi->vx_flags &= ~VXF_STATE_INIT;
20564 +       vxi->vx_initpid = p->tgid;
20565 +       return 0;
20566 +}
20567 +
20568 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
20569 +{
20570 +       vxdprintk(VXD_CBIT(xid, 6),
20571 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
20572 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20573 +
20574 +       vxi->exit_code = code;
20575 +       vxi->vx_initpid = 0;
20576 +}
20577 +
20578 +
20579 +void vx_set_persistent(struct vx_info *vxi)
20580 +{
20581 +       vxdprintk(VXD_CBIT(xid, 6),
20582 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
20583 +
20584 +       get_vx_info(vxi);
20585 +       claim_vx_info(vxi, NULL);
20586 +}
20587 +
20588 +void vx_clear_persistent(struct vx_info *vxi)
20589 +{
20590 +       vxdprintk(VXD_CBIT(xid, 6),
20591 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
20592 +
20593 +       release_vx_info(vxi, NULL);
20594 +       put_vx_info(vxi);
20595 +}
20596 +
20597 +void vx_update_persistent(struct vx_info *vxi)
20598 +{
20599 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
20600 +               vx_set_persistent(vxi);
20601 +       else
20602 +               vx_clear_persistent(vxi);
20603 +}
20604 +
20605 +
20606 +/*     task must be current or locked          */
20607 +
20608 +void   exit_vx_info(struct task_struct *p, int code)
20609 +{
20610 +       struct vx_info *vxi = p->vx_info;
20611 +
20612 +       if (vxi) {
20613 +               atomic_dec(&vxi->cvirt.nr_threads);
20614 +               vx_nproc_dec(p);
20615 +
20616 +               vxi->exit_code = code;
20617 +               release_vx_info(vxi, p);
20618 +       }
20619 +}
20620 +
20621 +void   exit_vx_info_early(struct task_struct *p, int code)
20622 +{
20623 +       struct vx_info *vxi = p->vx_info;
20624 +
20625 +       if (vxi) {
20626 +               if (vxi->vx_initpid == p->tgid)
20627 +                       vx_exit_init(vxi, p, code);
20628 +               if (vxi->vx_reaper == p)
20629 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
20630 +       }
20631 +}
20632 +
20633 +
20634 +/* vserver syscall commands below here */
20635 +
20636 +/* taks xid and vx_info functions */
20637 +
20638 +#include <asm/uaccess.h>
20639 +
20640 +
20641 +int vc_task_xid(uint32_t id)
20642 +{
20643 +       xid_t xid;
20644 +
20645 +       if (id) {
20646 +               struct task_struct *tsk;
20647 +
20648 +               read_lock(&tasklist_lock);
20649 +               tsk = find_task_by_real_pid(id);
20650 +               xid = (tsk) ? tsk->xid : -ESRCH;
20651 +               read_unlock(&tasklist_lock);
20652 +       } else
20653 +               xid = vx_current_xid();
20654 +       return xid;
20655 +}
20656 +
20657 +
20658 +int vc_vx_info(struct vx_info *vxi, void __user *data)
20659 +{
20660 +       struct vcmd_vx_info_v0 vc_data;
20661 +
20662 +       vc_data.xid = vxi->vx_id;
20663 +       vc_data.initpid = vxi->vx_initpid;
20664 +
20665 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20666 +               return -EFAULT;
20667 +       return 0;
20668 +}
20669 +
20670 +
20671 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
20672 +{
20673 +       struct vcmd_ctx_stat_v0 vc_data;
20674 +
20675 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
20676 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
20677 +
20678 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20679 +               return -EFAULT;
20680 +       return 0;
20681 +}
20682 +
20683 +
20684 +/* context functions */
20685 +
20686 +int vc_ctx_create(uint32_t xid, void __user *data)
20687 +{
20688 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
20689 +       struct vx_info *new_vxi;
20690 +       int ret;
20691 +
20692 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20693 +               return -EFAULT;
20694 +
20695 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
20696 +               return -EINVAL;
20697 +
20698 +       new_vxi = __create_vx_info(xid);
20699 +       if (IS_ERR(new_vxi))
20700 +               return PTR_ERR(new_vxi);
20701 +
20702 +       /* initial flags */
20703 +       new_vxi->vx_flags = vc_data.flagword;
20704 +
20705 +       ret = -ENOEXEC;
20706 +       if (vs_state_change(new_vxi, VSC_STARTUP))
20707 +               goto out;
20708 +
20709 +       ret = vx_migrate_task(current, new_vxi, (!data));
20710 +       if (ret)
20711 +               goto out;
20712 +
20713 +       /* return context id on success */
20714 +       ret = new_vxi->vx_id;
20715 +
20716 +       /* get a reference for persistent contexts */
20717 +       if ((vc_data.flagword & VXF_PERSISTENT))
20718 +               vx_set_persistent(new_vxi);
20719 +out:
20720 +       release_vx_info(new_vxi, NULL);
20721 +       put_vx_info(new_vxi);
20722 +       return ret;
20723 +}
20724 +
20725 +
20726 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
20727 +{
20728 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
20729 +       int ret;
20730 +
20731 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20732 +               return -EFAULT;
20733 +
20734 +       ret = vx_migrate_task(current, vxi, 0);
20735 +       if (ret)
20736 +               return ret;
20737 +       if (vc_data.flagword & VXM_SET_INIT)
20738 +               ret = vx_set_init(vxi, current);
20739 +       if (ret)
20740 +               return ret;
20741 +       if (vc_data.flagword & VXM_SET_REAPER)
20742 +               ret = vx_set_reaper(vxi, current);
20743 +       return ret;
20744 +}
20745 +
20746 +
20747 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
20748 +{
20749 +       struct vcmd_ctx_flags_v0 vc_data;
20750 +
20751 +       vc_data.flagword = vxi->vx_flags;
20752 +
20753 +       /* special STATE flag handling */
20754 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
20755 +
20756 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20757 +               return -EFAULT;
20758 +       return 0;
20759 +}
20760 +
20761 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
20762 +{
20763 +       struct vcmd_ctx_flags_v0 vc_data;
20764 +       uint64_t mask, trigger;
20765 +
20766 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20767 +               return -EFAULT;
20768 +
20769 +       /* special STATE flag handling */
20770 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
20771 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
20772 +
20773 +       if (vxi == current->vx_info) {
20774 +               if (trigger & VXF_STATE_SETUP)
20775 +                       vx_mask_cap_bset(vxi, current);
20776 +               if (trigger & VXF_STATE_INIT) {
20777 +                       int ret;
20778 +
20779 +                       ret = vx_set_init(vxi, current);
20780 +                       if (ret)
20781 +                               return ret;
20782 +                       ret = vx_set_reaper(vxi, current);
20783 +                       if (ret)
20784 +                               return ret;
20785 +               }
20786 +       }
20787 +
20788 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
20789 +               vc_data.flagword, mask);
20790 +       if (trigger & VXF_PERSISTENT)
20791 +               vx_update_persistent(vxi);
20792 +
20793 +       return 0;
20794 +}
20795 +
20796 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
20797 +{
20798 +       if (bcaps)
20799 +               *bcaps = vxi->vx_bcaps;
20800 +       if (ccaps)
20801 +               *ccaps = vxi->vx_ccaps;
20802 +
20803 +       return 0;
20804 +}
20805 +
20806 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
20807 +{
20808 +       struct vcmd_ctx_caps_v1 vc_data;
20809 +       int ret;
20810 +
20811 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
20812 +       if (ret)
20813 +               return ret;
20814 +       vc_data.cmask = ~0ULL;
20815 +
20816 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20817 +               return -EFAULT;
20818 +       return 0;
20819 +}
20820 +
20821 +static int do_set_caps(struct vx_info *vxi,
20822 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
20823 +{
20824 +       vxi->vx_bcaps = vs_mask_flags(vxi->vx_bcaps, bcaps, bmask);
20825 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
20826 +
20827 +       return 0;
20828 +}
20829 +
20830 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
20831 +{
20832 +       struct vcmd_ctx_caps_v1 vc_data;
20833 +
20834 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20835 +               return -EFAULT;
20836 +
20837 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
20838 +}
20839 +
20840 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
20841 +{
20842 +       struct vcmd_bcaps vc_data;
20843 +       int ret;
20844 +
20845 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
20846 +       if (ret)
20847 +               return ret;
20848 +       vc_data.bmask = ~0ULL;
20849 +
20850 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20851 +               return -EFAULT;
20852 +       return 0;
20853 +}
20854 +
20855 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
20856 +{
20857 +       struct vcmd_bcaps vc_data;
20858 +
20859 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20860 +               return -EFAULT;
20861 +
20862 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
20863 +}
20864 +
20865 +
20866 +int vc_get_badness(struct vx_info *vxi, void __user *data)
20867 +{
20868 +       struct vcmd_badness_v0 vc_data;
20869 +
20870 +       vc_data.bias = vxi->vx_badness_bias;
20871 +
20872 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20873 +               return -EFAULT;
20874 +       return 0;
20875 +}
20876 +
20877 +int vc_set_badness(struct vx_info *vxi, void __user *data)
20878 +{
20879 +       struct vcmd_badness_v0 vc_data;
20880 +
20881 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20882 +               return -EFAULT;
20883 +
20884 +       vxi->vx_badness_bias = vc_data.bias;
20885 +       return 0;
20886 +}
20887 +
20888 +#include <linux/module.h>
20889 +
20890 +EXPORT_SYMBOL_GPL(free_vx_info);
20891 +
20892 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
20893 --- linux-2.6.22.10/kernel/vserver/cvirt.c      1970-01-01 01:00:00 +0100
20894 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt.c   2007-08-15 22:00:34 +0200
20895 @@ -0,0 +1,300 @@
20896 +/*
20897 + *  linux/kernel/vserver/cvirt.c
20898 + *
20899 + *  Virtual Server: Context Virtualization
20900 + *
20901 + *  Copyright (C) 2004-2007  Herbert Pötzl
20902 + *
20903 + *  V0.01  broken out from limit.c
20904 + *  V0.02  added utsname stuff
20905 + *  V0.03  changed vcmds to vxi arg
20906 + *
20907 + */
20908 +
20909 +#include <linux/types.h>
20910 +#include <linux/vs_cvirt.h>
20911 +#include <linux/vserver/switch.h>
20912 +#include <linux/vserver/cvirt_cmd.h>
20913 +
20914 +#include <asm/uaccess.h>
20915 +
20916 +
20917 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
20918 +{
20919 +       struct vx_info *vxi = current->vx_info;
20920 +
20921 +       set_normalized_timespec(uptime,
20922 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
20923 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
20924 +       if (!idle)
20925 +               return;
20926 +       set_normalized_timespec(idle,
20927 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
20928 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
20929 +       return;
20930 +}
20931 +
20932 +uint64_t vx_idle_jiffies(void)
20933 +{
20934 +       return init_task.utime + init_task.stime;
20935 +}
20936 +
20937 +
20938 +
20939 +static inline uint32_t __update_loadavg(uint32_t load,
20940 +       int wsize, int delta, int n)
20941 +{
20942 +       unsigned long long calc, prev;
20943 +
20944 +       /* just set it to n */
20945 +       if (unlikely(delta >= wsize))
20946 +               return (n << FSHIFT);
20947 +
20948 +       calc = delta * n;
20949 +       calc <<= FSHIFT;
20950 +       prev = (wsize - delta);
20951 +       prev *= load;
20952 +       calc += prev;
20953 +       do_div(calc, wsize);
20954 +       return calc;
20955 +}
20956 +
20957 +
20958 +void vx_update_load(struct vx_info *vxi)
20959 +{
20960 +       uint32_t now, last, delta;
20961 +       unsigned int nr_running, nr_uninterruptible;
20962 +       unsigned int total;
20963 +       unsigned long flags;
20964 +
20965 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
20966 +
20967 +       now = jiffies;
20968 +       last = vxi->cvirt.load_last;
20969 +       delta = now - last;
20970 +
20971 +       if (delta < 5*HZ)
20972 +               goto out;
20973 +
20974 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
20975 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
20976 +       total = nr_running + nr_uninterruptible;
20977 +
20978 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
20979 +               60*HZ, delta, total);
20980 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
20981 +               5*60*HZ, delta, total);
20982 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
20983 +               15*60*HZ, delta, total);
20984 +
20985 +       vxi->cvirt.load_last = now;
20986 +out:
20987 +       atomic_inc(&vxi->cvirt.load_updates);
20988 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
20989 +}
20990 +
20991 +
20992 +/*
20993 + * Commands to do_syslog:
20994 + *
20995 + *      0 -- Close the log.  Currently a NOP.
20996 + *      1 -- Open the log. Currently a NOP.
20997 + *      2 -- Read from the log.
20998 + *      3 -- Read all messages remaining in the ring buffer.
20999 + *      4 -- Read and clear all messages remaining in the ring buffer
21000 + *      5 -- Clear ring buffer.
21001 + *      6 -- Disable printk's to console
21002 + *      7 -- Enable printk's to console
21003 + *      8 -- Set level of messages printed to console
21004 + *      9 -- Return number of unread characters in the log buffer
21005 + *     10 -- Return size of the log buffer
21006 + */
21007 +int vx_do_syslog(int type, char __user *buf, int len)
21008 +{
21009 +       int error = 0;
21010 +       int do_clear = 0;
21011 +       struct vx_info *vxi = current->vx_info;
21012 +       struct _vx_syslog *log;
21013 +
21014 +       if (!vxi)
21015 +               return -EINVAL;
21016 +       log = &vxi->cvirt.syslog;
21017 +
21018 +       switch (type) {
21019 +       case 0:         /* Close log */
21020 +       case 1:         /* Open log */
21021 +               break;
21022 +       case 2:         /* Read from log */
21023 +               error = wait_event_interruptible(log->log_wait,
21024 +                       (log->log_start - log->log_end));
21025 +               if (error)
21026 +                       break;
21027 +               spin_lock_irq(&log->logbuf_lock);
21028 +               spin_unlock_irq(&log->logbuf_lock);
21029 +               break;
21030 +       case 4:         /* Read/clear last kernel messages */
21031 +               do_clear = 1;
21032 +               /* fall through */
21033 +       case 3:         /* Read last kernel messages */
21034 +               return 0;
21035 +
21036 +       case 5:         /* Clear ring buffer */
21037 +               return 0;
21038 +
21039 +       case 6:         /* Disable logging to console */
21040 +       case 7:         /* Enable logging to console */
21041 +       case 8:         /* Set level of messages printed to console */
21042 +               break;
21043 +
21044 +       case 9:         /* Number of chars in the log buffer */
21045 +               return 0;
21046 +       case 10:        /* Size of the log buffer */
21047 +               return 0;
21048 +       default:
21049 +               error = -EINVAL;
21050 +               break;
21051 +       }
21052 +       return error;
21053 +}
21054 +
21055 +
21056 +/* virtual host info names */
21057 +
21058 +static char *vx_vhi_name(struct vx_info *vxi, int id)
21059 +{
21060 +       struct nsproxy *nsproxy;
21061 +       struct uts_namespace *uts;
21062 +
21063 +
21064 +       if (id == VHIN_CONTEXT)
21065 +               return vxi->vx_name;
21066 +
21067 +       nsproxy = vxi->vx_nsproxy;
21068 +       if (!nsproxy)
21069 +               return NULL;
21070 +
21071 +       uts = nsproxy->uts_ns;
21072 +       if (!uts)
21073 +               return NULL;
21074 +
21075 +       switch (id) {
21076 +       case VHIN_SYSNAME:
21077 +               return uts->name.sysname;
21078 +       case VHIN_NODENAME:
21079 +               return uts->name.nodename;
21080 +       case VHIN_RELEASE:
21081 +               return uts->name.release;
21082 +       case VHIN_VERSION:
21083 +               return uts->name.version;
21084 +       case VHIN_MACHINE:
21085 +               return uts->name.machine;
21086 +       case VHIN_DOMAINNAME:
21087 +               return uts->name.domainname;
21088 +       default:
21089 +               return NULL;
21090 +       }
21091 +       return NULL;
21092 +}
21093 +
21094 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
21095 +{
21096 +       struct vcmd_vhi_name_v0 vc_data;
21097 +       char *name;
21098 +
21099 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21100 +               return -EFAULT;
21101 +
21102 +       name = vx_vhi_name(vxi, vc_data.field);
21103 +       if (!name)
21104 +               return -EINVAL;
21105 +
21106 +       memcpy(name, vc_data.name, 65);
21107 +       return 0;
21108 +}
21109 +
21110 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
21111 +{
21112 +       struct vcmd_vhi_name_v0 vc_data;
21113 +       char *name;
21114 +
21115 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21116 +               return -EFAULT;
21117 +
21118 +       name = vx_vhi_name(vxi, vc_data.field);
21119 +       if (!name)
21120 +               return -EINVAL;
21121 +
21122 +       memcpy(vc_data.name, name, 65);
21123 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21124 +               return -EFAULT;
21125 +       return 0;
21126 +}
21127 +
21128 +
21129 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
21130 +{
21131 +       struct vcmd_virt_stat_v0 vc_data;
21132 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
21133 +       struct timespec uptime;
21134 +
21135 +       do_posix_clock_monotonic_gettime(&uptime);
21136 +       set_normalized_timespec(&uptime,
21137 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
21138 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
21139 +
21140 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
21141 +       vc_data.uptime = timespec_to_ns(&uptime);
21142 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
21143 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
21144 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
21145 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
21146 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
21147 +       vc_data.load[0] = cvirt->load[0];
21148 +       vc_data.load[1] = cvirt->load[1];
21149 +       vc_data.load[2] = cvirt->load[2];
21150 +
21151 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21152 +               return -EFAULT;
21153 +       return 0;
21154 +}
21155 +
21156 +
21157 +#ifdef CONFIG_VSERVER_VTIME
21158 +
21159 +/* virtualized time base */
21160 +
21161 +void vx_gettimeofday(struct timeval *tv)
21162 +{
21163 +       do_gettimeofday(tv);
21164 +       if (!vx_flags(VXF_VIRT_TIME, 0))
21165 +               return;
21166 +
21167 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
21168 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
21169 +
21170 +       if (tv->tv_usec >= USEC_PER_SEC) {
21171 +               tv->tv_sec++;
21172 +               tv->tv_usec -= USEC_PER_SEC;
21173 +       } else if (tv->tv_usec < 0) {
21174 +               tv->tv_sec--;
21175 +               tv->tv_usec += USEC_PER_SEC;
21176 +       }
21177 +}
21178 +
21179 +int vx_settimeofday(struct timespec *ts)
21180 +{
21181 +       struct timeval tv;
21182 +
21183 +       if (!vx_flags(VXF_VIRT_TIME, 0))
21184 +               return do_settimeofday(ts);
21185 +
21186 +       do_gettimeofday(&tv);
21187 +       current->vx_info->cvirt.bias_tv.tv_sec =
21188 +               ts->tv_sec - tv.tv_sec;
21189 +       current->vx_info->cvirt.bias_tv.tv_usec =
21190 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
21191 +       return 0;
21192 +}
21193 +
21194 +#endif
21195 +
21196 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
21197 --- linux-2.6.22.10/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00 +0100
21198 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt_init.h      2007-10-25 17:05:55 +0200
21199 @@ -0,0 +1,69 @@
21200 +
21201 +
21202 +extern uint64_t vx_idle_jiffies(void);
21203 +
21204 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
21205 +{
21206 +       uint64_t idle_jiffies = vx_idle_jiffies();
21207 +       uint64_t nsuptime;
21208 +
21209 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
21210 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
21211 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
21212 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
21213 +       cvirt->bias_tv.tv_sec = 0;
21214 +       cvirt->bias_tv.tv_usec = 0;
21215 +
21216 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
21217 +       atomic_set(&cvirt->nr_threads, 0);
21218 +       atomic_set(&cvirt->nr_running, 0);
21219 +       atomic_set(&cvirt->nr_uninterruptible, 0);
21220 +       atomic_set(&cvirt->nr_onhold, 0);
21221 +
21222 +       spin_lock_init(&cvirt->load_lock);
21223 +       cvirt->load_last = jiffies;
21224 +       atomic_set(&cvirt->load_updates, 0);
21225 +       cvirt->load[0] = 0;
21226 +       cvirt->load[1] = 0;
21227 +       cvirt->load[2] = 0;
21228 +       atomic_set(&cvirt->total_forks, 0);
21229 +
21230 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
21231 +       init_waitqueue_head(&cvirt->syslog.log_wait);
21232 +       cvirt->syslog.log_start = 0;
21233 +       cvirt->syslog.log_end = 0;
21234 +       cvirt->syslog.con_start = 0;
21235 +       cvirt->syslog.logged_chars = 0;
21236 +}
21237 +
21238 +static inline
21239 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
21240 +{
21241 +       // cvirt_pc->cpustat = { 0 };
21242 +}
21243 +
21244 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
21245 +{
21246 +       int value;
21247 +
21248 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
21249 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
21250 +               cvirt, value);
21251 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
21252 +               "!!! cvirt: %p[nr_running] = %d on exit.",
21253 +               cvirt, value);
21254 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
21255 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
21256 +               cvirt, value);
21257 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
21258 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
21259 +               cvirt, value);
21260 +       return;
21261 +}
21262 +
21263 +static inline
21264 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
21265 +{
21266 +       return;
21267 +}
21268 +
21269 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
21270 --- linux-2.6.22.10/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00 +0100
21271 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt_proc.h      2007-08-05 20:53:13 +0200
21272 @@ -0,0 +1,133 @@
21273 +#ifndef _VX_CVIRT_PROC_H
21274 +#define _VX_CVIRT_PROC_H
21275 +
21276 +#include <linux/nsproxy.h>
21277 +#include <linux/mnt_namespace.h>
21278 +#include <linux/utsname.h>
21279 +#include <linux/ipc.h>
21280 +
21281 +
21282 +static inline
21283 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
21284 +{
21285 +       struct mnt_namespace *ns;
21286 +       struct uts_namespace *uts;
21287 +       struct ipc_namespace *ipc;
21288 +       struct vfsmount *mnt;
21289 +       char *path, *root;
21290 +       int length = 0;
21291 +
21292 +       if (!nsproxy)
21293 +               goto out;
21294 +
21295 +       length += sprintf(buffer + length,
21296 +               "NSProxy:\t%p [%p,%p,%p]\n",
21297 +               nsproxy, nsproxy->mnt_ns,
21298 +               nsproxy->uts_ns, nsproxy->ipc_ns);
21299 +
21300 +       ns = nsproxy->mnt_ns;
21301 +       if (!ns)
21302 +               goto skip_ns;
21303 +
21304 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
21305 +       if (!path)
21306 +               goto skip_ns;
21307 +
21308 +       mnt = ns->root;
21309 +       root = d_path(mnt->mnt_root, mnt->mnt_parent, path, PATH_MAX - 2);
21310 +       length += sprintf(buffer + length,
21311 +               "Namespace:\t%p [#%u]\n"
21312 +               "RootPath:\t%s\n",
21313 +               ns, atomic_read(&ns->count),
21314 +               root);
21315 +       kfree(path);
21316 +skip_ns:
21317 +
21318 +       uts = nsproxy->uts_ns;
21319 +       if (!uts)
21320 +               goto skip_uts;
21321 +
21322 +       length += sprintf(buffer + length,
21323 +               "SysName:\t%.*s\n"
21324 +               "NodeName:\t%.*s\n"
21325 +               "Release:\t%.*s\n"
21326 +               "Version:\t%.*s\n"
21327 +               "Machine:\t%.*s\n"
21328 +               "DomainName:\t%.*s\n",
21329 +               __NEW_UTS_LEN, uts->name.sysname,
21330 +               __NEW_UTS_LEN, uts->name.nodename,
21331 +               __NEW_UTS_LEN, uts->name.release,
21332 +               __NEW_UTS_LEN, uts->name.version,
21333 +               __NEW_UTS_LEN, uts->name.machine,
21334 +               __NEW_UTS_LEN, uts->name.domainname);
21335 +skip_uts:
21336 +
21337 +       ipc = nsproxy->ipc_ns;
21338 +       if (!ipc)
21339 +               goto skip_ipc;
21340 +
21341 +       length += sprintf(buffer + length,
21342 +               "SEMS:\t\t%d %d %d %d  %d\n"
21343 +               "MSG:\t\t%d %d %d\n"
21344 +               "SHM:\t\t%lu %lu  %d %d\n",
21345 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
21346 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
21347 +               ipc->used_sems,
21348 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
21349 +               (unsigned long)ipc->shm_ctlmax,
21350 +               (unsigned long)ipc->shm_ctlall,
21351 +               ipc->shm_ctlmni, ipc->shm_tot);
21352 +skip_ipc:
21353 +out:
21354 +       return length;
21355 +}
21356 +
21357 +
21358 +#include <linux/sched.h>
21359 +
21360 +#define LOAD_INT(x) ((x) >> FSHIFT)
21361 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
21362 +
21363 +static inline
21364 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
21365 +{
21366 +       int length = 0;
21367 +       int a, b, c;
21368 +
21369 +       length += sprintf(buffer + length,
21370 +               "BiasUptime:\t%lu.%02lu\n",
21371 +               (unsigned long)cvirt->bias_uptime.tv_sec,
21372 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
21373 +
21374 +       a = cvirt->load[0] + (FIXED_1 / 200);
21375 +       b = cvirt->load[1] + (FIXED_1 / 200);
21376 +       c = cvirt->load[2] + (FIXED_1 / 200);
21377 +       length += sprintf(buffer + length,
21378 +               "nr_threads:\t%d\n"
21379 +               "nr_running:\t%d\n"
21380 +               "nr_unintr:\t%d\n"
21381 +               "nr_onhold:\t%d\n"
21382 +               "load_updates:\t%d\n"
21383 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
21384 +               "total_forks:\t%d\n",
21385 +               atomic_read(&cvirt->nr_threads),
21386 +               atomic_read(&cvirt->nr_running),
21387 +               atomic_read(&cvirt->nr_uninterruptible),
21388 +               atomic_read(&cvirt->nr_onhold),
21389 +               atomic_read(&cvirt->load_updates),
21390 +               LOAD_INT(a), LOAD_FRAC(a),
21391 +               LOAD_INT(b), LOAD_FRAC(b),
21392 +               LOAD_INT(c), LOAD_FRAC(c),
21393 +               atomic_read(&cvirt->total_forks));
21394 +       return length;
21395 +}
21396 +
21397 +static inline
21398 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
21399 +       char *buffer, int cpu)
21400 +{
21401 +       int length = 0;
21402 +       return length;
21403 +}
21404 +
21405 +#endif /* _VX_CVIRT_PROC_H */
21406 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
21407 --- linux-2.6.22.10/kernel/vserver/debug.c      1970-01-01 01:00:00 +0100
21408 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/debug.c   2007-10-01 14:57:41 +0200
21409 @@ -0,0 +1,32 @@
21410 +/*
21411 + *  kernel/vserver/debug.c
21412 + *
21413 + *  Copyright (C) 2005-2007 Herbert Pötzl
21414 + *
21415 + *  V0.01  vx_info dump support
21416 + *
21417 + */
21418 +
21419 +#include <linux/module.h>
21420 +
21421 +#include <linux/vserver/context.h>
21422 +
21423 +
21424 +void   dump_vx_info(struct vx_info *vxi, int level)
21425 +{
21426 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
21427 +               atomic_read(&vxi->vx_usecnt),
21428 +               atomic_read(&vxi->vx_tasks),
21429 +               vxi->vx_state);
21430 +       if (level > 0) {
21431 +               __dump_vx_limit(&vxi->limit);
21432 +               __dump_vx_sched(&vxi->sched);
21433 +               __dump_vx_cvirt(&vxi->cvirt);
21434 +               __dump_vx_cacct(&vxi->cacct);
21435 +       }
21436 +       printk("---\n");
21437 +}
21438 +
21439 +
21440 +EXPORT_SYMBOL_GPL(dump_vx_info);
21441 +
21442 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
21443 --- linux-2.6.22.10/kernel/vserver/device.c     1970-01-01 01:00:00 +0100
21444 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/device.c  2007-10-11 01:10:22 +0200
21445 @@ -0,0 +1,443 @@
21446 +/*
21447 + *  linux/kernel/vserver/device.c
21448 + *
21449 + *  Linux-VServer: Device Support
21450 + *
21451 + *  Copyright (C) 2006  Herbert Pötzl
21452 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
21453 + *
21454 + *  V0.01  device mapping basics
21455 + *  V0.02  added defaults
21456 + *
21457 + */
21458 +
21459 +#include <linux/slab.h>
21460 +#include <linux/rcupdate.h>
21461 +#include <linux/fs.h>
21462 +#include <linux/namei.h>
21463 +#include <linux/hash.h>
21464 +
21465 +#include <asm/errno.h>
21466 +#include <asm/uaccess.h>
21467 +#include <linux/vserver/base.h>
21468 +#include <linux/vserver/debug.h>
21469 +#include <linux/vserver/context.h>
21470 +#include <linux/vserver/device.h>
21471 +#include <linux/vserver/device_cmd.h>
21472 +
21473 +
21474 +#define DMAP_HASH_BITS 4
21475 +
21476 +
21477 +struct vs_mapping {
21478 +       union {
21479 +               struct hlist_node hlist;
21480 +               struct list_head list;
21481 +       } u;
21482 +#define dm_hlist       u.hlist
21483 +#define dm_list                u.list
21484 +       xid_t xid;
21485 +       dev_t device;
21486 +       struct vx_dmap_target target;
21487 +};
21488 +
21489 +
21490 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
21491 +
21492 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
21493 +
21494 +static struct vx_dmap_target dmap_defaults[2] = {
21495 +       { .flags = DATTR_OPEN },
21496 +       { .flags = DATTR_OPEN },
21497 +};
21498 +
21499 +
21500 +struct kmem_cache *dmap_cachep __read_mostly;
21501 +
21502 +int __init dmap_cache_init(void)
21503 +{
21504 +       dmap_cachep = kmem_cache_create("dmap_cache",
21505 +               sizeof(struct vs_mapping), 0,
21506 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
21507 +       return 0;
21508 +}
21509 +
21510 +__initcall(dmap_cache_init);
21511 +
21512 +
21513 +static inline unsigned int __hashval(dev_t dev, int bits)
21514 +{
21515 +       return hash_long((unsigned long)dev, bits);
21516 +}
21517 +
21518 +
21519 +/*     __hash_mapping()
21520 + *     add the mapping to the hash table
21521 + */
21522 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
21523 +{
21524 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21525 +       struct hlist_head *head, *hash = dmap_main_hash;
21526 +       int device = vdm->device;
21527 +
21528 +       spin_lock(hash_lock);
21529 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
21530 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
21531 +
21532 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
21533 +       hlist_add_head(&vdm->dm_hlist, head);
21534 +       spin_unlock(hash_lock);
21535 +}
21536 +
21537 +
21538 +static inline int __mode_to_default(umode_t mode)
21539 +{
21540 +       switch (mode) {
21541 +       case S_IFBLK:
21542 +               return 0;
21543 +       case S_IFCHR:
21544 +               return 1;
21545 +       default:
21546 +               BUG();
21547 +       }
21548 +}
21549 +
21550 +
21551 +/*     __set_default()
21552 + *     set a default
21553 + */
21554 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
21555 +       struct vx_dmap_target *vdmt)
21556 +{
21557 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21558 +       spin_lock(hash_lock);
21559 +
21560 +       if (vxi)
21561 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
21562 +       else
21563 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
21564 +
21565 +
21566 +       spin_unlock(hash_lock);
21567 +
21568 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
21569 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
21570 +}
21571 +
21572 +
21573 +/*     __remove_default()
21574 + *     remove a default
21575 + */
21576 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
21577 +{
21578 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21579 +       spin_lock(hash_lock);
21580 +
21581 +       if (vxi)
21582 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
21583 +       else    /* remove == reset */
21584 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
21585 +
21586 +       spin_unlock(hash_lock);
21587 +       return 0;
21588 +}
21589 +
21590 +
21591 +/*     __find_mapping()
21592 + *     find a mapping in the hash table
21593 + *
21594 + *     caller must hold hash_lock
21595 + */
21596 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
21597 +       struct vs_mapping **local, struct vs_mapping **global)
21598 +{
21599 +       struct hlist_head *hash = dmap_main_hash;
21600 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
21601 +       struct hlist_node *pos;
21602 +       struct vs_mapping *vdm;
21603 +
21604 +       *local = NULL;
21605 +       if (global)
21606 +               *global = NULL;
21607 +
21608 +       hlist_for_each(pos, head) {
21609 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
21610 +
21611 +               if ((vdm->device == device) &&
21612 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
21613 +                       if (vdm->xid == xid) {
21614 +                               *local = vdm;
21615 +                               return 1;
21616 +                       } else if (global && vdm->xid == 0)
21617 +                               *global = vdm;
21618 +               }
21619 +       }
21620 +
21621 +       if (global && *global)
21622 +               return 0;
21623 +       else
21624 +               return -ENOENT;
21625 +}
21626 +
21627 +
21628 +/*     __lookup_mapping()
21629 + *     find a mapping and store the result in target and flags
21630 + */
21631 +static inline int __lookup_mapping(struct vx_info *vxi,
21632 +       dev_t device, dev_t *target, int *flags, umode_t mode)
21633 +{
21634 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21635 +       struct vs_mapping *vdm, *global;
21636 +       struct vx_dmap_target *vdmt;
21637 +       int ret = 0;
21638 +       xid_t xid = vxi->vx_id;
21639 +       int index;
21640 +
21641 +       spin_lock(hash_lock);
21642 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
21643 +               ret = 1;
21644 +               vdmt = &vdm->target;
21645 +               goto found;
21646 +       }
21647 +
21648 +       index = __mode_to_default(mode);
21649 +       if (vxi && vxi->dmap.targets[index].flags) {
21650 +               ret = 2;
21651 +               vdmt = &vxi->dmap.targets[index];
21652 +       } else if (global) {
21653 +               ret = 3;
21654 +               vdmt = &global->target;
21655 +               goto found;
21656 +       } else {
21657 +               ret = 4;
21658 +               vdmt = &dmap_defaults[index];
21659 +       }
21660 +
21661 +found:
21662 +       if (target && (vdmt->flags & DATTR_REMAP))
21663 +               *target = vdmt->target;
21664 +       else if (target)
21665 +               *target = device;
21666 +       if (flags)
21667 +               *flags = vdmt->flags;
21668 +
21669 +       spin_unlock(hash_lock);
21670 +
21671 +       return ret;
21672 +}
21673 +
21674 +
21675 +/*     __remove_mapping()
21676 + *     remove a mapping from the hash table
21677 + */
21678 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
21679 +       umode_t mode)
21680 +{
21681 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21682 +       struct vs_mapping *vdm = NULL;
21683 +       int ret = 0;
21684 +
21685 +       spin_lock(hash_lock);
21686 +
21687 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
21688 +               NULL);
21689 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
21690 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
21691 +       if (ret < 0)
21692 +               goto out;
21693 +       hlist_del(&vdm->dm_hlist);
21694 +
21695 +out:
21696 +       spin_unlock(hash_lock);
21697 +       if (vdm)
21698 +               kmem_cache_free(dmap_cachep, vdm);
21699 +       return ret;
21700 +}
21701 +
21702 +
21703 +
21704 +int vs_map_device(struct vx_info *vxi,
21705 +       dev_t device, dev_t *target, umode_t mode)
21706 +{
21707 +       int ret, flags = DATTR_MASK;
21708 +
21709 +       if (!vxi) {
21710 +               if (target)
21711 +                       *target = device;
21712 +               goto out;
21713 +       }
21714 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
21715 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
21716 +               device, target ? *target : 0, flags, mode, ret);
21717 +out:
21718 +       return (flags & DATTR_MASK);
21719 +}
21720 +
21721 +
21722 +
21723 +static int do_set_mapping(struct vx_info *vxi,
21724 +       dev_t device, dev_t target, int flags, umode_t mode)
21725 +{
21726 +       if (device) {
21727 +               struct vs_mapping *new;
21728 +
21729 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
21730 +               if (!new)
21731 +                       return -ENOMEM;
21732 +
21733 +               INIT_HLIST_NODE(&new->dm_hlist);
21734 +               new->device = device;
21735 +               new->target.target = target;
21736 +               new->target.flags = flags | mode;
21737 +               new->xid = (vxi ? vxi->vx_id : 0);
21738 +
21739 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
21740 +               __hash_mapping(vxi, new);
21741 +       } else {
21742 +               struct vx_dmap_target new = {
21743 +                       .target = target,
21744 +                       .flags = flags | mode,
21745 +               };
21746 +               __set_default(vxi, mode, &new);
21747 +       }
21748 +       return 0;
21749 +}
21750 +
21751 +
21752 +static int do_unset_mapping(struct vx_info *vxi,
21753 +       dev_t device, dev_t target, int flags, umode_t mode)
21754 +{
21755 +       int ret = -EINVAL;
21756 +
21757 +       if (device) {
21758 +               ret = __remove_mapping(vxi, device, mode);
21759 +               if (ret < 0)
21760 +                       goto out;
21761 +       } else {
21762 +               ret = __remove_default(vxi, mode);
21763 +               if (ret < 0)
21764 +                       goto out;
21765 +       }
21766 +
21767 +out:
21768 +       return ret;
21769 +}
21770 +
21771 +
21772 +static inline int __user_device(const char __user *name, dev_t *dev,
21773 +       umode_t *mode)
21774 +{
21775 +       struct nameidata nd;
21776 +       int ret;
21777 +
21778 +       if (!name) {
21779 +               *dev = 0;
21780 +               return 0;
21781 +       }
21782 +       ret = user_path_walk_link(name, &nd);
21783 +       if (ret)
21784 +               return ret;
21785 +       if (nd.dentry->d_inode) {
21786 +               *dev = nd.dentry->d_inode->i_rdev;
21787 +               *mode = nd.dentry->d_inode->i_mode;
21788 +       }
21789 +       path_release(&nd);
21790 +       return 0;
21791 +}
21792 +
21793 +static inline int __mapping_mode(dev_t device, dev_t target,
21794 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
21795 +{
21796 +       if (device)
21797 +               *mode = device_mode & S_IFMT;
21798 +       else if (target)
21799 +               *mode = target_mode & S_IFMT;
21800 +       else
21801 +               *mode = 0;
21802 +
21803 +       /* if both given, device and target mode have to match */
21804 +       if (device && target &&
21805 +               ((device_mode ^ target_mode) & S_IFMT))
21806 +               return -EINVAL;
21807 +       return 0;
21808 +}
21809 +
21810 +
21811 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
21812 +       const char __user *target_path, int flags, int set)
21813 +{
21814 +       dev_t device = ~0, target = ~0;
21815 +       umode_t device_mode = 0, target_mode = 0, mode;
21816 +       int ret;
21817 +
21818 +       ret = __user_device(device_path, &device, &device_mode);
21819 +       if (ret)
21820 +               return ret;
21821 +       ret = __user_device(target_path, &target, &target_mode);
21822 +       if (ret)
21823 +               return ret;
21824 +
21825 +       ret = __mapping_mode(device, target,
21826 +               device_mode, target_mode, &mode);
21827 +       if (ret)
21828 +               return ret;
21829 +
21830 +       if (set)
21831 +               return do_set_mapping(vxi, device, target,
21832 +                       flags, mode);
21833 +       else
21834 +               return do_unset_mapping(vxi, device, target,
21835 +                       flags, mode);
21836 +}
21837 +
21838 +
21839 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
21840 +{
21841 +       struct vcmd_set_mapping_v0 vc_data;
21842 +
21843 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21844 +               return -EFAULT;
21845 +
21846 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21847 +               vc_data.flags, 1);
21848 +}
21849 +
21850 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
21851 +{
21852 +       struct vcmd_set_mapping_v0 vc_data;
21853 +
21854 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21855 +               return -EFAULT;
21856 +
21857 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21858 +               vc_data.flags, 0);
21859 +}
21860 +
21861 +
21862 +#ifdef CONFIG_COMPAT
21863 +
21864 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
21865 +{
21866 +       struct vcmd_set_mapping_v0_x32 vc_data;
21867 +
21868 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21869 +               return -EFAULT;
21870 +
21871 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21872 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
21873 +}
21874 +
21875 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
21876 +{
21877 +       struct vcmd_set_mapping_v0_x32 vc_data;
21878 +
21879 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21880 +               return -EFAULT;
21881 +
21882 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21883 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
21884 +}
21885 +
21886 +#endif /* CONFIG_COMPAT */
21887 +
21888 +
21889 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
21890 --- linux-2.6.22.10/kernel/vserver/dlimit.c     1970-01-01 01:00:00 +0100
21891 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/dlimit.c  2007-08-15 22:07:58 +0200
21892 @@ -0,0 +1,520 @@
21893 +/*
21894 + *  linux/kernel/vserver/dlimit.c
21895 + *
21896 + *  Virtual Server: Context Disk Limits
21897 + *
21898 + *  Copyright (C) 2004-2007  Herbert Pötzl
21899 + *
21900 + *  V0.01  initial version
21901 + *  V0.02  compat32 splitup
21902 + *
21903 + */
21904 +
21905 +#include <linux/statfs.h>
21906 +#include <linux/vs_tag.h>
21907 +#include <linux/vs_dlimit.h>
21908 +#include <linux/vserver/dlimit_cmd.h>
21909 +
21910 +#include <asm/uaccess.h>
21911 +
21912 +/*     __alloc_dl_info()
21913 +
21914 +       * allocate an initialized dl_info struct
21915 +       * doesn't make it visible (hash)                        */
21916 +
21917 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
21918 +{
21919 +       struct dl_info *new = NULL;
21920 +
21921 +       vxdprintk(VXD_CBIT(dlim, 5),
21922 +               "alloc_dl_info(%p,%d)*", sb, tag);
21923 +
21924 +       /* would this benefit from a slab cache? */
21925 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
21926 +       if (!new)
21927 +               return 0;
21928 +
21929 +       memset(new, 0, sizeof(struct dl_info));
21930 +       new->dl_tag = tag;
21931 +       new->dl_sb = sb;
21932 +       INIT_RCU_HEAD(&new->dl_rcu);
21933 +       INIT_HLIST_NODE(&new->dl_hlist);
21934 +       spin_lock_init(&new->dl_lock);
21935 +       atomic_set(&new->dl_refcnt, 0);
21936 +       atomic_set(&new->dl_usecnt, 0);
21937 +
21938 +       /* rest of init goes here */
21939 +
21940 +       vxdprintk(VXD_CBIT(dlim, 4),
21941 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
21942 +       return new;
21943 +}
21944 +
21945 +/*     __dealloc_dl_info()
21946 +
21947 +       * final disposal of dl_info                             */
21948 +
21949 +static void __dealloc_dl_info(struct dl_info *dli)
21950 +{
21951 +       vxdprintk(VXD_CBIT(dlim, 4),
21952 +               "dealloc_dl_info(%p)", dli);
21953 +
21954 +       dli->dl_hlist.next = LIST_POISON1;
21955 +       dli->dl_tag = -1;
21956 +       dli->dl_sb = 0;
21957 +
21958 +       BUG_ON(atomic_read(&dli->dl_usecnt));
21959 +       BUG_ON(atomic_read(&dli->dl_refcnt));
21960 +
21961 +       kfree(dli);
21962 +}
21963 +
21964 +
21965 +/*     hash table for dl_info hash */
21966 +
21967 +#define DL_HASH_SIZE   13
21968 +
21969 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
21970 +
21971 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
21972 +
21973 +
21974 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
21975 +{
21976 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
21977 +}
21978 +
21979 +
21980 +
21981 +/*     __hash_dl_info()
21982 +
21983 +       * add the dli to the global hash table
21984 +       * requires the hash_lock to be held                     */
21985 +
21986 +static inline void __hash_dl_info(struct dl_info *dli)
21987 +{
21988 +       struct hlist_head *head;
21989 +
21990 +       vxdprintk(VXD_CBIT(dlim, 6),
21991 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
21992 +       get_dl_info(dli);
21993 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
21994 +       hlist_add_head_rcu(&dli->dl_hlist, head);
21995 +}
21996 +
21997 +/*     __unhash_dl_info()
21998 +
21999 +       * remove the dli from the global hash table
22000 +       * requires the hash_lock to be held                     */
22001 +
22002 +static inline void __unhash_dl_info(struct dl_info *dli)
22003 +{
22004 +       vxdprintk(VXD_CBIT(dlim, 6),
22005 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
22006 +       hlist_del_rcu(&dli->dl_hlist);
22007 +       put_dl_info(dli);
22008 +}
22009 +
22010 +
22011 +/*     __lookup_dl_info()
22012 +
22013 +       * requires the rcu_read_lock()
22014 +       * doesn't increment the dl_refcnt                       */
22015 +
22016 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
22017 +{
22018 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
22019 +       struct hlist_node *pos;
22020 +       struct dl_info *dli;
22021 +
22022 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
22023 +
22024 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
22025 +                       return dli;
22026 +               }
22027 +       }
22028 +       return NULL;
22029 +}
22030 +
22031 +
22032 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
22033 +{
22034 +       struct dl_info *dli;
22035 +
22036 +       rcu_read_lock();
22037 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
22038 +       vxdprintk(VXD_CBIT(dlim, 7),
22039 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
22040 +       rcu_read_unlock();
22041 +       return dli;
22042 +}
22043 +
22044 +void rcu_free_dl_info(struct rcu_head *head)
22045 +{
22046 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
22047 +       int usecnt, refcnt;
22048 +
22049 +       BUG_ON(!dli || !head);
22050 +
22051 +       usecnt = atomic_read(&dli->dl_usecnt);
22052 +       BUG_ON(usecnt < 0);
22053 +
22054 +       refcnt = atomic_read(&dli->dl_refcnt);
22055 +       BUG_ON(refcnt < 0);
22056 +
22057 +       vxdprintk(VXD_CBIT(dlim, 3),
22058 +               "rcu_free_dl_info(%p)", dli);
22059 +       if (!usecnt)
22060 +               __dealloc_dl_info(dli);
22061 +       else
22062 +               printk("!!! rcu didn't free\n");
22063 +}
22064 +
22065 +
22066 +
22067 +
22068 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
22069 +       uint32_t flags, int add)
22070 +{
22071 +       struct nameidata nd;
22072 +       int ret;
22073 +
22074 +       ret = user_path_walk_link(name, &nd);
22075 +       if (!ret) {
22076 +               struct super_block *sb;
22077 +               struct dl_info *dli;
22078 +
22079 +               ret = -EINVAL;
22080 +               if (!nd.dentry->d_inode)
22081 +                       goto out_release;
22082 +               if (!(sb = nd.dentry->d_inode->i_sb))
22083 +                       goto out_release;
22084 +
22085 +               if (add) {
22086 +                       dli = __alloc_dl_info(sb, id);
22087 +                       spin_lock(&dl_info_hash_lock);
22088 +
22089 +                       ret = -EEXIST;
22090 +                       if (__lookup_dl_info(sb, id))
22091 +                               goto out_unlock;
22092 +                       __hash_dl_info(dli);
22093 +                       dli = NULL;
22094 +               } else {
22095 +                       spin_lock(&dl_info_hash_lock);
22096 +                       dli = __lookup_dl_info(sb, id);
22097 +
22098 +                       ret = -ESRCH;
22099 +                       if (!dli)
22100 +                               goto out_unlock;
22101 +                       __unhash_dl_info(dli);
22102 +               }
22103 +               ret = 0;
22104 +       out_unlock:
22105 +               spin_unlock(&dl_info_hash_lock);
22106 +               if (add && dli)
22107 +                       __dealloc_dl_info(dli);
22108 +       out_release:
22109 +               path_release(&nd);
22110 +       }
22111 +       return ret;
22112 +}
22113 +
22114 +int vc_add_dlimit(uint32_t id, void __user *data)
22115 +{
22116 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
22117 +
22118 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22119 +               return -EFAULT;
22120 +
22121 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
22122 +}
22123 +
22124 +int vc_rem_dlimit(uint32_t id, void __user *data)
22125 +{
22126 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
22127 +
22128 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22129 +               return -EFAULT;
22130 +
22131 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
22132 +}
22133 +
22134 +#ifdef CONFIG_COMPAT
22135 +
22136 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
22137 +{
22138 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
22139 +
22140 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22141 +               return -EFAULT;
22142 +
22143 +       return do_addrem_dlimit(id,
22144 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
22145 +}
22146 +
22147 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
22148 +{
22149 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
22150 +
22151 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22152 +               return -EFAULT;
22153 +
22154 +       return do_addrem_dlimit(id,
22155 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
22156 +}
22157 +
22158 +#endif /* CONFIG_COMPAT */
22159 +
22160 +
22161 +static inline
22162 +int do_set_dlimit(uint32_t id, const char __user *name,
22163 +       uint32_t space_used, uint32_t space_total,
22164 +       uint32_t inodes_used, uint32_t inodes_total,
22165 +       uint32_t reserved, uint32_t flags)
22166 +{
22167 +       struct nameidata nd;
22168 +       int ret;
22169 +
22170 +       ret = user_path_walk_link(name, &nd);
22171 +       if (!ret) {
22172 +               struct super_block *sb;
22173 +               struct dl_info *dli;
22174 +
22175 +               ret = -EINVAL;
22176 +               if (!nd.dentry->d_inode)
22177 +                       goto out_release;
22178 +               if (!(sb = nd.dentry->d_inode->i_sb))
22179 +                       goto out_release;
22180 +               if ((reserved != CDLIM_KEEP &&
22181 +                       reserved > 100) ||
22182 +                       (inodes_used != CDLIM_KEEP &&
22183 +                       inodes_used > inodes_total) ||
22184 +                       (space_used != CDLIM_KEEP &&
22185 +                       space_used > space_total))
22186 +                       goto out_release;
22187 +
22188 +               ret = -ESRCH;
22189 +               dli = locate_dl_info(sb, id);
22190 +               if (!dli)
22191 +                       goto out_release;
22192 +
22193 +               spin_lock(&dli->dl_lock);
22194 +
22195 +               if (inodes_used != CDLIM_KEEP)
22196 +                       dli->dl_inodes_used = inodes_used;
22197 +               if (inodes_total != CDLIM_KEEP)
22198 +                       dli->dl_inodes_total = inodes_total;
22199 +               if (space_used != CDLIM_KEEP) {
22200 +                       dli->dl_space_used = space_used;
22201 +                       dli->dl_space_used <<= 10;
22202 +               }
22203 +               if (space_total == CDLIM_INFINITY)
22204 +                       dli->dl_space_total = DLIM_INFINITY;
22205 +               else if (space_total != CDLIM_KEEP) {
22206 +                       dli->dl_space_total = space_total;
22207 +                       dli->dl_space_total <<= 10;
22208 +               }
22209 +               if (reserved != CDLIM_KEEP)
22210 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
22211 +
22212 +               spin_unlock(&dli->dl_lock);
22213 +
22214 +               put_dl_info(dli);
22215 +               ret = 0;
22216 +
22217 +       out_release:
22218 +               path_release(&nd);
22219 +       }
22220 +       return ret;
22221 +}
22222 +
22223 +int vc_set_dlimit(uint32_t id, void __user *data)
22224 +{
22225 +       struct vcmd_ctx_dlimit_v0 vc_data;
22226 +
22227 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22228 +               return -EFAULT;
22229 +
22230 +       return do_set_dlimit(id, vc_data.name,
22231 +               vc_data.space_used, vc_data.space_total,
22232 +               vc_data.inodes_used, vc_data.inodes_total,
22233 +               vc_data.reserved, vc_data.flags);
22234 +}
22235 +
22236 +#ifdef CONFIG_COMPAT
22237 +
22238 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
22239 +{
22240 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22241 +
22242 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22243 +               return -EFAULT;
22244 +
22245 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
22246 +               vc_data.space_used, vc_data.space_total,
22247 +               vc_data.inodes_used, vc_data.inodes_total,
22248 +               vc_data.reserved, vc_data.flags);
22249 +}
22250 +
22251 +#endif /* CONFIG_COMPAT */
22252 +
22253 +
22254 +static inline
22255 +int do_get_dlimit(uint32_t id, const char __user *name,
22256 +       uint32_t *space_used, uint32_t *space_total,
22257 +       uint32_t *inodes_used, uint32_t *inodes_total,
22258 +       uint32_t *reserved, uint32_t *flags)
22259 +{
22260 +       struct nameidata nd;
22261 +       int ret;
22262 +
22263 +       ret = user_path_walk_link(name, &nd);
22264 +       if (!ret) {
22265 +               struct super_block *sb;
22266 +               struct dl_info *dli;
22267 +
22268 +               ret = -EINVAL;
22269 +               if (!nd.dentry->d_inode)
22270 +                       goto out_release;
22271 +               if (!(sb = nd.dentry->d_inode->i_sb))
22272 +                       goto out_release;
22273 +
22274 +               ret = -ESRCH;
22275 +               dli = locate_dl_info(sb, id);
22276 +               if (!dli)
22277 +                       goto out_release;
22278 +
22279 +               spin_lock(&dli->dl_lock);
22280 +               *inodes_used = dli->dl_inodes_used;
22281 +               *inodes_total = dli->dl_inodes_total;
22282 +               *space_used = dli->dl_space_used >> 10;
22283 +               if (dli->dl_space_total == DLIM_INFINITY)
22284 +                       *space_total = CDLIM_INFINITY;
22285 +               else
22286 +                       *space_total = dli->dl_space_total >> 10;
22287 +
22288 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
22289 +               spin_unlock(&dli->dl_lock);
22290 +
22291 +               put_dl_info(dli);
22292 +               ret = -EFAULT;
22293 +
22294 +               ret = 0;
22295 +       out_release:
22296 +               path_release(&nd);
22297 +       }
22298 +       return ret;
22299 +}
22300 +
22301 +
22302 +int vc_get_dlimit(uint32_t id, void __user *data)
22303 +{
22304 +       struct vcmd_ctx_dlimit_v0 vc_data;
22305 +       int ret;
22306 +
22307 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22308 +               return -EFAULT;
22309 +
22310 +       ret = do_get_dlimit(id, vc_data.name,
22311 +               &vc_data.space_used, &vc_data.space_total,
22312 +               &vc_data.inodes_used, &vc_data.inodes_total,
22313 +               &vc_data.reserved, &vc_data.flags);
22314 +       if (ret)
22315 +               return ret;
22316 +
22317 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22318 +               return -EFAULT;
22319 +       return 0;
22320 +}
22321 +
22322 +#ifdef CONFIG_COMPAT
22323 +
22324 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
22325 +{
22326 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22327 +       int ret;
22328 +
22329 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22330 +               return -EFAULT;
22331 +
22332 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
22333 +               &vc_data.space_used, &vc_data.space_total,
22334 +               &vc_data.inodes_used, &vc_data.inodes_total,
22335 +               &vc_data.reserved, &vc_data.flags);
22336 +       if (ret)
22337 +               return ret;
22338 +
22339 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22340 +               return -EFAULT;
22341 +       return 0;
22342 +}
22343 +
22344 +#endif /* CONFIG_COMPAT */
22345 +
22346 +
22347 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
22348 +{
22349 +       struct dl_info *dli;
22350 +       __u64 blimit, bfree, bavail;
22351 +       __u32 ifree;
22352 +
22353 +       dli = locate_dl_info(sb, dx_current_tag());
22354 +       if (!dli)
22355 +               return;
22356 +
22357 +       spin_lock(&dli->dl_lock);
22358 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
22359 +               goto no_ilim;
22360 +
22361 +       /* reduce max inodes available to limit */
22362 +       if (buf->f_files > dli->dl_inodes_total)
22363 +               buf->f_files = dli->dl_inodes_total;
22364 +
22365 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
22366 +       /* reduce free inodes to min */
22367 +       if (ifree < buf->f_ffree)
22368 +               buf->f_ffree = ifree;
22369 +
22370 +no_ilim:
22371 +       if (dli->dl_space_total == DLIM_INFINITY)
22372 +               goto no_blim;
22373 +
22374 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
22375 +
22376 +       if (dli->dl_space_total < dli->dl_space_used)
22377 +               bfree = 0;
22378 +       else
22379 +               bfree = (dli->dl_space_total - dli->dl_space_used)
22380 +                       >> sb->s_blocksize_bits;
22381 +
22382 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
22383 +       if (bavail < dli->dl_space_used)
22384 +               bavail = 0;
22385 +       else
22386 +               bavail = (bavail - dli->dl_space_used)
22387 +                       >> sb->s_blocksize_bits;
22388 +
22389 +       /* reduce max space available to limit */
22390 +       if (buf->f_blocks > blimit)
22391 +               buf->f_blocks = blimit;
22392 +
22393 +       /* reduce free space to min */
22394 +       if (bfree < buf->f_bfree)
22395 +               buf->f_bfree = bfree;
22396 +
22397 +       /* reduce avail space to min */
22398 +       if (bavail < buf->f_bavail)
22399 +               buf->f_bavail = bavail;
22400 +
22401 +no_blim:
22402 +       spin_unlock(&dli->dl_lock);
22403 +       put_dl_info(dli);
22404 +
22405 +       return;
22406 +}
22407 +
22408 +#include <linux/module.h>
22409 +
22410 +EXPORT_SYMBOL_GPL(locate_dl_info);
22411 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
22412 +
22413 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
22414 --- linux-2.6.22.10/kernel/vserver/helper.c     1970-01-01 01:00:00 +0100
22415 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/helper.c  2007-08-15 22:12:01 +0200
22416 @@ -0,0 +1,199 @@
22417 +/*
22418 + *  linux/kernel/vserver/helper.c
22419 + *
22420 + *  Virtual Context Support
22421 + *
22422 + *  Copyright (C) 2004-2007  Herbert Pötzl
22423 + *
22424 + *  V0.01  basic helper
22425 + *
22426 + */
22427 +
22428 +#include <linux/kmod.h>
22429 +#include <linux/reboot.h>
22430 +#include <linux/vs_context.h>
22431 +#include <linux/vs_network.h>
22432 +#include <linux/vserver/signal.h>
22433 +
22434 +
22435 +char vshelper_path[255] = "/sbin/vshelper";
22436 +
22437 +
22438 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
22439 +{
22440 +       int ret;
22441 +
22442 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
22443 +               printk( KERN_WARNING
22444 +                       "%s: (%s %s) returned %s with %d\n",
22445 +                       name, argv[1], argv[2],
22446 +                       sync ? "sync" : "async", ret);
22447 +       }
22448 +       vxdprintk(VXD_CBIT(switch, 4),
22449 +               "%s: (%s %s) returned %s with %d",
22450 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
22451 +       return ret;
22452 +}
22453 +
22454 +/*
22455 + *      vshelper path is set via /proc/sys
22456 + *      invoked by vserver sys_reboot(), with
22457 + *      the following arguments
22458 + *
22459 + *      argv [0] = vshelper_path;
22460 + *      argv [1] = action: "restart", "halt", "poweroff", ...
22461 + *      argv [2] = context identifier
22462 + *
22463 + *      envp [*] = type-specific parameters
22464 + */
22465 +
22466 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
22467 +{
22468 +       char id_buf[8], cmd_buf[16];
22469 +       char uid_buf[16], pid_buf[16];
22470 +       int ret;
22471 +
22472 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22473 +       char *envp[] = {"HOME=/", "TERM=linux",
22474 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
22475 +                       uid_buf, pid_buf, cmd_buf, 0};
22476 +
22477 +       if (vx_info_state(vxi, VXS_HELPER))
22478 +               return -EAGAIN;
22479 +       vxi->vx_state |= VXS_HELPER;
22480 +
22481 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22482 +
22483 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22484 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
22485 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
22486 +
22487 +       switch (cmd) {
22488 +       case LINUX_REBOOT_CMD_RESTART:
22489 +               argv[1] = "restart";
22490 +               break;
22491 +
22492 +       case LINUX_REBOOT_CMD_HALT:
22493 +               argv[1] = "halt";
22494 +               break;
22495 +
22496 +       case LINUX_REBOOT_CMD_POWER_OFF:
22497 +               argv[1] = "poweroff";
22498 +               break;
22499 +
22500 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
22501 +               argv[1] = "swsusp";
22502 +               break;
22503 +
22504 +       default:
22505 +               vxi->vx_state &= ~VXS_HELPER;
22506 +               return 0;
22507 +       }
22508 +
22509 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
22510 +       vxi->vx_state &= ~VXS_HELPER;
22511 +       __wakeup_vx_info(vxi);
22512 +       return (ret) ? -EPERM : 0;
22513 +}
22514 +
22515 +
22516 +long vs_reboot(unsigned int cmd, void __user *arg)
22517 +{
22518 +       struct vx_info *vxi = current->vx_info;
22519 +       long ret = 0;
22520 +
22521 +       vxdprintk(VXD_CBIT(misc, 5),
22522 +               "vs_reboot(%p[#%d],%d)",
22523 +               vxi, vxi ? vxi->vx_id : 0, cmd);
22524 +
22525 +       ret = vs_reboot_helper(vxi, cmd, arg);
22526 +       if (ret)
22527 +               return ret;
22528 +
22529 +       vxi->reboot_cmd = cmd;
22530 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
22531 +               switch (cmd) {
22532 +               case LINUX_REBOOT_CMD_RESTART:
22533 +               case LINUX_REBOOT_CMD_HALT:
22534 +               case LINUX_REBOOT_CMD_POWER_OFF:
22535 +                       vx_info_kill(vxi, 0, SIGKILL);
22536 +                       vx_info_kill(vxi, 1, SIGKILL);
22537 +               default:
22538 +                       break;
22539 +               }
22540 +       }
22541 +       return 0;
22542 +}
22543 +
22544 +
22545 +/*
22546 + *      argv [0] = vshelper_path;
22547 + *      argv [1] = action: "startup", "shutdown"
22548 + *      argv [2] = context identifier
22549 + *
22550 + *      envp [*] = type-specific parameters
22551 + */
22552 +
22553 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
22554 +{
22555 +       char id_buf[8], cmd_buf[16];
22556 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22557 +       char *envp[] = {"HOME=/", "TERM=linux",
22558 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22559 +
22560 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
22561 +               return 0;
22562 +
22563 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22564 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22565 +
22566 +       switch (cmd) {
22567 +       case VSC_STARTUP:
22568 +               argv[1] = "startup";
22569 +               break;
22570 +       case VSC_SHUTDOWN:
22571 +               argv[1] = "shutdown";
22572 +               break;
22573 +       default:
22574 +               return 0;
22575 +       }
22576 +
22577 +       return do_vshelper(vshelper_path, argv, envp, 1);
22578 +}
22579 +
22580 +
22581 +/*
22582 + *      argv [0] = vshelper_path;
22583 + *      argv [1] = action: "netup", "netdown"
22584 + *      argv [2] = context identifier
22585 + *
22586 + *      envp [*] = type-specific parameters
22587 + */
22588 +
22589 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
22590 +{
22591 +       char id_buf[8], cmd_buf[16];
22592 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22593 +       char *envp[] = {"HOME=/", "TERM=linux",
22594 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22595 +
22596 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
22597 +               return 0;
22598 +
22599 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
22600 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22601 +
22602 +       switch (cmd) {
22603 +       case VSC_NETUP:
22604 +               argv[1] = "netup";
22605 +               break;
22606 +       case VSC_NETDOWN:
22607 +               argv[1] = "netdown";
22608 +               break;
22609 +       default:
22610 +               return 0;
22611 +       }
22612 +
22613 +       return do_vshelper(vshelper_path, argv, envp, 1);
22614 +}
22615 +
22616 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
22617 --- linux-2.6.22.10/kernel/vserver/history.c    1970-01-01 01:00:00 +0100
22618 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/history.c 2007-08-15 22:13:54 +0200
22619 @@ -0,0 +1,258 @@
22620 +/*
22621 + *  kernel/vserver/history.c
22622 + *
22623 + *  Virtual Context History Backtrace
22624 + *
22625 + *  Copyright (C) 2004-2007  Herbert Pötzl
22626 + *
22627 + *  V0.01  basic structure
22628 + *  V0.02  hash/unhash and trace
22629 + *  V0.03  preemption fixes
22630 + *
22631 + */
22632 +
22633 +#include <linux/module.h>
22634 +#include <asm/uaccess.h>
22635 +
22636 +#include <linux/vserver/context.h>
22637 +#include <linux/vserver/debug.h>
22638 +#include <linux/vserver/debug_cmd.h>
22639 +#include <linux/vserver/history.h>
22640 +
22641 +
22642 +#ifdef CONFIG_VSERVER_HISTORY
22643 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
22644 +#else
22645 +#define VXH_SIZE       64
22646 +#endif
22647 +
22648 +struct _vx_history {
22649 +       unsigned int counter;
22650 +
22651 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
22652 +};
22653 +
22654 +
22655 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
22656 +
22657 +unsigned volatile int vxh_active = 1;
22658 +
22659 +static atomic_t sequence = ATOMIC_INIT(0);
22660 +
22661 +
22662 +/*     vxh_advance()
22663 +
22664 +       * requires disabled preemption                          */
22665 +
22666 +struct _vx_hist_entry *vxh_advance(void *loc)
22667 +{
22668 +       unsigned int cpu = smp_processor_id();
22669 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22670 +       struct _vx_hist_entry *entry;
22671 +       unsigned int index;
22672 +
22673 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
22674 +       entry = &hist->entry[index];
22675 +
22676 +       entry->seq = atomic_inc_return(&sequence);
22677 +       entry->loc = loc;
22678 +       return entry;
22679 +}
22680 +
22681 +EXPORT_SYMBOL_GPL(vxh_advance);
22682 +
22683 +
22684 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
22685 +
22686 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
22687 +
22688 +
22689 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
22690 +
22691 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
22692 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
22693 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
22694 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
22695 +
22696 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
22697 +{
22698 +       switch (e->type) {
22699 +       case VXH_THROW_OOPS:
22700 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
22701 +               break;
22702 +
22703 +       case VXH_GET_VX_INFO:
22704 +       case VXH_PUT_VX_INFO:
22705 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22706 +                       VXH_LOC_ARGS(e),
22707 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
22708 +                       VXH_VXI_ARGS(e));
22709 +               break;
22710 +
22711 +       case VXH_INIT_VX_INFO:
22712 +       case VXH_SET_VX_INFO:
22713 +       case VXH_CLR_VX_INFO:
22714 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22715 +                       VXH_LOC_ARGS(e),
22716 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
22717 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
22718 +                       VXH_VXI_ARGS(e), e->sc.data);
22719 +               break;
22720 +
22721 +       case VXH_CLAIM_VX_INFO:
22722 +       case VXH_RELEASE_VX_INFO:
22723 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22724 +                       VXH_LOC_ARGS(e),
22725 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
22726 +                       VXH_VXI_ARGS(e), e->sc.data);
22727 +               break;
22728 +
22729 +       case VXH_ALLOC_VX_INFO:
22730 +       case VXH_DEALLOC_VX_INFO:
22731 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22732 +                       VXH_LOC_ARGS(e),
22733 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
22734 +                       VXH_VXI_ARGS(e));
22735 +               break;
22736 +
22737 +       case VXH_HASH_VX_INFO:
22738 +       case VXH_UNHASH_VX_INFO:
22739 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
22740 +                       VXH_LOC_ARGS(e),
22741 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
22742 +                       VXH_VXI_ARGS(e));
22743 +               break;
22744 +
22745 +       case VXH_LOC_VX_INFO:
22746 +       case VXH_LOOKUP_VX_INFO:
22747 +       case VXH_CREATE_VX_INFO:
22748 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
22749 +                       VXH_LOC_ARGS(e),
22750 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
22751 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
22752 +                       e->ll.arg, VXH_VXI_ARGS(e));
22753 +               break;
22754 +       }
22755 +}
22756 +
22757 +static void __vxh_dump_history(void)
22758 +{
22759 +       unsigned int i, cpu;
22760 +
22761 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
22762 +               atomic_read(&sequence), NR_CPUS);
22763 +
22764 +       for (i = 0; i < VXH_SIZE; i++) {
22765 +               for_each_online_cpu(cpu) {
22766 +                       struct _vx_history *hist =
22767 +                               &per_cpu(vx_history_buffer, cpu);
22768 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
22769 +                       struct _vx_hist_entry *entry = &hist->entry[index];
22770 +
22771 +                       vxh_dump_entry(entry, cpu);
22772 +               }
22773 +       }
22774 +}
22775 +
22776 +void   vxh_dump_history(void)
22777 +{
22778 +       vxh_active = 0;
22779 +#ifdef CONFIG_SMP
22780 +       local_irq_enable();
22781 +       smp_send_stop();
22782 +       local_irq_disable();
22783 +#endif
22784 +       __vxh_dump_history();
22785 +}
22786 +
22787 +
22788 +/* vserver syscall commands below here */
22789 +
22790 +
22791 +int vc_dump_history(uint32_t id)
22792 +{
22793 +       vxh_active = 0;
22794 +       __vxh_dump_history();
22795 +       vxh_active = 1;
22796 +
22797 +       return 0;
22798 +}
22799 +
22800 +
22801 +int do_read_history(struct __user _vx_hist_entry *data,
22802 +       int cpu, uint32_t *index, uint32_t *count)
22803 +{
22804 +       int pos, ret = 0;
22805 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22806 +       int end = hist->counter;
22807 +       int start = end - VXH_SIZE + 2;
22808 +       int idx = *index;
22809 +
22810 +       /* special case: get current pos */
22811 +       if (!*count) {
22812 +               *index = end;
22813 +               return 0;
22814 +       }
22815 +
22816 +       /* have we lost some data? */
22817 +       if (idx < start)
22818 +               idx = start;
22819 +
22820 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22821 +               struct _vx_hist_entry *entry =
22822 +                       &hist->entry[idx % VXH_SIZE];
22823 +
22824 +               /* send entry to userspace */
22825 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22826 +               if (ret)
22827 +                       break;
22828 +       }
22829 +       /* save new index and count */
22830 +       *index = idx;
22831 +       *count = pos;
22832 +       return ret ? ret : (*index < end);
22833 +}
22834 +
22835 +int vc_read_history(uint32_t id, void __user *data)
22836 +{
22837 +       struct vcmd_read_history_v0 vc_data;
22838 +       int ret;
22839 +
22840 +       if (id >= NR_CPUS)
22841 +               return -EINVAL;
22842 +
22843 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22844 +               return -EFAULT;
22845 +
22846 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
22847 +               id, &vc_data.index, &vc_data.count);
22848 +
22849 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22850 +               return -EFAULT;
22851 +       return ret;
22852 +}
22853 +
22854 +#ifdef CONFIG_COMPAT
22855 +
22856 +int vc_read_history_x32(uint32_t id, void __user *data)
22857 +{
22858 +       struct vcmd_read_history_v0_x32 vc_data;
22859 +       int ret;
22860 +
22861 +       if (id >= NR_CPUS)
22862 +               return -EINVAL;
22863 +
22864 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22865 +               return -EFAULT;
22866 +
22867 +       ret = do_read_history((struct __user _vx_hist_entry *)
22868 +               compat_ptr(vc_data.data_ptr),
22869 +               id, &vc_data.index, &vc_data.count);
22870 +
22871 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22872 +               return -EFAULT;
22873 +       return ret;
22874 +}
22875 +
22876 +#endif /* CONFIG_COMPAT */
22877 +
22878 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
22879 --- linux-2.6.22.10/kernel/vserver/inet.c       1970-01-01 01:00:00 +0100
22880 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/inet.c    2007-10-10 23:55:30 +0200
22881 @@ -0,0 +1,222 @@
22882 +
22883 +#include <linux/in.h>
22884 +#include <linux/inetdevice.h>
22885 +#include <linux/vs_inet6.h>
22886 +#include <linux/vserver/debug.h>
22887 +#include <net/route.h>
22888 +#include <net/addrconf.h>
22889 +
22890 +
22891 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22892 +{
22893 +       int ret = 0;
22894 +
22895 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22896 +               ret = 1;
22897 +       else {
22898 +               struct nx_addr_v4 *ptr;
22899 +
22900 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
22901 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22902 +                               ret = 1;
22903 +                               break;
22904 +                       }
22905 +               }
22906 +       }
22907 +
22908 +       vxdprintk(VXD_CBIT(net, 2),
22909 +               "nx_v4_addr_conflict(%p,%p): %d",
22910 +               nxi1, nxi2, ret);
22911 +
22912 +       return ret;
22913 +}
22914 +
22915 +
22916 +#ifdef CONFIG_IPV6
22917 +
22918 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22919 +{
22920 +       int ret = 0;
22921 +
22922 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22923 +               ret = 1;
22924 +       else {
22925 +               struct nx_addr_v6 *ptr;
22926 +
22927 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
22928 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22929 +                               ret = 1;
22930 +                               break;
22931 +                       }
22932 +               }
22933 +       }
22934 +
22935 +       vxdprintk(VXD_CBIT(net, 2),
22936 +               "nx_v6_addr_conflict(%p,%p): %d",
22937 +               nxi1, nxi2, ret);
22938 +
22939 +       return ret;
22940 +}
22941 +
22942 +#endif
22943 +
22944 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22945 +{
22946 +       struct in_device *in_dev;
22947 +       struct in_ifaddr **ifap;
22948 +       struct in_ifaddr *ifa;
22949 +       int ret = 0;
22950 +
22951 +       if (!dev)
22952 +               goto out;
22953 +       in_dev = in_dev_get(dev);
22954 +       if (!in_dev)
22955 +               goto out;
22956 +
22957 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
22958 +               ifap = &ifa->ifa_next) {
22959 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
22960 +                       ret = 1;
22961 +                       break;
22962 +               }
22963 +       }
22964 +       in_dev_put(in_dev);
22965 +out:
22966 +       return ret;
22967 +}
22968 +
22969 +
22970 +#ifdef CONFIG_IPV6
22971 +
22972 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22973 +{
22974 +       struct inet6_dev *in_dev;
22975 +       struct inet6_ifaddr **ifap;
22976 +       struct inet6_ifaddr *ifa;
22977 +       int ret = 0;
22978 +
22979 +       if (!dev)
22980 +               goto out;
22981 +       in_dev = in6_dev_get(dev);
22982 +       if (!in_dev)
22983 +               goto out;
22984 +
22985 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
22986 +               ifap = &ifa->if_next) {
22987 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
22988 +                       ret = 1;
22989 +                       break;
22990 +               }
22991 +       }
22992 +       in6_dev_put(in_dev);
22993 +out:
22994 +       return ret;
22995 +}
22996 +
22997 +#endif
22998 +
22999 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
23000 +{
23001 +       int ret = 1;
23002 +
23003 +       if (!nxi)
23004 +               goto out;
23005 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
23006 +               goto out;
23007 +#ifdef CONFIG_IPV6
23008 +       ret = 2;
23009 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
23010 +               goto out;
23011 +#endif
23012 +       ret = 0;
23013 +out:
23014 +       vxdprintk(VXD_CBIT(net, 3),
23015 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
23016 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
23017 +       return ret;
23018 +}
23019 +
23020 +int ip_v4_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
23021 +{
23022 +       if (!nxi)
23023 +               return 0;
23024 +
23025 +       /* FIXME: handle lback only case */
23026 +       if (!NX_IPV4(nxi))
23027 +               return -EPERM;
23028 +
23029 +       vxdprintk(VXD_CBIT(net, 4),
23030 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
23031 +               nxi, nxi ? nxi->nx_id : 0,
23032 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
23033 +
23034 +       /* single IP is unconditional */
23035 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
23036 +               (fl->fl4_src == INADDR_ANY))
23037 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
23038 +
23039 +       if (fl->fl4_src == INADDR_ANY) {
23040 +               struct nx_addr_v4 *ptr;
23041 +               __be32 found;
23042 +               int err;
23043 +
23044 +               err = __ip_route_output_key(rp, fl);
23045 +               if (!err) {
23046 +                       found = (*rp)->rt_src;
23047 +                       ip_rt_put(*rp);
23048 +                       vxdprintk(VXD_CBIT(net, 4),
23049 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
23050 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
23051 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
23052 +                               goto found;
23053 +               }
23054 +
23055 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
23056 +                       __be32 primary = ptr->ip[0].s_addr;
23057 +                       __be32 mask = ptr->mask.s_addr;
23058 +                       __be32 net = primary & mask;
23059 +
23060 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
23061 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
23062 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
23063 +                               NIPQUAD(mask), NIPQUAD(net));
23064 +                       if ((found & mask) != net)
23065 +                               continue;
23066 +
23067 +                       fl->fl4_src = primary;
23068 +                       err = __ip_route_output_key(rp, fl);
23069 +                       vxdprintk(VXD_CBIT(net, 4),
23070 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
23071 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
23072 +                       if (!err) {
23073 +                               found = (*rp)->rt_src;
23074 +                               ip_rt_put(*rp);
23075 +                               if (found == primary)
23076 +                                       goto found;
23077 +                       }
23078 +               }
23079 +               /* still no source ip? */
23080 +               found = LOOPBACK(fl->fl4_dst)
23081 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
23082 +       found:
23083 +               /* assign src ip to flow */
23084 +               fl->fl4_src = found;
23085 +
23086 +       } else {
23087 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
23088 +                       return -EPERM;
23089 +       }
23090 +
23091 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
23092 +               if (LOOPBACK(fl->fl4_dst))
23093 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
23094 +               if (LOOPBACK(fl->fl4_src))
23095 +                       fl->fl4_src = nxi->v4_lback.s_addr;
23096 +       } else if (LOOPBACK(fl->fl4_dst))
23097 +               return -EPERM;
23098 +
23099 +       return 0;
23100 +}
23101 +
23102 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
23103 +
23104 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
23105 --- linux-2.6.22.10/kernel/vserver/init.c       1970-01-01 01:00:00 +0100
23106 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/init.c    2007-08-15 22:15:36 +0200
23107 @@ -0,0 +1,45 @@
23108 +/*
23109 + *  linux/kernel/init.c
23110 + *
23111 + *  Virtual Server Init
23112 + *
23113 + *  Copyright (C) 2004-2007  Herbert Pötzl
23114 + *
23115 + *  V0.01  basic structure
23116 + *
23117 + */
23118 +
23119 +#include <linux/init.h>
23120 +
23121 +int    vserver_register_sysctl(void);
23122 +void   vserver_unregister_sysctl(void);
23123 +
23124 +
23125 +static int __init init_vserver(void)
23126 +{
23127 +       int ret = 0;
23128 +
23129 +#ifdef CONFIG_VSERVER_DEBUG
23130 +       vserver_register_sysctl();
23131 +#endif
23132 +       return ret;
23133 +}
23134 +
23135 +
23136 +static void __exit exit_vserver(void)
23137 +{
23138 +
23139 +#ifdef CONFIG_VSERVER_DEBUG
23140 +       vserver_unregister_sysctl();
23141 +#endif
23142 +       return;
23143 +}
23144 +
23145 +/* FIXME: GFP_ZONETYPES gone
23146 +long vx_slab[GFP_ZONETYPES]; */
23147 +long vx_area;
23148 +
23149 +
23150 +module_init(init_vserver);
23151 +module_exit(exit_vserver);
23152 +
23153 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
23154 --- linux-2.6.22.10/kernel/vserver/inode.c      1970-01-01 01:00:00 +0100
23155 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/inode.c   2007-09-11 17:57:41 +0200
23156 @@ -0,0 +1,409 @@
23157 +/*
23158 + *  linux/kernel/vserver/inode.c
23159 + *
23160 + *  Virtual Server: File System Support
23161 + *
23162 + *  Copyright (C) 2004-2007  Herbert Pötzl
23163 + *
23164 + *  V0.01  separated from vcontext V0.05
23165 + *  V0.02  moved to tag (instead of xid)
23166 + *
23167 + */
23168 +
23169 +#include <linux/tty.h>
23170 +#include <linux/proc_fs.h>
23171 +#include <linux/devpts_fs.h>
23172 +#include <linux/fs.h>
23173 +#include <linux/file.h>
23174 +#include <linux/mount.h>
23175 +#include <linux/parser.h>
23176 +#include <linux/vserver/inode.h>
23177 +#include <linux/vserver/inode_cmd.h>
23178 +#include <linux/vs_base.h>
23179 +#include <linux/vs_tag.h>
23180 +
23181 +#include <asm/uaccess.h>
23182 +
23183 +
23184 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
23185 +{
23186 +       struct proc_dir_entry *entry;
23187 +
23188 +       if (!in || !in->i_sb)
23189 +               return -ESRCH;
23190 +
23191 +       *flags = IATTR_TAG
23192 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
23193 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
23194 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
23195 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
23196 +
23197 +       if (S_ISDIR(in->i_mode))
23198 +               *mask |= IATTR_BARRIER;
23199 +
23200 +       if (IS_TAGGED(in)) {
23201 +               *tag = in->i_tag;
23202 +               *mask |= IATTR_TAG;
23203 +       }
23204 +
23205 +       switch (in->i_sb->s_magic) {
23206 +       case PROC_SUPER_MAGIC:
23207 +               entry = PROC_I(in)->pde;
23208 +
23209 +               /* check for specific inodes? */
23210 +               if (entry)
23211 +                       *mask |= IATTR_FLAGS;
23212 +               if (entry)
23213 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
23214 +               else
23215 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
23216 +               break;
23217 +
23218 +       case DEVPTS_SUPER_MAGIC:
23219 +               *tag = in->i_tag;
23220 +               *mask |= IATTR_TAG;
23221 +               break;
23222 +
23223 +       default:
23224 +               break;
23225 +       }
23226 +       return 0;
23227 +}
23228 +
23229 +int vc_get_iattr(void __user *data)
23230 +{
23231 +       struct nameidata nd;
23232 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
23233 +       int ret;
23234 +
23235 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23236 +               return -EFAULT;
23237 +
23238 +       ret = user_path_walk_link(vc_data.name, &nd);
23239 +       if (!ret) {
23240 +               ret = __vc_get_iattr(nd.dentry->d_inode,
23241 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23242 +               path_release(&nd);
23243 +       }
23244 +       if (ret)
23245 +               return ret;
23246 +
23247 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23248 +               ret = -EFAULT;
23249 +       return ret;
23250 +}
23251 +
23252 +#ifdef CONFIG_COMPAT
23253 +
23254 +int vc_get_iattr_x32(void __user *data)
23255 +{
23256 +       struct nameidata nd;
23257 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
23258 +       int ret;
23259 +
23260 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23261 +               return -EFAULT;
23262 +
23263 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23264 +       if (!ret) {
23265 +               ret = __vc_get_iattr(nd.dentry->d_inode,
23266 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23267 +               path_release(&nd);
23268 +       }
23269 +       if (ret)
23270 +               return ret;
23271 +
23272 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23273 +               ret = -EFAULT;
23274 +       return ret;
23275 +}
23276 +
23277 +#endif /* CONFIG_COMPAT */
23278 +
23279 +
23280 +int vc_fget_iattr(uint32_t fd, void __user *data)
23281 +{
23282 +       struct file *filp;
23283 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
23284 +       int ret;
23285 +
23286 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23287 +               return -EFAULT;
23288 +
23289 +       filp = fget(fd);
23290 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23291 +               return -EBADF;
23292 +
23293 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
23294 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
23295 +
23296 +       fput(filp);
23297 +
23298 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23299 +               ret = -EFAULT;
23300 +       return ret;
23301 +}
23302 +
23303 +
23304 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
23305 +{
23306 +       struct inode *in = de->d_inode;
23307 +       int error = 0, is_proc = 0, has_tag = 0;
23308 +       struct iattr attr = { 0 };
23309 +
23310 +       if (!in || !in->i_sb)
23311 +               return -ESRCH;
23312 +
23313 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
23314 +       if ((*mask & IATTR_FLAGS) && !is_proc)
23315 +               return -EINVAL;
23316 +
23317 +       has_tag = IS_TAGGED(in) ||
23318 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
23319 +       if ((*mask & IATTR_TAG) && !has_tag)
23320 +               return -EINVAL;
23321 +
23322 +       mutex_lock(&in->i_mutex);
23323 +       if (*mask & IATTR_TAG) {
23324 +               attr.ia_tag = *tag;
23325 +               attr.ia_valid |= ATTR_TAG;
23326 +       }
23327 +
23328 +       if (*mask & IATTR_FLAGS) {
23329 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
23330 +               unsigned int iflags = PROC_I(in)->vx_flags;
23331 +
23332 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
23333 +                       | (*flags & IATTR_FLAGS);
23334 +               PROC_I(in)->vx_flags = iflags;
23335 +               if (entry)
23336 +                       entry->vx_flags = iflags;
23337 +       }
23338 +
23339 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
23340 +               if (*mask & IATTR_IMMUTABLE) {
23341 +                       if (*flags & IATTR_IMMUTABLE)
23342 +                               in->i_flags |= S_IMMUTABLE;
23343 +                       else
23344 +                               in->i_flags &= ~S_IMMUTABLE;
23345 +               }
23346 +               if (*mask & IATTR_IUNLINK) {
23347 +                       if (*flags & IATTR_IUNLINK)
23348 +                               in->i_flags |= S_IUNLINK;
23349 +                       else
23350 +                               in->i_flags &= ~S_IUNLINK;
23351 +               }
23352 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
23353 +                       if (*flags & IATTR_BARRIER)
23354 +                               in->i_flags |= S_BARRIER;
23355 +                       else
23356 +                               in->i_flags &= ~S_BARRIER;
23357 +               }
23358 +               if (in->i_op && in->i_op->sync_flags) {
23359 +                       error = in->i_op->sync_flags(in);
23360 +                       if (error)
23361 +                               goto out;
23362 +               }
23363 +       }
23364 +
23365 +       if (attr.ia_valid) {
23366 +               if (in->i_op && in->i_op->setattr)
23367 +                       error = in->i_op->setattr(de, &attr);
23368 +               else {
23369 +                       error = inode_change_ok(in, &attr);
23370 +                       if (!error)
23371 +                               error = inode_setattr(in, &attr);
23372 +               }
23373 +       }
23374 +
23375 +out:
23376 +       mutex_unlock(&in->i_mutex);
23377 +       return error;
23378 +}
23379 +
23380 +int vc_set_iattr(void __user *data)
23381 +{
23382 +       struct nameidata nd;
23383 +       struct vcmd_ctx_iattr_v1 vc_data;
23384 +       int ret;
23385 +
23386 +       if (!capable(CAP_LINUX_IMMUTABLE))
23387 +               return -EPERM;
23388 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23389 +               return -EFAULT;
23390 +
23391 +       ret = user_path_walk_link(vc_data.name, &nd);
23392 +       if (!ret) {
23393 +               ret = __vc_set_iattr(nd.dentry,
23394 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23395 +               path_release(&nd);
23396 +       }
23397 +
23398 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23399 +               ret = -EFAULT;
23400 +       return ret;
23401 +}
23402 +
23403 +#ifdef CONFIG_COMPAT
23404 +
23405 +int vc_set_iattr_x32(void __user *data)
23406 +{
23407 +       struct nameidata nd;
23408 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
23409 +       int ret;
23410 +
23411 +       if (!capable(CAP_LINUX_IMMUTABLE))
23412 +               return -EPERM;
23413 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23414 +               return -EFAULT;
23415 +
23416 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23417 +       if (!ret) {
23418 +               ret = __vc_set_iattr(nd.dentry,
23419 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23420 +               path_release(&nd);
23421 +       }
23422 +
23423 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23424 +               ret = -EFAULT;
23425 +       return ret;
23426 +}
23427 +
23428 +#endif /* CONFIG_COMPAT */
23429 +
23430 +int vc_fset_iattr(uint32_t fd, void __user *data)
23431 +{
23432 +       struct file *filp;
23433 +       struct vcmd_ctx_fiattr_v0 vc_data;
23434 +       int ret;
23435 +
23436 +       if (!capable(CAP_LINUX_IMMUTABLE))
23437 +               return -EPERM;
23438 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23439 +               return -EFAULT;
23440 +
23441 +       filp = fget(fd);
23442 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23443 +               return -EBADF;
23444 +
23445 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
23446 +               &vc_data.flags, &vc_data.mask);
23447 +
23448 +       fput(filp);
23449 +
23450 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23451 +               return -EFAULT;
23452 +       return ret;
23453 +}
23454 +
23455 +
23456 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
23457 +
23458 +static match_table_t tokens = {
23459 +       {Opt_notagcheck, "notagcheck"},
23460 +#ifdef CONFIG_PROPAGATE
23461 +       {Opt_notag, "notag"},
23462 +       {Opt_tag, "tag"},
23463 +       {Opt_tagid, "tagid=%u"},
23464 +#endif
23465 +       {Opt_err, NULL}
23466 +};
23467 +
23468 +
23469 +static void __dx_parse_remove(char *string, char *opt)
23470 +{
23471 +       char *p = strstr(string, opt);
23472 +       char *q = p;
23473 +
23474 +       if (p) {
23475 +               while (*q != '\0' && *q != ',')
23476 +                       q++;
23477 +               while (*q)
23478 +                       *p++ = *q++;
23479 +               while (*p)
23480 +                       *p++ = '\0';
23481 +       }
23482 +}
23483 +
23484 +static inline
23485 +int __dx_parse_tag(char *string, tag_t *tag, int remove)
23486 +{
23487 +       substring_t args[MAX_OPT_ARGS];
23488 +       int token, option = 0;
23489 +
23490 +       if (!string)
23491 +               return 0;
23492 +
23493 +       token = match_token(string, tokens, args);
23494 +
23495 +       vxdprintk(VXD_CBIT(tag, 7),
23496 +               "dx_parse_tag(»%s«): %d:#%d",
23497 +               string, token, option);
23498 +
23499 +       switch (token) {
23500 +       case Opt_tag:
23501 +               if (tag)
23502 +                       *tag = 0;
23503 +               if (remove)
23504 +                       __dx_parse_remove(string, "tag");
23505 +               return MNT_TAGID;
23506 +       case Opt_notag:
23507 +               if (remove)
23508 +                       __dx_parse_remove(string, "notag");
23509 +               return MNT_NOTAG;
23510 +       case Opt_notagcheck:
23511 +               if (remove)
23512 +                       __dx_parse_remove(string, "notagcheck");
23513 +               return MNT_NOTAGCHECK;
23514 +       case Opt_tagid:
23515 +               if (tag && !match_int(args, &option))
23516 +                       *tag = option;
23517 +               if (remove)
23518 +                       __dx_parse_remove(string, "tagid");
23519 +               return MNT_TAGID;
23520 +       }
23521 +       return 0;
23522 +}
23523 +
23524 +int dx_parse_tag(char *string, tag_t *tag, int remove)
23525 +{
23526 +       int retval, flags = 0;
23527 +
23528 +       while ((retval = __dx_parse_tag(string, tag, remove)))
23529 +               flags |= retval;
23530 +       return flags;
23531 +}
23532 +
23533 +#ifdef CONFIG_PROPAGATE
23534 +
23535 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
23536 +{
23537 +       tag_t new_tag = 0;
23538 +       struct vfsmount *mnt;
23539 +       int propagate;
23540 +
23541 +       if (!nd)
23542 +               return;
23543 +       mnt = nd->mnt;
23544 +       if (!mnt)
23545 +               return;
23546 +
23547 +       propagate = (mnt->mnt_flags & MNT_TAGID);
23548 +       if (propagate)
23549 +               new_tag = mnt->mnt_tag;
23550 +
23551 +       vxdprintk(VXD_CBIT(tag, 7),
23552 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
23553 +               inode, inode->i_ino, inode->i_tag,
23554 +               new_tag, (propagate) ? 1 : 0);
23555 +
23556 +       if (propagate)
23557 +               inode->i_tag = new_tag;
23558 +}
23559 +
23560 +#include <linux/module.h>
23561 +
23562 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
23563 +
23564 +#endif /* CONFIG_PROPAGATE */
23565 +
23566 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
23567 --- linux-2.6.22.10/kernel/vserver/limit.c      1970-01-01 01:00:00 +0100
23568 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit.c   2007-08-19 00:08:19 +0200
23569 @@ -0,0 +1,318 @@
23570 +/*
23571 + *  linux/kernel/vserver/limit.c
23572 + *
23573 + *  Virtual Server: Context Limits
23574 + *
23575 + *  Copyright (C) 2004-2007  Herbert Pötzl
23576 + *
23577 + *  V0.01  broken out from vcontext V0.05
23578 + *  V0.02  changed vcmds to vxi arg
23579 + *
23580 + */
23581 +
23582 +#include <linux/module.h>
23583 +#include <linux/vs_limit.h>
23584 +#include <linux/vserver/limit.h>
23585 +#include <linux/vserver/limit_cmd.h>
23586 +
23587 +#include <asm/uaccess.h>
23588 +
23589 +
23590 +const char *vlimit_name[NUM_LIMITS] = {
23591 +       [RLIMIT_CPU]            = "CPU",
23592 +       [RLIMIT_RSS]            = "RSS",
23593 +       [RLIMIT_NPROC]          = "NPROC",
23594 +       [RLIMIT_NOFILE]         = "NOFILE",
23595 +       [RLIMIT_MEMLOCK]        = "VML",
23596 +       [RLIMIT_AS]             = "VM",
23597 +       [RLIMIT_LOCKS]          = "LOCKS",
23598 +       [RLIMIT_SIGPENDING]     = "SIGP",
23599 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
23600 +
23601 +       [VLIMIT_NSOCK]          = "NSOCK",
23602 +       [VLIMIT_OPENFD]         = "OPENFD",
23603 +       [VLIMIT_ANON]           = "ANON",
23604 +       [VLIMIT_SHMEM]          = "SHMEM",
23605 +       [VLIMIT_DENTRY]         = "DENTRY",
23606 +};
23607 +
23608 +EXPORT_SYMBOL_GPL(vlimit_name);
23609 +
23610 +#define MASK_ENTRY(x)  (1 << (x))
23611 +
23612 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
23613 +               /* minimum */
23614 +       0
23615 +       ,       /* softlimit */
23616 +       MASK_ENTRY( RLIMIT_RSS          ) |
23617 +       MASK_ENTRY( VLIMIT_ANON         ) |
23618 +       0
23619 +       ,       /* maximum */
23620 +       MASK_ENTRY( RLIMIT_RSS          ) |
23621 +       MASK_ENTRY( RLIMIT_NPROC        ) |
23622 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
23623 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
23624 +       MASK_ENTRY( RLIMIT_AS           ) |
23625 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
23626 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
23627 +
23628 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
23629 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
23630 +       MASK_ENTRY( VLIMIT_ANON         ) |
23631 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
23632 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
23633 +       0
23634 +};
23635 +               /* accounting only */
23636 +uint32_t account_mask =
23637 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
23638 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
23639 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
23640 +       0;
23641 +
23642 +
23643 +static int is_valid_vlimit(int id)
23644 +{
23645 +       uint32_t mask = vlimit_mask.minimum |
23646 +               vlimit_mask.softlimit | vlimit_mask.maximum;
23647 +       return mask & (1 << id);
23648 +}
23649 +
23650 +static int is_accounted_vlimit(int id)
23651 +{
23652 +       if (is_valid_vlimit(id))
23653 +               return 1;
23654 +       return account_mask & (1 << id);
23655 +}
23656 +
23657 +
23658 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
23659 +{
23660 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
23661 +       return VX_VLIM(limit);
23662 +}
23663 +
23664 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
23665 +{
23666 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
23667 +       return VX_VLIM(limit);
23668 +}
23669 +
23670 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
23671 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
23672 +{
23673 +       if (!is_valid_vlimit(id))
23674 +               return -EINVAL;
23675 +
23676 +       if (minimum)
23677 +               *minimum = CRLIM_UNSET;
23678 +       if (softlimit)
23679 +               *softlimit = vc_get_soft(vxi, id);
23680 +       if (maximum)
23681 +               *maximum = vc_get_hard(vxi, id);
23682 +       return 0;
23683 +}
23684 +
23685 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
23686 +{
23687 +       struct vcmd_ctx_rlimit_v0 vc_data;
23688 +       int ret;
23689 +
23690 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23691 +               return -EFAULT;
23692 +
23693 +       ret = do_get_rlimit(vxi, vc_data.id,
23694 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23695 +       if (ret)
23696 +               return ret;
23697 +
23698 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23699 +               return -EFAULT;
23700 +       return 0;
23701 +}
23702 +
23703 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
23704 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
23705 +{
23706 +       if (!is_valid_vlimit(id))
23707 +               return -EINVAL;
23708 +
23709 +       if (maximum != CRLIM_KEEP)
23710 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
23711 +       if (softlimit != CRLIM_KEEP)
23712 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
23713 +
23714 +       /* clamp soft limit */
23715 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
23716 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
23717 +
23718 +       return 0;
23719 +}
23720 +
23721 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
23722 +{
23723 +       struct vcmd_ctx_rlimit_v0 vc_data;
23724 +
23725 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23726 +               return -EFAULT;
23727 +
23728 +       return do_set_rlimit(vxi, vc_data.id,
23729 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23730 +}
23731 +
23732 +#ifdef CONFIG_IA32_EMULATION
23733 +
23734 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
23735 +{
23736 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23737 +
23738 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23739 +               return -EFAULT;
23740 +
23741 +       return do_set_rlimit(vxi, vc_data.id,
23742 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23743 +}
23744 +
23745 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
23746 +{
23747 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23748 +       int ret;
23749 +
23750 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23751 +               return -EFAULT;
23752 +
23753 +       ret = do_get_rlimit(vxi, vc_data.id,
23754 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23755 +       if (ret)
23756 +               return ret;
23757 +
23758 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23759 +               return -EFAULT;
23760 +       return 0;
23761 +}
23762 +
23763 +#endif /* CONFIG_IA32_EMULATION */
23764 +
23765 +
23766 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
23767 +{
23768 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
23769 +               return -EFAULT;
23770 +       return 0;
23771 +}
23772 +
23773 +
23774 +static inline void vx_reset_minmax(struct _vx_limit *limit)
23775 +{
23776 +       rlim_t value;
23777 +       int lim;
23778 +
23779 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23780 +               value = __rlim_get(limit, lim);
23781 +               __rlim_rmax(limit, lim) = value;
23782 +               __rlim_rmin(limit, lim) = value;
23783 +       }
23784 +}
23785 +
23786 +
23787 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
23788 +{
23789 +       vx_reset_minmax(&vxi->limit);
23790 +       return 0;
23791 +}
23792 +
23793 +
23794 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
23795 +{
23796 +       struct vcmd_rlimit_stat_v0 vc_data;
23797 +       struct _vx_limit *limit = &vxi->limit;
23798 +       int id;
23799 +
23800 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23801 +               return -EFAULT;
23802 +
23803 +       id = vc_data.id;
23804 +       if (!is_accounted_vlimit(id))
23805 +               return -EINVAL;
23806 +
23807 +       vx_limit_fixup(limit, id);
23808 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
23809 +       vc_data.value = __rlim_get(limit, id);
23810 +       vc_data.minimum = __rlim_rmin(limit, id);
23811 +       vc_data.maximum = __rlim_rmax(limit, id);
23812 +
23813 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23814 +               return -EFAULT;
23815 +       return 0;
23816 +}
23817 +
23818 +
23819 +void vx_vsi_meminfo(struct sysinfo *val)
23820 +{
23821 +       struct vx_info *vxi = current->vx_info;
23822 +       unsigned long totalram, freeram;
23823 +       rlim_t v;
23824 +
23825 +       /* we blindly accept the max */
23826 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23827 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
23828 +
23829 +       /* total minus used equals free */
23830 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23831 +       freeram = (v < totalram) ? totalram - v : 0;
23832 +
23833 +       val->totalram = totalram;
23834 +       val->freeram = freeram;
23835 +       val->bufferram = 0;
23836 +       val->totalhigh = 0;
23837 +       val->freehigh = 0;
23838 +       return;
23839 +}
23840 +
23841 +void vx_vsi_swapinfo(struct sysinfo *val)
23842 +{
23843 +       struct vx_info *vxi = current->vx_info;
23844 +       unsigned long totalswap, freeswap;
23845 +       rlim_t v, w;
23846 +
23847 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23848 +       if (v == RLIM_INFINITY) {
23849 +               val->freeswap = val->totalswap;
23850 +               return;
23851 +       }
23852 +
23853 +       /* we blindly accept the max */
23854 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
23855 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
23856 +
23857 +       /* currently 'used' swap */
23858 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23859 +       w -= (w > v) ? v : w;
23860 +
23861 +       /* total minus used equals free */
23862 +       freeswap = (w < totalswap) ? totalswap - w : 0;
23863 +
23864 +       val->totalswap = totalswap;
23865 +       val->freeswap = freeswap;
23866 +       return;
23867 +}
23868 +
23869 +
23870 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
23871 +{
23872 +       struct vx_info *vxi = mm->mm_vx_info;
23873 +       unsigned long points;
23874 +       rlim_t v, w;
23875 +
23876 +       if (!vxi)
23877 +               return 0;
23878 +
23879 +       points = vxi->vx_badness_bias;
23880 +
23881 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23882 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23883 +       points += (v > w) ? (v - w) : 0;
23884 +
23885 +       return points;
23886 +}
23887 +
23888 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
23889 --- linux-2.6.22.10/kernel/vserver/limit_init.h 1970-01-01 01:00:00 +0100
23890 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit_init.h      2007-10-25 17:05:55 +0200
23891 @@ -0,0 +1,33 @@
23892 +
23893 +
23894 +static inline void vx_info_init_limit(struct _vx_limit *limit)
23895 +{
23896 +       int lim;
23897 +
23898 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23899 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
23900 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
23901 +               __rlim_set(limit, lim, 0);
23902 +               atomic_set(&__rlim_lhit(limit, lim), 0);
23903 +               __rlim_rmin(limit, lim) = 0;
23904 +               __rlim_rmax(limit, lim) = 0;
23905 +       }
23906 +}
23907 +
23908 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
23909 +{
23910 +#ifdef CONFIG_VSERVER_WARN
23911 +       rlim_t value;
23912 +       int lim;
23913 +
23914 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23915 +               if ((1 << lim) & VLIM_NOCHECK)
23916 +                       continue;
23917 +               value = __rlim_get(limit, lim);
23918 +               vxwprintk_xid(value,
23919 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
23920 +                       limit, vlimit_name[lim], lim, (long)value);
23921 +       }
23922 +#endif
23923 +}
23924 +
23925 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
23926 --- linux-2.6.22.10/kernel/vserver/limit_proc.h 1970-01-01 01:00:00 +0100
23927 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit_proc.h      2007-08-05 20:53:13 +0200
23928 @@ -0,0 +1,57 @@
23929 +#ifndef _VX_LIMIT_PROC_H
23930 +#define _VX_LIMIT_PROC_H
23931 +
23932 +#include <linux/vserver/limit_int.h>
23933 +
23934 +
23935 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
23936 +#define VX_LIMIT_TOP   \
23937 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
23938 +
23939 +#define VX_LIMIT_ARG(r)                                \
23940 +       (unsigned long)__rlim_get(limit, r),    \
23941 +       (unsigned long)__rlim_rmin(limit, r),   \
23942 +       (unsigned long)__rlim_rmax(limit, r),   \
23943 +       VX_VLIM(__rlim_soft(limit, r)),         \
23944 +       VX_VLIM(__rlim_hard(limit, r)),         \
23945 +       atomic_read(&__rlim_lhit(limit, r))
23946 +
23947 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
23948 +{
23949 +       vx_limit_fixup(limit, -1);
23950 +       return sprintf(buffer, VX_LIMIT_TOP
23951 +               "PROC"  VX_LIMIT_FMT
23952 +               "VM"    VX_LIMIT_FMT
23953 +               "VML"   VX_LIMIT_FMT
23954 +               "RSS"   VX_LIMIT_FMT
23955 +               "ANON"  VX_LIMIT_FMT
23956 +               "RMAP"  VX_LIMIT_FMT
23957 +               "FILES" VX_LIMIT_FMT
23958 +               "OFD"   VX_LIMIT_FMT
23959 +               "LOCKS" VX_LIMIT_FMT
23960 +               "SOCK"  VX_LIMIT_FMT
23961 +               "MSGQ"  VX_LIMIT_FMT
23962 +               "SHM"   VX_LIMIT_FMT
23963 +               "SEMA"  VX_LIMIT_FMT
23964 +               "SEMS"  VX_LIMIT_FMT
23965 +               "DENT"  VX_LIMIT_FMT,
23966 +               VX_LIMIT_ARG(RLIMIT_NPROC),
23967 +               VX_LIMIT_ARG(RLIMIT_AS),
23968 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
23969 +               VX_LIMIT_ARG(RLIMIT_RSS),
23970 +               VX_LIMIT_ARG(VLIMIT_ANON),
23971 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
23972 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
23973 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
23974 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
23975 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
23976 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
23977 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
23978 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
23979 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
23980 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
23981 +}
23982 +
23983 +#endif /* _VX_LIMIT_PROC_H */
23984 +
23985 +
23986 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
23987 --- linux-2.6.22.10/kernel/vserver/monitor.c    1970-01-01 01:00:00 +0100
23988 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/monitor.c 2007-08-15 23:18:20 +0200
23989 @@ -0,0 +1,138 @@
23990 +/*
23991 + *  kernel/vserver/monitor.c
23992 + *
23993 + *  Virtual Context Scheduler Monitor
23994 + *
23995 + *  Copyright (C) 2006-2007 Herbert Pötzl
23996 + *
23997 + *  V0.01  basic design
23998 + *
23999 + */
24000 +
24001 +#include <linux/module.h>
24002 +#include <linux/jiffies.h>
24003 +#include <asm/uaccess.h>
24004 +#include <asm/atomic.h>
24005 +
24006 +#include <linux/vserver/monitor.h>
24007 +#include <linux/vserver/debug_cmd.h>
24008 +
24009 +
24010 +#ifdef CONFIG_VSERVER_MONITOR
24011 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
24012 +#else
24013 +#define VXM_SIZE       64
24014 +#endif
24015 +
24016 +struct _vx_monitor {
24017 +       unsigned int counter;
24018 +
24019 +       struct _vx_mon_entry entry[VXM_SIZE+1];
24020 +};
24021 +
24022 +
24023 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
24024 +
24025 +unsigned volatile int vxm_active = 1;
24026 +
24027 +static atomic_t sequence = ATOMIC_INIT(0);
24028 +
24029 +
24030 +/*     vxm_advance()
24031 +
24032 +       * requires disabled preemption                          */
24033 +
24034 +struct _vx_mon_entry *vxm_advance(int cpu)
24035 +{
24036 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24037 +       struct _vx_mon_entry *entry;
24038 +       unsigned int index;
24039 +
24040 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
24041 +       entry = &mon->entry[index];
24042 +
24043 +       entry->ev.seq = atomic_inc_return(&sequence);
24044 +       entry->ev.jif = jiffies;
24045 +       return entry;
24046 +}
24047 +
24048 +EXPORT_SYMBOL_GPL(vxm_advance);
24049 +
24050 +
24051 +int do_read_monitor(struct __user _vx_mon_entry *data,
24052 +       int cpu, uint32_t *index, uint32_t *count)
24053 +{
24054 +       int pos, ret = 0;
24055 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24056 +       int end = mon->counter;
24057 +       int start = end - VXM_SIZE + 2;
24058 +       int idx = *index;
24059 +
24060 +       /* special case: get current pos */
24061 +       if (!*count) {
24062 +               *index = end;
24063 +               return 0;
24064 +       }
24065 +
24066 +       /* have we lost some data? */
24067 +       if (idx < start)
24068 +               idx = start;
24069 +
24070 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
24071 +               struct _vx_mon_entry *entry =
24072 +                       &mon->entry[idx % VXM_SIZE];
24073 +
24074 +               /* send entry to userspace */
24075 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
24076 +               if (ret)
24077 +                       break;
24078 +       }
24079 +       /* save new index and count */
24080 +       *index = idx;
24081 +       *count = pos;
24082 +       return ret ? ret : (*index < end);
24083 +}
24084 +
24085 +int vc_read_monitor(uint32_t id, void __user *data)
24086 +{
24087 +       struct vcmd_read_monitor_v0 vc_data;
24088 +       int ret;
24089 +
24090 +       if (id >= NR_CPUS)
24091 +               return -EINVAL;
24092 +
24093 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24094 +               return -EFAULT;
24095 +
24096 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
24097 +               id, &vc_data.index, &vc_data.count);
24098 +
24099 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24100 +               return -EFAULT;
24101 +       return ret;
24102 +}
24103 +
24104 +#ifdef CONFIG_COMPAT
24105 +
24106 +int vc_read_monitor_x32(uint32_t id, void __user *data)
24107 +{
24108 +       struct vcmd_read_monitor_v0_x32 vc_data;
24109 +       int ret;
24110 +
24111 +       if (id >= NR_CPUS)
24112 +               return -EINVAL;
24113 +
24114 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24115 +               return -EFAULT;
24116 +
24117 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
24118 +               compat_ptr(vc_data.data_ptr),
24119 +               id, &vc_data.index, &vc_data.count);
24120 +
24121 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24122 +               return -EFAULT;
24123 +       return ret;
24124 +}
24125 +
24126 +#endif /* CONFIG_COMPAT */
24127 +
24128 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
24129 --- linux-2.6.22.10/kernel/vserver/network.c    1970-01-01 01:00:00 +0100
24130 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/network.c 2007-10-05 14:54:36 +0200
24131 @@ -0,0 +1,862 @@
24132 +/*
24133 + *  linux/kernel/vserver/network.c
24134 + *
24135 + *  Virtual Server: Network Support
24136 + *
24137 + *  Copyright (C) 2003-2007  Herbert Pötzl
24138 + *
24139 + *  V0.01  broken out from vcontext V0.05
24140 + *  V0.02  cleaned up implementation
24141 + *  V0.03  added equiv nx commands
24142 + *  V0.04  switch to RCU based hash
24143 + *  V0.05  and back to locking again
24144 + *  V0.06  changed vcmds to nxi arg
24145 + *  V0.07  have __create claim() the nxi
24146 + *
24147 + */
24148 +
24149 +#include <linux/err.h>
24150 +#include <linux/slab.h>
24151 +#include <linux/rcupdate.h>
24152 +
24153 +#include <linux/vs_network.h>
24154 +#include <linux/vserver/network_cmd.h>
24155 +
24156 +
24157 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
24158 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
24159 +
24160 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
24161 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
24162 +
24163 +
24164 +static int __init init_network(void)
24165 +{
24166 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
24167 +               sizeof(struct nx_addr_v4), 0, SLAB_PANIC, NULL, NULL);
24168 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
24169 +               sizeof(struct nx_addr_v6), 0, SLAB_PANIC, NULL, NULL);
24170 +       return 0;
24171 +}
24172 +
24173 +
24174 +/*     __alloc_nx_addr_v4()                                    */
24175 +
24176 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
24177 +{
24178 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
24179 +               nx_addr_v4_cachep, GFP_KERNEL);
24180 +
24181 +       if (!IS_ERR(nxa))
24182 +               memset(nxa, 0, sizeof(*nxa));
24183 +       return nxa;
24184 +}
24185 +
24186 +/*     __dealloc_nx_addr_v4()                                  */
24187 +
24188 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
24189 +{
24190 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
24191 +}
24192 +
24193 +/*     __dealloc_nx_addr_v4_all()                              */
24194 +
24195 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
24196 +{
24197 +       while (nxa) {
24198 +               struct nx_addr_v4 *next = nxa->next;
24199 +
24200 +               __dealloc_nx_addr_v4(nxa);
24201 +               nxa = next;
24202 +       }
24203 +}
24204 +
24205 +
24206 +#ifdef CONFIG_IPV6
24207 +
24208 +/*     __alloc_nx_addr_v6()                                    */
24209 +
24210 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
24211 +{
24212 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
24213 +               nx_addr_v6_cachep, GFP_KERNEL);
24214 +
24215 +       if (!IS_ERR(nxa))
24216 +               memset(nxa, 0, sizeof(*nxa));
24217 +       return nxa;
24218 +}
24219 +
24220 +/*     __dealloc_nx_addr_v6()                                  */
24221 +
24222 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
24223 +{
24224 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
24225 +}
24226 +
24227 +/*     __dealloc_nx_addr_v6_all()                              */
24228 +
24229 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
24230 +{
24231 +       while (nxa) {
24232 +               struct nx_addr_v6 *next = nxa->next;
24233 +
24234 +               __dealloc_nx_addr_v6(nxa);
24235 +               nxa = next;
24236 +       }
24237 +}
24238 +
24239 +#endif /* CONFIG_IPV6 */
24240 +
24241 +
24242 +/*     __alloc_nx_info()
24243 +
24244 +       * allocate an initialized nx_info struct
24245 +       * doesn't make it visible (hash)                        */
24246 +
24247 +static struct nx_info *__alloc_nx_info(nid_t nid)
24248 +{
24249 +       struct nx_info *new = NULL;
24250 +
24251 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
24252 +
24253 +       /* would this benefit from a slab cache? */
24254 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
24255 +       if (!new)
24256 +               return 0;
24257 +
24258 +       memset(new, 0, sizeof(struct nx_info));
24259 +       new->nx_id = nid;
24260 +       INIT_HLIST_NODE(&new->nx_hlist);
24261 +       atomic_set(&new->nx_usecnt, 0);
24262 +       atomic_set(&new->nx_tasks, 0);
24263 +       new->nx_state = 0;
24264 +
24265 +       new->nx_flags = NXF_INIT_SET;
24266 +
24267 +       /* rest of init goes here */
24268 +
24269 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
24270 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
24271 +
24272 +       vxdprintk(VXD_CBIT(nid, 0),
24273 +               "alloc_nx_info(%d) = %p", nid, new);
24274 +       atomic_inc(&nx_global_ctotal);
24275 +       return new;
24276 +}
24277 +
24278 +/*     __dealloc_nx_info()
24279 +
24280 +       * final disposal of nx_info                             */
24281 +
24282 +static void __dealloc_nx_info(struct nx_info *nxi)
24283 +{
24284 +       vxdprintk(VXD_CBIT(nid, 0),
24285 +               "dealloc_nx_info(%p)", nxi);
24286 +
24287 +       nxi->nx_hlist.next = LIST_POISON1;
24288 +       nxi->nx_id = -1;
24289 +
24290 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24291 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24292 +
24293 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
24294 +
24295 +       nxi->nx_state |= NXS_RELEASED;
24296 +       kfree(nxi);
24297 +       atomic_dec(&nx_global_ctotal);
24298 +}
24299 +
24300 +static void __shutdown_nx_info(struct nx_info *nxi)
24301 +{
24302 +       nxi->nx_state |= NXS_SHUTDOWN;
24303 +       vs_net_change(nxi, VSC_NETDOWN);
24304 +}
24305 +
24306 +/*     exported stuff                                          */
24307 +
24308 +void free_nx_info(struct nx_info *nxi)
24309 +{
24310 +       /* context shutdown is mandatory */
24311 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
24312 +
24313 +       /* context must not be hashed */
24314 +       BUG_ON(nxi->nx_state & NXS_HASHED);
24315 +
24316 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24317 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24318 +
24319 +       __dealloc_nx_info(nxi);
24320 +}
24321 +
24322 +
24323 +void __nx_set_lback(struct nx_info *nxi)
24324 +{
24325 +       int nid = nxi->nx_id;
24326 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
24327 +
24328 +       nxi->v4_lback.s_addr = lback;
24329 +}
24330 +
24331 +extern int __nx_inet_add_lback(__be32 addr);
24332 +extern int __nx_inet_del_lback(__be32 addr);
24333 +
24334 +
24335 +/*     hash table for nx_info hash */
24336 +
24337 +#define NX_HASH_SIZE   13
24338 +
24339 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
24340 +
24341 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
24342 +
24343 +
24344 +static inline unsigned int __hashval(nid_t nid)
24345 +{
24346 +       return (nid % NX_HASH_SIZE);
24347 +}
24348 +
24349 +
24350 +
24351 +/*     __hash_nx_info()
24352 +
24353 +       * add the nxi to the global hash table
24354 +       * requires the hash_lock to be held                     */
24355 +
24356 +static inline void __hash_nx_info(struct nx_info *nxi)
24357 +{
24358 +       struct hlist_head *head;
24359 +
24360 +       vxd_assert_lock(&nx_info_hash_lock);
24361 +       vxdprintk(VXD_CBIT(nid, 4),
24362 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
24363 +
24364 +       /* context must not be hashed */
24365 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
24366 +
24367 +       nxi->nx_state |= NXS_HASHED;
24368 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
24369 +       hlist_add_head(&nxi->nx_hlist, head);
24370 +       atomic_inc(&nx_global_cactive);
24371 +}
24372 +
24373 +/*     __unhash_nx_info()
24374 +
24375 +       * remove the nxi from the global hash table
24376 +       * requires the hash_lock to be held                     */
24377 +
24378 +static inline void __unhash_nx_info(struct nx_info *nxi)
24379 +{
24380 +       vxd_assert_lock(&nx_info_hash_lock);
24381 +       vxdprintk(VXD_CBIT(nid, 4),
24382 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
24383 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
24384 +
24385 +       /* context must be hashed */
24386 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
24387 +       /* but without tasks */
24388 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24389 +
24390 +       nxi->nx_state &= ~NXS_HASHED;
24391 +       hlist_del(&nxi->nx_hlist);
24392 +       atomic_dec(&nx_global_cactive);
24393 +}
24394 +
24395 +
24396 +/*     __lookup_nx_info()
24397 +
24398 +       * requires the hash_lock to be held
24399 +       * doesn't increment the nx_refcnt                       */
24400 +
24401 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
24402 +{
24403 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
24404 +       struct hlist_node *pos;
24405 +       struct nx_info *nxi;
24406 +
24407 +       vxd_assert_lock(&nx_info_hash_lock);
24408 +       hlist_for_each(pos, head) {
24409 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24410 +
24411 +               if (nxi->nx_id == nid)
24412 +                       goto found;
24413 +       }
24414 +       nxi = NULL;
24415 +found:
24416 +       vxdprintk(VXD_CBIT(nid, 0),
24417 +               "__lookup_nx_info(#%u): %p[#%u]",
24418 +               nid, nxi, nxi ? nxi->nx_id : 0);
24419 +       return nxi;
24420 +}
24421 +
24422 +
24423 +/*     __create_nx_info()
24424 +
24425 +       * create the requested context
24426 +       * get(), claim() and hash it                            */
24427 +
24428 +static struct nx_info *__create_nx_info(int id)
24429 +{
24430 +       struct nx_info *new, *nxi = NULL;
24431 +
24432 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
24433 +
24434 +       if (!(new = __alloc_nx_info(id)))
24435 +               return ERR_PTR(-ENOMEM);
24436 +
24437 +       /* required to make dynamic xids unique */
24438 +       spin_lock(&nx_info_hash_lock);
24439 +
24440 +       /* static context requested */
24441 +       if ((nxi = __lookup_nx_info(id))) {
24442 +               vxdprintk(VXD_CBIT(nid, 0),
24443 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
24444 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24445 +                       nxi = ERR_PTR(-EBUSY);
24446 +               else
24447 +                       nxi = ERR_PTR(-EEXIST);
24448 +               goto out_unlock;
24449 +       }
24450 +       /* new context */
24451 +       vxdprintk(VXD_CBIT(nid, 0),
24452 +               "create_nx_info(%d) = %p (new)", id, new);
24453 +       claim_nx_info(new, NULL);
24454 +       __nx_set_lback(new);
24455 +       __hash_nx_info(get_nx_info(new));
24456 +       nxi = new, new = NULL;
24457 +
24458 +out_unlock:
24459 +       spin_unlock(&nx_info_hash_lock);
24460 +       if (new)
24461 +               __dealloc_nx_info(new);
24462 +       return nxi;
24463 +}
24464 +
24465 +
24466 +
24467 +/*     exported stuff                                          */
24468 +
24469 +
24470 +void unhash_nx_info(struct nx_info *nxi)
24471 +{
24472 +       __shutdown_nx_info(nxi);
24473 +       spin_lock(&nx_info_hash_lock);
24474 +       __unhash_nx_info(nxi);
24475 +       spin_unlock(&nx_info_hash_lock);
24476 +}
24477 +
24478 +/*     lookup_nx_info()
24479 +
24480 +       * search for a nx_info and get() it
24481 +       * negative id means current                             */
24482 +
24483 +struct nx_info *lookup_nx_info(int id)
24484 +{
24485 +       struct nx_info *nxi = NULL;
24486 +
24487 +       if (id < 0) {
24488 +               nxi = get_nx_info(current->nx_info);
24489 +       } else if (id > 1) {
24490 +               spin_lock(&nx_info_hash_lock);
24491 +               nxi = get_nx_info(__lookup_nx_info(id));
24492 +               spin_unlock(&nx_info_hash_lock);
24493 +       }
24494 +       return nxi;
24495 +}
24496 +
24497 +/*     nid_is_hashed()
24498 +
24499 +       * verify that nid is still hashed                       */
24500 +
24501 +int nid_is_hashed(nid_t nid)
24502 +{
24503 +       int hashed;
24504 +
24505 +       spin_lock(&nx_info_hash_lock);
24506 +       hashed = (__lookup_nx_info(nid) != NULL);
24507 +       spin_unlock(&nx_info_hash_lock);
24508 +       return hashed;
24509 +}
24510 +
24511 +
24512 +#ifdef CONFIG_PROC_FS
24513 +
24514 +/*     get_nid_list()
24515 +
24516 +       * get a subset of hashed nids for proc
24517 +       * assumes size is at least one                          */
24518 +
24519 +int get_nid_list(int index, unsigned int *nids, int size)
24520 +{
24521 +       int hindex, nr_nids = 0;
24522 +
24523 +       /* only show current and children */
24524 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
24525 +               if (index > 0)
24526 +                       return 0;
24527 +               nids[nr_nids] = nx_current_nid();
24528 +               return 1;
24529 +       }
24530 +
24531 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
24532 +               struct hlist_head *head = &nx_info_hash[hindex];
24533 +               struct hlist_node *pos;
24534 +
24535 +               spin_lock(&nx_info_hash_lock);
24536 +               hlist_for_each(pos, head) {
24537 +                       struct nx_info *nxi;
24538 +
24539 +                       if (--index > 0)
24540 +                               continue;
24541 +
24542 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24543 +                       nids[nr_nids] = nxi->nx_id;
24544 +                       if (++nr_nids >= size) {
24545 +                               spin_unlock(&nx_info_hash_lock);
24546 +                               goto out;
24547 +                       }
24548 +               }
24549 +               /* keep the lock time short */
24550 +               spin_unlock(&nx_info_hash_lock);
24551 +       }
24552 +out:
24553 +       return nr_nids;
24554 +}
24555 +#endif
24556 +
24557 +
24558 +/*
24559 + *     migrate task to new network
24560 + *     gets nxi, puts old_nxi on change
24561 + */
24562 +
24563 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
24564 +{
24565 +       struct nx_info *old_nxi;
24566 +       int ret = 0;
24567 +
24568 +       if (!p || !nxi)
24569 +               BUG();
24570 +
24571 +       vxdprintk(VXD_CBIT(nid, 5),
24572 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
24573 +               p, nxi, nxi->nx_id,
24574 +               atomic_read(&nxi->nx_usecnt),
24575 +               atomic_read(&nxi->nx_tasks));
24576 +
24577 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
24578 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24579 +               return -EACCES;
24580 +
24581 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
24582 +               return -EFAULT;
24583 +
24584 +       /* maybe disallow this completely? */
24585 +       old_nxi = task_get_nx_info(p);
24586 +       if (old_nxi == nxi)
24587 +               goto out;
24588 +
24589 +       task_lock(p);
24590 +       if (old_nxi)
24591 +               clr_nx_info(&p->nx_info);
24592 +       claim_nx_info(nxi, p);
24593 +       set_nx_info(&p->nx_info, nxi);
24594 +       p->nid = nxi->nx_id;
24595 +       task_unlock(p);
24596 +
24597 +       vxdprintk(VXD_CBIT(nid, 5),
24598 +               "moved task %p into nxi:%p[#%d]",
24599 +               p, nxi, nxi->nx_id);
24600 +
24601 +       if (old_nxi)
24602 +               release_nx_info(old_nxi, p);
24603 +       ret = 0;
24604 +out:
24605 +       put_nx_info(old_nxi);
24606 +       return ret;
24607 +}
24608 +
24609 +
24610 +void nx_set_persistent(struct nx_info *nxi)
24611 +{
24612 +       vxdprintk(VXD_CBIT(nid, 6),
24613 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
24614 +
24615 +       get_nx_info(nxi);
24616 +       claim_nx_info(nxi, NULL);
24617 +}
24618 +
24619 +void nx_clear_persistent(struct nx_info *nxi)
24620 +{
24621 +       vxdprintk(VXD_CBIT(nid, 6),
24622 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
24623 +
24624 +       release_nx_info(nxi, NULL);
24625 +       put_nx_info(nxi);
24626 +}
24627 +
24628 +void nx_update_persistent(struct nx_info *nxi)
24629 +{
24630 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
24631 +               nx_set_persistent(nxi);
24632 +       else
24633 +               nx_clear_persistent(nxi);
24634 +}
24635 +
24636 +/* vserver syscall commands below here */
24637 +
24638 +/* taks nid and nx_info functions */
24639 +
24640 +#include <asm/uaccess.h>
24641 +
24642 +
24643 +int vc_task_nid(uint32_t id)
24644 +{
24645 +       nid_t nid;
24646 +
24647 +       if (id) {
24648 +               struct task_struct *tsk;
24649 +
24650 +               read_lock(&tasklist_lock);
24651 +               tsk = find_task_by_real_pid(id);
24652 +               nid = (tsk) ? tsk->nid : -ESRCH;
24653 +               read_unlock(&tasklist_lock);
24654 +       } else
24655 +               nid = nx_current_nid();
24656 +       return nid;
24657 +}
24658 +
24659 +
24660 +int vc_nx_info(struct nx_info *nxi, void __user *data)
24661 +{
24662 +       struct vcmd_nx_info_v0 vc_data;
24663 +
24664 +       vc_data.nid = nxi->nx_id;
24665 +
24666 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24667 +               return -EFAULT;
24668 +       return 0;
24669 +}
24670 +
24671 +
24672 +/* network functions */
24673 +
24674 +int vc_net_create(uint32_t nid, void __user *data)
24675 +{
24676 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
24677 +       struct nx_info *new_nxi;
24678 +       int ret;
24679 +
24680 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24681 +               return -EFAULT;
24682 +
24683 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
24684 +               return -EINVAL;
24685 +
24686 +       new_nxi = __create_nx_info(nid);
24687 +       if (IS_ERR(new_nxi))
24688 +               return PTR_ERR(new_nxi);
24689 +
24690 +       /* initial flags */
24691 +       new_nxi->nx_flags = vc_data.flagword;
24692 +
24693 +       ret = -ENOEXEC;
24694 +       if (vs_net_change(new_nxi, VSC_NETUP))
24695 +               goto out;
24696 +
24697 +       ret = nx_migrate_task(current, new_nxi);
24698 +       if (ret)
24699 +               goto out;
24700 +
24701 +       /* return context id on success */
24702 +       ret = new_nxi->nx_id;
24703 +
24704 +       /* get a reference for persistent contexts */
24705 +       if ((vc_data.flagword & NXF_PERSISTENT))
24706 +               nx_set_persistent(new_nxi);
24707 +out:
24708 +       release_nx_info(new_nxi, NULL);
24709 +       put_nx_info(new_nxi);
24710 +       return ret;
24711 +}
24712 +
24713 +
24714 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
24715 +{
24716 +       return nx_migrate_task(current, nxi);
24717 +}
24718 +
24719 +
24720 +
24721 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
24722 +       uint16_t type, uint16_t flags)
24723 +{
24724 +       struct nx_addr_v4 *nxa = &nxi->v4;
24725 +
24726 +       if (NX_IPV4(nxi)) {
24727 +               /* locate last entry */
24728 +               for (; nxa->next; nxa = nxa->next);
24729 +               nxa->next = __alloc_nx_addr_v4();
24730 +               nxa = nxa->next;
24731 +
24732 +               if (IS_ERR(nxa))
24733 +                       return PTR_ERR(nxa);
24734 +       }
24735 +
24736 +       if (nxi->v4.next)
24737 +               /* remove single ip for ip list */
24738 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
24739 +
24740 +       nxa->ip[0].s_addr = ip;
24741 +       nxa->ip[1].s_addr = ip2;
24742 +       nxa->mask.s_addr = mask;
24743 +       nxa->type = type;
24744 +       nxa->flags = flags;
24745 +       return 0;
24746 +}
24747 +
24748 +
24749 +int vc_net_add(struct nx_info *nxi, void __user *data)
24750 +{
24751 +       struct vcmd_net_addr_v0 vc_data;
24752 +       int index, ret = 0;
24753 +
24754 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24755 +               return -EFAULT;
24756 +
24757 +       switch (vc_data.type) {
24758 +       case NXA_TYPE_IPV4:
24759 +               if ((vc_data.count < 1) || (vc_data.count > 4))
24760 +                       return -EINVAL;
24761 +
24762 +               index = 0;
24763 +               while (index < vc_data.count) {
24764 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
24765 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
24766 +                       if (ret)
24767 +                               return ret;
24768 +                       index++;
24769 +               }
24770 +               ret = index;
24771 +               break;
24772 +
24773 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
24774 +               nxi->v4_bcast = vc_data.ip[0];
24775 +               ret = 1;
24776 +               break;
24777 +
24778 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
24779 +               nxi->v4_lback = vc_data.ip[0];
24780 +               ret = 1;
24781 +               break;
24782 +
24783 +       default:
24784 +               ret = -EINVAL;
24785 +               break;
24786 +       }
24787 +       return ret;
24788 +}
24789 +
24790 +int vc_net_remove(struct nx_info *nxi, void __user *data)
24791 +{
24792 +       struct vcmd_net_addr_v0 vc_data;
24793 +
24794 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24795 +               return -EFAULT;
24796 +
24797 +       switch (vc_data.type) {
24798 +       case NXA_TYPE_ANY:
24799 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24800 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24801 +               break;
24802 +
24803 +       default:
24804 +               return -EINVAL;
24805 +       }
24806 +       return 0;
24807 +}
24808 +
24809 +
24810 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
24811 +{
24812 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24813 +
24814 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24815 +               return -EFAULT;
24816 +
24817 +       switch (vc_data.type) {
24818 +       case NXA_TYPE_ADDR:
24819 +       case NXA_TYPE_RANGE:
24820 +       case NXA_TYPE_MASK:
24821 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
24822 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
24823 +
24824 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
24825 +               nxi->v4_bcast = vc_data.ip;
24826 +               break;
24827 +
24828 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
24829 +               nxi->v4_lback = vc_data.ip;
24830 +               break;
24831 +
24832 +       default:
24833 +               return -EINVAL;
24834 +       }
24835 +       return 0;
24836 +}
24837 +
24838 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
24839 +{
24840 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24841 +
24842 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24843 +               return -EFAULT;
24844 +
24845 +       switch (vc_data.type) {
24846 +/*     case NXA_TYPE_ADDR:
24847 +               break;          */
24848 +
24849 +       case NXA_TYPE_ANY:
24850 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24851 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24852 +               break;
24853 +
24854 +       default:
24855 +               return -EINVAL;
24856 +       }
24857 +       return 0;
24858 +}
24859 +
24860 +
24861 +#ifdef CONFIG_IPV6
24862 +
24863 +int do_add_v6_addr(struct nx_info *nxi,
24864 +       struct in6_addr *ip, struct in6_addr *mask,
24865 +       uint32_t prefix, uint16_t type, uint16_t flags)
24866 +{
24867 +       struct nx_addr_v6 *nxa = &nxi->v6;
24868 +
24869 +       if (NX_IPV6(nxi)) {
24870 +               /* locate last entry */
24871 +               for (; nxa->next; nxa = nxa->next);
24872 +               nxa->next = __alloc_nx_addr_v6();
24873 +               nxa = nxa->next;
24874 +
24875 +               if (IS_ERR(nxa))
24876 +                       return PTR_ERR(nxa);
24877 +       }
24878 +
24879 +       nxa->ip = *ip;
24880 +       nxa->mask = *mask;
24881 +       nxa->prefix = prefix;
24882 +       nxa->type = type;
24883 +       nxa->flags = flags;
24884 +       return 0;
24885 +}
24886 +
24887 +
24888 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
24889 +{
24890 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24891 +
24892 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24893 +               return -EFAULT;
24894 +
24895 +       switch (vc_data.type) {
24896 +       case NXA_TYPE_ADDR:
24897 +       case NXA_TYPE_MASK:
24898 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
24899 +                       vc_data.prefix, vc_data.type, vc_data.flags);
24900 +       default:
24901 +               return -EINVAL;
24902 +       }
24903 +       return 0;
24904 +}
24905 +
24906 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
24907 +{
24908 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24909 +
24910 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24911 +               return -EFAULT;
24912 +
24913 +       switch (vc_data.type) {
24914 +       case NXA_TYPE_ANY:
24915 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
24916 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
24917 +               break;
24918 +
24919 +       default:
24920 +               return -EINVAL;
24921 +       }
24922 +       return 0;
24923 +}
24924 +
24925 +#endif /* CONFIG_IPV6 */
24926 +
24927 +
24928 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
24929 +{
24930 +       struct vcmd_net_flags_v0 vc_data;
24931 +
24932 +       vc_data.flagword = nxi->nx_flags;
24933 +
24934 +       /* special STATE flag handling */
24935 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
24936 +
24937 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24938 +               return -EFAULT;
24939 +       return 0;
24940 +}
24941 +
24942 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
24943 +{
24944 +       struct vcmd_net_flags_v0 vc_data;
24945 +       uint64_t mask, trigger;
24946 +
24947 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24948 +               return -EFAULT;
24949 +
24950 +       /* special STATE flag handling */
24951 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
24952 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
24953 +
24954 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
24955 +               vc_data.flagword, mask);
24956 +       if (trigger & NXF_PERSISTENT)
24957 +               nx_update_persistent(nxi);
24958 +
24959 +       return 0;
24960 +}
24961 +
24962 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
24963 +{
24964 +       struct vcmd_net_caps_v0 vc_data;
24965 +
24966 +       vc_data.ncaps = nxi->nx_ncaps;
24967 +       vc_data.cmask = ~0ULL;
24968 +
24969 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24970 +               return -EFAULT;
24971 +       return 0;
24972 +}
24973 +
24974 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
24975 +{
24976 +       struct vcmd_net_caps_v0 vc_data;
24977 +
24978 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24979 +               return -EFAULT;
24980 +
24981 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
24982 +               vc_data.ncaps, vc_data.cmask);
24983 +       return 0;
24984 +}
24985 +
24986 +
24987 +#include <linux/module.h>
24988 +
24989 +module_init(init_network);
24990 +
24991 +EXPORT_SYMBOL_GPL(free_nx_info);
24992 +EXPORT_SYMBOL_GPL(unhash_nx_info);
24993 +
24994 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
24995 --- linux-2.6.22.10/kernel/vserver/proc.c       1970-01-01 01:00:00 +0100
24996 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/proc.c    2007-10-05 14:54:36 +0200
24997 @@ -0,0 +1,1065 @@
24998 +/*
24999 + *  linux/kernel/vserver/proc.c
25000 + *
25001 + *  Virtual Context Support
25002 + *
25003 + *  Copyright (C) 2003-2007  Herbert Pötzl
25004 + *
25005 + *  V0.01  basic structure
25006 + *  V0.02  adaptation vs1.3.0
25007 + *  V0.03  proc permissions
25008 + *  V0.04  locking/generic
25009 + *  V0.05  next generation procfs
25010 + *  V0.06  inode validation
25011 + *  V0.07  generic rewrite vid
25012 + *  V0.08  remove inode type
25013 + *
25014 + */
25015 +
25016 +#include <linux/proc_fs.h>
25017 +#include <asm/unistd.h>
25018 +
25019 +#include <linux/vs_context.h>
25020 +#include <linux/vs_network.h>
25021 +#include <linux/vs_cvirt.h>
25022 +#include <linux/vs_inet.h>
25023 +#include <linux/vs_inet6.h>
25024 +
25025 +#include <linux/vserver/global.h>
25026 +
25027 +#include "cvirt_proc.h"
25028 +#include "cacct_proc.h"
25029 +#include "limit_proc.h"
25030 +#include "sched_proc.h"
25031 +#include "vci_config.h"
25032 +
25033 +static struct proc_dir_entry *proc_virtual;
25034 +
25035 +static struct proc_dir_entry *proc_virtnet;
25036 +
25037 +
25038 +/* first the actual feeds */
25039 +
25040 +
25041 +static int proc_vci(char *buffer)
25042 +{
25043 +       return sprintf(buffer,
25044 +               "VCIVersion:\t%04x:%04x\n"
25045 +               "VCISyscall:\t%d\n"
25046 +               "VCIKernel:\t%08x\n",
25047 +               VCI_VERSION >> 16,
25048 +               VCI_VERSION & 0xFFFF,
25049 +               __NR_vserver,
25050 +               vci_kernel_config());
25051 +}
25052 +
25053 +static int proc_virtual_info(char *buffer)
25054 +{
25055 +       return proc_vci(buffer);
25056 +}
25057 +
25058 +static int proc_virtual_status(char *buffer)
25059 +{
25060 +       return sprintf(buffer,
25061 +               "#CTotal:\t%d\n"
25062 +               "#CActive:\t%d\n"
25063 +               "#NSProxy:\t%d\t%d %d %d %d\n",
25064 +               atomic_read(&vx_global_ctotal),
25065 +               atomic_read(&vx_global_cactive),
25066 +               atomic_read(&vs_global_nsproxy),
25067 +               atomic_read(&vs_global_fs),
25068 +               atomic_read(&vs_global_mnt_ns),
25069 +               atomic_read(&vs_global_uts_ns),
25070 +               atomic_read(&vs_global_ipc_ns));
25071 +}
25072 +
25073 +
25074 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
25075 +{
25076 +       int length;
25077 +
25078 +       length = sprintf(buffer,
25079 +               "ID:\t%d\n"
25080 +               "Info:\t%p\n"
25081 +               "Init:\t%d\n"
25082 +               "OOM:\t%lld\n",
25083 +               vxi->vx_id,
25084 +               vxi,
25085 +               vxi->vx_initpid,
25086 +               vxi->vx_badness_bias);
25087 +       return length;
25088 +}
25089 +
25090 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
25091 +{
25092 +       int length;
25093 +
25094 +       length = sprintf(buffer,
25095 +               "UseCnt:\t%d\n"
25096 +               "Tasks:\t%d\n"
25097 +               "Flags:\t%016llx\n"
25098 +               "BCaps:\t%016llx\n"
25099 +               "CCaps:\t%016llx\n"
25100 +               "Spaces:\t%08lx\n",
25101 +               atomic_read(&vxi->vx_usecnt),
25102 +               atomic_read(&vxi->vx_tasks),
25103 +               (unsigned long long)vxi->vx_flags,
25104 +               (unsigned long long)vxi->vx_bcaps,
25105 +               (unsigned long long)vxi->vx_ccaps,
25106 +               vxi->vx_nsmask);
25107 +       return length;
25108 +}
25109 +
25110 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
25111 +{
25112 +       return vx_info_proc_limit(&vxi->limit, buffer);
25113 +}
25114 +
25115 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
25116 +{
25117 +       int cpu, length;
25118 +
25119 +       length = vx_info_proc_sched(&vxi->sched, buffer);
25120 +       for_each_online_cpu(cpu) {
25121 +               length += vx_info_proc_sched_pc(
25122 +                       &vx_per_cpu(vxi, sched_pc, cpu),
25123 +                       buffer + length, cpu);
25124 +       }
25125 +       return length;
25126 +}
25127 +
25128 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
25129 +{
25130 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
25131 +}
25132 +
25133 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
25134 +{
25135 +       int cpu, length;
25136 +
25137 +       vx_update_load(vxi);
25138 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
25139 +       for_each_online_cpu(cpu) {
25140 +               length += vx_info_proc_cvirt_pc(
25141 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
25142 +                       buffer + length, cpu);
25143 +       }
25144 +       return length;
25145 +}
25146 +
25147 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
25148 +{
25149 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
25150 +}
25151 +
25152 +
25153 +static int proc_virtnet_info(char *buffer)
25154 +{
25155 +       return proc_vci(buffer);
25156 +}
25157 +
25158 +static int proc_virtnet_status(char *buffer)
25159 +{
25160 +       return sprintf(buffer,
25161 +               "#CTotal:\t%d\n"
25162 +               "#CActive:\t%d\n",
25163 +               atomic_read(&nx_global_ctotal),
25164 +               atomic_read(&nx_global_cactive));
25165 +}
25166 +
25167 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
25168 +{
25169 +       struct nx_addr_v4 *v4a;
25170 +#ifdef CONFIG_IPV6
25171 +       struct nx_addr_v6 *v6a;
25172 +#endif
25173 +       int length, i;
25174 +
25175 +       length = sprintf(buffer,
25176 +               "ID:\t%d\n"
25177 +               "Info:\t%p\n"
25178 +               "Bcast:\t" NIPQUAD_FMT "\n"
25179 +               "Lback:\t" NIPQUAD_FMT "\n",
25180 +               nxi->nx_id,
25181 +               nxi,
25182 +               NIPQUAD(nxi->v4_bcast.s_addr),
25183 +               NIPQUAD(nxi->v4_lback.s_addr));
25184 +
25185 +       if (!NX_IPV4(nxi))
25186 +               goto skip_v4;
25187 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
25188 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
25189 +                       i, NXAV4(v4a));
25190 +skip_v4:
25191 +#ifdef CONFIG_IPV6
25192 +       if (!NX_IPV6(nxi))
25193 +               goto skip_v6;
25194 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
25195 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
25196 +                       i, NXAV6(v6a));
25197 +skip_v6:
25198 +#endif
25199 +       return length;
25200 +}
25201 +
25202 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
25203 +{
25204 +       int length;
25205 +
25206 +       length = sprintf(buffer,
25207 +               "UseCnt:\t%d\n"
25208 +               "Tasks:\t%d\n"
25209 +               "Flags:\t%016llx\n"
25210 +               "NCaps:\t%016llx\n",
25211 +               atomic_read(&nxi->nx_usecnt),
25212 +               atomic_read(&nxi->nx_tasks),
25213 +               (unsigned long long)nxi->nx_flags,
25214 +               (unsigned long long)nxi->nx_ncaps);
25215 +       return length;
25216 +}
25217 +
25218 +
25219 +
25220 +/* here the inode helpers */
25221 +
25222 +struct vs_entry {
25223 +       int len;
25224 +       char *name;
25225 +       mode_t mode;
25226 +       struct inode_operations *iop;
25227 +       struct file_operations *fop;
25228 +       union proc_op op;
25229 +};
25230 +
25231 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
25232 +{
25233 +       struct inode *inode = new_inode(sb);
25234 +
25235 +       if (!inode)
25236 +               goto out;
25237 +
25238 +       inode->i_mode = p->mode;
25239 +       if (p->iop)
25240 +               inode->i_op = p->iop;
25241 +       if (p->fop)
25242 +               inode->i_fop = p->fop;
25243 +
25244 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
25245 +       inode->i_flags |= S_IMMUTABLE;
25246 +
25247 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
25248 +
25249 +       inode->i_uid = 0;
25250 +       inode->i_gid = 0;
25251 +       inode->i_tag = 0;
25252 +out:
25253 +       return inode;
25254 +}
25255 +
25256 +static struct dentry *vs_proc_instantiate(struct inode *dir,
25257 +       struct dentry *dentry, int id, void *ptr)
25258 +{
25259 +       struct vs_entry *p = ptr;
25260 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
25261 +       struct dentry *error = ERR_PTR(-EINVAL);
25262 +
25263 +       if (!inode)
25264 +               goto out;
25265 +
25266 +       PROC_I(inode)->op = p->op;
25267 +       PROC_I(inode)->fd = id;
25268 +       d_add(dentry, inode);
25269 +       error = NULL;
25270 +out:
25271 +       return error;
25272 +}
25273 +
25274 +/* Lookups */
25275 +
25276 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
25277 +
25278 +/*
25279 + * Fill a directory entry.
25280 + *
25281 + * If possible create the dcache entry and derive our inode number and
25282 + * file type from dcache entry.
25283 + *
25284 + * Since all of the proc inode numbers are dynamically generated, the inode
25285 + * numbers do not exist until the inode is cache.  This means creating the
25286 + * the dcache entry in readdir is necessary to keep the inode numbers
25287 + * reported by readdir in sync with the inode numbers reported
25288 + * by stat.
25289 + */
25290 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
25291 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
25292 +{
25293 +       struct dentry *child, *dir = filp->f_dentry;
25294 +       struct inode *inode;
25295 +       struct qstr qname;
25296 +       ino_t ino = 0;
25297 +       unsigned type = DT_UNKNOWN;
25298 +
25299 +       qname.name = name;
25300 +       qname.len  = len;
25301 +       qname.hash = full_name_hash(name, len);
25302 +
25303 +       child = d_lookup(dir, &qname);
25304 +       if (!child) {
25305 +               struct dentry *new;
25306 +               new = d_alloc(dir, &qname);
25307 +               if (new) {
25308 +                       child = instantiate(dir->d_inode, new, id, ptr);
25309 +                       if (child)
25310 +                               dput(new);
25311 +                       else
25312 +                               child = new;
25313 +               }
25314 +       }
25315 +       if (!child || IS_ERR(child) || !child->d_inode)
25316 +               goto end_instantiate;
25317 +       inode = child->d_inode;
25318 +       if (inode) {
25319 +               ino = inode->i_ino;
25320 +               type = inode->i_mode >> 12;
25321 +       }
25322 +       dput(child);
25323 +end_instantiate:
25324 +       if (!ino)
25325 +               ino = find_inode_number(dir, &qname);
25326 +       if (!ino)
25327 +               ino = 1;
25328 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
25329 +}
25330 +
25331 +
25332 +
25333 +/* get and revalidate vx_info/xid */
25334 +
25335 +static inline
25336 +struct vx_info *get_proc_vx_info(struct inode *inode)
25337 +{
25338 +       return lookup_vx_info(PROC_I(inode)->fd);
25339 +}
25340 +
25341 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
25342 +{
25343 +       struct inode *inode = dentry->d_inode;
25344 +       xid_t xid = PROC_I(inode)->fd;
25345 +
25346 +       if (!xid || xid_is_hashed(xid))
25347 +               return 1;
25348 +       d_drop(dentry);
25349 +       return 0;
25350 +}
25351 +
25352 +
25353 +/* get and revalidate nx_info/nid */
25354 +
25355 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
25356 +{
25357 +       struct inode *inode = dentry->d_inode;
25358 +       nid_t nid = PROC_I(inode)->fd;
25359 +
25360 +       if (!nid || nid_is_hashed(nid))
25361 +               return 1;
25362 +       d_drop(dentry);
25363 +       return 0;
25364 +}
25365 +
25366 +
25367 +
25368 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
25369 +
25370 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
25371 +                         size_t count, loff_t *ppos)
25372 +{
25373 +       struct inode *inode = file->f_dentry->d_inode;
25374 +       unsigned long page;
25375 +       ssize_t length = 0;
25376 +
25377 +       if (count > PROC_BLOCK_SIZE)
25378 +               count = PROC_BLOCK_SIZE;
25379 +
25380 +       /* fade that out as soon as stable */
25381 +       WARN_ON(PROC_I(inode)->fd);
25382 +
25383 +       if (!(page = __get_free_page(GFP_KERNEL)))
25384 +               return -ENOMEM;
25385 +
25386 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
25387 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
25388 +
25389 +       if (length >= 0)
25390 +               length = simple_read_from_buffer(buf, count, ppos,
25391 +                       (char *)page, length);
25392 +
25393 +       free_page(page);
25394 +       return length;
25395 +}
25396 +
25397 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
25398 +                         size_t count, loff_t *ppos)
25399 +{
25400 +       struct inode *inode = file->f_dentry->d_inode;
25401 +       struct vx_info *vxi = NULL;
25402 +       xid_t xid = PROC_I(inode)->fd;
25403 +       unsigned long page;
25404 +       ssize_t length = 0;
25405 +
25406 +       if (count > PROC_BLOCK_SIZE)
25407 +               count = PROC_BLOCK_SIZE;
25408 +
25409 +       /* fade that out as soon as stable */
25410 +       WARN_ON(!xid);
25411 +       vxi = lookup_vx_info(xid);
25412 +       if (!vxi)
25413 +               goto out;
25414 +
25415 +       length = -ENOMEM;
25416 +       if (!(page = __get_free_page(GFP_KERNEL)))
25417 +               goto out_put;
25418 +
25419 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
25420 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
25421 +
25422 +       if (length >= 0)
25423 +               length = simple_read_from_buffer(buf, count, ppos,
25424 +                       (char *)page, length);
25425 +
25426 +       free_page(page);
25427 +out_put:
25428 +       put_vx_info(vxi);
25429 +out:
25430 +       return length;
25431 +}
25432 +
25433 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
25434 +                         size_t count, loff_t *ppos)
25435 +{
25436 +       struct inode *inode = file->f_dentry->d_inode;
25437 +       struct nx_info *nxi = NULL;
25438 +       nid_t nid = PROC_I(inode)->fd;
25439 +       unsigned long page;
25440 +       ssize_t length = 0;
25441 +
25442 +       if (count > PROC_BLOCK_SIZE)
25443 +               count = PROC_BLOCK_SIZE;
25444 +
25445 +       /* fade that out as soon as stable */
25446 +       WARN_ON(!nid);
25447 +       nxi = lookup_nx_info(nid);
25448 +       if (!nxi)
25449 +               goto out;
25450 +
25451 +       length = -ENOMEM;
25452 +       if (!(page = __get_free_page(GFP_KERNEL)))
25453 +               goto out_put;
25454 +
25455 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
25456 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (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 +out_put:
25464 +       put_nx_info(nxi);
25465 +out:
25466 +       return length;
25467 +}
25468 +
25469 +
25470 +
25471 +/* here comes the lower level */
25472 +
25473 +
25474 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
25475 +       .len  = sizeof(NAME) - 1,       \
25476 +       .name = (NAME),                 \
25477 +       .mode = MODE,                   \
25478 +       .iop  = IOP,                    \
25479 +       .fop  = FOP,                    \
25480 +       .op   = OP,                     \
25481 +}
25482 +
25483 +
25484 +#define DIR(NAME, MODE, OTYPE)                         \
25485 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
25486 +               &proc_ ## OTYPE ## _inode_operations,   \
25487 +               &proc_ ## OTYPE ## _file_operations, { } )
25488 +
25489 +#define INF(NAME, MODE, OTYPE)                         \
25490 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25491 +               &proc_vs_info_file_operations,          \
25492 +               { .proc_vs_read = &proc_##OTYPE } )
25493 +
25494 +#define VINF(NAME, MODE, OTYPE)                                \
25495 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25496 +               &proc_vx_info_file_operations,          \
25497 +               { .proc_vxi_read = &proc_##OTYPE } )
25498 +
25499 +#define NINF(NAME, MODE, OTYPE)                                \
25500 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25501 +               &proc_nx_info_file_operations,          \
25502 +               { .proc_nxi_read = &proc_##OTYPE } )
25503 +
25504 +
25505 +static struct file_operations proc_vs_info_file_operations = {
25506 +       .read =         proc_vs_info_read,
25507 +};
25508 +
25509 +static struct file_operations proc_vx_info_file_operations = {
25510 +       .read =         proc_vx_info_read,
25511 +};
25512 +
25513 +static struct dentry_operations proc_xid_dentry_operations = {
25514 +       .d_revalidate = proc_xid_revalidate,
25515 +};
25516 +
25517 +static struct vs_entry vx_base_stuff[] = {
25518 +       VINF("info",    S_IRUGO, vxi_info),
25519 +       VINF("status",  S_IRUGO, vxi_status),
25520 +       VINF("limit",   S_IRUGO, vxi_limit),
25521 +       VINF("sched",   S_IRUGO, vxi_sched),
25522 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
25523 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
25524 +       VINF("cacct",   S_IRUGO, vxi_cacct),
25525 +       {}
25526 +};
25527 +
25528 +
25529 +
25530 +
25531 +static struct dentry *proc_xid_instantiate(struct inode *dir,
25532 +       struct dentry *dentry, int id, void *ptr)
25533 +{
25534 +       dentry->d_op = &proc_xid_dentry_operations;
25535 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25536 +}
25537 +
25538 +static struct dentry *proc_xid_lookup(struct inode *dir,
25539 +       struct dentry *dentry, struct nameidata *nd)
25540 +{
25541 +       struct vs_entry *p = vx_base_stuff;
25542 +       struct dentry *error = ERR_PTR(-ENOENT);
25543 +
25544 +       for (; p->name; p++) {
25545 +               if (p->len != dentry->d_name.len)
25546 +                       continue;
25547 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25548 +                       break;
25549 +       }
25550 +       if (!p->name)
25551 +               goto out;
25552 +
25553 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25554 +out:
25555 +       return error;
25556 +}
25557 +
25558 +static int proc_xid_readdir(struct file *filp,
25559 +       void *dirent, filldir_t filldir)
25560 +{
25561 +       struct dentry *dentry = filp->f_dentry;
25562 +       struct inode *inode = dentry->d_inode;
25563 +       struct vs_entry *p = vx_base_stuff;
25564 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
25565 +       int pos, index;
25566 +       u64 ino;
25567 +
25568 +       pos = filp->f_pos;
25569 +       switch (pos) {
25570 +       case 0:
25571 +               ino = inode->i_ino;
25572 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25573 +                       goto out;
25574 +               pos++;
25575 +               /* fall through */
25576 +       case 1:
25577 +               ino = parent_ino(dentry);
25578 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25579 +                       goto out;
25580 +               pos++;
25581 +               /* fall through */
25582 +       default:
25583 +               index = pos - 2;
25584 +               if (index >= size)
25585 +                       goto out;
25586 +               for (p += index; p->name; p++) {
25587 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25588 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25589 +                               goto out;
25590 +                       pos++;
25591 +               }
25592 +       }
25593 +out:
25594 +       filp->f_pos = pos;
25595 +       return 1;
25596 +}
25597 +
25598 +
25599 +
25600 +static struct file_operations proc_nx_info_file_operations = {
25601 +       .read =         proc_nx_info_read,
25602 +};
25603 +
25604 +static struct dentry_operations proc_nid_dentry_operations = {
25605 +       .d_revalidate = proc_nid_revalidate,
25606 +};
25607 +
25608 +static struct vs_entry nx_base_stuff[] = {
25609 +       NINF("info",    S_IRUGO, nxi_info),
25610 +       NINF("status",  S_IRUGO, nxi_status),
25611 +       {}
25612 +};
25613 +
25614 +
25615 +static struct dentry *proc_nid_instantiate(struct inode *dir,
25616 +       struct dentry *dentry, int id, void *ptr)
25617 +{
25618 +       dentry->d_op = &proc_nid_dentry_operations;
25619 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25620 +}
25621 +
25622 +static struct dentry *proc_nid_lookup(struct inode *dir,
25623 +       struct dentry *dentry, struct nameidata *nd)
25624 +{
25625 +       struct vs_entry *p = nx_base_stuff;
25626 +       struct dentry *error = ERR_PTR(-ENOENT);
25627 +
25628 +       for (; p->name; p++) {
25629 +               if (p->len != dentry->d_name.len)
25630 +                       continue;
25631 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25632 +                       break;
25633 +       }
25634 +       if (!p->name)
25635 +               goto out;
25636 +
25637 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25638 +out:
25639 +       return error;
25640 +}
25641 +
25642 +static int proc_nid_readdir(struct file *filp,
25643 +       void *dirent, filldir_t filldir)
25644 +{
25645 +       struct dentry *dentry = filp->f_dentry;
25646 +       struct inode *inode = dentry->d_inode;
25647 +       struct vs_entry *p = nx_base_stuff;
25648 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
25649 +       int pos, index;
25650 +       u64 ino;
25651 +
25652 +       pos = filp->f_pos;
25653 +       switch (pos) {
25654 +       case 0:
25655 +               ino = inode->i_ino;
25656 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25657 +                       goto out;
25658 +               pos++;
25659 +               /* fall through */
25660 +       case 1:
25661 +               ino = parent_ino(dentry);
25662 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25663 +                       goto out;
25664 +               pos++;
25665 +               /* fall through */
25666 +       default:
25667 +               index = pos - 2;
25668 +               if (index >= size)
25669 +                       goto out;
25670 +               for (p += index; p->name; p++) {
25671 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25672 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25673 +                               goto out;
25674 +                       pos++;
25675 +               }
25676 +       }
25677 +out:
25678 +       filp->f_pos = pos;
25679 +       return 1;
25680 +}
25681 +
25682 +
25683 +#define MAX_MULBY10    ((~0U - 9) / 10)
25684 +
25685 +static inline int atovid(const char *str, int len)
25686 +{
25687 +       int vid, c;
25688 +
25689 +       vid = 0;
25690 +       while (len-- > 0) {
25691 +               c = *str - '0';
25692 +               str++;
25693 +               if (c > 9)
25694 +                       return -1;
25695 +               if (vid >= MAX_MULBY10)
25696 +                       return -1;
25697 +               vid *= 10;
25698 +               vid += c;
25699 +               if (!vid)
25700 +                       return -1;
25701 +       }
25702 +       return vid;
25703 +}
25704 +
25705 +/* now the upper level (virtual) */
25706 +
25707 +
25708 +static struct file_operations proc_xid_file_operations = {
25709 +       .read =         generic_read_dir,
25710 +       .readdir =      proc_xid_readdir,
25711 +};
25712 +
25713 +static struct inode_operations proc_xid_inode_operations = {
25714 +       .lookup =       proc_xid_lookup,
25715 +};
25716 +
25717 +static struct vs_entry vx_virtual_stuff[] = {
25718 +       INF("info",     S_IRUGO, virtual_info),
25719 +       INF("status",   S_IRUGO, virtual_status),
25720 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
25721 +};
25722 +
25723 +
25724 +static struct dentry *proc_virtual_lookup(struct inode *dir,
25725 +       struct dentry *dentry, struct nameidata *nd)
25726 +{
25727 +       struct vs_entry *p = vx_virtual_stuff;
25728 +       struct dentry *error = ERR_PTR(-ENOENT);
25729 +       int id = 0;
25730 +
25731 +       for (; p->name; p++) {
25732 +               if (p->len != dentry->d_name.len)
25733 +                       continue;
25734 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25735 +                       break;
25736 +       }
25737 +       if (p->name)
25738 +               goto instantiate;
25739 +
25740 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25741 +       if ((id < 0) || !xid_is_hashed(id))
25742 +               goto out;
25743 +
25744 +instantiate:
25745 +       error = proc_xid_instantiate(dir, dentry, id, p);
25746 +out:
25747 +       return error;
25748 +}
25749 +
25750 +static struct file_operations proc_nid_file_operations = {
25751 +       .read =         generic_read_dir,
25752 +       .readdir =      proc_nid_readdir,
25753 +};
25754 +
25755 +static struct inode_operations proc_nid_inode_operations = {
25756 +       .lookup =       proc_nid_lookup,
25757 +};
25758 +
25759 +static struct vs_entry nx_virtnet_stuff[] = {
25760 +       INF("info",     S_IRUGO, virtnet_info),
25761 +       INF("status",   S_IRUGO, virtnet_status),
25762 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
25763 +};
25764 +
25765 +
25766 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
25767 +       struct dentry *dentry, struct nameidata *nd)
25768 +{
25769 +       struct vs_entry *p = nx_virtnet_stuff;
25770 +       struct dentry *error = ERR_PTR(-ENOENT);
25771 +       int id = 0;
25772 +
25773 +       for (; p->name; p++) {
25774 +               if (p->len != dentry->d_name.len)
25775 +                       continue;
25776 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25777 +                       break;
25778 +       }
25779 +       if (p->name)
25780 +               goto instantiate;
25781 +
25782 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25783 +       if ((id < 0) || !nid_is_hashed(id))
25784 +               goto out;
25785 +
25786 +instantiate:
25787 +       error = proc_nid_instantiate(dir, dentry, id, p);
25788 +out:
25789 +       return error;
25790 +}
25791 +
25792 +
25793 +
25794 +#define PROC_NUMBUF 10
25795 +#define PROC_MAXVIDS 32
25796 +
25797 +int proc_virtual_readdir(struct file *filp,
25798 +       void *dirent, filldir_t filldir)
25799 +{
25800 +       struct dentry *dentry = filp->f_dentry;
25801 +       struct inode *inode = dentry->d_inode;
25802 +       struct vs_entry *p = vx_virtual_stuff;
25803 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
25804 +       int pos, index;
25805 +       unsigned int xid_array[PROC_MAXVIDS];
25806 +       char buf[PROC_NUMBUF];
25807 +       unsigned int nr_xids, i;
25808 +       u64 ino;
25809 +
25810 +       pos = filp->f_pos;
25811 +       switch (pos) {
25812 +       case 0:
25813 +               ino = inode->i_ino;
25814 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25815 +                       goto out;
25816 +               pos++;
25817 +               /* fall through */
25818 +       case 1:
25819 +               ino = parent_ino(dentry);
25820 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25821 +                       goto out;
25822 +               pos++;
25823 +               /* fall through */
25824 +       default:
25825 +               index = pos - 2;
25826 +               if (index >= size)
25827 +                       goto entries;
25828 +               for (p += index; p->name; p++) {
25829 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25830 +                               vs_proc_instantiate, 0, p))
25831 +                               goto out;
25832 +                       pos++;
25833 +               }
25834 +       entries:
25835 +               index = pos - size;
25836 +               p = &vx_virtual_stuff[size - 1];
25837 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
25838 +               for (i = 0; i < nr_xids; i++) {
25839 +                       int n, xid = xid_array[i];
25840 +                       unsigned int j = PROC_NUMBUF;
25841 +
25842 +                       n = xid;
25843 +                       do
25844 +                               buf[--j] = '0' + (n % 10);
25845 +                       while (n /= 10);
25846 +
25847 +                       if (proc_fill_cache(filp, dirent, filldir,
25848 +                               buf + j, PROC_NUMBUF - j,
25849 +                               vs_proc_instantiate, xid, p))
25850 +                               goto out;
25851 +                       pos++;
25852 +               }
25853 +       }
25854 +out:
25855 +       filp->f_pos = pos;
25856 +       return 0;
25857 +}
25858 +
25859 +static int proc_virtual_getattr(struct vfsmount *mnt,
25860 +       struct dentry *dentry, struct kstat *stat)
25861 +{
25862 +       struct inode *inode = dentry->d_inode;
25863 +
25864 +       generic_fillattr(inode, stat);
25865 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
25866 +       return 0;
25867 +}
25868 +
25869 +static struct file_operations proc_virtual_dir_operations = {
25870 +       .read =         generic_read_dir,
25871 +       .readdir =      proc_virtual_readdir,
25872 +};
25873 +
25874 +static struct inode_operations proc_virtual_dir_inode_operations = {
25875 +       .getattr =      proc_virtual_getattr,
25876 +       .lookup =       proc_virtual_lookup,
25877 +};
25878 +
25879 +
25880 +
25881 +
25882 +
25883 +int proc_virtnet_readdir(struct file *filp,
25884 +       void *dirent, filldir_t filldir)
25885 +{
25886 +       struct dentry *dentry = filp->f_dentry;
25887 +       struct inode *inode = dentry->d_inode;
25888 +       struct vs_entry *p = nx_virtnet_stuff;
25889 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
25890 +       int pos, index;
25891 +       unsigned int nid_array[PROC_MAXVIDS];
25892 +       char buf[PROC_NUMBUF];
25893 +       unsigned int nr_nids, i;
25894 +       u64 ino;
25895 +
25896 +       pos = filp->f_pos;
25897 +       switch (pos) {
25898 +       case 0:
25899 +               ino = inode->i_ino;
25900 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25901 +                       goto out;
25902 +               pos++;
25903 +               /* fall through */
25904 +       case 1:
25905 +               ino = parent_ino(dentry);
25906 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25907 +                       goto out;
25908 +               pos++;
25909 +               /* fall through */
25910 +       default:
25911 +               index = pos - 2;
25912 +               if (index >= size)
25913 +                       goto entries;
25914 +               for (p += index; p->name; p++) {
25915 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25916 +                               vs_proc_instantiate, 0, p))
25917 +                               goto out;
25918 +                       pos++;
25919 +               }
25920 +       entries:
25921 +               index = pos - size;
25922 +               p = &nx_virtnet_stuff[size - 1];
25923 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
25924 +               for (i = 0; i < nr_nids; i++) {
25925 +                       int n, nid = nid_array[i];
25926 +                       unsigned int j = PROC_NUMBUF;
25927 +
25928 +                       n = nid;
25929 +                       do
25930 +                               buf[--j] = '0' + (n % 10);
25931 +                       while (n /= 10);
25932 +
25933 +                       if (proc_fill_cache(filp, dirent, filldir,
25934 +                               buf + j, PROC_NUMBUF - j,
25935 +                               vs_proc_instantiate, nid, p))
25936 +                               goto out;
25937 +                       pos++;
25938 +               }
25939 +       }
25940 +out:
25941 +       filp->f_pos = pos;
25942 +       return 0;
25943 +}
25944 +
25945 +static int proc_virtnet_getattr(struct vfsmount *mnt,
25946 +       struct dentry *dentry, struct kstat *stat)
25947 +{
25948 +       struct inode *inode = dentry->d_inode;
25949 +
25950 +       generic_fillattr(inode, stat);
25951 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
25952 +       return 0;
25953 +}
25954 +
25955 +static struct file_operations proc_virtnet_dir_operations = {
25956 +       .read =         generic_read_dir,
25957 +       .readdir =      proc_virtnet_readdir,
25958 +};
25959 +
25960 +static struct inode_operations proc_virtnet_dir_inode_operations = {
25961 +       .getattr =      proc_virtnet_getattr,
25962 +       .lookup =       proc_virtnet_lookup,
25963 +};
25964 +
25965 +
25966 +
25967 +void proc_vx_init(void)
25968 +{
25969 +       struct proc_dir_entry *ent;
25970 +
25971 +       ent = proc_mkdir("virtual", 0);
25972 +       if (ent) {
25973 +               ent->proc_fops = &proc_virtual_dir_operations;
25974 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
25975 +       }
25976 +       proc_virtual = ent;
25977 +
25978 +       ent = proc_mkdir("virtnet", 0);
25979 +       if (ent) {
25980 +               ent->proc_fops = &proc_virtnet_dir_operations;
25981 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
25982 +       }
25983 +       proc_virtnet = ent;
25984 +}
25985 +
25986 +
25987 +
25988 +
25989 +/* per pid info */
25990 +
25991 +
25992 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
25993 +{
25994 +       struct vx_info *vxi;
25995 +       char *orig = buffer;
25996 +
25997 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
25998 +
25999 +       vxi = task_get_vx_info(p);
26000 +       if (!vxi)
26001 +               goto out;
26002 +
26003 +       buffer += sprintf(buffer, "BCaps:\t%016llx\n",
26004 +               (unsigned long long)vxi->vx_bcaps);
26005 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
26006 +               (unsigned long long)vxi->vx_ccaps);
26007 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
26008 +               (unsigned long long)vxi->vx_flags);
26009 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
26010 +
26011 +       put_vx_info(vxi);
26012 +out:
26013 +       return buffer - orig;
26014 +}
26015 +
26016 +
26017 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
26018 +{
26019 +       struct nx_info *nxi;
26020 +       struct nx_addr_v4 *v4a;
26021 +#ifdef CONFIG_IPV6
26022 +       struct nx_addr_v6 *v6a;
26023 +#endif
26024 +       char *orig = buffer;
26025 +       int i;
26026 +
26027 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
26028 +
26029 +       nxi = task_get_nx_info(p);
26030 +       if (!nxi)
26031 +               goto out;
26032 +
26033 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
26034 +               (unsigned long long)nxi->nx_ncaps);
26035 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
26036 +               (unsigned long long)nxi->nx_flags);
26037 +
26038 +       buffer += sprintf(buffer,
26039 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
26040 +               NIPQUAD(nxi->v4_bcast.s_addr));
26041 +       buffer += sprintf (buffer,
26042 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
26043 +               NIPQUAD(nxi->v4_lback.s_addr));
26044 +       if (!NX_IPV4(nxi))
26045 +               goto skip_v4;
26046 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
26047 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
26048 +                       i, NXAV4(v4a));
26049 +skip_v4:
26050 +#ifdef CONFIG_IPV6
26051 +       if (!NX_IPV6(nxi))
26052 +               goto skip_v6;
26053 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
26054 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
26055 +                       i, NXAV6(v6a));
26056 +skip_v6:
26057 +#endif
26058 +       put_nx_info(nxi);
26059 +out:
26060 +       return buffer - orig;
26061 +}
26062 +
26063 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
26064 --- linux-2.6.22.10/kernel/vserver/sched.c      1970-01-01 01:00:00 +0100
26065 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched.c   2007-08-15 23:32:49 +0200
26066 @@ -0,0 +1,413 @@
26067 +/*
26068 + *  linux/kernel/vserver/sched.c
26069 + *
26070 + *  Virtual Server: Scheduler Support
26071 + *
26072 + *  Copyright (C) 2004-2007  Herbert Pötzl
26073 + *
26074 + *  V0.01  adapted Sam Vilains version to 2.6.3
26075 + *  V0.02  removed legacy interface
26076 + *  V0.03  changed vcmds to vxi arg
26077 + *  V0.04  removed older and legacy interfaces
26078 + *
26079 + */
26080 +
26081 +#include <linux/vs_context.h>
26082 +#include <linux/vs_sched.h>
26083 +#include <linux/vserver/sched_cmd.h>
26084 +
26085 +#include <asm/uaccess.h>
26086 +
26087 +
26088 +#define vxd_check_range(val, min, max) do {            \
26089 +       vxlprintk((val < min) || (val > max),           \
26090 +               "check_range(%ld,%ld,%ld)",             \
26091 +               (long)val, (long)min, (long)max,        \
26092 +               __FILE__, __LINE__);                    \
26093 +       } while (0)
26094 +
26095 +
26096 +void vx_update_sched_param(struct _vx_sched *sched,
26097 +       struct _vx_sched_pc *sched_pc)
26098 +{
26099 +       unsigned int set_mask = sched->update_mask;
26100 +
26101 +       if (set_mask & VXSM_FILL_RATE)
26102 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
26103 +       if (set_mask & VXSM_INTERVAL)
26104 +               sched_pc->interval[0] = sched->interval[0];
26105 +       if (set_mask & VXSM_FILL_RATE2)
26106 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
26107 +       if (set_mask & VXSM_INTERVAL2)
26108 +               sched_pc->interval[1] = sched->interval[1];
26109 +       if (set_mask & VXSM_TOKENS)
26110 +               sched_pc->tokens = sched->tokens;
26111 +       if (set_mask & VXSM_TOKENS_MIN)
26112 +               sched_pc->tokens_min = sched->tokens_min;
26113 +       if (set_mask & VXSM_TOKENS_MAX)
26114 +               sched_pc->tokens_max = sched->tokens_max;
26115 +       if (set_mask & VXSM_PRIO_BIAS)
26116 +               sched_pc->prio_bias = sched->prio_bias;
26117 +
26118 +       if (set_mask & VXSM_IDLE_TIME)
26119 +               sched_pc->flags |= VXSF_IDLE_TIME;
26120 +       else
26121 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
26122 +
26123 +       /* reset time */
26124 +       sched_pc->norm_time = jiffies;
26125 +}
26126 +
26127 +
26128 +/*
26129 + * recalculate the context's scheduling tokens
26130 + *
26131 + * ret > 0 : number of tokens available
26132 + * ret < 0 : on hold, check delta_min[]
26133 + *          -1 only jiffies
26134 + *          -2 also idle time
26135 + *
26136 + */
26137 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
26138 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
26139 +{
26140 +       long delta;
26141 +       long tokens = 0;
26142 +       int flags = sched_pc->flags;
26143 +
26144 +       /* how much time did pass? */
26145 +       delta = *norm_time - sched_pc->norm_time;
26146 +       vxd_check_range(delta, 0, INT_MAX);
26147 +
26148 +       if (delta >= sched_pc->interval[0]) {
26149 +               long tokens, integral;
26150 +
26151 +               /* calc integral token part */
26152 +               tokens = delta / sched_pc->interval[0];
26153 +               integral = tokens * sched_pc->interval[0];
26154 +               tokens *= sched_pc->fill_rate[0];
26155 +#ifdef CONFIG_VSERVER_HARDCPU
26156 +               delta_min[0] = delta - integral;
26157 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
26158 +#endif
26159 +               /* advance time */
26160 +               sched_pc->norm_time += delta;
26161 +
26162 +               /* add tokens */
26163 +               sched_pc->tokens += tokens;
26164 +               sched_pc->token_time += tokens;
26165 +       } else
26166 +               delta_min[0] = delta;
26167 +
26168 +#ifdef CONFIG_VSERVER_IDLETIME
26169 +       if (!(flags & VXSF_IDLE_TIME))
26170 +               goto skip_idle;
26171 +
26172 +       /* how much was the idle skip? */
26173 +       delta = *idle_time - sched_pc->idle_time;
26174 +       vxd_check_range(delta, 0, INT_MAX);
26175 +
26176 +       if (delta >= sched_pc->interval[1]) {
26177 +               long tokens, integral;
26178 +
26179 +               /* calc fair share token part */
26180 +               tokens = delta / sched_pc->interval[1];
26181 +               integral = tokens * sched_pc->interval[1];
26182 +               tokens *= sched_pc->fill_rate[1];
26183 +               delta_min[1] = delta - integral;
26184 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
26185 +
26186 +               /* advance idle time */
26187 +               sched_pc->idle_time += integral;
26188 +
26189 +               /* add tokens */
26190 +               sched_pc->tokens += tokens;
26191 +               sched_pc->token_time += tokens;
26192 +       } else
26193 +               delta_min[1] = delta;
26194 +skip_idle:
26195 +#endif
26196 +
26197 +       /* clip at maximum */
26198 +       if (sched_pc->tokens > sched_pc->tokens_max)
26199 +               sched_pc->tokens = sched_pc->tokens_max;
26200 +       tokens = sched_pc->tokens;
26201 +
26202 +       if ((flags & VXSF_ONHOLD)) {
26203 +               /* can we unhold? */
26204 +               if (tokens >= sched_pc->tokens_min) {
26205 +                       flags &= ~VXSF_ONHOLD;
26206 +                       sched_pc->hold_ticks +=
26207 +                               *norm_time - sched_pc->onhold;
26208 +               } else
26209 +                       goto on_hold;
26210 +       } else {
26211 +               /* put on hold? */
26212 +               if (tokens <= 0) {
26213 +                       flags |= VXSF_ONHOLD;
26214 +                       sched_pc->onhold = *norm_time;
26215 +                       goto on_hold;
26216 +               }
26217 +       }
26218 +       sched_pc->flags = flags;
26219 +       return tokens;
26220 +
26221 +on_hold:
26222 +       tokens = sched_pc->tokens_min - tokens;
26223 +       sched_pc->flags = flags;
26224 +       BUG_ON(tokens < 0);
26225 +
26226 +#ifdef CONFIG_VSERVER_HARDCPU
26227 +       /* next interval? */
26228 +       if (!sched_pc->fill_rate[0])
26229 +               delta_min[0] = HZ;
26230 +       else if (tokens > sched_pc->fill_rate[0])
26231 +               delta_min[0] += sched_pc->interval[0] *
26232 +                       tokens / sched_pc->fill_rate[0];
26233 +       else
26234 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
26235 +       vxd_check_range(delta_min[0], 0, INT_MAX);
26236 +
26237 +#ifdef CONFIG_VSERVER_IDLETIME
26238 +       if (!(flags & VXSF_IDLE_TIME))
26239 +               return -1;
26240 +
26241 +       /* next interval? */
26242 +       if (!sched_pc->fill_rate[1])
26243 +               delta_min[1] = HZ;
26244 +       else if (tokens > sched_pc->fill_rate[1])
26245 +               delta_min[1] += sched_pc->interval[1] *
26246 +                       tokens / sched_pc->fill_rate[1];
26247 +       else
26248 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
26249 +       vxd_check_range(delta_min[1], 0, INT_MAX);
26250 +
26251 +       return -2;
26252 +#else
26253 +       return -1;
26254 +#endif /* CONFIG_VSERVER_IDLETIME */
26255 +#else
26256 +       return 0;
26257 +#endif /* CONFIG_VSERVER_HARDCPU */
26258 +}
26259 +
26260 +static inline unsigned long msec_to_ticks(unsigned long msec)
26261 +{
26262 +       return msecs_to_jiffies(msec);
26263 +}
26264 +
26265 +static inline unsigned long ticks_to_msec(unsigned long ticks)
26266 +{
26267 +       return jiffies_to_msecs(ticks);
26268 +}
26269 +
26270 +static inline unsigned long ticks_to_usec(unsigned long ticks)
26271 +{
26272 +       return jiffies_to_usecs(ticks);
26273 +}
26274 +
26275 +
26276 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
26277 +{
26278 +       unsigned int set_mask = data->mask;
26279 +       unsigned int update_mask;
26280 +       int i, cpu;
26281 +
26282 +       /* Sanity check data values */
26283 +       if (data->tokens_max <= 0)
26284 +               data->tokens_max = HZ;
26285 +       if (data->tokens_min < 0)
26286 +               data->tokens_min = HZ / 3;
26287 +       if (data->tokens_min >= data->tokens_max)
26288 +               data->tokens_min = data->tokens_max;
26289 +
26290 +       if (data->prio_bias > MAX_PRIO_BIAS)
26291 +               data->prio_bias = MAX_PRIO_BIAS;
26292 +       if (data->prio_bias < MIN_PRIO_BIAS)
26293 +               data->prio_bias = MIN_PRIO_BIAS;
26294 +
26295 +       spin_lock(&vxi->sched.tokens_lock);
26296 +
26297 +       /* sync up on delayed updates */
26298 +       for_each_cpu_mask(cpu, vxi->sched.update)
26299 +               vx_update_sched_param(&vxi->sched,
26300 +                       &vx_per_cpu(vxi, sched_pc, cpu));
26301 +
26302 +       if (set_mask & VXSM_FILL_RATE)
26303 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
26304 +       if (set_mask & VXSM_FILL_RATE2)
26305 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
26306 +       if (set_mask & VXSM_INTERVAL)
26307 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
26308 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
26309 +       if (set_mask & VXSM_INTERVAL2)
26310 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
26311 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
26312 +       if (set_mask & VXSM_TOKENS)
26313 +               vxi->sched.tokens = data->tokens;
26314 +       if (set_mask & VXSM_TOKENS_MIN)
26315 +               vxi->sched.tokens_min = data->tokens_min;
26316 +       if (set_mask & VXSM_TOKENS_MAX)
26317 +               vxi->sched.tokens_max = data->tokens_max;
26318 +       if (set_mask & VXSM_PRIO_BIAS)
26319 +               vxi->sched.prio_bias = data->prio_bias;
26320 +
26321 +       /* Sanity check rate/interval */
26322 +       for (i = 0; i < 2; i++) {
26323 +               if (data->fill_rate[i] < 0)
26324 +                       data->fill_rate[i] = 0;
26325 +               if (data->interval[i] <= 0)
26326 +                       data->interval[i] = HZ;
26327 +       }
26328 +
26329 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
26330 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
26331 +       vxi->sched.update_mask = update_mask;
26332 +
26333 +#ifdef CONFIG_SMP
26334 +       rmb();
26335 +       if (set_mask & VXSM_CPU_ID) {
26336 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
26337 +               cpus_and(vxi->sched.update, cpu_online_map,
26338 +                       vxi->sched.update);
26339 +       } else
26340 +               vxi->sched.update = cpu_online_map;
26341 +
26342 +       /* forced reload? */
26343 +       if (set_mask & VXSM_FORCE) {
26344 +               for_each_cpu_mask(cpu, vxi->sched.update)
26345 +                       vx_update_sched_param(&vxi->sched,
26346 +                               &vx_per_cpu(vxi, sched_pc, cpu));
26347 +               vxi->sched.update = CPU_MASK_NONE;
26348 +       }
26349 +#else
26350 +       /* on UP we update immediately */
26351 +       vx_update_sched_param(&vxi->sched,
26352 +               &vx_per_cpu(vxi, sched_pc, 0));
26353 +#endif
26354 +
26355 +       spin_unlock(&vxi->sched.tokens_lock);
26356 +       return 0;
26357 +}
26358 +
26359 +
26360 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
26361 +#define COPY_PRI(C) C(prio_bias)
26362 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26363 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
26364 +                   C(fill_rate[1]); C(interval[1]);
26365 +
26366 +#define COPY_VALUE(name) vc_data.name = data->name
26367 +
26368 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
26369 +{
26370 +       struct vcmd_sched_v5 vc_data;
26371 +
26372 +       vc_data.mask = data->set_mask;
26373 +       COPY_IDS(COPY_VALUE);
26374 +       COPY_PRI(COPY_VALUE);
26375 +       COPY_TOK(COPY_VALUE);
26376 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
26377 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
26378 +       return do_set_sched(vxi, &vc_data);
26379 +}
26380 +
26381 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
26382 +{
26383 +       struct vcmd_set_sched_v4 vc_data;
26384 +
26385 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26386 +               return -EFAULT;
26387 +
26388 +       return do_set_sched_v4(vxi, &vc_data);
26389 +}
26390 +
26391 +       /* latest interface is v5 */
26392 +
26393 +int vc_set_sched(struct vx_info *vxi, void __user *data)
26394 +{
26395 +       struct vcmd_sched_v5 vc_data;
26396 +
26397 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26398 +               return -EFAULT;
26399 +
26400 +       return do_set_sched(vxi, &vc_data);
26401 +}
26402 +
26403 +
26404 +#define COPY_PRI(C) C(prio_bias)
26405 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26406 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
26407 +                   C(fill_rate[1]); C(interval[1]);
26408 +
26409 +#define COPY_VALUE(name) vc_data.name = data->name
26410 +
26411 +
26412 +int vc_get_sched(struct vx_info *vxi, void __user *data)
26413 +{
26414 +       struct vcmd_sched_v5 vc_data;
26415 +
26416 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26417 +               return -EFAULT;
26418 +
26419 +       if (vc_data.mask & VXSM_CPU_ID) {
26420 +               int cpu = vc_data.cpu_id;
26421 +               struct _vx_sched_pc *data;
26422 +
26423 +               if (!cpu_possible(cpu))
26424 +                       return -EINVAL;
26425 +
26426 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
26427 +               COPY_TOK(COPY_VALUE);
26428 +               COPY_PRI(COPY_VALUE);
26429 +               COPY_FRI(COPY_VALUE);
26430 +
26431 +               if (data->flags & VXSF_IDLE_TIME)
26432 +                       vc_data.mask |= VXSM_IDLE_TIME;
26433 +       } else {
26434 +               struct _vx_sched *data = &vxi->sched;
26435 +
26436 +               COPY_TOK(COPY_VALUE);
26437 +               COPY_PRI(COPY_VALUE);
26438 +               COPY_FRI(COPY_VALUE);
26439 +       }
26440 +
26441 +       if (vc_data.mask & VXSM_MSEC) {
26442 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
26443 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
26444 +       }
26445 +
26446 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26447 +               return -EFAULT;
26448 +       return 0;
26449 +}
26450 +
26451 +
26452 +int vc_sched_info(struct vx_info *vxi, void __user *data)
26453 +{
26454 +       struct vcmd_sched_info vc_data;
26455 +       int cpu;
26456 +
26457 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26458 +               return -EFAULT;
26459 +
26460 +       cpu = vc_data.cpu_id;
26461 +       if (!cpu_possible(cpu))
26462 +               return -EINVAL;
26463 +
26464 +       if (vxi) {
26465 +               struct _vx_sched_pc *sched_pc =
26466 +                       &vx_per_cpu(vxi, sched_pc, cpu);
26467 +
26468 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
26469 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
26470 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
26471 +               vc_data.vavavoom = sched_pc->vavavoom;
26472 +       }
26473 +       vc_data.token_usec = ticks_to_usec(1);
26474 +
26475 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26476 +               return -EFAULT;
26477 +       return 0;
26478 +}
26479 +
26480 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
26481 --- linux-2.6.22.10/kernel/vserver/sched_init.h 1970-01-01 01:00:00 +0100
26482 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched_init.h      2007-08-05 20:53:13 +0200
26483 @@ -0,0 +1,50 @@
26484 +
26485 +static inline void vx_info_init_sched(struct _vx_sched *sched)
26486 +{
26487 +       static struct lock_class_key tokens_lock_key;
26488 +
26489 +       /* scheduling; hard code starting values as constants */
26490 +       sched->fill_rate[0]     = 1;
26491 +       sched->interval[0]      = 4;
26492 +       sched->fill_rate[1]     = 1;
26493 +       sched->interval[1]      = 8;
26494 +       sched->tokens           = HZ >> 2;
26495 +       sched->tokens_min       = HZ >> 4;
26496 +       sched->tokens_max       = HZ >> 1;
26497 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
26498 +       sched->prio_bias        = 0;
26499 +
26500 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
26501 +}
26502 +
26503 +static inline
26504 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26505 +{
26506 +       sched_pc->fill_rate[0]  = 1;
26507 +       sched_pc->interval[0]   = 4;
26508 +       sched_pc->fill_rate[1]  = 1;
26509 +       sched_pc->interval[1]   = 8;
26510 +       sched_pc->tokens        = HZ >> 2;
26511 +       sched_pc->tokens_min    = HZ >> 4;
26512 +       sched_pc->tokens_max    = HZ >> 1;
26513 +       sched_pc->prio_bias     = 0;
26514 +       sched_pc->vavavoom      = 0;
26515 +       sched_pc->token_time    = 0;
26516 +       sched_pc->idle_time     = 0;
26517 +       sched_pc->norm_time     = jiffies;
26518 +
26519 +       sched_pc->user_ticks = 0;
26520 +       sched_pc->sys_ticks = 0;
26521 +       sched_pc->hold_ticks = 0;
26522 +}
26523 +
26524 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
26525 +{
26526 +       return;
26527 +}
26528 +
26529 +static inline
26530 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26531 +{
26532 +       return;
26533 +}
26534 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
26535 --- linux-2.6.22.10/kernel/vserver/sched_proc.h 1970-01-01 01:00:00 +0100
26536 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched_proc.h      2007-08-05 20:53:13 +0200
26537 @@ -0,0 +1,57 @@
26538 +#ifndef _VX_SCHED_PROC_H
26539 +#define _VX_SCHED_PROC_H
26540 +
26541 +
26542 +static inline
26543 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
26544 +{
26545 +       int length = 0;
26546 +
26547 +       length += sprintf(buffer,
26548 +               "FillRate:\t%8d,%d\n"
26549 +               "Interval:\t%8d,%d\n"
26550 +               "TokensMin:\t%8d\n"
26551 +               "TokensMax:\t%8d\n"
26552 +               "PrioBias:\t%8d\n",
26553 +               sched->fill_rate[0],
26554 +               sched->fill_rate[1],
26555 +               sched->interval[0],
26556 +               sched->interval[1],
26557 +               sched->tokens_min,
26558 +               sched->tokens_max,
26559 +               sched->prio_bias);
26560 +       return length;
26561 +}
26562 +
26563 +static inline
26564 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
26565 +       char *buffer, int cpu)
26566 +{
26567 +       int length = 0;
26568 +
26569 +       length += sprintf(buffer + length,
26570 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
26571 +               (unsigned long long)sched_pc->user_ticks,
26572 +               (unsigned long long)sched_pc->sys_ticks,
26573 +               (unsigned long long)sched_pc->hold_ticks,
26574 +               sched_pc->token_time,
26575 +               sched_pc->idle_time);
26576 +       length += sprintf(buffer + length,
26577 +               " %c%c %d %d %d %d/%d %d/%d",
26578 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
26579 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
26580 +               sched_pc->tokens,
26581 +               sched_pc->tokens_min,
26582 +               sched_pc->tokens_max,
26583 +               sched_pc->fill_rate[0],
26584 +               sched_pc->interval[0],
26585 +               sched_pc->fill_rate[1],
26586 +               sched_pc->interval[1]);
26587 +       length += sprintf(buffer + length,
26588 +               " %d %d\n",
26589 +               sched_pc->prio_bias,
26590 +               sched_pc->vavavoom);
26591 +       return length;
26592 +}
26593 +
26594 +#endif /* _VX_SCHED_PROC_H */
26595 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
26596 --- linux-2.6.22.10/kernel/vserver/signal.c     1970-01-01 01:00:00 +0100
26597 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/signal.c  2007-08-15 23:34:41 +0200
26598 @@ -0,0 +1,131 @@
26599 +/*
26600 + *  linux/kernel/vserver/signal.c
26601 + *
26602 + *  Virtual Server: Signal Support
26603 + *
26604 + *  Copyright (C) 2003-2007  Herbert Pötzl
26605 + *
26606 + *  V0.01  broken out from vcontext V0.05
26607 + *  V0.02  changed vcmds to vxi arg
26608 + *  V0.03  adjusted siginfo for kill
26609 + *
26610 + */
26611 +
26612 +#include <asm/uaccess.h>
26613 +
26614 +#include <linux/vs_context.h>
26615 +#include <linux/vserver/signal_cmd.h>
26616 +
26617 +
26618 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
26619 +{
26620 +       int retval, count = 0;
26621 +       struct task_struct *p;
26622 +       struct siginfo *sip = SEND_SIG_PRIV;
26623 +
26624 +       retval = -ESRCH;
26625 +       vxdprintk(VXD_CBIT(misc, 4),
26626 +               "vx_info_kill(%p[#%d],%d,%d)*",
26627 +               vxi, vxi->vx_id, pid, sig);
26628 +       read_lock(&tasklist_lock);
26629 +       switch (pid) {
26630 +       case  0:
26631 +       case -1:
26632 +               for_each_process(p) {
26633 +                       int err = 0;
26634 +
26635 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
26636 +                               (pid && vxi->vx_initpid == p->pid))
26637 +                               continue;
26638 +
26639 +                       err = group_send_sig_info(sig, sip, p);
26640 +                       ++count;
26641 +                       if (err != -EPERM)
26642 +                               retval = err;
26643 +               }
26644 +               break;
26645 +
26646 +       case 1:
26647 +               if (vxi->vx_initpid) {
26648 +                       pid = vxi->vx_initpid;
26649 +                       /* for now, only SIGINT to private init ... */
26650 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26651 +                               /* ... as long as there are tasks left */
26652 +                               (atomic_read(&vxi->vx_tasks) > 1))
26653 +                               sig = SIGINT;
26654 +               }
26655 +               /* fallthrough */
26656 +       default:
26657 +               p = find_task_by_real_pid(pid);
26658 +               if (p) {
26659 +                       if (vx_task_xid(p) == vxi->vx_id)
26660 +                               retval = group_send_sig_info(sig, sip, p);
26661 +               }
26662 +               break;
26663 +       }
26664 +       read_unlock(&tasklist_lock);
26665 +       vxdprintk(VXD_CBIT(misc, 4),
26666 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
26667 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
26668 +       return retval;
26669 +}
26670 +
26671 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
26672 +{
26673 +       struct vcmd_ctx_kill_v0 vc_data;
26674 +
26675 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26676 +               return -EFAULT;
26677 +
26678 +       /* special check to allow guest shutdown */
26679 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26680 +               /* forbid killall pid=0 when init is present */
26681 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
26682 +               (vc_data.pid > 1)))
26683 +               return -EACCES;
26684 +
26685 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
26686 +}
26687 +
26688 +
26689 +static int __wait_exit(struct vx_info *vxi)
26690 +{
26691 +       DECLARE_WAITQUEUE(wait, current);
26692 +       int ret = 0;
26693 +
26694 +       add_wait_queue(&vxi->vx_wait, &wait);
26695 +       set_current_state(TASK_INTERRUPTIBLE);
26696 +
26697 +wait:
26698 +       if (vx_info_state(vxi,
26699 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
26700 +               goto out;
26701 +       if (signal_pending(current)) {
26702 +               ret = -ERESTARTSYS;
26703 +               goto out;
26704 +       }
26705 +       schedule();
26706 +       goto wait;
26707 +
26708 +out:
26709 +       set_current_state(TASK_RUNNING);
26710 +       remove_wait_queue(&vxi->vx_wait, &wait);
26711 +       return ret;
26712 +}
26713 +
26714 +
26715 +
26716 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
26717 +{
26718 +       struct vcmd_wait_exit_v0 vc_data;
26719 +       int ret;
26720 +
26721 +       ret = __wait_exit(vxi);
26722 +       vc_data.reboot_cmd = vxi->reboot_cmd;
26723 +       vc_data.exit_code = vxi->exit_code;
26724 +
26725 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26726 +               ret = -EFAULT;
26727 +       return ret;
26728 +}
26729 +
26730 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
26731 --- linux-2.6.22.10/kernel/vserver/space.c      1970-01-01 01:00:00 +0100
26732 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/space.c   2007-08-15 23:39:13 +0200
26733 @@ -0,0 +1,277 @@
26734 +/*
26735 + *  linux/kernel/vserver/space.c
26736 + *
26737 + *  Virtual Server: Context Space Support
26738 + *
26739 + *  Copyright (C) 2003-2007  Herbert Pötzl
26740 + *
26741 + *  V0.01  broken out from context.c 0.07
26742 + *  V0.02  added task locking for namespace
26743 + *  V0.03  broken out vx_enter_namespace
26744 + *  V0.04  added *space support and commands
26745 + *
26746 + */
26747 +
26748 +#include <linux/utsname.h>
26749 +#include <linux/nsproxy.h>
26750 +#include <linux/err.h>
26751 +#include <asm/uaccess.h>
26752 +
26753 +#include <linux/vs_context.h>
26754 +#include <linux/vserver/space.h>
26755 +#include <linux/vserver/space_cmd.h>
26756 +
26757 +
26758 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
26759 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
26760 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
26761 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
26762 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
26763 +
26764 +
26765 +/* namespace functions */
26766 +
26767 +#include <linux/mnt_namespace.h>
26768 +
26769 +const struct vcmd_space_mask space_mask = {
26770 +       .mask = CLONE_NEWNS |
26771 +               CLONE_NEWUTS |
26772 +               CLONE_NEWIPC |
26773 +               CLONE_FS
26774 +};
26775 +
26776 +
26777 +/*
26778 + *     build a new nsproxy mix
26779 + *      assumes that both proxies are 'const'
26780 + *     does not touch nsproxy refcounts
26781 + *     will hold a reference on the result.
26782 + */
26783 +
26784 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
26785 +       struct nsproxy *new_nsproxy, unsigned long mask)
26786 +{
26787 +       struct mnt_namespace *old_ns;
26788 +       struct uts_namespace *old_uts;
26789 +       struct ipc_namespace *old_ipc;
26790 +       struct nsproxy *nsproxy;
26791 +
26792 +       nsproxy = copy_nsproxy(old_nsproxy);
26793 +       if (!nsproxy)
26794 +               goto out;
26795 +
26796 +       if (mask & CLONE_NEWNS) {
26797 +               old_ns = nsproxy->mnt_ns;
26798 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
26799 +               if (nsproxy->mnt_ns)
26800 +                       get_mnt_ns(nsproxy->mnt_ns);
26801 +       } else
26802 +               old_ns = NULL;
26803 +
26804 +       if (mask & CLONE_NEWUTS) {
26805 +               old_uts = nsproxy->uts_ns;
26806 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
26807 +               if (nsproxy->uts_ns)
26808 +                       get_uts_ns(nsproxy->uts_ns);
26809 +       } else
26810 +               old_uts = NULL;
26811 +
26812 +       if (mask & CLONE_NEWIPC) {
26813 +               old_ipc = nsproxy->ipc_ns;
26814 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
26815 +               if (nsproxy->ipc_ns)
26816 +                       get_ipc_ns(nsproxy->ipc_ns);
26817 +       } else
26818 +               old_ipc = NULL;
26819 +
26820 +       if (old_ns)
26821 +               put_mnt_ns(old_ns);
26822 +       if (old_uts)
26823 +               put_uts_ns(old_uts);
26824 +       if (old_ipc)
26825 +               put_ipc_ns(old_ipc);
26826 +out:
26827 +       return nsproxy;
26828 +}
26829 +
26830 +
26831 +/*
26832 + *     merge two nsproxy structs into a new one.
26833 + *     will hold a reference on the result.
26834 + */
26835 +
26836 +static inline
26837 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
26838 +       struct nsproxy *proxy, unsigned long mask)
26839 +{
26840 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
26841 +
26842 +       if (!proxy)
26843 +               return NULL;
26844 +
26845 +       if (mask) {
26846 +               /* vs_mix_nsproxy returns with reference */
26847 +               return vs_mix_nsproxy(old ? old : &null_proxy,
26848 +                       proxy, mask);
26849 +       }
26850 +       get_nsproxy(proxy);
26851 +       return proxy;
26852 +}
26853 +
26854 +/*
26855 + *     merge two fs structs into a new one.
26856 + *     will take a reference on the result.
26857 + */
26858 +
26859 +static inline
26860 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
26861 +       struct fs_struct *fs, unsigned long mask)
26862 +{
26863 +       if (!(mask & CLONE_FS)) {
26864 +               if (old)
26865 +                       atomic_inc(&old->count);
26866 +               return old;
26867 +       }
26868 +
26869 +       if (!fs)
26870 +               return NULL;
26871 +
26872 +       return copy_fs_struct(fs);
26873 +}
26874 +
26875 +
26876 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
26877 +{
26878 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
26879 +       struct fs_struct *fs, *fs_cur, *fs_new;
26880 +       int ret;
26881 +
26882 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
26883 +               return -EACCES;
26884 +
26885 +       if (!mask)
26886 +               mask = vxi->vx_nsmask;
26887 +
26888 +       if ((mask & vxi->vx_nsmask) != mask)
26889 +               return -EINVAL;
26890 +
26891 +       proxy = vxi->vx_nsproxy;
26892 +       fs = vxi->vx_fs;
26893 +
26894 +       task_lock(current);
26895 +       fs_cur = current->fs;
26896 +       atomic_inc(&fs_cur->count);
26897 +       proxy_cur = current->nsproxy;
26898 +       get_nsproxy(proxy_cur);
26899 +       task_unlock(current);
26900 +
26901 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
26902 +       if (IS_ERR(fs_new)) {
26903 +               ret = PTR_ERR(fs_new);
26904 +               goto out_put;
26905 +       }
26906 +
26907 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
26908 +       if (IS_ERR(proxy_new)) {
26909 +               ret = PTR_ERR(proxy_new);
26910 +               goto out_put_fs;
26911 +       }
26912 +
26913 +       fs_new = xchg(&current->fs, fs_new);
26914 +       proxy_new = xchg(&current->nsproxy, proxy_new);
26915 +       ret = 0;
26916 +
26917 +       if (proxy_new)
26918 +               put_nsproxy(proxy_new);
26919 +out_put_fs:
26920 +       if (fs_new)
26921 +               put_fs_struct(fs_new);
26922 +out_put:
26923 +       if (proxy_cur)
26924 +               put_nsproxy(proxy_cur);
26925 +       if (fs_cur)
26926 +               put_fs_struct(fs_cur);
26927 +       return ret;
26928 +}
26929 +
26930 +
26931 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
26932 +{
26933 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
26934 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
26935 +       int ret;
26936 +
26937 +       if (!mask)
26938 +               mask = space_mask.mask;
26939 +
26940 +       if ((mask & space_mask.mask) != mask)
26941 +               return -EINVAL;
26942 +
26943 +       proxy_vxi = vxi->vx_nsproxy;
26944 +       fs_vxi = vxi->vx_fs;
26945 +
26946 +       task_lock(current);
26947 +       fs_cur = current->fs;
26948 +       atomic_inc(&fs_cur->count);
26949 +       proxy_cur = current->nsproxy;
26950 +       get_nsproxy(proxy_cur);
26951 +       task_unlock(current);
26952 +
26953 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
26954 +       if (IS_ERR(fs_new)) {
26955 +               ret = PTR_ERR(fs_new);
26956 +               goto out_put;
26957 +       }
26958 +
26959 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
26960 +       if (IS_ERR(proxy_new)) {
26961 +               ret = PTR_ERR(proxy_new);
26962 +               goto out_put_fs;
26963 +       }
26964 +
26965 +       fs_new = xchg(&vxi->vx_fs, fs_new);
26966 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
26967 +       vxi->vx_nsmask |= mask;
26968 +       ret = 0;
26969 +
26970 +       if (proxy_new)
26971 +               put_nsproxy(proxy_new);
26972 +out_put_fs:
26973 +       if (fs_new)
26974 +               put_fs_struct(fs_new);
26975 +out_put:
26976 +       if (proxy_cur)
26977 +               put_nsproxy(proxy_cur);
26978 +       if (fs_cur)
26979 +               put_fs_struct(fs_cur);
26980 +       return ret;
26981 +}
26982 +
26983 +
26984 +int vc_enter_space(struct vx_info *vxi, void __user *data)
26985 +{
26986 +       struct vcmd_space_mask vc_data = { .mask = 0 };
26987 +
26988 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26989 +               return -EFAULT;
26990 +
26991 +       return vx_enter_space(vxi, vc_data.mask);
26992 +}
26993 +
26994 +int vc_set_space(struct vx_info *vxi, void __user *data)
26995 +{
26996 +       struct vcmd_space_mask vc_data = { .mask = 0 };
26997 +
26998 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26999 +               return -EFAULT;
27000 +
27001 +       return vx_set_space(vxi, vc_data.mask);
27002 +}
27003 +
27004 +int vc_get_space_mask(struct vx_info *vxi, void __user *data)
27005 +{
27006 +       if (copy_to_user(data, &space_mask, sizeof(space_mask)))
27007 +               return -EFAULT;
27008 +       return 0;
27009 +}
27010 +
27011 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
27012 --- linux-2.6.22.10/kernel/vserver/switch.c     1970-01-01 01:00:00 +0100
27013 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/switch.c  2007-10-25 17:05:55 +0200
27014 @@ -0,0 +1,529 @@
27015 +/*
27016 + *  linux/kernel/vserver/switch.c
27017 + *
27018 + *  Virtual Server: Syscall Switch
27019 + *
27020 + *  Copyright (C) 2003-2007  Herbert Pötzl
27021 + *
27022 + *  V0.01  syscall switch
27023 + *  V0.02  added signal to context
27024 + *  V0.03  added rlimit functions
27025 + *  V0.04  added iattr, task/xid functions
27026 + *  V0.05  added debug/history stuff
27027 + *  V0.06  added compat32 layer
27028 + *  V0.07  vcmd args and perms
27029 + *  V0.08  added status commands
27030 + *  V0.09  added tag commands
27031 + *  V0.10  added oom bias
27032 + *  V0.11  added device commands
27033 + *
27034 + */
27035 +
27036 +#include <linux/vs_context.h>
27037 +#include <linux/vs_network.h>
27038 +#include <linux/vserver/switch.h>
27039 +
27040 +#include "vci_config.h"
27041 +
27042 +
27043 +static inline
27044 +int vc_get_version(uint32_t id)
27045 +{
27046 +       return VCI_VERSION;
27047 +}
27048 +
27049 +static inline
27050 +int vc_get_vci(uint32_t id)
27051 +{
27052 +       return vci_kernel_config();
27053 +}
27054 +
27055 +#include <linux/vserver/context_cmd.h>
27056 +#include <linux/vserver/cvirt_cmd.h>
27057 +#include <linux/vserver/cacct_cmd.h>
27058 +#include <linux/vserver/limit_cmd.h>
27059 +#include <linux/vserver/network_cmd.h>
27060 +#include <linux/vserver/sched_cmd.h>
27061 +#include <linux/vserver/debug_cmd.h>
27062 +#include <linux/vserver/inode_cmd.h>
27063 +#include <linux/vserver/dlimit_cmd.h>
27064 +#include <linux/vserver/signal_cmd.h>
27065 +#include <linux/vserver/space_cmd.h>
27066 +#include <linux/vserver/tag_cmd.h>
27067 +#include <linux/vserver/device_cmd.h>
27068 +
27069 +#include <linux/vserver/inode.h>
27070 +#include <linux/vserver/dlimit.h>
27071 +
27072 +
27073 +#ifdef CONFIG_COMPAT
27074 +#define __COMPAT(name, id, data, compat)       \
27075 +       (compat) ? name ## _x32(id, data) : name(id, data)
27076 +#define __COMPAT_NO_ID(name, data, compat)     \
27077 +       (compat) ? name ## _x32(data) : name(data)
27078 +#else
27079 +#define __COMPAT(name, id, data, compat)       \
27080 +       name(id, data)
27081 +#define __COMPAT_NO_ID(name, data, compat)     \
27082 +       name(data)
27083 +#endif
27084 +
27085 +
27086 +static inline
27087 +long do_vcmd(uint32_t cmd, uint32_t id,
27088 +       struct vx_info *vxi, struct nx_info *nxi,
27089 +       void __user *data, int compat)
27090 +{
27091 +       switch (cmd) {
27092 +
27093 +       case VCMD_get_version:
27094 +               return vc_get_version(id);
27095 +       case VCMD_get_vci:
27096 +               return vc_get_vci(id);
27097 +
27098 +       case VCMD_task_xid:
27099 +               return vc_task_xid(id);
27100 +       case VCMD_vx_info:
27101 +               return vc_vx_info(vxi, data);
27102 +
27103 +       case VCMD_task_nid:
27104 +               return vc_task_nid(id);
27105 +       case VCMD_nx_info:
27106 +               return vc_nx_info(nxi, data);
27107 +
27108 +       case VCMD_task_tag:
27109 +               return vc_task_tag(id);
27110 +
27111 +       /* this is version 1 */
27112 +       case VCMD_set_space:
27113 +               return vc_set_space(vxi, data);
27114 +
27115 +       case VCMD_get_space_mask:
27116 +               return vc_get_space_mask(vxi, data);
27117 +
27118 +#ifdef CONFIG_IA32_EMULATION
27119 +       case VCMD_get_rlimit:
27120 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
27121 +       case VCMD_set_rlimit:
27122 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
27123 +#else
27124 +       case VCMD_get_rlimit:
27125 +               return vc_get_rlimit(vxi, data);
27126 +       case VCMD_set_rlimit:
27127 +               return vc_set_rlimit(vxi, data);
27128 +#endif
27129 +       case VCMD_get_rlimit_mask:
27130 +               return vc_get_rlimit_mask(id, data);
27131 +       case VCMD_reset_minmax:
27132 +               return vc_reset_minmax(vxi, data);
27133 +
27134 +       case VCMD_get_vhi_name:
27135 +               return vc_get_vhi_name(vxi, data);
27136 +       case VCMD_set_vhi_name:
27137 +               return vc_set_vhi_name(vxi, data);
27138 +
27139 +       case VCMD_ctx_stat:
27140 +               return vc_ctx_stat(vxi, data);
27141 +       case VCMD_virt_stat:
27142 +               return vc_virt_stat(vxi, data);
27143 +       case VCMD_sock_stat:
27144 +               return vc_sock_stat(vxi, data);
27145 +       case VCMD_rlimit_stat:
27146 +               return vc_rlimit_stat(vxi, data);
27147 +
27148 +       case VCMD_set_cflags:
27149 +               return vc_set_cflags(vxi, data);
27150 +       case VCMD_get_cflags:
27151 +               return vc_get_cflags(vxi, data);
27152 +
27153 +       /* this is version 1 */
27154 +       case VCMD_set_ccaps:
27155 +               return vc_set_ccaps(vxi, data);
27156 +       /* this is version 1 */
27157 +       case VCMD_get_ccaps:
27158 +               return vc_get_ccaps(vxi, data);
27159 +       case VCMD_set_bcaps:
27160 +               return vc_set_bcaps(vxi, data);
27161 +       case VCMD_get_bcaps:
27162 +               return vc_get_bcaps(vxi, data);
27163 +
27164 +       case VCMD_set_badness:
27165 +               return vc_set_badness(vxi, data);
27166 +       case VCMD_get_badness:
27167 +               return vc_get_badness(vxi, data);
27168 +
27169 +       case VCMD_set_nflags:
27170 +               return vc_set_nflags(nxi, data);
27171 +       case VCMD_get_nflags:
27172 +               return vc_get_nflags(nxi, data);
27173 +
27174 +       case VCMD_set_ncaps:
27175 +               return vc_set_ncaps(nxi, data);
27176 +       case VCMD_get_ncaps:
27177 +               return vc_get_ncaps(nxi, data);
27178 +
27179 +       case VCMD_set_sched_v4:
27180 +               return vc_set_sched_v4(vxi, data);
27181 +       /* this is version 5 */
27182 +       case VCMD_set_sched:
27183 +               return vc_set_sched(vxi, data);
27184 +       case VCMD_get_sched:
27185 +               return vc_get_sched(vxi, data);
27186 +       case VCMD_sched_info:
27187 +               return vc_sched_info(vxi, data);
27188 +
27189 +       case VCMD_add_dlimit:
27190 +               return __COMPAT(vc_add_dlimit, id, data, compat);
27191 +       case VCMD_rem_dlimit:
27192 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
27193 +       case VCMD_set_dlimit:
27194 +               return __COMPAT(vc_set_dlimit, id, data, compat);
27195 +       case VCMD_get_dlimit:
27196 +               return __COMPAT(vc_get_dlimit, id, data, compat);
27197 +
27198 +       case VCMD_ctx_kill:
27199 +               return vc_ctx_kill(vxi, data);
27200 +
27201 +       case VCMD_wait_exit:
27202 +               return vc_wait_exit(vxi, data);
27203 +
27204 +       case VCMD_get_iattr:
27205 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
27206 +       case VCMD_set_iattr:
27207 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
27208 +
27209 +       case VCMD_fget_iattr:
27210 +               return vc_fget_iattr(id, data);
27211 +       case VCMD_fset_iattr:
27212 +               return vc_fset_iattr(id, data);
27213 +
27214 +       case VCMD_enter_space_v0:
27215 +               return vc_enter_space(vxi, NULL);
27216 +       /* this is version 1 */
27217 +       case VCMD_enter_space:
27218 +               return vc_enter_space(vxi, data);
27219 +
27220 +       case VCMD_ctx_create_v0:
27221 +               return vc_ctx_create(id, NULL);
27222 +       case VCMD_ctx_create:
27223 +               return vc_ctx_create(id, data);
27224 +       case VCMD_ctx_migrate_v0:
27225 +               return vc_ctx_migrate(vxi, NULL);
27226 +       case VCMD_ctx_migrate:
27227 +               return vc_ctx_migrate(vxi, data);
27228 +
27229 +       case VCMD_net_create_v0:
27230 +               return vc_net_create(id, NULL);
27231 +       case VCMD_net_create:
27232 +               return vc_net_create(id, data);
27233 +       case VCMD_net_migrate:
27234 +               return vc_net_migrate(nxi, data);
27235 +
27236 +       case VCMD_tag_migrate:
27237 +               return vc_tag_migrate(id);
27238 +
27239 +       case VCMD_net_add:
27240 +               return vc_net_add(nxi, data);
27241 +       case VCMD_net_remove:
27242 +               return vc_net_remove(nxi, data);
27243 +
27244 +       case VCMD_net_add_ipv4:
27245 +               return vc_net_add_ipv4(nxi, data);
27246 +       case VCMD_net_remove_ipv4:
27247 +               return vc_net_remove_ipv4(nxi, data);
27248 +#ifdef CONFIG_IPV6
27249 +       case VCMD_net_add_ipv6:
27250 +               return vc_net_add_ipv6(nxi, data);
27251 +       case VCMD_net_remove_ipv6:
27252 +               return vc_net_remove_ipv6(nxi, data);
27253 +#endif
27254 +/*     case VCMD_add_match_ipv4:
27255 +               return vc_add_match_ipv4(nxi, data);
27256 +       case VCMD_get_match_ipv4:
27257 +               return vc_get_match_ipv4(nxi, data);
27258 +#ifdef CONFIG_IPV6
27259 +       case VCMD_add_match_ipv6:
27260 +               return vc_add_match_ipv6(nxi, data);
27261 +       case VCMD_get_match_ipv6:
27262 +               return vc_get_match_ipv6(nxi, data);
27263 +#endif */
27264 +
27265 +#ifdef CONFIG_VSERVER_DEVICE
27266 +       case VCMD_set_mapping:
27267 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
27268 +       case VCMD_unset_mapping:
27269 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
27270 +#endif
27271 +#ifdef CONFIG_VSERVER_HISTORY
27272 +       case VCMD_dump_history:
27273 +               return vc_dump_history(id);
27274 +       case VCMD_read_history:
27275 +               return __COMPAT(vc_read_history, id, data, compat);
27276 +#endif
27277 +#ifdef CONFIG_VSERVER_MONITOR
27278 +       case VCMD_read_monitor:
27279 +               return __COMPAT(vc_read_monitor, id, data, compat);
27280 +#endif
27281 +       default:
27282 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
27283 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
27284 +       }
27285 +       return -ENOSYS;
27286 +}
27287 +
27288 +
27289 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
27290 +       case VCMD_ ## vcmd: perm = _perm;               \
27291 +               args = _args; flags = _flags; break
27292 +
27293 +
27294 +#define VCA_NONE       0x00
27295 +#define VCA_VXI                0x01
27296 +#define VCA_NXI                0x02
27297 +
27298 +#define VCF_NONE       0x00
27299 +#define VCF_INFO       0x01
27300 +#define VCF_ADMIN      0x02
27301 +#define VCF_ARES       0x06    /* includes admin */
27302 +#define VCF_SETUP      0x08
27303 +
27304 +#define VCF_ZIDOK      0x10    /* zero id okay */
27305 +
27306 +
27307 +static inline
27308 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
27309 +{
27310 +       long ret;
27311 +       int permit = -1, state = 0;
27312 +       int perm = -1, args = 0, flags = 0;
27313 +       struct vx_info *vxi = NULL;
27314 +       struct nx_info *nxi = NULL;
27315 +
27316 +       switch (cmd) {
27317 +       /* unpriviledged commands */
27318 +       __VCMD(get_version,      0, VCA_NONE,   0);
27319 +       __VCMD(get_vci,          0, VCA_NONE,   0);
27320 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
27321 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
27322 +
27323 +       /* info commands */
27324 +       __VCMD(task_xid,         2, VCA_NONE,   0);
27325 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
27326 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
27327 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
27328 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
27329 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
27330 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
27331 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
27332 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
27333 +
27334 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
27335 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
27336 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
27337 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
27338 +
27339 +       __VCMD(task_nid,         2, VCA_NONE,   0);
27340 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
27341 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
27342 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
27343 +
27344 +       __VCMD(task_tag,         2, VCA_NONE,   0);
27345 +
27346 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
27347 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
27348 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
27349 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
27350 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
27351 +
27352 +       /* lower admin commands */
27353 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
27354 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
27355 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
27356 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
27357 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
27358 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
27359 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
27360 +
27361 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
27362 +       __VCMD(net_create,       5, VCA_NONE,   0);
27363 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
27364 +
27365 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
27366 +
27367 +       /* higher admin commands */
27368 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
27369 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27370 +
27371 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27372 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27373 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27374 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27375 +
27376 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27377 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27378 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27379 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27380 +
27381 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27382 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27383 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27384 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27385 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27386 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27387 +#ifdef CONFIG_IPV6
27388 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27389 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27390 +#endif
27391 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
27392 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
27393 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
27394 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
27395 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
27396 +
27397 +#ifdef CONFIG_VSERVER_DEVICE
27398 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27399 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27400 +#endif
27401 +       /* debug level admin commands */
27402 +#ifdef CONFIG_VSERVER_HISTORY
27403 +       __VCMD(dump_history,     9, VCA_NONE,   0);
27404 +       __VCMD(read_history,     9, VCA_NONE,   0);
27405 +#endif
27406 +#ifdef CONFIG_VSERVER_MONITOR
27407 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
27408 +#endif
27409 +
27410 +       default:
27411 +               perm = -1;
27412 +       }
27413 +
27414 +       vxdprintk(VXD_CBIT(switch, 0),
27415 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
27416 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27417 +               VC_VERSION(cmd), id, data, compat,
27418 +               perm, args, flags);
27419 +
27420 +       ret = -ENOSYS;
27421 +       if (perm < 0)
27422 +               goto out;
27423 +
27424 +       state = 1;
27425 +       if (!capable(CAP_CONTEXT))
27426 +               goto out;
27427 +
27428 +       state = 2;
27429 +       /* moved here from the individual commands */
27430 +       ret = -EPERM;
27431 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
27432 +               goto out;
27433 +
27434 +       state = 3;
27435 +       /* vcmd involves resource management  */
27436 +       ret = -EPERM;
27437 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
27438 +               goto out;
27439 +
27440 +       state = 4;
27441 +       /* various legacy exceptions */
27442 +       switch (cmd) {
27443 +       /* will go away when spectator is a cap */
27444 +       case VCMD_ctx_migrate_v0:
27445 +       case VCMD_ctx_migrate:
27446 +               if (id == 1) {
27447 +                       current->xid = 1;
27448 +                       ret = 1;
27449 +                       goto out;
27450 +               }
27451 +               break;
27452 +
27453 +       /* will go away when spectator is a cap */
27454 +       case VCMD_net_migrate:
27455 +               if (id == 1) {
27456 +                       current->nid = 1;
27457 +                       ret = 1;
27458 +                       goto out;
27459 +               }
27460 +               break;
27461 +       }
27462 +
27463 +       /* vcmds are fine by default */
27464 +       permit = 1;
27465 +
27466 +       /* admin type vcmds require admin ... */
27467 +       if (flags & VCF_ADMIN)
27468 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
27469 +
27470 +       /* ... but setup type vcmds override that */
27471 +       if (!permit && (flags & VCF_SETUP))
27472 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
27473 +
27474 +       state = 5;
27475 +       ret = -EPERM;
27476 +       if (!permit)
27477 +               goto out;
27478 +
27479 +       state = 6;
27480 +       if (!id && (flags & VCF_ZIDOK))
27481 +               goto skip_id;
27482 +
27483 +       ret = -ESRCH;
27484 +       if (args & VCA_VXI) {
27485 +               vxi = lookup_vx_info(id);
27486 +               if (!vxi)
27487 +                       goto out;
27488 +
27489 +               if ((flags & VCF_ADMIN) &&
27490 +                       /* special case kill for shutdown */
27491 +                       (cmd != VCMD_ctx_kill) &&
27492 +                       /* can context be administrated? */
27493 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
27494 +                       ret = -EACCES;
27495 +                       goto out_vxi;
27496 +               }
27497 +       }
27498 +       state = 7;
27499 +       if (args & VCA_NXI) {
27500 +               nxi = lookup_nx_info(id);
27501 +               if (!nxi)
27502 +                       goto out_vxi;
27503 +
27504 +               if ((flags & VCF_ADMIN) &&
27505 +                       /* can context be administrated? */
27506 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
27507 +                       ret = -EACCES;
27508 +                       goto out_nxi;
27509 +               }
27510 +       }
27511 +skip_id:
27512 +       state = 8;
27513 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
27514 +
27515 +out_nxi:
27516 +       if ((args & VCA_NXI) && nxi)
27517 +               put_nx_info(nxi);
27518 +out_vxi:
27519 +       if ((args & VCA_VXI) && vxi)
27520 +               put_vx_info(vxi);
27521 +out:
27522 +       vxdprintk(VXD_CBIT(switch, 1),
27523 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
27524 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27525 +               VC_VERSION(cmd), ret, ret, state, permit);
27526 +       return ret;
27527 +}
27528 +
27529 +asmlinkage long
27530 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
27531 +{
27532 +       return do_vserver(cmd, id, data, 0);
27533 +}
27534 +
27535 +#ifdef CONFIG_COMPAT
27536 +
27537 +asmlinkage long
27538 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
27539 +{
27540 +       return do_vserver(cmd, id, data, 1);
27541 +}
27542 +
27543 +#endif /* CONFIG_COMPAT */
27544 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
27545 --- linux-2.6.22.10/kernel/vserver/sysctl.c     1970-01-01 01:00:00 +0100
27546 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sysctl.c  2007-08-15 23:42:57 +0200
27547 @@ -0,0 +1,243 @@
27548 +/*
27549 + *  kernel/vserver/sysctl.c
27550 + *
27551 + *  Virtual Context Support
27552 + *
27553 + *  Copyright (C) 2004-2007  Herbert Pötzl
27554 + *
27555 + *  V0.01  basic structure
27556 + *
27557 + */
27558 +
27559 +#include <linux/module.h>
27560 +#include <linux/ctype.h>
27561 +#include <linux/sysctl.h>
27562 +#include <linux/parser.h>
27563 +#include <asm/uaccess.h>
27564 +
27565 +
27566 +#define CTL_VSERVER    4242    /* unused? */
27567 +
27568 +enum {
27569 +       CTL_DEBUG_ERROR         = 0,
27570 +       CTL_DEBUG_SWITCH        = 1,
27571 +       CTL_DEBUG_XID,
27572 +       CTL_DEBUG_NID,
27573 +       CTL_DEBUG_TAG,
27574 +       CTL_DEBUG_NET,
27575 +       CTL_DEBUG_LIMIT,
27576 +       CTL_DEBUG_CRES,
27577 +       CTL_DEBUG_DLIM,
27578 +       CTL_DEBUG_QUOTA,
27579 +       CTL_DEBUG_CVIRT,
27580 +       CTL_DEBUG_SPACE,
27581 +       CTL_DEBUG_MISC,
27582 +};
27583 +
27584 +
27585 +unsigned int vx_debug_switch   = 0;
27586 +unsigned int vx_debug_xid      = 0;
27587 +unsigned int vx_debug_nid      = 0;
27588 +unsigned int vx_debug_tag      = 0;
27589 +unsigned int vx_debug_net      = 0;
27590 +unsigned int vx_debug_limit    = 0;
27591 +unsigned int vx_debug_cres     = 0;
27592 +unsigned int vx_debug_dlim     = 0;
27593 +unsigned int vx_debug_quota    = 0;
27594 +unsigned int vx_debug_cvirt    = 0;
27595 +unsigned int vx_debug_space    = 0;
27596 +unsigned int vx_debug_misc     = 0;
27597 +
27598 +
27599 +static struct ctl_table_header *vserver_table_header;
27600 +static ctl_table vserver_table[];
27601 +
27602 +
27603 +void vserver_register_sysctl(void)
27604 +{
27605 +       if (!vserver_table_header) {
27606 +               vserver_table_header = register_sysctl_table(vserver_table);
27607 +       }
27608 +
27609 +}
27610 +
27611 +void vserver_unregister_sysctl(void)
27612 +{
27613 +       if (vserver_table_header) {
27614 +               unregister_sysctl_table(vserver_table_header);
27615 +               vserver_table_header = NULL;
27616 +       }
27617 +}
27618 +
27619 +
27620 +static int proc_dodebug(ctl_table *table, int write,
27621 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
27622 +{
27623 +       char            tmpbuf[20], *p, c;
27624 +       unsigned int    value;
27625 +       size_t          left, len;
27626 +
27627 +       if ((*ppos && !write) || !*lenp) {
27628 +               *lenp = 0;
27629 +               return 0;
27630 +       }
27631 +
27632 +       left = *lenp;
27633 +
27634 +       if (write) {
27635 +               if (!access_ok(VERIFY_READ, buffer, left))
27636 +                       return -EFAULT;
27637 +               p = (char *)buffer;
27638 +               while (left && __get_user(c, p) >= 0 && isspace(c))
27639 +                       left--, p++;
27640 +               if (!left)
27641 +                       goto done;
27642 +
27643 +               if (left > sizeof(tmpbuf) - 1)
27644 +                       return -EINVAL;
27645 +               if (copy_from_user(tmpbuf, p, left))
27646 +                       return -EFAULT;
27647 +               tmpbuf[left] = '\0';
27648 +
27649 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
27650 +                       value = 10 * value + (*p - '0');
27651 +               if (*p && !isspace(*p))
27652 +                       return -EINVAL;
27653 +               while (left && isspace(*p))
27654 +                       left--, p++;
27655 +               *(unsigned int *)table->data = value;
27656 +       } else {
27657 +               if (!access_ok(VERIFY_WRITE, buffer, left))
27658 +                       return -EFAULT;
27659 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
27660 +               if (len > left)
27661 +                       len = left;
27662 +               if (__copy_to_user(buffer, tmpbuf, len))
27663 +                       return -EFAULT;
27664 +               if ((left -= len) > 0) {
27665 +                       if (put_user('\n', (char *)buffer + len))
27666 +                               return -EFAULT;
27667 +                       left--;
27668 +               }
27669 +       }
27670 +
27671 +done:
27672 +       *lenp -= left;
27673 +       *ppos += *lenp;
27674 +       return 0;
27675 +}
27676 +
27677 +
27678 +#define        CTL_ENTRY(ctl, name)                            \
27679 +       {                                               \
27680 +               .ctl_name       = ctl,                  \
27681 +               .procname       = #name,                \
27682 +               .data           = &vx_ ## name,         \
27683 +               .maxlen         = sizeof(int),          \
27684 +               .mode           = 0644,                 \
27685 +               .proc_handler   = &proc_dodebug         \
27686 +       }
27687 +
27688 +static ctl_table debug_table[] = {
27689 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
27690 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
27691 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
27692 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
27693 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
27694 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
27695 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
27696 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
27697 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
27698 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
27699 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
27700 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
27701 +       { .ctl_name = 0 }
27702 +};
27703 +
27704 +static ctl_table vserver_table[] = {
27705 +       {
27706 +               .ctl_name       = CTL_VSERVER,
27707 +               .procname       = "vserver",
27708 +               .mode           = 0555,
27709 +               .child          = debug_table
27710 +       },
27711 +       { .ctl_name = 0 }
27712 +};
27713 +
27714 +
27715 +static match_table_t tokens = {
27716 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
27717 +       { CTL_DEBUG_XID,        "xid=%x"        },
27718 +       { CTL_DEBUG_NID,        "nid=%x"        },
27719 +       { CTL_DEBUG_TAG,        "tag=%x"        },
27720 +       { CTL_DEBUG_NET,        "net=%x"        },
27721 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
27722 +       { CTL_DEBUG_CRES,       "cres=%x"       },
27723 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
27724 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
27725 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
27726 +       { CTL_DEBUG_SPACE,      "space=%x"      },
27727 +       { CTL_DEBUG_MISC,       "misc=%x"       },
27728 +       { CTL_DEBUG_ERROR,      NULL            }
27729 +};
27730 +
27731 +#define        HANDLE_CASE(id, name, val)                              \
27732 +       case CTL_DEBUG_ ## id:                                  \
27733 +               vx_debug_ ## name = val;                        \
27734 +               printk("vs_debug_" #name "=0x%x\n", val);       \
27735 +               break
27736 +
27737 +
27738 +static int __init vs_debug_setup(char *str)
27739 +{
27740 +       char *p;
27741 +       int token;
27742 +
27743 +       printk("vs_debug_setup(%s)\n", str);
27744 +       while ((p = strsep(&str, ",")) != NULL) {
27745 +               substring_t args[MAX_OPT_ARGS];
27746 +               unsigned int value;
27747 +
27748 +               if (!*p)
27749 +                       continue;
27750 +
27751 +               token = match_token(p, tokens, args);
27752 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
27753 +
27754 +               switch (token) {
27755 +               HANDLE_CASE(SWITCH, switch, value);
27756 +               HANDLE_CASE(XID,    xid,    value);
27757 +               HANDLE_CASE(NID,    nid,    value);
27758 +               HANDLE_CASE(TAG,    tag,    value);
27759 +               HANDLE_CASE(NET,    net,    value);
27760 +               HANDLE_CASE(LIMIT,  limit,  value);
27761 +               HANDLE_CASE(CRES,   cres,   value);
27762 +               HANDLE_CASE(DLIM,   dlim,   value);
27763 +               HANDLE_CASE(QUOTA,  quota,  value);
27764 +               HANDLE_CASE(CVIRT,  cvirt,  value);
27765 +               HANDLE_CASE(SPACE,  space,  value);
27766 +               HANDLE_CASE(MISC,   misc,   value);
27767 +               default:
27768 +                       return -EINVAL;
27769 +                       break;
27770 +               }
27771 +       }
27772 +       return 1;
27773 +}
27774 +
27775 +__setup("vsdebug=", vs_debug_setup);
27776 +
27777 +
27778 +
27779 +EXPORT_SYMBOL_GPL(vx_debug_switch);
27780 +EXPORT_SYMBOL_GPL(vx_debug_xid);
27781 +EXPORT_SYMBOL_GPL(vx_debug_nid);
27782 +EXPORT_SYMBOL_GPL(vx_debug_net);
27783 +EXPORT_SYMBOL_GPL(vx_debug_limit);
27784 +EXPORT_SYMBOL_GPL(vx_debug_cres);
27785 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
27786 +EXPORT_SYMBOL_GPL(vx_debug_quota);
27787 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
27788 +EXPORT_SYMBOL_GPL(vx_debug_space);
27789 +EXPORT_SYMBOL_GPL(vx_debug_misc);
27790 +
27791 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
27792 --- linux-2.6.22.10/kernel/vserver/tag.c        1970-01-01 01:00:00 +0100
27793 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/tag.c     2007-10-05 14:54:36 +0200
27794 @@ -0,0 +1,62 @@
27795 +/*
27796 + *  linux/kernel/vserver/tag.c
27797 + *
27798 + *  Virtual Server: Shallow Tag Space
27799 + *
27800 + *  Copyright (C) 2007  Herbert Pötzl
27801 + *
27802 + *  V0.01  basic implementation
27803 + *
27804 + */
27805 +
27806 +#include <linux/sched.h>
27807 +#include <linux/vserver/debug.h>
27808 +#include <linux/vs_tag.h>
27809 +
27810 +#include <linux/vserver/tag_cmd.h>
27811 +
27812 +
27813 +int dx_migrate_task(struct task_struct *p, tag_t tag)
27814 +{
27815 +       if (!p)
27816 +               BUG();
27817 +
27818 +       vxdprintk(VXD_CBIT(tag, 5),
27819 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
27820 +
27821 +       task_lock(p);
27822 +       p->tag = tag;
27823 +       task_unlock(p);
27824 +
27825 +       vxdprintk(VXD_CBIT(tag, 5),
27826 +               "moved task %p into [#%d]", p, tag);
27827 +       return 0;
27828 +}
27829 +
27830 +/* vserver syscall commands below here */
27831 +
27832 +/* taks xid and vx_info functions */
27833 +
27834 +
27835 +int vc_task_tag(uint32_t id)
27836 +{
27837 +       tag_t tag;
27838 +
27839 +       if (id) {
27840 +               struct task_struct *tsk;
27841 +               read_lock(&tasklist_lock);
27842 +               tsk = find_task_by_real_pid(id);
27843 +               tag = (tsk) ? tsk->tag : -ESRCH;
27844 +               read_unlock(&tasklist_lock);
27845 +       } else
27846 +               tag = dx_current_tag();
27847 +       return tag;
27848 +}
27849 +
27850 +
27851 +int vc_tag_migrate(uint32_t tag)
27852 +{
27853 +       return dx_migrate_task(current, tag & 0xFFFF);
27854 +}
27855 +
27856 +
27857 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
27858 --- linux-2.6.22.10/kernel/vserver/vci_config.h 1970-01-01 01:00:00 +0100
27859 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/vci_config.h      2007-08-16 03:56:22 +0200
27860 @@ -0,0 +1,81 @@
27861 +
27862 +/*  interface version */
27863 +
27864 +#define VCI_VERSION            0x00020302
27865 +
27866 +
27867 +enum {
27868 +       VCI_KCBIT_NO_DYNAMIC = 0,
27869 +
27870 +       VCI_KCBIT_PROC_SECURE = 4,
27871 +       VCI_KCBIT_HARDCPU = 5,
27872 +       VCI_KCBIT_IDLELIMIT = 6,
27873 +       VCI_KCBIT_IDLETIME = 7,
27874 +
27875 +       VCI_KCBIT_COWBL = 8,
27876 +       VCI_KCBIT_FULLCOWBL = 9,
27877 +       VCI_KCBIT_SPACES = 10,
27878 +       VCI_KCBIT_NETV2 = 11,
27879 +
27880 +       VCI_KCBIT_DEBUG = 16,
27881 +       VCI_KCBIT_HISTORY = 20,
27882 +       VCI_KCBIT_TAGGED = 24,
27883 +       VCI_KCBIT_PPTAG = 28,
27884 +
27885 +       VCI_KCBIT_MORE = 31,
27886 +};
27887 +
27888 +
27889 +static inline uint32_t vci_kernel_config(void)
27890 +{
27891 +       return
27892 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
27893 +
27894 +       /* configured features */
27895 +#ifdef CONFIG_VSERVER_PROC_SECURE
27896 +       (1 << VCI_KCBIT_PROC_SECURE) |
27897 +#endif
27898 +#ifdef CONFIG_VSERVER_HARDCPU
27899 +       (1 << VCI_KCBIT_HARDCPU) |
27900 +#endif
27901 +#ifdef CONFIG_VSERVER_IDLELIMIT
27902 +       (1 << VCI_KCBIT_IDLELIMIT) |
27903 +#endif
27904 +#ifdef CONFIG_VSERVER_IDLETIME
27905 +       (1 << VCI_KCBIT_IDLETIME) |
27906 +#endif
27907 +#ifdef CONFIG_VSERVER_COWBL
27908 +       (1 << VCI_KCBIT_COWBL) |
27909 +       (1 << VCI_KCBIT_FULLCOWBL) |
27910 +#endif
27911 +       (1 << VCI_KCBIT_SPACES) |
27912 +       (1 << VCI_KCBIT_NETV2) |
27913 +
27914 +       /* debug options */
27915 +#ifdef CONFIG_VSERVER_DEBUG
27916 +       (1 << VCI_KCBIT_DEBUG) |
27917 +#endif
27918 +#ifdef CONFIG_VSERVER_HISTORY
27919 +       (1 << VCI_KCBIT_HISTORY) |
27920 +#endif
27921 +
27922 +       /* inode context tagging */
27923 +#if    defined(CONFIG_TAGGING_NONE)
27924 +       (0 << VCI_KCBIT_TAGGED) |
27925 +#elif  defined(CONFIG_TAGGING_UID16)
27926 +       (1 << VCI_KCBIT_TAGGED) |
27927 +#elif  defined(CONFIG_TAGGING_GID16)
27928 +       (2 << VCI_KCBIT_TAGGED) |
27929 +#elif  defined(CONFIG_TAGGING_ID24)
27930 +       (3 << VCI_KCBIT_TAGGED) |
27931 +#elif  defined(CONFIG_TAGGING_INTERN)
27932 +       (4 << VCI_KCBIT_TAGGED) |
27933 +#elif  defined(CONFIG_TAGGING_RUNTIME)
27934 +       (5 << VCI_KCBIT_TAGGED) |
27935 +#else
27936 +       (7 << VCI_KCBIT_TAGGED) |
27937 +#endif
27938 +       (1 << VCI_KCBIT_PPTAG) |
27939 +       0;
27940 +}
27941 +
27942 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
27943 --- linux-2.6.22.10/mm/filemap_xip.c    2007-07-09 13:20:04 +0200
27944 +++ linux-2.6.22.10-vs2.3.0.29/mm/filemap_xip.c 2007-08-05 20:53:13 +0200
27945 @@ -14,6 +14,7 @@
27946  #include <linux/uio.h>
27947  #include <linux/rmap.h>
27948  #include <linux/sched.h>
27949 +#include <linux/vs_memory.h>
27950  #include <asm/tlbflush.h>
27951  #include "filemap.h"
27952  
27953 diff -NurpP --minimal linux-2.6.22.10/mm/fremap.c linux-2.6.22.10-vs2.3.0.29/mm/fremap.c
27954 --- linux-2.6.22.10/mm/fremap.c 2007-02-06 03:01:56 +0100
27955 +++ linux-2.6.22.10-vs2.3.0.29/mm/fremap.c      2007-08-05 20:53:13 +0200
27956 @@ -15,6 +15,7 @@
27957  #include <linux/rmap.h>
27958  #include <linux/module.h>
27959  #include <linux/syscalls.h>
27960 +#include <linux/vs_memory.h>
27961  
27962  #include <asm/mmu_context.h>
27963  #include <asm/cacheflush.h>
27964 @@ -74,6 +75,8 @@ int install_page(struct mm_struct *mm, s
27965         err = -ENOMEM;
27966         if (page_mapcount(page) > INT_MAX/2)
27967                 goto unlock;
27968 +       if (!vx_rss_avail(mm, 1))
27969 +               goto unlock;
27970  
27971         if (pte_none(*pte) || !zap_pte(mm, vma, addr, pte))
27972                 inc_mm_counter(mm, file_rss);
27973 diff -NurpP --minimal linux-2.6.22.10/mm/hugetlb.c linux-2.6.22.10-vs2.3.0.29/mm/hugetlb.c
27974 --- linux-2.6.22.10/mm/hugetlb.c        2007-10-30 01:57:15 +0100
27975 +++ linux-2.6.22.10-vs2.3.0.29/mm/hugetlb.c     2007-08-11 22:41:51 +0200
27976 @@ -19,6 +19,7 @@
27977  #include <asm/pgtable.h>
27978  
27979  #include <linux/hugetlb.h>
27980 +#include <linux/vs_memory.h>
27981  #include "internal.h"
27982  
27983  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
27984 diff -NurpP --minimal linux-2.6.22.10/mm/memory.c linux-2.6.22.10-vs2.3.0.29/mm/memory.c
27985 --- linux-2.6.22.10/mm/memory.c 2007-07-09 13:20:04 +0200
27986 +++ linux-2.6.22.10-vs2.3.0.29/mm/memory.c      2007-08-05 20:53:13 +0200
27987 @@ -498,6 +498,9 @@ static int copy_pte_range(struct mm_stru
27988         int progress = 0;
27989         int rss[2];
27990  
27991 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
27992 +               return -ENOMEM;
27993 +
27994  again:
27995         rss[1] = rss[0] = 0;
27996         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
27997 @@ -2157,6 +2160,11 @@ static int do_swap_page(struct mm_struct
27998                 count_vm_event(PGMAJFAULT);
27999         }
28000  
28001 +       if (!vx_rss_avail(mm, 1)) {
28002 +               ret = VM_FAULT_OOM;
28003 +               goto out;
28004 +       }
28005 +
28006         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
28007         mark_page_accessed(page);
28008         lock_page(page);
28009 @@ -2229,6 +2237,8 @@ static int do_anonymous_page(struct mm_s
28010                 /* Allocate our own private page. */
28011                 pte_unmap(page_table);
28012  
28013 +               if (!vx_rss_avail(mm, 1))
28014 +                       goto oom;
28015                 if (unlikely(anon_vma_prepare(vma)))
28016                         goto oom;
28017                 page = alloc_zeroed_user_highpage(vma, address);
28018 @@ -2302,6 +2312,9 @@ static int do_no_page(struct mm_struct *
28019         pte_unmap(page_table);
28020         BUG_ON(vma->vm_flags & VM_PFNMAP);
28021  
28022 +       if (!vx_rss_avail(mm, 1))
28023 +               return VM_FAULT_OOM;
28024 +
28025         if (vma->vm_file) {
28026                 mapping = vma->vm_file->f_mapping;
28027                 sequence = mapping->truncate_count;
28028 @@ -2527,6 +2540,7 @@ static inline int handle_pte_fault(struc
28029  {
28030         pte_t entry;
28031         spinlock_t *ptl;
28032 +       int ret, type = VXPT_UNKNOWN;
28033  
28034         entry = *pte;
28035         if (!pte_present(entry)) {
28036 @@ -2555,9 +2569,12 @@ static inline int handle_pte_fault(struc
28037         if (unlikely(!pte_same(*pte, entry)))
28038                 goto unlock;
28039         if (write_access) {
28040 -               if (!pte_write(entry))
28041 -                       return do_wp_page(mm, vma, address,
28042 +               if (!pte_write(entry)) {
28043 +                       ret = do_wp_page(mm, vma, address,
28044                                         pte, pmd, ptl, entry);
28045 +                       type = VXPT_WRITE;
28046 +                       goto out;
28047 +               }
28048                 entry = pte_mkdirty(entry);
28049         }
28050         entry = pte_mkyoung(entry);
28051 @@ -2576,7 +2593,10 @@ static inline int handle_pte_fault(struc
28052         }
28053  unlock:
28054         pte_unmap_unlock(pte, ptl);
28055 -       return VM_FAULT_MINOR;
28056 +       ret = VM_FAULT_MINOR;
28057 +out:
28058 +       vx_page_fault(mm, vma, type, ret);
28059 +       return ret;
28060  }
28061  
28062  /*
28063 diff -NurpP --minimal linux-2.6.22.10/mm/mlock.c linux-2.6.22.10-vs2.3.0.29/mm/mlock.c
28064 --- linux-2.6.22.10/mm/mlock.c  2007-10-30 01:57:15 +0100
28065 +++ linux-2.6.22.10-vs2.3.0.29/mm/mlock.c       2007-08-11 22:41:51 +0200
28066 @@ -12,6 +12,7 @@
28067  #include <linux/syscalls.h>
28068  #include <linux/sched.h>
28069  #include <linux/module.h>
28070 +#include <linux/vs_memory.h>
28071  
28072  int can_do_mlock(void)
28073  {
28074 @@ -76,7 +77,7 @@ success:
28075                         ret = make_pages_present(start, end);
28076         }
28077  
28078 -       mm->locked_vm -= pages;
28079 +       vx_vmlocked_sub(mm, pages);
28080  out:
28081         if (ret == -ENOMEM)
28082                 ret = -EAGAIN;
28083 @@ -134,7 +135,7 @@ static int do_mlock(unsigned long start,
28084  
28085  asmlinkage long sys_mlock(unsigned long start, size_t len)
28086  {
28087 -       unsigned long locked;
28088 +       unsigned long locked, grow;
28089         unsigned long lock_limit;
28090         int error = -ENOMEM;
28091  
28092 @@ -145,8 +146,10 @@ asmlinkage long sys_mlock(unsigned long 
28093         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
28094         start &= PAGE_MASK;
28095  
28096 -       locked = len >> PAGE_SHIFT;
28097 -       locked += current->mm->locked_vm;
28098 +       grow = len >> PAGE_SHIFT;
28099 +       if (!vx_vmlocked_avail(current->mm, grow))
28100 +               goto out;
28101 +       locked = current->mm->locked_vm + grow;
28102  
28103         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
28104         lock_limit >>= PAGE_SHIFT;
28105 @@ -154,6 +157,7 @@ asmlinkage long sys_mlock(unsigned long 
28106         /* check against resource limits */
28107         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
28108                 error = do_mlock(start, len, 1);
28109 +out:
28110         up_write(&current->mm->mmap_sem);
28111         return error;
28112  }
28113 @@ -213,6 +217,8 @@ asmlinkage long sys_mlockall(int flags)
28114         lock_limit >>= PAGE_SHIFT;
28115  
28116         ret = -ENOMEM;
28117 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
28118 +               goto out;
28119         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
28120             capable(CAP_IPC_LOCK))
28121                 ret = do_mlockall(flags);
28122 diff -NurpP --minimal linux-2.6.22.10/mm/mmap.c linux-2.6.22.10-vs2.3.0.29/mm/mmap.c
28123 --- linux-2.6.22.10/mm/mmap.c   2007-07-09 13:20:04 +0200
28124 +++ linux-2.6.22.10-vs2.3.0.29/mm/mmap.c        2007-08-05 20:53:13 +0200
28125 @@ -1144,10 +1144,10 @@ munmap_back:
28126                 kmem_cache_free(vm_area_cachep, vma);
28127         }
28128  out:   
28129 -       mm->total_vm += len >> PAGE_SHIFT;
28130 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28131         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
28132         if (vm_flags & VM_LOCKED) {
28133 -               mm->locked_vm += len >> PAGE_SHIFT;
28134 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28135                 make_pages_present(addr, addr + len);
28136         }
28137         if (flags & MAP_POPULATE) {
28138 @@ -1502,9 +1502,9 @@ static int acct_stack_growth(struct vm_a
28139                 return -ENOMEM;
28140  
28141         /* Ok, everything looks good - let it rip */
28142 -       mm->total_vm += grow;
28143 +       vx_vmpages_add(mm, grow);
28144         if (vma->vm_flags & VM_LOCKED)
28145 -               mm->locked_vm += grow;
28146 +               vx_vmlocked_add(mm, grow);
28147         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
28148         return 0;
28149  }
28150 @@ -1662,9 +1662,9 @@ static void remove_vma_list(struct mm_st
28151         do {
28152                 long nrpages = vma_pages(vma);
28153  
28154 -               mm->total_vm -= nrpages;
28155 +               vx_vmpages_sub(mm, nrpages);
28156                 if (vma->vm_flags & VM_LOCKED)
28157 -                       mm->locked_vm -= nrpages;
28158 +                       vx_vmlocked_sub(mm, nrpages);
28159                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
28160                 vma = remove_vma(vma);
28161         } while (vma);
28162 @@ -1903,6 +1903,8 @@ unsigned long do_brk(unsigned long addr,
28163                 lock_limit >>= PAGE_SHIFT;
28164                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28165                         return -EAGAIN;
28166 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
28167 +                       return -ENOMEM;
28168         }
28169  
28170         /*
28171 @@ -1929,7 +1931,8 @@ unsigned long do_brk(unsigned long addr,
28172         if (mm->map_count > sysctl_max_map_count)
28173                 return -ENOMEM;
28174  
28175 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
28176 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
28177 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
28178                 return -ENOMEM;
28179  
28180         /* Can we just expand an old private anonymous mapping? */
28181 @@ -1955,9 +1958,9 @@ unsigned long do_brk(unsigned long addr,
28182                                 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
28183         vma_link(mm, vma, prev, rb_link, rb_parent);
28184  out:
28185 -       mm->total_vm += len >> PAGE_SHIFT;
28186 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28187         if (flags & VM_LOCKED) {
28188 -               mm->locked_vm += len >> PAGE_SHIFT;
28189 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28190                 make_pages_present(addr, addr + len);
28191         }
28192         return addr;
28193 @@ -1986,6 +1989,11 @@ void exit_mmap(struct mm_struct *mm)
28194         free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
28195         tlb_finish_mmu(tlb, 0, end);
28196  
28197 +       set_mm_counter(mm, file_rss, 0);
28198 +       set_mm_counter(mm, anon_rss, 0);
28199 +       vx_vmpages_sub(mm, mm->total_vm);
28200 +       vx_vmlocked_sub(mm, mm->locked_vm);
28201 +
28202         /*
28203          * Walk the list again, actually closing and freeing it,
28204          * with preemption enabled, without holding any MM locks.
28205 @@ -2025,7 +2033,8 @@ int insert_vm_struct(struct mm_struct * 
28206         if (__vma && __vma->vm_start < vma->vm_end)
28207                 return -ENOMEM;
28208         if ((vma->vm_flags & VM_ACCOUNT) &&
28209 -            security_vm_enough_memory(vma_pages(vma)))
28210 +               (security_vm_enough_memory(vma_pages(vma)) ||
28211 +               !vx_vmpages_avail(mm, vma_pages(vma))))
28212                 return -ENOMEM;
28213         vma_link(mm, vma, prev, rb_link, rb_parent);
28214         return 0;
28215 @@ -2098,6 +2107,8 @@ int may_expand_vm(struct mm_struct *mm, 
28216  
28217         if (cur + npages > lim)
28218                 return 0;
28219 +       if (!vx_vmpages_avail(mm, npages))
28220 +               return 0;
28221         return 1;
28222  }
28223  
28224 @@ -2168,7 +2179,6 @@ int install_special_mapping(struct mm_st
28225                 return -ENOMEM;
28226         }
28227  
28228 -       mm->total_vm += len >> PAGE_SHIFT;
28229 -
28230 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28231         return 0;
28232  }
28233 diff -NurpP --minimal linux-2.6.22.10/mm/mremap.c linux-2.6.22.10-vs2.3.0.29/mm/mremap.c
28234 --- linux-2.6.22.10/mm/mremap.c 2007-02-06 03:01:56 +0100
28235 +++ linux-2.6.22.10-vs2.3.0.29/mm/mremap.c      2007-08-05 20:53:13 +0200
28236 @@ -18,6 +18,7 @@
28237  #include <linux/highmem.h>
28238  #include <linux/security.h>
28239  #include <linux/syscalls.h>
28240 +#include <linux/vs_memory.h>
28241  
28242  #include <asm/uaccess.h>
28243  #include <asm/cacheflush.h>
28244 @@ -212,7 +213,7 @@ static unsigned long move_vma(struct vm_
28245          * If this were a serious issue, we'd add a flag to do_munmap().
28246          */
28247         hiwater_vm = mm->hiwater_vm;
28248 -       mm->total_vm += new_len >> PAGE_SHIFT;
28249 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
28250         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
28251  
28252         if (do_munmap(mm, old_addr, old_len) < 0) {
28253 @@ -230,7 +231,7 @@ static unsigned long move_vma(struct vm_
28254         }
28255  
28256         if (vm_flags & VM_LOCKED) {
28257 -               mm->locked_vm += new_len >> PAGE_SHIFT;
28258 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
28259                 if (new_len > old_len)
28260                         make_pages_present(new_addr + old_len,
28261                                            new_addr + new_len);
28262 @@ -337,6 +338,9 @@ unsigned long do_mremap(unsigned long ad
28263                 ret = -EAGAIN;
28264                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28265                         goto out;
28266 +               if (!vx_vmlocked_avail(current->mm,
28267 +                       (new_len - old_len) >> PAGE_SHIFT))
28268 +                       goto out;
28269         }
28270         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
28271                 ret = -ENOMEM;
28272 @@ -365,10 +369,10 @@ unsigned long do_mremap(unsigned long ad
28273                         vma_adjust(vma, vma->vm_start,
28274                                 addr + new_len, vma->vm_pgoff, NULL);
28275  
28276 -                       mm->total_vm += pages;
28277 +                       vx_vmpages_add(mm, pages);
28278                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
28279                         if (vma->vm_flags & VM_LOCKED) {
28280 -                               mm->locked_vm += pages;
28281 +                               vx_vmlocked_add(mm, pages);
28282                                 make_pages_present(addr + old_len,
28283                                                    addr + new_len);
28284                         }
28285 diff -NurpP --minimal linux-2.6.22.10/mm/nommu.c linux-2.6.22.10-vs2.3.0.29/mm/nommu.c
28286 --- linux-2.6.22.10/mm/nommu.c  2007-07-09 13:20:04 +0200
28287 +++ linux-2.6.22.10-vs2.3.0.29/mm/nommu.c       2007-08-05 20:53:13 +0200
28288 @@ -936,7 +936,7 @@ unsigned long do_mmap_pgoff(struct file 
28289         realalloc += kobjsize(vma);
28290         askedalloc += sizeof(*vma);
28291  
28292 -       current->mm->total_vm += len >> PAGE_SHIFT;
28293 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
28294  
28295         add_nommu_vma(vma);
28296  
28297 @@ -1061,7 +1061,7 @@ int do_munmap(struct mm_struct *mm, unsi
28298         kfree(vml);
28299  
28300         update_hiwater_vm(mm);
28301 -       mm->total_vm -= len >> PAGE_SHIFT;
28302 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
28303  
28304  #ifdef DEBUG
28305         show_process_blocks();
28306 @@ -1093,7 +1093,7 @@ void exit_mmap(struct mm_struct * mm)
28307                 printk("Exit_mmap:\n");
28308  #endif
28309  
28310 -               mm->total_vm = 0;
28311 +               vx_vmpages_sub(mm, mm->total_vm);
28312  
28313                 while ((tmp = mm->context.vmlist)) {
28314                         mm->context.vmlist = tmp->next;
28315 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
28316 --- linux-2.6.22.10/mm/oom_kill.c       2007-07-09 13:20:04 +0200
28317 +++ linux-2.6.22.10-vs2.3.0.29/mm/oom_kill.c    2007-08-05 20:53:13 +0200
28318 @@ -24,6 +24,7 @@
28319  #include <linux/cpuset.h>
28320  #include <linux/module.h>
28321  #include <linux/notifier.h>
28322 +#include <linux/vs_memory.h>
28323  
28324  int sysctl_panic_on_oom;
28325  /* #define DEBUG */
28326 @@ -66,6 +67,12 @@ unsigned long badness(struct task_struct
28327         points = mm->total_vm;
28328  
28329         /*
28330 +        * add points for context badness
28331 +        */
28332 +
28333 +       points += vx_badness(p, mm);
28334 +
28335 +       /*
28336          * After this unlock we can no longer dereference local variable `mm'
28337          */
28338         task_unlock(p);
28339 @@ -156,8 +163,8 @@ unsigned long badness(struct task_struct
28340         }
28341  
28342  #ifdef DEBUG
28343 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
28344 -       p->pid, p->comm, points);
28345 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
28346 +               p->pid, p->xid, p->comm, points);
28347  #endif
28348         return points;
28349  }
28350 @@ -288,7 +295,8 @@ static void __oom_kill_task(struct task_
28351         }
28352  
28353         if (verbose)
28354 -               printk(KERN_ERR "Killed process %d (%s)\n", p->pid, p->comm);
28355 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
28356 +                               p->pid, p->xid, p->comm);
28357  
28358         /*
28359          * We give our sacrificial lamb high priority and access to
28360 @@ -358,8 +366,8 @@ static int oom_kill_process(struct task_
28361                 return 0;
28362         }
28363  
28364 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
28365 -                                       message, p->pid, p->comm, points);
28366 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
28367 +                               message, p->pid, p->xid, p->comm, points);
28368  
28369         /* Try to kill a child first */
28370         list_for_each(tsk, &p->children) {
28371 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
28372 --- linux-2.6.22.10/mm/page_alloc.c     2007-07-09 13:20:04 +0200
28373 +++ linux-2.6.22.10-vs2.3.0.29/mm/page_alloc.c  2007-08-05 20:53:13 +0200
28374 @@ -41,6 +41,8 @@
28375  #include <linux/pfn.h>
28376  #include <linux/backing-dev.h>
28377  #include <linux/fault-inject.h>
28378 +#include <linux/vs_base.h>
28379 +#include <linux/vs_limit.h>
28380  
28381  #include <asm/tlbflush.h>
28382  #include <asm/div64.h>
28383 @@ -1488,6 +1490,9 @@ void si_meminfo(struct sysinfo *val)
28384         val->totalhigh = totalhigh_pages;
28385         val->freehigh = nr_free_highpages();
28386         val->mem_unit = PAGE_SIZE;
28387 +
28388 +       if (vx_flags(VXF_VIRT_MEM, 0))
28389 +               vx_vsi_meminfo(val);
28390  }
28391  
28392  EXPORT_SYMBOL(si_meminfo);
28393 @@ -1508,6 +1513,9 @@ void si_meminfo_node(struct sysinfo *val
28394         val->freehigh = 0;
28395  #endif
28396         val->mem_unit = PAGE_SIZE;
28397 +
28398 +       if (vx_flags(VXF_VIRT_MEM, 0))
28399 +               vx_vsi_meminfo(val);
28400  }
28401  #endif
28402  
28403 diff -NurpP --minimal linux-2.6.22.10/mm/rmap.c linux-2.6.22.10-vs2.3.0.29/mm/rmap.c
28404 --- linux-2.6.22.10/mm/rmap.c   2007-07-09 13:20:04 +0200
28405 +++ linux-2.6.22.10-vs2.3.0.29/mm/rmap.c        2007-08-05 20:53:13 +0200
28406 @@ -48,6 +48,7 @@
28407  #include <linux/rcupdate.h>
28408  #include <linux/module.h>
28409  #include <linux/kallsyms.h>
28410 +#include <linux/vs_memory.h>
28411  
28412  #include <asm/tlbflush.h>
28413  
28414 diff -NurpP --minimal linux-2.6.22.10/mm/shmem.c linux-2.6.22.10-vs2.3.0.29/mm/shmem.c
28415 --- linux-2.6.22.10/mm/shmem.c  2007-07-09 13:20:04 +0200
28416 +++ linux-2.6.22.10-vs2.3.0.29/mm/shmem.c       2007-08-05 20:53:13 +0200
28417 @@ -55,7 +55,6 @@
28418  #include <asm/pgtable.h>
28419  
28420  /* This magic number is used in glibc for posix shared memory */
28421 -#define TMPFS_MAGIC    0x01021994
28422  
28423  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
28424  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
28425 @@ -1734,7 +1733,7 @@ static int shmem_statfs(struct dentry *d
28426  {
28427         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
28428  
28429 -       buf->f_type = TMPFS_MAGIC;
28430 +       buf->f_type = TMPFS_SUPER_MAGIC;
28431         buf->f_bsize = PAGE_CACHE_SIZE;
28432         buf->f_namelen = NAME_MAX;
28433         spin_lock(&sbinfo->stat_lock);
28434 @@ -2308,7 +2307,7 @@ static int shmem_fill_super(struct super
28435         sb->s_maxbytes = SHMEM_MAX_BYTES;
28436         sb->s_blocksize = PAGE_CACHE_SIZE;
28437         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
28438 -       sb->s_magic = TMPFS_MAGIC;
28439 +       sb->s_magic = TMPFS_SUPER_MAGIC;
28440         sb->s_op = &shmem_ops;
28441         sb->s_time_gran = 1;
28442  #ifdef CONFIG_TMPFS_POSIX_ACL
28443 diff -NurpP --minimal linux-2.6.22.10/mm/slab.c linux-2.6.22.10-vs2.3.0.29/mm/slab.c
28444 --- linux-2.6.22.10/mm/slab.c   2007-07-09 13:20:04 +0200
28445 +++ linux-2.6.22.10-vs2.3.0.29/mm/slab.c        2007-08-05 20:53:13 +0200
28446 @@ -510,6 +510,8 @@ struct kmem_cache {
28447  #define STATS_INC_FREEMISS(x)  do { } while (0)
28448  #endif
28449  
28450 +#include "slab_vs.h"
28451 +
28452  #if DEBUG
28453  
28454  /*
28455 @@ -3314,6 +3316,7 @@ retry:
28456  
28457         obj = slab_get_obj(cachep, slabp, nodeid);
28458         check_slabp(cachep, slabp);
28459 +       vx_slab_alloc(cachep, flags);
28460         l3->free_objects--;
28461         /* move slabp to correct slabp list: */
28462         list_del(&slabp->list);
28463 @@ -3386,6 +3389,7 @@ __cache_alloc_node(struct kmem_cache *ca
28464         /* ___cache_alloc_node can fall back to other nodes */
28465         ptr = ____cache_alloc_node(cachep, flags, nodeid);
28466    out:
28467 +       vx_slab_alloc(cachep, flags);
28468         local_irq_restore(save_flags);
28469         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
28470  
28471 @@ -3551,6 +3555,7 @@ static inline void __cache_free(struct k
28472  
28473         check_irq_off();
28474         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
28475 +       vx_slab_free(cachep);
28476  
28477         if (cache_free_alien(cachep, objp))
28478                 return;
28479 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
28480 --- linux-2.6.22.10/mm/slab_vs.h        1970-01-01 01:00:00 +0100
28481 +++ linux-2.6.22.10-vs2.3.0.29/mm/slab_vs.h     2007-08-05 20:53:13 +0200
28482 @@ -0,0 +1,27 @@
28483 +
28484 +#include <linux/vserver/context.h>
28485 +
28486 +#include <linux/vs_context.h>
28487 +
28488 +static inline
28489 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
28490 +{
28491 +       int what = gfp_zone(cachep->gfpflags);
28492 +
28493 +       if (!current->vx_info)
28494 +               return;
28495 +
28496 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28497 +}
28498 +
28499 +static inline
28500 +void vx_slab_free(struct kmem_cache *cachep)
28501 +{
28502 +       int what = gfp_zone(cachep->gfpflags);
28503 +
28504 +       if (!current->vx_info)
28505 +               return;
28506 +
28507 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28508 +}
28509 +
28510 diff -NurpP --minimal linux-2.6.22.10/mm/swapfile.c linux-2.6.22.10-vs2.3.0.29/mm/swapfile.c
28511 --- linux-2.6.22.10/mm/swapfile.c       2007-07-09 13:20:04 +0200
28512 +++ linux-2.6.22.10-vs2.3.0.29/mm/swapfile.c    2007-08-05 20:53:13 +0200
28513 @@ -31,6 +31,8 @@
28514  #include <asm/pgtable.h>
28515  #include <asm/tlbflush.h>
28516  #include <linux/swapops.h>
28517 +#include <linux/vs_base.h>
28518 +#include <linux/vs_memory.h>
28519  
28520  DEFINE_SPINLOCK(swap_lock);
28521  unsigned int nr_swapfiles;
28522 @@ -1712,6 +1714,8 @@ void si_swapinfo(struct sysinfo *val)
28523         val->freeswap = nr_swap_pages + nr_to_be_unused;
28524         val->totalswap = total_swap_pages + nr_to_be_unused;
28525         spin_unlock(&swap_lock);
28526 +       if (vx_flags(VXF_VIRT_MEM, 0))
28527 +               vx_vsi_swapinfo(val);
28528  }
28529  
28530  /*
28531 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
28532 --- linux-2.6.22.10/net/core/dev.c      2007-10-30 01:57:15 +0100
28533 +++ linux-2.6.22.10-vs2.3.0.29/net/core/dev.c   2007-09-05 03:06:12 +0200
28534 @@ -117,6 +117,7 @@
28535  #include <linux/err.h>
28536  #include <linux/ctype.h>
28537  #include <linux/if_arp.h>
28538 +#include <linux/vs_inet.h>
28539  
28540  /*
28541   *     The list of packet types we will receive (as opposed to discard)
28542 @@ -2120,6 +2121,8 @@ static int dev_ifconf(char __user *arg)
28543  
28544         total = 0;
28545         for_each_netdev(dev) {
28546 +               if (!nx_dev_visible(current->nx_info, dev))
28547 +                       continue;
28548                 for (i = 0; i < NPROTO; i++) {
28549                         if (gifconf_list[i]) {
28550                                 int done;
28551 @@ -2184,6 +2187,9 @@ static void dev_seq_printf_stats(struct 
28552  {
28553         struct net_device_stats *stats = dev->get_stats(dev);
28554  
28555 +       if (!nx_dev_visible(current->nx_info, dev))
28556 +               return;
28557 +
28558         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
28559                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
28560                    dev->name, stats->rx_bytes, stats->rx_packets,
28561 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
28562 --- linux-2.6.22.10/net/core/rtnetlink.c        2007-07-09 13:20:05 +0200
28563 +++ linux-2.6.22.10-vs2.3.0.29/net/core/rtnetlink.c     2007-08-05 20:53:13 +0200
28564 @@ -537,6 +537,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
28565  
28566         idx = 0;
28567         for_each_netdev(dev) {
28568 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
28569 +                       continue;
28570                 if (idx < s_idx)
28571                         goto cont;
28572                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
28573 @@ -797,6 +799,9 @@ void rtmsg_ifinfo(int type, struct net_d
28574         struct sk_buff *skb;
28575         int err = -ENOBUFS;
28576  
28577 +       if (!nx_dev_visible(current->nx_info, dev))
28578 +               return;
28579 +
28580         skb = nlmsg_new(if_nlmsg_size(), GFP_KERNEL);
28581         if (skb == NULL)
28582                 goto errout;
28583 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
28584 --- linux-2.6.22.10/net/core/sock.c     2007-07-09 13:20:05 +0200
28585 +++ linux-2.6.22.10-vs2.3.0.29/net/core/sock.c  2007-10-01 14:57:43 +0200
28586 @@ -125,6 +125,10 @@
28587  #include <linux/ipsec.h>
28588  
28589  #include <linux/filter.h>
28590 +#include <linux/vs_socket.h>
28591 +#include <linux/vs_limit.h>
28592 +#include <linux/vs_context.h>
28593 +#include <linux/vs_network.h>
28594  
28595  #ifdef CONFIG_INET
28596  #include <net/tcp.h>
28597 @@ -812,6 +816,9 @@ int sock_getsockopt(struct socket *sock,
28598         case SO_PEERSEC:
28599                 return security_socket_getpeersec_stream(sock, optval, optlen, len);
28600  
28601 +               case SO_PEERTAG:
28602 +                       return vx_socket_peer_tag(sock, level, optval, optlen, len);
28603 +
28604         default:
28605                 return -ENOPROTOOPT;
28606         }
28607 @@ -869,6 +876,8 @@ struct sock *sk_alloc(int family, gfp_t 
28608                         sk->sk_prot = sk->sk_prot_creator = prot;
28609                         sock_lock_init(sk);
28610                 }
28611 +               sock_vx_init(sk);
28612 +               sock_nx_init(sk);
28613  
28614                 if (security_sk_alloc(sk, family, priority))
28615                         goto out_free;
28616 @@ -907,6 +916,11 @@ void sk_free(struct sock *sk)
28617                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
28618  
28619         security_sk_free(sk);
28620 +       vx_sock_dec(sk);
28621 +       clr_vx_info(&sk->sk_vx_info);
28622 +       sk->sk_xid = -1;
28623 +       clr_nx_info(&sk->sk_nx_info);
28624 +       sk->sk_nid = -1;
28625         if (sk->sk_prot_creator->slab != NULL)
28626                 kmem_cache_free(sk->sk_prot_creator->slab, sk);
28627         else
28628 @@ -924,6 +938,8 @@ struct sock *sk_clone(const struct sock 
28629                 sock_copy(newsk, sk);
28630  
28631                 /* SANITY */
28632 +               sock_vx_init(newsk);
28633 +               sock_nx_init(newsk);
28634                 sk_node_init(&newsk->sk_node);
28635                 sock_lock_init(newsk);
28636                 bh_lock_sock(newsk);
28637 @@ -969,6 +985,12 @@ struct sock *sk_clone(const struct sock 
28638                 newsk->sk_priority = 0;
28639                 atomic_set(&newsk->sk_refcnt, 2);
28640  
28641 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
28642 +               newsk->sk_xid = sk->sk_xid;
28643 +               vx_sock_inc(newsk);
28644 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
28645 +               newsk->sk_nid = sk->sk_nid;
28646 +
28647                 /*
28648                  * Increment the counter in the same struct proto as the master
28649                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
28650 @@ -1551,6 +1573,11 @@ void sock_init_data(struct socket *sock,
28651  
28652         sk->sk_stamp = ktime_set(-1L, -1L);
28653  
28654 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
28655 +       sk->sk_xid = vx_current_xid();
28656 +       vx_sock_inc(sk);
28657 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
28658 +       sk->sk_nid = nx_current_nid();
28659         atomic_set(&sk->sk_refcnt, 1);
28660  }
28661  
28662 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
28663 --- linux-2.6.22.10/net/ipv4/af_inet.c  2007-10-30 01:57:15 +0100
28664 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/af_inet.c       2007-10-05 14:54:36 +0200
28665 @@ -115,6 +115,7 @@
28666  #ifdef CONFIG_IP_MROUTE
28667  #include <linux/mroute.h>
28668  #endif
28669 +#include <linux/vs_limit.h>
28670  
28671  DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
28672  
28673 @@ -308,9 +309,12 @@ lookup_protocol:
28674         }
28675  
28676         err = -EPERM;
28677 +       if ((protocol == IPPROTO_ICMP) &&
28678 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28679 +               goto override;
28680         if (answer->capability > 0 && !capable(answer->capability))
28681                 goto out_rcu_unlock;
28682 -
28683 +override:
28684         sock->ops = answer->ops;
28685         answer_prot = answer->prot;
28686         answer_no_check = answer->no_check;
28687 @@ -424,6 +428,7 @@ int inet_bind(struct socket *sock, struc
28688         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
28689         struct sock *sk = sock->sk;
28690         struct inet_sock *inet = inet_sk(sk);
28691 +       struct nx_v4_sock_addr nsa;
28692         unsigned short snum;
28693         int chk_addr_ret;
28694         int err;
28695 @@ -437,7 +442,11 @@ int inet_bind(struct socket *sock, struc
28696         if (addr_len < sizeof(struct sockaddr_in))
28697                 goto out;
28698  
28699 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
28700 +       err = v4_map_sock_addr(inet, addr, &nsa);
28701 +       if (err)
28702 +               goto out;
28703 +
28704 +       chk_addr_ret = inet_addr_type(nsa.saddr);
28705  
28706         /* Not specified by any standard per-se, however it breaks too
28707          * many applications when removed.  It is unfortunate since
28708 @@ -449,7 +458,7 @@ int inet_bind(struct socket *sock, struc
28709         err = -EADDRNOTAVAIL;
28710         if (!sysctl_ip_nonlocal_bind &&
28711             !inet->freebind &&
28712 -           addr->sin_addr.s_addr != INADDR_ANY &&
28713 +           nsa.saddr != INADDR_ANY &&
28714             chk_addr_ret != RTN_LOCAL &&
28715             chk_addr_ret != RTN_MULTICAST &&
28716             chk_addr_ret != RTN_BROADCAST)
28717 @@ -474,7 +483,7 @@ int inet_bind(struct socket *sock, struc
28718         if (sk->sk_state != TCP_CLOSE || inet->num)
28719                 goto out_release_sock;
28720  
28721 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
28722 +       v4_set_sock_addr(inet, &nsa);
28723         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
28724                 inet->saddr = 0;  /* Use device */
28725  
28726 @@ -667,11 +676,13 @@ int inet_getname(struct socket *sock, st
28727                      peer == 1))
28728                         return -ENOTCONN;
28729                 sin->sin_port = inet->dport;
28730 -               sin->sin_addr.s_addr = inet->daddr;
28731 +               sin->sin_addr.s_addr =
28732 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28733         } else {
28734                 __be32 addr = inet->rcv_saddr;
28735                 if (!addr)
28736                         addr = inet->saddr;
28737 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
28738                 sin->sin_port = inet->sport;
28739                 sin->sin_addr.s_addr = addr;
28740         }
28741 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
28742 --- linux-2.6.22.10/net/ipv4/devinet.c  2007-10-30 01:57:15 +0100
28743 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/devinet.c       2007-09-30 14:58:01 +0200
28744 @@ -427,6 +427,7 @@ struct in_device *inetdev_by_index(int i
28745         return in_dev;
28746  }
28747  
28748 +
28749  /* Called only from RTNL semaphored context. No locks. */
28750  
28751  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
28752 @@ -676,6 +677,8 @@ int devinet_ioctl(unsigned int cmd, void
28753                 *colon = ':';
28754  
28755         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
28756 +               struct nx_info *nxi = current->nx_info;
28757 +
28758                 if (tryaddrmatch) {
28759                         /* Matthias Andree */
28760                         /* compare label and address (4.4BSD style) */
28761 @@ -684,6 +687,8 @@ int devinet_ioctl(unsigned int cmd, void
28762                            This is checked above. */
28763                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28764                              ifap = &ifa->ifa_next) {
28765 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28766 +                                       continue;
28767                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
28768                                     sin_orig.sin_addr.s_addr ==
28769                                                         ifa->ifa_address) {
28770 @@ -696,9 +701,12 @@ int devinet_ioctl(unsigned int cmd, void
28771                    comparing just the label */
28772                 if (!ifa) {
28773                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28774 -                            ifap = &ifa->ifa_next)
28775 +                            ifap = &ifa->ifa_next) {
28776 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28777 +                                       continue;
28778                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
28779                                         break;
28780 +                       }
28781                 }
28782         }
28783  
28784 @@ -849,6 +857,8 @@ static int inet_gifconf(struct net_devic
28785                 goto out;
28786  
28787         for (; ifa; ifa = ifa->ifa_next) {
28788 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
28789 +                       continue;
28790                 if (!buf) {
28791                         done += sizeof(ifr);
28792                         continue;
28793 @@ -1179,6 +1189,7 @@ static int inet_dump_ifaddr(struct sk_bu
28794         struct net_device *dev;
28795         struct in_device *in_dev;
28796         struct in_ifaddr *ifa;
28797 +       struct sock *sk = skb->sk;
28798         int s_ip_idx, s_idx = cb->args[0];
28799  
28800         s_ip_idx = ip_idx = cb->args[1];
28801 @@ -1193,6 +1204,8 @@ static int inet_dump_ifaddr(struct sk_bu
28802  
28803                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
28804                      ifa = ifa->ifa_next, ip_idx++) {
28805 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
28806 +                               continue;
28807                         if (ip_idx < s_ip_idx)
28808                                 continue;
28809                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
28810 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
28811 --- linux-2.6.22.10/net/ipv4/fib_hash.c 2007-07-09 13:20:05 +0200
28812 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/fib_hash.c      2007-08-05 20:53:13 +0200
28813 @@ -1012,7 +1012,7 @@ static int fib_seq_show(struct seq_file 
28814         prefix  = f->fn_key;
28815         mask    = FZ_MASK(iter->zone);
28816         flags   = fib_flag_trans(fa->fa_type, mask, fi);
28817 -       if (fi)
28818 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
28819                 snprintf(bf, sizeof(bf),
28820                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
28821                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
28822 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
28823 --- linux-2.6.22.10/net/ipv4/inet_connection_sock.c     2007-07-09 13:20:05 +0200
28824 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_connection_sock.c  2007-10-18 01:28:12 +0200
28825 @@ -34,10 +34,40 @@ EXPORT_SYMBOL(inet_csk_timer_bug_msg);
28826   */
28827  int sysctl_local_port_range[2] = { 32768, 61000 };
28828  
28829 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
28830 +{
28831 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
28832 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
28833 +
28834 +       if (inet_v6_ipv6only(sk2))
28835 +               return 0;
28836 +
28837 +       if (sk1_rcv_saddr &&
28838 +           sk2_rcv_saddr &&
28839 +           sk1_rcv_saddr == sk2_rcv_saddr)
28840 +               return 1;
28841 +
28842 +       if (sk1_rcv_saddr &&
28843 +           !sk2_rcv_saddr &&
28844 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
28845 +               return 1;
28846 +
28847 +       if (sk2_rcv_saddr &&
28848 +           !sk1_rcv_saddr &&
28849 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
28850 +               return 1;
28851 +
28852 +       if (!sk1_rcv_saddr &&
28853 +           !sk2_rcv_saddr &&
28854 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
28855 +               return 1;
28856 +
28857 +       return 0;
28858 +}
28859 +
28860  int inet_csk_bind_conflict(const struct sock *sk,
28861                            const struct inet_bind_bucket *tb)
28862  {
28863 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
28864         struct sock *sk2;
28865         struct hlist_node *node;
28866         int reuse = sk->sk_reuse;
28867 @@ -50,9 +80,7 @@ int inet_csk_bind_conflict(const struct 
28868                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
28869                         if (!reuse || !sk2->sk_reuse ||
28870                             sk2->sk_state == TCP_LISTEN) {
28871 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
28872 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
28873 -                                   sk2_rcv_saddr == sk_rcv_saddr)
28874 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
28875                                         break;
28876                         }
28877                 }
28878 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
28879 --- linux-2.6.22.10/net/ipv4/inet_diag.c        2007-10-30 01:57:15 +0100
28880 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_diag.c     2007-10-30 02:36:32 +0100
28881 @@ -98,8 +98,8 @@ static int inet_csk_diag_fill(struct soc
28882  
28883         r->id.idiag_sport = inet->sport;
28884         r->id.idiag_dport = inet->dport;
28885 -       r->id.idiag_src[0] = inet->rcv_saddr;
28886 -       r->id.idiag_dst[0] = inet->daddr;
28887 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
28888 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28889  
28890  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28891         if (r->idiag_family == AF_INET6) {
28892 @@ -186,8 +186,8 @@ static int inet_twsk_diag_fill(struct in
28893         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
28894         r->id.idiag_sport     = tw->tw_sport;
28895         r->id.idiag_dport     = tw->tw_dport;
28896 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
28897 -       r->id.idiag_dst[0]    = tw->tw_daddr;
28898 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
28899 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
28900         r->idiag_state        = tw->tw_substate;
28901         r->idiag_timer        = 3;
28902         r->idiag_expires      = (tmo * 1000 + HZ - 1) / HZ;
28903 @@ -239,6 +239,7 @@ static int inet_diag_get_exact(struct sk
28904         hashinfo = handler->idiag_hashinfo;
28905  
28906         if (req->idiag_family == AF_INET) {
28907 +               /* TODO: lback */
28908                 sk = inet_lookup(hashinfo, req->id.idiag_dst[0],
28909                                  req->id.idiag_dport, req->id.idiag_src[0],
28910                                  req->id.idiag_sport, req->id.idiag_if);
28911 @@ -478,6 +479,7 @@ static int inet_csk_diag_dump(struct soc
28912                 } else
28913  #endif
28914                 {
28915 +                       /* TODO: lback */
28916                         entry.saddr = &inet->rcv_saddr;
28917                         entry.daddr = &inet->daddr;
28918                 }
28919 @@ -514,6 +516,7 @@ static int inet_twsk_diag_dump(struct in
28920                 } else
28921  #endif
28922                 {
28923 +                       /* TODO: lback */
28924                         entry.saddr = &tw->tw_rcv_saddr;
28925                         entry.daddr = &tw->tw_daddr;
28926                 }
28927 @@ -560,8 +563,8 @@ static int inet_diag_fill_req(struct sk_
28928  
28929         r->id.idiag_sport = inet->sport;
28930         r->id.idiag_dport = ireq->rmt_port;
28931 -       r->id.idiag_src[0] = ireq->loc_addr;
28932 -       r->id.idiag_dst[0] = ireq->rmt_addr;
28933 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
28934 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
28935         r->idiag_expires = jiffies_to_msecs(tmo);
28936         r->idiag_rqueue = 0;
28937         r->idiag_wqueue = 0;
28938 @@ -631,6 +634,7 @@ static int inet_diag_dump_reqs(struct sk
28939                                 continue;
28940  
28941                         if (bc) {
28942 +                               /* TODO: lback */
28943                                 entry.saddr =
28944  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28945                                         (entry.family == AF_INET6) ?
28946 @@ -697,6 +701,8 @@ static int inet_diag_dump(struct sk_buff
28947                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
28948                                 struct inet_sock *inet = inet_sk(sk);
28949  
28950 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28951 +                                       continue;
28952                                 if (num < s_num) {
28953                                         num++;
28954                                         continue;
28955 @@ -757,6 +763,8 @@ skip_listen_ht:
28956                 sk_for_each(sk, node, &head->chain) {
28957                         struct inet_sock *inet = inet_sk(sk);
28958  
28959 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28960 +                               continue;
28961                         if (num < s_num)
28962                                 goto next_normal;
28963                         if (!(r->idiag_states & (1 << sk->sk_state)))
28964 @@ -781,6 +789,8 @@ next_normal:
28965                         inet_twsk_for_each(tw, node,
28966                                     &head->twchain) {
28967  
28968 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
28969 +                                       continue;
28970                                 if (num < s_num)
28971                                         goto next_dying;
28972                                 if (r->id.idiag_sport != tw->tw_sport &&
28973 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
28974 --- linux-2.6.22.10/net/ipv4/inet_hashtables.c  2007-05-02 19:25:40 +0200
28975 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_hashtables.c       2007-08-05 20:53:13 +0200
28976 @@ -140,11 +140,10 @@ static struct sock *inet_lookup_listener
28977                         const __be32 rcv_saddr = inet->rcv_saddr;
28978                         int score = sk->sk_family == PF_INET ? 1 : 0;
28979  
28980 -                       if (rcv_saddr) {
28981 -                               if (rcv_saddr != daddr)
28982 -                                       continue;
28983 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
28984                                 score += 2;
28985 -                       }
28986 +                       else
28987 +                               continue;
28988                         if (sk->sk_bound_dev_if) {
28989                                 if (sk->sk_bound_dev_if != dif)
28990                                         continue;
28991 @@ -175,7 +174,7 @@ struct sock *__inet_lookup_listener(stru
28992                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
28993  
28994                 if (inet->num == hnum && !sk->sk_node.next &&
28995 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
28996 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
28997                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
28998                     !sk->sk_bound_dev_if)
28999                         goto sherry_cache;
29000 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
29001 --- linux-2.6.22.10/net/ipv4/raw.c      2007-07-09 13:20:06 +0200
29002 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/raw.c   2007-10-05 12:29:05 +0200
29003 @@ -112,7 +112,7 @@ struct sock *__raw_v4_lookup(struct sock
29004  
29005                 if (inet->num == num                                    &&
29006                     !(inet->daddr && inet->daddr != raddr)              &&
29007 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
29008 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
29009                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
29010                         goto found; /* gotcha */
29011         }
29012 @@ -314,6 +314,12 @@ static int raw_send_hdrinc(struct sock *
29013                 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
29014         }
29015  
29016 +       err = -EPERM;
29017 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
29018 +               sk->sk_nx_info &&
29019 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
29020 +               goto error_free;
29021 +
29022         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
29023                       dst_output);
29024         if (err > 0)
29025 @@ -325,6 +331,7 @@ out:
29026  
29027  error_fault:
29028         err = -EFAULT;
29029 +error_free:
29030         kfree_skb(skb);
29031  error:
29032         IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
29033 @@ -491,6 +498,12 @@ static int raw_sendmsg(struct kiocb *ioc
29034                 }
29035  
29036                 security_sk_classify_flow(sk, &fl);
29037 +               if (sk->sk_nx_info) {
29038 +                       err = ip_v4_find_src(sk->sk_nx_info, &rt, &fl);
29039 +
29040 +                       if (err)
29041 +                               goto done;
29042 +               }
29043                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29044         }
29045         if (err)
29046 @@ -553,17 +566,19 @@ static int raw_bind(struct sock *sk, str
29047  {
29048         struct inet_sock *inet = inet_sk(sk);
29049         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
29050 +       struct nx_v4_sock_addr nsa = { 0 };
29051         int ret = -EINVAL;
29052         int chk_addr_ret;
29053  
29054         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
29055                 goto out;
29056 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
29057 +       v4_map_sock_addr(inet, addr, &nsa);
29058 +       chk_addr_ret = inet_addr_type(nsa.saddr);
29059         ret = -EADDRNOTAVAIL;
29060 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
29061 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
29062             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
29063                 goto out;
29064 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
29065 +       v4_set_sock_addr(inet, &nsa);
29066         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
29067                 inet->saddr = 0;  /* Use device */
29068         sk_dst_reset(sk);
29069 @@ -615,7 +630,8 @@ static int raw_recvmsg(struct kiocb *ioc
29070         /* Copy the address. */
29071         if (sin) {
29072                 sin->sin_family = AF_INET;
29073 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29074 +               sin->sin_addr.s_addr =
29075 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
29076                 sin->sin_port = 0;
29077                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
29078         }
29079 @@ -795,7 +811,8 @@ static struct sock *raw_get_first(struct
29080                 struct hlist_node *node;
29081  
29082                 sk_for_each(sk, node, &raw_v4_htable[state->bucket])
29083 -                       if (sk->sk_family == PF_INET)
29084 +                       if (sk->sk_family == PF_INET &&
29085 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29086                                 goto found;
29087         }
29088         sk = NULL;
29089 @@ -811,7 +828,8 @@ static struct sock *raw_get_next(struct 
29090                 sk = sk_next(sk);
29091  try_again:
29092                 ;
29093 -       } while (sk && sk->sk_family != PF_INET);
29094 +       } while (sk && (sk->sk_family != PF_INET ||
29095 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29096  
29097         if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
29098                 sk = sk_head(&raw_v4_htable[state->bucket]);
29099 @@ -863,7 +881,10 @@ static __inline__ char *get_raw_sock(str
29100  
29101         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29102                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29103 -               i, src, srcp, dest, destp, sp->sk_state,
29104 +               i,
29105 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29106 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29107 +               sp->sk_state,
29108                 atomic_read(&sp->sk_wmem_alloc),
29109                 atomic_read(&sp->sk_rmem_alloc),
29110                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29111 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
29112 --- linux-2.6.22.10/net/ipv4/tcp.c      2007-10-30 01:57:15 +0100
29113 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp.c   2007-09-05 03:06:12 +0200
29114 @@ -258,6 +258,7 @@
29115  #include <linux/cache.h>
29116  #include <linux/err.h>
29117  #include <linux/crypto.h>
29118 +#include <linux/in.h>
29119  
29120  #include <net/icmp.h>
29121  #include <net/tcp.h>
29122 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
29123 --- linux-2.6.22.10/net/ipv4/tcp_ipv4.c 2007-10-30 01:57:15 +0100
29124 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp_ipv4.c      2007-09-05 03:06:12 +0200
29125 @@ -1975,6 +1975,12 @@ static void *listening_get_next(struct s
29126                 req = req->dl_next;
29127                 while (1) {
29128                         while (req) {
29129 +                               vxdprintk(VXD_CBIT(net, 6),
29130 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
29131 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
29132 +                               if (req->sk &&
29133 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
29134 +                                       continue;
29135                                 if (req->rsk_ops->family == st->family) {
29136                                         cur = req;
29137                                         goto out;
29138 @@ -1999,6 +2005,10 @@ get_req:
29139         }
29140  get_sk:
29141         sk_for_each_from(sk, node) {
29142 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
29143 +                       sk, sk->sk_nid, nx_current_nid());
29144 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29145 +                       continue;
29146                 if (sk->sk_family == st->family) {
29147                         cur = sk;
29148                         goto out;
29149 @@ -2050,18 +2060,26 @@ static void *established_get_first(struc
29150  
29151                 read_lock(&tcp_hashinfo.ehash[st->bucket].lock);
29152                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
29153 -                       if (sk->sk_family != st->family) {
29154 +                       vxdprintk(VXD_CBIT(net, 6),
29155 +                               "sk,egf: %p [#%d] (from %d)",
29156 +                               sk, sk->sk_nid, nx_current_nid());
29157 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29158 +                               continue;
29159 +                       if (sk->sk_family != st->family)
29160                                 continue;
29161 -                       }
29162                         rc = sk;
29163                         goto out;
29164                 }
29165                 st->state = TCP_SEQ_STATE_TIME_WAIT;
29166                 inet_twsk_for_each(tw, node,
29167                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
29168 -                       if (tw->tw_family != st->family) {
29169 +                       vxdprintk(VXD_CBIT(net, 6),
29170 +                               "tw: %p [#%d] (from %d)",
29171 +                               tw, tw->tw_nid, nx_current_nid());
29172 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
29173 +                               continue;
29174 +                       if (tw->tw_family != st->family)
29175                                 continue;
29176 -                       }
29177                         rc = tw;
29178                         goto out;
29179                 }
29180 @@ -2085,7 +2103,8 @@ static void *established_get_next(struct
29181                 tw = cur;
29182                 tw = tw_next(tw);
29183  get_tw:
29184 -               while (tw && tw->tw_family != st->family) {
29185 +               while (tw && (tw->tw_family != st->family ||
29186 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
29187                         tw = tw_next(tw);
29188                 }
29189                 if (tw) {
29190 @@ -2109,6 +2128,11 @@ get_tw:
29191                 sk = sk_next(sk);
29192  
29193         sk_for_each_from(sk, node) {
29194 +               vxdprintk(VXD_CBIT(net, 6),
29195 +                       "sk,egn: %p [#%d] (from %d)",
29196 +                       sk, sk->sk_nid, nx_current_nid());
29197 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29198 +                       continue;
29199                 if (sk->sk_family == st->family)
29200                         goto found;
29201         }
29202 @@ -2284,9 +2308,9 @@ static void get_openreq4(struct sock *sk
29203         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29204                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p",
29205                 i,
29206 -               ireq->loc_addr,
29207 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
29208                 ntohs(inet_sk(sk)->sport),
29209 -               ireq->rmt_addr,
29210 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
29211                 ntohs(ireq->rmt_port),
29212                 TCP_SYN_RECV,
29213                 0, 0, /* could print option size, but that is af dependent. */
29214 @@ -2328,7 +2352,10 @@ static void get_tcp4_sock(struct sock *s
29215  
29216         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
29217                         "%08X %5d %8d %lu %d %p %u %u %u %u %d",
29218 -               i, src, srcp, dest, destp, sk->sk_state,
29219 +               i,
29220 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29221 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29222 +               sk->sk_state,
29223                 tp->write_seq - tp->snd_una,
29224                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
29225                                              (tp->rcv_nxt - tp->copied_seq),
29226 @@ -2363,7 +2390,10 @@ static void get_timewait4_sock(struct in
29227  
29228         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29229                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p",
29230 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
29231 +               i,
29232 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29233 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29234 +               tw->tw_substate, 0, 0,
29235                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
29236                 atomic_read(&tw->tw_refcnt), tw);
29237  }
29238 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
29239 --- linux-2.6.22.10/net/ipv4/tcp_minisocks.c    2007-07-09 13:20:06 +0200
29240 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp_minisocks.c 2007-08-05 20:53:13 +0200
29241 @@ -28,6 +28,10 @@
29242  #include <net/inet_common.h>
29243  #include <net/xfrm.h>
29244  
29245 +#include <linux/vs_limit.h>
29246 +#include <linux/vs_socket.h>
29247 +#include <linux/vs_context.h>
29248 +
29249  #ifdef CONFIG_SYSCTL
29250  #define SYNC_INIT 0 /* let the user enable it */
29251  #else
29252 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
29253                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
29254                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
29255  
29256 +               tw->tw_xid              = sk->sk_xid;
29257 +               tw->tw_vx_info          = NULL;
29258 +               tw->tw_nid              = sk->sk_nid;
29259 +               tw->tw_nx_info          = NULL;
29260 +
29261  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
29262                 if (tw->tw_family == PF_INET6) {
29263                         struct ipv6_pinfo *np = inet6_sk(sk);
29264 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
29265 --- linux-2.6.22.10/net/ipv4/udp.c      2007-07-09 13:20:06 +0200
29266 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/udp.c   2007-10-09 14:09:19 +0200
29267 @@ -219,14 +219,7 @@ int udp_get_port(struct sock *sk, unsign
29268         return  __udp_lib_get_port(sk, snum, udp_hash, &udp_port_rover, scmp);
29269  }
29270  
29271 -int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
29272 -{
29273 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
29274 -
29275 -       return  ( !ipv6_only_sock(sk2)  &&
29276 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
29277 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
29278 -}
29279 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29280  
29281  static inline int udp_v4_get_port(struct sock *sk, unsigned short snum)
29282  {
29283 @@ -246,15 +239,22 @@ static struct sock *__udp4_lib_lookup(__
29284         int badness = -1;
29285  
29286         read_lock(&udp_hash_lock);
29287 +
29288         sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
29289                 struct inet_sock *inet = inet_sk(sk);
29290  
29291                 if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
29292                         int score = (sk->sk_family == PF_INET ? 1 : 0);
29293 +
29294                         if (inet->rcv_saddr) {
29295                                 if (inet->rcv_saddr != daddr)
29296                                         continue;
29297                                 score+=2;
29298 +                       } else {
29299 +                               /* block non nx_info ips */
29300 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
29301 +                                       daddr, NXA_MASK_BIND))
29302 +                                       continue;
29303                         }
29304                         if (inet->daddr) {
29305                                 if (inet->daddr != saddr)
29306 @@ -280,6 +280,7 @@ static struct sock *__udp4_lib_lookup(__
29307                         }
29308                 }
29309         }
29310 +
29311         if (result)
29312                 sock_hold(result);
29313         read_unlock(&udp_hash_lock);
29314 @@ -301,7 +302,7 @@ static inline struct sock *udp_v4_mcast_
29315                 if (s->sk_hash != hnum                                  ||
29316                     (inet->daddr && inet->daddr != rmt_addr)            ||
29317                     (inet->dport != rmt_port && inet->dport)            ||
29318 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
29319 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
29320                     ipv6_only_sock(s)                                   ||
29321                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
29322                         continue;
29323 @@ -631,7 +632,14 @@ int udp_sendmsg(struct kiocb *iocb, stru
29324                                     .uli_u = { .ports =
29325                                                { .sport = inet->sport,
29326                                                  .dport = dport } } };
29327 +               struct nx_info *nxi = sk->sk_nx_info;
29328 +
29329                 security_sk_classify_flow(sk, &fl);
29330 +
29331 +               err = ip_v4_find_src(nxi, &rt, &fl);
29332 +               if (err)
29333 +                       goto out;
29334 +
29335                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29336                 if (err) {
29337                         if (err == -ENETUNREACH)
29338 @@ -871,7 +879,8 @@ try_again:
29339         {
29340                 sin->sin_family = AF_INET;
29341                 sin->sin_port = udp_hdr(skb)->source;
29342 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29343 +               sin->sin_addr.s_addr = nx_map_sock_lback(
29344 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
29345                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
29346         }
29347         if (inet->cmsg_flags)
29348 @@ -1551,7 +1560,8 @@ static struct sock *udp_get_first(struct
29349         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
29350                 struct hlist_node *node;
29351                 sk_for_each(sk, node, state->hashtable + state->bucket) {
29352 -                       if (sk->sk_family == state->family)
29353 +                       if (sk->sk_family == state->family &&
29354 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29355                                 goto found;
29356                 }
29357         }
29358 @@ -1568,7 +1578,8 @@ static struct sock *udp_get_next(struct 
29359                 sk = sk_next(sk);
29360  try_again:
29361                 ;
29362 -       } while (sk && sk->sk_family != state->family);
29363 +       } while (sk && (sk->sk_family != state->family ||
29364 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29365  
29366         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
29367                 sk = sk_head(state->hashtable + state->bucket);
29368 @@ -1681,7 +1692,10 @@ static void udp4_format_sock(struct sock
29369  
29370         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29371                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29372 -               bucket, src, srcp, dest, destp, sp->sk_state,
29373 +               bucket,
29374 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29375 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29376 +               sp->sk_state,
29377                 atomic_read(&sp->sk_wmem_alloc),
29378                 atomic_read(&sp->sk_rmem_alloc),
29379                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29380 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/Kconfig linux-2.6.22.10-vs2.3.0.29/net/ipv6/Kconfig
29381 --- linux-2.6.22.10/net/ipv6/Kconfig    2007-07-09 13:20:06 +0200
29382 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/Kconfig 2007-08-05 20:53:13 +0200
29383 @@ -4,8 +4,8 @@
29384  
29385  #   IPv6 as module will cause a CRASH if you try to unload it
29386  config IPV6
29387 -       tristate "The IPv6 protocol"
29388 -       default m
29389 +       bool "The IPv6 protocol"
29390 +       default n
29391         ---help---
29392           This is complemental support for the IP version 6.
29393           You will still be able to do traditional IPv4 networking as well.
29394 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
29395 --- linux-2.6.22.10/net/ipv6/addrconf.c 2007-10-30 01:57:15 +0100
29396 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/addrconf.c      2007-10-05 14:54:36 +0200
29397 @@ -85,6 +85,7 @@
29398  
29399  #include <linux/proc_fs.h>
29400  #include <linux/seq_file.h>
29401 +#include <linux/vs_inet6.h>
29402  
29403  /* Set to 3 to get tracing... */
29404  #define ACONF_DEBUG 2
29405 @@ -897,7 +898,8 @@ static inline int ipv6_saddr_label(const
29406  }
29407  
29408  int ipv6_dev_get_saddr(struct net_device *daddr_dev,
29409 -                      struct in6_addr *daddr, struct in6_addr *saddr)
29410 +                      struct in6_addr *daddr, struct in6_addr *saddr,
29411 +                      struct nx_info *nxi)
29412  {
29413         struct ipv6_saddr_score hiscore;
29414         struct inet6_ifaddr *ifa_result = NULL;
29415 @@ -942,6 +944,10 @@ int ipv6_dev_get_saddr(struct net_device
29416  
29417                         score.addr_type = __ipv6_addr_type(&ifa->addr);
29418  
29419 +                       /* Use only addresses assigned to the context */
29420 +                       if (!v6_ifa_in_nx_info(ifa, nxi))
29421 +                               continue;
29422 +
29423                         /* Rule 0:
29424                          * - Tentative Address (RFC2462 section 5.4)
29425                          *  - A tentative address is not considered
29426 @@ -1155,9 +1161,10 @@ record_it:
29427  
29428  
29429  int ipv6_get_saddr(struct dst_entry *dst,
29430 -                  struct in6_addr *daddr, struct in6_addr *saddr)
29431 +                  struct in6_addr *daddr, struct in6_addr *saddr,
29432 +                  struct nx_info *nxi)
29433  {
29434 -       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
29435 +       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr, nxi);
29436  }
29437  
29438  EXPORT_SYMBOL(ipv6_get_saddr);
29439 @@ -1253,35 +1260,46 @@ struct inet6_ifaddr * ipv6_get_ifaddr(st
29440         return ifp;
29441  }
29442  
29443 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29444 +
29445  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
29446  {
29447         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
29448         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
29449 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
29450         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
29451         int sk_ipv6only = ipv6_only_sock(sk);
29452         int sk2_ipv6only = inet_v6_ipv6only(sk2);
29453         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
29454         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
29455  
29456 -       if (!sk2_rcv_saddr && !sk_ipv6only)
29457 +       /* FIXME: needs handling for v4 ANY */
29458 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
29459                 return 1;
29460  
29461         if (addr_type2 == IPV6_ADDR_ANY &&
29462 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
29463 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
29464 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
29465                 return 1;
29466  
29467         if (addr_type == IPV6_ADDR_ANY &&
29468 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
29469 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
29470 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
29471 +               return 1;
29472 +
29473 +       if (addr_type == IPV6_ADDR_ANY &&
29474 +           addr_type2 == IPV6_ADDR_ANY &&
29475 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
29476                 return 1;
29477  
29478         if (sk2_rcv_saddr6 &&
29479 +           addr_type != IPV6_ADDR_ANY &&
29480 +           addr_type != IPV6_ADDR_ANY &&
29481             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
29482                 return 1;
29483  
29484         if (addr_type == IPV6_ADDR_MAPPED &&
29485             !sk2_ipv6only &&
29486 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
29487 +           ipv4_rcv_saddr_equal(sk, sk2))
29488                 return 1;
29489  
29490         return 0;
29491 @@ -2772,7 +2790,10 @@ static void if6_seq_stop(struct seq_file
29492  static int if6_seq_show(struct seq_file *seq, void *v)
29493  {
29494         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
29495 -       seq_printf(seq,
29496 +
29497 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
29498 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
29499 +               seq_printf(seq,
29500                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
29501                    NIP6(ifp->addr),
29502                    ifp->idev->dev->ifindex,
29503 @@ -3254,6 +3275,11 @@ static int inet6_dump_addr(struct sk_buf
29504         struct inet6_ifaddr *ifa;
29505         struct ifmcaddr6 *ifmca;
29506         struct ifacaddr6 *ifaca;
29507 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29508 +
29509 +       /* disable ipv6 on non v6 guests */
29510 +       if (nxi && !nx_info_has_v6(nxi))
29511 +               return skb->len;
29512  
29513         s_idx = cb->args[0];
29514         s_ip_idx = ip_idx = cb->args[1];
29515 @@ -3275,6 +3301,8 @@ static int inet6_dump_addr(struct sk_buf
29516                              ifa = ifa->if_next, ip_idx++) {
29517                                 if (ip_idx < s_ip_idx)
29518                                         continue;
29519 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
29520 +                                       continue;
29521                                 if ((err = inet6_fill_ifaddr(skb, ifa,
29522                                     NETLINK_CB(cb->skb).pid,
29523                                     cb->nlh->nlmsg_seq, RTM_NEWADDR,
29524 @@ -3288,6 +3316,8 @@ static int inet6_dump_addr(struct sk_buf
29525                              ifmca = ifmca->next, ip_idx++) {
29526                                 if (ip_idx < s_ip_idx)
29527                                         continue;
29528 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
29529 +                                       continue;
29530                                 if ((err = inet6_fill_ifmcaddr(skb, ifmca,
29531                                     NETLINK_CB(cb->skb).pid,
29532                                     cb->nlh->nlmsg_seq, RTM_GETMULTICAST,
29533 @@ -3301,6 +3331,8 @@ static int inet6_dump_addr(struct sk_buf
29534                              ifaca = ifaca->aca_next, ip_idx++) {
29535                                 if (ip_idx < s_ip_idx)
29536                                         continue;
29537 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
29538 +                                       continue;
29539                                 if ((err = inet6_fill_ifacaddr(skb, ifaca,
29540                                     NETLINK_CB(cb->skb).pid,
29541                                     cb->nlh->nlmsg_seq, RTM_GETANYCAST,
29542 @@ -3577,12 +3609,19 @@ static int inet6_dump_ifinfo(struct sk_b
29543         int s_idx = cb->args[0];
29544         struct net_device *dev;
29545         struct inet6_dev *idev;
29546 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29547 +
29548 +       /* FIXME: maybe disable ipv6 on non v6 guests?
29549 +       if (skb->sk && skb->sk->sk_vx_info)
29550 +               return skb->len;        */
29551  
29552         read_lock(&dev_base_lock);
29553         idx = 0;
29554         for_each_netdev(dev) {
29555                 if (idx < s_idx)
29556                         goto cont;
29557 +               if (!v6_dev_in_nx_info(dev, nxi))
29558 +                       goto cont;
29559                 if ((idev = in6_dev_get(dev)) == NULL)
29560                         goto cont;
29561                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
29562 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
29563 --- linux-2.6.22.10/net/ipv6/af_inet6.c 2007-10-30 01:57:15 +0100
29564 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/af_inet6.c      2007-10-05 12:29:05 +0200
29565 @@ -43,6 +43,7 @@
29566  #include <linux/netdevice.h>
29567  #include <linux/icmpv6.h>
29568  #include <linux/netfilter_ipv6.h>
29569 +#include <linux/vs_inet6.h>
29570  
29571  #include <net/ip.h>
29572  #include <net/ipv6.h>
29573 @@ -150,9 +151,12 @@ lookup_protocol:
29574         }
29575  
29576         err = -EPERM;
29577 +       if ((protocol == IPPROTO_ICMPV6) &&
29578 +               nx_capable(answer->capability, NXC_RAW_ICMP))
29579 +               goto override;
29580         if (answer->capability > 0 && !capable(answer->capability))
29581                 goto out_rcu_unlock;
29582 -
29583 +override:
29584         sock->ops = answer->ops;
29585         answer_prot = answer->prot;
29586         answer_no_check = answer->no_check;
29587 @@ -250,6 +254,7 @@ int inet6_bind(struct socket *sock, stru
29588         struct sock *sk = sock->sk;
29589         struct inet_sock *inet = inet_sk(sk);
29590         struct ipv6_pinfo *np = inet6_sk(sk);
29591 +       struct nx_v6_sock_addr nsa;
29592         __be32 v4addr = 0;
29593         unsigned short snum;
29594         int addr_type = 0;
29595 @@ -261,6 +266,11 @@ int inet6_bind(struct socket *sock, stru
29596  
29597         if (addr_len < SIN6_LEN_RFC2133)
29598                 return -EINVAL;
29599 +
29600 +       err = v6_map_sock_addr(inet, addr, &nsa);
29601 +       if (err)
29602 +               return err;
29603 +
29604         addr_type = ipv6_addr_type(&addr->sin6_addr);
29605         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
29606                 return -EINVAL;
29607 @@ -284,6 +294,10 @@ int inet6_bind(struct socket *sock, stru
29608                         err = -EADDRNOTAVAIL;
29609                         goto out;
29610                 }
29611 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
29612 +                       err = -EADDRNOTAVAIL;
29613 +                       goto out;
29614 +               }
29615         } else {
29616                 if (addr_type != IPV6_ADDR_ANY) {
29617                         struct net_device *dev = NULL;
29618 @@ -309,6 +323,11 @@ int inet6_bind(struct socket *sock, stru
29619                                 }
29620                         }
29621  
29622 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
29623 +                               err = -EADDRNOTAVAIL;
29624 +                               goto out;
29625 +                       }
29626 +
29627                         /* ipv4 addr of the socket is invalid.  Only the
29628                          * unspecified and mapped address have a v4 equivalent.
29629                          */
29630 @@ -326,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
29631                 }
29632         }
29633  
29634 +       v6_set_sock_addr(inet, &nsa);
29635 +
29636         inet->rcv_saddr = v4addr;
29637         inet->saddr = v4addr;
29638  
29639 @@ -420,9 +441,11 @@ int inet6_getname(struct socket *sock, s
29640                         return -ENOTCONN;
29641                 sin->sin6_port = inet->dport;
29642                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
29643 +               /* FIXME: remap lback? */
29644                 if (np->sndflow)
29645                         sin->sin6_flowinfo = np->flow_label;
29646         } else {
29647 +               /* FIXME: remap lback? */
29648                 if (ipv6_addr_any(&np->rcv_saddr))
29649                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
29650                 else
29651 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
29652 --- linux-2.6.22.10/net/ipv6/fib6_rules.c       2007-07-09 13:20:06 +0200
29653 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/fib6_rules.c    2007-08-12 00:22:19 +0200
29654 @@ -107,7 +107,7 @@ static int fib6_rule_action(struct fib_r
29655                     r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
29656                         struct in6_addr saddr;
29657                         if (ipv6_get_saddr(&rt->u.dst, &flp->fl6_dst,
29658 -                                          &saddr))
29659 +                                          &saddr, NULL))
29660                                 goto again;
29661                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
29662                                                r->src.plen))
29663 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
29664 --- linux-2.6.22.10/net/ipv6/inet6_hashtables.c 2007-05-02 19:25:45 +0200
29665 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/inet6_hashtables.c      2007-08-05 20:53:13 +0200
29666 @@ -16,6 +16,7 @@
29667  
29668  #include <linux/module.h>
29669  #include <linux/random.h>
29670 +#include <linux/vs_inet6.h>
29671  
29672  #include <net/inet_connection_sock.h>
29673  #include <net/inet_hashtables.h>
29674 @@ -121,6 +122,9 @@ struct sock *inet6_lookup_listener(struc
29675                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29676                                         continue;
29677                                 score++;
29678 +                       } else {
29679 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29680 +                                       continue;
29681                         }
29682                         if (sk->sk_bound_dev_if) {
29683                                 if (sk->sk_bound_dev_if != dif)
29684 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
29685 --- linux-2.6.22.10/net/ipv6/ip6_output.c       2007-10-30 01:57:15 +0100
29686 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/ip6_output.c    2007-09-30 14:58:01 +0200
29687 @@ -884,7 +884,7 @@ static int ip6_dst_lookup_tail(struct so
29688                 goto out_err_release;
29689  
29690         if (ipv6_addr_any(&fl->fl6_src)) {
29691 -               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src);
29692 +               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src, sk->sk_nx_info);
29693                 if (err)
29694                         goto out_err_release;
29695         }
29696 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
29697 --- linux-2.6.22.10/net/ipv6/ndisc.c    2007-10-30 01:57:15 +0100
29698 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/ndisc.c 2007-09-30 14:58:01 +0200
29699 @@ -531,7 +531,7 @@ static void ndisc_send_na(struct net_dev
29700                         override = 0;
29701                 in6_ifa_put(ifp);
29702         } else {
29703 -               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr))
29704 +               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr, NULL))
29705                         return;
29706                 src_addr = &tmpaddr;
29707         }
29708 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
29709 --- linux-2.6.22.10/net/ipv6/route.c    2007-07-09 13:20:06 +0200
29710 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/route.c 2007-08-12 00:22:19 +0200
29711 @@ -2182,7 +2182,7 @@ static int rt6_fill_node(struct sk_buff 
29712                 NLA_PUT_U32(skb, RTA_IIF, iif);
29713         else if (dst) {
29714                 struct in6_addr saddr_buf;
29715 -               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0)
29716 +               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf, skb->sk->sk_nx_info) == 0)
29717                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
29718         }
29719  
29720 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
29721 --- linux-2.6.22.10/net/ipv6/tcp_ipv6.c 2007-10-30 01:57:15 +0100
29722 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/tcp_ipv6.c      2007-09-18 12:32:20 +0200
29723 @@ -68,6 +68,7 @@
29724  
29725  #include <linux/crypto.h>
29726  #include <linux/scatterlist.h>
29727 +#include <linux/vs_inet6.h>
29728  
29729  /* Socket used for sending RSTs and ACKs */
29730  static struct socket *tcp6_socket;
29731 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
29732          *      connect() to INADDR_ANY means loopback (BSD'ism).
29733          */
29734  
29735 -       if(ipv6_addr_any(&usin->sin6_addr))
29736 -               usin->sin6_addr.s6_addr[15] = 0x1;
29737 +       if(ipv6_addr_any(&usin->sin6_addr)) {
29738 +               struct nx_info *nxi =  sk->sk_nx_info;
29739 +
29740 +               if (nxi && nx_info_has_v6(nxi))
29741 +                       /* FIXME: remap lback? */
29742 +                       usin->sin6_addr = nxi->v6.ip;
29743 +               else
29744 +                       usin->sin6_addr.s6_addr[15] = 0x1;
29745 +       }
29746  
29747         addr_type = ipv6_addr_type(&usin->sin6_addr);
29748  
29749 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
29750 --- linux-2.6.22.10/net/ipv6/udp.c      2007-07-09 13:20:06 +0200
29751 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/udp.c   2007-08-12 03:34:32 +0200
29752 @@ -48,6 +48,7 @@
29753  
29754  #include <linux/proc_fs.h>
29755  #include <linux/seq_file.h>
29756 +#include <linux/vs_inet6.h>
29757  #include "udp_impl.h"
29758  
29759  DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
29760 @@ -82,6 +83,10 @@ static struct sock *__udp6_lib_lookup(st
29761                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29762                                         continue;
29763                                 score++;
29764 +                       } else {
29765 +                               /* block non nx_info ips */
29766 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29767 +                                       continue;
29768                         }
29769                         if (!ipv6_addr_any(&np->daddr)) {
29770                                 if (!ipv6_addr_equal(&np->daddr, saddr))
29771 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
29772 --- linux-2.6.22.10/net/ipv6/xfrm6_policy.c     2007-07-09 13:20:06 +0200
29773 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/xfrm6_policy.c  2007-08-12 00:22:19 +0200
29774 @@ -49,7 +49,7 @@ static int xfrm6_get_saddr(xfrm_address_
29775  
29776         if (!xfrm6_dst_lookup((struct xfrm_dst **)&rt, &fl_tunnel)) {
29777                 ipv6_get_saddr(&rt->u.dst, (struct in6_addr *)&daddr->a6,
29778 -                              (struct in6_addr *)&saddr->a6);
29779 +                              (struct in6_addr *)&saddr->a6, NULL);
29780                 dst_release(&rt->u.dst);
29781                 return 0;
29782         }
29783 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
29784 --- linux-2.6.22.10/net/netlink/af_netlink.c    2007-07-09 13:20:07 +0200
29785 +++ linux-2.6.22.10-vs2.3.0.29/net/netlink/af_netlink.c 2007-08-05 20:53:13 +0200
29786 @@ -56,6 +56,9 @@
29787  #include <linux/audit.h>
29788  #include <linux/selinux.h>
29789  #include <linux/mutex.h>
29790 +#include <linux/vs_context.h>
29791 +#include <linux/vs_network.h>
29792 +#include <linux/vs_limit.h>
29793  
29794  #include <net/sock.h>
29795  #include <net/scm.h>
29796 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
29797 --- linux-2.6.22.10/net/sctp/ipv6.c     2007-10-30 01:57:15 +0100
29798 +++ linux-2.6.22.10-vs2.3.0.29/net/sctp/ipv6.c  2007-08-12 00:22:19 +0200
29799 @@ -303,7 +303,7 @@ static void sctp_v6_get_saddr(struct sct
29800                           __FUNCTION__, asoc, dst, NIP6(daddr->v6.sin6_addr));
29801  
29802         if (!asoc) {
29803 -               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr);
29804 +               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr, asoc->base.sk->sk_nx_info);
29805                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
29806                                   NIP6(saddr->v6.sin6_addr));
29807                 return;
29808 diff -NurpP --minimal linux-2.6.22.10/net/socket.c linux-2.6.22.10-vs2.3.0.29/net/socket.c
29809 --- linux-2.6.22.10/net/socket.c        2007-10-30 01:57:15 +0100
29810 +++ linux-2.6.22.10-vs2.3.0.29/net/socket.c     2007-09-05 03:06:12 +0200
29811 @@ -92,6 +92,10 @@
29812  
29813  #include <net/sock.h>
29814  #include <linux/netfilter.h>
29815 +#include <linux/vs_base.h>
29816 +#include <linux/vs_socket.h>
29817 +#include <linux/vs_inet.h>
29818 +#include <linux/vs_inet6.h>
29819  
29820  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
29821  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
29822 @@ -543,7 +547,7 @@ static inline int __sock_sendmsg(struct 
29823                                  struct msghdr *msg, size_t size)
29824  {
29825         struct sock_iocb *si = kiocb_to_siocb(iocb);
29826 -       int err;
29827 +       int err, len;
29828  
29829         si->sock = sock;
29830         si->scm = NULL;
29831 @@ -554,7 +558,22 @@ static inline int __sock_sendmsg(struct 
29832         if (err)
29833                 return err;
29834  
29835 -       return sock->ops->sendmsg(iocb, sock, msg, size);
29836 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
29837 +       if (sock->sk) {
29838 +               if (len == size)
29839 +                       vx_sock_send(sock->sk, size);
29840 +               else
29841 +                       vx_sock_fail(sock->sk, size);
29842 +       }
29843 +       vxdprintk(VXD_CBIT(net, 7),
29844 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29845 +               sock, sock->sk,
29846 +               (sock->sk)?sock->sk->sk_nx_info:0,
29847 +               (sock->sk)?sock->sk->sk_vx_info:0,
29848 +               (sock->sk)?sock->sk->sk_xid:0,
29849 +               (sock->sk)?sock->sk->sk_nid:0,
29850 +               (unsigned int)size, len);
29851 +       return len;
29852  }
29853  
29854  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
29855 @@ -623,7 +642,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
29856  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
29857                                  struct msghdr *msg, size_t size, int flags)
29858  {
29859 -       int err;
29860 +       int err, len;
29861         struct sock_iocb *si = kiocb_to_siocb(iocb);
29862  
29863         si->sock = sock;
29864 @@ -636,7 +655,18 @@ static inline int __sock_recvmsg(struct 
29865         if (err)
29866                 return err;
29867  
29868 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
29869 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
29870 +       if ((len >= 0) && sock->sk)
29871 +               vx_sock_recv(sock->sk, len);
29872 +       vxdprintk(VXD_CBIT(net, 7),
29873 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29874 +               sock, sock->sk,
29875 +               (sock->sk)?sock->sk->sk_nx_info:0,
29876 +               (sock->sk)?sock->sk->sk_vx_info:0,
29877 +               (sock->sk)?sock->sk->sk_xid:0,
29878 +               (sock->sk)?sock->sk->sk_nid:0,
29879 +               (unsigned int)size, len);
29880 +       return len;
29881  }
29882  
29883  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
29884 @@ -1090,6 +1120,13 @@ static int __sock_create(int family, int
29885         if (type < 0 || type >= SOCK_MAX)
29886                 return -EINVAL;
29887  
29888 +       if (!nx_check(0, VS_ADMIN)) {
29889 +               if (family == PF_INET && !current_nx_info_has_v4())
29890 +                       return -EAFNOSUPPORT;
29891 +               if (family == PF_INET6 && !current_nx_info_has_v6())
29892 +                       return -EAFNOSUPPORT;
29893 +       }
29894 +
29895         /* Compatibility.
29896  
29897            This uglymoron is moved from INET layer to here to avoid
29898 @@ -1207,6 +1244,7 @@ asmlinkage long sys_socket(int family, i
29899         if (retval < 0)
29900                 goto out;
29901  
29902 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
29903         retval = sock_map_fd(sock);
29904         if (retval < 0)
29905                 goto out_release;
29906 @@ -1239,10 +1277,12 @@ asmlinkage long sys_socketpair(int famil
29907         err = sock_create(family, type, protocol, &sock1);
29908         if (err < 0)
29909                 goto out;
29910 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
29911  
29912         err = sock_create(family, type, protocol, &sock2);
29913         if (err < 0)
29914                 goto out_release_1;
29915 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
29916  
29917         err = sock1->ops->socketpair(sock1, sock2);
29918         if (err < 0)
29919 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
29920 --- linux-2.6.22.10/net/sunrpc/auth.c   2007-05-02 19:25:48 +0200
29921 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/auth.c        2007-08-05 20:53:13 +0200
29922 @@ -13,6 +13,7 @@
29923  #include <linux/errno.h>
29924  #include <linux/sunrpc/clnt.h>
29925  #include <linux/spinlock.h>
29926 +#include <linux/vs_tag.h>
29927  
29928  #ifdef RPC_DEBUG
29929  # define RPCDBG_FACILITY       RPCDBG_AUTH
29930 @@ -263,6 +264,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
29931         struct auth_cred acred = {
29932                 .uid = current->fsuid,
29933                 .gid = current->fsgid,
29934 +               .tag = dx_current_tag(),
29935                 .group_info = current->group_info,
29936         };
29937         struct rpc_cred *ret;
29938 @@ -282,6 +284,7 @@ rpcauth_bindcred(struct rpc_task *task)
29939         struct auth_cred acred = {
29940                 .uid = current->fsuid,
29941                 .gid = current->fsgid,
29942 +               .tag = dx_current_tag(),
29943                 .group_info = current->group_info,
29944         };
29945         struct rpc_cred *ret;
29946 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
29947 --- linux-2.6.22.10/net/sunrpc/auth_unix.c      2007-05-02 19:25:48 +0200
29948 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/auth_unix.c   2007-08-05 20:53:13 +0200
29949 @@ -11,12 +11,14 @@
29950  #include <linux/module.h>
29951  #include <linux/sunrpc/clnt.h>
29952  #include <linux/sunrpc/auth.h>
29953 +#include <linux/vs_tag.h>
29954  
29955  #define NFS_NGROUPS    16
29956  
29957  struct unx_cred {
29958         struct rpc_cred         uc_base;
29959         gid_t                   uc_gid;
29960 +       tag_t                   uc_tag;
29961         gid_t                   uc_gids[NFS_NGROUPS];
29962  };
29963  #define uc_uid                 uc_base.cr_uid
29964 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
29965         if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
29966                 cred->uc_uid = 0;
29967                 cred->uc_gid = 0;
29968 +               cred->uc_tag = dx_current_tag();
29969                 cred->uc_gids[0] = NOGROUP;
29970         } else {
29971                 int groups = acred->group_info->ngroups;
29972 @@ -87,6 +90,7 @@ unx_create_cred(struct rpc_auth *auth, s
29973  
29974                 cred->uc_uid = acred->uid;
29975                 cred->uc_gid = acred->gid;
29976 +               cred->uc_tag = acred->tag;
29977                 for (i = 0; i < groups; i++)
29978                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
29979                 if (i < NFS_NGROUPS)
29980 @@ -118,7 +122,8 @@ unx_match(struct auth_cred *acred, struc
29981                 int groups;
29982  
29983                 if (cred->uc_uid != acred->uid
29984 -                || cred->uc_gid != acred->gid)
29985 +                || cred->uc_gid != acred->gid
29986 +                || cred->uc_tag != acred->tag)
29987                         return 0;
29988  
29989                 groups = acred->group_info->ngroups;
29990 @@ -144,7 +149,7 @@ unx_marshal(struct rpc_task *task, __be3
29991         struct rpc_clnt *clnt = task->tk_client;
29992         struct unx_cred *cred = (struct unx_cred *) task->tk_msg.rpc_cred;
29993         __be32          *base, *hold;
29994 -       int             i;
29995 +       int             i, tag;
29996  
29997         *p++ = htonl(RPC_AUTH_UNIX);
29998         base = p++;
29999 @@ -154,9 +159,12 @@ unx_marshal(struct rpc_task *task, __be3
30000          * Copy the UTS nodename captured when the client was created.
30001          */
30002         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
30003 +       tag = task->tk_client->cl_tag;
30004  
30005 -       *p++ = htonl((u32) cred->uc_uid);
30006 -       *p++ = htonl((u32) cred->uc_gid);
30007 +       *p++ = htonl((u32) TAGINO_UID(tag,
30008 +               cred->uc_uid, cred->uc_tag));
30009 +       *p++ = htonl((u32) TAGINO_GID(tag,
30010 +               cred->uc_gid, cred->uc_tag));
30011         hold = p++;
30012         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
30013                 *p++ = htonl((u32) cred->uc_gids[i]);
30014 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
30015 --- linux-2.6.22.10/net/sunrpc/clnt.c   2007-07-09 13:20:13 +0200
30016 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/clnt.c        2007-08-05 20:53:13 +0200
30017 @@ -30,6 +30,7 @@
30018  #include <linux/smp_lock.h>
30019  #include <linux/utsname.h>
30020  #include <linux/workqueue.h>
30021 +#include <linux/vs_cvirt.h>
30022  
30023  #include <linux/sunrpc/clnt.h>
30024  #include <linux/sunrpc/rpc_pipe_fs.h>
30025 @@ -249,7 +250,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
30026                 clnt->cl_oneshot = 1;
30027         if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
30028                 clnt->cl_discrtry = 1;
30029 -
30030 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
30031 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
30032 +               clnt->cl_tag = 1; */
30033         return clnt;
30034  }
30035  EXPORT_SYMBOL_GPL(rpc_create);
30036 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
30037 --- linux-2.6.22.10/net/unix/af_unix.c  2007-07-09 13:20:13 +0200
30038 +++ linux-2.6.22.10-vs2.3.0.29/net/unix/af_unix.c       2007-08-05 20:53:13 +0200
30039 @@ -115,6 +115,8 @@
30040  #include <linux/mount.h>
30041  #include <net/checksum.h>
30042  #include <linux/security.h>
30043 +#include <linux/vs_context.h>
30044 +#include <linux/vs_limit.h>
30045  
30046  int sysctl_unix_max_dgram_qlen __read_mostly = 10;
30047  
30048 @@ -252,6 +254,8 @@ static struct sock *__unix_find_socket_b
30049         sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
30050                 struct unix_sock *u = unix_sk(s);
30051  
30052 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
30053 +                       continue;
30054                 if (u->addr->len == len &&
30055                     !memcmp(u->addr->name, sunname, len))
30056                         goto found;
30057 @@ -807,7 +811,7 @@ static int unix_bind(struct socket *sock
30058                  */
30059                 mode = S_IFSOCK |
30060                        (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
30061 -               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
30062 +               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0, NULL);
30063                 if (err)
30064                         goto out_mknod_dput;
30065                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
30066 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
30067 --- linux-2.6.22.10/net/x25/af_x25.c    2007-07-09 13:20:13 +0200
30068 +++ linux-2.6.22.10-vs2.3.0.29/net/x25/af_x25.c 2007-08-05 20:53:13 +0200
30069 @@ -500,7 +500,10 @@ static int x25_create(struct socket *soc
30070  
30071         x25 = x25_sk(sk);
30072  
30073 -       sock_init_data(sock, sk);
30074 +       sk->sk_socket = sock;
30075 +       sk->sk_type = sock->type;
30076 +       sk->sk_sleep = &sock->wait;
30077 +       sock->sk = sk;
30078  
30079         x25_init_timers(sk);
30080  
30081 diff -NurpP --minimal linux-2.6.22.10/security/Kconfig linux-2.6.22.10-vs2.3.0.29/security/Kconfig
30082 --- linux-2.6.22.10/security/Kconfig    2006-11-30 21:19:47 +0100
30083 +++ linux-2.6.22.10-vs2.3.0.29/security/Kconfig 2007-08-05 20:53:13 +0200
30084 @@ -6,6 +6,7 @@ menu "Security options"
30085  
30086  config KEYS
30087         bool "Enable access key retention support"
30088 +       depends on !VSERVER_SECURITY
30089         help
30090           This option provides support for retaining authentication tokens and
30091           access keys in the kernel.
30092 diff -NurpP --minimal linux-2.6.22.10/security/commoncap.c linux-2.6.22.10-vs2.3.0.29/security/commoncap.c
30093 --- linux-2.6.22.10/security/commoncap.c        2007-07-09 13:20:14 +0200
30094 +++ linux-2.6.22.10-vs2.3.0.29/security/commoncap.c     2007-08-05 20:53:13 +0200
30095 @@ -22,10 +22,11 @@
30096  #include <linux/ptrace.h>
30097  #include <linux/xattr.h>
30098  #include <linux/hugetlb.h>
30099 +#include <linux/vs_context.h>
30100  
30101  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
30102  {
30103 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30104 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30105         return 0;
30106  }
30107  
30108 @@ -43,7 +44,7 @@ EXPORT_SYMBOL(cap_netlink_recv);
30109  int cap_capable (struct task_struct *tsk, int cap)
30110  {
30111         /* Derived from include/linux/sched.h:capable. */
30112 -       if (cap_raised(tsk->cap_effective, cap))
30113 +       if (vx_cap_raised(tsk->vx_info, tsk->cap_effective, cap))
30114                 return 0;
30115         return -EPERM;
30116  }
30117 @@ -141,7 +142,8 @@ void cap_bprm_apply_creds (struct linux_
30118         /* Derived from fs/exec.c:compute_creds. */
30119         kernel_cap_t new_permitted, working;
30120  
30121 -       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
30122 +       new_permitted = cap_intersect (bprm->cap_permitted,
30123 +                                       vx_current_cap_bset());
30124         working = cap_intersect (bprm->cap_inheritable,
30125                                  current->cap_inheritable);
30126         new_permitted = cap_combine (new_permitted, working);
30127 @@ -310,7 +312,8 @@ void cap_task_reparent_to_init (struct t
30128  
30129  int cap_syslog (int type)
30130  {
30131 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
30132 +       if ((type != 3 && type != 10) &&
30133 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
30134                 return -EPERM;
30135         return 0;
30136  }
30137 diff -NurpP --minimal linux-2.6.22.10/security/dummy.c linux-2.6.22.10-vs2.3.0.29/security/dummy.c
30138 --- linux-2.6.22.10/security/dummy.c    2007-05-02 19:25:51 +0200
30139 +++ linux-2.6.22.10-vs2.3.0.29/security/dummy.c 2007-08-05 20:53:13 +0200
30140 @@ -28,6 +28,7 @@
30141  #include <linux/hugetlb.h>
30142  #include <linux/ptrace.h>
30143  #include <linux/file.h>
30144 +#include <linux/vs_context.h>
30145  
30146  static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
30147  {
30148 @@ -678,7 +679,7 @@ static int dummy_sem_semop (struct sem_a
30149  
30150  static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
30151  {
30152 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30153 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30154         return 0;
30155  }
30156  
30157 diff -NurpP --minimal linux-2.6.22.10/security/selinux/hooks.c linux-2.6.22.10-vs2.3.0.29/security/selinux/hooks.c
30158 --- linux-2.6.22.10/security/selinux/hooks.c    2007-10-30 01:57:15 +0100
30159 +++ linux-2.6.22.10-vs2.3.0.29/security/selinux/hooks.c 2007-10-30 01:21:54 +0100
30160 @@ -60,7 +60,6 @@
30161  #include <linux/dccp.h>
30162  #include <linux/quota.h>
30163  #include <linux/un.h>          /* for Unix socket types */
30164 -#include <net/af_unix.h>       /* for Unix socket types */
30165  #include <linux/parser.h>
30166  #include <linux/nfs_mount.h>
30167  #include <net/ipv6.h>
This page took 2.400739 seconds and 3 git commands to generate.