Reset to the original
[linux-2.6.git] / patch-2.6.22.14-vs2.3.0.29.diff
1 diff -NurpP --minimal linux-2.6.22.10/Documentation/vserver/debug.txt linux-2.6.22.10-vs2.3.0.29/Documentation/vserver/debug.txt
2 --- linux-2.6.22.10/Documentation/vserver/debug.txt     1970-01-01 01:00:00 +0100
3 +++ linux-2.6.22.10-vs2.3.0.29/Documentation/vserver/debug.txt  2007-08-05 20:53:12 +0200
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
13 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
14 +       "FREE  (%p,#%d)%c inode"
15 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 +       "FREE  (%p,#%d)%c %lld bytes"
17 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 +       "rcu_free_dl_info(%p)"
21 + 4  10 "alloc_dl_info(%p,%d) = %p"
22 +       "dealloc_dl_info(%p)"
23 +       "get_dl_info(%p[#%d.%d])"
24 +       "put_dl_info(%p[#%d.%d])"
25 + 5  20 "alloc_dl_info(%p,%d)*"
26 + 6  40 "__hash_dl_info: %p[#%d]"
27 +       "__unhash_dl_info: %p[#%d]"
28 + 7  80 "locate_dl_info(%p,#%d) = %p"
29 +
30 +debug_misc:
31 +
32 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 +       "new_dqhash: %p [#0x%08x]"
34 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 +       "vroot_get_real_bdev not set"
38 + 1   2 "cow_break_link(»%s«)"
39 +       "temp copy »%s«"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path »%s«"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %d"
48 + 3   8 "fput(new_file=%p[#%d])"
49 +       "fput(old_file=%p[#%d])"
50 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 +       "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5  20 "vs_reboot(%p[#%d],%d)"
53 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
54 +
55 +debug_net:
56 +
57 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6  40 "sk,egf: %p [#%d] (from %d)"
63 +       "sk,egn: %p [#%d] (from %d)"
64 +       "sk,req: %p [#%d] (from %d)"
65 +       "sk: %p [#%d] (from %d)"
66 +       "tw: %p [#%d] (from %d)"
67 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
69 +
70 +debug_nid:
71 +
72 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
73 +       "alloc_nx_info(%d) = %p"
74 +       "create_nx_info(%d) (dynamic rejected)"
75 +       "create_nx_info(%d) = %p (already there)"
76 +       "create_nx_info(%d) = %p (new)"
77 +       "dealloc_nx_info(%p)"
78 + 1   2 "alloc_nx_info(%d)*"
79 +       "create_nx_info(%d)*"
80 + 2   4 "get_nx_info(%p[#%d.%d])"
81 +       "put_nx_info(%p[#%d.%d])"
82 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 +       "clr_nx_info(%p[#%d.%d])"
84 +       "init_nx_info(%p[#%d.%d])"
85 +       "release_nx_info(%p[#%d.%d.%d]) %p"
86 +       "set_nx_info(%p[#%d.%d])"
87 + 4  10 "__hash_nx_info: %p[#%d]"
88 +       "__nx_dynamic_id: [#%d]"
89 +       "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5  20 "moved task %p into nxi:%p[#%d]"
91 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 +       "task_get_nx_info(%p)"
93 + 6  40 "nx_clear_persistent(%p[#%d])"
94 +
95 +debug_quota:
96 +
97 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1   2 "quota_sync_dqh(%p,%d)"
99 +       "sync_dquots(%p,%d)"
100 +       "sync_dquots_dqh(%p,%d)"
101 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
102 +
103 +debug_switch:
104 +
105 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4  10 "%s: (%s %s) returned %s with %d"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
116 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
117 +       "alloc_vx_info(%d) = %p"
118 +       "alloc_vx_info(%d)*"
119 +       "create_vx_info(%d) (dynamic rejected)"
120 +       "create_vx_info(%d) = %p (already there)"
121 +       "create_vx_info(%d) = %p (new)"
122 +       "dealloc_vx_info(%p)"
123 +       "loc_vx_info(%d) = %p (found)"
124 +       "loc_vx_info(%d) = %p (new)"
125 +       "loc_vx_info(%d) = %p (not available)"
126 + 1   2 "create_vx_info(%d)*"
127 +       "loc_vx_info(%d)*"
128 + 2   4 "get_vx_info(%p[#%d.%d])"
129 +       "put_vx_info(%p[#%d.%d])"
130 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 +       "clr_vx_info(%p[#%d.%d])"
132 +       "init_vx_info(%p[#%d.%d])"
133 +       "release_vx_info(%p[#%d.%d.%d]) %p"
134 +       "set_vx_info(%p[#%d.%d])"
135 + 4  10 "__hash_vx_info: %p[#%d]"
136 +       "__unhash_vx_info: %p[#%d.%d.%d]"
137 +       "__vx_dynamic_id: [#%d]"
138 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 +       "moved task %p into vxi:%p[#%d]"
141 +       "task_get_vx_info(%p)"
142 +       "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6  40 "vx_clear_persistent(%p[#%d])"
144 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 +       "vx_set_persistent(%p[#%d])"
147 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-2.6.22.10/Makefile linux-2.6.22.10-vs2.3.0.29/Makefile
160 --- linux-2.6.22.10/Makefile    2007-10-30 01:57:11 +0100
161 +++ linux-2.6.22.10-vs2.3.0.29/Makefile 2007-10-30 02:41:27 +0100
162 @@ -1,7 +1,7 @@
163  VERSION = 2
164  PATCHLEVEL = 6
165  SUBLEVEL = 22
166 -EXTRAVERSION = .14
167 +EXTRAVERSION = .14-vs2.3.0.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/inet.h>
7785  #include <linux/nfs_xdr.h>
7786  #include <linux/magic.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_NONLM, ",nolock", "" },
7793                 { NFS_MOUNT_NOACL, ",noacl", "" },
7794                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
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/nfsd_idmap.h>
7922  #include <linux/nfs4.h>
7923  #include <linux/nfs4_acl.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) || IS_RDONLY(inode))
8061 +                       if (EX_RDONLY(exp) || 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_STRICTLOCK   0x1000  /* reserved for NFSv4 */
11471  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
11472  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11473 +#define NFS_MOUNT_TAGGED       0x8000  /* context tagging */
11474  #define NFS_MOUNT_FLAGMASK     0xFFFF
11475  
11476  #endif
11477 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
11478 --- linux-2.6.22.10/include/linux/nsproxy.h     2007-07-09 13:20:00 +0200
11479 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/nsproxy.h  2007-08-05 20:53:13 +0200
11480 @@ -3,6 +3,7 @@
11481  
11482  #include <linux/spinlock.h>
11483  #include <linux/sched.h>
11484 +#include <linux/vserver/debug.h>
11485  
11486  struct mnt_namespace;
11487  struct uts_namespace;
11488 @@ -32,26 +33,46 @@ struct nsproxy {
11489  extern struct nsproxy init_nsproxy;
11490  
11491  int copy_namespaces(int flags, struct task_struct *tsk);
11492 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
11493  void get_task_namespaces(struct task_struct *tsk);
11494  void free_nsproxy(struct nsproxy *ns);
11495  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
11496         struct fs_struct *);
11497  
11498 -static inline void put_nsproxy(struct nsproxy *ns)
11499 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
11500 +
11501 +static inline void __get_nsproxy(struct nsproxy *ns,
11502 +       const char *_file, int _line)
11503  {
11504 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
11505 +               ns, atomic_read(&ns->count), _file, _line);
11506 +       atomic_inc(&ns->count);
11507 +}
11508 +
11509 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
11510 +
11511 +static inline void __put_nsproxy(struct nsproxy *ns,
11512 +       const char *_file, int _line)
11513 +{
11514 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
11515 +               ns, atomic_read(&ns->count), _file, _line);
11516         if (atomic_dec_and_test(&ns->count)) {
11517                 free_nsproxy(ns);
11518         }
11519  }
11520  
11521 -static inline void exit_task_namespaces(struct task_struct *p)
11522 +#define        exit_task_namespaces(p) __exit_task_namespaces(p, __FILE__, __LINE__)
11523 +
11524 +static inline void __exit_task_namespaces(struct task_struct *p,
11525 +       const char *_file, int _line)
11526  {
11527         struct nsproxy *ns = p->nsproxy;
11528         if (ns) {
11529                 task_lock(p);
11530                 p->nsproxy = NULL;
11531                 task_unlock(p);
11532 -               put_nsproxy(ns);
11533 +               __put_nsproxy(ns, _file, _line);
11534         }
11535  }
11536 +
11537  #endif
11538 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
11539 --- linux-2.6.22.10/include/linux/pid.h 2007-07-09 13:20:00 +0200
11540 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/pid.h      2007-08-05 20:53:13 +0200
11541 @@ -8,7 +8,8 @@ enum pid_type
11542         PIDTYPE_PID,
11543         PIDTYPE_PGID,
11544         PIDTYPE_SID,
11545 -       PIDTYPE_MAX
11546 +       PIDTYPE_MAX,
11547 +       PIDTYPE_REALPID
11548  };
11549  
11550  /*
11551 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
11552 --- linux-2.6.22.10/include/linux/proc_fs.h     2007-07-09 13:20:00 +0200
11553 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/proc_fs.h  2007-08-05 20:53:13 +0200
11554 @@ -54,6 +54,7 @@ struct proc_dir_entry {
11555         nlink_t nlink;
11556         uid_t uid;
11557         gid_t gid;
11558 +       int vx_flags;
11559         loff_t size;
11560         const struct inode_operations *proc_iops;
11561         const struct file_operations *proc_fops;
11562 @@ -246,13 +247,20 @@ static inline void kclist_add(struct kco
11563  extern void kclist_add(struct kcore_list *, void *, size_t);
11564  #endif
11565  
11566 +struct vx_info;
11567 +struct nx_info;
11568 +
11569  union proc_op {
11570         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
11571         int (*proc_read)(struct task_struct *task, char *page);
11572 +       int (*proc_vs_read)(char *page);
11573 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
11574 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
11575  };
11576  
11577  struct proc_inode {
11578         struct pid *pid;
11579 +       int vx_flags;
11580         int fd;
11581         union proc_op op;
11582         struct proc_dir_entry *pde;
11583 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
11584 --- linux-2.6.22.10/include/linux/reiserfs_fs.h 2007-05-02 19:25:34 +0200
11585 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/reiserfs_fs.h      2007-08-05 20:53:13 +0200
11586 @@ -821,6 +821,10 @@ struct stat_data_v1 {
11587  #define REISERFS_COMPR_FL     FS_COMPR_FL
11588  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
11589  
11590 +/* unfortunately reiserfs sdattr is only 16 bit */
11591 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
11592 +#define REISERFS_IUNLINK_FL   (FS_IUNLINK_FL >> 16)
11593 +
11594  /* persistent flags that file inherits from the parent directory */
11595  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
11596                                 REISERFS_SYNC_FL |      \
11597 @@ -830,6 +834,9 @@ struct stat_data_v1 {
11598                                 REISERFS_COMPR_FL |     \
11599                                 REISERFS_NOTAIL_FL )
11600  
11601 +#define REISERFS_FL_USER_VISIBLE       0x80FF
11602 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
11603 +
11604  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
11605     address blocks) */
11606  struct stat_data {
11607 @@ -1901,6 +1908,7 @@ static inline void reiserfs_update_sd(st
11608  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
11609  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
11610  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
11611 +int reiserfs_sync_flags(struct inode *inode);
11612  
11613  /* namei.c */
11614  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
11615 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
11616 --- linux-2.6.22.10/include/linux/reiserfs_fs_sb.h      2007-07-09 13:20:00 +0200
11617 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/reiserfs_fs_sb.h   2007-08-05 20:53:13 +0200
11618 @@ -458,6 +458,7 @@ enum reiserfs_mount_options {
11619         REISERFS_POSIXACL,
11620         REISERFS_BARRIER_NONE,
11621         REISERFS_BARRIER_FLUSH,
11622 +       REISERFS_TAGGED,
11623  
11624         /* Actions on error */
11625         REISERFS_ERROR_PANIC,
11626 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
11627 --- linux-2.6.22.10/include/linux/sched.h       2007-07-09 13:20:01 +0200
11628 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sched.h    2007-10-04 23:47:06 +0200
11629 @@ -26,6 +26,7 @@
11630  #define CLONE_STOPPED          0x02000000      /* Start in stopped state */
11631  #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
11632  #define CLONE_NEWIPC           0x08000000      /* New ipcs */
11633 +#define CLONE_KTHREAD          0x10000000      /* clone a kernel thread */
11634  
11635  /*
11636   * Scheduling policies
11637 @@ -94,7 +95,7 @@ struct bio;
11638   * List of flags we want to share for kernel threads,
11639   * if only because they are not used by them anyway.
11640   */
11641 -#define CLONE_KERNEL   (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
11642 +#define CLONE_KERNEL   (CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_KTHREAD)
11643  
11644  /*
11645   * These are the constant used to fake the fixed-point load-average
11646 @@ -146,12 +147,13 @@ extern unsigned long weighted_cpuload(co
11647  #define TASK_UNINTERRUPTIBLE   2
11648  #define TASK_STOPPED           4
11649  #define TASK_TRACED            8
11650 +#define TASK_ONHOLD            16
11651  /* in tsk->exit_state */
11652 -#define EXIT_ZOMBIE            16
11653 -#define EXIT_DEAD              32
11654 +#define EXIT_ZOMBIE            32
11655 +#define EXIT_DEAD              64
11656  /* in tsk->state again */
11657 -#define TASK_NONINTERACTIVE    64
11658 -#define TASK_DEAD              128
11659 +#define TASK_NONINTERACTIVE    128
11660 +#define TASK_DEAD              256
11661  
11662  #define __set_task_state(tsk, state_value)             \
11663         do { (tsk)->state = (state_value); } while (0)
11664 @@ -287,27 +289,30 @@ extern void arch_unmap_area_topdown(stru
11665   * The mm counters are not protected by its page_table_lock,
11666   * so must be incremented atomically.
11667   */
11668 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
11669 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
11670 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
11671 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
11672 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
11673  typedef atomic_long_t mm_counter_t;
11674 +#define __set_mm_counter(mm, member, value) \
11675 +       atomic_long_set(&(mm)->_##member, value)
11676 +#define get_mm_counter(mm, member) \
11677 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
11678  
11679  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11680  /*
11681   * The mm counters are protected by its page_table_lock,
11682   * so can be incremented directly.
11683   */
11684 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
11685 -#define get_mm_counter(mm, member) ((mm)->_##member)
11686 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
11687 -#define inc_mm_counter(mm, member) (mm)->_##member++
11688 -#define dec_mm_counter(mm, member) (mm)->_##member--
11689  typedef unsigned long mm_counter_t;
11690 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
11691 +#define get_mm_counter(mm, member) ((mm)->_##member)
11692  
11693  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11694  
11695 +#define set_mm_counter(mm, member, value) \
11696 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
11697 +#define add_mm_counter(mm, member, value) \
11698 +       vx_ ## member ## pages_add((mm), (value))
11699 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
11700 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
11701 +
11702  #define get_mm_rss(mm)                                 \
11703         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
11704  #define update_hiwater_rss(mm) do {                    \
11705 @@ -365,6 +370,7 @@ struct mm_struct {
11706  
11707         /* Architecture-specific MM context */
11708         mm_context_t context;
11709 +       struct vx_info *mm_vx_info;
11710  
11711         /* Swap token stuff */
11712         /*
11713 @@ -570,9 +576,10 @@ struct user_struct {
11714         /* Hash table maintenance information */
11715         struct list_head uidhash_list;
11716         uid_t uid;
11717 +       xid_t xid;
11718  };
11719  
11720 -extern struct user_struct *find_user(uid_t);
11721 +extern struct user_struct *find_user(xid_t, uid_t);
11722  
11723  extern struct user_struct root_user;
11724  #define INIT_USER (&root_user)
11725 @@ -969,6 +976,15 @@ struct task_struct {
11726         
11727         void *security;
11728         struct audit_context *audit_context;
11729 +
11730 +/* vserver context data */
11731 +       struct vx_info *vx_info;
11732 +       struct nx_info *nx_info;
11733 +
11734 +       xid_t xid;
11735 +       nid_t nid;
11736 +       tag_t tag;
11737 +
11738         seccomp_t seccomp;
11739  
11740  /* Thread group tracking */
11741 @@ -1290,12 +1306,16 @@ extern struct task_struct init_task;
11742  
11743  extern struct   mm_struct init_mm;
11744  
11745 -#define find_task_by_pid(nr)   find_task_by_pid_type(PIDTYPE_PID, nr)
11746 +#define find_task_by_real_pid(nr) \
11747 +       find_task_by_pid_type(PIDTYPE_REALPID, nr)
11748 +#define find_task_by_pid(nr) \
11749 +       find_task_by_pid_type(PIDTYPE_PID, nr)
11750 +
11751  extern struct task_struct *find_task_by_pid_type(int type, int pid);
11752  extern void __set_special_pids(pid_t session, pid_t pgrp);
11753  
11754  /* per-UID process charging. */
11755 -extern struct user_struct * alloc_uid(uid_t);
11756 +extern struct user_struct * alloc_uid(xid_t, uid_t);
11757  static inline struct user_struct *get_uid(struct user_struct *u)
11758  {
11759         atomic_inc(&u->__count);
11760 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
11761 --- linux-2.6.22.10/include/linux/shmem_fs.h    2006-11-30 21:19:39 +0100
11762 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/shmem_fs.h 2007-08-05 20:53:13 +0200
11763 @@ -8,6 +8,9 @@
11764  
11765  #define SHMEM_NR_DIRECT 16
11766  
11767 +#define TMPFS_SUPER_MAGIC      0x01021994
11768 +
11769 +
11770  struct shmem_inode_info {
11771         spinlock_t              lock;
11772         unsigned long           flags;
11773 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
11774 --- linux-2.6.22.10/include/linux/stat.h        2007-07-09 13:20:01 +0200
11775 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/stat.h     2007-08-05 20:53:13 +0200
11776 @@ -66,6 +66,7 @@ struct kstat {
11777         unsigned int    nlink;
11778         uid_t           uid;
11779         gid_t           gid;
11780 +       tag_t           tag;
11781         dev_t           rdev;
11782         loff_t          size;
11783         struct timespec  atime;
11784 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
11785 --- linux-2.6.22.10/include/linux/sunrpc/auth.h 2006-11-30 21:19:40 +0100
11786 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sunrpc/auth.h      2007-08-05 20:53:13 +0200
11787 @@ -24,6 +24,7 @@
11788  struct auth_cred {
11789         uid_t   uid;
11790         gid_t   gid;
11791 +       tag_t   tag;
11792         struct group_info *group_info;
11793  };
11794  
11795 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
11796 --- linux-2.6.22.10/include/linux/sunrpc/clnt.h 2007-07-09 13:20:01 +0200
11797 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sunrpc/clnt.h      2007-08-05 20:53:13 +0200
11798 @@ -43,7 +43,8 @@ struct rpc_clnt {
11799                                 cl_discrtry : 1,/* disconnect before retry */
11800                                 cl_autobind : 1,/* use getport() */
11801                                 cl_oneshot  : 1,/* dispose after use */
11802 -                               cl_dead     : 1;/* abandoned */
11803 +                               cl_dead     : 1,/* abandoned */
11804 +                               cl_tag      : 1;/* context tagging */
11805  
11806         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
11807  
11808 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
11809 --- linux-2.6.22.10/include/linux/syscalls.h    2007-07-09 13:20:01 +0200
11810 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/syscalls.h 2007-08-05 20:53:13 +0200
11811 @@ -294,6 +294,8 @@ asmlinkage long sys_symlink(const char _
11812  asmlinkage long sys_unlink(const char __user *pathname);
11813  asmlinkage long sys_rename(const char __user *oldname,
11814                                 const char __user *newname);
11815 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
11816 +                               umode_t mode);
11817  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
11818  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
11819  
11820 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
11821 --- linux-2.6.22.10/include/linux/sysctl.h      2007-07-09 13:20:01 +0200
11822 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sysctl.h   2007-08-05 20:53:13 +0200
11823 @@ -106,6 +106,7 @@ enum
11824         KERN_CAP_BSET=14,       /* int: capability bounding set */
11825         KERN_PANIC=15,          /* int: panic timeout */
11826         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11827 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11828  
11829         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11830         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11831 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
11832 --- linux-2.6.22.10/include/linux/sysfs.h       2007-07-09 13:20:01 +0200
11833 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/sysfs.h    2007-08-05 20:53:13 +0200
11834 @@ -15,6 +15,8 @@
11835  #include <linux/list.h>
11836  #include <asm/atomic.h>
11837  
11838 +#define SYSFS_SUPER_MAGIC      0x62656572
11839 +
11840  struct kobject;
11841  struct module;
11842  struct nameidata;
11843 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
11844 --- linux-2.6.22.10/include/linux/time.h        2007-07-09 13:20:01 +0200
11845 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/time.h     2007-08-05 20:53:13 +0200
11846 @@ -176,6 +176,9 @@ static inline void timespec_add_ns(struc
11847         }
11848         a->tv_nsec = ns;
11849  }
11850 +
11851 +#include <linux/vs_time.h>
11852 +
11853  #endif /* __KERNEL__ */
11854  
11855  #define NFDBITS                        __NFDBITS
11856 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
11857 --- linux-2.6.22.10/include/linux/types.h       2007-02-06 03:01:52 +0100
11858 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/types.h    2007-08-05 20:53:13 +0200
11859 @@ -39,6 +39,9 @@ typedef __kernel_uid32_t      uid_t;
11860  typedef __kernel_gid32_t       gid_t;
11861  typedef __kernel_uid16_t        uid16_t;
11862  typedef __kernel_gid16_t        gid16_t;
11863 +typedef unsigned int           xid_t;
11864 +typedef unsigned int           nid_t;
11865 +typedef unsigned int           tag_t;
11866  
11867  #ifdef CONFIG_UID16
11868  /* This is defined by include/asm-{arch}/posix_types.h */
11869 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
11870 --- linux-2.6.22.10/include/linux/vroot.h       1970-01-01 01:00:00 +0100
11871 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vroot.h    2007-08-05 20:53:13 +0200
11872 @@ -0,0 +1,51 @@
11873 +
11874 +/*
11875 + * include/linux/vroot.h
11876 + *
11877 + * written by Herbert Pötzl, 9/11/2002
11878 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
11879 + *
11880 + * Copyright (C) 2002-2007 by Herbert Pötzl.
11881 + * Redistribution of this file is permitted under the
11882 + * GNU General Public License.
11883 + */
11884 +
11885 +#ifndef _LINUX_VROOT_H
11886 +#define _LINUX_VROOT_H
11887 +
11888 +
11889 +#ifdef __KERNEL__
11890 +
11891 +/* Possible states of device */
11892 +enum {
11893 +       Vr_unbound,
11894 +       Vr_bound,
11895 +};
11896 +
11897 +struct vroot_device {
11898 +       int             vr_number;
11899 +       int             vr_refcnt;
11900 +
11901 +       struct semaphore        vr_ctl_mutex;
11902 +       struct block_device    *vr_device;
11903 +       int                     vr_state;
11904 +};
11905 +
11906 +
11907 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
11908 +
11909 +extern int register_vroot_grb(vroot_grb_func *);
11910 +extern int unregister_vroot_grb(vroot_grb_func *);
11911 +
11912 +#endif /* __KERNEL__ */
11913 +
11914 +#define MAX_VROOT_DEFAULT      8
11915 +
11916 +/*
11917 + * IOCTL commands --- we will commandeer 0x56 ('V')
11918 + */
11919 +
11920 +#define VROOT_SET_DEV          0x5600
11921 +#define VROOT_CLR_DEV          0x5601
11922 +
11923 +#endif /* _LINUX_VROOT_H */
11924 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
11925 --- linux-2.6.22.10/include/linux/vs_base.h     1970-01-01 01:00:00 +0100
11926 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_base.h  2007-08-05 20:53:13 +0200
11927 @@ -0,0 +1,9 @@
11928 +#ifndef _VS_BASE_H
11929 +#define _VS_BASE_H
11930 +
11931 +#include "vserver/base.h"
11932 +#include "vserver/debug.h"
11933 +
11934 +#else
11935 +#warning duplicate inclusion
11936 +#endif
11937 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
11938 --- linux-2.6.22.10/include/linux/vs_context.h  1970-01-01 01:00:00 +0100
11939 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_context.h       2007-10-01 14:57:41 +0200
11940 @@ -0,0 +1,224 @@
11941 +#ifndef _VS_CONTEXT_H
11942 +#define _VS_CONTEXT_H
11943 +
11944 +#include "vserver/base.h"
11945 +#include "vserver/context.h"
11946 +#include "vserver/history.h"
11947 +#include "vserver/debug.h"
11948 +
11949 +
11950 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
11951 +
11952 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
11953 +       const char *_file, int _line, void *_here)
11954 +{
11955 +       if (!vxi)
11956 +               return NULL;
11957 +
11958 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
11959 +               vxi, vxi ? vxi->vx_id : 0,
11960 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11961 +               _file, _line);
11962 +       __vxh_get_vx_info(vxi, _here);
11963 +
11964 +       atomic_inc(&vxi->vx_usecnt);
11965 +       return vxi;
11966 +}
11967 +
11968 +
11969 +extern void free_vx_info(struct vx_info *);
11970 +
11971 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
11972 +
11973 +static inline void __put_vx_info(struct vx_info *vxi,
11974 +       const char *_file, int _line, void *_here)
11975 +{
11976 +       if (!vxi)
11977 +               return;
11978 +
11979 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
11980 +               vxi, vxi ? vxi->vx_id : 0,
11981 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11982 +               _file, _line);
11983 +       __vxh_put_vx_info(vxi, _here);
11984 +
11985 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
11986 +               free_vx_info(vxi);
11987 +}
11988 +
11989 +
11990 +#define init_vx_info(p, i) \
11991 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11992 +
11993 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11994 +       const char *_file, int _line, void *_here)
11995 +{
11996 +       if (vxi) {
11997 +               vxlprintk(VXD_CBIT(xid, 3),
11998 +                       "init_vx_info(%p[#%d.%d])",
11999 +                       vxi, vxi ? vxi->vx_id : 0,
12000 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12001 +                       _file, _line);
12002 +               __vxh_init_vx_info(vxi, vxp, _here);
12003 +
12004 +               atomic_inc(&vxi->vx_usecnt);
12005 +       }
12006 +       *vxp = vxi;
12007 +}
12008 +
12009 +
12010 +#define set_vx_info(p, i) \
12011 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
12012 +
12013 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
12014 +       const char *_file, int _line, void *_here)
12015 +{
12016 +       struct vx_info *vxo;
12017 +
12018 +       if (!vxi)
12019 +               return;
12020 +
12021 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
12022 +               vxi, vxi ? vxi->vx_id : 0,
12023 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12024 +               _file, _line);
12025 +       __vxh_set_vx_info(vxi, vxp, _here);
12026 +
12027 +       atomic_inc(&vxi->vx_usecnt);
12028 +       vxo = xchg(vxp, vxi);
12029 +       BUG_ON(vxo);
12030 +}
12031 +
12032 +
12033 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
12034 +
12035 +static inline void __clr_vx_info(struct vx_info **vxp,
12036 +       const char *_file, int _line, void *_here)
12037 +{
12038 +       struct vx_info *vxo;
12039 +
12040 +       vxo = xchg(vxp, NULL);
12041 +       if (!vxo)
12042 +               return;
12043 +
12044 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
12045 +               vxo, vxo ? vxo->vx_id : 0,
12046 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
12047 +               _file, _line);
12048 +       __vxh_clr_vx_info(vxo, vxp, _here);
12049 +
12050 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
12051 +               free_vx_info(vxo);
12052 +}
12053 +
12054 +
12055 +#define claim_vx_info(v, p) \
12056 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12057 +
12058 +static inline void __claim_vx_info(struct vx_info *vxi,
12059 +       struct task_struct *task,
12060 +       const char *_file, int _line, void *_here)
12061 +{
12062 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
12063 +               vxi, vxi ? vxi->vx_id : 0,
12064 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12065 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12066 +               task, _file, _line);
12067 +       __vxh_claim_vx_info(vxi, task, _here);
12068 +
12069 +       atomic_inc(&vxi->vx_tasks);
12070 +}
12071 +
12072 +
12073 +extern void unhash_vx_info(struct vx_info *);
12074 +
12075 +#define release_vx_info(v, p) \
12076 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
12077 +
12078 +static inline void __release_vx_info(struct vx_info *vxi,
12079 +       struct task_struct *task,
12080 +       const char *_file, int _line, void *_here)
12081 +{
12082 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
12083 +               vxi, vxi ? vxi->vx_id : 0,
12084 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
12085 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
12086 +               task, _file, _line);
12087 +       __vxh_release_vx_info(vxi, task, _here);
12088 +
12089 +       might_sleep();
12090 +
12091 +       if (atomic_dec_and_test(&vxi->vx_tasks))
12092 +               unhash_vx_info(vxi);
12093 +}
12094 +
12095 +
12096 +#define task_get_vx_info(p) \
12097 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
12098 +
12099 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
12100 +       const char *_file, int _line, void *_here)
12101 +{
12102 +       struct vx_info *vxi;
12103 +
12104 +       task_lock(p);
12105 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
12106 +               p, _file, _line);
12107 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
12108 +       task_unlock(p);
12109 +       return vxi;
12110 +}
12111 +
12112 +
12113 +static inline void __wakeup_vx_info(struct vx_info *vxi)
12114 +{
12115 +       if (waitqueue_active(&vxi->vx_wait))
12116 +               wake_up_interruptible(&vxi->vx_wait);
12117 +}
12118 +
12119 +
12120 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
12121 +
12122 +static inline void __enter_vx_info(struct vx_info *vxi,
12123 +       struct vx_info_save *vxis, const char *_file, int _line)
12124 +{
12125 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
12126 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
12127 +               current->xid, current->vx_info, _file, _line);
12128 +       vxis->vxi = xchg(&current->vx_info, vxi);
12129 +       vxis->xid = current->xid;
12130 +       current->xid = vxi ? vxi->vx_id : 0;
12131 +}
12132 +
12133 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
12134 +
12135 +static inline void __leave_vx_info(struct vx_info_save *vxis,
12136 +       const char *_file, int _line)
12137 +{
12138 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
12139 +               vxis, vxis->xid, vxis->vxi, current,
12140 +               current->xid, current->vx_info, _file, _line);
12141 +       (void)xchg(&current->vx_info, vxis->vxi);
12142 +       current->xid = vxis->xid;
12143 +}
12144 +
12145 +
12146 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
12147 +{
12148 +       vxis->vxi = xchg(&current->vx_info, NULL);
12149 +       vxis->xid = xchg(&current->xid, (xid_t)0);
12150 +}
12151 +
12152 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
12153 +{
12154 +       (void)xchg(&current->xid, vxis->xid);
12155 +       (void)xchg(&current->vx_info, vxis->vxi);
12156 +}
12157 +
12158 +extern void exit_vx_info(struct task_struct *, int);
12159 +extern void exit_vx_info_early(struct task_struct *, int);
12160 +
12161 +
12162 +#else
12163 +#warning duplicate inclusion
12164 +#endif
12165 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
12166 --- linux-2.6.22.10/include/linux/vs_cowbl.h    1970-01-01 01:00:00 +0100
12167 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_cowbl.h 2007-08-05 20:53:13 +0200
12168 @@ -0,0 +1,44 @@
12169 +#ifndef _VS_COWBL_H
12170 +#define _VS_COWBL_H
12171 +
12172 +#include <linux/fs.h>
12173 +#include <linux/dcache.h>
12174 +#include <linux/namei.h>
12175 +
12176 +extern struct dentry *cow_break_link(const char *pathname);
12177 +
12178 +static inline int cow_check_and_break(struct nameidata *nd)
12179 +{
12180 +       struct inode *inode = nd->dentry->d_inode;
12181 +       int error = 0;
12182 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
12183 +               return -EROFS;
12184 +       if (IS_COW(inode)) {
12185 +               if (IS_COW_LINK(inode)) {
12186 +                       struct dentry *new_dentry, *old_dentry = nd->dentry;
12187 +                       char *path, *buf;
12188 +
12189 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
12190 +                       if (!buf) {
12191 +                               return -ENOMEM;
12192 +                       }
12193 +                       path = d_path(nd->dentry, nd->mnt, buf, PATH_MAX);
12194 +                       new_dentry = cow_break_link(path);
12195 +                       kfree(buf);
12196 +                       if (!IS_ERR(new_dentry)) {
12197 +                               nd->dentry = new_dentry;
12198 +                               dput(old_dentry);
12199 +                       } else
12200 +                               error = PTR_ERR(new_dentry);
12201 +               } else {
12202 +                       inode->i_flags &= ~(S_IUNLINK | S_IMMUTABLE);
12203 +                       inode->i_ctime = CURRENT_TIME;
12204 +                       mark_inode_dirty(inode);
12205 +               }
12206 +       }
12207 +       return error;
12208 +}
12209 +
12210 +#else
12211 +#warning duplicate inclusion
12212 +#endif
12213 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
12214 --- linux-2.6.22.10/include/linux/vs_cvirt.h    1970-01-01 01:00:00 +0100
12215 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_cvirt.h 2007-08-05 20:53:13 +0200
12216 @@ -0,0 +1,49 @@
12217 +#ifndef _VS_CVIRT_H
12218 +#define _VS_CVIRT_H
12219 +
12220 +#include "vserver/cvirt.h"
12221 +#include "vserver/context.h"
12222 +#include "vserver/base.h"
12223 +#include "vserver/debug.h"
12224 +
12225 +
12226 +static inline void vx_activate_task(struct task_struct *p)
12227 +{
12228 +       struct vx_info *vxi;
12229 +
12230 +       if ((vxi = p->vx_info)) {
12231 +               vx_update_load(vxi);
12232 +               atomic_inc(&vxi->cvirt.nr_running);
12233 +       }
12234 +}
12235 +
12236 +static inline void vx_deactivate_task(struct task_struct *p)
12237 +{
12238 +       struct vx_info *vxi;
12239 +
12240 +       if ((vxi = p->vx_info)) {
12241 +               vx_update_load(vxi);
12242 +               atomic_dec(&vxi->cvirt.nr_running);
12243 +       }
12244 +}
12245 +
12246 +static inline void vx_uninterruptible_inc(struct task_struct *p)
12247 +{
12248 +       struct vx_info *vxi;
12249 +
12250 +       if ((vxi = p->vx_info))
12251 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
12252 +}
12253 +
12254 +static inline void vx_uninterruptible_dec(struct task_struct *p)
12255 +{
12256 +       struct vx_info *vxi;
12257 +
12258 +       if ((vxi = p->vx_info))
12259 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
12260 +}
12261 +
12262 +
12263 +#else
12264 +#warning duplicate inclusion
12265 +#endif
12266 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
12267 --- linux-2.6.22.10/include/linux/vs_device.h   1970-01-01 01:00:00 +0100
12268 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_device.h        2007-10-11 01:10:22 +0200
12269 @@ -0,0 +1,45 @@
12270 +#ifndef _VS_DEVICE_H
12271 +#define _VS_DEVICE_H
12272 +
12273 +#include "vserver/base.h"
12274 +#include "vserver/device.h"
12275 +#include "vserver/debug.h"
12276 +
12277 +
12278 +#ifdef CONFIG_VSERVER_DEVICE
12279 +
12280 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
12281 +
12282 +#define vs_device_perm(v, d, m, p) \
12283 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
12284 +
12285 +#else
12286 +
12287 +static inline
12288 +int vs_map_device(struct vx_info *vxi,
12289 +       dev_t device, dev_t *target, umode_t mode)
12290 +{
12291 +       if (target)
12292 +               *target = device;
12293 +       return ~0;
12294 +}
12295 +
12296 +#define vs_device_perm(v, d, m, p) ((p) == (p))
12297 +
12298 +#endif
12299 +
12300 +
12301 +#define vs_map_chrdev(d, t, p) \
12302 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
12303 +#define vs_map_blkdev(d, t, p) \
12304 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
12305 +
12306 +#define vs_chrdev_perm(d, p) \
12307 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
12308 +#define vs_blkdev_perm(d, p) \
12309 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
12310 +
12311 +
12312 +#else
12313 +#warning duplicate inclusion
12314 +#endif
12315 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
12316 --- linux-2.6.22.10/include/linux/vs_dlimit.h   1970-01-01 01:00:00 +0100
12317 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_dlimit.h        2007-08-15 22:04:43 +0200
12318 @@ -0,0 +1,211 @@
12319 +#ifndef _VS_DLIMIT_H
12320 +#define _VS_DLIMIT_H
12321 +
12322 +#include <linux/fs.h>
12323 +
12324 +#include "vserver/dlimit.h"
12325 +#include "vserver/base.h"
12326 +#include "vserver/debug.h"
12327 +
12328 +
12329 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
12330 +
12331 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
12332 +       const char *_file, int _line)
12333 +{
12334 +       if (!dli)
12335 +               return NULL;
12336 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
12337 +               dli, dli ? dli->dl_tag : 0,
12338 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12339 +               _file, _line);
12340 +       atomic_inc(&dli->dl_usecnt);
12341 +       return dli;
12342 +}
12343 +
12344 +
12345 +#define free_dl_info(i) \
12346 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
12347 +
12348 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
12349 +
12350 +static inline void __put_dl_info(struct dl_info *dli,
12351 +       const char *_file, int _line)
12352 +{
12353 +       if (!dli)
12354 +               return;
12355 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
12356 +               dli, dli ? dli->dl_tag : 0,
12357 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
12358 +               _file, _line);
12359 +       if (atomic_dec_and_test(&dli->dl_usecnt))
12360 +               free_dl_info(dli);
12361 +}
12362 +
12363 +
12364 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
12365 +
12366 +static inline int __dl_alloc_space(struct super_block *sb,
12367 +       tag_t tag, dlsize_t nr, const char *file, int line)
12368 +{
12369 +       struct dl_info *dli = NULL;
12370 +       int ret = 0;
12371 +
12372 +       if (nr == 0)
12373 +               goto out;
12374 +       dli = locate_dl_info(sb, tag);
12375 +       if (!dli)
12376 +               goto out;
12377 +
12378 +       spin_lock(&dli->dl_lock);
12379 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
12380 +       if (!ret)
12381 +               dli->dl_space_used += nr;
12382 +       spin_unlock(&dli->dl_lock);
12383 +       put_dl_info(dli);
12384 +out:
12385 +       vxlprintk(VXD_CBIT(dlim, 1),
12386 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
12387 +               sb, tag, __dlimit_char(dli), (long long)nr,
12388 +               ret, file, line);
12389 +       return ret;
12390 +}
12391 +
12392 +static inline void __dl_free_space(struct super_block *sb,
12393 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
12394 +{
12395 +       struct dl_info *dli = NULL;
12396 +
12397 +       if (nr == 0)
12398 +               goto out;
12399 +       dli = locate_dl_info(sb, tag);
12400 +       if (!dli)
12401 +               goto out;
12402 +
12403 +       spin_lock(&dli->dl_lock);
12404 +       if (dli->dl_space_used > nr)
12405 +               dli->dl_space_used -= nr;
12406 +       else
12407 +               dli->dl_space_used = 0;
12408 +       spin_unlock(&dli->dl_lock);
12409 +       put_dl_info(dli);
12410 +out:
12411 +       vxlprintk(VXD_CBIT(dlim, 1),
12412 +               "FREE  (%p,#%d)%c %lld bytes",
12413 +               sb, tag, __dlimit_char(dli), (long long)nr,
12414 +               _file, _line);
12415 +}
12416 +
12417 +static inline int __dl_alloc_inode(struct super_block *sb,
12418 +       tag_t tag, const char *_file, int _line)
12419 +{
12420 +       struct dl_info *dli;
12421 +       int ret = 0;
12422 +
12423 +       dli = locate_dl_info(sb, tag);
12424 +       if (!dli)
12425 +               goto out;
12426 +
12427 +       spin_lock(&dli->dl_lock);
12428 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
12429 +       if (!ret)
12430 +               dli->dl_inodes_used++;
12431 +       spin_unlock(&dli->dl_lock);
12432 +       put_dl_info(dli);
12433 +out:
12434 +       vxlprintk(VXD_CBIT(dlim, 0),
12435 +               "ALLOC (%p,#%d)%c inode (%d)",
12436 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
12437 +       return ret;
12438 +}
12439 +
12440 +static inline void __dl_free_inode(struct super_block *sb,
12441 +       tag_t tag, const char *_file, int _line)
12442 +{
12443 +       struct dl_info *dli;
12444 +
12445 +       dli = locate_dl_info(sb, tag);
12446 +       if (!dli)
12447 +               goto out;
12448 +
12449 +       spin_lock(&dli->dl_lock);
12450 +       if (dli->dl_inodes_used > 1)
12451 +               dli->dl_inodes_used--;
12452 +       else
12453 +               dli->dl_inodes_used = 0;
12454 +       spin_unlock(&dli->dl_lock);
12455 +       put_dl_info(dli);
12456 +out:
12457 +       vxlprintk(VXD_CBIT(dlim, 0),
12458 +               "FREE  (%p,#%d)%c inode",
12459 +               sb, tag, __dlimit_char(dli), _file, _line);
12460 +}
12461 +
12462 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
12463 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
12464 +       const char *_file, int _line)
12465 +{
12466 +       struct dl_info *dli;
12467 +       uint64_t broot, bfree;
12468 +
12469 +       dli = locate_dl_info(sb, tag);
12470 +       if (!dli)
12471 +               return;
12472 +
12473 +       spin_lock(&dli->dl_lock);
12474 +       broot = (dli->dl_space_total -
12475 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
12476 +               >> sb->s_blocksize_bits;
12477 +       bfree = (dli->dl_space_total - dli->dl_space_used)
12478 +                       >> sb->s_blocksize_bits;
12479 +       spin_unlock(&dli->dl_lock);
12480 +
12481 +       vxlprintk(VXD_CBIT(dlim, 2),
12482 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
12483 +               (long long)bfree, (long long)broot,
12484 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
12485 +               _file, _line);
12486 +       if (free_blocks) {
12487 +               if (*free_blocks > bfree)
12488 +                       *free_blocks = bfree;
12489 +       }
12490 +       if (root_blocks) {
12491 +               if (*root_blocks > broot)
12492 +                       *root_blocks = broot;
12493 +       }
12494 +       put_dl_info(dli);
12495 +}
12496 +
12497 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
12498 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12499 +               __FILE__, __LINE__ )
12500 +
12501 +#define DLIMIT_FREE_SPACE(in, bytes) \
12502 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
12503 +               __FILE__, __LINE__ )
12504 +
12505 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
12506 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
12507 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12508 +               __FILE__, __LINE__ )
12509 +
12510 +#define DLIMIT_FREE_BLOCK(in, nr) \
12511 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
12512 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
12513 +               __FILE__, __LINE__ )
12514 +
12515 +
12516 +#define DLIMIT_ALLOC_INODE(in) \
12517 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12518 +
12519 +#define DLIMIT_FREE_INODE(in) \
12520 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
12521 +
12522 +
12523 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
12524 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
12525 +
12526 +
12527 +#else
12528 +#warning duplicate inclusion
12529 +#endif
12530 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
12531 --- linux-2.6.22.10/include/linux/vs_inet.h     1970-01-01 01:00:00 +0100
12532 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_inet.h  2007-10-05 15:07:22 +0200
12533 @@ -0,0 +1,341 @@
12534 +#ifndef _VS_INET_H
12535 +#define _VS_INET_H
12536 +
12537 +#include "vserver/base.h"
12538 +#include "vserver/network.h"
12539 +#include "vserver/debug.h"
12540 +
12541 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
12542 +
12543 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
12544 +                       NIPQUAD((a)->mask), (a)->type
12545 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
12546 +
12547 +
12548 +static inline
12549 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
12550 +{
12551 +       __be32 ip = nxa->ip[0].s_addr;
12552 +       __be32 mask = nxa->mask.s_addr;
12553 +       __be32 bcast = ip | ~mask;
12554 +       int ret = 0;
12555 +
12556 +       switch (nxa->type & tmask) {
12557 +       case NXA_TYPE_MASK:
12558 +               ret = (ip == (addr & mask));
12559 +               break;
12560 +       case NXA_TYPE_ADDR:
12561 +               ret = 3;
12562 +               if (addr == ip)
12563 +                       break;
12564 +               /* fall through to broadcast */
12565 +       case NXA_MOD_BCAST:
12566 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
12567 +               break;
12568 +       case NXA_TYPE_RANGE:
12569 +               ret = ((nxa->ip[0].s_addr <= addr) &&
12570 +                       (nxa->ip[1].s_addr > addr));
12571 +               break;
12572 +       case NXA_TYPE_ANY:
12573 +               ret = 2;
12574 +               break;
12575 +       }
12576 +
12577 +       vxdprintk(VXD_CBIT(net, 0),
12578 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
12579 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
12580 +       return ret;
12581 +}
12582 +
12583 +static inline
12584 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
12585 +{
12586 +       struct nx_addr_v4 *nxa;
12587 +       int ret = 1;
12588 +
12589 +       if (!nxi)
12590 +               goto out;
12591 +
12592 +       ret = 2;
12593 +       /* allow 127.0.0.1 when remapping lback */
12594 +       if ((tmask & NXA_LOOPBACK) &&
12595 +               (addr == IPI_LOOPBACK) &&
12596 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12597 +               goto out;
12598 +       ret = 3;
12599 +       /* check for lback address */
12600 +       if ((tmask & NXA_MOD_LBACK) &&
12601 +               (nxi->v4_lback.s_addr == addr))
12602 +               goto out;
12603 +       ret = 4;
12604 +       /* check for broadcast address */
12605 +       if ((tmask & NXA_MOD_BCAST) &&
12606 +               (nxi->v4_bcast.s_addr == addr))
12607 +               goto out;
12608 +       ret = 5;
12609 +       /* check for v4 addresses */
12610 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
12611 +               if (v4_addr_match(nxa, addr, tmask))
12612 +                       goto out;
12613 +       ret = 0;
12614 +out:
12615 +       vxdprintk(VXD_CBIT(net, 0),
12616 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
12617 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
12618 +       return ret;
12619 +}
12620 +
12621 +static inline
12622 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
12623 +{
12624 +       /* FIXME: needs full range checks */
12625 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
12626 +}
12627 +
12628 +static inline
12629 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
12630 +{
12631 +       struct nx_addr_v4 *ptr;
12632 +
12633 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
12634 +               if (v4_nx_addr_match(ptr, nxa, mask))
12635 +                       return 1;
12636 +       return 0;
12637 +}
12638 +
12639 +#include <net/inet_sock.h>
12640 +
12641 +/*
12642 + *     Check if a given address matches for a socket
12643 + *
12644 + *     nxi:            the socket's nx_info if any
12645 + *     addr:           to be verified address
12646 + */
12647 +static inline
12648 +int v4_sock_addr_match (
12649 +       struct nx_info *nxi,
12650 +       struct inet_sock *inet,
12651 +       __be32 addr)
12652 +{
12653 +       __be32 saddr = inet->rcv_saddr;
12654 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
12655 +
12656 +       if (addr && (saddr == addr || bcast == addr))
12657 +               return 1;
12658 +       if (!saddr)
12659 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
12660 +       return 0;
12661 +}
12662 +
12663 +
12664 +/* inet related checks and helpers */
12665 +
12666 +
12667 +struct in_ifaddr;
12668 +struct net_device;
12669 +struct sock;
12670 +
12671 +#ifdef CONFIG_INET
12672 +
12673 +#include <linux/netdevice.h>
12674 +#include <linux/inetdevice.h>
12675 +#include <net/inet_timewait_sock.h>
12676 +
12677 +
12678 +int dev_in_nx_info(struct net_device *, struct nx_info *);
12679 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
12680 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
12681 +
12682 +
12683 +/*
12684 + *     check if address is covered by socket
12685 + *
12686 + *     sk:     the socket to check against
12687 + *     addr:   the address in question (must be != 0)
12688 + */
12689 +
12690 +static inline
12691 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
12692 +{
12693 +       struct nx_info *nxi = sk->sk_nx_info;
12694 +       __be32 saddr = inet_rcv_saddr(sk);
12695 +
12696 +       vxdprintk(VXD_CBIT(net, 5),
12697 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
12698 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
12699 +               (sk->sk_socket?sk->sk_socket->flags:0));
12700 +
12701 +       if (saddr) {            /* direct address match */
12702 +               return v4_addr_match(nxa, saddr, -1);
12703 +       } else if (nxi) {       /* match against nx_info */
12704 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
12705 +       } else {                /* unrestricted any socket */
12706 +               return 1;
12707 +       }
12708 +}
12709 +
12710 +
12711 +
12712 +static inline
12713 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
12714 +{
12715 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p »%s«) %d",
12716 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
12717 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
12718 +
12719 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12720 +               return 1;
12721 +       if (dev_in_nx_info(dev, nxi))
12722 +               return 1;
12723 +       return 0;
12724 +}
12725 +
12726 +
12727 +static inline
12728 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
12729 +{
12730 +       if (!nxi)
12731 +               return 1;
12732 +       if (!ifa)
12733 +               return 0;
12734 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
12735 +}
12736 +
12737 +static inline
12738 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
12739 +{
12740 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
12741 +               nxi, nxi ? nxi->nx_id : 0, ifa,
12742 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
12743 +
12744 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
12745 +               return 1;
12746 +       if (v4_ifa_in_nx_info(ifa, nxi))
12747 +               return 1;
12748 +       return 0;
12749 +}
12750 +
12751 +
12752 +struct nx_v4_sock_addr {
12753 +       __be32 saddr;   /* Address used for validation */
12754 +       __be32 baddr;   /* Address used for socket bind */
12755 +};
12756 +
12757 +static inline
12758 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
12759 +       struct nx_v4_sock_addr *nsa)
12760 +{
12761 +       struct sock *sk = &inet->sk;
12762 +       struct nx_info *nxi = sk->sk_nx_info;
12763 +       __be32 saddr = addr->sin_addr.s_addr;
12764 +       __be32 baddr = saddr;
12765 +
12766 +       vxdprintk(VXD_CBIT(net, 3),
12767 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
12768 +               sk, sk->sk_nx_info, sk->sk_socket,
12769 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
12770 +               NIPQUAD(saddr));
12771 +
12772 +       if (nxi) {
12773 +               if (saddr == INADDR_ANY) {
12774 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
12775 +                               baddr = nxi->v4.ip[0].s_addr;
12776 +               } else if (saddr == IPI_LOOPBACK) {
12777 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12778 +                               baddr = nxi->v4_lback.s_addr;
12779 +               } else {        /* normal address bind */
12780 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
12781 +                               return -EADDRNOTAVAIL;
12782 +               }
12783 +       }
12784 +
12785 +       vxdprintk(VXD_CBIT(net, 3),
12786 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
12787 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
12788 +
12789 +       nsa->saddr = saddr;
12790 +       nsa->baddr = baddr;
12791 +       return 0;
12792 +}
12793 +
12794 +static inline
12795 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
12796 +{
12797 +       inet->saddr = nsa->baddr;
12798 +       inet->rcv_saddr = nsa->baddr;
12799 +}
12800 +
12801 +
12802 +/*
12803 + *      helper to simplify inet_lookup_listener
12804 + *
12805 + *      nxi:   the socket's nx_info if any
12806 + *      addr:  to be verified address
12807 + *      saddr: socket address
12808 + */
12809 +static inline int v4_inet_addr_match (
12810 +       struct nx_info *nxi,
12811 +       __be32 addr,
12812 +       __be32 saddr)
12813 +{
12814 +       if (addr && (saddr == addr))
12815 +               return 1;
12816 +       if (!saddr)
12817 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
12818 +       return 0;
12819 +}
12820 +
12821 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
12822 +{
12823 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
12824 +               (addr == nxi->v4_lback.s_addr))
12825 +               return IPI_LOOPBACK;
12826 +       return addr;
12827 +}
12828 +
12829 +static inline
12830 +int nx_info_has_v4(struct nx_info *nxi)
12831 +{
12832 +       if (!nxi)
12833 +               return 1;
12834 +       if (NX_IPV4(nxi))
12835 +               return 1;
12836 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
12837 +               return 1;
12838 +       return 0;
12839 +}
12840 +
12841 +#else /* CONFIG_INET */
12842 +
12843 +static inline
12844 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
12845 +{
12846 +       return 1;
12847 +}
12848 +
12849 +static inline
12850 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
12851 +{
12852 +       return 1;
12853 +}
12854 +
12855 +static inline
12856 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
12857 +{
12858 +       return 1;
12859 +}
12860 +
12861 +static inline
12862 +int nx_info_has_v4(struct nx_info *nxi)
12863 +{
12864 +       return 0;
12865 +}
12866 +
12867 +#endif /* CONFIG_INET */
12868 +
12869 +#define current_nx_info_has_v4() \
12870 +       nx_info_has_v4(current_nx_info())
12871 +
12872 +#else
12873 +#warning duplicate inclusion
12874 +#endif
12875 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
12876 --- linux-2.6.22.10/include/linux/vs_inet6.h    1970-01-01 01:00:00 +0100
12877 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_inet6.h 2007-10-05 14:54:36 +0200
12878 @@ -0,0 +1,228 @@
12879 +#ifndef _VS_INET6_H
12880 +#define _VS_INET6_H
12881 +
12882 +#include <net/ipv6.h>
12883 +#include "vserver/base.h"
12884 +#include "vserver/network.h"
12885 +#include "vserver/debug.h"
12886 +
12887 +#define NXAV6(a)       NIP6((a)->ip), NIP6((a)->mask), (a)->prefix, (a)->type
12888 +#define NXAV6_FMT      "[" NIP6_FMT "/" NIP6_FMT "/%d:%04x]"
12889 +
12890 +
12891 +#ifdef CONFIG_IPV6
12892 +
12893 +static inline
12894 +int v6_addr_match(struct nx_addr_v6 *nxa,
12895 +       const struct in6_addr *addr, uint16_t mask)
12896 +{
12897 +       switch (nxa->type & mask) {
12898 +       case NXA_TYPE_MASK:
12899 +               return ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
12900 +       case NXA_TYPE_ADDR:
12901 +               return ipv6_addr_equal(&nxa->ip, addr);
12902 +       case NXA_TYPE_ANY:
12903 +               return 1;
12904 +       default:
12905 +               return 0;
12906 +       }
12907 +}
12908 +
12909 +static inline
12910 +int v6_addr_in_nx_info(struct nx_info *nxi,
12911 +       const struct in6_addr *addr, uint16_t mask)
12912 +{
12913 +       struct nx_addr_v6 *nxa;
12914 +
12915 +       if (!nxi)
12916 +               return 1;
12917 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
12918 +               if (v6_addr_match(nxa, addr, mask))
12919 +                       return 1;
12920 +       return 0;
12921 +}
12922 +
12923 +static inline
12924 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
12925 +{
12926 +       /* FIXME: needs full range checks */
12927 +       return v6_addr_match(nxa, &addr->ip, mask);
12928 +}
12929 +
12930 +static inline
12931 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
12932 +{
12933 +       struct nx_addr_v6 *ptr;
12934 +
12935 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
12936 +               if (v6_nx_addr_match(ptr, nxa, mask))
12937 +                       return 1;
12938 +       return 0;
12939 +}
12940 +
12941 +
12942 +/*
12943 + *     Check if a given address matches for a socket
12944 + *
12945 + *     nxi:            the socket's nx_info if any
12946 + *     addr:           to be verified address
12947 + */
12948 +static inline
12949 +int v6_sock_addr_match (
12950 +       struct nx_info *nxi,
12951 +       struct inet_sock *inet,
12952 +       struct in6_addr *addr)
12953 +{
12954 +       struct sock *sk = &inet->sk;
12955 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12956 +
12957 +       if (!ipv6_addr_any(addr) &&
12958 +               ipv6_addr_equal(saddr, addr))
12959 +               return 1;
12960 +       if (ipv6_addr_any(saddr))
12961 +               return v6_addr_in_nx_info(nxi, addr, -1);
12962 +       return 0;
12963 +}
12964 +
12965 +/*
12966 + *     check if address is covered by socket
12967 + *
12968 + *     sk:     the socket to check against
12969 + *     addr:   the address in question (must be != 0)
12970 + */
12971 +
12972 +static inline
12973 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
12974 +{
12975 +       struct nx_info *nxi = sk->sk_nx_info;
12976 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
12977 +
12978 +       vxdprintk(VXD_CBIT(net, 5),
12979 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:" NIP6_FMT " %p;%lx",
12980 +               sk, NXAV6(nxa), nxi, NIP6(*saddr), sk->sk_socket,
12981 +               (sk->sk_socket?sk->sk_socket->flags:0));
12982 +
12983 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
12984 +               return v6_addr_match(nxa, saddr, -1);
12985 +       } else if (nxi) {               /* match against nx_info */
12986 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
12987 +       } else {                        /* unrestricted any socket */
12988 +               return 1;
12989 +       }
12990 +}
12991 +
12992 +
12993 +/* inet related checks and helpers */
12994 +
12995 +
12996 +struct in_ifaddr;
12997 +struct net_device;
12998 +struct sock;
12999 +
13000 +
13001 +#include <linux/netdevice.h>
13002 +#include <linux/inetdevice.h>
13003 +#include <net/inet_timewait_sock.h>
13004 +
13005 +
13006 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13007 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13008 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13009 +
13010 +
13011 +
13012 +static inline
13013 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13014 +{
13015 +       if (!nxi)
13016 +               return 1;
13017 +       if (!ifa)
13018 +               return 0;
13019 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13020 +}
13021 +
13022 +static inline
13023 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13024 +{
13025 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13026 +               return 1;
13027 +       if (v6_ifa_in_nx_info(ifa, nxi))
13028 +               return 1;
13029 +       return 0;
13030 +}
13031 +
13032 +
13033 +struct nx_v6_sock_addr {
13034 +       struct in6_addr saddr;  /* Address used for validation */
13035 +       struct in6_addr baddr;  /* Address used for socket bind */
13036 +};
13037 +
13038 +static inline
13039 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13040 +       struct nx_v6_sock_addr *nsa)
13041 +{
13042 +       // struct sock *sk = &inet->sk;
13043 +       // struct nx_info *nxi = sk->sk_nx_info;
13044 +       struct in6_addr saddr = addr->sin6_addr;
13045 +       struct in6_addr baddr = saddr;
13046 +
13047 +       nsa->saddr = saddr;
13048 +       nsa->baddr = baddr;
13049 +       return 0;
13050 +}
13051 +
13052 +static inline
13053 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13054 +{
13055 +       // struct sock *sk = &inet->sk;
13056 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13057 +
13058 +       // *saddr = nsa->baddr;
13059 +       // inet->saddr = nsa->baddr;
13060 +}
13061 +
13062 +static inline
13063 +int nx_info_has_v6(struct nx_info *nxi)
13064 +{
13065 +       if (!nxi)
13066 +               return 1;
13067 +       if (NX_IPV6(nxi))
13068 +               return 1;
13069 +       return 0;
13070 +}
13071 +
13072 +#else /* CONFIG_IPV6 */
13073 +
13074 +static inline
13075 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13076 +{
13077 +       return 1;
13078 +}
13079 +
13080 +
13081 +static inline
13082 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13083 +{
13084 +       return 1;
13085 +}
13086 +
13087 +static inline
13088 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13089 +{
13090 +       return 1;
13091 +}
13092 +
13093 +static inline
13094 +int nx_info_has_v6(struct nx_info *nxi)
13095 +{
13096 +       return 0;
13097 +}
13098 +
13099 +#endif /* CONFIG_IPV6 */
13100 +
13101 +#define current_nx_info_has_v6() \
13102 +       nx_info_has_v6(current_nx_info())
13103 +
13104 +#else
13105 +#warning duplicate inclusion
13106 +#endif
13107 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
13108 --- linux-2.6.22.10/include/linux/vs_limit.h    1970-01-01 01:00:00 +0100
13109 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_limit.h 2007-08-05 20:53:13 +0200
13110 @@ -0,0 +1,140 @@
13111 +#ifndef _VS_LIMIT_H
13112 +#define _VS_LIMIT_H
13113 +
13114 +#include "vserver/limit.h"
13115 +#include "vserver/base.h"
13116 +#include "vserver/context.h"
13117 +#include "vserver/debug.h"
13118 +#include "vserver/context.h"
13119 +#include "vserver/limit_int.h"
13120 +
13121 +
13122 +#define vx_acc_cres(v, d, p, r) \
13123 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13124 +
13125 +#define vx_acc_cres_cond(x, d, p, r) \
13126 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13127 +       r, d, p, __FILE__, __LINE__)
13128 +
13129 +
13130 +#define vx_add_cres(v, a, p, r) \
13131 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13132 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13133 +
13134 +#define vx_add_cres_cond(x, a, p, r) \
13135 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13136 +       r, a, p, __FILE__, __LINE__)
13137 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13138 +
13139 +
13140 +/* process and file limits */
13141 +
13142 +#define vx_nproc_inc(p) \
13143 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13144 +
13145 +#define vx_nproc_dec(p) \
13146 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13147 +
13148 +#define vx_files_inc(f) \
13149 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13150 +
13151 +#define vx_files_dec(f) \
13152 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13153 +
13154 +#define vx_locks_inc(l) \
13155 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13156 +
13157 +#define vx_locks_dec(l) \
13158 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13159 +
13160 +#define vx_openfd_inc(f) \
13161 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
13162 +
13163 +#define vx_openfd_dec(f) \
13164 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
13165 +
13166 +
13167 +#define vx_cres_avail(v, n, r) \
13168 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13169 +
13170 +
13171 +#define vx_nproc_avail(n) \
13172 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
13173 +
13174 +#define vx_files_avail(n) \
13175 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
13176 +
13177 +#define vx_locks_avail(n) \
13178 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
13179 +
13180 +#define vx_openfd_avail(n) \
13181 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
13182 +
13183 +
13184 +/* dentry limits */
13185 +
13186 +#define vx_dentry_inc(d) do {                                          \
13187 +       if (atomic_read(&d->d_count) == 1)                              \
13188 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
13189 +       } while (0)
13190 +
13191 +#define vx_dentry_dec(d) do {                                          \
13192 +       if (atomic_read(&d->d_count) == 0)                              \
13193 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
13194 +       } while (0)
13195 +
13196 +#define vx_dentry_avail(n) \
13197 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
13198 +
13199 +
13200 +/* socket limits */
13201 +
13202 +#define vx_sock_inc(s) \
13203 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13204 +
13205 +#define vx_sock_dec(s) \
13206 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13207 +
13208 +#define vx_sock_avail(n) \
13209 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
13210 +
13211 +
13212 +/* ipc resource limits */
13213 +
13214 +#define vx_ipcmsg_add(v, u, a) \
13215 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13216 +
13217 +#define vx_ipcmsg_sub(v, u, a) \
13218 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13219 +
13220 +#define vx_ipcmsg_avail(v, a) \
13221 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13222 +
13223 +
13224 +#define vx_ipcshm_add(v, k, a) \
13225 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13226 +
13227 +#define vx_ipcshm_sub(v, k, a) \
13228 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13229 +
13230 +#define vx_ipcshm_avail(v, a) \
13231 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13232 +
13233 +
13234 +#define vx_semary_inc(a) \
13235 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
13236 +
13237 +#define vx_semary_dec(a) \
13238 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
13239 +
13240 +
13241 +#define vx_nsems_add(a,n) \
13242 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13243 +
13244 +#define vx_nsems_sub(a,n) \
13245 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
13246 +
13247 +
13248 +#else
13249 +#warning duplicate inclusion
13250 +#endif
13251 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
13252 --- linux-2.6.22.10/include/linux/vs_memory.h   1970-01-01 01:00:00 +0100
13253 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_memory.h        2007-08-05 20:53:13 +0200
13254 @@ -0,0 +1,159 @@
13255 +#ifndef _VS_MEMORY_H
13256 +#define _VS_MEMORY_H
13257 +
13258 +#include "vserver/limit.h"
13259 +#include "vserver/base.h"
13260 +#include "vserver/context.h"
13261 +#include "vserver/debug.h"
13262 +#include "vserver/context.h"
13263 +#include "vserver/limit_int.h"
13264 +
13265 +
13266 +#define __acc_add_long(a, v)   (*(v) += (a))
13267 +#define __acc_inc_long(v)      (++*(v))
13268 +#define __acc_dec_long(v)      (--*(v))
13269 +
13270 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
13271 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
13272 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
13273 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
13274 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13275 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
13276 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
13277 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
13278 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
13279 +
13280 +
13281 +#define vx_acc_page(m, d, v, r) do {                                   \
13282 +       if ((d) > 0)                                                    \
13283 +               __acc_inc_long(&(m)->v);                                \
13284 +       else                                                            \
13285 +               __acc_dec_long(&(m)->v);                                \
13286 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13287 +} while (0)
13288 +
13289 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
13290 +       if ((d) > 0)                                                    \
13291 +               __acc_inc_atomic(&(m)->v);                              \
13292 +       else                                                            \
13293 +               __acc_dec_atomic(&(m)->v);                              \
13294 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
13295 +} while (0)
13296 +
13297 +
13298 +#define vx_acc_pages(m, p, v, r) do {                                  \
13299 +       unsigned long __p = (p);                                        \
13300 +       __acc_add_long(__p, &(m)->v);                                   \
13301 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13302 +} while (0)
13303 +
13304 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
13305 +       unsigned long __p = (p);                                        \
13306 +       __acc_add_atomic(__p, &(m)->v);                                 \
13307 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
13308 +} while (0)
13309 +
13310 +
13311 +
13312 +#define vx_acc_vmpage(m, d) \
13313 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
13314 +#define vx_acc_vmlpage(m, d) \
13315 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
13316 +#define vx_acc_file_rsspage(m, d) \
13317 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
13318 +#define vx_acc_anon_rsspage(m, d) \
13319 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
13320 +
13321 +#define vx_acc_vmpages(m, p) \
13322 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
13323 +#define vx_acc_vmlpages(m, p) \
13324 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
13325 +#define vx_acc_file_rsspages(m, p) \
13326 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
13327 +#define vx_acc_anon_rsspages(m, p) \
13328 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
13329 +
13330 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
13331 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
13332 +
13333 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
13334 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
13335 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
13336 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
13337 +
13338 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
13339 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
13340 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
13341 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
13342 +
13343 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
13344 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
13345 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
13346 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
13347 +
13348 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
13349 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
13350 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
13351 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
13352 +
13353 +
13354 +#define vx_pages_avail(m, p, r) \
13355 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
13356 +
13357 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
13358 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
13359 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
13360 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
13361 +
13362 +#define vx_rss_avail(m, p) \
13363 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
13364 +
13365 +
13366 +enum {
13367 +       VXPT_UNKNOWN = 0,
13368 +       VXPT_ANON,
13369 +       VXPT_NONE,
13370 +       VXPT_FILE,
13371 +       VXPT_SWAP,
13372 +       VXPT_WRITE
13373 +};
13374 +
13375 +#if 0
13376 +#define        vx_page_fault(mm, vma, type, ret)
13377 +#else
13378 +
13379 +static inline
13380 +void __vx_page_fault(struct mm_struct *mm,
13381 +       struct vm_area_struct *vma, int type, int ret)
13382 +{
13383 +       struct vx_info *vxi = mm->mm_vx_info;
13384 +       int what;
13385 +/*
13386 +       static char *page_type[6] =
13387 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
13388 +       static char *page_what[4] =
13389 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
13390 +*/
13391 +
13392 +       if (!vxi)
13393 +               return;
13394 +
13395 +       what = (ret & 0x3);
13396 +
13397 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
13398 +               type, what, ret, page_type[type], page_what[what]);
13399 +*/
13400 +       if (ret & VM_FAULT_WRITE)
13401 +               what |= 0x4;
13402 +       atomic_inc(&vxi->cacct.page[type][what]);
13403 +}
13404 +
13405 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
13406 +#endif
13407 +
13408 +
13409 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
13410 +
13411 +#else
13412 +#warning duplicate inclusion
13413 +#endif
13414 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
13415 --- linux-2.6.22.10/include/linux/vs_network.h  1970-01-01 01:00:00 +0100
13416 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_network.h       2007-08-05 20:53:13 +0200
13417 @@ -0,0 +1,166 @@
13418 +#ifndef _NX_VS_NETWORK_H
13419 +#define _NX_VS_NETWORK_H
13420 +
13421 +#include "vserver/context.h"
13422 +#include "vserver/network.h"
13423 +#include "vserver/base.h"
13424 +#include "vserver/debug.h"
13425 +
13426 +
13427 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
13428 +
13429 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
13430 +       const char *_file, int _line)
13431 +{
13432 +       if (!nxi)
13433 +               return NULL;
13434 +
13435 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
13436 +               nxi, nxi ? nxi->nx_id : 0,
13437 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13438 +               _file, _line);
13439 +
13440 +       atomic_inc(&nxi->nx_usecnt);
13441 +       return nxi;
13442 +}
13443 +
13444 +
13445 +extern void free_nx_info(struct nx_info *);
13446 +
13447 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
13448 +
13449 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
13450 +{
13451 +       if (!nxi)
13452 +               return;
13453 +
13454 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
13455 +               nxi, nxi ? nxi->nx_id : 0,
13456 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13457 +               _file, _line);
13458 +
13459 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
13460 +               free_nx_info(nxi);
13461 +}
13462 +
13463 +
13464 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
13465 +
13466 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
13467 +               const char *_file, int _line)
13468 +{
13469 +       if (nxi) {
13470 +               vxlprintk(VXD_CBIT(nid, 3),
13471 +                       "init_nx_info(%p[#%d.%d])",
13472 +                       nxi, nxi ? nxi->nx_id : 0,
13473 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13474 +                       _file, _line);
13475 +
13476 +               atomic_inc(&nxi->nx_usecnt);
13477 +       }
13478 +       *nxp = nxi;
13479 +}
13480 +
13481 +
13482 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
13483 +
13484 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
13485 +       const char *_file, int _line)
13486 +{
13487 +       struct nx_info *nxo;
13488 +
13489 +       if (!nxi)
13490 +               return;
13491 +
13492 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
13493 +               nxi, nxi ? nxi->nx_id : 0,
13494 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13495 +               _file, _line);
13496 +
13497 +       atomic_inc(&nxi->nx_usecnt);
13498 +       nxo = xchg(nxp, nxi);
13499 +       BUG_ON(nxo);
13500 +}
13501 +
13502 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
13503 +
13504 +static inline void __clr_nx_info(struct nx_info **nxp,
13505 +       const char *_file, int _line)
13506 +{
13507 +       struct nx_info *nxo;
13508 +
13509 +       nxo = xchg(nxp, NULL);
13510 +       if (!nxo)
13511 +               return;
13512 +
13513 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
13514 +               nxo, nxo ? nxo->nx_id : 0,
13515 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
13516 +               _file, _line);
13517 +
13518 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
13519 +               free_nx_info(nxo);
13520 +}
13521 +
13522 +
13523 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
13524 +
13525 +static inline void __claim_nx_info(struct nx_info *nxi,
13526 +       struct task_struct *task, const char *_file, int _line)
13527 +{
13528 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
13529 +               nxi, nxi ? nxi->nx_id : 0,
13530 +               nxi?atomic_read(&nxi->nx_usecnt):0,
13531 +               nxi?atomic_read(&nxi->nx_tasks):0,
13532 +               task, _file, _line);
13533 +
13534 +       atomic_inc(&nxi->nx_tasks);
13535 +}
13536 +
13537 +
13538 +extern void unhash_nx_info(struct nx_info *);
13539 +
13540 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
13541 +
13542 +static inline void __release_nx_info(struct nx_info *nxi,
13543 +       struct task_struct *task, const char *_file, int _line)
13544 +{
13545 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
13546 +               nxi, nxi ? nxi->nx_id : 0,
13547 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
13548 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
13549 +               task, _file, _line);
13550 +
13551 +       might_sleep();
13552 +
13553 +       if (atomic_dec_and_test(&nxi->nx_tasks))
13554 +               unhash_nx_info(nxi);
13555 +}
13556 +
13557 +
13558 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
13559 +
13560 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
13561 +       const char *_file, int _line)
13562 +{
13563 +       struct nx_info *nxi;
13564 +
13565 +       task_lock(p);
13566 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
13567 +               p, _file, _line);
13568 +       nxi = __get_nx_info(p->nx_info, _file, _line);
13569 +       task_unlock(p);
13570 +       return nxi;
13571 +}
13572 +
13573 +
13574 +static inline void exit_nx_info(struct task_struct *p)
13575 +{
13576 +       if (p->nx_info)
13577 +               release_nx_info(p->nx_info, p);
13578 +}
13579 +
13580 +
13581 +#else
13582 +#warning duplicate inclusion
13583 +#endif
13584 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
13585 --- linux-2.6.22.10/include/linux/vs_pid.h      1970-01-01 01:00:00 +0100
13586 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_pid.h   2007-09-05 02:49:29 +0200
13587 @@ -0,0 +1,133 @@
13588 +#ifndef _VS_PID_H
13589 +#define _VS_PID_H
13590 +
13591 +#include "vserver/base.h"
13592 +#include "vserver/context.h"
13593 +#include "vserver/debug.h"
13594 +#include <linux/pid_namespace.h>
13595 +
13596 +
13597 +/* pid faking stuff */
13598 +
13599 +
13600 +#define vx_info_map_pid(v, p) \
13601 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
13602 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13603 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
13604 +#define vx_map_tgid(p) vx_map_pid(p)
13605 +
13606 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13607 +       const char *func, const char *file, int line)
13608 +{
13609 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13610 +               vxfprintk(VXD_CBIT(cvirt, 2),
13611 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13612 +                       vxi, (long long)vxi->vx_flags, pid,
13613 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13614 +                       func, file, line);
13615 +               if (pid == 0)
13616 +                       return 0;
13617 +               if (pid == vxi->vx_initpid)
13618 +                       return 1;
13619 +       }
13620 +       return pid;
13621 +}
13622 +
13623 +#define vx_info_rmap_pid(v, p) \
13624 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
13625 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
13626 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13627 +
13628 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13629 +       const char *func, const char *file, int line)
13630 +{
13631 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13632 +               vxfprintk(VXD_CBIT(cvirt, 2),
13633 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13634 +                       vxi, (long long)vxi->vx_flags, pid,
13635 +                       (pid == 1) ? vxi->vx_initpid : pid,
13636 +                       func, file, line);
13637 +               if ((pid == 1) && vxi->vx_initpid)
13638 +                       return vxi->vx_initpid;
13639 +               if (pid == vxi->vx_initpid)
13640 +                       return ~0U;
13641 +       }
13642 +       return pid;
13643 +}
13644 +
13645 +
13646 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
13647 +
13648 +static inline
13649 +int vx_proc_task_visible(struct task_struct *task)
13650 +{
13651 +       if ((task->pid == 1) &&
13652 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
13653 +               /* show a blend through init */
13654 +               goto visible;
13655 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
13656 +               goto visible;
13657 +       return 0;
13658 +visible:
13659 +       return 1;
13660 +}
13661 +
13662 +static inline
13663 +struct task_struct *vx_find_proc_task_by_pid(int pid)
13664 +{
13665 +       struct task_struct *task = find_task_by_pid(pid);
13666 +
13667 +       if (task && !vx_proc_task_visible(task)) {
13668 +               vxdprintk(VXD_CBIT(misc, 6),
13669 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
13670 +                       task, task->xid, task->pid,
13671 +                       current, current->xid, current->pid);
13672 +               task = NULL;
13673 +       }
13674 +       return task;
13675 +}
13676 +
13677 +static inline
13678 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
13679 +{
13680 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
13681 +
13682 +       if (task && !vx_proc_task_visible(task)) {
13683 +               vxdprintk(VXD_CBIT(misc, 6),
13684 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
13685 +                       task, task->xid, task->pid,
13686 +                       current, current->xid, current->pid);
13687 +               put_task_struct(task);
13688 +               task = NULL;
13689 +       }
13690 +       return task;
13691 +}
13692 +
13693 +
13694 +static inline
13695 +struct task_struct *vx_child_reaper(struct task_struct *p)
13696 +{
13697 +       struct vx_info *vxi = p->vx_info;
13698 +       struct task_struct *reaper = child_reaper(p);
13699 +
13700 +       if (!vxi)
13701 +               goto out;
13702 +
13703 +       BUG_ON(!p->vx_info->vx_reaper);
13704 +
13705 +       /* child reaper for the guest reaper */
13706 +       if (vxi->vx_reaper == p)
13707 +               goto out;
13708 +
13709 +       reaper = vxi->vx_reaper;
13710 +out:
13711 +       vxdprintk(VXD_CBIT(xid, 7),
13712 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
13713 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
13714 +       return reaper;
13715 +}
13716 +
13717 +
13718 +#else
13719 +#warning duplicate inclusion
13720 +#endif
13721 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
13722 --- linux-2.6.22.10/include/linux/vs_sched.h    1970-01-01 01:00:00 +0100
13723 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_sched.h 2007-08-05 20:53:13 +0200
13724 @@ -0,0 +1,110 @@
13725 +#ifndef _VS_SCHED_H
13726 +#define _VS_SCHED_H
13727 +
13728 +#include "vserver/base.h"
13729 +#include "vserver/context.h"
13730 +#include "vserver/sched.h"
13731 +
13732 +
13733 +#define VAVAVOOM_RATIO          50
13734 +
13735 +#define MAX_PRIO_BIAS           20
13736 +#define MIN_PRIO_BIAS          -20
13737 +
13738 +
13739 +#ifdef CONFIG_VSERVER_HARDCPU
13740 +
13741 +/*
13742 + * effective_prio - return the priority that is based on the static
13743 + * priority but is modified by bonuses/penalties.
13744 + *
13745 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
13746 + * into a -4 ... 0 ... +4 bonus/penalty range.
13747 + *
13748 + * Additionally, we scale another amount based on the number of
13749 + * CPU tokens currently held by the context, if the process is
13750 + * part of a context (and the appropriate SCHED flag is set).
13751 + * This ranges from -5 ... 0 ... +15, quadratically.
13752 + *
13753 + * So, the total bonus is -9 .. 0 .. +19
13754 + * We use ~50% of the full 0...39 priority range so that:
13755 + *
13756 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
13757 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
13758 + *    unless that context is far exceeding its CPU allocation.
13759 + *
13760 + * Both properties are important to certain workloads.
13761 + */
13762 +static inline
13763 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
13764 +{
13765 +       int vavavoom, max;
13766 +
13767 +       /* lots of tokens = lots of vavavoom
13768 +        *      no tokens = no vavavoom      */
13769 +       if ((vavavoom = sched_pc->tokens) >= 0) {
13770 +               max = sched_pc->tokens_max;
13771 +               vavavoom = max - vavavoom;
13772 +               max = max * max;
13773 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
13774 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
13775 +               return vavavoom;
13776 +       }
13777 +       return 0;
13778 +}
13779 +
13780 +
13781 +static inline
13782 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
13783 +{
13784 +       struct vx_info *vxi = p->vx_info;
13785 +       struct _vx_sched_pc *sched_pc;
13786 +
13787 +       if (!vxi)
13788 +               return prio;
13789 +
13790 +       sched_pc = &vx_cpu(vxi, sched_pc);
13791 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
13792 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
13793 +
13794 +               sched_pc->vavavoom = vavavoom;
13795 +               prio += vavavoom;
13796 +       }
13797 +       prio += sched_pc->prio_bias;
13798 +       return prio;
13799 +}
13800 +
13801 +#else /* !CONFIG_VSERVER_HARDCPU */
13802 +
13803 +static inline
13804 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
13805 +{
13806 +       struct vx_info *vxi = p->vx_info;
13807 +
13808 +       if (vxi)
13809 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
13810 +       return prio;
13811 +}
13812 +
13813 +#endif /* CONFIG_VSERVER_HARDCPU */
13814 +
13815 +
13816 +static inline void vx_account_user(struct vx_info *vxi,
13817 +       cputime_t cputime, int nice)
13818 +{
13819 +       if (!vxi)
13820 +               return;
13821 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
13822 +}
13823 +
13824 +static inline void vx_account_system(struct vx_info *vxi,
13825 +       cputime_t cputime, int idle)
13826 +{
13827 +       if (!vxi)
13828 +               return;
13829 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
13830 +}
13831 +
13832 +#else
13833 +#warning duplicate inclusion
13834 +#endif
13835 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
13836 --- linux-2.6.22.10/include/linux/vs_socket.h   1970-01-01 01:00:00 +0100
13837 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_socket.h        2007-08-05 20:53:13 +0200
13838 @@ -0,0 +1,80 @@
13839 +#ifndef _VS_SOCKET_H
13840 +#define _VS_SOCKET_H
13841 +
13842 +#include "vserver/debug.h"
13843 +#include "vserver/base.h"
13844 +#include "vserver/cacct.h"
13845 +#include "vserver/context.h"
13846 +#include "vserver/tag.h"
13847 +
13848 +
13849 +/* socket accounting */
13850 +
13851 +#include <linux/socket.h>
13852 +
13853 +static inline int vx_sock_type(int family)
13854 +{
13855 +       switch (family) {
13856 +       case PF_UNSPEC:
13857 +               return VXA_SOCK_UNSPEC;
13858 +       case PF_UNIX:
13859 +               return VXA_SOCK_UNIX;
13860 +       case PF_INET:
13861 +               return VXA_SOCK_INET;
13862 +       case PF_INET6:
13863 +               return VXA_SOCK_INET6;
13864 +       case PF_PACKET:
13865 +               return VXA_SOCK_PACKET;
13866 +       default:
13867 +               return VXA_SOCK_OTHER;
13868 +       }
13869 +}
13870 +
13871 +#define vx_acc_sock(v, f, p, s) \
13872 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
13873 +
13874 +static inline void __vx_acc_sock(struct vx_info *vxi,
13875 +       int family, int pos, int size, char *file, int line)
13876 +{
13877 +       if (vxi) {
13878 +               int type = vx_sock_type(family);
13879 +
13880 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
13881 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
13882 +       }
13883 +}
13884 +
13885 +#define vx_sock_recv(sk, s) \
13886 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
13887 +#define vx_sock_send(sk, s) \
13888 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
13889 +#define vx_sock_fail(sk, s) \
13890 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
13891 +
13892 +
13893 +#define sock_vx_init(s) do {           \
13894 +       (s)->sk_xid = 0;                \
13895 +       (s)->sk_vx_info = NULL;         \
13896 +       } while (0)
13897 +
13898 +#define sock_nx_init(s) do {           \
13899 +       (s)->sk_nid = 0;                \
13900 +       (s)->sk_nx_info = NULL;         \
13901 +       } while (0)
13902 +
13903 +static inline
13904 +int vx_socket_peer_tag(struct socket *sock, int level,
13905 +       char __user *optval, int __user *optlen, int len)
13906 +{
13907 +       struct peer_tag tag;
13908 +
13909 +       tag.xid = sock->sk->sk_xid;
13910 +       tag.nid = sock->sk->sk_nid;
13911 +       if (copy_to_user(optval, &tag, sizeof(tag)))
13912 +               return -EFAULT;
13913 +       return 0;
13914 +}
13915 +
13916 +#else
13917 +#warning duplicate inclusion
13918 +#endif
13919 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
13920 --- linux-2.6.22.10/include/linux/vs_tag.h      1970-01-01 01:00:00 +0100
13921 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_tag.h   2007-08-15 19:11:32 +0200
13922 @@ -0,0 +1,43 @@
13923 +#ifndef _VS_TAG_H
13924 +#define _VS_TAG_H
13925 +
13926 +#include <linux/vserver/tag.h>
13927 +
13928 +/* check conditions */
13929 +
13930 +#define DX_ADMIN       0x0001
13931 +#define DX_WATCH       0x0002
13932 +#define DX_HOSTID      0x0008
13933 +
13934 +#define DX_IDENT       0x0010
13935 +
13936 +#define DX_ARG_MASK    0x0010
13937 +
13938 +
13939 +#define dx_task_tag(t) ((t)->tag)
13940 +
13941 +#define dx_current_tag() dx_task_tag(current)
13942 +
13943 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
13944 +
13945 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
13946 +
13947 +
13948 +/*
13949 + * check current context for ADMIN/WATCH and
13950 + * optionally against supplied argument
13951 + */
13952 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
13953 +{
13954 +       if (mode & DX_ARG_MASK) {
13955 +               if ((mode & DX_IDENT) && (id == cid))
13956 +                       return 1;
13957 +       }
13958 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
13959 +               ((mode & DX_WATCH) && (cid == 1)) ||
13960 +               ((mode & DX_HOSTID) && (id == 0)));
13961 +}
13962 +
13963 +#else
13964 +#warning duplicate inclusion
13965 +#endif
13966 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
13967 --- linux-2.6.22.10/include/linux/vs_time.h     1970-01-01 01:00:00 +0100
13968 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vs_time.h  2007-08-05 20:53:13 +0200
13969 @@ -0,0 +1,19 @@
13970 +#ifndef _VS_TIME_H
13971 +#define _VS_TIME_H
13972 +
13973 +
13974 +/* time faking stuff */
13975 +
13976 +#ifdef CONFIG_VSERVER_VTIME
13977 +
13978 +extern void vx_gettimeofday(struct timeval *tv);
13979 +extern int vx_settimeofday(struct timespec *ts);
13980 +
13981 +#else
13982 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
13983 +#define        vx_settimeofday(t)      do_settimeofday(t)
13984 +#endif
13985 +
13986 +#else
13987 +#warning duplicate inclusion
13988 +#endif
13989 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
13990 --- linux-2.6.22.10/include/linux/vserver/Kbuild        1970-01-01 01:00:00 +0100
13991 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/Kbuild     2007-10-11 01:10:22 +0200
13992 @@ -0,0 +1,8 @@
13993 +
13994 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
13995 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
13996 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
13997 +       debug_cmd.h device_cmd.h
13998 +
13999 +unifdef-y += switch.h network.h monitor.h inode.h device.h
14000 +
14001 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
14002 --- linux-2.6.22.10/include/linux/vserver/base.h        1970-01-01 01:00:00 +0100
14003 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/base.h     2007-09-17 14:07:30 +0200
14004 @@ -0,0 +1,218 @@
14005 +#ifndef _VX_BASE_H
14006 +#define _VX_BASE_H
14007 +
14008 +
14009 +/* context state changes */
14010 +
14011 +enum {
14012 +       VSC_STARTUP = 1,
14013 +       VSC_SHUTDOWN,
14014 +
14015 +       VSC_NETUP,
14016 +       VSC_NETDOWN,
14017 +};
14018 +
14019 +
14020 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
14021 +
14022 +/* check conditions */
14023 +
14024 +#define VS_ADMIN       0x0001
14025 +#define VS_WATCH       0x0002
14026 +#define VS_HIDE                0x0004
14027 +#define VS_HOSTID      0x0008
14028 +
14029 +#define VS_IDENT       0x0010
14030 +#define VS_EQUIV       0x0020
14031 +#define VS_PARENT      0x0040
14032 +#define VS_CHILD       0x0080
14033 +
14034 +#define VS_ARG_MASK    0x00F0
14035 +
14036 +#ifdef CONFIG_VSERVER_PRIVACY
14037 +#define VS_ADMIN_P     (0)
14038 +#define VS_WATCH_P     (0)
14039 +#else
14040 +#define VS_ADMIN_P     VS_ADMIN
14041 +#define VS_WATCH_P     VS_WATCH
14042 +#endif
14043 +
14044 +#define VS_HARDIRQ     0x1000
14045 +#define VS_SOFTIRQ     0x2000
14046 +#define VS_IRQ         0x4000
14047 +
14048 +#define VS_IRQ_MASK    0xF000
14049 +
14050 +#include <linux/hardirq.h>
14051 +
14052 +/*
14053 + * check current context for ADMIN/WATCH and
14054 + * optionally against supplied argument
14055 + */
14056 +static inline int __vs_check(int cid, int id, unsigned int mode)
14057 +{
14058 +       if (mode & VS_ARG_MASK) {
14059 +               if ((mode & VS_IDENT) && (id == cid))
14060 +                       return 1;
14061 +       }
14062 +       if (mode & VS_IRQ_MASK) {
14063 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
14064 +                       return 1;
14065 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
14066 +                       return 1;
14067 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
14068 +                       return 1;
14069 +       }
14070 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
14071 +               ((mode & VS_WATCH) && (cid == 1)) ||
14072 +               ((mode & VS_HOSTID) && (id == 0)));
14073 +}
14074 +
14075 +#define vx_task_xid(t) ((t)->xid)
14076 +
14077 +#define vx_current_xid() vx_task_xid(current)
14078 +
14079 +#define current_vx_info() (current->vx_info)
14080 +
14081 +
14082 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
14083 +
14084 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
14085 +
14086 +
14087 +#define nx_task_nid(t) ((t)->nid)
14088 +
14089 +#define nx_current_nid() nx_task_nid(current)
14090 +
14091 +#define current_nx_info() (current->nx_info)
14092 +
14093 +
14094 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
14095 +
14096 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
14097 +
14098 +
14099 +
14100 +/* generic flag merging */
14101 +
14102 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
14103 +
14104 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
14105 +
14106 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
14107 +
14108 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
14109 +
14110 +
14111 +/* context flags */
14112 +
14113 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
14114 +
14115 +#define vx_current_flags()     __vx_flags(current->vx_info)
14116 +
14117 +#define vx_info_flags(v, m, f) \
14118 +       vs_check_flags(__vx_flags(v), m, f)
14119 +
14120 +#define task_vx_flags(t, m, f) \
14121 +       ((t) && vx_info_flags((t)->vx_info, m, f))
14122 +
14123 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
14124 +
14125 +
14126 +/* context caps */
14127 +
14128 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
14129 +
14130 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
14131 +
14132 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
14133 +
14134 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
14135 +
14136 +
14137 +
14138 +/* network flags */
14139 +
14140 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
14141 +
14142 +#define nx_current_flags()     __nx_flags(current->nx_info)
14143 +
14144 +#define nx_info_flags(n, m, f) \
14145 +       vs_check_flags(__nx_flags(n), m, f)
14146 +
14147 +#define task_nx_flags(t, m, f) \
14148 +       ((t) && nx_info_flags((t)->nx_info, m, f))
14149 +
14150 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
14151 +
14152 +
14153 +/* network caps */
14154 +
14155 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
14156 +
14157 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
14158 +
14159 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
14160 +
14161 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
14162 +
14163 +
14164 +/* context mask capabilities */
14165 +
14166 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
14167 +
14168 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
14169 +
14170 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
14171 +
14172 +
14173 +/* context bcap mask */
14174 +
14175 +#define __vx_bcaps(v)  ((v) ? (v)->vx_bcaps : ~0 )
14176 +
14177 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
14178 +
14179 +#define vx_info_bcaps(v, c)    (__vx_bcaps(v) & (c))
14180 +
14181 +#define vx_bcaps(c)    vx_info_bcaps(current->vx_info, c)
14182 +
14183 +
14184 +#define vx_info_cap_bset(v)    ((v) ? (v)->vx_cap_bset : cap_bset)
14185 +
14186 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
14187 +
14188 +
14189 +#define __vx_info_mbcap(v, b) \
14190 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
14191 +       vx_info_bcaps(v, b) : (b))
14192 +
14193 +#define vx_info_mbcap(v, b)    __vx_info_mbcap(v, cap_t(b))
14194 +
14195 +#define task_vx_mbcap(t, b) \
14196 +       vx_info_mbcap((t)->vx_info, (t)->b)
14197 +
14198 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
14199 +
14200 +#define vx_cap_raised(v, c, f) (vx_info_mbcap(v, c) & CAP_TO_MASK(f))
14201 +
14202 +#define vx_capable(b, c) (capable(b) || \
14203 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
14204 +
14205 +#define nx_capable(b, c) (capable(b) || \
14206 +       (cap_raised(current->cap_effective, b) && nx_ncaps(c)))
14207 +
14208 +#define vx_current_initpid(n) \
14209 +       (current->vx_info && \
14210 +       (current->vx_info->vx_initpid == (n)))
14211 +
14212 +
14213 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
14214 +
14215 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
14216 +
14217 +
14218 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
14219 +
14220 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
14221 +
14222 +#endif
14223 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
14224 --- linux-2.6.22.10/include/linux/vserver/cacct.h       1970-01-01 01:00:00 +0100
14225 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct.h    2007-08-05 20:53:13 +0200
14226 @@ -0,0 +1,15 @@
14227 +#ifndef _VX_CACCT_H
14228 +#define _VX_CACCT_H
14229 +
14230 +
14231 +enum sock_acc_field {
14232 +       VXA_SOCK_UNSPEC = 0,
14233 +       VXA_SOCK_UNIX,
14234 +       VXA_SOCK_INET,
14235 +       VXA_SOCK_INET6,
14236 +       VXA_SOCK_PACKET,
14237 +       VXA_SOCK_OTHER,
14238 +       VXA_SOCK_SIZE   /* array size */
14239 +};
14240 +
14241 +#endif /* _VX_CACCT_H */
14242 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
14243 --- linux-2.6.22.10/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00 +0100
14244 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_cmd.h        2007-08-05 20:53:13 +0200
14245 @@ -0,0 +1,23 @@
14246 +#ifndef _VX_CACCT_CMD_H
14247 +#define _VX_CACCT_CMD_H
14248 +
14249 +
14250 +/* virtual host info name commands */
14251 +
14252 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
14253 +
14254 +struct vcmd_sock_stat_v0 {
14255 +       uint32_t field;
14256 +       uint32_t count[3];
14257 +       uint64_t total[3];
14258 +};
14259 +
14260 +
14261 +#ifdef __KERNEL__
14262 +
14263 +#include <linux/compiler.h>
14264 +
14265 +extern int vc_sock_stat(struct vx_info *, void __user *);
14266 +
14267 +#endif /* __KERNEL__ */
14268 +#endif /* _VX_CACCT_CMD_H */
14269 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
14270 --- linux-2.6.22.10/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00 +0100
14271 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_def.h        2007-08-05 20:53:13 +0200
14272 @@ -0,0 +1,43 @@
14273 +#ifndef _VX_CACCT_DEF_H
14274 +#define _VX_CACCT_DEF_H
14275 +
14276 +#include <asm/atomic.h>
14277 +#include <linux/vserver/cacct.h>
14278 +
14279 +
14280 +struct _vx_sock_acc {
14281 +       atomic_long_t count;
14282 +       atomic_long_t total;
14283 +};
14284 +
14285 +/* context sub struct */
14286 +
14287 +struct _vx_cacct {
14288 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
14289 +       atomic_t slab[8];
14290 +       atomic_t page[6][8];
14291 +};
14292 +
14293 +#ifdef CONFIG_VSERVER_DEBUG
14294 +
14295 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
14296 +{
14297 +       int i, j;
14298 +
14299 +       printk("\t_vx_cacct:");
14300 +       for (i = 0; i < 6; i++) {
14301 +               struct _vx_sock_acc *ptr = cacct->sock[i];
14302 +
14303 +               printk("\t [%d] =", i);
14304 +               for (j = 0; j < 3; j++) {
14305 +                       printk(" [%d] = %8lu, %8lu", j,
14306 +                               atomic_long_read(&ptr[j].count),
14307 +                               atomic_long_read(&ptr[j].total));
14308 +               }
14309 +               printk("\n");
14310 +       }
14311 +}
14312 +
14313 +#endif
14314 +
14315 +#endif /* _VX_CACCT_DEF_H */
14316 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
14317 --- linux-2.6.22.10/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00 +0100
14318 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cacct_int.h        2007-08-05 20:53:13 +0200
14319 @@ -0,0 +1,21 @@
14320 +#ifndef _VX_CACCT_INT_H
14321 +#define _VX_CACCT_INT_H
14322 +
14323 +
14324 +#ifdef __KERNEL__
14325 +
14326 +static inline
14327 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
14328 +{
14329 +       return atomic_long_read(&cacct->sock[type][pos].count);
14330 +}
14331 +
14332 +
14333 +static inline
14334 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
14335 +{
14336 +       return atomic_long_read(&cacct->sock[type][pos].total);
14337 +}
14338 +
14339 +#endif /* __KERNEL__ */
14340 +#endif /* _VX_CACCT_INT_H */
14341 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
14342 --- linux-2.6.22.10/include/linux/vserver/context.h     1970-01-01 01:00:00 +0100
14343 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/context.h  2007-10-11 01:10:22 +0200
14344 @@ -0,0 +1,176 @@
14345 +#ifndef _VX_CONTEXT_H
14346 +#define _VX_CONTEXT_H
14347 +
14348 +#include <linux/types.h>
14349 +#include <linux/capability.h>
14350 +
14351 +
14352 +/* context flags */
14353 +
14354 +#define VXF_INFO_SCHED         0x00000002
14355 +#define VXF_INFO_NPROC         0x00000004
14356 +#define VXF_INFO_PRIVATE       0x00000008
14357 +
14358 +#define VXF_INFO_INIT          0x00000010
14359 +#define VXF_INFO_HIDE          0x00000020
14360 +#define VXF_INFO_ULIMIT                0x00000040
14361 +#define VXF_INFO_NSPACE                0x00000080
14362 +
14363 +#define VXF_SCHED_HARD         0x00000100
14364 +#define VXF_SCHED_PRIO         0x00000200
14365 +#define VXF_SCHED_PAUSE                0x00000400
14366 +
14367 +#define VXF_VIRT_MEM           0x00010000
14368 +#define VXF_VIRT_UPTIME                0x00020000
14369 +#define VXF_VIRT_CPU           0x00040000
14370 +#define VXF_VIRT_LOAD          0x00080000
14371 +#define VXF_VIRT_TIME          0x00100000
14372 +
14373 +#define VXF_HIDE_MOUNT         0x01000000
14374 +/* was VXF_HIDE_NETIF          0x02000000 */
14375 +#define VXF_HIDE_VINFO         0x04000000
14376 +
14377 +#define VXF_STATE_SETUP                (1ULL << 32)
14378 +#define VXF_STATE_INIT         (1ULL << 33)
14379 +#define VXF_STATE_ADMIN                (1ULL << 34)
14380 +
14381 +#define VXF_SC_HELPER          (1ULL << 36)
14382 +#define VXF_REBOOT_KILL                (1ULL << 37)
14383 +#define VXF_PERSISTENT         (1ULL << 38)
14384 +
14385 +#define VXF_FORK_RSS           (1ULL << 48)
14386 +#define VXF_PROLIFIC           (1ULL << 49)
14387 +
14388 +#define VXF_IGNEG_NICE         (1ULL << 52)
14389 +
14390 +#define VXF_ONE_TIME           (0x0007ULL << 32)
14391 +
14392 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
14393 +
14394 +
14395 +/* context migration */
14396 +
14397 +#define VXM_SET_INIT           0x00000001
14398 +#define VXM_SET_REAPER         0x00000002
14399 +
14400 +/* context caps */
14401 +
14402 +#define VXC_CAP_MASK           0x00000000
14403 +
14404 +#define VXC_SET_UTSNAME                0x00000001
14405 +#define VXC_SET_RLIMIT         0x00000002
14406 +
14407 +/* was VXC_RAW_ICMP            0x00000100 */
14408 +#define VXC_SYSLOG             0x00001000
14409 +
14410 +#define VXC_SECURE_MOUNT       0x00010000
14411 +#define VXC_SECURE_REMOUNT     0x00020000
14412 +#define VXC_BINARY_MOUNT       0x00040000
14413 +
14414 +#define VXC_QUOTA_CTL          0x00100000
14415 +#define VXC_ADMIN_MAPPER       0x00200000
14416 +#define VXC_ADMIN_CLOOP                0x00400000
14417 +
14418 +#define VXC_KTHREAD            0x01000000
14419 +
14420 +
14421 +#ifdef __KERNEL__
14422 +
14423 +#include <linux/list.h>
14424 +#include <linux/spinlock.h>
14425 +#include <linux/rcupdate.h>
14426 +
14427 +#include "limit_def.h"
14428 +#include "sched_def.h"
14429 +#include "cvirt_def.h"
14430 +#include "cacct_def.h"
14431 +#include "device_def.h"
14432 +
14433 +struct _vx_info_pc {
14434 +       struct _vx_sched_pc sched_pc;
14435 +       struct _vx_cvirt_pc cvirt_pc;
14436 +};
14437 +
14438 +struct vx_info {
14439 +       struct hlist_node vx_hlist;             /* linked list of contexts */
14440 +       xid_t vx_id;                            /* context id */
14441 +       atomic_t vx_usecnt;                     /* usage count */
14442 +       atomic_t vx_tasks;                      /* tasks count */
14443 +       struct vx_info *vx_parent;              /* parent context */
14444 +       int vx_state;                           /* context state */
14445 +
14446 +       unsigned long vx_nsmask;                /* assignment mask */
14447 +       struct nsproxy *vx_nsproxy;             /* private namespace */
14448 +       struct fs_struct *vx_fs;                /* private namespace fs */
14449 +
14450 +       uint64_t vx_flags;                      /* context flags */
14451 +       uint64_t vx_bcaps;                      /* bounding caps (system) */
14452 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
14453 +       kernel_cap_t vx_cap_bset;               /* the guest's bset */
14454 +
14455 +       struct task_struct *vx_reaper;          /* guest reaper process */
14456 +       pid_t vx_initpid;                       /* PID of guest init */
14457 +       int64_t vx_badness_bias;                /* OOM points bias */
14458 +
14459 +       struct _vx_limit limit;                 /* vserver limits */
14460 +       struct _vx_sched sched;                 /* vserver scheduler */
14461 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
14462 +       struct _vx_cacct cacct;                 /* context accounting */
14463 +
14464 +       struct _vx_device dmap;                 /* default device map targets */
14465 +
14466 +#ifndef CONFIG_SMP
14467 +       struct _vx_info_pc info_pc;             /* per cpu data */
14468 +#else
14469 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
14470 +#endif
14471 +
14472 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
14473 +       int reboot_cmd;                         /* last sys_reboot() cmd */
14474 +       int exit_code;                          /* last process exit code */
14475 +
14476 +       char vx_name[65];                       /* vserver name */
14477 +};
14478 +
14479 +#ifndef CONFIG_SMP
14480 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
14481 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
14482 +#else
14483 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
14484 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
14485 +#endif
14486 +
14487 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
14488 +
14489 +
14490 +struct vx_info_save {
14491 +       struct vx_info *vxi;
14492 +       xid_t xid;
14493 +};
14494 +
14495 +
14496 +/* status flags */
14497 +
14498 +#define VXS_HASHED     0x0001
14499 +#define VXS_PAUSED     0x0010
14500 +#define VXS_SHUTDOWN   0x0100
14501 +#define VXS_HELPER     0x1000
14502 +#define VXS_RELEASED   0x8000
14503 +
14504 +
14505 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
14506 +extern void release_vx_info(struct vx_info *, struct task_struct *);
14507 +
14508 +extern struct vx_info *lookup_vx_info(int);
14509 +extern struct vx_info *lookup_or_create_vx_info(int);
14510 +
14511 +extern int get_xid_list(int, unsigned int *, int);
14512 +extern int xid_is_hashed(xid_t);
14513 +
14514 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
14515 +
14516 +extern long vs_state_change(struct vx_info *, unsigned int);
14517 +
14518 +
14519 +#endif /* __KERNEL__ */
14520 +#endif /* _VX_CONTEXT_H */
14521 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
14522 --- linux-2.6.22.10/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00 +0100
14523 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/context_cmd.h      2007-08-19 00:40:28 +0200
14524 @@ -0,0 +1,128 @@
14525 +#ifndef _VX_CONTEXT_CMD_H
14526 +#define _VX_CONTEXT_CMD_H
14527 +
14528 +
14529 +/* vinfo commands */
14530 +
14531 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
14532 +
14533 +#ifdef __KERNEL__
14534 +extern int vc_task_xid(uint32_t);
14535 +
14536 +#endif /* __KERNEL__ */
14537 +
14538 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
14539 +
14540 +struct vcmd_vx_info_v0 {
14541 +       uint32_t xid;
14542 +       uint32_t initpid;
14543 +       /* more to come */
14544 +};
14545 +
14546 +#ifdef __KERNEL__
14547 +extern int vc_vx_info(struct vx_info *, void __user *);
14548 +
14549 +#endif /* __KERNEL__ */
14550 +
14551 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
14552 +
14553 +struct vcmd_ctx_stat_v0 {
14554 +       uint32_t usecnt;
14555 +       uint32_t tasks;
14556 +       /* more to come */
14557 +};
14558 +
14559 +#ifdef __KERNEL__
14560 +extern int vc_ctx_stat(struct vx_info *, void __user *);
14561 +
14562 +#endif /* __KERNEL__ */
14563 +
14564 +/* context commands */
14565 +
14566 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
14567 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
14568 +
14569 +struct vcmd_ctx_create {
14570 +       uint64_t flagword;
14571 +};
14572 +
14573 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
14574 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
14575 +
14576 +struct vcmd_ctx_migrate {
14577 +       uint64_t flagword;
14578 +};
14579 +
14580 +#ifdef __KERNEL__
14581 +extern int vc_ctx_create(uint32_t, void __user *);
14582 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
14583 +
14584 +#endif /* __KERNEL__ */
14585 +
14586 +
14587 +/* flag commands */
14588 +
14589 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
14590 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
14591 +
14592 +struct vcmd_ctx_flags_v0 {
14593 +       uint64_t flagword;
14594 +       uint64_t mask;
14595 +};
14596 +
14597 +#ifdef __KERNEL__
14598 +extern int vc_get_cflags(struct vx_info *, void __user *);
14599 +extern int vc_set_cflags(struct vx_info *, void __user *);
14600 +
14601 +#endif /* __KERNEL__ */
14602 +
14603 +
14604 +/* context caps commands */
14605 +
14606 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
14607 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
14608 +
14609 +struct vcmd_ctx_caps_v1 {
14610 +       uint64_t ccaps;
14611 +       uint64_t cmask;
14612 +};
14613 +
14614 +#ifdef __KERNEL__
14615 +extern int vc_get_ccaps(struct vx_info *, void __user *);
14616 +extern int vc_set_ccaps(struct vx_info *, void __user *);
14617 +
14618 +#endif /* __KERNEL__ */
14619 +
14620 +
14621 +/* bcaps commands */
14622 +
14623 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
14624 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
14625 +
14626 +struct vcmd_bcaps {
14627 +       uint64_t bcaps;
14628 +       uint64_t bmask;
14629 +};
14630 +
14631 +#ifdef __KERNEL__
14632 +extern int vc_get_bcaps(struct vx_info *, void __user *);
14633 +extern int vc_set_bcaps(struct vx_info *, void __user *);
14634 +
14635 +#endif /* __KERNEL__ */
14636 +
14637 +
14638 +/* OOM badness */
14639 +
14640 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
14641 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
14642 +
14643 +struct vcmd_badness_v0 {
14644 +       int64_t bias;
14645 +};
14646 +
14647 +#ifdef __KERNEL__
14648 +extern int vc_get_badness(struct vx_info *, void __user *);
14649 +extern int vc_set_badness(struct vx_info *, void __user *);
14650 +
14651 +#endif /* __KERNEL__ */
14652 +#endif /* _VX_CONTEXT_CMD_H */
14653 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
14654 --- linux-2.6.22.10/include/linux/vserver/cvirt.h       1970-01-01 01:00:00 +0100
14655 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt.h    2007-08-05 20:53:13 +0200
14656 @@ -0,0 +1,20 @@
14657 +#ifndef _VX_CVIRT_H
14658 +#define _VX_CVIRT_H
14659 +
14660 +
14661 +#ifdef __KERNEL__
14662 +
14663 +struct timespec;
14664 +
14665 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14666 +
14667 +
14668 +struct vx_info;
14669 +
14670 +void vx_update_load(struct vx_info *);
14671 +
14672 +
14673 +int vx_do_syslog(int, char __user *, int);
14674 +
14675 +#endif /* __KERNEL__ */
14676 +#endif /* _VX_CVIRT_H */
14677 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
14678 --- linux-2.6.22.10/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00 +0100
14679 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt_cmd.h        2007-08-05 20:53:13 +0200
14680 @@ -0,0 +1,53 @@
14681 +#ifndef _VX_CVIRT_CMD_H
14682 +#define _VX_CVIRT_CMD_H
14683 +
14684 +
14685 +/* virtual host info name commands */
14686 +
14687 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
14688 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
14689 +
14690 +struct vcmd_vhi_name_v0 {
14691 +       uint32_t field;
14692 +       char name[65];
14693 +};
14694 +
14695 +
14696 +enum vhi_name_field {
14697 +       VHIN_CONTEXT = 0,
14698 +       VHIN_SYSNAME,
14699 +       VHIN_NODENAME,
14700 +       VHIN_RELEASE,
14701 +       VHIN_VERSION,
14702 +       VHIN_MACHINE,
14703 +       VHIN_DOMAINNAME,
14704 +};
14705 +
14706 +
14707 +#ifdef __KERNEL__
14708 +
14709 +#include <linux/compiler.h>
14710 +
14711 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
14712 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
14713 +
14714 +#endif /* __KERNEL__ */
14715 +
14716 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
14717 +
14718 +struct vcmd_virt_stat_v0 {
14719 +       uint64_t offset;
14720 +       uint64_t uptime;
14721 +       uint32_t nr_threads;
14722 +       uint32_t nr_running;
14723 +       uint32_t nr_uninterruptible;
14724 +       uint32_t nr_onhold;
14725 +       uint32_t nr_forks;
14726 +       uint32_t load[3];
14727 +};
14728 +
14729 +#ifdef __KERNEL__
14730 +extern int vc_virt_stat(struct vx_info *, void __user *);
14731 +
14732 +#endif /* __KERNEL__ */
14733 +#endif /* _VX_CVIRT_CMD_H */
14734 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
14735 --- linux-2.6.22.10/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00 +0100
14736 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/cvirt_def.h        2007-08-05 20:53:13 +0200
14737 @@ -0,0 +1,81 @@
14738 +#ifndef _VX_CVIRT_DEF_H
14739 +#define _VX_CVIRT_DEF_H
14740 +
14741 +#include <linux/jiffies.h>
14742 +#include <linux/spinlock.h>
14743 +#include <linux/wait.h>
14744 +#include <linux/time.h>
14745 +#include <linux/utsname.h>
14746 +#include <asm/atomic.h>
14747 +
14748 +
14749 +struct _vx_usage_stat {
14750 +       uint64_t user;
14751 +       uint64_t nice;
14752 +       uint64_t system;
14753 +       uint64_t softirq;
14754 +       uint64_t irq;
14755 +       uint64_t idle;
14756 +       uint64_t iowait;
14757 +};
14758 +
14759 +struct _vx_syslog {
14760 +       wait_queue_head_t log_wait;
14761 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
14762 +
14763 +       unsigned long log_start;        /* next char to be read by syslog() */
14764 +       unsigned long con_start;        /* next char to be sent to consoles */
14765 +       unsigned long log_end;  /* most-recently-written-char + 1 */
14766 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
14767 +
14768 +       char log_buf[1024];
14769 +};
14770 +
14771 +
14772 +/* context sub struct */
14773 +
14774 +struct _vx_cvirt {
14775 +       atomic_t nr_threads;            /* number of current threads */
14776 +       atomic_t nr_running;            /* number of running threads */
14777 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
14778 +
14779 +       atomic_t nr_onhold;             /* processes on hold */
14780 +       uint32_t onhold_last;           /* jiffies when put on hold */
14781 +
14782 +       struct timeval bias_tv;         /* time offset to the host */
14783 +       struct timespec bias_idle;
14784 +       struct timespec bias_uptime;    /* context creation point */
14785 +       uint64_t bias_clock;            /* offset in clock_t */
14786 +
14787 +       spinlock_t load_lock;           /* lock for the load averages */
14788 +       atomic_t load_updates;          /* nr of load updates done so far */
14789 +       uint32_t load_last;             /* last time load was calculated */
14790 +       uint32_t load[3];               /* load averages 1,5,15 */
14791 +
14792 +       atomic_t total_forks;           /* number of forks so far */
14793 +
14794 +       struct _vx_syslog syslog;
14795 +};
14796 +
14797 +struct _vx_cvirt_pc {
14798 +       struct _vx_usage_stat cpustat;
14799 +};
14800 +
14801 +
14802 +#ifdef CONFIG_VSERVER_DEBUG
14803 +
14804 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
14805 +{
14806 +       printk("\t_vx_cvirt:\n");
14807 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
14808 +               atomic_read(&cvirt->nr_threads),
14809 +               atomic_read(&cvirt->nr_running),
14810 +               atomic_read(&cvirt->nr_uninterruptible),
14811 +               atomic_read(&cvirt->nr_onhold));
14812 +       /* add rest here */
14813 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
14814 +}
14815 +
14816 +#endif
14817 +
14818 +#endif /* _VX_CVIRT_DEF_H */
14819 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
14820 --- linux-2.6.22.10/include/linux/vserver/debug.h       1970-01-01 01:00:00 +0100
14821 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/debug.h    2007-10-25 17:05:55 +0200
14822 @@ -0,0 +1,130 @@
14823 +#ifndef _VX_DEBUG_H
14824 +#define _VX_DEBUG_H
14825 +
14826 +
14827 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
14828 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
14829 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
14830 +
14831 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
14832 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
14833 +#define VXF_DEV                "%p[%lu,%d:%d]"
14834 +
14835 +
14836 +#define __FUNC__       __func__
14837 +
14838 +
14839 +#define vxd_path(d, m)                                         \
14840 +       ({ static char _buffer[PATH_MAX];                       \
14841 +          d_path(d, m, _buffer, sizeof(_buffer)); })
14842 +
14843 +#define vxd_cond_path(n)                                       \
14844 +       ((n) ? vxd_path((n)->dentry, (n)->mnt) : "<null>" )
14845 +
14846 +
14847 +#ifdef CONFIG_VSERVER_DEBUG
14848 +
14849 +extern unsigned int vx_debug_switch;
14850 +extern unsigned int vx_debug_xid;
14851 +extern unsigned int vx_debug_nid;
14852 +extern unsigned int vx_debug_tag;
14853 +extern unsigned int vx_debug_net;
14854 +extern unsigned int vx_debug_limit;
14855 +extern unsigned int vx_debug_cres;
14856 +extern unsigned int vx_debug_dlim;
14857 +extern unsigned int vx_debug_quota;
14858 +extern unsigned int vx_debug_cvirt;
14859 +extern unsigned int vx_debug_space;
14860 +extern unsigned int vx_debug_misc;
14861 +
14862 +
14863 +#define VX_LOGLEVEL    "vxD: "
14864 +#define VX_PROC_FMT    "%p: "
14865 +#define VX_PROCESS     current
14866 +
14867 +#define vxdprintk(c, f, x...)                                  \
14868 +       do {                                                    \
14869 +               if (c)                                          \
14870 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
14871 +                               VX_PROCESS , ##x);              \
14872 +       } while (0)
14873 +
14874 +#define vxlprintk(c, f, x...)                                  \
14875 +       do {                                                    \
14876 +               if (c)                                          \
14877 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
14878 +       } while (0)
14879 +
14880 +#define vxfprintk(c, f, x...)                                  \
14881 +       do {                                                    \
14882 +               if (c)                                          \
14883 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
14884 +       } while (0)
14885 +
14886 +
14887 +struct vx_info;
14888 +
14889 +void dump_vx_info(struct vx_info *, int);
14890 +void dump_vx_info_inactive(int);
14891 +
14892 +#else  /* CONFIG_VSERVER_DEBUG */
14893 +
14894 +#define vx_debug_switch 0
14895 +#define vx_debug_xid   0
14896 +#define vx_debug_nid   0
14897 +#define vx_debug_tag   0
14898 +#define vx_debug_net   0
14899 +#define vx_debug_limit 0
14900 +#define vx_debug_cres  0
14901 +#define vx_debug_dlim  0
14902 +#define vx_debug_cvirt 0
14903 +
14904 +#define vxdprintk(x...) do { } while (0)
14905 +#define vxlprintk(x...) do { } while (0)
14906 +#define vxfprintk(x...) do { } while (0)
14907 +
14908 +#endif /* CONFIG_VSERVER_DEBUG */
14909 +
14910 +
14911 +#ifdef CONFIG_VSERVER_WARN
14912 +
14913 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
14914 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
14915 +#define VX_WARN_XID    "[xid #%u] "
14916 +#define VX_WARN_NID    "[nid #%u] "
14917 +#define VX_WARN_TAG    "[tag #%u] "
14918 +
14919 +#define vxwprintk(c, f, x...)                                  \
14920 +       do {                                                    \
14921 +               if (c)                                          \
14922 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
14923 +       } while (0)
14924 +
14925 +#else  /* CONFIG_VSERVER_WARN */
14926 +
14927 +#define vxwprintk(x...) do { } while (0)
14928 +
14929 +#endif /* CONFIG_VSERVER_WARN */
14930 +
14931 +#define vxwprintk_task(c, f, x...)                             \
14932 +       vxwprintk(c, VX_WARN_TASK f,                            \
14933 +               current->comm, current->pid,                    \
14934 +               current->xid, current->nid, current->tag, ##x)
14935 +#define vxwprintk_xid(c, f, x...)                              \
14936 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
14937 +#define vxwprintk_nid(c, f, x...)                              \
14938 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
14939 +#define vxwprintk_tag(c, f, x...)                              \
14940 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
14941 +
14942 +#ifdef CONFIG_VSERVER_DEBUG
14943 +#define vxd_assert_lock(l)     assert_spin_locked(l)
14944 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
14945 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
14946 +#else
14947 +#define vxd_assert_lock(l)     do { } while (0)
14948 +#define vxd_assert(c, f, x...) do { } while (0)
14949 +#endif
14950 +
14951 +
14952 +#endif /* _VX_DEBUG_H */
14953 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
14954 --- linux-2.6.22.10/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00 +0100
14955 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/debug_cmd.h        2007-08-05 20:53:13 +0200
14956 @@ -0,0 +1,58 @@
14957 +#ifndef _VX_DEBUG_CMD_H
14958 +#define _VX_DEBUG_CMD_H
14959 +
14960 +
14961 +/* debug commands */
14962 +
14963 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
14964 +
14965 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
14966 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
14967 +
14968 +struct  vcmd_read_history_v0 {
14969 +       uint32_t index;
14970 +       uint32_t count;
14971 +       char __user *data;
14972 +};
14973 +
14974 +struct  vcmd_read_monitor_v0 {
14975 +       uint32_t index;
14976 +       uint32_t count;
14977 +       char __user *data;
14978 +};
14979 +
14980 +
14981 +#ifdef __KERNEL__
14982 +
14983 +#ifdef CONFIG_COMPAT
14984 +
14985 +#include <asm/compat.h>
14986 +
14987 +struct vcmd_read_history_v0_x32 {
14988 +       uint32_t index;
14989 +       uint32_t count;
14990 +       compat_uptr_t data_ptr;
14991 +};
14992 +
14993 +struct vcmd_read_monitor_v0_x32 {
14994 +       uint32_t index;
14995 +       uint32_t count;
14996 +       compat_uptr_t data_ptr;
14997 +};
14998 +
14999 +#endif  /* CONFIG_COMPAT */
15000 +
15001 +extern int vc_dump_history(uint32_t);
15002 +
15003 +extern int vc_read_history(uint32_t, void __user *);
15004 +extern int vc_read_monitor(uint32_t, void __user *);
15005 +
15006 +#ifdef CONFIG_COMPAT
15007 +
15008 +extern int vc_read_history_x32(uint32_t, void __user *);
15009 +extern int vc_read_monitor_x32(uint32_t, void __user *);
15010 +
15011 +#endif  /* CONFIG_COMPAT */
15012 +
15013 +#endif /* __KERNEL__ */
15014 +#endif /* _VX_DEBUG_CMD_H */
15015 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
15016 --- linux-2.6.22.10/include/linux/vserver/device.h      1970-01-01 01:00:00 +0100
15017 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device.h   2007-10-11 01:10:22 +0200
15018 @@ -0,0 +1,15 @@
15019 +#ifndef _VX_DEVICE_H
15020 +#define _VX_DEVICE_H
15021 +
15022 +
15023 +#define DATTR_CREATE   0x00000001
15024 +#define DATTR_OPEN     0x00000002
15025 +
15026 +#define DATTR_REMAP    0x00000010
15027 +
15028 +#define DATTR_MASK     0x00000013
15029 +
15030 +
15031 +#else  /* _VX_DEVICE_H */
15032 +#warning duplicate inclusion
15033 +#endif /* _VX_DEVICE_H */
15034 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
15035 --- linux-2.6.22.10/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00 +0100
15036 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device_cmd.h       2007-10-11 01:10:22 +0200
15037 @@ -0,0 +1,44 @@
15038 +#ifndef _VX_DEVICE_CMD_H
15039 +#define _VX_DEVICE_CMD_H
15040 +
15041 +
15042 +/*  device vserver commands */
15043 +
15044 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
15045 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
15046 +
15047 +struct vcmd_set_mapping_v0 {
15048 +       const char __user *device;
15049 +       const char __user *target;
15050 +       uint32_t flags;
15051 +};
15052 +
15053 +
15054 +#ifdef __KERNEL__
15055 +
15056 +#ifdef CONFIG_COMPAT
15057 +
15058 +#include <asm/compat.h>
15059 +
15060 +struct vcmd_set_mapping_v0_x32 {
15061 +       compat_uptr_t device_ptr;
15062 +       compat_uptr_t target_ptr;
15063 +       uint32_t flags;
15064 +};
15065 +
15066 +#endif /* CONFIG_COMPAT */
15067 +
15068 +#include <linux/compiler.h>
15069 +
15070 +extern int vc_set_mapping(struct vx_info *, void __user *);
15071 +extern int vc_unset_mapping(struct vx_info *, void __user *);
15072 +
15073 +#ifdef CONFIG_COMPAT
15074 +
15075 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
15076 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
15077 +
15078 +#endif /* CONFIG_COMPAT */
15079 +
15080 +#endif /* __KERNEL__ */
15081 +#endif /* _VX_DEVICE_CMD_H */
15082 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
15083 --- linux-2.6.22.10/include/linux/vserver/device_def.h  1970-01-01 01:00:00 +0100
15084 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/device_def.h       2007-10-11 01:10:22 +0200
15085 @@ -0,0 +1,17 @@
15086 +#ifndef _VX_DEVICE_DEF_H
15087 +#define _VX_DEVICE_DEF_H
15088 +
15089 +#include <linux/types.h>
15090 +
15091 +struct vx_dmap_target {
15092 +       dev_t target;
15093 +       uint32_t flags;
15094 +};
15095 +
15096 +struct _vx_device {
15097 +#ifdef CONFIG_VSERVER_DEVICE
15098 +       struct vx_dmap_target targets[2];
15099 +#endif
15100 +};
15101 +
15102 +#endif /* _VX_DEVICE_DEF_H */
15103 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
15104 --- linux-2.6.22.10/include/linux/vserver/dlimit.h      1970-01-01 01:00:00 +0100
15105 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/dlimit.h   2007-08-15 22:03:58 +0200
15106 @@ -0,0 +1,54 @@
15107 +#ifndef _VX_DLIMIT_H
15108 +#define _VX_DLIMIT_H
15109 +
15110 +#include "switch.h"
15111 +
15112 +
15113 +#ifdef __KERNEL__
15114 +
15115 +/*      keep in sync with CDLIM_INFINITY       */
15116 +
15117 +#define DLIM_INFINITY          (~0ULL)
15118 +
15119 +#include <linux/spinlock.h>
15120 +#include <linux/rcupdate.h>
15121 +
15122 +struct super_block;
15123 +
15124 +struct dl_info {
15125 +       struct hlist_node dl_hlist;             /* linked list of contexts */
15126 +       struct rcu_head dl_rcu;                 /* the rcu head */
15127 +       tag_t dl_tag;                           /* context tag */
15128 +       atomic_t dl_usecnt;                     /* usage count */
15129 +       atomic_t dl_refcnt;                     /* reference count */
15130 +
15131 +       struct super_block *dl_sb;              /* associated superblock */
15132 +
15133 +       spinlock_t dl_lock;                     /* protect the values */
15134 +
15135 +       unsigned long long dl_space_used;       /* used space in bytes */
15136 +       unsigned long long dl_space_total;      /* maximum space in bytes */
15137 +       unsigned long dl_inodes_used;           /* used inodes */
15138 +       unsigned long dl_inodes_total;          /* maximum inodes */
15139 +
15140 +       unsigned int dl_nrlmult;                /* non root limit mult */
15141 +};
15142 +
15143 +struct rcu_head;
15144 +
15145 +extern void rcu_free_dl_info(struct rcu_head *);
15146 +extern void unhash_dl_info(struct dl_info *);
15147 +
15148 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
15149 +
15150 +
15151 +struct kstatfs;
15152 +
15153 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
15154 +
15155 +typedef uint64_t dlsize_t;
15156 +
15157 +#endif /* __KERNEL__ */
15158 +#else  /* _VX_DLIMIT_H */
15159 +#warning duplicate inclusion
15160 +#endif /* _VX_DLIMIT_H */
15161 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
15162 --- linux-2.6.22.10/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00 +0100
15163 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/dlimit_cmd.h       2007-08-05 20:53:13 +0200
15164 @@ -0,0 +1,74 @@
15165 +#ifndef _VX_DLIMIT_CMD_H
15166 +#define _VX_DLIMIT_CMD_H
15167 +
15168 +
15169 +/*  dlimit vserver commands */
15170 +
15171 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
15172 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
15173 +
15174 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
15175 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
15176 +
15177 +struct vcmd_ctx_dlimit_base_v0 {
15178 +       const char __user *name;
15179 +       uint32_t flags;
15180 +};
15181 +
15182 +struct vcmd_ctx_dlimit_v0 {
15183 +       const char __user *name;
15184 +       uint32_t space_used;                    /* used space in kbytes */
15185 +       uint32_t space_total;                   /* maximum space in kbytes */
15186 +       uint32_t inodes_used;                   /* used inodes */
15187 +       uint32_t inodes_total;                  /* maximum inodes */
15188 +       uint32_t reserved;                      /* reserved for root in % */
15189 +       uint32_t flags;
15190 +};
15191 +
15192 +#define CDLIM_UNSET            ((uint32_t)0UL)
15193 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
15194 +#define CDLIM_KEEP             ((uint32_t)~1UL)
15195 +
15196 +#ifdef __KERNEL__
15197 +
15198 +#ifdef CONFIG_COMPAT
15199 +
15200 +#include <asm/compat.h>
15201 +
15202 +struct vcmd_ctx_dlimit_base_v0_x32 {
15203 +       compat_uptr_t name_ptr;
15204 +       uint32_t flags;
15205 +};
15206 +
15207 +struct vcmd_ctx_dlimit_v0_x32 {
15208 +       compat_uptr_t name_ptr;
15209 +       uint32_t space_used;                    /* used space in kbytes */
15210 +       uint32_t space_total;                   /* maximum space in kbytes */
15211 +       uint32_t inodes_used;                   /* used inodes */
15212 +       uint32_t inodes_total;                  /* maximum inodes */
15213 +       uint32_t reserved;                      /* reserved for root in % */
15214 +       uint32_t flags;
15215 +};
15216 +
15217 +#endif /* CONFIG_COMPAT */
15218 +
15219 +#include <linux/compiler.h>
15220 +
15221 +extern int vc_add_dlimit(uint32_t, void __user *);
15222 +extern int vc_rem_dlimit(uint32_t, void __user *);
15223 +
15224 +extern int vc_set_dlimit(uint32_t, void __user *);
15225 +extern int vc_get_dlimit(uint32_t, void __user *);
15226 +
15227 +#ifdef CONFIG_COMPAT
15228 +
15229 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
15230 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
15231 +
15232 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
15233 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
15234 +
15235 +#endif /* CONFIG_COMPAT */
15236 +
15237 +#endif /* __KERNEL__ */
15238 +#endif /* _VX_DLIMIT_CMD_H */
15239 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
15240 --- linux-2.6.22.10/include/linux/vserver/global.h      1970-01-01 01:00:00 +0100
15241 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/global.h   2007-08-05 20:53:13 +0200
15242 @@ -0,0 +1,18 @@
15243 +#ifndef _VX_GLOBAL_H
15244 +#define _VX_GLOBAL_H
15245 +
15246 +
15247 +extern atomic_t vx_global_ctotal;
15248 +extern atomic_t vx_global_cactive;
15249 +
15250 +extern atomic_t nx_global_ctotal;
15251 +extern atomic_t nx_global_cactive;
15252 +
15253 +extern atomic_t vs_global_nsproxy;
15254 +extern atomic_t vs_global_fs;
15255 +extern atomic_t vs_global_mnt_ns;
15256 +extern atomic_t vs_global_uts_ns;
15257 +extern atomic_t vs_global_ipc_ns;
15258 +
15259 +
15260 +#endif /* _VX_GLOBAL_H */
15261 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
15262 --- linux-2.6.22.10/include/linux/vserver/history.h     1970-01-01 01:00:00 +0100
15263 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/history.h  2007-08-05 20:53:13 +0200
15264 @@ -0,0 +1,197 @@
15265 +#ifndef _VX_HISTORY_H
15266 +#define _VX_HISTORY_H
15267 +
15268 +
15269 +enum {
15270 +       VXH_UNUSED = 0,
15271 +       VXH_THROW_OOPS = 1,
15272 +
15273 +       VXH_GET_VX_INFO,
15274 +       VXH_PUT_VX_INFO,
15275 +       VXH_INIT_VX_INFO,
15276 +       VXH_SET_VX_INFO,
15277 +       VXH_CLR_VX_INFO,
15278 +       VXH_CLAIM_VX_INFO,
15279 +       VXH_RELEASE_VX_INFO,
15280 +       VXH_ALLOC_VX_INFO,
15281 +       VXH_DEALLOC_VX_INFO,
15282 +       VXH_HASH_VX_INFO,
15283 +       VXH_UNHASH_VX_INFO,
15284 +       VXH_LOC_VX_INFO,
15285 +       VXH_LOOKUP_VX_INFO,
15286 +       VXH_CREATE_VX_INFO,
15287 +};
15288 +
15289 +struct _vxhe_vxi {
15290 +       struct vx_info *ptr;
15291 +       unsigned xid;
15292 +       unsigned usecnt;
15293 +       unsigned tasks;
15294 +};
15295 +
15296 +struct _vxhe_set_clr {
15297 +       void *data;
15298 +};
15299 +
15300 +struct _vxhe_loc_lookup {
15301 +       unsigned arg;
15302 +};
15303 +
15304 +struct _vx_hist_entry {
15305 +       void *loc;
15306 +       unsigned short seq;
15307 +       unsigned short type;
15308 +       struct _vxhe_vxi vxi;
15309 +       union {
15310 +               struct _vxhe_set_clr sc;
15311 +               struct _vxhe_loc_lookup ll;
15312 +       };
15313 +};
15314 +
15315 +#ifdef CONFIG_VSERVER_HISTORY
15316 +
15317 +extern unsigned volatile int vxh_active;
15318 +
15319 +struct _vx_hist_entry *vxh_advance(void *loc);
15320 +
15321 +
15322 +static inline
15323 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
15324 +{
15325 +       entry->vxi.ptr = vxi;
15326 +       if (vxi) {
15327 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
15328 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
15329 +               entry->vxi.xid = vxi->vx_id;
15330 +       }
15331 +}
15332 +
15333 +
15334 +#define        __HERE__ current_text_addr()
15335 +
15336 +#define __VXH_BODY(__type, __data, __here)     \
15337 +       struct _vx_hist_entry *entry;           \
15338 +                                               \
15339 +       preempt_disable();                      \
15340 +       entry = vxh_advance(__here);            \
15341 +       __data;                                 \
15342 +       entry->type = __type;                   \
15343 +       preempt_enable();
15344 +
15345 +
15346 +       /* pass vxi only */
15347 +
15348 +#define __VXH_SMPL                             \
15349 +       __vxh_copy_vxi(entry, vxi)
15350 +
15351 +static inline
15352 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
15353 +{
15354 +       __VXH_BODY(__type, __VXH_SMPL, __here)
15355 +}
15356 +
15357 +       /* pass vxi and data (void *) */
15358 +
15359 +#define __VXH_DATA                             \
15360 +       __vxh_copy_vxi(entry, vxi);             \
15361 +       entry->sc.data = data
15362 +
15363 +static inline
15364 +void   __vxh_data(struct vx_info *vxi, void *data,
15365 +                       int __type, void *__here)
15366 +{
15367 +       __VXH_BODY(__type, __VXH_DATA, __here)
15368 +}
15369 +
15370 +       /* pass vxi and arg (long) */
15371 +
15372 +#define __VXH_LONG                             \
15373 +       __vxh_copy_vxi(entry, vxi);             \
15374 +       entry->ll.arg = arg
15375 +
15376 +static inline
15377 +void   __vxh_long(struct vx_info *vxi, long arg,
15378 +                       int __type, void *__here)
15379 +{
15380 +       __VXH_BODY(__type, __VXH_LONG, __here)
15381 +}
15382 +
15383 +
15384 +static inline
15385 +void   __vxh_throw_oops(void *__here)
15386 +{
15387 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
15388 +       /* prevent further acquisition */
15389 +       vxh_active = 0;
15390 +}
15391 +
15392 +
15393 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
15394 +
15395 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
15396 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
15397 +
15398 +#define __vxh_init_vx_info(v, d, h) \
15399 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
15400 +#define __vxh_set_vx_info(v, d, h) \
15401 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
15402 +#define __vxh_clr_vx_info(v, d, h) \
15403 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
15404 +
15405 +#define __vxh_claim_vx_info(v, d, h) \
15406 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
15407 +#define __vxh_release_vx_info(v, d, h) \
15408 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
15409 +
15410 +#define vxh_alloc_vx_info(v) \
15411 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
15412 +#define vxh_dealloc_vx_info(v) \
15413 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
15414 +
15415 +#define vxh_hash_vx_info(v) \
15416 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
15417 +#define vxh_unhash_vx_info(v) \
15418 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
15419 +
15420 +#define vxh_loc_vx_info(v, l) \
15421 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
15422 +#define vxh_lookup_vx_info(v, l) \
15423 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
15424 +#define vxh_create_vx_info(v, l) \
15425 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
15426 +
15427 +extern void vxh_dump_history(void);
15428 +
15429 +
15430 +#else  /* CONFIG_VSERVER_HISTORY */
15431 +
15432 +#define        __HERE__        0
15433 +
15434 +#define vxh_throw_oops()               do { } while (0)
15435 +
15436 +#define __vxh_get_vx_info(v, h)                do { } while (0)
15437 +#define __vxh_put_vx_info(v, h)                do { } while (0)
15438 +
15439 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
15440 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
15441 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
15442 +
15443 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
15444 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
15445 +
15446 +#define vxh_alloc_vx_info(v)           do { } while (0)
15447 +#define vxh_dealloc_vx_info(v)         do { } while (0)
15448 +
15449 +#define vxh_hash_vx_info(v)            do { } while (0)
15450 +#define vxh_unhash_vx_info(v)          do { } while (0)
15451 +
15452 +#define vxh_loc_vx_info(v, l)          do { } while (0)
15453 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
15454 +#define vxh_create_vx_info(v, l)       do { } while (0)
15455 +
15456 +#define vxh_dump_history()             do { } while (0)
15457 +
15458 +
15459 +#endif /* CONFIG_VSERVER_HISTORY */
15460 +
15461 +#endif /* _VX_HISTORY_H */
15462 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
15463 --- linux-2.6.22.10/include/linux/vserver/inode.h       1970-01-01 01:00:00 +0100
15464 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/inode.h    2007-08-05 20:53:13 +0200
15465 @@ -0,0 +1,38 @@
15466 +#ifndef _VX_INODE_H
15467 +#define _VX_INODE_H
15468 +
15469 +
15470 +#define IATTR_TAG      0x01000000
15471 +
15472 +#define IATTR_ADMIN    0x00000001
15473 +#define IATTR_WATCH    0x00000002
15474 +#define IATTR_HIDE     0x00000004
15475 +#define IATTR_FLAGS    0x00000007
15476 +
15477 +#define IATTR_BARRIER  0x00010000
15478 +#define IATTR_IUNLINK  0x00020000
15479 +#define IATTR_IMMUTABLE 0x00040000
15480 +
15481 +#ifdef __KERNEL__
15482 +
15483 +
15484 +#ifdef CONFIG_VSERVER_PROC_SECURE
15485 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
15486 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
15487 +#else
15488 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
15489 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
15490 +#endif
15491 +
15492 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
15493 +
15494 +#endif /* __KERNEL__ */
15495 +
15496 +/* inode ioctls */
15497 +
15498 +#define FIOC_GETXFLG   _IOR('x', 5, long)
15499 +#define FIOC_SETXFLG   _IOW('x', 6, long)
15500 +
15501 +#else  /* _VX_INODE_H */
15502 +#warning duplicate inclusion
15503 +#endif /* _VX_INODE_H */
15504 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
15505 --- linux-2.6.22.10/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00 +0100
15506 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/inode_cmd.h        2007-08-15 18:08:31 +0200
15507 @@ -0,0 +1,59 @@
15508 +#ifndef _VX_INODE_CMD_H
15509 +#define _VX_INODE_CMD_H
15510 +
15511 +
15512 +/*  inode vserver commands */
15513 +
15514 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
15515 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
15516 +
15517 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
15518 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
15519 +
15520 +struct vcmd_ctx_iattr_v1 {
15521 +       const char __user *name;
15522 +       uint32_t tag;
15523 +       uint32_t flags;
15524 +       uint32_t mask;
15525 +};
15526 +
15527 +struct vcmd_ctx_fiattr_v0 {
15528 +       uint32_t tag;
15529 +       uint32_t flags;
15530 +       uint32_t mask;
15531 +};
15532 +
15533 +
15534 +#ifdef __KERNEL__
15535 +
15536 +
15537 +#ifdef CONFIG_COMPAT
15538 +
15539 +#include <asm/compat.h>
15540 +
15541 +struct vcmd_ctx_iattr_v1_x32 {
15542 +       compat_uptr_t name_ptr;
15543 +       uint32_t tag;
15544 +       uint32_t flags;
15545 +       uint32_t mask;
15546 +};
15547 +
15548 +#endif /* CONFIG_COMPAT */
15549 +
15550 +#include <linux/compiler.h>
15551 +
15552 +extern int vc_get_iattr(void __user *);
15553 +extern int vc_set_iattr(void __user *);
15554 +
15555 +extern int vc_fget_iattr(uint32_t, void __user *);
15556 +extern int vc_fset_iattr(uint32_t, void __user *);
15557 +
15558 +#ifdef CONFIG_COMPAT
15559 +
15560 +extern int vc_get_iattr_x32(void __user *);
15561 +extern int vc_set_iattr_x32(void __user *);
15562 +
15563 +#endif /* CONFIG_COMPAT */
15564 +
15565 +#endif /* __KERNEL__ */
15566 +#endif /* _VX_INODE_CMD_H */
15567 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
15568 --- linux-2.6.22.10/include/linux/vserver/limit.h       1970-01-01 01:00:00 +0100
15569 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit.h    2007-08-15 22:27:29 +0200
15570 @@ -0,0 +1,70 @@
15571 +#ifndef _VX_LIMIT_H
15572 +#define _VX_LIMIT_H
15573 +
15574 +#define VLIMIT_NSOCK   16
15575 +#define VLIMIT_OPENFD  17
15576 +#define VLIMIT_ANON    18
15577 +#define VLIMIT_SHMEM   19
15578 +#define VLIMIT_SEMARY  20
15579 +#define VLIMIT_NSEMS   21
15580 +#define VLIMIT_DENTRY  22
15581 +#define VLIMIT_MAPPED  23
15582 +
15583 +
15584 +#ifdef __KERNEL__
15585 +
15586 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
15587 +
15588 +/*     keep in sync with CRLIM_INFINITY */
15589 +
15590 +#define        VLIM_INFINITY   (~0ULL)
15591 +
15592 +#include <asm/atomic.h>
15593 +#include <asm/resource.h>
15594 +
15595 +#ifndef RLIM_INFINITY
15596 +#warning RLIM_INFINITY is undefined
15597 +#endif
15598 +
15599 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
15600 +
15601 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
15602 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
15603 +
15604 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
15605 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
15606 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
15607 +
15608 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
15609 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
15610 +
15611 +typedef atomic_long_t rlim_atomic_t;
15612 +typedef unsigned long rlim_t;
15613 +
15614 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
15615 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
15616 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
15617 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
15618 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
15619 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
15620 +
15621 +
15622 +#if    (RLIM_INFINITY == VLIM_INFINITY)
15623 +#define        VX_VLIM(r) ((long long)(long)(r))
15624 +#define        VX_RLIM(v) ((rlim_t)(v))
15625 +#else
15626 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
15627 +               ? VLIM_INFINITY : (long long)(r))
15628 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
15629 +               ? RLIM_INFINITY : (rlim_t)(v))
15630 +#endif
15631 +
15632 +struct sysinfo;
15633 +
15634 +void vx_vsi_meminfo(struct sysinfo *);
15635 +void vx_vsi_swapinfo(struct sysinfo *);
15636 +
15637 +#define NUM_LIMITS     24
15638 +
15639 +#endif /* __KERNEL__ */
15640 +#endif /* _VX_LIMIT_H */
15641 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
15642 --- linux-2.6.22.10/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00 +0100
15643 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_cmd.h        2007-08-05 20:53:13 +0200
15644 @@ -0,0 +1,69 @@
15645 +#ifndef _VX_LIMIT_CMD_H
15646 +#define _VX_LIMIT_CMD_H
15647 +
15648 +
15649 +/*  rlimit vserver commands */
15650 +
15651 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
15652 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
15653 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
15654 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
15655 +
15656 +struct vcmd_ctx_rlimit_v0 {
15657 +       uint32_t id;
15658 +       uint64_t minimum;
15659 +       uint64_t softlimit;
15660 +       uint64_t maximum;
15661 +};
15662 +
15663 +struct vcmd_ctx_rlimit_mask_v0 {
15664 +       uint32_t minimum;
15665 +       uint32_t softlimit;
15666 +       uint32_t maximum;
15667 +};
15668 +
15669 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
15670 +
15671 +struct vcmd_rlimit_stat_v0 {
15672 +       uint32_t id;
15673 +       uint32_t hits;
15674 +       uint64_t value;
15675 +       uint64_t minimum;
15676 +       uint64_t maximum;
15677 +};
15678 +
15679 +#define CRLIM_UNSET            (0ULL)
15680 +#define CRLIM_INFINITY         (~0ULL)
15681 +#define CRLIM_KEEP             (~1ULL)
15682 +
15683 +#ifdef __KERNEL__
15684 +
15685 +#ifdef CONFIG_IA32_EMULATION
15686 +
15687 +struct vcmd_ctx_rlimit_v0_x32 {
15688 +       uint32_t id;
15689 +       uint64_t minimum;
15690 +       uint64_t softlimit;
15691 +       uint64_t maximum;
15692 +} __attribute__ ((aligned (4)));
15693 +
15694 +#endif /* CONFIG_IA32_EMULATION */
15695 +
15696 +#include <linux/compiler.h>
15697 +
15698 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
15699 +extern int vc_get_rlimit(struct vx_info *, void __user *);
15700 +extern int vc_set_rlimit(struct vx_info *, void __user *);
15701 +extern int vc_reset_minmax(struct vx_info *, void __user *);
15702 +
15703 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
15704 +
15705 +#ifdef CONFIG_IA32_EMULATION
15706 +
15707 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
15708 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
15709 +
15710 +#endif /* CONFIG_IA32_EMULATION */
15711 +
15712 +#endif /* __KERNEL__ */
15713 +#endif /* _VX_LIMIT_CMD_H */
15714 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
15715 --- linux-2.6.22.10/include/linux/vserver/limit_def.h   1970-01-01 01:00:00 +0100
15716 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_def.h        2007-08-05 20:53:13 +0200
15717 @@ -0,0 +1,47 @@
15718 +#ifndef _VX_LIMIT_DEF_H
15719 +#define _VX_LIMIT_DEF_H
15720 +
15721 +#include <asm/atomic.h>
15722 +#include <asm/resource.h>
15723 +
15724 +#include "limit.h"
15725 +
15726 +
15727 +struct _vx_res_limit {
15728 +       rlim_t soft;            /* Context soft limit */
15729 +       rlim_t hard;            /* Context hard limit */
15730 +
15731 +       rlim_atomic_t rcur;     /* Current value */
15732 +       rlim_t rmin;            /* Context minimum */
15733 +       rlim_t rmax;            /* Context maximum */
15734 +
15735 +       atomic_t lhit;          /* Limit hits */
15736 +};
15737 +
15738 +/* context sub struct */
15739 +
15740 +struct _vx_limit {
15741 +       struct _vx_res_limit res[NUM_LIMITS];
15742 +};
15743 +
15744 +#ifdef CONFIG_VSERVER_DEBUG
15745 +
15746 +static inline void __dump_vx_limit(struct _vx_limit *limit)
15747 +{
15748 +       int i;
15749 +
15750 +       printk("\t_vx_limit:");
15751 +       for (i = 0; i < NUM_LIMITS; i++) {
15752 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
15753 +                       i, (unsigned long)__rlim_get(limit, i),
15754 +                       (unsigned long)__rlim_rmin(limit, i),
15755 +                       (unsigned long)__rlim_rmax(limit, i),
15756 +                       (long)__rlim_soft(limit, i),
15757 +                       (long)__rlim_hard(limit, i),
15758 +                       atomic_read(&__rlim_lhit(limit, i)));
15759 +       }
15760 +}
15761 +
15762 +#endif
15763 +
15764 +#endif /* _VX_LIMIT_DEF_H */
15765 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
15766 --- linux-2.6.22.10/include/linux/vserver/limit_int.h   1970-01-01 01:00:00 +0100
15767 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/limit_int.h        2007-08-05 20:53:13 +0200
15768 @@ -0,0 +1,198 @@
15769 +#ifndef _VX_LIMIT_INT_H
15770 +#define _VX_LIMIT_INT_H
15771 +
15772 +#include "context.h"
15773 +
15774 +#ifdef __KERNEL__
15775 +
15776 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
15777 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
15778 +
15779 +extern const char *vlimit_name[NUM_LIMITS];
15780 +
15781 +static inline void __vx_acc_cres(struct vx_info *vxi,
15782 +       int res, int dir, void *_data, char *_file, int _line)
15783 +{
15784 +       if (VXD_RCRES_COND(res))
15785 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
15786 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15787 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15788 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
15789 +       if (!vxi)
15790 +               return;
15791 +
15792 +       if (dir > 0)
15793 +               __rlim_inc(&vxi->limit, res);
15794 +       else
15795 +               __rlim_dec(&vxi->limit, res);
15796 +}
15797 +
15798 +static inline void __vx_add_cres(struct vx_info *vxi,
15799 +       int res, int amount, void *_data, char *_file, int _line)
15800 +{
15801 +       if (VXD_RCRES_COND(res))
15802 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
15803 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15804 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15805 +                       amount, _data, _file, _line);
15806 +       if (amount == 0)
15807 +               return;
15808 +       if (!vxi)
15809 +               return;
15810 +       __rlim_add(&vxi->limit, res, amount);
15811 +}
15812 +
15813 +static inline
15814 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
15815 +{
15816 +       int cond = (value > __rlim_rmax(limit, res));
15817 +
15818 +       if (cond)
15819 +               __rlim_rmax(limit, res) = value;
15820 +       return cond;
15821 +}
15822 +
15823 +static inline
15824 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
15825 +{
15826 +       int cond = (value < __rlim_rmin(limit, res));
15827 +
15828 +       if (cond)
15829 +               __rlim_rmin(limit, res) = value;
15830 +       return cond;
15831 +}
15832 +
15833 +static inline
15834 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
15835 +{
15836 +       if (!__vx_cres_adjust_max(limit, res, value))
15837 +               __vx_cres_adjust_min(limit, res, value);
15838 +}
15839 +
15840 +
15841 +/*     return values:
15842 +        +1 ... no limit hit
15843 +        -1 ... over soft limit
15844 +         0 ... over hard limit         */
15845 +
15846 +static inline int __vx_cres_avail(struct vx_info *vxi,
15847 +       int res, int num, char *_file, int _line)
15848 +{
15849 +       struct _vx_limit *limit;
15850 +       rlim_t value;
15851 +
15852 +       if (VXD_RLIMIT_COND(res))
15853 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
15854 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
15855 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
15856 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
15857 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
15858 +                       num, _file, _line);
15859 +       if (!vxi)
15860 +               return 1;
15861 +
15862 +       limit = &vxi->limit;
15863 +       value = __rlim_get(limit, res);
15864 +
15865 +       if (!__vx_cres_adjust_max(limit, res, value))
15866 +               __vx_cres_adjust_min(limit, res, value);
15867 +
15868 +       if (num == 0)
15869 +               return 1;
15870 +
15871 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
15872 +               return -1;
15873 +       if (value + num <= __rlim_soft(limit, res))
15874 +               return -1;
15875 +
15876 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
15877 +               return 1;
15878 +       if (value + num <= __rlim_hard(limit, res))
15879 +               return 1;
15880 +
15881 +       __rlim_hit(limit, res);
15882 +       return 0;
15883 +}
15884 +
15885 +
15886 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
15887 +
15888 +static inline
15889 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
15890 +{
15891 +       rlim_t value, sum = 0;
15892 +       int res;
15893 +
15894 +       while ((res = *array++)) {
15895 +               value = __rlim_get(limit, res);
15896 +               __vx_cres_fixup(limit, res, value);
15897 +               sum += value;
15898 +       }
15899 +       return sum;
15900 +}
15901 +
15902 +static inline
15903 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
15904 +{
15905 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
15906 +       int res = *array;
15907 +
15908 +       if (value == __rlim_get(limit, res))
15909 +               return value;
15910 +
15911 +       __rlim_set(limit, res, value);
15912 +       /* now adjust min/max */
15913 +       if (!__vx_cres_adjust_max(limit, res, value))
15914 +               __vx_cres_adjust_min(limit, res, value);
15915 +
15916 +       return value;
15917 +}
15918 +
15919 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
15920 +       const int *array, int num, char *_file, int _line)
15921 +{
15922 +       struct _vx_limit *limit;
15923 +       rlim_t value = 0;
15924 +       int res;
15925 +
15926 +       if (num == 0)
15927 +               return 1;
15928 +       if (!vxi)
15929 +               return 1;
15930 +
15931 +       limit = &vxi->limit;
15932 +       res = *array;
15933 +       value = __vx_cres_array_sum(limit, array + 1);
15934 +
15935 +       __rlim_set(limit, res, value);
15936 +       __vx_cres_fixup(limit, res, value);
15937 +
15938 +       return __vx_cres_avail(vxi, res, num, _file, _line);
15939 +}
15940 +
15941 +
15942 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
15943 +{
15944 +       rlim_t value;
15945 +       int res;
15946 +
15947 +       /* complex resources first */
15948 +       if ((id < 0) || (id == RLIMIT_RSS))
15949 +               __vx_cres_array_fixup(limit, VLA_RSS);
15950 +
15951 +       for (res = 0; res < NUM_LIMITS; res++) {
15952 +               if ((id > 0) && (res != id))
15953 +                       continue;
15954 +
15955 +               value = __rlim_get(limit, res);
15956 +               __vx_cres_fixup(limit, res, value);
15957 +
15958 +               /* not supposed to happen, maybe warn? */
15959 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
15960 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
15961 +       }
15962 +}
15963 +
15964 +
15965 +#endif /* __KERNEL__ */
15966 +#endif /* _VX_LIMIT_INT_H */
15967 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
15968 --- linux-2.6.22.10/include/linux/vserver/monitor.h     1970-01-01 01:00:00 +0100
15969 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/monitor.h  2007-08-15 23:16:12 +0200
15970 @@ -0,0 +1,96 @@
15971 +#ifndef _VX_MONITOR_H
15972 +#define _VX_MONITOR_H
15973 +
15974 +#include <linux/types.h>
15975 +
15976 +enum {
15977 +       VXM_UNUSED = 0,
15978 +
15979 +       VXM_SYNC = 0x10,
15980 +
15981 +       VXM_UPDATE = 0x20,
15982 +       VXM_UPDATE_1,
15983 +       VXM_UPDATE_2,
15984 +
15985 +       VXM_RQINFO_1 = 0x24,
15986 +       VXM_RQINFO_2,
15987 +
15988 +       VXM_ACTIVATE = 0x40,
15989 +       VXM_DEACTIVATE,
15990 +       VXM_IDLE,
15991 +
15992 +       VXM_HOLD = 0x44,
15993 +       VXM_UNHOLD,
15994 +
15995 +       VXM_MIGRATE = 0x48,
15996 +       VXM_RESCHED,
15997 +
15998 +       /* all other bits are flags */
15999 +       VXM_SCHED = 0x80,
16000 +};
16001 +
16002 +struct _vxm_update_1 {
16003 +       uint32_t tokens_max;
16004 +       uint32_t fill_rate;
16005 +       uint32_t interval;
16006 +};
16007 +
16008 +struct _vxm_update_2 {
16009 +       uint32_t tokens_min;
16010 +       uint32_t fill_rate;
16011 +       uint32_t interval;
16012 +};
16013 +
16014 +struct _vxm_rqinfo_1 {
16015 +       uint16_t running;
16016 +       uint16_t onhold;
16017 +       uint16_t iowait;
16018 +       uint16_t uintr;
16019 +       uint32_t idle_tokens;
16020 +};
16021 +
16022 +struct _vxm_rqinfo_2 {
16023 +       uint32_t norm_time;
16024 +       uint32_t idle_time;
16025 +       uint32_t idle_skip;
16026 +};
16027 +
16028 +struct _vxm_sched {
16029 +       uint32_t tokens;
16030 +       uint32_t norm_time;
16031 +       uint32_t idle_time;
16032 +};
16033 +
16034 +struct _vxm_task {
16035 +       uint16_t pid;
16036 +       uint16_t state;
16037 +};
16038 +
16039 +struct _vxm_event {
16040 +       uint32_t jif;
16041 +       union {
16042 +               uint32_t seq;
16043 +               uint32_t sec;
16044 +       };
16045 +       union {
16046 +               uint32_t tokens;
16047 +               uint32_t nsec;
16048 +               struct _vxm_task tsk;
16049 +       };
16050 +};
16051 +
16052 +struct _vx_mon_entry {
16053 +       uint16_t type;
16054 +       uint16_t xid;
16055 +       union {
16056 +               struct _vxm_event ev;
16057 +               struct _vxm_sched sd;
16058 +               struct _vxm_update_1 u1;
16059 +               struct _vxm_update_2 u2;
16060 +               struct _vxm_rqinfo_1 q1;
16061 +               struct _vxm_rqinfo_2 q2;
16062 +       };
16063 +};
16064 +
16065 +
16066 +#endif /* _VX_MONITOR_H */
16067 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
16068 --- linux-2.6.22.10/include/linux/vserver/network.h     1970-01-01 01:00:00 +0100
16069 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/network.h  2007-10-05 12:29:05 +0200
16070 @@ -0,0 +1,143 @@
16071 +#ifndef _VX_NETWORK_H
16072 +#define _VX_NETWORK_H
16073 +
16074 +#include <linux/types.h>
16075 +
16076 +
16077 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
16078 +
16079 +
16080 +/* network flags */
16081 +
16082 +#define NXF_INFO_PRIVATE       0x00000008
16083 +
16084 +#define NXF_SINGLE_IP          0x00000100
16085 +#define NXF_LBACK_REMAP                0x00000200
16086 +
16087 +#define NXF_HIDE_NETIF         0x02000000
16088 +#define NXF_HIDE_LBACK         0x04000000
16089 +
16090 +#define NXF_STATE_SETUP                (1ULL << 32)
16091 +#define NXF_STATE_ADMIN                (1ULL << 34)
16092 +
16093 +#define NXF_SC_HELPER          (1ULL << 36)
16094 +#define NXF_PERSISTENT         (1ULL << 38)
16095 +
16096 +#define NXF_ONE_TIME           (0x0005ULL << 32)
16097 +
16098 +
16099 +#define        NXF_INIT_SET            (__nxf_init_set())
16100 +
16101 +static inline uint64_t __nxf_init_set(void) {
16102 +       return    NXF_STATE_ADMIN
16103 +#ifdef CONFIG_VSERVER_AUTO_LBACK
16104 +               | NXF_LBACK_REMAP
16105 +               | NXF_HIDE_LBACK
16106 +#endif
16107 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
16108 +               | NXF_SINGLE_IP
16109 +#endif
16110 +               | NXF_HIDE_NETIF;
16111 +}
16112 +
16113 +
16114 +/* network caps */
16115 +
16116 +#define NXC_RAW_ICMP           0x00000100
16117 +
16118 +
16119 +/* address types */
16120 +
16121 +#define NXA_TYPE_IPV4          0x0001
16122 +#define NXA_TYPE_IPV6          0x0002
16123 +
16124 +#define NXA_TYPE_NONE          0x0000
16125 +#define NXA_TYPE_ANY           0x00FF
16126 +
16127 +#define NXA_TYPE_ADDR          0x0010
16128 +#define NXA_TYPE_MASK          0x0020
16129 +#define NXA_TYPE_RANGE         0x0040
16130 +
16131 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
16132 +
16133 +#define NXA_MOD_BCAST          0x0100
16134 +#define NXA_MOD_LBACK          0x0200
16135 +
16136 +#define NXA_LOOPBACK           0x1000
16137 +
16138 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
16139 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
16140 +
16141 +#ifdef __KERNEL__
16142 +
16143 +#include <linux/list.h>
16144 +#include <linux/spinlock.h>
16145 +#include <linux/rcupdate.h>
16146 +#include <linux/in.h>
16147 +#include <linux/in6.h>
16148 +#include <asm/atomic.h>
16149 +
16150 +struct nx_addr_v4 {
16151 +       struct nx_addr_v4 *next;
16152 +       struct in_addr ip[2];
16153 +       struct in_addr mask;
16154 +       uint16_t type;
16155 +       uint16_t flags;
16156 +};
16157 +
16158 +struct nx_addr_v6 {
16159 +       struct nx_addr_v6 *next;
16160 +       struct in6_addr ip;
16161 +       struct in6_addr mask;
16162 +       uint32_t prefix;
16163 +       uint16_t type;
16164 +       uint16_t flags;
16165 +};
16166 +
16167 +struct nx_info {
16168 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
16169 +       nid_t nx_id;                    /* vnet id */
16170 +       atomic_t nx_usecnt;             /* usage count */
16171 +       atomic_t nx_tasks;              /* tasks count */
16172 +       int nx_state;                   /* context state */
16173 +
16174 +       uint64_t nx_flags;              /* network flag word */
16175 +       uint64_t nx_ncaps;              /* network capabilities */
16176 +
16177 +       struct in_addr v4_lback;        /* Loopback address */
16178 +       struct in_addr v4_bcast;        /* Broadcast address */
16179 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
16180 +#ifdef CONFIG_IPV6
16181 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
16182 +#endif
16183 +       char nx_name[65];               /* network context name */
16184 +};
16185 +
16186 +
16187 +/* status flags */
16188 +
16189 +#define NXS_HASHED      0x0001
16190 +#define NXS_SHUTDOWN    0x0100
16191 +#define NXS_RELEASED    0x8000
16192 +
16193 +extern struct nx_info *lookup_nx_info(int);
16194 +
16195 +extern int get_nid_list(int, unsigned int *, int);
16196 +extern int nid_is_hashed(nid_t);
16197 +
16198 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
16199 +
16200 +extern long vs_net_change(struct nx_info *, unsigned int);
16201 +
16202 +struct sock;
16203 +
16204 +
16205 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
16206 +#ifdef  CONFIG_IPV6
16207 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
16208 +#else
16209 +#define NX_IPV6(n)     (0)
16210 +#endif
16211 +
16212 +#endif /* __KERNEL__ */
16213 +#endif /* _VX_NETWORK_H */
16214 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
16215 --- linux-2.6.22.10/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00 +0100
16216 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/network_cmd.h      2007-08-15 20:08:10 +0200
16217 @@ -0,0 +1,150 @@
16218 +#ifndef _VX_NETWORK_CMD_H
16219 +#define _VX_NETWORK_CMD_H
16220 +
16221 +
16222 +/* vinfo commands */
16223 +
16224 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
16225 +
16226 +#ifdef __KERNEL__
16227 +extern int vc_task_nid(uint32_t);
16228 +
16229 +#endif /* __KERNEL__ */
16230 +
16231 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
16232 +
16233 +struct vcmd_nx_info_v0 {
16234 +       uint32_t nid;
16235 +       /* more to come */
16236 +};
16237 +
16238 +#ifdef __KERNEL__
16239 +extern int vc_nx_info(struct nx_info *, void __user *);
16240 +
16241 +#endif /* __KERNEL__ */
16242 +
16243 +#include <linux/in.h>
16244 +#include <linux/in6.h>
16245 +
16246 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
16247 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
16248 +
16249 +struct  vcmd_net_create {
16250 +       uint64_t flagword;
16251 +};
16252 +
16253 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
16254 +
16255 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
16256 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
16257 +
16258 +struct vcmd_net_addr_v0 {
16259 +       uint16_t type;
16260 +       uint16_t count;
16261 +       struct in_addr ip[4];
16262 +       struct in_addr mask[4];
16263 +};
16264 +
16265 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
16266 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
16267 +
16268 +struct vcmd_net_addr_ipv4_v1 {
16269 +       uint16_t type;
16270 +       uint16_t flags;
16271 +       struct in_addr ip;
16272 +       struct in_addr mask;
16273 +};
16274 +
16275 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
16276 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
16277 +
16278 +struct vcmd_net_addr_ipv6_v1 {
16279 +       uint16_t type;
16280 +       uint16_t flags;
16281 +       uint32_t prefix;
16282 +       struct in6_addr ip;
16283 +       struct in6_addr mask;
16284 +};
16285 +
16286 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
16287 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
16288 +
16289 +struct vcmd_match_ipv4_v0 {
16290 +       uint16_t type;
16291 +       uint16_t flags;
16292 +       uint16_t parent;
16293 +       uint16_t prefix;
16294 +       struct in_addr ip;
16295 +       struct in_addr ip2;
16296 +       struct in_addr mask;
16297 +};
16298 +
16299 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
16300 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
16301 +
16302 +struct vcmd_match_ipv6_v0 {
16303 +       uint16_t type;
16304 +       uint16_t flags;
16305 +       uint16_t parent;
16306 +       uint16_t prefix;
16307 +       struct in6_addr ip;
16308 +       struct in6_addr ip2;
16309 +       struct in6_addr mask;
16310 +};
16311 +
16312 +
16313 +#ifdef __KERNEL__
16314 +extern int vc_net_create(uint32_t, void __user *);
16315 +extern int vc_net_migrate(struct nx_info *, void __user *);
16316 +
16317 +extern int vc_net_add(struct nx_info *, void __user *);
16318 +extern int vc_net_remove(struct nx_info *, void __user *);
16319 +
16320 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
16321 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
16322 +
16323 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
16324 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
16325 +
16326 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
16327 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
16328 +
16329 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
16330 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
16331 +
16332 +#endif /* __KERNEL__ */
16333 +
16334 +
16335 +/* flag commands */
16336 +
16337 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
16338 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
16339 +
16340 +struct vcmd_net_flags_v0 {
16341 +       uint64_t flagword;
16342 +       uint64_t mask;
16343 +};
16344 +
16345 +#ifdef __KERNEL__
16346 +extern int vc_get_nflags(struct nx_info *, void __user *);
16347 +extern int vc_set_nflags(struct nx_info *, void __user *);
16348 +
16349 +#endif /* __KERNEL__ */
16350 +
16351 +
16352 +/* network caps commands */
16353 +
16354 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
16355 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
16356 +
16357 +struct vcmd_net_caps_v0 {
16358 +       uint64_t ncaps;
16359 +       uint64_t cmask;
16360 +};
16361 +
16362 +#ifdef __KERNEL__
16363 +extern int vc_get_ncaps(struct nx_info *, void __user *);
16364 +extern int vc_set_ncaps(struct nx_info *, void __user *);
16365 +
16366 +#endif /* __KERNEL__ */
16367 +#endif /* _VX_CONTEXT_CMD_H */
16368 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
16369 --- linux-2.6.22.10/include/linux/vserver/percpu.h      1970-01-01 01:00:00 +0100
16370 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/percpu.h   2007-08-05 20:53:13 +0200
16371 @@ -0,0 +1,14 @@
16372 +#ifndef _VX_PERCPU_H
16373 +#define _VX_PERCPU_H
16374 +
16375 +#include "cvirt_def.h"
16376 +#include "sched_def.h"
16377 +
16378 +struct _vx_percpu {
16379 +       struct _vx_cvirt_pc cvirt;
16380 +       struct _vx_sched_pc sched;
16381 +};
16382 +
16383 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
16384 +
16385 +#endif /* _VX_PERCPU_H */
16386 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
16387 --- linux-2.6.22.10/include/linux/vserver/sched.h       1970-01-01 01:00:00 +0100
16388 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched.h    2007-08-05 20:53:13 +0200
16389 @@ -0,0 +1,26 @@
16390 +#ifndef _VX_SCHED_H
16391 +#define _VX_SCHED_H
16392 +
16393 +
16394 +#ifdef __KERNEL__
16395 +
16396 +struct timespec;
16397 +
16398 +void vx_vsi_uptime(struct timespec *, struct timespec *);
16399 +
16400 +
16401 +struct vx_info;
16402 +
16403 +void vx_update_load(struct vx_info *);
16404 +
16405 +
16406 +int vx_tokens_recalc(struct _vx_sched_pc *,
16407 +       unsigned long *, unsigned long *, int [2]);
16408 +
16409 +void vx_update_sched_param(struct _vx_sched *sched,
16410 +       struct _vx_sched_pc *sched_pc);
16411 +
16412 +#endif /* __KERNEL__ */
16413 +#else  /* _VX_SCHED_H */
16414 +#warning duplicate inclusion
16415 +#endif /* _VX_SCHED_H */
16416 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
16417 --- linux-2.6.22.10/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00 +0100
16418 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched_cmd.h        2007-08-05 20:53:13 +0200
16419 @@ -0,0 +1,108 @@
16420 +#ifndef _VX_SCHED_CMD_H
16421 +#define _VX_SCHED_CMD_H
16422 +
16423 +
16424 +/*  sched vserver commands */
16425 +
16426 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
16427 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
16428 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
16429 +
16430 +struct vcmd_set_sched_v2 {
16431 +       int32_t fill_rate;
16432 +       int32_t interval;
16433 +       int32_t tokens;
16434 +       int32_t tokens_min;
16435 +       int32_t tokens_max;
16436 +       uint64_t cpu_mask;
16437 +};
16438 +
16439 +struct vcmd_set_sched_v3 {
16440 +       uint32_t set_mask;
16441 +       int32_t fill_rate;
16442 +       int32_t interval;
16443 +       int32_t tokens;
16444 +       int32_t tokens_min;
16445 +       int32_t tokens_max;
16446 +       int32_t priority_bias;
16447 +};
16448 +
16449 +struct vcmd_set_sched_v4 {
16450 +       uint32_t set_mask;
16451 +       int32_t fill_rate;
16452 +       int32_t interval;
16453 +       int32_t tokens;
16454 +       int32_t tokens_min;
16455 +       int32_t tokens_max;
16456 +       int32_t prio_bias;
16457 +       int32_t cpu_id;
16458 +       int32_t bucket_id;
16459 +};
16460 +
16461 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
16462 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
16463 +
16464 +struct vcmd_sched_v5 {
16465 +       uint32_t mask;
16466 +       int32_t cpu_id;
16467 +       int32_t bucket_id;
16468 +       int32_t fill_rate[2];
16469 +       int32_t interval[2];
16470 +       int32_t tokens;
16471 +       int32_t tokens_min;
16472 +       int32_t tokens_max;
16473 +       int32_t prio_bias;
16474 +};
16475 +
16476 +#define VXSM_FILL_RATE         0x0001
16477 +#define VXSM_INTERVAL          0x0002
16478 +#define VXSM_FILL_RATE2                0x0004
16479 +#define VXSM_INTERVAL2         0x0008
16480 +#define VXSM_TOKENS            0x0010
16481 +#define VXSM_TOKENS_MIN                0x0020
16482 +#define VXSM_TOKENS_MAX                0x0040
16483 +#define VXSM_PRIO_BIAS         0x0100
16484 +
16485 +#define VXSM_IDLE_TIME         0x0200
16486 +#define VXSM_FORCE             0x0400
16487 +
16488 +#define        VXSM_V3_MASK            0x0173
16489 +#define        VXSM_SET_MASK           0x01FF
16490 +
16491 +#define VXSM_CPU_ID            0x1000
16492 +#define VXSM_BUCKET_ID         0x2000
16493 +
16494 +#define VXSM_MSEC              0x4000
16495 +
16496 +#define SCHED_KEEP             (-2)    /* only for v2 */
16497 +
16498 +#ifdef __KERNEL__
16499 +
16500 +#include <linux/compiler.h>
16501 +
16502 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
16503 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
16504 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
16505 +extern int vc_set_sched(struct vx_info *, void __user *);
16506 +extern int vc_get_sched(struct vx_info *, void __user *);
16507 +
16508 +#endif /* __KERNEL__ */
16509 +
16510 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
16511 +
16512 +struct vcmd_sched_info {
16513 +       int32_t cpu_id;
16514 +       int32_t bucket_id;
16515 +       uint64_t user_msec;
16516 +       uint64_t sys_msec;
16517 +       uint64_t hold_msec;
16518 +       uint32_t token_usec;
16519 +       int32_t vavavoom;
16520 +};
16521 +
16522 +#ifdef __KERNEL__
16523 +
16524 +extern int vc_sched_info(struct vx_info *, void __user *);
16525 +
16526 +#endif /* __KERNEL__ */
16527 +#endif /* _VX_SCHED_CMD_H */
16528 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
16529 --- linux-2.6.22.10/include/linux/vserver/sched_def.h   1970-01-01 01:00:00 +0100
16530 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/sched_def.h        2007-08-05 20:53:13 +0200
16531 @@ -0,0 +1,68 @@
16532 +#ifndef _VX_SCHED_DEF_H
16533 +#define _VX_SCHED_DEF_H
16534 +
16535 +#include <linux/spinlock.h>
16536 +#include <linux/jiffies.h>
16537 +#include <linux/cpumask.h>
16538 +#include <asm/atomic.h>
16539 +#include <asm/param.h>
16540 +
16541 +
16542 +/* context sub struct */
16543 +
16544 +struct _vx_sched {
16545 +       spinlock_t tokens_lock;         /* lock for token bucket */
16546 +
16547 +       int tokens;                     /* number of CPU tokens */
16548 +       int fill_rate[2];               /* Fill rate: add X tokens... */
16549 +       int interval[2];                /* Divisor:   per Y jiffies   */
16550 +       int tokens_min;                 /* Limit:     minimum for unhold */
16551 +       int tokens_max;                 /* Limit:     no more than N tokens */
16552 +
16553 +       int prio_bias;                  /* bias offset for priority */
16554 +
16555 +       unsigned update_mask;           /* which features should be updated */
16556 +       cpumask_t update;               /* CPUs which should update */
16557 +};
16558 +
16559 +struct _vx_sched_pc {
16560 +       int tokens;                     /* number of CPU tokens */
16561 +       int flags;                      /* bucket flags */
16562 +
16563 +       int fill_rate[2];               /* Fill rate: add X tokens... */
16564 +       int interval[2];                /* Divisor:   per Y jiffies   */
16565 +       int tokens_min;                 /* Limit:     minimum for unhold */
16566 +       int tokens_max;                 /* Limit:     no more than N tokens */
16567 +
16568 +       int prio_bias;                  /* bias offset for priority */
16569 +       int vavavoom;                   /* last calculated vavavoom */
16570 +
16571 +       unsigned long norm_time;        /* last time accounted */
16572 +       unsigned long idle_time;        /* non linear time for fair sched */
16573 +       unsigned long token_time;       /* token time for accounting */
16574 +       unsigned long onhold;           /* jiffies when put on hold */
16575 +
16576 +       uint64_t user_ticks;            /* token tick events */
16577 +       uint64_t sys_ticks;             /* token tick events */
16578 +       uint64_t hold_ticks;            /* token ticks paused */
16579 +};
16580 +
16581 +
16582 +#define VXSF_ONHOLD    0x0001
16583 +#define VXSF_IDLE_TIME 0x0100
16584 +
16585 +#ifdef CONFIG_VSERVER_DEBUG
16586 +
16587 +static inline void __dump_vx_sched(struct _vx_sched *sched)
16588 +{
16589 +       printk("\t_vx_sched:\n");
16590 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
16591 +               sched->fill_rate[0], sched->interval[0],
16592 +               sched->fill_rate[1], sched->interval[1],
16593 +               sched->tokens_min, sched->tokens_max);
16594 +       printk("\t priority = %4d\n", sched->prio_bias);
16595 +}
16596 +
16597 +#endif
16598 +
16599 +#endif /* _VX_SCHED_DEF_H */
16600 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
16601 --- linux-2.6.22.10/include/linux/vserver/signal.h      1970-01-01 01:00:00 +0100
16602 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/signal.h   2007-08-05 20:53:13 +0200
16603 @@ -0,0 +1,14 @@
16604 +#ifndef _VX_SIGNAL_H
16605 +#define _VX_SIGNAL_H
16606 +
16607 +
16608 +#ifdef __KERNEL__
16609 +
16610 +struct vx_info;
16611 +
16612 +int vx_info_kill(struct vx_info *, int, int);
16613 +
16614 +#endif /* __KERNEL__ */
16615 +#else  /* _VX_SIGNAL_H */
16616 +#warning duplicate inclusion
16617 +#endif /* _VX_SIGNAL_H */
16618 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
16619 --- linux-2.6.22.10/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00 +0100
16620 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/signal_cmd.h       2007-08-05 20:53:13 +0200
16621 @@ -0,0 +1,43 @@
16622 +#ifndef _VX_SIGNAL_CMD_H
16623 +#define _VX_SIGNAL_CMD_H
16624 +
16625 +
16626 +/*  signalling vserver commands */
16627 +
16628 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
16629 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
16630 +
16631 +struct vcmd_ctx_kill_v0 {
16632 +       int32_t pid;
16633 +       int32_t sig;
16634 +};
16635 +
16636 +struct vcmd_wait_exit_v0 {
16637 +       int32_t reboot_cmd;
16638 +       int32_t exit_code;
16639 +};
16640 +
16641 +#ifdef __KERNEL__
16642 +
16643 +extern int vc_ctx_kill(struct vx_info *, void __user *);
16644 +extern int vc_wait_exit(struct vx_info *, void __user *);
16645 +
16646 +#endif /* __KERNEL__ */
16647 +
16648 +/*  process alteration commands */
16649 +
16650 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
16651 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
16652 +
16653 +struct vcmd_pflags_v0 {
16654 +       uint32_t flagword;
16655 +       uint32_t mask;
16656 +};
16657 +
16658 +#ifdef __KERNEL__
16659 +
16660 +extern int vc_get_pflags(uint32_t pid, void __user *);
16661 +extern int vc_set_pflags(uint32_t pid, void __user *);
16662 +
16663 +#endif /* __KERNEL__ */
16664 +#endif /* _VX_SIGNAL_CMD_H */
16665 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
16666 --- linux-2.6.22.10/include/linux/vserver/space.h       1970-01-01 01:00:00 +0100
16667 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/space.h    2007-08-05 20:53:13 +0200
16668 @@ -0,0 +1,13 @@
16669 +#ifndef _VX_SPACE_H
16670 +#define _VX_SPACE_H
16671 +
16672 +
16673 +#include <linux/types.h>
16674 +
16675 +struct vx_info;
16676 +
16677 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
16678 +
16679 +#else  /* _VX_SPACE_H */
16680 +#warning duplicate inclusion
16681 +#endif /* _VX_SPACE_H */
16682 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
16683 --- linux-2.6.22.10/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00 +0100
16684 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/space_cmd.h        2007-08-05 20:53:13 +0200
16685 @@ -0,0 +1,26 @@
16686 +#ifndef _VX_SPACE_CMD_H
16687 +#define _VX_SPACE_CMD_H
16688 +
16689 +
16690 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
16691 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
16692 +
16693 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
16694 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
16695 +
16696 +#define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
16697 +
16698 +
16699 +struct vcmd_space_mask {
16700 +       uint64_t mask;
16701 +};
16702 +
16703 +
16704 +#ifdef __KERNEL__
16705 +
16706 +extern int vc_enter_space(struct vx_info *, void __user *);
16707 +extern int vc_set_space(struct vx_info *, void __user *);
16708 +extern int vc_get_space_mask(struct vx_info *, void __user *);
16709 +
16710 +#endif /* __KERNEL__ */
16711 +#endif /* _VX_SPACE_CMD_H */
16712 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
16713 --- linux-2.6.22.10/include/linux/vserver/switch.h      1970-01-01 01:00:00 +0100
16714 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/switch.h   2007-10-11 01:10:22 +0200
16715 @@ -0,0 +1,99 @@
16716 +#ifndef _VX_SWITCH_H
16717 +#define _VX_SWITCH_H
16718 +
16719 +#include <linux/types.h>
16720 +
16721 +
16722 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
16723 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
16724 +#define VC_VERSION(c)          ((c) & 0xFFF)
16725 +
16726 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
16727 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
16728 +
16729 +/*
16730 +
16731 +  Syscall Matrix V2.8
16732 +
16733 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
16734 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
16735 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
16736 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16737 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
16738 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
16739 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16740 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
16741 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
16742 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16743 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
16744 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
16745 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16746 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
16747 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
16748 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16749 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
16750 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
16751 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16752 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
16753 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
16754 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
16755 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
16756 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
16757 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16758 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
16759 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
16760 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
16761 +
16762 +*/
16763 +
16764 +#define VC_CAT_VERSION         0
16765 +
16766 +#define VC_CAT_VSETUP          1
16767 +#define VC_CAT_VHOST           2
16768 +
16769 +#define VC_CAT_DEVICE          6
16770 +
16771 +#define VC_CAT_VPROC           9
16772 +#define VC_CAT_PROCALT         10
16773 +#define VC_CAT_PROCMIG         11
16774 +#define VC_CAT_PROCTRL         12
16775 +
16776 +#define VC_CAT_SCHED           14
16777 +#define VC_CAT_MEMCTRL         20
16778 +
16779 +#define VC_CAT_VNET            25
16780 +#define VC_CAT_NETALT          26
16781 +#define VC_CAT_NETMIG          27
16782 +#define VC_CAT_NETCTRL         28
16783 +
16784 +#define VC_CAT_TAGMIG          35
16785 +#define VC_CAT_DLIMIT          36
16786 +#define VC_CAT_INODE           38
16787 +
16788 +#define VC_CAT_VSTAT           40
16789 +#define VC_CAT_VINFO           46
16790 +#define VC_CAT_EVENT           48
16791 +
16792 +#define VC_CAT_FLAGS           52
16793 +#define VC_CAT_DEBUG           56
16794 +#define VC_CAT_RLIMIT          60
16795 +
16796 +#define VC_CAT_SYSTEST         61
16797 +#define VC_CAT_COMPAT          63
16798 +
16799 +/*  query version */
16800 +
16801 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
16802 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
16803 +
16804 +
16805 +#ifdef __KERNEL__
16806 +
16807 +#include <linux/errno.h>
16808 +
16809 +
16810 +#else  /* __KERNEL__ */
16811 +#define __user
16812 +#endif /* __KERNEL__ */
16813 +
16814 +#endif /* _VX_SWITCH_H */
16815 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
16816 --- linux-2.6.22.10/include/linux/vserver/tag.h 1970-01-01 01:00:00 +0100
16817 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/tag.h      2007-10-10 19:05:04 +0200
16818 @@ -0,0 +1,143 @@
16819 +#ifndef _DX_TAG_H
16820 +#define _DX_TAG_H
16821 +
16822 +#include <linux/types.h>
16823 +
16824 +
16825 +#define DX_TAG(in)     (IS_TAGGED(in))
16826 +
16827 +
16828 +#ifdef CONFIG_DX_TAG_NFSD
16829 +#define DX_TAG_NFSD    1
16830 +#else
16831 +#define DX_TAG_NFSD    0
16832 +#endif
16833 +
16834 +
16835 +#ifdef CONFIG_TAGGING_NONE
16836 +
16837 +#define MAX_UID                0xFFFFFFFF
16838 +#define MAX_GID                0xFFFFFFFF
16839 +
16840 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
16841 +
16842 +#define TAGINO_UID(cond, uid, tag)     (uid)
16843 +#define TAGINO_GID(cond, gid, tag)     (gid)
16844 +
16845 +#endif
16846 +
16847 +
16848 +#ifdef CONFIG_TAGGING_GID16
16849 +
16850 +#define MAX_UID                0xFFFFFFFF
16851 +#define MAX_GID                0x0000FFFF
16852 +
16853 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16854 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
16855 +
16856 +#define TAGINO_UID(cond, uid, tag)     (uid)
16857 +#define TAGINO_GID(cond, gid, tag)     \
16858 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
16859 +
16860 +#endif
16861 +
16862 +
16863 +#ifdef CONFIG_TAGGING_ID24
16864 +
16865 +#define MAX_UID                0x00FFFFFF
16866 +#define MAX_GID                0x00FFFFFF
16867 +
16868 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16869 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
16870 +
16871 +#define TAGINO_UID(cond, uid, tag)     \
16872 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
16873 +#define TAGINO_GID(cond, gid, tag)     \
16874 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
16875 +
16876 +#endif
16877 +
16878 +
16879 +#ifdef CONFIG_TAGGING_UID16
16880 +
16881 +#define MAX_UID                0x0000FFFF
16882 +#define MAX_GID                0xFFFFFFFF
16883 +
16884 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16885 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
16886 +
16887 +#define TAGINO_UID(cond, uid, tag)     \
16888 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
16889 +#define TAGINO_GID(cond, gid, tag)     (gid)
16890 +
16891 +#endif
16892 +
16893 +
16894 +#ifdef CONFIG_TAGGING_INTERN
16895 +
16896 +#define MAX_UID                0xFFFFFFFF
16897 +#define MAX_GID                0xFFFFFFFF
16898 +
16899 +#define INOTAG_TAG(cond, uid, gid, tag)        \
16900 +       ((cond) ? (tag) : 0)
16901 +
16902 +#define TAGINO_UID(cond, uid, tag)     (uid)
16903 +#define TAGINO_GID(cond, gid, tag)     (gid)
16904 +
16905 +#endif
16906 +
16907 +
16908 +#ifndef CONFIG_TAGGING_NONE
16909 +#define dx_current_fstag(sb)   \
16910 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
16911 +#else
16912 +#define dx_current_fstag(sb)   (0)
16913 +#endif
16914 +
16915 +#ifndef CONFIG_TAGGING_INTERN
16916 +#define TAGINO_TAG(cond, tag)  (0)
16917 +#else
16918 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
16919 +#endif
16920 +
16921 +#define INOTAG_UID(cond, uid, gid)     \
16922 +       ((cond) ? ((uid) & MAX_UID) : (uid))
16923 +#define INOTAG_GID(cond, uid, gid)     \
16924 +       ((cond) ? ((gid) & MAX_GID) : (gid))
16925 +
16926 +
16927 +static inline uid_t dx_map_uid(uid_t uid)
16928 +{
16929 +       if ((uid > MAX_UID) && (uid != -1))
16930 +               uid = -2;
16931 +       return (uid & MAX_UID);
16932 +}
16933 +
16934 +static inline gid_t dx_map_gid(gid_t gid)
16935 +{
16936 +       if ((gid > MAX_GID) && (gid != -1))
16937 +               gid = -2;
16938 +       return (gid & MAX_GID);
16939 +}
16940 +
16941 +struct peer_tag {
16942 +       int32_t xid;
16943 +       int32_t nid;
16944 +};
16945 +
16946 +#define dx_notagcheck(nd) \
16947 +       ((nd) && (nd)->mnt && ((nd)->mnt->mnt_flags & MNT_NOTAGCHECK))
16948 +
16949 +int dx_parse_tag(char *string, tag_t *tag, int remove);
16950 +
16951 +#ifdef CONFIG_PROPAGATE
16952 +
16953 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
16954 +
16955 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
16956 +
16957 +#else
16958 +#define dx_propagate_tag(n, i) do { } while (0)
16959 +#endif
16960 +
16961 +#endif /* _DX_TAG_H */
16962 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
16963 --- linux-2.6.22.10/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00 +0100
16964 +++ linux-2.6.22.10-vs2.3.0.29/include/linux/vserver/tag_cmd.h  2007-08-15 20:16:43 +0200
16965 @@ -0,0 +1,22 @@
16966 +#ifndef _VX_TAG_CMD_H
16967 +#define _VX_TAG_CMD_H
16968 +
16969 +
16970 +/* vinfo commands */
16971 +
16972 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
16973 +
16974 +#ifdef __KERNEL__
16975 +extern int vc_task_tag(uint32_t);
16976 +
16977 +#endif /* __KERNEL__ */
16978 +
16979 +/* context commands */
16980 +
16981 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
16982 +
16983 +#ifdef __KERNEL__
16984 +extern int vc_tag_migrate(uint32_t);
16985 +
16986 +#endif /* __KERNEL__ */
16987 +#endif /* _VX_TAG_CMD_H */
16988 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
16989 --- linux-2.6.22.10/include/net/addrconf.h      2007-07-09 13:20:01 +0200
16990 +++ linux-2.6.22.10-vs2.3.0.29/include/net/addrconf.h   2007-08-12 00:22:19 +0200
16991 @@ -69,10 +69,12 @@ extern struct inet6_ifaddr *        ipv6_get_if
16992                                                 int strict);
16993  extern int                     ipv6_get_saddr(struct dst_entry *dst, 
16994                                                struct in6_addr *daddr,
16995 -                                              struct in6_addr *saddr);
16996 +                                              struct in6_addr *saddr,
16997 +                                              struct nx_info *nxi);
16998  extern int                     ipv6_dev_get_saddr(struct net_device *dev, 
16999                                                struct in6_addr *daddr,
17000 -                                              struct in6_addr *saddr);
17001 +                                              struct in6_addr *saddr,
17002 +                                              struct nx_info *nxi);
17003  extern int                     ipv6_get_lladdr(struct net_device *dev,
17004                                                 struct in6_addr *addr,
17005                                                 unsigned char banned_flags);
17006 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
17007 --- linux-2.6.22.10/include/net/af_unix.h       2007-07-09 13:20:01 +0200
17008 +++ linux-2.6.22.10-vs2.3.0.29/include/net/af_unix.h    2007-08-05 20:53:13 +0200
17009 @@ -4,6 +4,7 @@
17010  #include <linux/socket.h>
17011  #include <linux/un.h>
17012  #include <linux/mutex.h>
17013 +#include <linux/vs_base.h>
17014  #include <net/sock.h>
17015  
17016  extern void unix_inflight(struct file *fp);
17017 @@ -17,9 +18,9 @@ extern spinlock_t unix_table_lock;
17018  
17019  extern atomic_t unix_tot_inflight;
17020  
17021 -static inline struct sock *first_unix_socket(int *i)
17022 +static inline struct sock *next_unix_socket_table(int *i)
17023  {
17024 -       for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
17025 +       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17026                 if (!hlist_empty(&unix_socket_table[*i]))
17027                         return __sk_head(&unix_socket_table[*i]);
17028         }
17029 @@ -28,16 +29,19 @@ static inline struct sock *first_unix_so
17030  
17031  static inline struct sock *next_unix_socket(int *i, struct sock *s)
17032  {
17033 -       struct sock *next = sk_next(s);
17034 -       /* More in this chain? */
17035 -       if (next)
17036 -               return next;
17037 -       /* Look for next non-empty chain. */
17038 -       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
17039 -               if (!hlist_empty(&unix_socket_table[*i]))
17040 -                       return __sk_head(&unix_socket_table[*i]);
17041 -       }
17042 -       return NULL;
17043 +       do {
17044 +               if (s)
17045 +                       s = sk_next(s);
17046 +               if (!s)
17047 +                       s = next_unix_socket_table(i);
17048 +       } while (s && !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT));
17049 +       return s;
17050 +}
17051 +
17052 +static inline struct sock *first_unix_socket(int *i)
17053 +{
17054 +       *i = 0;
17055 +       return next_unix_socket(i, NULL);
17056  }
17057  
17058  #define forall_unix_sockets(i, s) \
17059 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
17060 --- linux-2.6.22.10/include/net/inet_timewait_sock.h    2007-05-02 19:25:35 +0200
17061 +++ linux-2.6.22.10-vs2.3.0.29/include/net/inet_timewait_sock.h 2007-08-05 20:53:13 +0200
17062 @@ -115,6 +115,10 @@ struct inet_timewait_sock {
17063  #define tw_refcnt              __tw_common.skc_refcnt
17064  #define tw_hash                        __tw_common.skc_hash
17065  #define tw_prot                        __tw_common.skc_prot
17066 +#define tw_xid         __tw_common.skc_xid
17067 +#define tw_vx_info             __tw_common.skc_vx_info
17068 +#define tw_nid         __tw_common.skc_nid
17069 +#define tw_nx_info             __tw_common.skc_nx_info
17070         volatile unsigned char  tw_substate;
17071         /* 3 bits hole, try to pack */
17072         unsigned char           tw_rcv_wscale;
17073 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
17074 --- linux-2.6.22.10/include/net/route.h 2007-05-02 19:25:35 +0200
17075 +++ linux-2.6.22.10-vs2.3.0.29/include/net/route.h      2007-09-18 03:52:05 +0200
17076 @@ -27,12 +27,16 @@
17077  #include <net/dst.h>
17078  #include <net/inetpeer.h>
17079  #include <net/flow.h>
17080 +#include <net/inet_sock.h>
17081  #include <linux/in_route.h>
17082  #include <linux/rtnetlink.h>
17083  #include <linux/route.h>
17084  #include <linux/ip.h>
17085  #include <linux/cache.h>
17086  #include <linux/security.h>
17087 +#include <linux/vs_base.h>
17088 +#include <linux/vs_inet.h>
17089 +#include <linux/in.h>
17090  
17091  #ifndef __KERNEL__
17092  #warning This file is not supposed to be used outside of kernel.
17093 @@ -143,6 +147,8 @@ static inline char rt_tos2priority(u8 to
17094         return ip_tos2prio[IPTOS_TOS(tos)>>1];
17095  }
17096  
17097 +extern int ip_v4_find_src(struct nx_info *, struct rtable **, struct flowi *);
17098 +
17099  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
17100                                    __be32 src, u32 tos, int oif, u8 protocol,
17101                                    __be16 sport, __be16 dport, struct sock *sk,
17102 @@ -158,7 +164,21 @@ static inline int ip_route_connect(struc
17103                                          .dport = dport } } };
17104  
17105         int err;
17106 -       if (!dst || !src) {
17107 +       struct nx_info *nx_info = current->nx_info;
17108 +
17109 +       if (sk)
17110 +               nx_info = sk->sk_nx_info;
17111 +
17112 +       vxdprintk(VXD_CBIT(net, 4),
17113 +               "ip_route_connect(%p) %p,%p;%lx",
17114 +               sk, nx_info, sk->sk_socket,
17115 +               (sk->sk_socket?sk->sk_socket->flags:0));
17116 +
17117 +       err = ip_v4_find_src(nx_info, rp, &fl);
17118 +       if (err)
17119 +               return err;
17120 +
17121 +       if (!fl.fl4_dst || !fl.fl4_src) {
17122                 err = __ip_route_output_key(rp, &fl);
17123                 if (err)
17124                         return err;
17125 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
17126 --- linux-2.6.22.10/include/net/sock.h  2007-07-09 13:20:02 +0200
17127 +++ linux-2.6.22.10-vs2.3.0.29/include/net/sock.h       2007-08-05 20:53:13 +0200
17128 @@ -119,6 +119,10 @@ struct sock_common {
17129         atomic_t                skc_refcnt;
17130         unsigned int            skc_hash;
17131         struct proto            *skc_prot;
17132 +       xid_t                   skc_xid;
17133 +       struct vx_info          *skc_vx_info;
17134 +       nid_t                   skc_nid;
17135 +       struct nx_info          *skc_nx_info;
17136  };
17137  
17138  /**
17139 @@ -195,6 +199,10 @@ struct sock {
17140  #define sk_refcnt              __sk_common.skc_refcnt
17141  #define sk_hash                        __sk_common.skc_hash
17142  #define sk_prot                        __sk_common.skc_prot
17143 +#define sk_xid                 __sk_common.skc_xid
17144 +#define sk_vx_info             __sk_common.skc_vx_info
17145 +#define sk_nid                 __sk_common.skc_nid
17146 +#define sk_nx_info             __sk_common.skc_nx_info
17147         unsigned char           sk_shutdown : 2,
17148                                 sk_no_check : 2,
17149                                 sk_userlocks : 4;
17150 diff -NurpP --minimal linux-2.6.22.10/init/main.c linux-2.6.22.10-vs2.3.0.29/init/main.c
17151 --- linux-2.6.22.10/init/main.c 2007-07-09 13:20:03 +0200
17152 +++ linux-2.6.22.10-vs2.3.0.29/init/main.c      2007-08-05 20:53:13 +0200
17153 @@ -55,6 +55,7 @@
17154  #include <linux/pid_namespace.h>
17155  #include <linux/device.h>
17156  #include <linux/kthread.h>
17157 +#include <linux/vserver/percpu.h>
17158  
17159  #include <asm/io.h>
17160  #include <asm/bugs.h>
17161 @@ -364,12 +365,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
17162  
17163  static void __init setup_per_cpu_areas(void)
17164  {
17165 -       unsigned long size, i;
17166 +       unsigned long size, vspc, i;
17167         char *ptr;
17168         unsigned long nr_possible_cpus = num_possible_cpus();
17169  
17170 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
17171 +
17172         /* Copy section for each CPU (we discard the original) */
17173 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
17174 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
17175         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
17176  
17177         for_each_possible_cpu(i) {
17178 diff -NurpP --minimal linux-2.6.22.10/ipc/mqueue.c linux-2.6.22.10-vs2.3.0.29/ipc/mqueue.c
17179 --- linux-2.6.22.10/ipc/mqueue.c        2007-07-09 13:20:03 +0200
17180 +++ linux-2.6.22.10-vs2.3.0.29/ipc/mqueue.c     2007-10-01 14:57:41 +0200
17181 @@ -29,6 +29,8 @@
17182  #include <linux/audit.h>
17183  #include <linux/signal.h>
17184  #include <linux/mutex.h>
17185 +#include <linux/vs_context.h>
17186 +#include <linux/vs_limit.h>
17187  
17188  #include <net/sock.h>
17189  #include "util.h"
17190 @@ -151,17 +153,20 @@ static struct inode *mqueue_get_inode(st
17191                         spin_lock(&mq_lock);
17192                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
17193                             u->mq_bytes + mq_bytes >
17194 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
17195 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
17196 +                           !vx_ipcmsg_avail(p->vx_info, mq_bytes)) {
17197                                 spin_unlock(&mq_lock);
17198                                 goto out_inode;
17199                         }
17200                         u->mq_bytes += mq_bytes;
17201 +                       vx_ipcmsg_add(p->vx_info, u, mq_bytes);
17202                         spin_unlock(&mq_lock);
17203  
17204                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
17205                         if (!info->messages) {
17206                                 spin_lock(&mq_lock);
17207                                 u->mq_bytes -= mq_bytes;
17208 +                               vx_ipcmsg_sub(p->vx_info, u, mq_bytes);
17209                                 spin_unlock(&mq_lock);
17210                                 goto out_inode;
17211                         }
17212 @@ -257,10 +262,14 @@ static void mqueue_delete_inode(struct i
17213                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
17214         user = info->user;
17215         if (user) {
17216 +               struct vx_info *vxi = lookup_vx_info(user->xid);
17217 +
17218                 spin_lock(&mq_lock);
17219                 user->mq_bytes -= mq_bytes;
17220 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
17221                 queues_count--;
17222                 spin_unlock(&mq_lock);
17223 +               put_vx_info(vxi);
17224                 free_uid(user);
17225         }
17226  }
17227 @@ -748,7 +757,7 @@ asmlinkage long sys_mq_unlink(const char
17228         if (inode)
17229                 atomic_inc(&inode->i_count);
17230  
17231 -       err = vfs_unlink(dentry->d_parent->d_inode, dentry);
17232 +       err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
17233  out_err:
17234         dput(dentry);
17235  
17236 diff -NurpP --minimal linux-2.6.22.10/ipc/msg.c linux-2.6.22.10-vs2.3.0.29/ipc/msg.c
17237 --- linux-2.6.22.10/ipc/msg.c   2007-02-06 03:01:55 +0100
17238 +++ linux-2.6.22.10-vs2.3.0.29/ipc/msg.c        2007-08-05 20:53:13 +0200
17239 @@ -36,6 +36,7 @@
17240  #include <linux/seq_file.h>
17241  #include <linux/mutex.h>
17242  #include <linux/nsproxy.h>
17243 +#include <linux/vs_base.h>
17244  
17245  #include <asm/current.h>
17246  #include <asm/uaccess.h>
17247 @@ -149,6 +150,7 @@ static int newque (struct ipc_namespace 
17248  
17249         msq->q_perm.mode = msgflg & S_IRWXUGO;
17250         msq->q_perm.key = key;
17251 +       msq->q_perm.xid = vx_current_xid();
17252  
17253         msq->q_perm.security = NULL;
17254         retval = security_msg_queue_alloc(msq);
17255 diff -NurpP --minimal linux-2.6.22.10/ipc/sem.c linux-2.6.22.10-vs2.3.0.29/ipc/sem.c
17256 --- linux-2.6.22.10/ipc/sem.c   2007-07-09 13:20:03 +0200
17257 +++ linux-2.6.22.10-vs2.3.0.29/ipc/sem.c        2007-08-05 20:53:13 +0200
17258 @@ -82,6 +82,8 @@
17259  #include <linux/seq_file.h>
17260  #include <linux/mutex.h>
17261  #include <linux/nsproxy.h>
17262 +#include <linux/vs_base.h>
17263 +#include <linux/vs_limit.h>
17264  
17265  #include <asm/uaccess.h>
17266  #include "util.h"
17267 @@ -229,6 +231,7 @@ static int newary (struct ipc_namespace 
17268  
17269         sma->sem_perm.mode = (semflg & S_IRWXUGO);
17270         sma->sem_perm.key = key;
17271 +       sma->sem_perm.xid = vx_current_xid();
17272  
17273         sma->sem_perm.security = NULL;
17274         retval = security_sem_alloc(sma);
17275 @@ -244,6 +247,9 @@ static int newary (struct ipc_namespace 
17276                 return -ENOSPC;
17277         }
17278         ns->used_sems += nsems;
17279 +       /* FIXME: obsoleted? */
17280 +       vx_semary_inc(sma);
17281 +       vx_nsems_add(sma, nsems);
17282  
17283         sma->sem_id = sem_buildid(ns, id, sma->sem_perm.seq);
17284         sma->sem_base = (struct sem *) &sma[1];
17285 @@ -525,6 +531,9 @@ static void freeary (struct ipc_namespac
17286         sem_unlock(sma);
17287  
17288         ns->used_sems -= sma->sem_nsems;
17289 +       /* FIXME: obsoleted? */
17290 +       vx_nsems_sub(sma, sma->sem_nsems);
17291 +       vx_semary_dec(sma);
17292         size = sizeof (*sma) + sma->sem_nsems * sizeof (struct sem);
17293         security_sem_free(sma);
17294         ipc_rcu_putref(sma);
17295 diff -NurpP --minimal linux-2.6.22.10/ipc/shm.c linux-2.6.22.10-vs2.3.0.29/ipc/shm.c
17296 --- linux-2.6.22.10/ipc/shm.c   2007-10-30 01:57:14 +0100
17297 +++ linux-2.6.22.10-vs2.3.0.29/ipc/shm.c        2007-10-01 14:57:41 +0200
17298 @@ -38,6 +38,8 @@
17299  #include <linux/mutex.h>
17300  #include <linux/nsproxy.h>
17301  #include <linux/mount.h>
17302 +#include <linux/vs_context.h>
17303 +#include <linux/vs_limit.h>
17304  
17305  #include <asm/uaccess.h>
17306  
17307 @@ -185,7 +187,12 @@ static void shm_open(struct vm_area_stru
17308   */
17309  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
17310  {
17311 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17312 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
17313 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
17314 +
17315 +       vx_ipcshm_sub(vxi, shp, numpages);
17316 +       ns->shm_tot -= numpages;
17317 +
17318         shm_rmid(ns, shp->id);
17319         shm_unlock(shp);
17320         if (!is_file_hugepages(shp->shm_file))
17321 @@ -195,6 +202,7 @@ static void shm_destroy(struct ipc_names
17322                                                 shp->mlock_user);
17323         fput (shp->shm_file);
17324         security_shm_free(shp);
17325 +       put_vx_info(vxi);
17326         ipc_rcu_putref(shp);
17327  }
17328  
17329 @@ -351,11 +359,15 @@ static int newseg (struct ipc_namespace 
17330         if (ns->shm_tot + numpages > ns->shm_ctlall)
17331                 return -ENOSPC;
17332  
17333 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
17334 +               return -ENOSPC;
17335 +
17336         shp = ipc_rcu_alloc(sizeof(*shp));
17337         if (!shp)
17338                 return -ENOMEM;
17339  
17340         shp->shm_perm.key = key;
17341 +       shp->shm_perm.xid = vx_current_xid();
17342         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
17343         shp->mlock_user = NULL;
17344  
17345 @@ -406,6 +418,7 @@ static int newseg (struct ipc_namespace 
17346         file->f_dentry->d_inode->i_ino = shp->id;
17347  
17348         ns->shm_tot += numpages;
17349 +       vx_ipcshm_add(current->vx_info, key, numpages);
17350         shm_unlock(shp);
17351         return shp->id;
17352  
17353 diff -NurpP --minimal linux-2.6.22.10/ipc/util.c linux-2.6.22.10-vs2.3.0.29/ipc/util.c
17354 --- linux-2.6.22.10/ipc/util.c  2007-07-09 13:20:03 +0200
17355 +++ linux-2.6.22.10-vs2.3.0.29/ipc/util.c       2007-08-05 20:53:13 +0200
17356 @@ -32,6 +32,8 @@
17357  #include <linux/proc_fs.h>
17358  #include <linux/audit.h>
17359  #include <linux/nsproxy.h>
17360 +#include <linux/vs_base.h>
17361 +#include <linux/vserver/global.h>
17362  
17363  #include <asm/unistd.h>
17364  
17365 @@ -72,6 +74,7 @@ static struct ipc_namespace *clone_ipc_n
17366                 goto err_shm;
17367  
17368         kref_init(&ns->kref);
17369 +       atomic_inc(&vs_global_ipc_ns);
17370         return ns;
17371  
17372  err_shm:
17373 @@ -108,6 +111,7 @@ void free_ipc_ns(struct kref *kref)
17374         sem_exit_ns(ns);
17375         msg_exit_ns(ns);
17376         shm_exit_ns(ns);
17377 +       atomic_dec(&vs_global_ipc_ns);
17378         kfree(ns);
17379  }
17380  #else
17381 diff -NurpP --minimal linux-2.6.22.10/kernel/Makefile linux-2.6.22.10-vs2.3.0.29/kernel/Makefile
17382 --- linux-2.6.22.10/kernel/Makefile     2007-07-09 13:20:03 +0200
17383 +++ linux-2.6.22.10-vs2.3.0.29/kernel/Makefile  2007-08-05 20:53:13 +0200
17384 @@ -10,6 +10,8 @@ obj-y     = sched.o fork.o exec_domain.o
17385             kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
17386             hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o
17387  
17388 +obj-y    += vserver/
17389 +
17390  obj-$(CONFIG_STACKTRACE) += stacktrace.o
17391  obj-y += time/
17392  obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
17393 diff -NurpP --minimal linux-2.6.22.10/kernel/capability.c linux-2.6.22.10-vs2.3.0.29/kernel/capability.c
17394 --- linux-2.6.22.10/kernel/capability.c 2007-05-02 19:25:37 +0200
17395 +++ linux-2.6.22.10-vs2.3.0.29/kernel/capability.c      2007-08-05 20:53:13 +0200
17396 @@ -12,6 +12,7 @@
17397  #include <linux/module.h>
17398  #include <linux/security.h>
17399  #include <linux/syscalls.h>
17400 +#include <linux/vs_context.h>
17401  #include <asm/uaccess.h>
17402  
17403  unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
17404 @@ -103,6 +104,8 @@ static inline int cap_set_pg(int pgrp_nr
17405  
17406         pgrp = find_pid(pgrp_nr);
17407         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
17408 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
17409 +                       continue;
17410                 target = g;
17411                 while_each_thread(g, target) {
17412                         if (!security_capset_check(target, effective,
17413 @@ -246,8 +249,12 @@ int __capable(struct task_struct *t, int
17414  }
17415  EXPORT_SYMBOL(__capable);
17416  
17417 +#include <linux/vserver/base.h>
17418  int capable(int cap)
17419  {
17420 +       /* here for now so we don't require task locking */
17421 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
17422 +               return 0;
17423         return __capable(current, cap);
17424  }
17425  EXPORT_SYMBOL(capable);
17426 diff -NurpP --minimal linux-2.6.22.10/kernel/compat.c linux-2.6.22.10-vs2.3.0.29/kernel/compat.c
17427 --- linux-2.6.22.10/kernel/compat.c     2007-07-09 13:20:03 +0200
17428 +++ linux-2.6.22.10-vs2.3.0.29/kernel/compat.c  2007-08-05 20:53:13 +0200
17429 @@ -846,7 +846,7 @@ asmlinkage long compat_sys_time(compat_t
17430         compat_time_t i;
17431         struct timeval tv;
17432  
17433 -       do_gettimeofday(&tv);
17434 +       vx_gettimeofday(&tv);
17435         i = tv.tv_sec;
17436  
17437         if (tloc) {
17438 @@ -870,7 +870,7 @@ asmlinkage long compat_sys_stime(compat_
17439         if (err)
17440                 return err;
17441  
17442 -       do_settimeofday(&tv);
17443 +       vx_settimeofday(&tv);
17444         return 0;
17445  }
17446  
17447 diff -NurpP --minimal linux-2.6.22.10/kernel/exit.c linux-2.6.22.10-vs2.3.0.29/kernel/exit.c
17448 --- linux-2.6.22.10/kernel/exit.c       2007-07-09 13:20:03 +0200
17449 +++ linux-2.6.22.10-vs2.3.0.29/kernel/exit.c    2007-10-01 18:31:46 +0200
17450 @@ -44,6 +44,11 @@
17451  #include <linux/resource.h>
17452  #include <linux/blkdev.h>
17453  #include <linux/task_io_accounting_ops.h>
17454 +#include <linux/vs_limit.h>
17455 +#include <linux/vs_context.h>
17456 +#include <linux/vs_network.h>
17457 +#include <linux/vs_pid.h>
17458 +#include <linux/vserver/global.h>
17459  
17460  #include <asm/uaccess.h>
17461  #include <asm/unistd.h>
17462 @@ -443,9 +448,11 @@ static void close_files(struct files_str
17463                                         filp_close(file, files);
17464                                         cond_resched();
17465                                 }
17466 +                               vx_openfd_dec(i);
17467                         }
17468                         i++;
17469                         set >>= 1;
17470 +                       cond_resched();
17471                 }
17472         }
17473  }
17474 @@ -525,6 +532,7 @@ static inline void __put_fs_struct(struc
17475                         dput(fs->altroot);
17476                         mntput(fs->altrootmnt);
17477                 }
17478 +               atomic_dec(&vs_global_fs);
17479                 kmem_cache_free(fs_cachep, fs);
17480         }
17481  }
17482 @@ -596,6 +604,14 @@ static void exit_mm(struct task_struct *
17483  static inline void
17484  choose_new_parent(struct task_struct *p, struct task_struct *reaper)
17485  {
17486 +       /* check for reaper context */
17487 +       vxwprintk((p->xid != reaper->xid) && (reaper != child_reaper(p)),
17488 +               "rogue reaper: %p[%d,#%u] <> %p[%d,#%u]",
17489 +               p, p->pid, p->xid, reaper, reaper->pid, reaper->xid);
17490 +
17491 +       if (p == reaper)
17492 +               reaper = vx_child_reaper(p);
17493 +
17494         /*
17495          * Make sure we're not reparenting to ourselves and that
17496          * the parent is not a zombie.
17497 @@ -687,7 +703,7 @@ forget_original_parent(struct task_struc
17498         do {
17499                 reaper = next_thread(reaper);
17500                 if (reaper == father) {
17501 -                       reaper = child_reaper(father);
17502 +                       reaper = vx_child_reaper(father);
17503                         break;
17504                 }
17505         } while (reaper->exit_state);
17506 @@ -964,6 +980,8 @@ fastcall NORET_TYPE void do_exit(long co
17507         tsk->exit_code = code;
17508         proc_exit_connector(tsk);
17509         exit_task_namespaces(tsk);
17510 +       /* needs to stay before exit_notify() */
17511 +       exit_vx_info_early(tsk, code);
17512         exit_notify(tsk);
17513  #ifdef CONFIG_NUMA
17514         mpol_free(tsk->mempolicy);
17515 @@ -994,6 +1012,10 @@ fastcall NORET_TYPE void do_exit(long co
17516         if (tsk->splice_pipe)
17517                 __free_pipe_info(tsk->splice_pipe);
17518  
17519 +       /* needs to stay after exit_notify() */
17520 +       exit_vx_info(tsk, code);
17521 +       exit_nx_info(tsk);
17522 +
17523         preempt_disable();
17524         /* causes final put_task_struct in finish_task_switch(). */
17525         tsk->state = TASK_DEAD;
17526 diff -NurpP --minimal linux-2.6.22.10/kernel/fork.c linux-2.6.22.10-vs2.3.0.29/kernel/fork.c
17527 --- linux-2.6.22.10/kernel/fork.c       2007-07-09 13:20:03 +0200
17528 +++ linux-2.6.22.10-vs2.3.0.29/kernel/fork.c    2007-10-25 17:05:55 +0200
17529 @@ -49,6 +49,11 @@
17530  #include <linux/delayacct.h>
17531  #include <linux/taskstats_kern.h>
17532  #include <linux/random.h>
17533 +#include <linux/vs_context.h>
17534 +#include <linux/vs_network.h>
17535 +#include <linux/vs_limit.h>
17536 +#include <linux/vs_memory.h>
17537 +#include <linux/vserver/global.h>
17538  
17539  #include <asm/pgtable.h>
17540  #include <asm/pgalloc.h>
17541 @@ -108,6 +113,8 @@ void free_task(struct task_struct *tsk)
17542  {
17543         free_thread_info(tsk->stack);
17544         rt_mutex_debug_task_free(tsk);
17545 +       clr_vx_info(&tsk->vx_info);
17546 +       clr_nx_info(&tsk->nx_info);
17547         free_task_struct(tsk);
17548  }
17549  EXPORT_SYMBOL(free_task);
17550 @@ -215,6 +222,8 @@ static inline int dup_mmap(struct mm_str
17551         mm->free_area_cache = oldmm->mmap_base;
17552         mm->cached_hole_size = ~0UL;
17553         mm->map_count = 0;
17554 +       __set_mm_counter(mm, file_rss, 0);
17555 +       __set_mm_counter(mm, anon_rss, 0);
17556         cpus_clear(mm->cpu_vm_mask);
17557         mm->mm_rb = RB_ROOT;
17558         rb_link = &mm->mm_rb.rb_node;
17559 @@ -226,7 +235,7 @@ static inline int dup_mmap(struct mm_str
17560  
17561                 if (mpnt->vm_flags & VM_DONTCOPY) {
17562                         long pages = vma_pages(mpnt);
17563 -                       mm->total_vm -= pages;
17564 +                       vx_vmpages_sub(mm, pages);
17565                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
17566                                                                 -pages);
17567                         continue;
17568 @@ -327,7 +336,7 @@ static inline void mm_free_pgd(struct mm
17569  
17570  #include <linux/init_task.h>
17571  
17572 -static struct mm_struct * mm_init(struct mm_struct * mm)
17573 +static struct mm_struct * mm_init(struct mm_struct * mm, struct vx_info *vxi)
17574  {
17575         atomic_set(&mm->mm_users, 1);
17576         atomic_set(&mm->mm_count, 1);
17577 @@ -335,8 +344,8 @@ static struct mm_struct * mm_init(struct
17578         INIT_LIST_HEAD(&mm->mmlist);
17579         mm->core_waiters = 0;
17580         mm->nr_ptes = 0;
17581 -       set_mm_counter(mm, file_rss, 0);
17582 -       set_mm_counter(mm, anon_rss, 0);
17583 +       __set_mm_counter(mm, file_rss, 0);
17584 +       __set_mm_counter(mm, anon_rss, 0);
17585         spin_lock_init(&mm->page_table_lock);
17586         rwlock_init(&mm->ioctx_list_lock);
17587         mm->ioctx_list = NULL;
17588 @@ -345,6 +354,7 @@ static struct mm_struct * mm_init(struct
17589  
17590         if (likely(!mm_alloc_pgd(mm))) {
17591                 mm->def_flags = 0;
17592 +               set_vx_info(&mm->mm_vx_info, vxi);
17593                 return mm;
17594         }
17595         free_mm(mm);
17596 @@ -361,7 +371,7 @@ struct mm_struct * mm_alloc(void)
17597         mm = allocate_mm();
17598         if (mm) {
17599                 memset(mm, 0, sizeof(*mm));
17600 -               mm = mm_init(mm);
17601 +               mm = mm_init(mm, current->vx_info);
17602         }
17603         return mm;
17604  }
17605 @@ -376,6 +386,7 @@ void fastcall __mmdrop(struct mm_struct 
17606         BUG_ON(mm == &init_mm);
17607         mm_free_pgd(mm);
17608         destroy_context(mm);
17609 +       clr_vx_info(&mm->mm_vx_info);
17610         free_mm(mm);
17611  }
17612  
17613 @@ -490,12 +501,13 @@ static struct mm_struct *dup_mm(struct t
17614                 goto fail_nomem;
17615  
17616         memcpy(mm, oldmm, sizeof(*mm));
17617 +       mm->mm_vx_info = NULL;
17618  
17619         /* Initializing for Swap token stuff */
17620         mm->token_priority = 0;
17621         mm->last_interval = 0;
17622  
17623 -       if (!mm_init(mm))
17624 +       if (!mm_init(mm, oldmm->mm_vx_info))
17625                 goto fail_nomem;
17626  
17627         if (init_new_context(tsk, mm))
17628 @@ -521,6 +533,7 @@ fail_nocontext:
17629          * If init_new_context() failed, we cannot use mmput() to free the mm
17630          * because it calls destroy_context()
17631          */
17632 +       clr_vx_info(&mm->mm_vx_info);
17633         mm_free_pgd(mm);
17634         free_mm(mm);
17635         return NULL;
17636 @@ -591,6 +604,7 @@ static inline struct fs_struct *__copy_f
17637                         fs->altroot = NULL;
17638                 }
17639                 read_unlock(&old->lock);
17640 +               atomic_inc(&vs_global_fs);
17641         }
17642         return fs;
17643  }
17644 @@ -709,6 +723,8 @@ static struct files_struct *dup_fd(struc
17645                 struct file *f = *old_fds++;
17646                 if (f) {
17647                         get_file(f);
17648 +                       /* TODO: sum it first for check and performance */
17649 +                       vx_openfd_inc(open_files - i);
17650                 } else {
17651                         /*
17652                          * The fd may be claimed in the fd bitmap but not yet
17653 @@ -961,6 +977,8 @@ static struct task_struct *copy_process(
17654  {
17655         int retval;
17656         struct task_struct *p = NULL;
17657 +       struct vx_info *vxi;
17658 +       struct nx_info *nxi;
17659  
17660         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
17661                 return ERR_PTR(-EINVAL);
17662 @@ -995,12 +1013,30 @@ static struct task_struct *copy_process(
17663         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
17664         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
17665  #endif
17666 +       init_vx_info(&p->vx_info, current->vx_info);
17667 +       init_nx_info(&p->nx_info, current->nx_info);
17668 +
17669 +       /* check vserver memory */
17670 +       if (p->mm && !(clone_flags & CLONE_VM)) {
17671 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
17672 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17673 +               else
17674 +                       goto bad_fork_free;
17675 +       }
17676 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
17677 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
17678 +                       goto bad_fork_cleanup_vm;
17679 +       }
17680 +
17681         retval = -EAGAIN;
17682 +       if (!vx_nproc_avail(1))
17683 +               goto bad_fork_cleanup_vm;
17684 +
17685         if (atomic_read(&p->user->processes) >=
17686                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
17687                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
17688                                 p->user != &root_user)
17689 -                       goto bad_fork_free;
17690 +                       goto bad_fork_cleanup_vm;
17691         }
17692  
17693         atomic_inc(&p->user->__count);
17694 @@ -1265,6 +1301,18 @@ static struct task_struct *copy_process(
17695  
17696         total_forks++;
17697         spin_unlock(&current->sighand->siglock);
17698 +
17699 +       /* p is copy of current */
17700 +       vxi = p->vx_info;
17701 +       if (vxi) {
17702 +               claim_vx_info(vxi, p);
17703 +               atomic_inc(&vxi->cvirt.nr_threads);
17704 +               atomic_inc(&vxi->cvirt.total_forks);
17705 +               vx_nproc_inc(p);
17706 +       }
17707 +       nxi = p->nx_info;
17708 +       if (nxi)
17709 +               claim_nx_info(nxi, p);
17710         write_unlock_irq(&tasklist_lock);
17711         proc_fork_connector(p);
17712         return p;
17713 @@ -1306,6 +1354,9 @@ bad_fork_cleanup_count:
17714         put_group_info(p->group_info);
17715         atomic_dec(&p->user->processes);
17716         free_uid(p->user);
17717 +bad_fork_cleanup_vm:
17718 +       if (p->mm && !(clone_flags & CLONE_VM))
17719 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
17720  bad_fork_free:
17721         free_task(p);
17722  fork_out:
17723 @@ -1367,6 +1418,15 @@ long do_fork(unsigned long clone_flags,
17724  
17725         if (!pid)
17726                 return -EAGAIN;
17727 +
17728 +       /* kernel threads are host only */
17729 +       if ((clone_flags & CLONE_KTHREAD) &&
17730 +               !vx_capable(CAP_SYS_ADMIN, VXC_KTHREAD)) {
17731 +               vxwprintk_task(1, "tried to spawn a kernel thread.");
17732 +               free_pid(pid);
17733 +               return -EPERM;
17734 +       }
17735 +
17736         nr = pid->nr;
17737         if (unlikely(current->ptrace)) {
17738                 trace = fork_traceflag (clone_flags);
17739 diff -NurpP --minimal linux-2.6.22.10/kernel/kthread.c linux-2.6.22.10-vs2.3.0.29/kernel/kthread.c
17740 --- linux-2.6.22.10/kernel/kthread.c    2007-07-09 13:20:03 +0200
17741 +++ linux-2.6.22.10-vs2.3.0.29/kernel/kthread.c 2007-08-05 20:53:13 +0200
17742 @@ -96,7 +96,7 @@ static void create_kthread(struct kthrea
17743         } else {
17744                 wait_for_completion(&create->started);
17745                 read_lock(&tasklist_lock);
17746 -               create->result = find_task_by_pid(pid);
17747 +               create->result = find_task_by_real_pid(pid);
17748                 read_unlock(&tasklist_lock);
17749         }
17750         complete(&create->done);
17751 diff -NurpP --minimal linux-2.6.22.10/kernel/nsproxy.c linux-2.6.22.10-vs2.3.0.29/kernel/nsproxy.c
17752 --- linux-2.6.22.10/kernel/nsproxy.c    2007-07-09 13:20:03 +0200
17753 +++ linux-2.6.22.10-vs2.3.0.29/kernel/nsproxy.c 2007-08-05 20:53:13 +0200
17754 @@ -20,14 +20,11 @@
17755  #include <linux/mnt_namespace.h>
17756  #include <linux/utsname.h>
17757  #include <linux/pid_namespace.h>
17758 +#include <linux/vserver/global.h>
17759 +#include <linux/vserver/debug.h>
17760  
17761  struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
17762  
17763 -static inline void get_nsproxy(struct nsproxy *ns)
17764 -{
17765 -       atomic_inc(&ns->count);
17766 -}
17767 -
17768  void get_task_namespaces(struct task_struct *tsk)
17769  {
17770         struct nsproxy *ns = tsk->nsproxy;
17771 @@ -46,6 +43,9 @@ static inline struct nsproxy *clone_nspr
17772         ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
17773         if (ns)
17774                 atomic_set(&ns->count, 1);
17775 +       vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
17776 +               orig, atomic_read(&orig->count), ns);
17777 +       atomic_inc(&vs_global_nsproxy);
17778         return ns;
17779  }
17780  
17781 @@ -54,28 +54,32 @@ static inline struct nsproxy *clone_nspr
17782   * Return the newly created nsproxy.  Do not attach this to the task,
17783   * leave it to the caller to do proper locking and attach it to task.
17784   */
17785 -static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17786 +static struct nsproxy *unshare_namespaces(int flags, struct nsproxy *orig,
17787                         struct fs_struct *new_fs)
17788  {
17789         struct nsproxy *new_nsp;
17790  
17791 -       new_nsp = clone_nsproxy(tsk->nsproxy);
17792 +       vxdprintk(VXD_CBIT(space, 4),
17793 +               "unshare_namespaces(0x%08x,%p,%p)",
17794 +               flags, orig, new_fs);
17795 +
17796 +       new_nsp = clone_nsproxy(orig);
17797         if (!new_nsp)
17798                 return ERR_PTR(-ENOMEM);
17799  
17800 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
17801 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
17802         if (IS_ERR(new_nsp->mnt_ns))
17803                 goto out_ns;
17804  
17805 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
17806 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
17807         if (IS_ERR(new_nsp->uts_ns))
17808                 goto out_uts;
17809  
17810 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
17811 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
17812         if (IS_ERR(new_nsp->ipc_ns))
17813                 goto out_ipc;
17814  
17815 -       new_nsp->pid_ns = copy_pid_ns(flags, tsk->nsproxy->pid_ns);
17816 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
17817         if (IS_ERR(new_nsp->pid_ns))
17818                 goto out_pid;
17819  
17820 @@ -95,6 +99,33 @@ out_ns:
17821         return ERR_PTR(-ENOMEM);
17822  }
17823  
17824 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
17825 +                       struct fs_struct *new_fs)
17826 +{
17827 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
17828 +}
17829 +
17830 +/*
17831 + * copies the nsproxy, setting refcount to 1, and grabbing a
17832 + * reference to all contained namespaces.
17833 + */
17834 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
17835 +{
17836 +       struct nsproxy *ns = clone_nsproxy(orig);
17837 +
17838 +       if (ns) {
17839 +               if (ns->mnt_ns)
17840 +                       get_mnt_ns(ns->mnt_ns);
17841 +               if (ns->uts_ns)
17842 +                       get_uts_ns(ns->uts_ns);
17843 +               if (ns->ipc_ns)
17844 +                       get_ipc_ns(ns->ipc_ns);
17845 +               if (ns->pid_ns)
17846 +                       get_pid_ns(ns->pid_ns);
17847 +       }
17848 +       return ns;
17849 +}
17850 +
17851  /*
17852   * called from clone.  This now handles copy for nsproxy and all
17853   * namespaces therein.
17854 @@ -102,9 +133,12 @@ out_ns:
17855  int copy_namespaces(int flags, struct task_struct *tsk)
17856  {
17857         struct nsproxy *old_ns = tsk->nsproxy;
17858 -       struct nsproxy *new_ns;
17859 +       struct nsproxy *new_ns = NULL;
17860         int err = 0;
17861  
17862 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08x,%p[%p])",
17863 +               flags, tsk, old_ns);
17864 +
17865         if (!old_ns)
17866                 return 0;
17867  
17868 @@ -127,6 +161,9 @@ int copy_namespaces(int flags, struct ta
17869         tsk->nsproxy = new_ns;
17870  out:
17871         put_nsproxy(old_ns);
17872 +       vxdprintk(VXD_CBIT(space, 3),
17873 +               "copy_namespaces(0x%08x,%p[%p]) = %d [%p]",
17874 +               flags, tsk, old_ns, err, new_ns);
17875         return err;
17876  }
17877  
17878 @@ -140,6 +177,7 @@ void free_nsproxy(struct nsproxy *ns)
17879                 put_ipc_ns(ns->ipc_ns);
17880         if (ns->pid_ns)
17881                 put_pid_ns(ns->pid_ns);
17882 +       atomic_dec(&vs_global_nsproxy);
17883         kfree(ns);
17884  }
17885  
17886 @@ -152,6 +190,10 @@ int unshare_nsproxy_namespaces(unsigned 
17887  {
17888         int err = 0;
17889  
17890 +       vxdprintk(VXD_CBIT(space, 4),
17891 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
17892 +               unshare_flags, current->nsproxy);
17893 +
17894         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC)))
17895                 return 0;
17896  
17897 diff -NurpP --minimal linux-2.6.22.10/kernel/pid.c linux-2.6.22.10-vs2.3.0.29/kernel/pid.c
17898 --- linux-2.6.22.10/kernel/pid.c        2007-07-09 13:20:03 +0200
17899 +++ linux-2.6.22.10-vs2.3.0.29/kernel/pid.c     2007-08-05 20:53:13 +0200
17900 @@ -28,6 +28,7 @@
17901  #include <linux/hash.h>
17902  #include <linux/pid_namespace.h>
17903  #include <linux/init_task.h>
17904 +#include <linux/vs_pid.h>
17905  
17906  #define pid_hashfn(nr) hash_long((unsigned long)nr, pidhash_shift)
17907  static struct hlist_head *pid_hash;
17908 @@ -295,6 +296,9 @@ void fastcall transfer_pid(struct task_s
17909  struct task_struct * fastcall pid_task(struct pid *pid, enum pid_type type)
17910  {
17911         struct task_struct *result = NULL;
17912 +
17913 +       if (type == PIDTYPE_REALPID)
17914 +               type = PIDTYPE_PID;
17915         if (pid) {
17916                 struct hlist_node *first;
17917                 first = rcu_dereference(pid->tasks[type].first);
17918 @@ -309,7 +313,17 @@ struct task_struct * fastcall pid_task(s
17919   */
17920  struct task_struct *find_task_by_pid_type(int type, int nr)
17921  {
17922 -       return pid_task(find_pid(nr), type);
17923 +       struct task_struct *task;
17924 +
17925 +       if (type == PIDTYPE_PID)
17926 +               nr = vx_rmap_pid(nr);
17927 +
17928 +       task = pid_task(find_pid(nr), type);
17929 +       if (task && (type != PIDTYPE_REALPID) &&
17930 +               /* maybe VS_WATCH_P in the future? */
17931 +               !vx_check(task->xid, VS_WATCH|VS_IDENT))
17932 +               return NULL;
17933 +       return task;
17934  }
17935  
17936  EXPORT_SYMBOL(find_task_by_pid_type);
17937 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
17938 --- linux-2.6.22.10/kernel/posix-timers.c       2007-07-09 13:20:03 +0200
17939 +++ linux-2.6.22.10-vs2.3.0.29/kernel/posix-timers.c    2007-10-01 15:41:45 +0200
17940 @@ -47,6 +47,7 @@
17941  #include <linux/wait.h>
17942  #include <linux/workqueue.h>
17943  #include <linux/module.h>
17944 +#include <linux/vs_context.h>
17945  
17946  /*
17947   * Management arrays for POSIX timers.  Timers are kept in slab memory
17948 @@ -297,6 +298,12 @@ void do_schedule_next_timer(struct sigin
17949  
17950  int posix_timer_event(struct k_itimer *timr,int si_private)
17951  {
17952 +       struct vx_info_save vxis;
17953 +       struct vx_info *vxi;
17954 +       int ret;
17955 +
17956 +       vxi = task_get_vx_info(timr->it_process);
17957 +       enter_vx_info(vxi, &vxis);
17958         memset(&timr->sigq->info, 0, sizeof(siginfo_t));
17959         timr->sigq->info.si_sys_private = si_private;
17960         /* Send signal to the process that owns this timer.*/
17961 @@ -309,11 +316,11 @@ int posix_timer_event(struct k_itimer *t
17962  
17963         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
17964                 struct task_struct *leader;
17965 -               int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
17966 -                                       timr->it_process);
17967  
17968 +               ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
17969 +                                   timr->it_process);
17970                 if (likely(ret >= 0))
17971 -                       return ret;
17972 +                       goto out;
17973  
17974                 timr->it_sigev_notify = SIGEV_SIGNAL;
17975                 leader = timr->it_process->group_leader;
17976 @@ -321,8 +328,12 @@ int posix_timer_event(struct k_itimer *t
17977                 timr->it_process = leader;
17978         }
17979  
17980 -       return send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
17981 +       ret = send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
17982                                    timr->it_process);
17983 +out:
17984 +       leave_vx_info(&vxis);
17985 +       put_vx_info(vxi);
17986 +       return ret;
17987  }
17988  EXPORT_SYMBOL_GPL(posix_timer_event);
17989  
17990 @@ -402,7 +413,7 @@ static struct task_struct * good_sigeven
17991         struct task_struct *rtn = current->group_leader;
17992  
17993         if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
17994 -               (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
17995 +               (!(rtn = find_task_by_real_pid(event->sigev_notify_thread_id)) ||
17996                  rtn->tgid != current->tgid ||
17997                  (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
17998                 return NULL;
17999 diff -NurpP --minimal linux-2.6.22.10/kernel/printk.c linux-2.6.22.10-vs2.3.0.29/kernel/printk.c
18000 --- linux-2.6.22.10/kernel/printk.c     2007-07-09 13:20:03 +0200
18001 +++ linux-2.6.22.10-vs2.3.0.29/kernel/printk.c  2007-08-05 20:53:13 +0200
18002 @@ -31,6 +31,7 @@
18003  #include <linux/bootmem.h>
18004  #include <linux/syscalls.h>
18005  #include <linux/jiffies.h>
18006 +#include <linux/vs_cvirt.h>
18007  
18008  #include <asm/uaccess.h>
18009  
18010 @@ -182,18 +183,13 @@ int do_syslog(int type, char __user *buf
18011         unsigned long i, j, limit, count;
18012         int do_clear = 0;
18013         char c;
18014 -       int error = 0;
18015 +       int error;
18016  
18017         error = security_syslog(type);
18018         if (error)
18019                 return error;
18020  
18021 -       switch (type) {
18022 -       case 0:         /* Close log */
18023 -               break;
18024 -       case 1:         /* Open log */
18025 -               break;
18026 -       case 2:         /* Read from log */
18027 +       if ((type >= 2) && (type <= 4)) {
18028                 error = -EINVAL;
18029                 if (!buf || len < 0)
18030                         goto out;
18031 @@ -204,6 +200,16 @@ int do_syslog(int type, char __user *buf
18032                         error = -EFAULT;
18033                         goto out;
18034                 }
18035 +       }
18036 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
18037 +               return vx_do_syslog(type, buf, len);
18038 +
18039 +       switch (type) {
18040 +       case 0:         /* Close log */
18041 +               break;
18042 +       case 1:         /* Open log */
18043 +               break;
18044 +       case 2:         /* Read from log */
18045                 error = wait_event_interruptible(log_wait,
18046                                                         (log_start - log_end));
18047                 if (error)
18048 @@ -228,16 +234,6 @@ int do_syslog(int type, char __user *buf
18049                 do_clear = 1;
18050                 /* FALL THRU */
18051         case 3:         /* Read last kernel messages */
18052 -               error = -EINVAL;
18053 -               if (!buf || len < 0)
18054 -                       goto out;
18055 -               error = 0;
18056 -               if (!len)
18057 -                       goto out;
18058 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
18059 -                       error = -EFAULT;
18060 -                       goto out;
18061 -               }
18062                 count = len;
18063                 if (count > log_buf_len)
18064                         count = log_buf_len;
18065 diff -NurpP --minimal linux-2.6.22.10/kernel/ptrace.c linux-2.6.22.10-vs2.3.0.29/kernel/ptrace.c
18066 --- linux-2.6.22.10/kernel/ptrace.c     2007-07-09 13:20:03 +0200
18067 +++ linux-2.6.22.10-vs2.3.0.29/kernel/ptrace.c  2007-08-05 20:53:13 +0200
18068 @@ -19,6 +19,7 @@
18069  #include <linux/security.h>
18070  #include <linux/signal.h>
18071  #include <linux/audit.h>
18072 +#include <linux/vs_context.h>
18073  
18074  #include <asm/pgtable.h>
18075  #include <asm/uaccess.h>
18076 @@ -145,6 +146,11 @@ static int may_attach(struct task_struct
18077                 dumpable = task->mm->dumpable;
18078         if (!dumpable && !capable(CAP_SYS_PTRACE))
18079                 return -EPERM;
18080 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
18081 +               return -EPERM;
18082 +       if (!vx_check(task->xid, VS_IDENT) &&
18083 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
18084 +               return -EACCES;
18085  
18086         return security_ptrace(current, task);
18087  }
18088 @@ -471,6 +477,10 @@ asmlinkage long sys_ptrace(long request,
18089                 goto out;
18090         }
18091  
18092 +       ret = -EPERM;
18093 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
18094 +               goto out_put_task_struct;
18095 +
18096         if (request == PTRACE_ATTACH) {
18097                 ret = ptrace_attach(child);
18098                 goto out_put_task_struct;
18099 diff -NurpP --minimal linux-2.6.22.10/kernel/sched.c linux-2.6.22.10-vs2.3.0.29/kernel/sched.c
18100 --- linux-2.6.22.10/kernel/sched.c      2007-07-09 13:20:03 +0200
18101 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched.c   2007-08-05 20:53:13 +0200
18102 @@ -56,6 +56,8 @@
18103  
18104  #include <asm/tlb.h>
18105  #include <asm/unistd.h>
18106 +#include <linux/vs_sched.h>
18107 +#include <linux/vs_cvirt.h>
18108  
18109  /*
18110   * Scheduler clock - returns current time in nanosec units.
18111 @@ -281,6 +283,16 @@ struct rq {
18112         struct task_struct *migration_thread;
18113         struct list_head migration_queue;
18114  #endif
18115 +       unsigned long norm_time;
18116 +       unsigned long idle_time;
18117 +#ifdef CONFIG_VSERVER_IDLETIME
18118 +       int idle_skip;
18119 +#endif
18120 +#ifdef CONFIG_VSERVER_HARDCPU
18121 +       struct list_head hold_queue;
18122 +       unsigned long nr_onhold;
18123 +       int idle_tokens;
18124 +#endif
18125  
18126  #ifdef CONFIG_SCHEDSTATS
18127         /* latency stats */
18128 @@ -714,6 +726,7 @@ sched_info_switch(struct task_struct *pr
18129   */
18130  static void dequeue_task(struct task_struct *p, struct prio_array *array)
18131  {
18132 +       BUG_ON(p->state & TASK_ONHOLD);
18133         array->nr_active--;
18134         list_del(&p->run_list);
18135         if (list_empty(array->queue + p->prio))
18136 @@ -722,6 +735,7 @@ static void dequeue_task(struct task_str
18137  
18138  static void enqueue_task(struct task_struct *p, struct prio_array *array)
18139  {
18140 +       BUG_ON(p->state & TASK_ONHOLD);
18141         sched_info_queued(p);
18142         list_add_tail(&p->run_list, array->queue + p->prio);
18143         __set_bit(p->prio, array->bitmap);
18144 @@ -735,12 +749,14 @@ static void enqueue_task(struct task_str
18145   */
18146  static void requeue_task(struct task_struct *p, struct prio_array *array)
18147  {
18148 +       BUG_ON(p->state & TASK_ONHOLD);
18149         list_move_tail(&p->run_list, array->queue + p->prio);
18150  }
18151  
18152  static inline void
18153  enqueue_task_head(struct task_struct *p, struct prio_array *array)
18154  {
18155 +       BUG_ON(p->state & TASK_ONHOLD);
18156         list_add(&p->run_list, array->queue + p->prio);
18157         __set_bit(p->prio, array->bitmap);
18158         array->nr_active++;
18159 @@ -769,6 +785,10 @@ static inline int __normal_prio(struct t
18160         bonus = CURRENT_BONUS(p) - MAX_BONUS / 2;
18161  
18162         prio = p->static_prio - bonus;
18163 +
18164 +       /* adjust effective priority */
18165 +       prio = vx_adjust_prio(p, prio, MAX_USER_PRIO);
18166 +
18167         if (prio < MAX_RT_PRIO)
18168                 prio = MAX_RT_PRIO;
18169         if (prio > MAX_PRIO-1)
18170 @@ -878,6 +898,9 @@ static int effective_prio(struct task_st
18171         return p->prio;
18172  }
18173  
18174 +#include "sched_mon.h"
18175 +
18176 +
18177  /*
18178   * __activate_task - move a task to the runqueue.
18179   */
18180 @@ -887,6 +910,7 @@ static void __activate_task(struct task_
18181  
18182         if (batch_task(p))
18183                 target = rq->expired;
18184 +       vxm_activate_task(p, rq);
18185         enqueue_task(p, target);
18186         inc_nr_running(p, rq);
18187  }
18188 @@ -896,6 +920,7 @@ static void __activate_task(struct task_
18189   */
18190  static inline void __activate_idle_task(struct task_struct *p, struct rq *rq)
18191  {
18192 +       vxm_activate_idle(p, rq);
18193         enqueue_task_head(p, rq->active);
18194         inc_nr_running(p, rq);
18195  }
18196 @@ -1030,19 +1055,30 @@ static void activate_task(struct task_st
18197         }
18198         p->timestamp = now;
18199  out:
18200 +       vx_activate_task(p);
18201         __activate_task(p, rq);
18202  }
18203  
18204  /*
18205 - * deactivate_task - remove a task from the runqueue.
18206 + * __deactivate_task - remove a task from the runqueue.
18207   */
18208 -static void deactivate_task(struct task_struct *p, struct rq *rq)
18209 +static void __deactivate_task(struct task_struct *p, struct rq *rq)
18210  {
18211         dec_nr_running(p, rq);
18212         dequeue_task(p, p->array);
18213 +       vxm_deactivate_task(p, rq);
18214         p->array = NULL;
18215  }
18216  
18217 +static inline
18218 +void deactivate_task(struct task_struct *p, struct rq *rq)
18219 +{
18220 +       vx_deactivate_task(p);
18221 +       __deactivate_task(p, rq);
18222 +}
18223 +
18224 +#include "sched_hard.h"
18225 +
18226  /*
18227   * resched_task - mark a task 'to be rescheduled now'.
18228   *
18229 @@ -1129,6 +1165,7 @@ migrate_task(struct task_struct *p, int 
18230  {
18231         struct rq *rq = task_rq(p);
18232  
18233 +       vxm_migrate_task(p, rq, dest_cpu);
18234         /*
18235          * If the task is not on a runqueue (and not running), then
18236          * it is sufficient to simply update the task's cpu field.
18237 @@ -1518,6 +1555,12 @@ static int try_to_wake_up(struct task_st
18238  
18239         rq = task_rq_lock(p, &flags);
18240         old_state = p->state;
18241 +
18242 +       /* we need to unhold suspended tasks */
18243 +       if (old_state & TASK_ONHOLD) {
18244 +               vx_unhold_task(p, rq);
18245 +               old_state = p->state;
18246 +       }
18247         if (!(old_state & state))
18248                 goto out;
18249  
18250 @@ -1625,6 +1668,7 @@ out_activate:
18251  #endif /* CONFIG_SMP */
18252         if (old_state == TASK_UNINTERRUPTIBLE) {
18253                 rq->nr_uninterruptible--;
18254 +               vx_uninterruptible_dec(p);
18255                 /*
18256                  * Tasks on involuntary sleep don't earn
18257                  * sleep_avg beyond just interactive state.
18258 @@ -1676,7 +1720,7 @@ int fastcall wake_up_state(struct task_s
18259         return try_to_wake_up(p, state, 0);
18260  }
18261  
18262 -static void task_running_tick(struct rq *rq, struct task_struct *p);
18263 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu);
18264  /*
18265   * Perform scheduler related setup for a newly forked process p.
18266   * p is forked by current.
18267 @@ -1737,7 +1781,7 @@ void fastcall sched_fork(struct task_str
18268                  * runqueue lock is not a problem.
18269                  */
18270                 current->time_slice = 1;
18271 -               task_running_tick(cpu_rq(cpu), current);
18272 +               task_running_tick(cpu_rq(cpu), current, cpu);
18273         }
18274         local_irq_enable();
18275         put_cpu();
18276 @@ -1772,6 +1816,7 @@ void fastcall wake_up_new_task(struct ta
18277  
18278         p->prio = effective_prio(p);
18279  
18280 +       vx_activate_task(p);
18281         if (likely(cpu == this_cpu)) {
18282                 if (!(clone_flags & CLONE_VM)) {
18283                         /*
18284 @@ -1783,6 +1828,7 @@ void fastcall wake_up_new_task(struct ta
18285                                 __activate_task(p, rq);
18286                         else {
18287                                 p->prio = current->prio;
18288 +                               BUG_ON(p->state & TASK_ONHOLD);
18289                                 p->normal_prio = current->normal_prio;
18290                                 list_add_tail(&p->run_list, &current->run_list);
18291                                 p->array = current->array;
18292 @@ -3351,13 +3397,16 @@ static inline int expired_starving(struc
18293  void account_user_time(struct task_struct *p, cputime_t cputime)
18294  {
18295         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18296 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18297         cputime64_t tmp;
18298 +       int nice = (TASK_NICE(p) > 0);
18299  
18300         p->utime = cputime_add(p->utime, cputime);
18301 +       vx_account_user(vxi, cputime, nice);
18302  
18303         /* Add user time to cpustat. */
18304         tmp = cputime_to_cputime64(cputime);
18305 -       if (TASK_NICE(p) > 0)
18306 +       if (nice)
18307                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
18308         else
18309                 cpustat->user = cputime64_add(cpustat->user, tmp);
18310 @@ -3373,10 +3422,12 @@ void account_system_time(struct task_str
18311                          cputime_t cputime)
18312  {
18313         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
18314 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
18315         struct rq *rq = this_rq();
18316         cputime64_t tmp;
18317  
18318         p->stime = cputime_add(p->stime, cputime);
18319 +       vx_account_system(vxi, cputime, (p == rq->idle));
18320  
18321         /* Add system time to cpustat. */
18322         tmp = cputime_to_cputime64(cputime);
18323 @@ -3415,7 +3466,7 @@ void account_steal_time(struct task_stru
18324                 cpustat->steal = cputime64_add(cpustat->steal, tmp);
18325  }
18326  
18327 -static void task_running_tick(struct rq *rq, struct task_struct *p)
18328 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu)
18329  {
18330         if (p->array != rq->active) {
18331                 /* Task has expired but was not scheduled yet */
18332 @@ -3445,7 +3496,7 @@ static void task_running_tick(struct rq 
18333                 }
18334                 goto out_unlock;
18335         }
18336 -       if (!--p->time_slice) {
18337 +       if (vx_need_resched(p, --p->time_slice, cpu)) {
18338                 dequeue_task(p, rq->active);
18339                 set_tsk_need_resched(p);
18340                 p->prio = effective_prio(p);
18341 @@ -3506,9 +3557,12 @@ void scheduler_tick(void)
18342         struct rq *rq = cpu_rq(cpu);
18343  
18344         update_cpu_clock(p, rq, now);
18345 +       vxm_sync(now, cpu);
18346  
18347 -       if (!idle_at_tick)
18348 -               task_running_tick(rq, p);
18349 +       if (idle_at_tick)
18350 +               vx_idle_resched(rq);
18351 +       else
18352 +               task_running_tick(rq, p, cpu);
18353  #ifdef CONFIG_SMP
18354         update_load(rq);
18355         rq->idle_at_tick = idle_at_tick;
18356 @@ -3630,14 +3684,25 @@ need_resched_nonpreemptible:
18357                                 unlikely(signal_pending(prev))))
18358                         prev->state = TASK_RUNNING;
18359                 else {
18360 -                       if (prev->state == TASK_UNINTERRUPTIBLE)
18361 +                       if (prev->state == TASK_UNINTERRUPTIBLE) {
18362                                 rq->nr_uninterruptible++;
18363 +                               vx_uninterruptible_inc(prev);
18364 +                       }
18365                         deactivate_task(prev, rq);
18366                 }
18367         }
18368  
18369         cpu = smp_processor_id();
18370 +       vx_set_rq_time(rq, jiffies);
18371 +try_unhold:
18372 +       vx_try_unhold(rq, cpu);
18373 +pick_next:
18374 +
18375         if (unlikely(!rq->nr_running)) {
18376 +               /* can we skip idle time? */
18377 +               if (vx_try_skip(rq, cpu))
18378 +                       goto try_unhold;
18379 +
18380                 idle_balance(cpu, rq);
18381                 if (!rq->nr_running) {
18382                         next = rq->idle;
18383 @@ -3663,6 +3728,10 @@ need_resched_nonpreemptible:
18384         queue = array->queue + idx;
18385         next = list_entry(queue->next, struct task_struct, run_list);
18386  
18387 +       /* check before we schedule this context */
18388 +       if (!vx_schedule(next, rq, cpu))
18389 +               goto pick_next;
18390 +
18391         if (!rt_task(next) && interactive_sleep(next->sleep_type)) {
18392                 unsigned long long delta = now - next->timestamp;
18393                 if (unlikely((long long)(now - next->timestamp) < 0))
18394 @@ -4263,7 +4332,7 @@ asmlinkage long sys_nice(int increment)
18395                 nice = 19;
18396  
18397         if (increment < 0 && !can_nice(current, nice))
18398 -               return -EPERM;
18399 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
18400  
18401         retval = security_task_setnice(current, nice);
18402         if (retval)
18403 @@ -4435,6 +4504,7 @@ recheck:
18404         oldprio = p->prio;
18405         __setscheduler(p, policy, param->sched_priority);
18406         if (array) {
18407 +               vx_activate_task(p);
18408                 __activate_task(p, rq);
18409                 /*
18410                  * Reschedule if we are currently running on this runqueue and
18411 @@ -5188,6 +5258,7 @@ static int __migrate_task(struct task_st
18412                 p->timestamp = p->timestamp - rq_src->most_recent_timestamp
18413                                 + rq_dest->most_recent_timestamp;
18414                 deactivate_task(p, rq_src);
18415 +               vx_activate_task(p);
18416                 __activate_task(p, rq_dest);
18417                 if (TASK_PREEMPTS_CURR(p, rq_dest))
18418                         resched_task(rq_dest->curr);
18419 @@ -7058,7 +7129,10 @@ void __init sched_init(void)
18420                 INIT_LIST_HEAD(&rq->migration_queue);
18421  #endif
18422                 atomic_set(&rq->nr_iowait, 0);
18423 -
18424 +#ifdef CONFIG_VSERVER_HARDCPU
18425 +               INIT_LIST_HEAD(&rq->hold_queue);
18426 +               rq->nr_onhold = 0;
18427 +#endif
18428                 for (j = 0; j < 2; j++) {
18429                         array = rq->arrays + j;
18430                         for (k = 0; k < MAX_PRIO; k++) {
18431 @@ -7144,6 +7218,7 @@ void normalize_rt_tasks(void)
18432                         deactivate_task(p, task_rq(p));
18433                 __setscheduler(p, SCHED_NORMAL, 0);
18434                 if (array) {
18435 +                       vx_activate_task(p);
18436                         __activate_task(p, task_rq(p));
18437                         resched_task(rq->curr);
18438                 }
18439 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
18440 --- linux-2.6.22.10/kernel/sched_hard.h 1970-01-01 01:00:00 +0100
18441 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched_hard.h      2007-08-05 20:53:13 +0200
18442 @@ -0,0 +1,324 @@
18443 +
18444 +#ifdef CONFIG_VSERVER_IDLELIMIT
18445 +
18446 +/*
18447 + * vx_idle_resched - reschedule after maxidle
18448 + */
18449 +static inline
18450 +void vx_idle_resched(struct rq *rq)
18451 +{
18452 +       /* maybe have a better criterion for paused */
18453 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
18454 +               set_need_resched();
18455 +}
18456 +
18457 +#else /* !CONFIG_VSERVER_IDLELIMIT */
18458 +
18459 +#define vx_idle_resched(rq)
18460 +
18461 +#endif /* CONFIG_VSERVER_IDLELIMIT */
18462 +
18463 +
18464 +
18465 +#ifdef CONFIG_VSERVER_IDLETIME
18466 +
18467 +#define vx_set_rq_min_skip(rq, min)            \
18468 +       (rq)->idle_skip = (min)
18469 +
18470 +#define vx_save_min_skip(ret, min, val)                \
18471 +       __vx_save_min_skip(ret, min, val)
18472 +
18473 +static inline
18474 +void __vx_save_min_skip(int ret, int *min, int val)
18475 +{
18476 +       if (ret > -2)
18477 +               return;
18478 +       if ((*min > val) || !*min)
18479 +               *min = val;
18480 +}
18481 +
18482 +static inline
18483 +int vx_try_skip(struct rq *rq, int cpu)
18484 +{
18485 +       /* artificially advance time */
18486 +       if (rq->idle_skip > 0) {
18487 +               vxdprintk(list_empty(&rq->hold_queue),
18488 +                       "hold queue empty on cpu %d", cpu);
18489 +               rq->idle_time += rq->idle_skip;
18490 +               vxm_idle_skip(rq, cpu);
18491 +               return 1;
18492 +       }
18493 +       return 0;
18494 +}
18495 +
18496 +#else /* !CONFIG_VSERVER_IDLETIME */
18497 +
18498 +#define vx_set_rq_min_skip(rq, min)            \
18499 +       ({ int dummy = (min); dummy; })
18500 +
18501 +#define vx_save_min_skip(ret, min, val)
18502 +
18503 +static inline
18504 +int vx_try_skip(struct rq *rq, int cpu)
18505 +{
18506 +       return 0;
18507 +}
18508 +
18509 +#endif /* CONFIG_VSERVER_IDLETIME */
18510 +
18511 +
18512 +
18513 +#ifdef CONFIG_VSERVER_HARDCPU
18514 +
18515 +#define vx_set_rq_max_idle(rq, max)            \
18516 +       (rq)->idle_tokens = (max)
18517 +
18518 +#define vx_save_max_idle(ret, min, val)                \
18519 +       __vx_save_max_idle(ret, min, val)
18520 +
18521 +static inline
18522 +void __vx_save_max_idle(int ret, int *min, int val)
18523 +{
18524 +       if (*min > val)
18525 +               *min = val;
18526 +}
18527 +
18528 +
18529 +/*
18530 + * vx_hold_task - put a task on the hold queue
18531 + */
18532 +static inline
18533 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18534 +{
18535 +       __deactivate_task(p, rq);
18536 +       p->state |= TASK_ONHOLD;
18537 +       /* a new one on hold */
18538 +       rq->nr_onhold++;
18539 +       vxm_hold_task(p, rq);
18540 +       list_add_tail(&p->run_list, &rq->hold_queue);
18541 +}
18542 +
18543 +/*
18544 + * vx_unhold_task - put a task back to the runqueue
18545 + */
18546 +static inline
18547 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18548 +{
18549 +       list_del(&p->run_list);
18550 +       /* one less waiting */
18551 +       rq->nr_onhold--;
18552 +       p->state &= ~TASK_ONHOLD;
18553 +       enqueue_task(p, rq->expired);
18554 +       inc_nr_running(p, rq);
18555 +       vxm_unhold_task(p, rq);
18556 +
18557 +       if (p->static_prio < rq->best_expired_prio)
18558 +               rq->best_expired_prio = p->static_prio;
18559 +}
18560 +
18561 +unsigned long nr_onhold(void)
18562 +{
18563 +       unsigned long i, sum = 0;
18564 +
18565 +       for_each_online_cpu(i)
18566 +               sum += cpu_rq(i)->nr_onhold;
18567 +
18568 +       return sum;
18569 +}
18570 +
18571 +
18572 +
18573 +static inline
18574 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
18575 +{
18576 +       return sched_pc->tokens;
18577 +}
18578 +
18579 +static inline
18580 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
18581 +{
18582 +       sched_pc->tokens--;
18583 +}
18584 +
18585 +static inline
18586 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18587 +{
18588 +       struct vx_info *vxi = p->vx_info;
18589 +
18590 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
18591 +               struct _vx_sched_pc *sched_pc =
18592 +                       &vx_per_cpu(vxi, sched_pc, cpu);
18593 +               int tokens;
18594 +
18595 +               /* maybe we can simplify that to decrement
18596 +                  the token counter unconditional? */
18597 +
18598 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
18599 +                       __vx_consume_token(sched_pc);
18600 +
18601 +               /* for tokens > 0, one token was consumed */
18602 +               if (tokens < 2)
18603 +                       slice = 0;
18604 +       }
18605 +       vxm_need_resched(p, slice, cpu);
18606 +       return (slice == 0);
18607 +}
18608 +
18609 +
18610 +#define vx_set_rq_time(rq, time) do {  \
18611 +       rq->norm_time = time;           \
18612 +} while (0)
18613 +
18614 +
18615 +static inline
18616 +void vx_try_unhold(struct rq *rq, int cpu)
18617 +{
18618 +       struct vx_info *vxi = NULL;
18619 +       struct list_head *l, *n;
18620 +       int maxidle = HZ;
18621 +       int minskip = 0;
18622 +
18623 +       /* nothing to do? what about pause? */
18624 +       if (list_empty(&rq->hold_queue))
18625 +               return;
18626 +
18627 +       list_for_each_safe(l, n, &rq->hold_queue) {
18628 +               int ret, delta_min[2];
18629 +               struct _vx_sched_pc *sched_pc;
18630 +               struct task_struct *p;
18631 +
18632 +               p = list_entry(l, struct task_struct, run_list);
18633 +               /* don't bother with same context */
18634 +               if (vxi == p->vx_info)
18635 +                       continue;
18636 +
18637 +               vxi = p->vx_info;
18638 +               /* ignore paused contexts */
18639 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
18640 +                       continue;
18641 +
18642 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18643 +
18644 +               /* recalc tokens */
18645 +               vxm_sched_info(sched_pc, vxi, cpu);
18646 +               ret = vx_tokens_recalc(sched_pc,
18647 +                       &rq->norm_time, &rq->idle_time, delta_min);
18648 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18649 +
18650 +               if (ret > 0) {
18651 +                       /* we found a runable context */
18652 +                       vx_unhold_task(p, rq);
18653 +                       break;
18654 +               }
18655 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
18656 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
18657 +       }
18658 +       vx_set_rq_max_idle(rq, maxidle);
18659 +       vx_set_rq_min_skip(rq, minskip);
18660 +       vxm_rq_max_min(rq, cpu);
18661 +}
18662 +
18663 +
18664 +static inline
18665 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18666 +{
18667 +       struct vx_info *vxi = next->vx_info;
18668 +       struct _vx_sched_pc *sched_pc;
18669 +       int delta_min[2];
18670 +       int flags, ret;
18671 +
18672 +       if (!vxi)
18673 +               return 1;
18674 +
18675 +       flags = vxi->vx_flags;
18676 +
18677 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
18678 +               goto put_on_hold;
18679 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
18680 +               return 1;
18681 +
18682 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18683 +#ifdef CONFIG_SMP
18684 +       /* update scheduler params */
18685 +       if (cpu_isset(cpu, vxi->sched.update)) {
18686 +               vx_update_sched_param(&vxi->sched, sched_pc);
18687 +               vxm_update_sched(sched_pc, vxi, cpu);
18688 +               cpu_clear(cpu, vxi->sched.update);
18689 +       }
18690 +#endif
18691 +       vxm_sched_info(sched_pc, vxi, cpu);
18692 +       ret  = vx_tokens_recalc(sched_pc,
18693 +               &rq->norm_time, &rq->idle_time, delta_min);
18694 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18695 +
18696 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
18697 +               return 1;
18698 +
18699 +       if (unlikely(ret < 0)) {
18700 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
18701 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
18702 +               vxm_rq_max_min(rq, cpu);
18703 +       put_on_hold:
18704 +               vx_hold_task(next, rq);
18705 +               return 0;
18706 +       }
18707 +       return 1;
18708 +}
18709 +
18710 +
18711 +#else /* CONFIG_VSERVER_HARDCPU */
18712 +
18713 +static inline
18714 +void vx_hold_task(struct task_struct *p, struct rq *rq)
18715 +{
18716 +       return;
18717 +}
18718 +
18719 +static inline
18720 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
18721 +{
18722 +       return;
18723 +}
18724 +
18725 +unsigned long nr_onhold(void)
18726 +{
18727 +       return 0;
18728 +}
18729 +
18730 +
18731 +static inline
18732 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
18733 +{
18734 +       return (slice == 0);
18735 +}
18736 +
18737 +
18738 +#define vx_set_rq_time(rq, time)
18739 +
18740 +static inline
18741 +void vx_try_unhold(struct rq *rq, int cpu)
18742 +{
18743 +       return;
18744 +}
18745 +
18746 +static inline
18747 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
18748 +{
18749 +       struct vx_info *vxi = next->vx_info;
18750 +       struct _vx_sched_pc *sched_pc;
18751 +       int delta_min[2];
18752 +       int ret;
18753 +
18754 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
18755 +               return 1;
18756 +
18757 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
18758 +       vxm_sched_info(sched_pc, vxi, cpu);
18759 +       ret  = vx_tokens_recalc(sched_pc,
18760 +               &rq->norm_time, &rq->idle_time, delta_min);
18761 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
18762 +       return 1;
18763 +}
18764 +
18765 +#endif /* CONFIG_VSERVER_HARDCPU */
18766 +
18767 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
18768 --- linux-2.6.22.10/kernel/sched_mon.h  1970-01-01 01:00:00 +0100
18769 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sched_mon.h       2007-08-05 20:53:13 +0200
18770 @@ -0,0 +1,200 @@
18771 +
18772 +#include <linux/vserver/monitor.h>
18773 +
18774 +#ifdef  CONFIG_VSERVER_MONITOR
18775 +
18776 +#ifdef CONFIG_VSERVER_HARDCPU
18777 +#define HARDCPU(x) (x)
18778 +#else
18779 +#define HARDCPU(x) (0)
18780 +#endif
18781 +
18782 +#ifdef CONFIG_VSERVER_IDLETIME
18783 +#define IDLETIME(x) (x)
18784 +#else
18785 +#define IDLETIME(x) (0)
18786 +#endif
18787 +
18788 +struct _vx_mon_entry *vxm_advance(int cpu);
18789 +
18790 +
18791 +static inline
18792 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
18793 +{
18794 +       entry->type = type;
18795 +       entry->xid = xid;
18796 +}
18797 +
18798 +static inline
18799 +void   __vxm_sync(int cpu)
18800 +{
18801 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18802 +
18803 +       __vxm_basic(entry, 0, VXM_SYNC);
18804 +       entry->ev.sec = xtime.tv_sec;
18805 +       entry->ev.nsec = xtime.tv_nsec;
18806 +}
18807 +
18808 +static inline
18809 +void   __vxm_task(struct task_struct *p, int type)
18810 +{
18811 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
18812 +
18813 +       __vxm_basic(entry, p->xid, type);
18814 +       entry->ev.tsk.pid = p->pid;
18815 +       entry->ev.tsk.state = p->state;
18816 +}
18817 +
18818 +static inline
18819 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18820 +{
18821 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18822 +
18823 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
18824 +       entry->sd.tokens = s->tokens;
18825 +       entry->sd.norm_time = s->norm_time;
18826 +       entry->sd.idle_time = s->idle_time;
18827 +}
18828 +
18829 +static inline
18830 +void   __vxm_rqinfo1(struct rq *q, int cpu)
18831 +{
18832 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18833 +
18834 +       entry->type = VXM_RQINFO_1;
18835 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
18836 +       entry->q1.running = q->nr_running;
18837 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
18838 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
18839 +       entry->q1.uintr = q->nr_uninterruptible;
18840 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
18841 +}
18842 +
18843 +static inline
18844 +void   __vxm_rqinfo2(struct rq *q, int cpu)
18845 +{
18846 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18847 +
18848 +       entry->type = VXM_RQINFO_2;
18849 +       entry->xid = (unsigned long)q & 0xffff;
18850 +       entry->q2.norm_time = q->norm_time;
18851 +       entry->q2.idle_time = q->idle_time;
18852 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
18853 +}
18854 +
18855 +static inline
18856 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18857 +{
18858 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18859 +
18860 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
18861 +       entry->ev.tokens = s->tokens;
18862 +}
18863 +
18864 +static inline
18865 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18866 +{
18867 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18868 +
18869 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
18870 +       entry->u1.tokens_max = s->tokens_max;
18871 +       entry->u1.fill_rate = s->fill_rate[0];
18872 +       entry->u1.interval = s->interval[0];
18873 +}
18874 +
18875 +static inline
18876 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18877 +{
18878 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
18879 +
18880 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
18881 +       entry->u2.tokens_min = s->tokens_min;
18882 +       entry->u2.fill_rate = s->fill_rate[1];
18883 +       entry->u2.interval = s->interval[1];
18884 +}
18885 +
18886 +
18887 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
18888 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
18889 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
18890 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
18891 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
18892 +
18893 +static inline
18894 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
18895 +{
18896 +       __vxm_task(p, VXM_MIGRATE);
18897 +       __vxm_rqinfo1(rq, task_cpu(p));
18898 +       __vxm_rqinfo2(rq, task_cpu(p));
18899 +}
18900 +
18901 +static inline
18902 +void   vxm_idle_skip(struct rq *rq, int cpu)
18903 +{
18904 +       __vxm_rqinfo1(rq, cpu);
18905 +       __vxm_rqinfo2(rq, cpu);
18906 +}
18907 +
18908 +static inline
18909 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
18910 +{
18911 +       if (slice)
18912 +               return;
18913 +
18914 +       __vxm_task(p, VXM_RESCHED);
18915 +}
18916 +
18917 +static inline
18918 +void   vxm_sync(unsigned long now, int cpu)
18919 +{
18920 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
18921 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
18922 +               return;
18923 +
18924 +       __vxm_sync(cpu);
18925 +}
18926 +
18927 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
18928 +
18929 +static inline
18930 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
18931 +       struct vx_info *vxi, int cpu)
18932 +{
18933 +       __vxm_sched(s, vxi, cpu);
18934 +       __vxm_rqinfo2(rq, cpu);
18935 +}
18936 +
18937 +static inline
18938 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
18939 +{
18940 +       __vxm_sched(s, vxi, cpu);
18941 +       __vxm_update(s, vxi, cpu);
18942 +       __vxm_update1(s, vxi, cpu);
18943 +       __vxm_update2(s, vxi, cpu);
18944 +}
18945 +
18946 +static inline
18947 +void   vxm_rq_max_min(struct rq *rq, int cpu)
18948 +{
18949 +       __vxm_rqinfo1(rq, cpu);
18950 +       __vxm_rqinfo2(rq, cpu);
18951 +}
18952 +
18953 +#else  /* CONFIG_VSERVER_MONITOR */
18954 +
18955 +#define        vxm_activate_task(t,q)          do { } while (0)
18956 +#define        vxm_activate_idle(t,q)          do { } while (0)
18957 +#define        vxm_deactivate_task(t,q)        do { } while (0)
18958 +#define        vxm_hold_task(t,q)              do { } while (0)
18959 +#define        vxm_unhold_task(t,q)            do { } while (0)
18960 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
18961 +#define        vxm_idle_skip(q,c)              do { } while (0)
18962 +#define        vxm_need_resched(t,s,c)         do { } while (0)
18963 +#define        vxm_sync(s,c)                   do { } while (0)
18964 +#define        vxm_sched_info(s,v,c)           do { } while (0)
18965 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
18966 +#define        vxm_update_sched(s,v,c)         do { } while (0)
18967 +#define        vxm_rq_max_min(q,c)             do { } while (0)
18968 +
18969 +#endif /* CONFIG_VSERVER_MONITOR */
18970 +
18971 diff -NurpP --minimal linux-2.6.22.10/kernel/signal.c linux-2.6.22.10-vs2.3.0.29/kernel/signal.c
18972 --- linux-2.6.22.10/kernel/signal.c     2007-10-30 01:57:15 +0100
18973 +++ linux-2.6.22.10-vs2.3.0.29/kernel/signal.c  2007-09-30 14:58:01 +0200
18974 @@ -26,6 +26,8 @@
18975  #include <linux/freezer.h>
18976  #include <linux/pid_namespace.h>
18977  #include <linux/nsproxy.h>
18978 +#include <linux/vs_context.h>
18979 +#include <linux/vs_pid.h>
18980  
18981  #include <asm/param.h>
18982  #include <asm/uaccess.h>
18983 @@ -523,19 +525,34 @@ static int check_kill_permission(int sig
18984         if (!valid_signal(sig))
18985                 return error;
18986  
18987 +       if ((info != SEND_SIG_NOINFO) &&
18988 +               (is_si_special(info) || !SI_FROMUSER(info)))
18989 +               goto skip;
18990 +
18991 +       vxdprintk(VXD_CBIT(misc, 7),
18992 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
18993 +               sig, info, t, vx_task_xid(t), t->pid);
18994 +
18995         error = audit_signal_info(sig, t); /* Let audit system see the signal */
18996         if (error)
18997                 return error;
18998  
18999         error = -EPERM;
19000 -       if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
19001 -           && ((sig != SIGCONT) ||
19002 +       if (((sig != SIGCONT) ||
19003                 (process_session(current) != process_session(t)))
19004             && (current->euid ^ t->suid) && (current->euid ^ t->uid)
19005             && (current->uid ^ t->suid) && (current->uid ^ t->uid)
19006             && !capable(CAP_KILL))
19007                 return error;
19008  
19009 +       error = -ESRCH;
19010 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
19011 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
19012 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
19013 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
19014 +               return error;
19015 +       }
19016 +skip:
19017         return security_task_kill(t, info, sig, 0);
19018  }
19019  
19020 @@ -1043,7 +1060,7 @@ int kill_pid_info(int sig, struct siginf
19021  
19022         p = pid_task(pid, PIDTYPE_PID);
19023         error = -ESRCH;
19024 -       if (p)
19025 +       if (p && vx_check(vx_task_xid(p), VS_IDENT))
19026                 error = group_send_sig_info(sig, info, p);
19027  
19028         if (unlikely(sig_needs_tasklist(sig)))
19029 @@ -1057,7 +1074,7 @@ kill_proc_info(int sig, struct siginfo *
19030  {
19031         int error;
19032         rcu_read_lock();
19033 -       error = kill_pid_info(sig, info, find_pid(pid));
19034 +       error = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
19035         rcu_read_unlock();
19036         return error;
19037  }
19038 @@ -1118,7 +1135,8 @@ static int kill_something_info(int sig, 
19039  
19040                 read_lock(&tasklist_lock);
19041                 for_each_process(p) {
19042 -                       if (p->pid > 1 && p->tgid != current->tgid) {
19043 +                       if (vx_check(vx_task_xid(p), VS_ADMIN_P|VS_IDENT) &&
19044 +                               p->pid > 1 && p->tgid != current->tgid) {
19045                                 int err = group_send_sig_info(sig, info, p);
19046                                 ++count;
19047                                 if (err != -EPERM)
19048 @@ -1814,6 +1832,11 @@ relock:
19049                 if (current == child_reaper(current))
19050                         continue;
19051  
19052 +               /* virtual init is protected against user signals */
19053 +               if ((info->si_code == SI_USER) &&
19054 +                       vx_current_initpid(current->pid))
19055 +                       continue;
19056 +
19057                 if (sig_kernel_stop(signr)) {
19058                         /*
19059                          * The default action is to stop all threads in
19060 diff -NurpP --minimal linux-2.6.22.10/kernel/softirq.c linux-2.6.22.10-vs2.3.0.29/kernel/softirq.c
19061 --- linux-2.6.22.10/kernel/softirq.c    2007-07-09 13:20:03 +0200
19062 +++ linux-2.6.22.10-vs2.3.0.29/kernel/softirq.c 2007-08-05 20:53:13 +0200
19063 @@ -18,6 +18,7 @@
19064  #include <linux/rcupdate.h>
19065  #include <linux/smp.h>
19066  #include <linux/tick.h>
19067 +#include <linux/vs_context.h>
19068  
19069  #include <asm/irq.h>
19070  /*
19071 diff -NurpP --minimal linux-2.6.22.10/kernel/sys.c linux-2.6.22.10-vs2.3.0.29/kernel/sys.c
19072 --- linux-2.6.22.10/kernel/sys.c        2007-10-30 01:57:15 +0100
19073 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sys.c     2007-10-30 01:21:54 +0100
19074 @@ -36,6 +36,7 @@
19075  #include <linux/compat.h>
19076  #include <linux/syscalls.h>
19077  #include <linux/kprobes.h>
19078 +#include <linux/vs_pid.h>
19079  
19080  #include <asm/uaccess.h>
19081  #include <asm/io.h>
19082 @@ -639,7 +640,10 @@ static int set_one_prio(struct task_stru
19083                 goto out;
19084         }
19085         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
19086 -               error = -EACCES;
19087 +               if (vx_flags(VXF_IGNEG_NICE, 0))
19088 +                       error = 0;
19089 +               else
19090 +                       error = -EACCES;
19091                 goto out;
19092         }
19093         no_nice = security_task_setnice(p, niceval);
19094 @@ -687,6 +691,8 @@ asmlinkage long sys_setpriority(int whic
19095                         else
19096                                 pgrp = task_pgrp(current);
19097                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19098 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19099 +                                       continue;
19100                                 error = set_one_prio(p, niceval, error);
19101                         } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
19102                         break;
19103 @@ -695,7 +701,8 @@ asmlinkage long sys_setpriority(int whic
19104                         if (!who)
19105                                 who = current->uid;
19106                         else
19107 -                               if ((who != current->uid) && !(user = find_user(who)))
19108 +                               if ((who != current->uid) &&
19109 +                                       !(user = find_user(vx_current_xid(), who)))
19110                                         goto out_unlock;        /* No processes for this user */
19111  
19112                         do_each_thread(g, p)
19113 @@ -747,6 +754,8 @@ asmlinkage long sys_getpriority(int whic
19114                         else
19115                                 pgrp = task_pgrp(current);
19116                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
19117 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
19118 +                                       continue;
19119                                 niceval = 20 - task_nice(p);
19120                                 if (niceval > retval)
19121                                         retval = niceval;
19122 @@ -757,7 +766,8 @@ asmlinkage long sys_getpriority(int whic
19123                         if (!who)
19124                                 who = current->uid;
19125                         else
19126 -                               if ((who != current->uid) && !(user = find_user(who)))
19127 +                               if ((who != current->uid) &&
19128 +                                       !(user = find_user(vx_current_xid(), who)))
19129                                         goto out_unlock;        /* No processes for this user */
19130  
19131                         do_each_thread(g, p)
19132 @@ -871,6 +881,9 @@ void kernel_power_off(void)
19133         machine_power_off();
19134  }
19135  EXPORT_SYMBOL_GPL(kernel_power_off);
19136 +
19137 +long vs_reboot(unsigned int, void __user *);
19138 +
19139  /*
19140   * Reboot system call: for obvious reasons only root may call it,
19141   * and even root needs to set up some magic numbers in the registers
19142 @@ -901,6 +914,9 @@ asmlinkage long sys_reboot(int magic1, i
19143         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
19144                 cmd = LINUX_REBOOT_CMD_HALT;
19145  
19146 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
19147 +               return vs_reboot(cmd, arg);
19148 +
19149         lock_kernel();
19150         switch (cmd) {
19151         case LINUX_REBOOT_CMD_RESTART:
19152 @@ -1080,7 +1096,7 @@ static int set_user(uid_t new_ruid, int 
19153  {
19154         struct user_struct *new_user;
19155  
19156 -       new_user = alloc_uid(new_ruid);
19157 +       new_user = alloc_uid(vx_current_xid(), new_ruid);
19158         if (!new_user)
19159                 return -EAGAIN;
19160  
19161 @@ -1434,15 +1450,18 @@ asmlinkage long sys_setpgid(pid_t pid, p
19162  {
19163         struct task_struct *p;
19164         struct task_struct *group_leader = current->group_leader;
19165 +       pid_t rpgid;
19166         int err = -EINVAL;
19167  
19168         if (!pid)
19169 -               pid = group_leader->pid;
19170 +               pid = vx_map_pid(group_leader->pid);
19171         if (!pgid)
19172                 pgid = pid;
19173         if (pgid < 0)
19174                 return -EINVAL;
19175  
19176 +       rpgid = vx_rmap_pid(pgid);
19177 +
19178         /* From this point forward we keep holding onto the tasklist lock
19179          * so that our parent does not change from under us. -DaveM
19180          */
19181 @@ -1476,20 +1495,20 @@ asmlinkage long sys_setpgid(pid_t pid, p
19182  
19183         if (pgid != pid) {
19184                 struct task_struct *g =
19185 -                       find_task_by_pid_type(PIDTYPE_PGID, pgid);
19186 +                       find_task_by_pid_type(PIDTYPE_PGID, rpgid);
19187  
19188                 if (!g || task_session(g) != task_session(group_leader))
19189                         goto out;
19190         }
19191  
19192 -       err = security_task_setpgid(p, pgid);
19193 +       err = security_task_setpgid(p, rpgid);
19194         if (err)
19195                 goto out;
19196  
19197 -       if (process_group(p) != pgid) {
19198 +       if (process_group(p) != rpgid) {
19199                 detach_pid(p, PIDTYPE_PGID);
19200 -               p->signal->pgrp = pgid;
19201 -               attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
19202 +               p->signal->pgrp = rpgid;
19203 +               attach_pid(p, PIDTYPE_PGID, find_pid(rpgid));
19204         }
19205  
19206         err = 0;
19207 @@ -1502,7 +1521,7 @@ out:
19208  asmlinkage long sys_getpgid(pid_t pid)
19209  {
19210         if (!pid)
19211 -               return process_group(current);
19212 +               return vx_rmap_pid(process_group(current));
19213         else {
19214                 int retval;
19215                 struct task_struct *p;
19216 @@ -1514,7 +1533,7 @@ asmlinkage long sys_getpgid(pid_t pid)
19217                 if (p) {
19218                         retval = security_task_getpgid(p);
19219                         if (!retval)
19220 -                               retval = process_group(p);
19221 +                               retval = vx_rmap_pid(process_group(p));
19222                 }
19223                 read_unlock(&tasklist_lock);
19224                 return retval;
19225 @@ -1865,7 +1884,7 @@ asmlinkage long sys_sethostname(char __u
19226         int errno;
19227         char tmp[__NEW_UTS_LEN];
19228  
19229 -       if (!capable(CAP_SYS_ADMIN))
19230 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19231                 return -EPERM;
19232         if (len < 0 || len > __NEW_UTS_LEN)
19233                 return -EINVAL;
19234 @@ -1910,7 +1929,7 @@ asmlinkage long sys_setdomainname(char _
19235         int errno;
19236         char tmp[__NEW_UTS_LEN];
19237  
19238 -       if (!capable(CAP_SYS_ADMIN))
19239 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
19240                 return -EPERM;
19241         if (len < 0 || len > __NEW_UTS_LEN)
19242                 return -EINVAL;
19243 @@ -1977,7 +1996,7 @@ asmlinkage long sys_setrlimit(unsigned i
19244                 return -EINVAL;
19245         old_rlim = current->signal->rlim + resource;
19246         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
19247 -           !capable(CAP_SYS_RESOURCE))
19248 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
19249                 return -EPERM;
19250         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
19251                 return -EPERM;
19252 diff -NurpP --minimal linux-2.6.22.10/kernel/sysctl.c linux-2.6.22.10-vs2.3.0.29/kernel/sysctl.c
19253 --- linux-2.6.22.10/kernel/sysctl.c     2007-07-09 13:20:03 +0200
19254 +++ linux-2.6.22.10-vs2.3.0.29/kernel/sysctl.c  2007-08-05 20:53:13 +0200
19255 @@ -89,6 +89,7 @@ static int ngroups_max = NGROUPS_MAX;
19256  #ifdef CONFIG_KMOD
19257  extern char modprobe_path[];
19258  #endif
19259 +extern char vshelper_path[];
19260  #ifdef CONFIG_CHR_DEV_SG
19261  extern int sg_big_buff;
19262  #endif
19263 @@ -343,6 +344,15 @@ static ctl_table kern_table[] = {
19264                 .strategy       = &sysctl_string,
19265         },
19266  #endif
19267 +       {
19268 +               .ctl_name       = KERN_VSHELPER,
19269 +               .procname       = "vshelper",
19270 +               .data           = &vshelper_path,
19271 +               .maxlen         = 256,
19272 +               .mode           = 0644,
19273 +               .proc_handler   = &proc_dostring,
19274 +               .strategy       = &sysctl_string,
19275 +       },
19276  #ifdef CONFIG_CHR_DEV_SG
19277         {
19278                 .ctl_name       = KERN_SG_BIG_BUFF,
19279 diff -NurpP --minimal linux-2.6.22.10/kernel/time.c linux-2.6.22.10-vs2.3.0.29/kernel/time.c
19280 --- linux-2.6.22.10/kernel/time.c       2007-07-09 13:20:03 +0200
19281 +++ linux-2.6.22.10-vs2.3.0.29/kernel/time.c    2007-08-05 20:53:13 +0200
19282 @@ -60,7 +60,7 @@ asmlinkage long sys_time(time_t __user *
19283         time_t i;
19284         struct timeval tv;
19285  
19286 -       do_gettimeofday(&tv);
19287 +       vx_gettimeofday(&tv);
19288         i = tv.tv_sec;
19289  
19290         if (tloc) {
19291 @@ -91,7 +91,7 @@ asmlinkage long sys_stime(time_t __user 
19292         if (err)
19293                 return err;
19294  
19295 -       do_settimeofday(&tv);
19296 +       vx_settimeofday(&tv);
19297         return 0;
19298  }
19299  
19300 @@ -101,7 +101,7 @@ asmlinkage long sys_gettimeofday(struct 
19301  {
19302         if (likely(tv != NULL)) {
19303                 struct timeval ktv;
19304 -               do_gettimeofday(&ktv);
19305 +               vx_gettimeofday(&ktv);
19306                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
19307                         return -EFAULT;
19308         }
19309 @@ -175,7 +175,7 @@ int do_sys_settimeofday(struct timespec 
19310                 /* SMP safe, again the code in arch/foo/time.c should
19311                  * globally block out interrupts when it runs.
19312                  */
19313 -               return do_settimeofday(tv);
19314 +               return vx_settimeofday(tv);
19315         }
19316         return 0;
19317  }
19318 @@ -388,7 +388,7 @@ void getnstimeofday(struct timespec *tv)
19319  {
19320         struct timeval x;
19321  
19322 -       do_gettimeofday(&x);
19323 +       vx_gettimeofday(&x);
19324         tv->tv_sec = x.tv_sec;
19325         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
19326  }
19327 diff -NurpP --minimal linux-2.6.22.10/kernel/timer.c linux-2.6.22.10-vs2.3.0.29/kernel/timer.c
19328 --- linux-2.6.22.10/kernel/timer.c      2007-07-09 13:20:04 +0200
19329 +++ linux-2.6.22.10-vs2.3.0.29/kernel/timer.c   2007-08-05 20:53:13 +0200
19330 @@ -36,6 +36,10 @@
19331  #include <linux/delay.h>
19332  #include <linux/tick.h>
19333  #include <linux/kallsyms.h>
19334 +#include <linux/vs_base.h>
19335 +#include <linux/vs_cvirt.h>
19336 +#include <linux/vs_pid.h>
19337 +#include <linux/vserver/sched.h>
19338  
19339  #include <asm/uaccess.h>
19340  #include <asm/unistd.h>
19341 @@ -921,12 +925,6 @@ asmlinkage unsigned long sys_alarm(unsig
19342  
19343  #endif
19344  
19345 -#ifndef __alpha__
19346 -
19347 -/*
19348 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
19349 - * should be moved into arch/i386 instead?
19350 - */
19351  
19352  /**
19353   * sys_getpid - return the thread group id of the current process
19354 @@ -939,7 +937,7 @@ asmlinkage unsigned long sys_alarm(unsig
19355   */
19356  asmlinkage long sys_getpid(void)
19357  {
19358 -       return current->tgid;
19359 +       return vx_map_tgid(current->tgid);
19360  }
19361  
19362  /*
19363 @@ -955,10 +953,23 @@ asmlinkage long sys_getppid(void)
19364         rcu_read_lock();
19365         pid = rcu_dereference(current->real_parent)->tgid;
19366         rcu_read_unlock();
19367 +       return vx_map_pid(pid);
19368 +}
19369  
19370 -       return pid;
19371 +#ifdef __alpha__
19372 +
19373 +/*
19374 + * The Alpha uses getxpid, getxuid, and getxgid instead.
19375 + */
19376 +
19377 +asmlinkage long do_getxpid(long *ppid)
19378 +{
19379 +       *ppid = sys_getppid();
19380 +       return sys_getpid();
19381  }
19382  
19383 +#else /* _alpha_ */
19384 +
19385  asmlinkage long sys_getuid(void)
19386  {
19387         /* Only we change this so SMP safe */
19388 @@ -1118,6 +1129,8 @@ int do_sysinfo(struct sysinfo *info)
19389                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
19390                         tp.tv_sec++;
19391                 }
19392 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
19393 +                       vx_vsi_uptime(&tp, NULL);
19394                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
19395  
19396                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
19397 diff -NurpP --minimal linux-2.6.22.10/kernel/user.c linux-2.6.22.10-vs2.3.0.29/kernel/user.c
19398 --- linux-2.6.22.10/kernel/user.c       2007-02-06 03:01:56 +0100
19399 +++ linux-2.6.22.10-vs2.3.0.29/kernel/user.c    2007-08-05 20:53:13 +0200
19400 @@ -23,8 +23,8 @@
19401  #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
19402  #define UIDHASH_SZ             (1 << UIDHASH_BITS)
19403  #define UIDHASH_MASK           (UIDHASH_SZ - 1)
19404 -#define __uidhashfn(uid)       (((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
19405 -#define uidhashentry(uid)      (uidhash_table + __uidhashfn((uid)))
19406 +#define __uidhashfn(xid,uid)   ((((uid) >> UIDHASH_BITS) + ((uid)^(xid))) & UIDHASH_MASK)
19407 +#define uidhashentry(xid,uid)  (uidhash_table + __uidhashfn((xid),(uid)))
19408  
19409  static struct kmem_cache *uid_cachep;
19410  static struct list_head uidhash_table[UIDHASH_SZ];
19411 @@ -66,7 +66,7 @@ static inline void uid_hash_remove(struc
19412         list_del(&up->uidhash_list);
19413  }
19414  
19415 -static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *hashent)
19416 +static inline struct user_struct *uid_hash_find(xid_t xid, uid_t uid, struct list_head *hashent)
19417  {
19418         struct list_head *up;
19419  
19420 @@ -75,7 +75,7 @@ static inline struct user_struct *uid_ha
19421  
19422                 user = list_entry(up, struct user_struct, uidhash_list);
19423  
19424 -               if(user->uid == uid) {
19425 +               if(user->uid == uid && user->xid == xid) {
19426                         atomic_inc(&user->__count);
19427                         return user;
19428                 }
19429 @@ -90,13 +90,13 @@ static inline struct user_struct *uid_ha
19430   *
19431   * If the user_struct could not be found, return NULL.
19432   */
19433 -struct user_struct *find_user(uid_t uid)
19434 +struct user_struct *find_user(xid_t xid, uid_t uid)
19435  {
19436         struct user_struct *ret;
19437         unsigned long flags;
19438  
19439         spin_lock_irqsave(&uidhash_lock, flags);
19440 -       ret = uid_hash_find(uid, uidhashentry(uid));
19441 +       ret = uid_hash_find(xid, uid, uidhashentry(xid, uid));
19442         spin_unlock_irqrestore(&uidhash_lock, flags);
19443         return ret;
19444  }
19445 @@ -120,13 +120,13 @@ void free_uid(struct user_struct *up)
19446         }
19447  }
19448  
19449 -struct user_struct * alloc_uid(uid_t uid)
19450 +struct user_struct * alloc_uid(xid_t xid, uid_t uid)
19451  {
19452 -       struct list_head *hashent = uidhashentry(uid);
19453 +       struct list_head *hashent = uidhashentry(xid, uid);
19454         struct user_struct *up;
19455  
19456         spin_lock_irq(&uidhash_lock);
19457 -       up = uid_hash_find(uid, hashent);
19458 +       up = uid_hash_find(xid, uid, hashent);
19459         spin_unlock_irq(&uidhash_lock);
19460  
19461         if (!up) {
19462 @@ -136,6 +136,7 @@ struct user_struct * alloc_uid(uid_t uid
19463                 if (!new)
19464                         return NULL;
19465                 new->uid = uid;
19466 +               new->xid = xid;
19467                 atomic_set(&new->__count, 1);
19468                 atomic_set(&new->processes, 0);
19469                 atomic_set(&new->files, 0);
19470 @@ -158,7 +159,7 @@ struct user_struct * alloc_uid(uid_t uid
19471                  * on adding the same user already..
19472                  */
19473                 spin_lock_irq(&uidhash_lock);
19474 -               up = uid_hash_find(uid, hashent);
19475 +               up = uid_hash_find(xid, uid, hashent);
19476                 if (up) {
19477                         key_put(new->uid_keyring);
19478                         key_put(new->session_keyring);
19479 @@ -215,7 +216,7 @@ static int __init uid_cache_init(void)
19480  
19481         /* Insert the root user immediately (init already runs as root) */
19482         spin_lock_irq(&uidhash_lock);
19483 -       uid_hash_insert(&root_user, uidhashentry(0));
19484 +       uid_hash_insert(&root_user, uidhashentry(0,0));
19485         spin_unlock_irq(&uidhash_lock);
19486  
19487         return 0;
19488 diff -NurpP --minimal linux-2.6.22.10/kernel/utsname.c linux-2.6.22.10-vs2.3.0.29/kernel/utsname.c
19489 --- linux-2.6.22.10/kernel/utsname.c    2007-07-09 13:20:04 +0200
19490 +++ linux-2.6.22.10-vs2.3.0.29/kernel/utsname.c 2007-08-05 20:53:13 +0200
19491 @@ -13,6 +13,7 @@
19492  #include <linux/uts.h>
19493  #include <linux/utsname.h>
19494  #include <linux/version.h>
19495 +#include <linux/vserver/global.h>
19496  
19497  /*
19498   * Clone a new ns copying an original utsname, setting refcount to 1
19499 @@ -27,6 +28,7 @@ static struct uts_namespace *clone_uts_n
19500         if (ns) {
19501                 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
19502                 kref_init(&ns->kref);
19503 +               atomic_inc(&vs_global_uts_ns);
19504         }
19505         return ns;
19506  }
19507 @@ -58,5 +60,6 @@ void free_uts_ns(struct kref *kref)
19508         struct uts_namespace *ns;
19509  
19510         ns = container_of(kref, struct uts_namespace, kref);
19511 +       atomic_dec(&vs_global_uts_ns);
19512         kfree(ns);
19513  }
19514 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/Kconfig linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Kconfig
19515 --- linux-2.6.22.10/kernel/vserver/Kconfig      1970-01-01 01:00:00 +0100
19516 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Kconfig   2007-10-11 01:10:22 +0200
19517 @@ -0,0 +1,249 @@
19518 +#
19519 +# Linux VServer configuration
19520 +#
19521 +
19522 +menu "Linux VServer"
19523 +
19524 +config VSERVER_AUTO_LBACK
19525 +       bool    "Automatically Assign Loopback IP"
19526 +       default y
19527 +       help
19528 +         Automatically assign a guest specific loopback
19529 +         IP and add it to the kernel network stack on
19530 +         startup.
19531 +
19532 +config VSERVER_AUTO_SINGLE
19533 +       bool    "Automatic Single IP Special Casing"
19534 +       depends on EXPERIMENTAL
19535 +       default y
19536 +       help
19537 +         This allows network contexts with a single IP to
19538 +         automatically remap 0.0.0.0 bindings to that IP,
19539 +         avoiding further network checks and improving
19540 +         performance.
19541 +
19542 +         (note: such guests do not allow to change the ip
19543 +          on the fly and do not show loopback addresses)
19544 +
19545 +config VSERVER_COWBL
19546 +       bool    "Enable COW Immutable Link Breaking"
19547 +       default y
19548 +       help
19549 +         This enables the COW (Copy-On-Write) link break code.
19550 +         It allows you to treat unified files like normal files
19551 +         when writing to them (which will implicitely break the
19552 +         link and create a copy of the unified file)
19553 +
19554 +config VSERVER_VTIME
19555 +       bool    "Enable Virtualized Guest Time"
19556 +       depends on EXPERIMENTAL
19557 +       default n
19558 +       help
19559 +         This enables per guest time offsets to allow for
19560 +         adjusting the system clock individually per guest.
19561 +         this adds some overhead to the time functions and
19562 +         therefore should not be enabled without good reason.
19563 +
19564 +config VSERVER_DEVICE
19565 +       bool    "Enable Guest Device Mapping"
19566 +       depends on EXPERIMENTAL
19567 +       default n
19568 +       help
19569 +         This enables generic device remapping.
19570 +
19571 +config VSERVER_PROC_SECURE
19572 +       bool    "Enable Proc Security"
19573 +       depends on PROC_FS
19574 +       default y
19575 +       help
19576 +         This configures ProcFS security to initially hide
19577 +         non-process entries for all contexts except the main and
19578 +         spectator context (i.e. for all guests), which is a secure
19579 +         default.
19580 +
19581 +         (note: on 1.2x the entries were visible by default)
19582 +
19583 +config VSERVER_HARDCPU
19584 +       bool    "Enable Hard CPU Limits"
19585 +       default y
19586 +       help
19587 +         Activate the Hard CPU Limits
19588 +
19589 +         This will compile in code that allows the Token Bucket
19590 +         Scheduler to put processes on hold when a context's
19591 +         tokens are depleted (provided that its per-context
19592 +         sched_hard flag is set).
19593 +
19594 +         Processes belonging to that context will not be able
19595 +         to consume CPU resources again until a per-context
19596 +         configured minimum of tokens has been reached.
19597 +
19598 +config VSERVER_IDLETIME
19599 +       bool    "Avoid idle CPUs by skipping Time"
19600 +       depends on VSERVER_HARDCPU
19601 +       default y
19602 +       help
19603 +         This option allows the scheduler to artificially
19604 +         advance time (per cpu) when otherwise the idle
19605 +         task would be scheduled, thus keeping the cpu
19606 +         busy and sharing the available resources among
19607 +         certain contexts.
19608 +
19609 +config VSERVER_IDLELIMIT
19610 +       bool    "Limit the IDLE task"
19611 +       depends on VSERVER_HARDCPU
19612 +       default n
19613 +       help
19614 +         Limit the idle slices, so the the next context
19615 +         will be scheduled as soon as possible.
19616 +
19617 +         This might improve interactivity and latency, but
19618 +         will also marginally increase scheduling overhead.
19619 +
19620 +choice
19621 +       prompt  "Persistent Inode Tagging"
19622 +       default TAGGING_ID24
19623 +       help
19624 +         This adds persistent context information to filesystems
19625 +         mounted with the tagxid option. Tagging is a requirement
19626 +         for per-context disk limits and per-context quota.
19627 +
19628 +
19629 +config TAGGING_NONE
19630 +       bool    "Disabled"
19631 +       help
19632 +         do not store per-context information in inodes.
19633 +
19634 +config TAGGING_UID16
19635 +       bool    "UID16/GID32"
19636 +       help
19637 +         reduces UID to 16 bit, but leaves GID at 32 bit.
19638 +
19639 +config TAGGING_GID16
19640 +       bool    "UID32/GID16"
19641 +       help
19642 +         reduces GID to 16 bit, but leaves UID at 32 bit.
19643 +
19644 +config TAGGING_ID24
19645 +       bool    "UID24/GID24"
19646 +       help
19647 +         uses the upper 8bit from UID and GID for XID tagging
19648 +         which leaves 24bit for UID/GID each, which should be
19649 +         more than sufficient for normal use.
19650 +
19651 +config TAGGING_INTERN
19652 +       bool    "UID32/GID32"
19653 +       help
19654 +         this uses otherwise reserved inode fields in the on
19655 +         disk representation, which limits the use to a few
19656 +         filesystems (currently ext2 and ext3)
19657 +
19658 +endchoice
19659 +
19660 +config TAG_NFSD
19661 +       bool    "Tag NFSD User Auth and Files"
19662 +       default n
19663 +       help
19664 +         Enable this if you do want the in-kernel NFS
19665 +         Server to use the tagging specified above.
19666 +         (will require patched clients too)
19667 +
19668 +config VSERVER_PRIVACY
19669 +       bool    "Honor Privacy Aspects of Guests"
19670 +       default n
19671 +       help
19672 +         When enabled, most context checks will disallow
19673 +         access to structures assigned to a specific context,
19674 +         like ptys or loop devices.
19675 +
19676 +config VSERVER_CONTEXTS
19677 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
19678 +       range 1 65533
19679 +       default "768"   if 64BIT
19680 +       default "256"
19681 +       help
19682 +         This setting will optimize certain data structures
19683 +         and memory allocations according to the expected
19684 +         maximum.
19685 +
19686 +         note: this is not a strict upper limit.
19687 +
19688 +config VSERVER_WARN
19689 +       bool    "VServer Warnings"
19690 +       default y
19691 +       help
19692 +         This enables various runtime warnings, which will
19693 +         notify about potential manipulation attempts or
19694 +         resource shortage. It is generally considered to
19695 +         be a good idea to have that enabled.
19696 +
19697 +config VSERVER_DEBUG
19698 +       bool    "VServer Debugging Code"
19699 +       default n
19700 +       help
19701 +         Set this to yes if you want to be able to activate
19702 +         debugging output at runtime. It adds a very small
19703 +         overhead to all vserver related functions and
19704 +         increases the kernel size by about 20k.
19705 +
19706 +config VSERVER_HISTORY
19707 +       bool    "VServer History Tracing"
19708 +       depends on VSERVER_DEBUG
19709 +       default n
19710 +       help
19711 +         Set this to yes if you want to record the history of
19712 +         linux-vserver activities, so they can be replayed in
19713 +         the event of a kernel panic or oops.
19714 +
19715 +config VSERVER_HISTORY_SIZE
19716 +       int     "Per-CPU History Size (32-65536)"
19717 +       depends on VSERVER_HISTORY
19718 +       range 32 65536
19719 +       default 64
19720 +       help
19721 +         This allows you to specify the number of entries in
19722 +         the per-CPU history buffer.
19723 +
19724 +config VSERVER_MONITOR
19725 +       bool    "VServer Scheduling Monitor"
19726 +       depends on VSERVER_DEBUG
19727 +       default n
19728 +       help
19729 +         Set this to yes if you want to record the scheduling
19730 +         decisions, so that they can be relayed to userspace
19731 +         for detailed analysis.
19732 +
19733 +config VSERVER_MONITOR_SIZE
19734 +       int     "Per-CPU Monitor Queue Size (32-65536)"
19735 +       depends on VSERVER_MONITOR
19736 +       range 32 65536
19737 +       default 1024
19738 +       help
19739 +         This allows you to specify the number of entries in
19740 +         the per-CPU scheduling monitor buffer.
19741 +
19742 +config VSERVER_MONITOR_SYNC
19743 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
19744 +       depends on VSERVER_MONITOR
19745 +       range 0 65536
19746 +       default 256
19747 +       help
19748 +         This allows you to specify the interval in ticks
19749 +         when a time sync entry is inserted.
19750 +
19751 +endmenu
19752 +
19753 +
19754 +config VSERVER
19755 +       bool
19756 +       default y
19757 +       select UTS_NS
19758 +       select SYSVIPC
19759 +       select IPC_NS
19760 +
19761 +config VSERVER_SECURITY
19762 +       bool
19763 +       depends on SECURITY
19764 +       default y
19765 +       select SECURITY_CAPABILITIES
19766 +
19767 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/Makefile linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Makefile
19768 --- linux-2.6.22.10/kernel/vserver/Makefile     1970-01-01 01:00:00 +0100
19769 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/Makefile  2007-10-11 01:10:22 +0200
19770 @@ -0,0 +1,18 @@
19771 +#
19772 +# Makefile for the Linux vserver routines.
19773 +#
19774 +
19775 +
19776 +obj-y          += vserver.o
19777 +
19778 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
19779 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
19780 +                  dlimit.o tag.o
19781 +
19782 +vserver-$(CONFIG_INET) += inet.o
19783 +vserver-$(CONFIG_PROC_FS) += proc.o
19784 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
19785 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
19786 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
19787 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
19788 +
19789 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
19790 --- linux-2.6.22.10/kernel/vserver/cacct.c      1970-01-01 01:00:00 +0100
19791 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct.c   2007-08-15 21:54:31 +0200
19792 @@ -0,0 +1,42 @@
19793 +/*
19794 + *  linux/kernel/vserver/cacct.c
19795 + *
19796 + *  Virtual Server: Context Accounting
19797 + *
19798 + *  Copyright (C) 2006-2007 Herbert Pötzl
19799 + *
19800 + *  V0.01  added accounting stats
19801 + *
19802 + */
19803 +
19804 +#include <linux/types.h>
19805 +#include <linux/vs_context.h>
19806 +#include <linux/vserver/cacct_cmd.h>
19807 +#include <linux/vserver/cacct_int.h>
19808 +
19809 +#include <asm/errno.h>
19810 +#include <asm/uaccess.h>
19811 +
19812 +
19813 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
19814 +{
19815 +       struct vcmd_sock_stat_v0 vc_data;
19816 +       int j, field;
19817 +
19818 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19819 +               return -EFAULT;
19820 +
19821 +       field = vc_data.field;
19822 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
19823 +               return -EINVAL;
19824 +
19825 +       for (j = 0; j < 3; j++) {
19826 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
19827 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
19828 +       }
19829 +
19830 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19831 +               return -EFAULT;
19832 +       return 0;
19833 +}
19834 +
19835 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
19836 --- linux-2.6.22.10/kernel/vserver/cacct_init.h 1970-01-01 01:00:00 +0100
19837 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct_init.h      2007-08-05 20:53:13 +0200
19838 @@ -0,0 +1,25 @@
19839 +
19840 +
19841 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
19842 +{
19843 +       int i, j;
19844 +
19845 +
19846 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19847 +               for (j = 0; j < 3; j++) {
19848 +                       atomic_set(&cacct->sock[i][j].count, 0);
19849 +                       atomic_set(&cacct->sock[i][j].total, 0);
19850 +               }
19851 +       }
19852 +       for (i = 0; i < 8; i++)
19853 +               atomic_set(&cacct->slab[i], 0);
19854 +       for (i = 0; i < 5; i++)
19855 +               for (j = 0; j < 4; j++)
19856 +                       atomic_set(&cacct->page[i][j], 0);
19857 +}
19858 +
19859 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
19860 +{
19861 +       return;
19862 +}
19863 +
19864 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
19865 --- linux-2.6.22.10/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00 +0100
19866 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cacct_proc.h      2007-08-05 20:53:13 +0200
19867 @@ -0,0 +1,53 @@
19868 +#ifndef _VX_CACCT_PROC_H
19869 +#define _VX_CACCT_PROC_H
19870 +
19871 +#include <linux/vserver/cacct_int.h>
19872 +
19873 +
19874 +#define VX_SOCKA_TOP   \
19875 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
19876 +
19877 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
19878 +{
19879 +       int i, j, length = 0;
19880 +       static char *type[VXA_SOCK_SIZE] = {
19881 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
19882 +       };
19883 +
19884 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
19885 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
19886 +               length += sprintf(buffer + length, "%s:", type[i]);
19887 +               for (j = 0; j < 3; j++) {
19888 +                       length += sprintf(buffer + length,
19889 +                               "\t%10lu/%-10lu",
19890 +                               vx_sock_count(cacct, i, j),
19891 +                               vx_sock_total(cacct, i, j));
19892 +               }
19893 +               buffer[length++] = '\n';
19894 +       }
19895 +
19896 +       length += sprintf(buffer + length, "\n");
19897 +       length += sprintf(buffer + length,
19898 +               "slab:\t %8u %8u %8u %8u\n",
19899 +               atomic_read(&cacct->slab[1]),
19900 +               atomic_read(&cacct->slab[4]),
19901 +               atomic_read(&cacct->slab[0]),
19902 +               atomic_read(&cacct->slab[2]));
19903 +
19904 +       length += sprintf(buffer + length, "\n");
19905 +       for (i = 0; i < 5; i++) {
19906 +               length += sprintf(buffer + length,
19907 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
19908 +                       atomic_read(&cacct->page[i][0]),
19909 +                       atomic_read(&cacct->page[i][1]),
19910 +                       atomic_read(&cacct->page[i][2]),
19911 +                       atomic_read(&cacct->page[i][3]),
19912 +                       atomic_read(&cacct->page[i][4]),
19913 +                       atomic_read(&cacct->page[i][5]),
19914 +                       atomic_read(&cacct->page[i][6]),
19915 +                       atomic_read(&cacct->page[i][7]));
19916 +       }
19917 +       return length;
19918 +}
19919 +
19920 +#endif /* _VX_CACCT_PROC_H */
19921 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
19922 --- linux-2.6.22.10/kernel/vserver/context.c    1970-01-01 01:00:00 +0100
19923 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/context.c 2007-10-05 14:54:36 +0200
19924 @@ -0,0 +1,966 @@
19925 +/*
19926 + *  linux/kernel/vserver/context.c
19927 + *
19928 + *  Virtual Server: Context Support
19929 + *
19930 + *  Copyright (C) 2003-2007  Herbert Pötzl
19931 + *
19932 + *  V0.01  context helper
19933 + *  V0.02  vx_ctx_kill syscall command
19934 + *  V0.03  replaced context_info calls
19935 + *  V0.04  redesign of struct (de)alloc
19936 + *  V0.05  rlimit basic implementation
19937 + *  V0.06  task_xid and info commands
19938 + *  V0.07  context flags and caps
19939 + *  V0.08  switch to RCU based hash
19940 + *  V0.09  revert to non RCU for now
19941 + *  V0.10  and back to working RCU hash
19942 + *  V0.11  and back to locking again
19943 + *  V0.12  referenced context store
19944 + *  V0.13  separate per cpu data
19945 + *  V0.14  changed vcmds to vxi arg
19946 + *  V0.15  added context stat
19947 + *  V0.16  have __create claim() the vxi
19948 + *  V0.17  removed older and legacy stuff
19949 + *
19950 + */
19951 +
19952 +#include <linux/slab.h>
19953 +#include <linux/types.h>
19954 +#include <linux/pid_namespace.h>
19955 +
19956 +#include <linux/vserver/context.h>
19957 +#include <linux/vserver/network.h>
19958 +#include <linux/vserver/debug.h>
19959 +#include <linux/vserver/limit.h>
19960 +#include <linux/vserver/limit_int.h>
19961 +#include <linux/vserver/space.h>
19962 +
19963 +#include <linux/vs_context.h>
19964 +#include <linux/vs_limit.h>
19965 +#include <linux/vserver/context_cmd.h>
19966 +
19967 +#include "cvirt_init.h"
19968 +#include "cacct_init.h"
19969 +#include "limit_init.h"
19970 +#include "sched_init.h"
19971 +
19972 +
19973 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
19974 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
19975 +
19976 +
19977 +/*     now inactive context structures */
19978 +
19979 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
19980 +
19981 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
19982 +
19983 +
19984 +/*     __alloc_vx_info()
19985 +
19986 +       * allocate an initialized vx_info struct
19987 +       * doesn't make it visible (hash)                        */
19988 +
19989 +static struct vx_info *__alloc_vx_info(xid_t xid)
19990 +{
19991 +       struct vx_info *new = NULL;
19992 +       int cpu;
19993 +
19994 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
19995 +
19996 +       /* would this benefit from a slab cache? */
19997 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
19998 +       if (!new)
19999 +               return 0;
20000 +
20001 +       memset(new, 0, sizeof(struct vx_info));
20002 +#ifdef CONFIG_SMP
20003 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
20004 +       if (!new->ptr_pc)
20005 +               goto error;
20006 +#endif
20007 +       new->vx_id = xid;
20008 +       INIT_HLIST_NODE(&new->vx_hlist);
20009 +       atomic_set(&new->vx_usecnt, 0);
20010 +       atomic_set(&new->vx_tasks, 0);
20011 +       new->vx_parent = NULL;
20012 +       new->vx_state = 0;
20013 +       init_waitqueue_head(&new->vx_wait);
20014 +
20015 +       /* prepare reaper */
20016 +       get_task_struct(init_pid_ns.child_reaper);
20017 +       new->vx_reaper = init_pid_ns.child_reaper;
20018 +       new->vx_badness_bias = 0;
20019 +
20020 +       /* rest of init goes here */
20021 +       vx_info_init_limit(&new->limit);
20022 +       vx_info_init_sched(&new->sched);
20023 +       vx_info_init_cvirt(&new->cvirt);
20024 +       vx_info_init_cacct(&new->cacct);
20025 +
20026 +       /* per cpu data structures */
20027 +       for_each_possible_cpu(cpu) {
20028 +               vx_info_init_sched_pc(
20029 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
20030 +               vx_info_init_cvirt_pc(
20031 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
20032 +       }
20033 +
20034 +       new->vx_flags = VXF_INIT_SET;
20035 +       new->vx_bcaps = CAP_INIT_EFF_SET;
20036 +       new->vx_ccaps = 0;
20037 +       new->vx_cap_bset = cap_bset;
20038 +
20039 +       new->reboot_cmd = 0;
20040 +       new->exit_code = 0;
20041 +
20042 +       new->vx_nsproxy = copy_nsproxy(current->nsproxy);
20043 +
20044 +       vxdprintk(VXD_CBIT(xid, 0),
20045 +               "alloc_vx_info(%d) = %p", xid, new);
20046 +       vxh_alloc_vx_info(new);
20047 +       atomic_inc(&vx_global_ctotal);
20048 +       return new;
20049 +#ifdef CONFIG_SMP
20050 +error:
20051 +       kfree(new);
20052 +       return 0;
20053 +#endif
20054 +}
20055 +
20056 +/*     __dealloc_vx_info()
20057 +
20058 +       * final disposal of vx_info                             */
20059 +
20060 +static void __dealloc_vx_info(struct vx_info *vxi)
20061 +{
20062 +       int cpu;
20063 +
20064 +       vxdprintk(VXD_CBIT(xid, 0),
20065 +               "dealloc_vx_info(%p)", vxi);
20066 +       vxh_dealloc_vx_info(vxi);
20067 +
20068 +       vxi->vx_id = -1;
20069 +
20070 +       vx_info_exit_limit(&vxi->limit);
20071 +       vx_info_exit_sched(&vxi->sched);
20072 +       vx_info_exit_cvirt(&vxi->cvirt);
20073 +       vx_info_exit_cacct(&vxi->cacct);
20074 +
20075 +       for_each_possible_cpu(cpu) {
20076 +               vx_info_exit_sched_pc(
20077 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
20078 +               vx_info_exit_cvirt_pc(
20079 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
20080 +       }
20081 +
20082 +       vxi->vx_state |= VXS_RELEASED;
20083 +
20084 +#ifdef CONFIG_SMP
20085 +       free_percpu(vxi->ptr_pc);
20086 +#endif
20087 +       kfree(vxi);
20088 +       atomic_dec(&vx_global_ctotal);
20089 +}
20090 +
20091 +static void __shutdown_vx_info(struct vx_info *vxi)
20092 +{
20093 +       struct nsproxy *nsproxy;
20094 +       struct fs_struct *fs;
20095 +
20096 +       might_sleep();
20097 +
20098 +       vxi->vx_state |= VXS_SHUTDOWN;
20099 +       vs_state_change(vxi, VSC_SHUTDOWN);
20100 +
20101 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
20102 +       fs = xchg(&vxi->vx_fs, NULL);
20103 +
20104 +       if (nsproxy)
20105 +               put_nsproxy(nsproxy);
20106 +       if (fs)
20107 +               put_fs_struct(fs);
20108 +}
20109 +
20110 +/* exported stuff */
20111 +
20112 +void free_vx_info(struct vx_info *vxi)
20113 +{
20114 +       unsigned long flags;
20115 +
20116 +       /* check for reference counts first */
20117 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
20118 +       BUG_ON(atomic_read(&vxi->vx_tasks));
20119 +
20120 +       /* context must not be hashed */
20121 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
20122 +
20123 +       /* context shutdown is mandatory */
20124 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
20125 +
20126 +       BUG_ON(vxi->vx_nsproxy);
20127 +       BUG_ON(vxi->vx_fs);
20128 +
20129 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
20130 +       hlist_del(&vxi->vx_hlist);
20131 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
20132 +
20133 +       __dealloc_vx_info(vxi);
20134 +}
20135 +
20136 +
20137 +/*     hash table for vx_info hash */
20138 +
20139 +#define VX_HASH_SIZE   13
20140 +
20141 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
20142 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
20143 +
20144 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20145 +
20146 +
20147 +static inline unsigned int __hashval(xid_t xid)
20148 +{
20149 +       return (xid % VX_HASH_SIZE);
20150 +}
20151 +
20152 +
20153 +
20154 +/*     __hash_vx_info()
20155 +
20156 +       * add the vxi to the global hash table
20157 +       * requires the hash_lock to be held                     */
20158 +
20159 +static inline void __hash_vx_info(struct vx_info *vxi)
20160 +{
20161 +       struct hlist_head *head;
20162 +
20163 +       vxd_assert_lock(&vx_info_hash_lock);
20164 +       vxdprintk(VXD_CBIT(xid, 4),
20165 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
20166 +       vxh_hash_vx_info(vxi);
20167 +
20168 +       /* context must not be hashed */
20169 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
20170 +
20171 +       vxi->vx_state |= VXS_HASHED;
20172 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
20173 +       hlist_add_head(&vxi->vx_hlist, head);
20174 +       atomic_inc(&vx_global_cactive);
20175 +}
20176 +
20177 +/*     __unhash_vx_info()
20178 +
20179 +       * remove the vxi from the global hash table
20180 +       * requires the hash_lock to be held                     */
20181 +
20182 +static inline void __unhash_vx_info(struct vx_info *vxi)
20183 +{
20184 +       unsigned long flags;
20185 +
20186 +       vxd_assert_lock(&vx_info_hash_lock);
20187 +       vxdprintk(VXD_CBIT(xid, 4),
20188 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
20189 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
20190 +       vxh_unhash_vx_info(vxi);
20191 +
20192 +       /* context must be hashed */
20193 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
20194 +       /* but without tasks */
20195 +       BUG_ON(atomic_read(&vxi->vx_tasks));
20196 +
20197 +       vxi->vx_state &= ~VXS_HASHED;
20198 +       hlist_del_init(&vxi->vx_hlist);
20199 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
20200 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
20201 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
20202 +       atomic_dec(&vx_global_cactive);
20203 +}
20204 +
20205 +
20206 +/*     __lookup_vx_info()
20207 +
20208 +       * requires the hash_lock to be held
20209 +       * doesn't increment the vx_refcnt                       */
20210 +
20211 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
20212 +{
20213 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
20214 +       struct hlist_node *pos;
20215 +       struct vx_info *vxi;
20216 +
20217 +       vxd_assert_lock(&vx_info_hash_lock);
20218 +       hlist_for_each(pos, head) {
20219 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20220 +
20221 +               if (vxi->vx_id == xid)
20222 +                       goto found;
20223 +       }
20224 +       vxi = NULL;
20225 +found:
20226 +       vxdprintk(VXD_CBIT(xid, 0),
20227 +               "__lookup_vx_info(#%u): %p[#%u]",
20228 +               xid, vxi, vxi ? vxi->vx_id : 0);
20229 +       vxh_lookup_vx_info(vxi, xid);
20230 +       return vxi;
20231 +}
20232 +
20233 +
20234 +/*     __create_vx_info()
20235 +
20236 +       * create the requested context
20237 +       * get(), claim() and hash it                            */
20238 +
20239 +static struct vx_info *__create_vx_info(int id)
20240 +{
20241 +       struct vx_info *new, *vxi = NULL;
20242 +
20243 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
20244 +
20245 +       if (!(new = __alloc_vx_info(id)))
20246 +               return ERR_PTR(-ENOMEM);
20247 +
20248 +       /* required to make dynamic xids unique */
20249 +       spin_lock(&vx_info_hash_lock);
20250 +
20251 +       /* static context requested */
20252 +       if ((vxi = __lookup_vx_info(id))) {
20253 +               vxdprintk(VXD_CBIT(xid, 0),
20254 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
20255 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20256 +                       vxi = ERR_PTR(-EBUSY);
20257 +               else
20258 +                       vxi = ERR_PTR(-EEXIST);
20259 +               goto out_unlock;
20260 +       }
20261 +       /* new context */
20262 +       vxdprintk(VXD_CBIT(xid, 0),
20263 +               "create_vx_info(%d) = %p (new)", id, new);
20264 +       claim_vx_info(new, NULL);
20265 +       __hash_vx_info(get_vx_info(new));
20266 +       vxi = new, new = NULL;
20267 +
20268 +out_unlock:
20269 +       spin_unlock(&vx_info_hash_lock);
20270 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
20271 +       if (new)
20272 +               __dealloc_vx_info(new);
20273 +       return vxi;
20274 +}
20275 +
20276 +
20277 +/*     exported stuff                                          */
20278 +
20279 +
20280 +void unhash_vx_info(struct vx_info *vxi)
20281 +{
20282 +       __shutdown_vx_info(vxi);
20283 +       spin_lock(&vx_info_hash_lock);
20284 +       __unhash_vx_info(vxi);
20285 +       spin_unlock(&vx_info_hash_lock);
20286 +       __wakeup_vx_info(vxi);
20287 +}
20288 +
20289 +
20290 +/*     lookup_vx_info()
20291 +
20292 +       * search for a vx_info and get() it
20293 +       * negative id means current                             */
20294 +
20295 +struct vx_info *lookup_vx_info(int id)
20296 +{
20297 +       struct vx_info *vxi = NULL;
20298 +
20299 +       if (id < 0) {
20300 +               vxi = get_vx_info(current->vx_info);
20301 +       } else if (id > 1) {
20302 +               spin_lock(&vx_info_hash_lock);
20303 +               vxi = get_vx_info(__lookup_vx_info(id));
20304 +               spin_unlock(&vx_info_hash_lock);
20305 +       }
20306 +       return vxi;
20307 +}
20308 +
20309 +/*     xid_is_hashed()
20310 +
20311 +       * verify that xid is still hashed                       */
20312 +
20313 +int xid_is_hashed(xid_t xid)
20314 +{
20315 +       int hashed;
20316 +
20317 +       spin_lock(&vx_info_hash_lock);
20318 +       hashed = (__lookup_vx_info(xid) != NULL);
20319 +       spin_unlock(&vx_info_hash_lock);
20320 +       return hashed;
20321 +}
20322 +
20323 +#ifdef CONFIG_PROC_FS
20324 +
20325 +/*     get_xid_list()
20326 +
20327 +       * get a subset of hashed xids for proc
20328 +       * assumes size is at least one                          */
20329 +
20330 +int get_xid_list(int index, unsigned int *xids, int size)
20331 +{
20332 +       int hindex, nr_xids = 0;
20333 +
20334 +       /* only show current and children */
20335 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
20336 +               if (index > 0)
20337 +                       return 0;
20338 +               xids[nr_xids] = vx_current_xid();
20339 +               return 1;
20340 +       }
20341 +
20342 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
20343 +               struct hlist_head *head = &vx_info_hash[hindex];
20344 +               struct hlist_node *pos;
20345 +
20346 +               spin_lock(&vx_info_hash_lock);
20347 +               hlist_for_each(pos, head) {
20348 +                       struct vx_info *vxi;
20349 +
20350 +                       if (--index > 0)
20351 +                               continue;
20352 +
20353 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
20354 +                       xids[nr_xids] = vxi->vx_id;
20355 +                       if (++nr_xids >= size) {
20356 +                               spin_unlock(&vx_info_hash_lock);
20357 +                               goto out;
20358 +                       }
20359 +               }
20360 +               /* keep the lock time short */
20361 +               spin_unlock(&vx_info_hash_lock);
20362 +       }
20363 +out:
20364 +       return nr_xids;
20365 +}
20366 +#endif
20367 +
20368 +#ifdef CONFIG_VSERVER_DEBUG
20369 +
20370 +void   dump_vx_info_inactive(int level)
20371 +{
20372 +       struct hlist_node *entry, *next;
20373 +
20374 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
20375 +               struct vx_info *vxi =
20376 +                       list_entry(entry, struct vx_info, vx_hlist);
20377 +
20378 +               dump_vx_info(vxi, level);
20379 +       }
20380 +}
20381 +
20382 +#endif
20383 +
20384 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
20385 +{
20386 +       struct user_struct *new_user, *old_user;
20387 +
20388 +       if (!p || !vxi)
20389 +               BUG();
20390 +
20391 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
20392 +               return -EACCES;
20393 +
20394 +       new_user = alloc_uid(vxi->vx_id, p->uid);
20395 +       if (!new_user)
20396 +               return -ENOMEM;
20397 +
20398 +       old_user = p->user;
20399 +       if (new_user != old_user) {
20400 +               atomic_inc(&new_user->processes);
20401 +               atomic_dec(&old_user->processes);
20402 +               p->user = new_user;
20403 +       }
20404 +       free_uid(old_user);
20405 +       return 0;
20406 +}
20407 +
20408 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
20409 +{
20410 +       p->cap_effective &= vxi->vx_cap_bset;
20411 +       p->cap_inheritable &= vxi->vx_cap_bset;
20412 +       p->cap_permitted &= vxi->vx_cap_bset;
20413 +}
20414 +
20415 +
20416 +#include <linux/file.h>
20417 +
20418 +static int vx_openfd_task(struct task_struct *tsk)
20419 +{
20420 +       struct files_struct *files = tsk->files;
20421 +       struct fdtable *fdt;
20422 +       const unsigned long *bptr;
20423 +       int count, total;
20424 +
20425 +       /* no rcu_read_lock() because of spin_lock() */
20426 +       spin_lock(&files->file_lock);
20427 +       fdt = files_fdtable(files);
20428 +       bptr = fdt->open_fds->fds_bits;
20429 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
20430 +       for (total = 0; count > 0; count--) {
20431 +               if (*bptr)
20432 +                       total += hweight_long(*bptr);
20433 +               bptr++;
20434 +       }
20435 +       spin_unlock(&files->file_lock);
20436 +       return total;
20437 +}
20438 +
20439 +
20440 +/*     for *space compatibility */
20441 +
20442 +asmlinkage long sys_unshare(unsigned long);
20443 +
20444 +/*
20445 + *     migrate task to new context
20446 + *     gets vxi, puts old_vxi on change
20447 + *     optionally unshares namespaces (hack)
20448 + */
20449 +
20450 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
20451 +{
20452 +       struct vx_info *old_vxi;
20453 +       int ret = 0;
20454 +
20455 +       if (!p || !vxi)
20456 +               BUG();
20457 +
20458 +       vxdprintk(VXD_CBIT(xid, 5),
20459 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
20460 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
20461 +
20462 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
20463 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
20464 +               return -EACCES;
20465 +
20466 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
20467 +               return -EFAULT;
20468 +
20469 +       old_vxi = task_get_vx_info(p);
20470 +       if (old_vxi == vxi)
20471 +               goto out;
20472 +
20473 +       if (!(ret = vx_migrate_user(p, vxi))) {
20474 +               int openfd;
20475 +
20476 +               task_lock(p);
20477 +               openfd = vx_openfd_task(p);
20478 +
20479 +               if (old_vxi) {
20480 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
20481 +                       atomic_dec(&old_vxi->cvirt.nr_running);
20482 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
20483 +                       /* FIXME: what about the struct files here? */
20484 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
20485 +                       /* account for the executable */
20486 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
20487 +               }
20488 +               atomic_inc(&vxi->cvirt.nr_threads);
20489 +               atomic_inc(&vxi->cvirt.nr_running);
20490 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
20491 +               /* FIXME: what about the struct files here? */
20492 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
20493 +               /* account for the executable */
20494 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
20495 +
20496 +               if (old_vxi) {
20497 +                       release_vx_info(old_vxi, p);
20498 +                       clr_vx_info(&p->vx_info);
20499 +               }
20500 +               claim_vx_info(vxi, p);
20501 +               set_vx_info(&p->vx_info, vxi);
20502 +               p->xid = vxi->vx_id;
20503 +
20504 +               vxdprintk(VXD_CBIT(xid, 5),
20505 +                       "moved task %p into vxi:%p[#%d]",
20506 +                       p, vxi, vxi->vx_id);
20507 +
20508 +               vx_mask_cap_bset(vxi, p);
20509 +               task_unlock(p);
20510 +
20511 +               /* hack for *spaces to provide compatibility */
20512 +               if (unshare) {
20513 +                       struct nsproxy *old_nsp, *new_nsp;
20514 +
20515 +                       ret = unshare_nsproxy_namespaces(
20516 +                               CLONE_NEWUTS | CLONE_NEWIPC,
20517 +                               &new_nsp, NULL);
20518 +                       if (ret)
20519 +                               goto out;
20520 +
20521 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
20522 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC);
20523 +                       put_nsproxy(old_nsp);
20524 +               }
20525 +       }
20526 +out:
20527 +       put_vx_info(old_vxi);
20528 +       return ret;
20529 +}
20530 +
20531 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
20532 +{
20533 +       struct task_struct *old_reaper;
20534 +
20535 +       if (!vxi)
20536 +               return -EINVAL;
20537 +
20538 +       vxdprintk(VXD_CBIT(xid, 6),
20539 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
20540 +               vxi, vxi->vx_id, p, p->xid, p->pid);
20541 +
20542 +       old_reaper = vxi->vx_reaper;
20543 +       if (old_reaper == p)
20544 +               return 0;
20545 +
20546 +       /* set new child reaper */
20547 +       get_task_struct(p);
20548 +       vxi->vx_reaper = p;
20549 +       put_task_struct(old_reaper);
20550 +       return 0;
20551 +}
20552 +
20553 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
20554 +{
20555 +       if (!vxi)
20556 +               return -EINVAL;
20557 +
20558 +       vxdprintk(VXD_CBIT(xid, 6),
20559 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
20560 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20561 +
20562 +       vxi->vx_flags &= ~VXF_STATE_INIT;
20563 +       vxi->vx_initpid = p->tgid;
20564 +       return 0;
20565 +}
20566 +
20567 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
20568 +{
20569 +       vxdprintk(VXD_CBIT(xid, 6),
20570 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
20571 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
20572 +
20573 +       vxi->exit_code = code;
20574 +       vxi->vx_initpid = 0;
20575 +}
20576 +
20577 +
20578 +void vx_set_persistent(struct vx_info *vxi)
20579 +{
20580 +       vxdprintk(VXD_CBIT(xid, 6),
20581 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
20582 +
20583 +       get_vx_info(vxi);
20584 +       claim_vx_info(vxi, NULL);
20585 +}
20586 +
20587 +void vx_clear_persistent(struct vx_info *vxi)
20588 +{
20589 +       vxdprintk(VXD_CBIT(xid, 6),
20590 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
20591 +
20592 +       release_vx_info(vxi, NULL);
20593 +       put_vx_info(vxi);
20594 +}
20595 +
20596 +void vx_update_persistent(struct vx_info *vxi)
20597 +{
20598 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
20599 +               vx_set_persistent(vxi);
20600 +       else
20601 +               vx_clear_persistent(vxi);
20602 +}
20603 +
20604 +
20605 +/*     task must be current or locked          */
20606 +
20607 +void   exit_vx_info(struct task_struct *p, int code)
20608 +{
20609 +       struct vx_info *vxi = p->vx_info;
20610 +
20611 +       if (vxi) {
20612 +               atomic_dec(&vxi->cvirt.nr_threads);
20613 +               vx_nproc_dec(p);
20614 +
20615 +               vxi->exit_code = code;
20616 +               release_vx_info(vxi, p);
20617 +       }
20618 +}
20619 +
20620 +void   exit_vx_info_early(struct task_struct *p, int code)
20621 +{
20622 +       struct vx_info *vxi = p->vx_info;
20623 +
20624 +       if (vxi) {
20625 +               if (vxi->vx_initpid == p->tgid)
20626 +                       vx_exit_init(vxi, p, code);
20627 +               if (vxi->vx_reaper == p)
20628 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
20629 +       }
20630 +}
20631 +
20632 +
20633 +/* vserver syscall commands below here */
20634 +
20635 +/* taks xid and vx_info functions */
20636 +
20637 +#include <asm/uaccess.h>
20638 +
20639 +
20640 +int vc_task_xid(uint32_t id)
20641 +{
20642 +       xid_t xid;
20643 +
20644 +       if (id) {
20645 +               struct task_struct *tsk;
20646 +
20647 +               read_lock(&tasklist_lock);
20648 +               tsk = find_task_by_real_pid(id);
20649 +               xid = (tsk) ? tsk->xid : -ESRCH;
20650 +               read_unlock(&tasklist_lock);
20651 +       } else
20652 +               xid = vx_current_xid();
20653 +       return xid;
20654 +}
20655 +
20656 +
20657 +int vc_vx_info(struct vx_info *vxi, void __user *data)
20658 +{
20659 +       struct vcmd_vx_info_v0 vc_data;
20660 +
20661 +       vc_data.xid = vxi->vx_id;
20662 +       vc_data.initpid = vxi->vx_initpid;
20663 +
20664 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20665 +               return -EFAULT;
20666 +       return 0;
20667 +}
20668 +
20669 +
20670 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
20671 +{
20672 +       struct vcmd_ctx_stat_v0 vc_data;
20673 +
20674 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
20675 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
20676 +
20677 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20678 +               return -EFAULT;
20679 +       return 0;
20680 +}
20681 +
20682 +
20683 +/* context functions */
20684 +
20685 +int vc_ctx_create(uint32_t xid, void __user *data)
20686 +{
20687 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
20688 +       struct vx_info *new_vxi;
20689 +       int ret;
20690 +
20691 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20692 +               return -EFAULT;
20693 +
20694 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
20695 +               return -EINVAL;
20696 +
20697 +       new_vxi = __create_vx_info(xid);
20698 +       if (IS_ERR(new_vxi))
20699 +               return PTR_ERR(new_vxi);
20700 +
20701 +       /* initial flags */
20702 +       new_vxi->vx_flags = vc_data.flagword;
20703 +
20704 +       ret = -ENOEXEC;
20705 +       if (vs_state_change(new_vxi, VSC_STARTUP))
20706 +               goto out;
20707 +
20708 +       ret = vx_migrate_task(current, new_vxi, (!data));
20709 +       if (ret)
20710 +               goto out;
20711 +
20712 +       /* return context id on success */
20713 +       ret = new_vxi->vx_id;
20714 +
20715 +       /* get a reference for persistent contexts */
20716 +       if ((vc_data.flagword & VXF_PERSISTENT))
20717 +               vx_set_persistent(new_vxi);
20718 +out:
20719 +       release_vx_info(new_vxi, NULL);
20720 +       put_vx_info(new_vxi);
20721 +       return ret;
20722 +}
20723 +
20724 +
20725 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
20726 +{
20727 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
20728 +       int ret;
20729 +
20730 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20731 +               return -EFAULT;
20732 +
20733 +       ret = vx_migrate_task(current, vxi, 0);
20734 +       if (ret)
20735 +               return ret;
20736 +       if (vc_data.flagword & VXM_SET_INIT)
20737 +               ret = vx_set_init(vxi, current);
20738 +       if (ret)
20739 +               return ret;
20740 +       if (vc_data.flagword & VXM_SET_REAPER)
20741 +               ret = vx_set_reaper(vxi, current);
20742 +       return ret;
20743 +}
20744 +
20745 +
20746 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
20747 +{
20748 +       struct vcmd_ctx_flags_v0 vc_data;
20749 +
20750 +       vc_data.flagword = vxi->vx_flags;
20751 +
20752 +       /* special STATE flag handling */
20753 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
20754 +
20755 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20756 +               return -EFAULT;
20757 +       return 0;
20758 +}
20759 +
20760 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
20761 +{
20762 +       struct vcmd_ctx_flags_v0 vc_data;
20763 +       uint64_t mask, trigger;
20764 +
20765 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20766 +               return -EFAULT;
20767 +
20768 +       /* special STATE flag handling */
20769 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
20770 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
20771 +
20772 +       if (vxi == current->vx_info) {
20773 +               if (trigger & VXF_STATE_SETUP)
20774 +                       vx_mask_cap_bset(vxi, current);
20775 +               if (trigger & VXF_STATE_INIT) {
20776 +                       int ret;
20777 +
20778 +                       ret = vx_set_init(vxi, current);
20779 +                       if (ret)
20780 +                               return ret;
20781 +                       ret = vx_set_reaper(vxi, current);
20782 +                       if (ret)
20783 +                               return ret;
20784 +               }
20785 +       }
20786 +
20787 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
20788 +               vc_data.flagword, mask);
20789 +       if (trigger & VXF_PERSISTENT)
20790 +               vx_update_persistent(vxi);
20791 +
20792 +       return 0;
20793 +}
20794 +
20795 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
20796 +{
20797 +       if (bcaps)
20798 +               *bcaps = vxi->vx_bcaps;
20799 +       if (ccaps)
20800 +               *ccaps = vxi->vx_ccaps;
20801 +
20802 +       return 0;
20803 +}
20804 +
20805 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
20806 +{
20807 +       struct vcmd_ctx_caps_v1 vc_data;
20808 +       int ret;
20809 +
20810 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
20811 +       if (ret)
20812 +               return ret;
20813 +       vc_data.cmask = ~0ULL;
20814 +
20815 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20816 +               return -EFAULT;
20817 +       return 0;
20818 +}
20819 +
20820 +static int do_set_caps(struct vx_info *vxi,
20821 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
20822 +{
20823 +       vxi->vx_bcaps = vs_mask_flags(vxi->vx_bcaps, bcaps, bmask);
20824 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
20825 +
20826 +       return 0;
20827 +}
20828 +
20829 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
20830 +{
20831 +       struct vcmd_ctx_caps_v1 vc_data;
20832 +
20833 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20834 +               return -EFAULT;
20835 +
20836 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
20837 +}
20838 +
20839 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
20840 +{
20841 +       struct vcmd_bcaps vc_data;
20842 +       int ret;
20843 +
20844 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
20845 +       if (ret)
20846 +               return ret;
20847 +       vc_data.bmask = ~0ULL;
20848 +
20849 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20850 +               return -EFAULT;
20851 +       return 0;
20852 +}
20853 +
20854 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
20855 +{
20856 +       struct vcmd_bcaps vc_data;
20857 +
20858 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20859 +               return -EFAULT;
20860 +
20861 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
20862 +}
20863 +
20864 +
20865 +int vc_get_badness(struct vx_info *vxi, void __user *data)
20866 +{
20867 +       struct vcmd_badness_v0 vc_data;
20868 +
20869 +       vc_data.bias = vxi->vx_badness_bias;
20870 +
20871 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20872 +               return -EFAULT;
20873 +       return 0;
20874 +}
20875 +
20876 +int vc_set_badness(struct vx_info *vxi, void __user *data)
20877 +{
20878 +       struct vcmd_badness_v0 vc_data;
20879 +
20880 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20881 +               return -EFAULT;
20882 +
20883 +       vxi->vx_badness_bias = vc_data.bias;
20884 +       return 0;
20885 +}
20886 +
20887 +#include <linux/module.h>
20888 +
20889 +EXPORT_SYMBOL_GPL(free_vx_info);
20890 +
20891 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
20892 --- linux-2.6.22.10/kernel/vserver/cvirt.c      1970-01-01 01:00:00 +0100
20893 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt.c   2007-08-15 22:00:34 +0200
20894 @@ -0,0 +1,300 @@
20895 +/*
20896 + *  linux/kernel/vserver/cvirt.c
20897 + *
20898 + *  Virtual Server: Context Virtualization
20899 + *
20900 + *  Copyright (C) 2004-2007  Herbert Pötzl
20901 + *
20902 + *  V0.01  broken out from limit.c
20903 + *  V0.02  added utsname stuff
20904 + *  V0.03  changed vcmds to vxi arg
20905 + *
20906 + */
20907 +
20908 +#include <linux/types.h>
20909 +#include <linux/vs_cvirt.h>
20910 +#include <linux/vserver/switch.h>
20911 +#include <linux/vserver/cvirt_cmd.h>
20912 +
20913 +#include <asm/uaccess.h>
20914 +
20915 +
20916 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
20917 +{
20918 +       struct vx_info *vxi = current->vx_info;
20919 +
20920 +       set_normalized_timespec(uptime,
20921 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
20922 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
20923 +       if (!idle)
20924 +               return;
20925 +       set_normalized_timespec(idle,
20926 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
20927 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
20928 +       return;
20929 +}
20930 +
20931 +uint64_t vx_idle_jiffies(void)
20932 +{
20933 +       return init_task.utime + init_task.stime;
20934 +}
20935 +
20936 +
20937 +
20938 +static inline uint32_t __update_loadavg(uint32_t load,
20939 +       int wsize, int delta, int n)
20940 +{
20941 +       unsigned long long calc, prev;
20942 +
20943 +       /* just set it to n */
20944 +       if (unlikely(delta >= wsize))
20945 +               return (n << FSHIFT);
20946 +
20947 +       calc = delta * n;
20948 +       calc <<= FSHIFT;
20949 +       prev = (wsize - delta);
20950 +       prev *= load;
20951 +       calc += prev;
20952 +       do_div(calc, wsize);
20953 +       return calc;
20954 +}
20955 +
20956 +
20957 +void vx_update_load(struct vx_info *vxi)
20958 +{
20959 +       uint32_t now, last, delta;
20960 +       unsigned int nr_running, nr_uninterruptible;
20961 +       unsigned int total;
20962 +       unsigned long flags;
20963 +
20964 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
20965 +
20966 +       now = jiffies;
20967 +       last = vxi->cvirt.load_last;
20968 +       delta = now - last;
20969 +
20970 +       if (delta < 5*HZ)
20971 +               goto out;
20972 +
20973 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
20974 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
20975 +       total = nr_running + nr_uninterruptible;
20976 +
20977 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
20978 +               60*HZ, delta, total);
20979 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
20980 +               5*60*HZ, delta, total);
20981 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
20982 +               15*60*HZ, delta, total);
20983 +
20984 +       vxi->cvirt.load_last = now;
20985 +out:
20986 +       atomic_inc(&vxi->cvirt.load_updates);
20987 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
20988 +}
20989 +
20990 +
20991 +/*
20992 + * Commands to do_syslog:
20993 + *
20994 + *      0 -- Close the log.  Currently a NOP.
20995 + *      1 -- Open the log. Currently a NOP.
20996 + *      2 -- Read from the log.
20997 + *      3 -- Read all messages remaining in the ring buffer.
20998 + *      4 -- Read and clear all messages remaining in the ring buffer
20999 + *      5 -- Clear ring buffer.
21000 + *      6 -- Disable printk's to console
21001 + *      7 -- Enable printk's to console
21002 + *      8 -- Set level of messages printed to console
21003 + *      9 -- Return number of unread characters in the log buffer
21004 + *     10 -- Return size of the log buffer
21005 + */
21006 +int vx_do_syslog(int type, char __user *buf, int len)
21007 +{
21008 +       int error = 0;
21009 +       int do_clear = 0;
21010 +       struct vx_info *vxi = current->vx_info;
21011 +       struct _vx_syslog *log;
21012 +
21013 +       if (!vxi)
21014 +               return -EINVAL;
21015 +       log = &vxi->cvirt.syslog;
21016 +
21017 +       switch (type) {
21018 +       case 0:         /* Close log */
21019 +       case 1:         /* Open log */
21020 +               break;
21021 +       case 2:         /* Read from log */
21022 +               error = wait_event_interruptible(log->log_wait,
21023 +                       (log->log_start - log->log_end));
21024 +               if (error)
21025 +                       break;
21026 +               spin_lock_irq(&log->logbuf_lock);
21027 +               spin_unlock_irq(&log->logbuf_lock);
21028 +               break;
21029 +       case 4:         /* Read/clear last kernel messages */
21030 +               do_clear = 1;
21031 +               /* fall through */
21032 +       case 3:         /* Read last kernel messages */
21033 +               return 0;
21034 +
21035 +       case 5:         /* Clear ring buffer */
21036 +               return 0;
21037 +
21038 +       case 6:         /* Disable logging to console */
21039 +       case 7:         /* Enable logging to console */
21040 +       case 8:         /* Set level of messages printed to console */
21041 +               break;
21042 +
21043 +       case 9:         /* Number of chars in the log buffer */
21044 +               return 0;
21045 +       case 10:        /* Size of the log buffer */
21046 +               return 0;
21047 +       default:
21048 +               error = -EINVAL;
21049 +               break;
21050 +       }
21051 +       return error;
21052 +}
21053 +
21054 +
21055 +/* virtual host info names */
21056 +
21057 +static char *vx_vhi_name(struct vx_info *vxi, int id)
21058 +{
21059 +       struct nsproxy *nsproxy;
21060 +       struct uts_namespace *uts;
21061 +
21062 +
21063 +       if (id == VHIN_CONTEXT)
21064 +               return vxi->vx_name;
21065 +
21066 +       nsproxy = vxi->vx_nsproxy;
21067 +       if (!nsproxy)
21068 +               return NULL;
21069 +
21070 +       uts = nsproxy->uts_ns;
21071 +       if (!uts)
21072 +               return NULL;
21073 +
21074 +       switch (id) {
21075 +       case VHIN_SYSNAME:
21076 +               return uts->name.sysname;
21077 +       case VHIN_NODENAME:
21078 +               return uts->name.nodename;
21079 +       case VHIN_RELEASE:
21080 +               return uts->name.release;
21081 +       case VHIN_VERSION:
21082 +               return uts->name.version;
21083 +       case VHIN_MACHINE:
21084 +               return uts->name.machine;
21085 +       case VHIN_DOMAINNAME:
21086 +               return uts->name.domainname;
21087 +       default:
21088 +               return NULL;
21089 +       }
21090 +       return NULL;
21091 +}
21092 +
21093 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
21094 +{
21095 +       struct vcmd_vhi_name_v0 vc_data;
21096 +       char *name;
21097 +
21098 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21099 +               return -EFAULT;
21100 +
21101 +       name = vx_vhi_name(vxi, vc_data.field);
21102 +       if (!name)
21103 +               return -EINVAL;
21104 +
21105 +       memcpy(name, vc_data.name, 65);
21106 +       return 0;
21107 +}
21108 +
21109 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
21110 +{
21111 +       struct vcmd_vhi_name_v0 vc_data;
21112 +       char *name;
21113 +
21114 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21115 +               return -EFAULT;
21116 +
21117 +       name = vx_vhi_name(vxi, vc_data.field);
21118 +       if (!name)
21119 +               return -EINVAL;
21120 +
21121 +       memcpy(vc_data.name, name, 65);
21122 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21123 +               return -EFAULT;
21124 +       return 0;
21125 +}
21126 +
21127 +
21128 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
21129 +{
21130 +       struct vcmd_virt_stat_v0 vc_data;
21131 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
21132 +       struct timespec uptime;
21133 +
21134 +       do_posix_clock_monotonic_gettime(&uptime);
21135 +       set_normalized_timespec(&uptime,
21136 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
21137 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
21138 +
21139 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
21140 +       vc_data.uptime = timespec_to_ns(&uptime);
21141 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
21142 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
21143 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
21144 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
21145 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
21146 +       vc_data.load[0] = cvirt->load[0];
21147 +       vc_data.load[1] = cvirt->load[1];
21148 +       vc_data.load[2] = cvirt->load[2];
21149 +
21150 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21151 +               return -EFAULT;
21152 +       return 0;
21153 +}
21154 +
21155 +
21156 +#ifdef CONFIG_VSERVER_VTIME
21157 +
21158 +/* virtualized time base */
21159 +
21160 +void vx_gettimeofday(struct timeval *tv)
21161 +{
21162 +       do_gettimeofday(tv);
21163 +       if (!vx_flags(VXF_VIRT_TIME, 0))
21164 +               return;
21165 +
21166 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
21167 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
21168 +
21169 +       if (tv->tv_usec >= USEC_PER_SEC) {
21170 +               tv->tv_sec++;
21171 +               tv->tv_usec -= USEC_PER_SEC;
21172 +       } else if (tv->tv_usec < 0) {
21173 +               tv->tv_sec--;
21174 +               tv->tv_usec += USEC_PER_SEC;
21175 +       }
21176 +}
21177 +
21178 +int vx_settimeofday(struct timespec *ts)
21179 +{
21180 +       struct timeval tv;
21181 +
21182 +       if (!vx_flags(VXF_VIRT_TIME, 0))
21183 +               return do_settimeofday(ts);
21184 +
21185 +       do_gettimeofday(&tv);
21186 +       current->vx_info->cvirt.bias_tv.tv_sec =
21187 +               ts->tv_sec - tv.tv_sec;
21188 +       current->vx_info->cvirt.bias_tv.tv_usec =
21189 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
21190 +       return 0;
21191 +}
21192 +
21193 +#endif
21194 +
21195 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
21196 --- linux-2.6.22.10/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00 +0100
21197 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt_init.h      2007-10-25 17:05:55 +0200
21198 @@ -0,0 +1,69 @@
21199 +
21200 +
21201 +extern uint64_t vx_idle_jiffies(void);
21202 +
21203 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
21204 +{
21205 +       uint64_t idle_jiffies = vx_idle_jiffies();
21206 +       uint64_t nsuptime;
21207 +
21208 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
21209 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
21210 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
21211 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
21212 +       cvirt->bias_tv.tv_sec = 0;
21213 +       cvirt->bias_tv.tv_usec = 0;
21214 +
21215 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
21216 +       atomic_set(&cvirt->nr_threads, 0);
21217 +       atomic_set(&cvirt->nr_running, 0);
21218 +       atomic_set(&cvirt->nr_uninterruptible, 0);
21219 +       atomic_set(&cvirt->nr_onhold, 0);
21220 +
21221 +       spin_lock_init(&cvirt->load_lock);
21222 +       cvirt->load_last = jiffies;
21223 +       atomic_set(&cvirt->load_updates, 0);
21224 +       cvirt->load[0] = 0;
21225 +       cvirt->load[1] = 0;
21226 +       cvirt->load[2] = 0;
21227 +       atomic_set(&cvirt->total_forks, 0);
21228 +
21229 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
21230 +       init_waitqueue_head(&cvirt->syslog.log_wait);
21231 +       cvirt->syslog.log_start = 0;
21232 +       cvirt->syslog.log_end = 0;
21233 +       cvirt->syslog.con_start = 0;
21234 +       cvirt->syslog.logged_chars = 0;
21235 +}
21236 +
21237 +static inline
21238 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
21239 +{
21240 +       // cvirt_pc->cpustat = { 0 };
21241 +}
21242 +
21243 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
21244 +{
21245 +       int value;
21246 +
21247 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
21248 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
21249 +               cvirt, value);
21250 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
21251 +               "!!! cvirt: %p[nr_running] = %d on exit.",
21252 +               cvirt, value);
21253 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
21254 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
21255 +               cvirt, value);
21256 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
21257 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
21258 +               cvirt, value);
21259 +       return;
21260 +}
21261 +
21262 +static inline
21263 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
21264 +{
21265 +       return;
21266 +}
21267 +
21268 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
21269 --- linux-2.6.22.10/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00 +0100
21270 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/cvirt_proc.h      2007-08-05 20:53:13 +0200
21271 @@ -0,0 +1,133 @@
21272 +#ifndef _VX_CVIRT_PROC_H
21273 +#define _VX_CVIRT_PROC_H
21274 +
21275 +#include <linux/nsproxy.h>
21276 +#include <linux/mnt_namespace.h>
21277 +#include <linux/utsname.h>
21278 +#include <linux/ipc.h>
21279 +
21280 +
21281 +static inline
21282 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
21283 +{
21284 +       struct mnt_namespace *ns;
21285 +       struct uts_namespace *uts;
21286 +       struct ipc_namespace *ipc;
21287 +       struct vfsmount *mnt;
21288 +       char *path, *root;
21289 +       int length = 0;
21290 +
21291 +       if (!nsproxy)
21292 +               goto out;
21293 +
21294 +       length += sprintf(buffer + length,
21295 +               "NSProxy:\t%p [%p,%p,%p]\n",
21296 +               nsproxy, nsproxy->mnt_ns,
21297 +               nsproxy->uts_ns, nsproxy->ipc_ns);
21298 +
21299 +       ns = nsproxy->mnt_ns;
21300 +       if (!ns)
21301 +               goto skip_ns;
21302 +
21303 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
21304 +       if (!path)
21305 +               goto skip_ns;
21306 +
21307 +       mnt = ns->root;
21308 +       root = d_path(mnt->mnt_root, mnt->mnt_parent, path, PATH_MAX - 2);
21309 +       length += sprintf(buffer + length,
21310 +               "Namespace:\t%p [#%u]\n"
21311 +               "RootPath:\t%s\n",
21312 +               ns, atomic_read(&ns->count),
21313 +               root);
21314 +       kfree(path);
21315 +skip_ns:
21316 +
21317 +       uts = nsproxy->uts_ns;
21318 +       if (!uts)
21319 +               goto skip_uts;
21320 +
21321 +       length += sprintf(buffer + length,
21322 +               "SysName:\t%.*s\n"
21323 +               "NodeName:\t%.*s\n"
21324 +               "Release:\t%.*s\n"
21325 +               "Version:\t%.*s\n"
21326 +               "Machine:\t%.*s\n"
21327 +               "DomainName:\t%.*s\n",
21328 +               __NEW_UTS_LEN, uts->name.sysname,
21329 +               __NEW_UTS_LEN, uts->name.nodename,
21330 +               __NEW_UTS_LEN, uts->name.release,
21331 +               __NEW_UTS_LEN, uts->name.version,
21332 +               __NEW_UTS_LEN, uts->name.machine,
21333 +               __NEW_UTS_LEN, uts->name.domainname);
21334 +skip_uts:
21335 +
21336 +       ipc = nsproxy->ipc_ns;
21337 +       if (!ipc)
21338 +               goto skip_ipc;
21339 +
21340 +       length += sprintf(buffer + length,
21341 +               "SEMS:\t\t%d %d %d %d  %d\n"
21342 +               "MSG:\t\t%d %d %d\n"
21343 +               "SHM:\t\t%lu %lu  %d %d\n",
21344 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
21345 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
21346 +               ipc->used_sems,
21347 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
21348 +               (unsigned long)ipc->shm_ctlmax,
21349 +               (unsigned long)ipc->shm_ctlall,
21350 +               ipc->shm_ctlmni, ipc->shm_tot);
21351 +skip_ipc:
21352 +out:
21353 +       return length;
21354 +}
21355 +
21356 +
21357 +#include <linux/sched.h>
21358 +
21359 +#define LOAD_INT(x) ((x) >> FSHIFT)
21360 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
21361 +
21362 +static inline
21363 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
21364 +{
21365 +       int length = 0;
21366 +       int a, b, c;
21367 +
21368 +       length += sprintf(buffer + length,
21369 +               "BiasUptime:\t%lu.%02lu\n",
21370 +               (unsigned long)cvirt->bias_uptime.tv_sec,
21371 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
21372 +
21373 +       a = cvirt->load[0] + (FIXED_1 / 200);
21374 +       b = cvirt->load[1] + (FIXED_1 / 200);
21375 +       c = cvirt->load[2] + (FIXED_1 / 200);
21376 +       length += sprintf(buffer + length,
21377 +               "nr_threads:\t%d\n"
21378 +               "nr_running:\t%d\n"
21379 +               "nr_unintr:\t%d\n"
21380 +               "nr_onhold:\t%d\n"
21381 +               "load_updates:\t%d\n"
21382 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
21383 +               "total_forks:\t%d\n",
21384 +               atomic_read(&cvirt->nr_threads),
21385 +               atomic_read(&cvirt->nr_running),
21386 +               atomic_read(&cvirt->nr_uninterruptible),
21387 +               atomic_read(&cvirt->nr_onhold),
21388 +               atomic_read(&cvirt->load_updates),
21389 +               LOAD_INT(a), LOAD_FRAC(a),
21390 +               LOAD_INT(b), LOAD_FRAC(b),
21391 +               LOAD_INT(c), LOAD_FRAC(c),
21392 +               atomic_read(&cvirt->total_forks));
21393 +       return length;
21394 +}
21395 +
21396 +static inline
21397 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
21398 +       char *buffer, int cpu)
21399 +{
21400 +       int length = 0;
21401 +       return length;
21402 +}
21403 +
21404 +#endif /* _VX_CVIRT_PROC_H */
21405 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
21406 --- linux-2.6.22.10/kernel/vserver/debug.c      1970-01-01 01:00:00 +0100
21407 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/debug.c   2007-10-01 14:57:41 +0200
21408 @@ -0,0 +1,32 @@
21409 +/*
21410 + *  kernel/vserver/debug.c
21411 + *
21412 + *  Copyright (C) 2005-2007 Herbert Pötzl
21413 + *
21414 + *  V0.01  vx_info dump support
21415 + *
21416 + */
21417 +
21418 +#include <linux/module.h>
21419 +
21420 +#include <linux/vserver/context.h>
21421 +
21422 +
21423 +void   dump_vx_info(struct vx_info *vxi, int level)
21424 +{
21425 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
21426 +               atomic_read(&vxi->vx_usecnt),
21427 +               atomic_read(&vxi->vx_tasks),
21428 +               vxi->vx_state);
21429 +       if (level > 0) {
21430 +               __dump_vx_limit(&vxi->limit);
21431 +               __dump_vx_sched(&vxi->sched);
21432 +               __dump_vx_cvirt(&vxi->cvirt);
21433 +               __dump_vx_cacct(&vxi->cacct);
21434 +       }
21435 +       printk("---\n");
21436 +}
21437 +
21438 +
21439 +EXPORT_SYMBOL_GPL(dump_vx_info);
21440 +
21441 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
21442 --- linux-2.6.22.10/kernel/vserver/device.c     1970-01-01 01:00:00 +0100
21443 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/device.c  2007-10-11 01:10:22 +0200
21444 @@ -0,0 +1,443 @@
21445 +/*
21446 + *  linux/kernel/vserver/device.c
21447 + *
21448 + *  Linux-VServer: Device Support
21449 + *
21450 + *  Copyright (C) 2006  Herbert Pötzl
21451 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
21452 + *
21453 + *  V0.01  device mapping basics
21454 + *  V0.02  added defaults
21455 + *
21456 + */
21457 +
21458 +#include <linux/slab.h>
21459 +#include <linux/rcupdate.h>
21460 +#include <linux/fs.h>
21461 +#include <linux/namei.h>
21462 +#include <linux/hash.h>
21463 +
21464 +#include <asm/errno.h>
21465 +#include <asm/uaccess.h>
21466 +#include <linux/vserver/base.h>
21467 +#include <linux/vserver/debug.h>
21468 +#include <linux/vserver/context.h>
21469 +#include <linux/vserver/device.h>
21470 +#include <linux/vserver/device_cmd.h>
21471 +
21472 +
21473 +#define DMAP_HASH_BITS 4
21474 +
21475 +
21476 +struct vs_mapping {
21477 +       union {
21478 +               struct hlist_node hlist;
21479 +               struct list_head list;
21480 +       } u;
21481 +#define dm_hlist       u.hlist
21482 +#define dm_list                u.list
21483 +       xid_t xid;
21484 +       dev_t device;
21485 +       struct vx_dmap_target target;
21486 +};
21487 +
21488 +
21489 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
21490 +
21491 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
21492 +
21493 +static struct vx_dmap_target dmap_defaults[2] = {
21494 +       { .flags = DATTR_OPEN },
21495 +       { .flags = DATTR_OPEN },
21496 +};
21497 +
21498 +
21499 +struct kmem_cache *dmap_cachep __read_mostly;
21500 +
21501 +int __init dmap_cache_init(void)
21502 +{
21503 +       dmap_cachep = kmem_cache_create("dmap_cache",
21504 +               sizeof(struct vs_mapping), 0,
21505 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
21506 +       return 0;
21507 +}
21508 +
21509 +__initcall(dmap_cache_init);
21510 +
21511 +
21512 +static inline unsigned int __hashval(dev_t dev, int bits)
21513 +{
21514 +       return hash_long((unsigned long)dev, bits);
21515 +}
21516 +
21517 +
21518 +/*     __hash_mapping()
21519 + *     add the mapping to the hash table
21520 + */
21521 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
21522 +{
21523 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21524 +       struct hlist_head *head, *hash = dmap_main_hash;
21525 +       int device = vdm->device;
21526 +
21527 +       spin_lock(hash_lock);
21528 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
21529 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
21530 +
21531 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
21532 +       hlist_add_head(&vdm->dm_hlist, head);
21533 +       spin_unlock(hash_lock);
21534 +}
21535 +
21536 +
21537 +static inline int __mode_to_default(umode_t mode)
21538 +{
21539 +       switch (mode) {
21540 +       case S_IFBLK:
21541 +               return 0;
21542 +       case S_IFCHR:
21543 +               return 1;
21544 +       default:
21545 +               BUG();
21546 +       }
21547 +}
21548 +
21549 +
21550 +/*     __set_default()
21551 + *     set a default
21552 + */
21553 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
21554 +       struct vx_dmap_target *vdmt)
21555 +{
21556 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21557 +       spin_lock(hash_lock);
21558 +
21559 +       if (vxi)
21560 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
21561 +       else
21562 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
21563 +
21564 +
21565 +       spin_unlock(hash_lock);
21566 +
21567 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
21568 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
21569 +}
21570 +
21571 +
21572 +/*     __remove_default()
21573 + *     remove a default
21574 + */
21575 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
21576 +{
21577 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21578 +       spin_lock(hash_lock);
21579 +
21580 +       if (vxi)
21581 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
21582 +       else    /* remove == reset */
21583 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
21584 +
21585 +       spin_unlock(hash_lock);
21586 +       return 0;
21587 +}
21588 +
21589 +
21590 +/*     __find_mapping()
21591 + *     find a mapping in the hash table
21592 + *
21593 + *     caller must hold hash_lock
21594 + */
21595 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
21596 +       struct vs_mapping **local, struct vs_mapping **global)
21597 +{
21598 +       struct hlist_head *hash = dmap_main_hash;
21599 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
21600 +       struct hlist_node *pos;
21601 +       struct vs_mapping *vdm;
21602 +
21603 +       *local = NULL;
21604 +       if (global)
21605 +               *global = NULL;
21606 +
21607 +       hlist_for_each(pos, head) {
21608 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
21609 +
21610 +               if ((vdm->device == device) &&
21611 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
21612 +                       if (vdm->xid == xid) {
21613 +                               *local = vdm;
21614 +                               return 1;
21615 +                       } else if (global && vdm->xid == 0)
21616 +                               *global = vdm;
21617 +               }
21618 +       }
21619 +
21620 +       if (global && *global)
21621 +               return 0;
21622 +       else
21623 +               return -ENOENT;
21624 +}
21625 +
21626 +
21627 +/*     __lookup_mapping()
21628 + *     find a mapping and store the result in target and flags
21629 + */
21630 +static inline int __lookup_mapping(struct vx_info *vxi,
21631 +       dev_t device, dev_t *target, int *flags, umode_t mode)
21632 +{
21633 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21634 +       struct vs_mapping *vdm, *global;
21635 +       struct vx_dmap_target *vdmt;
21636 +       int ret = 0;
21637 +       xid_t xid = vxi->vx_id;
21638 +       int index;
21639 +
21640 +       spin_lock(hash_lock);
21641 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
21642 +               ret = 1;
21643 +               vdmt = &vdm->target;
21644 +               goto found;
21645 +       }
21646 +
21647 +       index = __mode_to_default(mode);
21648 +       if (vxi && vxi->dmap.targets[index].flags) {
21649 +               ret = 2;
21650 +               vdmt = &vxi->dmap.targets[index];
21651 +       } else if (global) {
21652 +               ret = 3;
21653 +               vdmt = &global->target;
21654 +               goto found;
21655 +       } else {
21656 +               ret = 4;
21657 +               vdmt = &dmap_defaults[index];
21658 +       }
21659 +
21660 +found:
21661 +       if (target && (vdmt->flags & DATTR_REMAP))
21662 +               *target = vdmt->target;
21663 +       else if (target)
21664 +               *target = device;
21665 +       if (flags)
21666 +               *flags = vdmt->flags;
21667 +
21668 +       spin_unlock(hash_lock);
21669 +
21670 +       return ret;
21671 +}
21672 +
21673 +
21674 +/*     __remove_mapping()
21675 + *     remove a mapping from the hash table
21676 + */
21677 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
21678 +       umode_t mode)
21679 +{
21680 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
21681 +       struct vs_mapping *vdm = NULL;
21682 +       int ret = 0;
21683 +
21684 +       spin_lock(hash_lock);
21685 +
21686 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
21687 +               NULL);
21688 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
21689 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
21690 +       if (ret < 0)
21691 +               goto out;
21692 +       hlist_del(&vdm->dm_hlist);
21693 +
21694 +out:
21695 +       spin_unlock(hash_lock);
21696 +       if (vdm)
21697 +               kmem_cache_free(dmap_cachep, vdm);
21698 +       return ret;
21699 +}
21700 +
21701 +
21702 +
21703 +int vs_map_device(struct vx_info *vxi,
21704 +       dev_t device, dev_t *target, umode_t mode)
21705 +{
21706 +       int ret, flags = DATTR_MASK;
21707 +
21708 +       if (!vxi) {
21709 +               if (target)
21710 +                       *target = device;
21711 +               goto out;
21712 +       }
21713 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
21714 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
21715 +               device, target ? *target : 0, flags, mode, ret);
21716 +out:
21717 +       return (flags & DATTR_MASK);
21718 +}
21719 +
21720 +
21721 +
21722 +static int do_set_mapping(struct vx_info *vxi,
21723 +       dev_t device, dev_t target, int flags, umode_t mode)
21724 +{
21725 +       if (device) {
21726 +               struct vs_mapping *new;
21727 +
21728 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
21729 +               if (!new)
21730 +                       return -ENOMEM;
21731 +
21732 +               INIT_HLIST_NODE(&new->dm_hlist);
21733 +               new->device = device;
21734 +               new->target.target = target;
21735 +               new->target.flags = flags | mode;
21736 +               new->xid = (vxi ? vxi->vx_id : 0);
21737 +
21738 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
21739 +               __hash_mapping(vxi, new);
21740 +       } else {
21741 +               struct vx_dmap_target new = {
21742 +                       .target = target,
21743 +                       .flags = flags | mode,
21744 +               };
21745 +               __set_default(vxi, mode, &new);
21746 +       }
21747 +       return 0;
21748 +}
21749 +
21750 +
21751 +static int do_unset_mapping(struct vx_info *vxi,
21752 +       dev_t device, dev_t target, int flags, umode_t mode)
21753 +{
21754 +       int ret = -EINVAL;
21755 +
21756 +       if (device) {
21757 +               ret = __remove_mapping(vxi, device, mode);
21758 +               if (ret < 0)
21759 +                       goto out;
21760 +       } else {
21761 +               ret = __remove_default(vxi, mode);
21762 +               if (ret < 0)
21763 +                       goto out;
21764 +       }
21765 +
21766 +out:
21767 +       return ret;
21768 +}
21769 +
21770 +
21771 +static inline int __user_device(const char __user *name, dev_t *dev,
21772 +       umode_t *mode)
21773 +{
21774 +       struct nameidata nd;
21775 +       int ret;
21776 +
21777 +       if (!name) {
21778 +               *dev = 0;
21779 +               return 0;
21780 +       }
21781 +       ret = user_path_walk_link(name, &nd);
21782 +       if (ret)
21783 +               return ret;
21784 +       if (nd.dentry->d_inode) {
21785 +               *dev = nd.dentry->d_inode->i_rdev;
21786 +               *mode = nd.dentry->d_inode->i_mode;
21787 +       }
21788 +       path_release(&nd);
21789 +       return 0;
21790 +}
21791 +
21792 +static inline int __mapping_mode(dev_t device, dev_t target,
21793 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
21794 +{
21795 +       if (device)
21796 +               *mode = device_mode & S_IFMT;
21797 +       else if (target)
21798 +               *mode = target_mode & S_IFMT;
21799 +       else
21800 +               *mode = 0;
21801 +
21802 +       /* if both given, device and target mode have to match */
21803 +       if (device && target &&
21804 +               ((device_mode ^ target_mode) & S_IFMT))
21805 +               return -EINVAL;
21806 +       return 0;
21807 +}
21808 +
21809 +
21810 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
21811 +       const char __user *target_path, int flags, int set)
21812 +{
21813 +       dev_t device = ~0, target = ~0;
21814 +       umode_t device_mode = 0, target_mode = 0, mode;
21815 +       int ret;
21816 +
21817 +       ret = __user_device(device_path, &device, &device_mode);
21818 +       if (ret)
21819 +               return ret;
21820 +       ret = __user_device(target_path, &target, &target_mode);
21821 +       if (ret)
21822 +               return ret;
21823 +
21824 +       ret = __mapping_mode(device, target,
21825 +               device_mode, target_mode, &mode);
21826 +       if (ret)
21827 +               return ret;
21828 +
21829 +       if (set)
21830 +               return do_set_mapping(vxi, device, target,
21831 +                       flags, mode);
21832 +       else
21833 +               return do_unset_mapping(vxi, device, target,
21834 +                       flags, mode);
21835 +}
21836 +
21837 +
21838 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
21839 +{
21840 +       struct vcmd_set_mapping_v0 vc_data;
21841 +
21842 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21843 +               return -EFAULT;
21844 +
21845 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21846 +               vc_data.flags, 1);
21847 +}
21848 +
21849 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
21850 +{
21851 +       struct vcmd_set_mapping_v0 vc_data;
21852 +
21853 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21854 +               return -EFAULT;
21855 +
21856 +       return do_mapping(vxi, vc_data.device, vc_data.target,
21857 +               vc_data.flags, 0);
21858 +}
21859 +
21860 +
21861 +#ifdef CONFIG_COMPAT
21862 +
21863 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
21864 +{
21865 +       struct vcmd_set_mapping_v0_x32 vc_data;
21866 +
21867 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21868 +               return -EFAULT;
21869 +
21870 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21871 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
21872 +}
21873 +
21874 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
21875 +{
21876 +       struct vcmd_set_mapping_v0_x32 vc_data;
21877 +
21878 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21879 +               return -EFAULT;
21880 +
21881 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
21882 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
21883 +}
21884 +
21885 +#endif /* CONFIG_COMPAT */
21886 +
21887 +
21888 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
21889 --- linux-2.6.22.10/kernel/vserver/dlimit.c     1970-01-01 01:00:00 +0100
21890 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/dlimit.c  2007-08-15 22:07:58 +0200
21891 @@ -0,0 +1,520 @@
21892 +/*
21893 + *  linux/kernel/vserver/dlimit.c
21894 + *
21895 + *  Virtual Server: Context Disk Limits
21896 + *
21897 + *  Copyright (C) 2004-2007  Herbert Pötzl
21898 + *
21899 + *  V0.01  initial version
21900 + *  V0.02  compat32 splitup
21901 + *
21902 + */
21903 +
21904 +#include <linux/statfs.h>
21905 +#include <linux/vs_tag.h>
21906 +#include <linux/vs_dlimit.h>
21907 +#include <linux/vserver/dlimit_cmd.h>
21908 +
21909 +#include <asm/uaccess.h>
21910 +
21911 +/*     __alloc_dl_info()
21912 +
21913 +       * allocate an initialized dl_info struct
21914 +       * doesn't make it visible (hash)                        */
21915 +
21916 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
21917 +{
21918 +       struct dl_info *new = NULL;
21919 +
21920 +       vxdprintk(VXD_CBIT(dlim, 5),
21921 +               "alloc_dl_info(%p,%d)*", sb, tag);
21922 +
21923 +       /* would this benefit from a slab cache? */
21924 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
21925 +       if (!new)
21926 +               return 0;
21927 +
21928 +       memset(new, 0, sizeof(struct dl_info));
21929 +       new->dl_tag = tag;
21930 +       new->dl_sb = sb;
21931 +       INIT_RCU_HEAD(&new->dl_rcu);
21932 +       INIT_HLIST_NODE(&new->dl_hlist);
21933 +       spin_lock_init(&new->dl_lock);
21934 +       atomic_set(&new->dl_refcnt, 0);
21935 +       atomic_set(&new->dl_usecnt, 0);
21936 +
21937 +       /* rest of init goes here */
21938 +
21939 +       vxdprintk(VXD_CBIT(dlim, 4),
21940 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
21941 +       return new;
21942 +}
21943 +
21944 +/*     __dealloc_dl_info()
21945 +
21946 +       * final disposal of dl_info                             */
21947 +
21948 +static void __dealloc_dl_info(struct dl_info *dli)
21949 +{
21950 +       vxdprintk(VXD_CBIT(dlim, 4),
21951 +               "dealloc_dl_info(%p)", dli);
21952 +
21953 +       dli->dl_hlist.next = LIST_POISON1;
21954 +       dli->dl_tag = -1;
21955 +       dli->dl_sb = 0;
21956 +
21957 +       BUG_ON(atomic_read(&dli->dl_usecnt));
21958 +       BUG_ON(atomic_read(&dli->dl_refcnt));
21959 +
21960 +       kfree(dli);
21961 +}
21962 +
21963 +
21964 +/*     hash table for dl_info hash */
21965 +
21966 +#define DL_HASH_SIZE   13
21967 +
21968 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
21969 +
21970 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
21971 +
21972 +
21973 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
21974 +{
21975 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
21976 +}
21977 +
21978 +
21979 +
21980 +/*     __hash_dl_info()
21981 +
21982 +       * add the dli to the global hash table
21983 +       * requires the hash_lock to be held                     */
21984 +
21985 +static inline void __hash_dl_info(struct dl_info *dli)
21986 +{
21987 +       struct hlist_head *head;
21988 +
21989 +       vxdprintk(VXD_CBIT(dlim, 6),
21990 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
21991 +       get_dl_info(dli);
21992 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
21993 +       hlist_add_head_rcu(&dli->dl_hlist, head);
21994 +}
21995 +
21996 +/*     __unhash_dl_info()
21997 +
21998 +       * remove the dli from the global hash table
21999 +       * requires the hash_lock to be held                     */
22000 +
22001 +static inline void __unhash_dl_info(struct dl_info *dli)
22002 +{
22003 +       vxdprintk(VXD_CBIT(dlim, 6),
22004 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
22005 +       hlist_del_rcu(&dli->dl_hlist);
22006 +       put_dl_info(dli);
22007 +}
22008 +
22009 +
22010 +/*     __lookup_dl_info()
22011 +
22012 +       * requires the rcu_read_lock()
22013 +       * doesn't increment the dl_refcnt                       */
22014 +
22015 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
22016 +{
22017 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
22018 +       struct hlist_node *pos;
22019 +       struct dl_info *dli;
22020 +
22021 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
22022 +
22023 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
22024 +                       return dli;
22025 +               }
22026 +       }
22027 +       return NULL;
22028 +}
22029 +
22030 +
22031 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
22032 +{
22033 +       struct dl_info *dli;
22034 +
22035 +       rcu_read_lock();
22036 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
22037 +       vxdprintk(VXD_CBIT(dlim, 7),
22038 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
22039 +       rcu_read_unlock();
22040 +       return dli;
22041 +}
22042 +
22043 +void rcu_free_dl_info(struct rcu_head *head)
22044 +{
22045 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
22046 +       int usecnt, refcnt;
22047 +
22048 +       BUG_ON(!dli || !head);
22049 +
22050 +       usecnt = atomic_read(&dli->dl_usecnt);
22051 +       BUG_ON(usecnt < 0);
22052 +
22053 +       refcnt = atomic_read(&dli->dl_refcnt);
22054 +       BUG_ON(refcnt < 0);
22055 +
22056 +       vxdprintk(VXD_CBIT(dlim, 3),
22057 +               "rcu_free_dl_info(%p)", dli);
22058 +       if (!usecnt)
22059 +               __dealloc_dl_info(dli);
22060 +       else
22061 +               printk("!!! rcu didn't free\n");
22062 +}
22063 +
22064 +
22065 +
22066 +
22067 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
22068 +       uint32_t flags, int add)
22069 +{
22070 +       struct nameidata nd;
22071 +       int ret;
22072 +
22073 +       ret = user_path_walk_link(name, &nd);
22074 +       if (!ret) {
22075 +               struct super_block *sb;
22076 +               struct dl_info *dli;
22077 +
22078 +               ret = -EINVAL;
22079 +               if (!nd.dentry->d_inode)
22080 +                       goto out_release;
22081 +               if (!(sb = nd.dentry->d_inode->i_sb))
22082 +                       goto out_release;
22083 +
22084 +               if (add) {
22085 +                       dli = __alloc_dl_info(sb, id);
22086 +                       spin_lock(&dl_info_hash_lock);
22087 +
22088 +                       ret = -EEXIST;
22089 +                       if (__lookup_dl_info(sb, id))
22090 +                               goto out_unlock;
22091 +                       __hash_dl_info(dli);
22092 +                       dli = NULL;
22093 +               } else {
22094 +                       spin_lock(&dl_info_hash_lock);
22095 +                       dli = __lookup_dl_info(sb, id);
22096 +
22097 +                       ret = -ESRCH;
22098 +                       if (!dli)
22099 +                               goto out_unlock;
22100 +                       __unhash_dl_info(dli);
22101 +               }
22102 +               ret = 0;
22103 +       out_unlock:
22104 +               spin_unlock(&dl_info_hash_lock);
22105 +               if (add && dli)
22106 +                       __dealloc_dl_info(dli);
22107 +       out_release:
22108 +               path_release(&nd);
22109 +       }
22110 +       return ret;
22111 +}
22112 +
22113 +int vc_add_dlimit(uint32_t id, void __user *data)
22114 +{
22115 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
22116 +
22117 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22118 +               return -EFAULT;
22119 +
22120 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
22121 +}
22122 +
22123 +int vc_rem_dlimit(uint32_t id, void __user *data)
22124 +{
22125 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
22126 +
22127 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22128 +               return -EFAULT;
22129 +
22130 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
22131 +}
22132 +
22133 +#ifdef CONFIG_COMPAT
22134 +
22135 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
22136 +{
22137 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
22138 +
22139 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22140 +               return -EFAULT;
22141 +
22142 +       return do_addrem_dlimit(id,
22143 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
22144 +}
22145 +
22146 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
22147 +{
22148 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
22149 +
22150 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22151 +               return -EFAULT;
22152 +
22153 +       return do_addrem_dlimit(id,
22154 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
22155 +}
22156 +
22157 +#endif /* CONFIG_COMPAT */
22158 +
22159 +
22160 +static inline
22161 +int do_set_dlimit(uint32_t id, const char __user *name,
22162 +       uint32_t space_used, uint32_t space_total,
22163 +       uint32_t inodes_used, uint32_t inodes_total,
22164 +       uint32_t reserved, uint32_t flags)
22165 +{
22166 +       struct nameidata nd;
22167 +       int ret;
22168 +
22169 +       ret = user_path_walk_link(name, &nd);
22170 +       if (!ret) {
22171 +               struct super_block *sb;
22172 +               struct dl_info *dli;
22173 +
22174 +               ret = -EINVAL;
22175 +               if (!nd.dentry->d_inode)
22176 +                       goto out_release;
22177 +               if (!(sb = nd.dentry->d_inode->i_sb))
22178 +                       goto out_release;
22179 +               if ((reserved != CDLIM_KEEP &&
22180 +                       reserved > 100) ||
22181 +                       (inodes_used != CDLIM_KEEP &&
22182 +                       inodes_used > inodes_total) ||
22183 +                       (space_used != CDLIM_KEEP &&
22184 +                       space_used > space_total))
22185 +                       goto out_release;
22186 +
22187 +               ret = -ESRCH;
22188 +               dli = locate_dl_info(sb, id);
22189 +               if (!dli)
22190 +                       goto out_release;
22191 +
22192 +               spin_lock(&dli->dl_lock);
22193 +
22194 +               if (inodes_used != CDLIM_KEEP)
22195 +                       dli->dl_inodes_used = inodes_used;
22196 +               if (inodes_total != CDLIM_KEEP)
22197 +                       dli->dl_inodes_total = inodes_total;
22198 +               if (space_used != CDLIM_KEEP) {
22199 +                       dli->dl_space_used = space_used;
22200 +                       dli->dl_space_used <<= 10;
22201 +               }
22202 +               if (space_total == CDLIM_INFINITY)
22203 +                       dli->dl_space_total = DLIM_INFINITY;
22204 +               else if (space_total != CDLIM_KEEP) {
22205 +                       dli->dl_space_total = space_total;
22206 +                       dli->dl_space_total <<= 10;
22207 +               }
22208 +               if (reserved != CDLIM_KEEP)
22209 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
22210 +
22211 +               spin_unlock(&dli->dl_lock);
22212 +
22213 +               put_dl_info(dli);
22214 +               ret = 0;
22215 +
22216 +       out_release:
22217 +               path_release(&nd);
22218 +       }
22219 +       return ret;
22220 +}
22221 +
22222 +int vc_set_dlimit(uint32_t id, void __user *data)
22223 +{
22224 +       struct vcmd_ctx_dlimit_v0 vc_data;
22225 +
22226 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22227 +               return -EFAULT;
22228 +
22229 +       return do_set_dlimit(id, vc_data.name,
22230 +               vc_data.space_used, vc_data.space_total,
22231 +               vc_data.inodes_used, vc_data.inodes_total,
22232 +               vc_data.reserved, vc_data.flags);
22233 +}
22234 +
22235 +#ifdef CONFIG_COMPAT
22236 +
22237 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
22238 +{
22239 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22240 +
22241 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22242 +               return -EFAULT;
22243 +
22244 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
22245 +               vc_data.space_used, vc_data.space_total,
22246 +               vc_data.inodes_used, vc_data.inodes_total,
22247 +               vc_data.reserved, vc_data.flags);
22248 +}
22249 +
22250 +#endif /* CONFIG_COMPAT */
22251 +
22252 +
22253 +static inline
22254 +int do_get_dlimit(uint32_t id, const char __user *name,
22255 +       uint32_t *space_used, uint32_t *space_total,
22256 +       uint32_t *inodes_used, uint32_t *inodes_total,
22257 +       uint32_t *reserved, uint32_t *flags)
22258 +{
22259 +       struct nameidata nd;
22260 +       int ret;
22261 +
22262 +       ret = user_path_walk_link(name, &nd);
22263 +       if (!ret) {
22264 +               struct super_block *sb;
22265 +               struct dl_info *dli;
22266 +
22267 +               ret = -EINVAL;
22268 +               if (!nd.dentry->d_inode)
22269 +                       goto out_release;
22270 +               if (!(sb = nd.dentry->d_inode->i_sb))
22271 +                       goto out_release;
22272 +
22273 +               ret = -ESRCH;
22274 +               dli = locate_dl_info(sb, id);
22275 +               if (!dli)
22276 +                       goto out_release;
22277 +
22278 +               spin_lock(&dli->dl_lock);
22279 +               *inodes_used = dli->dl_inodes_used;
22280 +               *inodes_total = dli->dl_inodes_total;
22281 +               *space_used = dli->dl_space_used >> 10;
22282 +               if (dli->dl_space_total == DLIM_INFINITY)
22283 +                       *space_total = CDLIM_INFINITY;
22284 +               else
22285 +                       *space_total = dli->dl_space_total >> 10;
22286 +
22287 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
22288 +               spin_unlock(&dli->dl_lock);
22289 +
22290 +               put_dl_info(dli);
22291 +               ret = -EFAULT;
22292 +
22293 +               ret = 0;
22294 +       out_release:
22295 +               path_release(&nd);
22296 +       }
22297 +       return ret;
22298 +}
22299 +
22300 +
22301 +int vc_get_dlimit(uint32_t id, void __user *data)
22302 +{
22303 +       struct vcmd_ctx_dlimit_v0 vc_data;
22304 +       int ret;
22305 +
22306 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22307 +               return -EFAULT;
22308 +
22309 +       ret = do_get_dlimit(id, vc_data.name,
22310 +               &vc_data.space_used, &vc_data.space_total,
22311 +               &vc_data.inodes_used, &vc_data.inodes_total,
22312 +               &vc_data.reserved, &vc_data.flags);
22313 +       if (ret)
22314 +               return ret;
22315 +
22316 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22317 +               return -EFAULT;
22318 +       return 0;
22319 +}
22320 +
22321 +#ifdef CONFIG_COMPAT
22322 +
22323 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
22324 +{
22325 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
22326 +       int ret;
22327 +
22328 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22329 +               return -EFAULT;
22330 +
22331 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
22332 +               &vc_data.space_used, &vc_data.space_total,
22333 +               &vc_data.inodes_used, &vc_data.inodes_total,
22334 +               &vc_data.reserved, &vc_data.flags);
22335 +       if (ret)
22336 +               return ret;
22337 +
22338 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22339 +               return -EFAULT;
22340 +       return 0;
22341 +}
22342 +
22343 +#endif /* CONFIG_COMPAT */
22344 +
22345 +
22346 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
22347 +{
22348 +       struct dl_info *dli;
22349 +       __u64 blimit, bfree, bavail;
22350 +       __u32 ifree;
22351 +
22352 +       dli = locate_dl_info(sb, dx_current_tag());
22353 +       if (!dli)
22354 +               return;
22355 +
22356 +       spin_lock(&dli->dl_lock);
22357 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
22358 +               goto no_ilim;
22359 +
22360 +       /* reduce max inodes available to limit */
22361 +       if (buf->f_files > dli->dl_inodes_total)
22362 +               buf->f_files = dli->dl_inodes_total;
22363 +
22364 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
22365 +       /* reduce free inodes to min */
22366 +       if (ifree < buf->f_ffree)
22367 +               buf->f_ffree = ifree;
22368 +
22369 +no_ilim:
22370 +       if (dli->dl_space_total == DLIM_INFINITY)
22371 +               goto no_blim;
22372 +
22373 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
22374 +
22375 +       if (dli->dl_space_total < dli->dl_space_used)
22376 +               bfree = 0;
22377 +       else
22378 +               bfree = (dli->dl_space_total - dli->dl_space_used)
22379 +                       >> sb->s_blocksize_bits;
22380 +
22381 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
22382 +       if (bavail < dli->dl_space_used)
22383 +               bavail = 0;
22384 +       else
22385 +               bavail = (bavail - dli->dl_space_used)
22386 +                       >> sb->s_blocksize_bits;
22387 +
22388 +       /* reduce max space available to limit */
22389 +       if (buf->f_blocks > blimit)
22390 +               buf->f_blocks = blimit;
22391 +
22392 +       /* reduce free space to min */
22393 +       if (bfree < buf->f_bfree)
22394 +               buf->f_bfree = bfree;
22395 +
22396 +       /* reduce avail space to min */
22397 +       if (bavail < buf->f_bavail)
22398 +               buf->f_bavail = bavail;
22399 +
22400 +no_blim:
22401 +       spin_unlock(&dli->dl_lock);
22402 +       put_dl_info(dli);
22403 +
22404 +       return;
22405 +}
22406 +
22407 +#include <linux/module.h>
22408 +
22409 +EXPORT_SYMBOL_GPL(locate_dl_info);
22410 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
22411 +
22412 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
22413 --- linux-2.6.22.10/kernel/vserver/helper.c     1970-01-01 01:00:00 +0100
22414 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/helper.c  2007-08-15 22:12:01 +0200
22415 @@ -0,0 +1,199 @@
22416 +/*
22417 + *  linux/kernel/vserver/helper.c
22418 + *
22419 + *  Virtual Context Support
22420 + *
22421 + *  Copyright (C) 2004-2007  Herbert Pötzl
22422 + *
22423 + *  V0.01  basic helper
22424 + *
22425 + */
22426 +
22427 +#include <linux/kmod.h>
22428 +#include <linux/reboot.h>
22429 +#include <linux/vs_context.h>
22430 +#include <linux/vs_network.h>
22431 +#include <linux/vserver/signal.h>
22432 +
22433 +
22434 +char vshelper_path[255] = "/sbin/vshelper";
22435 +
22436 +
22437 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
22438 +{
22439 +       int ret;
22440 +
22441 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
22442 +               printk( KERN_WARNING
22443 +                       "%s: (%s %s) returned %s with %d\n",
22444 +                       name, argv[1], argv[2],
22445 +                       sync ? "sync" : "async", ret);
22446 +       }
22447 +       vxdprintk(VXD_CBIT(switch, 4),
22448 +               "%s: (%s %s) returned %s with %d",
22449 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
22450 +       return ret;
22451 +}
22452 +
22453 +/*
22454 + *      vshelper path is set via /proc/sys
22455 + *      invoked by vserver sys_reboot(), with
22456 + *      the following arguments
22457 + *
22458 + *      argv [0] = vshelper_path;
22459 + *      argv [1] = action: "restart", "halt", "poweroff", ...
22460 + *      argv [2] = context identifier
22461 + *
22462 + *      envp [*] = type-specific parameters
22463 + */
22464 +
22465 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
22466 +{
22467 +       char id_buf[8], cmd_buf[16];
22468 +       char uid_buf[16], pid_buf[16];
22469 +       int ret;
22470 +
22471 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22472 +       char *envp[] = {"HOME=/", "TERM=linux",
22473 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
22474 +                       uid_buf, pid_buf, cmd_buf, 0};
22475 +
22476 +       if (vx_info_state(vxi, VXS_HELPER))
22477 +               return -EAGAIN;
22478 +       vxi->vx_state |= VXS_HELPER;
22479 +
22480 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22481 +
22482 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22483 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
22484 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
22485 +
22486 +       switch (cmd) {
22487 +       case LINUX_REBOOT_CMD_RESTART:
22488 +               argv[1] = "restart";
22489 +               break;
22490 +
22491 +       case LINUX_REBOOT_CMD_HALT:
22492 +               argv[1] = "halt";
22493 +               break;
22494 +
22495 +       case LINUX_REBOOT_CMD_POWER_OFF:
22496 +               argv[1] = "poweroff";
22497 +               break;
22498 +
22499 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
22500 +               argv[1] = "swsusp";
22501 +               break;
22502 +
22503 +       default:
22504 +               vxi->vx_state &= ~VXS_HELPER;
22505 +               return 0;
22506 +       }
22507 +
22508 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
22509 +       vxi->vx_state &= ~VXS_HELPER;
22510 +       __wakeup_vx_info(vxi);
22511 +       return (ret) ? -EPERM : 0;
22512 +}
22513 +
22514 +
22515 +long vs_reboot(unsigned int cmd, void __user *arg)
22516 +{
22517 +       struct vx_info *vxi = current->vx_info;
22518 +       long ret = 0;
22519 +
22520 +       vxdprintk(VXD_CBIT(misc, 5),
22521 +               "vs_reboot(%p[#%d],%d)",
22522 +               vxi, vxi ? vxi->vx_id : 0, cmd);
22523 +
22524 +       ret = vs_reboot_helper(vxi, cmd, arg);
22525 +       if (ret)
22526 +               return ret;
22527 +
22528 +       vxi->reboot_cmd = cmd;
22529 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
22530 +               switch (cmd) {
22531 +               case LINUX_REBOOT_CMD_RESTART:
22532 +               case LINUX_REBOOT_CMD_HALT:
22533 +               case LINUX_REBOOT_CMD_POWER_OFF:
22534 +                       vx_info_kill(vxi, 0, SIGKILL);
22535 +                       vx_info_kill(vxi, 1, SIGKILL);
22536 +               default:
22537 +                       break;
22538 +               }
22539 +       }
22540 +       return 0;
22541 +}
22542 +
22543 +
22544 +/*
22545 + *      argv [0] = vshelper_path;
22546 + *      argv [1] = action: "startup", "shutdown"
22547 + *      argv [2] = context identifier
22548 + *
22549 + *      envp [*] = type-specific parameters
22550 + */
22551 +
22552 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
22553 +{
22554 +       char id_buf[8], cmd_buf[16];
22555 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22556 +       char *envp[] = {"HOME=/", "TERM=linux",
22557 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22558 +
22559 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
22560 +               return 0;
22561 +
22562 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
22563 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22564 +
22565 +       switch (cmd) {
22566 +       case VSC_STARTUP:
22567 +               argv[1] = "startup";
22568 +               break;
22569 +       case VSC_SHUTDOWN:
22570 +               argv[1] = "shutdown";
22571 +               break;
22572 +       default:
22573 +               return 0;
22574 +       }
22575 +
22576 +       return do_vshelper(vshelper_path, argv, envp, 1);
22577 +}
22578 +
22579 +
22580 +/*
22581 + *      argv [0] = vshelper_path;
22582 + *      argv [1] = action: "netup", "netdown"
22583 + *      argv [2] = context identifier
22584 + *
22585 + *      envp [*] = type-specific parameters
22586 + */
22587 +
22588 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
22589 +{
22590 +       char id_buf[8], cmd_buf[16];
22591 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
22592 +       char *envp[] = {"HOME=/", "TERM=linux",
22593 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
22594 +
22595 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
22596 +               return 0;
22597 +
22598 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
22599 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
22600 +
22601 +       switch (cmd) {
22602 +       case VSC_NETUP:
22603 +               argv[1] = "netup";
22604 +               break;
22605 +       case VSC_NETDOWN:
22606 +               argv[1] = "netdown";
22607 +               break;
22608 +       default:
22609 +               return 0;
22610 +       }
22611 +
22612 +       return do_vshelper(vshelper_path, argv, envp, 1);
22613 +}
22614 +
22615 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
22616 --- linux-2.6.22.10/kernel/vserver/history.c    1970-01-01 01:00:00 +0100
22617 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/history.c 2007-08-15 22:13:54 +0200
22618 @@ -0,0 +1,258 @@
22619 +/*
22620 + *  kernel/vserver/history.c
22621 + *
22622 + *  Virtual Context History Backtrace
22623 + *
22624 + *  Copyright (C) 2004-2007  Herbert Pötzl
22625 + *
22626 + *  V0.01  basic structure
22627 + *  V0.02  hash/unhash and trace
22628 + *  V0.03  preemption fixes
22629 + *
22630 + */
22631 +
22632 +#include <linux/module.h>
22633 +#include <asm/uaccess.h>
22634 +
22635 +#include <linux/vserver/context.h>
22636 +#include <linux/vserver/debug.h>
22637 +#include <linux/vserver/debug_cmd.h>
22638 +#include <linux/vserver/history.h>
22639 +
22640 +
22641 +#ifdef CONFIG_VSERVER_HISTORY
22642 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
22643 +#else
22644 +#define VXH_SIZE       64
22645 +#endif
22646 +
22647 +struct _vx_history {
22648 +       unsigned int counter;
22649 +
22650 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
22651 +};
22652 +
22653 +
22654 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
22655 +
22656 +unsigned volatile int vxh_active = 1;
22657 +
22658 +static atomic_t sequence = ATOMIC_INIT(0);
22659 +
22660 +
22661 +/*     vxh_advance()
22662 +
22663 +       * requires disabled preemption                          */
22664 +
22665 +struct _vx_hist_entry *vxh_advance(void *loc)
22666 +{
22667 +       unsigned int cpu = smp_processor_id();
22668 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22669 +       struct _vx_hist_entry *entry;
22670 +       unsigned int index;
22671 +
22672 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
22673 +       entry = &hist->entry[index];
22674 +
22675 +       entry->seq = atomic_inc_return(&sequence);
22676 +       entry->loc = loc;
22677 +       return entry;
22678 +}
22679 +
22680 +EXPORT_SYMBOL_GPL(vxh_advance);
22681 +
22682 +
22683 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
22684 +
22685 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
22686 +
22687 +
22688 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
22689 +
22690 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
22691 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
22692 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
22693 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
22694 +
22695 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
22696 +{
22697 +       switch (e->type) {
22698 +       case VXH_THROW_OOPS:
22699 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
22700 +               break;
22701 +
22702 +       case VXH_GET_VX_INFO:
22703 +       case VXH_PUT_VX_INFO:
22704 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22705 +                       VXH_LOC_ARGS(e),
22706 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
22707 +                       VXH_VXI_ARGS(e));
22708 +               break;
22709 +
22710 +       case VXH_INIT_VX_INFO:
22711 +       case VXH_SET_VX_INFO:
22712 +       case VXH_CLR_VX_INFO:
22713 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22714 +                       VXH_LOC_ARGS(e),
22715 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
22716 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
22717 +                       VXH_VXI_ARGS(e), e->sc.data);
22718 +               break;
22719 +
22720 +       case VXH_CLAIM_VX_INFO:
22721 +       case VXH_RELEASE_VX_INFO:
22722 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
22723 +                       VXH_LOC_ARGS(e),
22724 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
22725 +                       VXH_VXI_ARGS(e), e->sc.data);
22726 +               break;
22727 +
22728 +       case VXH_ALLOC_VX_INFO:
22729 +       case VXH_DEALLOC_VX_INFO:
22730 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
22731 +                       VXH_LOC_ARGS(e),
22732 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
22733 +                       VXH_VXI_ARGS(e));
22734 +               break;
22735 +
22736 +       case VXH_HASH_VX_INFO:
22737 +       case VXH_UNHASH_VX_INFO:
22738 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
22739 +                       VXH_LOC_ARGS(e),
22740 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
22741 +                       VXH_VXI_ARGS(e));
22742 +               break;
22743 +
22744 +       case VXH_LOC_VX_INFO:
22745 +       case VXH_LOOKUP_VX_INFO:
22746 +       case VXH_CREATE_VX_INFO:
22747 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
22748 +                       VXH_LOC_ARGS(e),
22749 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
22750 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
22751 +                       e->ll.arg, VXH_VXI_ARGS(e));
22752 +               break;
22753 +       }
22754 +}
22755 +
22756 +static void __vxh_dump_history(void)
22757 +{
22758 +       unsigned int i, cpu;
22759 +
22760 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
22761 +               atomic_read(&sequence), NR_CPUS);
22762 +
22763 +       for (i = 0; i < VXH_SIZE; i++) {
22764 +               for_each_online_cpu(cpu) {
22765 +                       struct _vx_history *hist =
22766 +                               &per_cpu(vx_history_buffer, cpu);
22767 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
22768 +                       struct _vx_hist_entry *entry = &hist->entry[index];
22769 +
22770 +                       vxh_dump_entry(entry, cpu);
22771 +               }
22772 +       }
22773 +}
22774 +
22775 +void   vxh_dump_history(void)
22776 +{
22777 +       vxh_active = 0;
22778 +#ifdef CONFIG_SMP
22779 +       local_irq_enable();
22780 +       smp_send_stop();
22781 +       local_irq_disable();
22782 +#endif
22783 +       __vxh_dump_history();
22784 +}
22785 +
22786 +
22787 +/* vserver syscall commands below here */
22788 +
22789 +
22790 +int vc_dump_history(uint32_t id)
22791 +{
22792 +       vxh_active = 0;
22793 +       __vxh_dump_history();
22794 +       vxh_active = 1;
22795 +
22796 +       return 0;
22797 +}
22798 +
22799 +
22800 +int do_read_history(struct __user _vx_hist_entry *data,
22801 +       int cpu, uint32_t *index, uint32_t *count)
22802 +{
22803 +       int pos, ret = 0;
22804 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
22805 +       int end = hist->counter;
22806 +       int start = end - VXH_SIZE + 2;
22807 +       int idx = *index;
22808 +
22809 +       /* special case: get current pos */
22810 +       if (!*count) {
22811 +               *index = end;
22812 +               return 0;
22813 +       }
22814 +
22815 +       /* have we lost some data? */
22816 +       if (idx < start)
22817 +               idx = start;
22818 +
22819 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22820 +               struct _vx_hist_entry *entry =
22821 +                       &hist->entry[idx % VXH_SIZE];
22822 +
22823 +               /* send entry to userspace */
22824 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22825 +               if (ret)
22826 +                       break;
22827 +       }
22828 +       /* save new index and count */
22829 +       *index = idx;
22830 +       *count = pos;
22831 +       return ret ? ret : (*index < end);
22832 +}
22833 +
22834 +int vc_read_history(uint32_t id, void __user *data)
22835 +{
22836 +       struct vcmd_read_history_v0 vc_data;
22837 +       int ret;
22838 +
22839 +       if (id >= NR_CPUS)
22840 +               return -EINVAL;
22841 +
22842 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22843 +               return -EFAULT;
22844 +
22845 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
22846 +               id, &vc_data.index, &vc_data.count);
22847 +
22848 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22849 +               return -EFAULT;
22850 +       return ret;
22851 +}
22852 +
22853 +#ifdef CONFIG_COMPAT
22854 +
22855 +int vc_read_history_x32(uint32_t id, void __user *data)
22856 +{
22857 +       struct vcmd_read_history_v0_x32 vc_data;
22858 +       int ret;
22859 +
22860 +       if (id >= NR_CPUS)
22861 +               return -EINVAL;
22862 +
22863 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22864 +               return -EFAULT;
22865 +
22866 +       ret = do_read_history((struct __user _vx_hist_entry *)
22867 +               compat_ptr(vc_data.data_ptr),
22868 +               id, &vc_data.index, &vc_data.count);
22869 +
22870 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22871 +               return -EFAULT;
22872 +       return ret;
22873 +}
22874 +
22875 +#endif /* CONFIG_COMPAT */
22876 +
22877 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
22878 --- linux-2.6.22.10/kernel/vserver/inet.c       1970-01-01 01:00:00 +0100
22879 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/inet.c    2007-10-10 23:55:30 +0200
22880 @@ -0,0 +1,222 @@
22881 +
22882 +#include <linux/in.h>
22883 +#include <linux/inetdevice.h>
22884 +#include <linux/vs_inet6.h>
22885 +#include <linux/vserver/debug.h>
22886 +#include <net/route.h>
22887 +#include <net/addrconf.h>
22888 +
22889 +
22890 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22891 +{
22892 +       int ret = 0;
22893 +
22894 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22895 +               ret = 1;
22896 +       else {
22897 +               struct nx_addr_v4 *ptr;
22898 +
22899 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
22900 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22901 +                               ret = 1;
22902 +                               break;
22903 +                       }
22904 +               }
22905 +       }
22906 +
22907 +       vxdprintk(VXD_CBIT(net, 2),
22908 +               "nx_v4_addr_conflict(%p,%p): %d",
22909 +               nxi1, nxi2, ret);
22910 +
22911 +       return ret;
22912 +}
22913 +
22914 +
22915 +#ifdef CONFIG_IPV6
22916 +
22917 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
22918 +{
22919 +       int ret = 0;
22920 +
22921 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
22922 +               ret = 1;
22923 +       else {
22924 +               struct nx_addr_v6 *ptr;
22925 +
22926 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
22927 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
22928 +                               ret = 1;
22929 +                               break;
22930 +                       }
22931 +               }
22932 +       }
22933 +
22934 +       vxdprintk(VXD_CBIT(net, 2),
22935 +               "nx_v6_addr_conflict(%p,%p): %d",
22936 +               nxi1, nxi2, ret);
22937 +
22938 +       return ret;
22939 +}
22940 +
22941 +#endif
22942 +
22943 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22944 +{
22945 +       struct in_device *in_dev;
22946 +       struct in_ifaddr **ifap;
22947 +       struct in_ifaddr *ifa;
22948 +       int ret = 0;
22949 +
22950 +       if (!dev)
22951 +               goto out;
22952 +       in_dev = in_dev_get(dev);
22953 +       if (!in_dev)
22954 +               goto out;
22955 +
22956 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
22957 +               ifap = &ifa->ifa_next) {
22958 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
22959 +                       ret = 1;
22960 +                       break;
22961 +               }
22962 +       }
22963 +       in_dev_put(in_dev);
22964 +out:
22965 +       return ret;
22966 +}
22967 +
22968 +
22969 +#ifdef CONFIG_IPV6
22970 +
22971 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22972 +{
22973 +       struct inet6_dev *in_dev;
22974 +       struct inet6_ifaddr **ifap;
22975 +       struct inet6_ifaddr *ifa;
22976 +       int ret = 0;
22977 +
22978 +       if (!dev)
22979 +               goto out;
22980 +       in_dev = in6_dev_get(dev);
22981 +       if (!in_dev)
22982 +               goto out;
22983 +
22984 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
22985 +               ifap = &ifa->if_next) {
22986 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
22987 +                       ret = 1;
22988 +                       break;
22989 +               }
22990 +       }
22991 +       in6_dev_put(in_dev);
22992 +out:
22993 +       return ret;
22994 +}
22995 +
22996 +#endif
22997 +
22998 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22999 +{
23000 +       int ret = 1;
23001 +
23002 +       if (!nxi)
23003 +               goto out;
23004 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
23005 +               goto out;
23006 +#ifdef CONFIG_IPV6
23007 +       ret = 2;
23008 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
23009 +               goto out;
23010 +#endif
23011 +       ret = 0;
23012 +out:
23013 +       vxdprintk(VXD_CBIT(net, 3),
23014 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
23015 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
23016 +       return ret;
23017 +}
23018 +
23019 +int ip_v4_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
23020 +{
23021 +       if (!nxi)
23022 +               return 0;
23023 +
23024 +       /* FIXME: handle lback only case */
23025 +       if (!NX_IPV4(nxi))
23026 +               return -EPERM;
23027 +
23028 +       vxdprintk(VXD_CBIT(net, 4),
23029 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
23030 +               nxi, nxi ? nxi->nx_id : 0,
23031 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
23032 +
23033 +       /* single IP is unconditional */
23034 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
23035 +               (fl->fl4_src == INADDR_ANY))
23036 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
23037 +
23038 +       if (fl->fl4_src == INADDR_ANY) {
23039 +               struct nx_addr_v4 *ptr;
23040 +               __be32 found;
23041 +               int err;
23042 +
23043 +               err = __ip_route_output_key(rp, fl);
23044 +               if (!err) {
23045 +                       found = (*rp)->rt_src;
23046 +                       ip_rt_put(*rp);
23047 +                       vxdprintk(VXD_CBIT(net, 4),
23048 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
23049 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
23050 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
23051 +                               goto found;
23052 +               }
23053 +
23054 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
23055 +                       __be32 primary = ptr->ip[0].s_addr;
23056 +                       __be32 mask = ptr->mask.s_addr;
23057 +                       __be32 net = primary & mask;
23058 +
23059 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
23060 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
23061 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
23062 +                               NIPQUAD(mask), NIPQUAD(net));
23063 +                       if ((found & mask) != net)
23064 +                               continue;
23065 +
23066 +                       fl->fl4_src = primary;
23067 +                       err = __ip_route_output_key(rp, fl);
23068 +                       vxdprintk(VXD_CBIT(net, 4),
23069 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
23070 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
23071 +                       if (!err) {
23072 +                               found = (*rp)->rt_src;
23073 +                               ip_rt_put(*rp);
23074 +                               if (found == primary)
23075 +                                       goto found;
23076 +                       }
23077 +               }
23078 +               /* still no source ip? */
23079 +               found = LOOPBACK(fl->fl4_dst)
23080 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
23081 +       found:
23082 +               /* assign src ip to flow */
23083 +               fl->fl4_src = found;
23084 +
23085 +       } else {
23086 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
23087 +                       return -EPERM;
23088 +       }
23089 +
23090 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
23091 +               if (LOOPBACK(fl->fl4_dst))
23092 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
23093 +               if (LOOPBACK(fl->fl4_src))
23094 +                       fl->fl4_src = nxi->v4_lback.s_addr;
23095 +       } else if (LOOPBACK(fl->fl4_dst))
23096 +               return -EPERM;
23097 +
23098 +       return 0;
23099 +}
23100 +
23101 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
23102 +
23103 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
23104 --- linux-2.6.22.10/kernel/vserver/init.c       1970-01-01 01:00:00 +0100
23105 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/init.c    2007-08-15 22:15:36 +0200
23106 @@ -0,0 +1,45 @@
23107 +/*
23108 + *  linux/kernel/init.c
23109 + *
23110 + *  Virtual Server Init
23111 + *
23112 + *  Copyright (C) 2004-2007  Herbert Pötzl
23113 + *
23114 + *  V0.01  basic structure
23115 + *
23116 + */
23117 +
23118 +#include <linux/init.h>
23119 +
23120 +int    vserver_register_sysctl(void);
23121 +void   vserver_unregister_sysctl(void);
23122 +
23123 +
23124 +static int __init init_vserver(void)
23125 +{
23126 +       int ret = 0;
23127 +
23128 +#ifdef CONFIG_VSERVER_DEBUG
23129 +       vserver_register_sysctl();
23130 +#endif
23131 +       return ret;
23132 +}
23133 +
23134 +
23135 +static void __exit exit_vserver(void)
23136 +{
23137 +
23138 +#ifdef CONFIG_VSERVER_DEBUG
23139 +       vserver_unregister_sysctl();
23140 +#endif
23141 +       return;
23142 +}
23143 +
23144 +/* FIXME: GFP_ZONETYPES gone
23145 +long vx_slab[GFP_ZONETYPES]; */
23146 +long vx_area;
23147 +
23148 +
23149 +module_init(init_vserver);
23150 +module_exit(exit_vserver);
23151 +
23152 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
23153 --- linux-2.6.22.10/kernel/vserver/inode.c      1970-01-01 01:00:00 +0100
23154 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/inode.c   2007-09-11 17:57:41 +0200
23155 @@ -0,0 +1,409 @@
23156 +/*
23157 + *  linux/kernel/vserver/inode.c
23158 + *
23159 + *  Virtual Server: File System Support
23160 + *
23161 + *  Copyright (C) 2004-2007  Herbert Pötzl
23162 + *
23163 + *  V0.01  separated from vcontext V0.05
23164 + *  V0.02  moved to tag (instead of xid)
23165 + *
23166 + */
23167 +
23168 +#include <linux/tty.h>
23169 +#include <linux/proc_fs.h>
23170 +#include <linux/devpts_fs.h>
23171 +#include <linux/fs.h>
23172 +#include <linux/file.h>
23173 +#include <linux/mount.h>
23174 +#include <linux/parser.h>
23175 +#include <linux/vserver/inode.h>
23176 +#include <linux/vserver/inode_cmd.h>
23177 +#include <linux/vs_base.h>
23178 +#include <linux/vs_tag.h>
23179 +
23180 +#include <asm/uaccess.h>
23181 +
23182 +
23183 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
23184 +{
23185 +       struct proc_dir_entry *entry;
23186 +
23187 +       if (!in || !in->i_sb)
23188 +               return -ESRCH;
23189 +
23190 +       *flags = IATTR_TAG
23191 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
23192 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
23193 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
23194 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
23195 +
23196 +       if (S_ISDIR(in->i_mode))
23197 +               *mask |= IATTR_BARRIER;
23198 +
23199 +       if (IS_TAGGED(in)) {
23200 +               *tag = in->i_tag;
23201 +               *mask |= IATTR_TAG;
23202 +       }
23203 +
23204 +       switch (in->i_sb->s_magic) {
23205 +       case PROC_SUPER_MAGIC:
23206 +               entry = PROC_I(in)->pde;
23207 +
23208 +               /* check for specific inodes? */
23209 +               if (entry)
23210 +                       *mask |= IATTR_FLAGS;
23211 +               if (entry)
23212 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
23213 +               else
23214 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
23215 +               break;
23216 +
23217 +       case DEVPTS_SUPER_MAGIC:
23218 +               *tag = in->i_tag;
23219 +               *mask |= IATTR_TAG;
23220 +               break;
23221 +
23222 +       default:
23223 +               break;
23224 +       }
23225 +       return 0;
23226 +}
23227 +
23228 +int vc_get_iattr(void __user *data)
23229 +{
23230 +       struct nameidata nd;
23231 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
23232 +       int ret;
23233 +
23234 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23235 +               return -EFAULT;
23236 +
23237 +       ret = user_path_walk_link(vc_data.name, &nd);
23238 +       if (!ret) {
23239 +               ret = __vc_get_iattr(nd.dentry->d_inode,
23240 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23241 +               path_release(&nd);
23242 +       }
23243 +       if (ret)
23244 +               return ret;
23245 +
23246 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23247 +               ret = -EFAULT;
23248 +       return ret;
23249 +}
23250 +
23251 +#ifdef CONFIG_COMPAT
23252 +
23253 +int vc_get_iattr_x32(void __user *data)
23254 +{
23255 +       struct nameidata nd;
23256 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
23257 +       int ret;
23258 +
23259 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23260 +               return -EFAULT;
23261 +
23262 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23263 +       if (!ret) {
23264 +               ret = __vc_get_iattr(nd.dentry->d_inode,
23265 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23266 +               path_release(&nd);
23267 +       }
23268 +       if (ret)
23269 +               return ret;
23270 +
23271 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23272 +               ret = -EFAULT;
23273 +       return ret;
23274 +}
23275 +
23276 +#endif /* CONFIG_COMPAT */
23277 +
23278 +
23279 +int vc_fget_iattr(uint32_t fd, void __user *data)
23280 +{
23281 +       struct file *filp;
23282 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
23283 +       int ret;
23284 +
23285 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23286 +               return -EFAULT;
23287 +
23288 +       filp = fget(fd);
23289 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23290 +               return -EBADF;
23291 +
23292 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
23293 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
23294 +
23295 +       fput(filp);
23296 +
23297 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23298 +               ret = -EFAULT;
23299 +       return ret;
23300 +}
23301 +
23302 +
23303 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
23304 +{
23305 +       struct inode *in = de->d_inode;
23306 +       int error = 0, is_proc = 0, has_tag = 0;
23307 +       struct iattr attr = { 0 };
23308 +
23309 +       if (!in || !in->i_sb)
23310 +               return -ESRCH;
23311 +
23312 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
23313 +       if ((*mask & IATTR_FLAGS) && !is_proc)
23314 +               return -EINVAL;
23315 +
23316 +       has_tag = IS_TAGGED(in) ||
23317 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
23318 +       if ((*mask & IATTR_TAG) && !has_tag)
23319 +               return -EINVAL;
23320 +
23321 +       mutex_lock(&in->i_mutex);
23322 +       if (*mask & IATTR_TAG) {
23323 +               attr.ia_tag = *tag;
23324 +               attr.ia_valid |= ATTR_TAG;
23325 +       }
23326 +
23327 +       if (*mask & IATTR_FLAGS) {
23328 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
23329 +               unsigned int iflags = PROC_I(in)->vx_flags;
23330 +
23331 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
23332 +                       | (*flags & IATTR_FLAGS);
23333 +               PROC_I(in)->vx_flags = iflags;
23334 +               if (entry)
23335 +                       entry->vx_flags = iflags;
23336 +       }
23337 +
23338 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
23339 +               if (*mask & IATTR_IMMUTABLE) {
23340 +                       if (*flags & IATTR_IMMUTABLE)
23341 +                               in->i_flags |= S_IMMUTABLE;
23342 +                       else
23343 +                               in->i_flags &= ~S_IMMUTABLE;
23344 +               }
23345 +               if (*mask & IATTR_IUNLINK) {
23346 +                       if (*flags & IATTR_IUNLINK)
23347 +                               in->i_flags |= S_IUNLINK;
23348 +                       else
23349 +                               in->i_flags &= ~S_IUNLINK;
23350 +               }
23351 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
23352 +                       if (*flags & IATTR_BARRIER)
23353 +                               in->i_flags |= S_BARRIER;
23354 +                       else
23355 +                               in->i_flags &= ~S_BARRIER;
23356 +               }
23357 +               if (in->i_op && in->i_op->sync_flags) {
23358 +                       error = in->i_op->sync_flags(in);
23359 +                       if (error)
23360 +                               goto out;
23361 +               }
23362 +       }
23363 +
23364 +       if (attr.ia_valid) {
23365 +               if (in->i_op && in->i_op->setattr)
23366 +                       error = in->i_op->setattr(de, &attr);
23367 +               else {
23368 +                       error = inode_change_ok(in, &attr);
23369 +                       if (!error)
23370 +                               error = inode_setattr(in, &attr);
23371 +               }
23372 +       }
23373 +
23374 +out:
23375 +       mutex_unlock(&in->i_mutex);
23376 +       return error;
23377 +}
23378 +
23379 +int vc_set_iattr(void __user *data)
23380 +{
23381 +       struct nameidata nd;
23382 +       struct vcmd_ctx_iattr_v1 vc_data;
23383 +       int ret;
23384 +
23385 +       if (!capable(CAP_LINUX_IMMUTABLE))
23386 +               return -EPERM;
23387 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23388 +               return -EFAULT;
23389 +
23390 +       ret = user_path_walk_link(vc_data.name, &nd);
23391 +       if (!ret) {
23392 +               ret = __vc_set_iattr(nd.dentry,
23393 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23394 +               path_release(&nd);
23395 +       }
23396 +
23397 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23398 +               ret = -EFAULT;
23399 +       return ret;
23400 +}
23401 +
23402 +#ifdef CONFIG_COMPAT
23403 +
23404 +int vc_set_iattr_x32(void __user *data)
23405 +{
23406 +       struct nameidata nd;
23407 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
23408 +       int ret;
23409 +
23410 +       if (!capable(CAP_LINUX_IMMUTABLE))
23411 +               return -EPERM;
23412 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23413 +               return -EFAULT;
23414 +
23415 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
23416 +       if (!ret) {
23417 +               ret = __vc_set_iattr(nd.dentry,
23418 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
23419 +               path_release(&nd);
23420 +       }
23421 +
23422 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23423 +               ret = -EFAULT;
23424 +       return ret;
23425 +}
23426 +
23427 +#endif /* CONFIG_COMPAT */
23428 +
23429 +int vc_fset_iattr(uint32_t fd, void __user *data)
23430 +{
23431 +       struct file *filp;
23432 +       struct vcmd_ctx_fiattr_v0 vc_data;
23433 +       int ret;
23434 +
23435 +       if (!capable(CAP_LINUX_IMMUTABLE))
23436 +               return -EPERM;
23437 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23438 +               return -EFAULT;
23439 +
23440 +       filp = fget(fd);
23441 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
23442 +               return -EBADF;
23443 +
23444 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
23445 +               &vc_data.flags, &vc_data.mask);
23446 +
23447 +       fput(filp);
23448 +
23449 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23450 +               return -EFAULT;
23451 +       return ret;
23452 +}
23453 +
23454 +
23455 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
23456 +
23457 +static match_table_t tokens = {
23458 +       {Opt_notagcheck, "notagcheck"},
23459 +#ifdef CONFIG_PROPAGATE
23460 +       {Opt_notag, "notag"},
23461 +       {Opt_tag, "tag"},
23462 +       {Opt_tagid, "tagid=%u"},
23463 +#endif
23464 +       {Opt_err, NULL}
23465 +};
23466 +
23467 +
23468 +static void __dx_parse_remove(char *string, char *opt)
23469 +{
23470 +       char *p = strstr(string, opt);
23471 +       char *q = p;
23472 +
23473 +       if (p) {
23474 +               while (*q != '\0' && *q != ',')
23475 +                       q++;
23476 +               while (*q)
23477 +                       *p++ = *q++;
23478 +               while (*p)
23479 +                       *p++ = '\0';
23480 +       }
23481 +}
23482 +
23483 +static inline
23484 +int __dx_parse_tag(char *string, tag_t *tag, int remove)
23485 +{
23486 +       substring_t args[MAX_OPT_ARGS];
23487 +       int token, option = 0;
23488 +
23489 +       if (!string)
23490 +               return 0;
23491 +
23492 +       token = match_token(string, tokens, args);
23493 +
23494 +       vxdprintk(VXD_CBIT(tag, 7),
23495 +               "dx_parse_tag(»%s«): %d:#%d",
23496 +               string, token, option);
23497 +
23498 +       switch (token) {
23499 +       case Opt_tag:
23500 +               if (tag)
23501 +                       *tag = 0;
23502 +               if (remove)
23503 +                       __dx_parse_remove(string, "tag");
23504 +               return MNT_TAGID;
23505 +       case Opt_notag:
23506 +               if (remove)
23507 +                       __dx_parse_remove(string, "notag");
23508 +               return MNT_NOTAG;
23509 +       case Opt_notagcheck:
23510 +               if (remove)
23511 +                       __dx_parse_remove(string, "notagcheck");
23512 +               return MNT_NOTAGCHECK;
23513 +       case Opt_tagid:
23514 +               if (tag && !match_int(args, &option))
23515 +                       *tag = option;
23516 +               if (remove)
23517 +                       __dx_parse_remove(string, "tagid");
23518 +               return MNT_TAGID;
23519 +       }
23520 +       return 0;
23521 +}
23522 +
23523 +int dx_parse_tag(char *string, tag_t *tag, int remove)
23524 +{
23525 +       int retval, flags = 0;
23526 +
23527 +       while ((retval = __dx_parse_tag(string, tag, remove)))
23528 +               flags |= retval;
23529 +       return flags;
23530 +}
23531 +
23532 +#ifdef CONFIG_PROPAGATE
23533 +
23534 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
23535 +{
23536 +       tag_t new_tag = 0;
23537 +       struct vfsmount *mnt;
23538 +       int propagate;
23539 +
23540 +       if (!nd)
23541 +               return;
23542 +       mnt = nd->mnt;
23543 +       if (!mnt)
23544 +               return;
23545 +
23546 +       propagate = (mnt->mnt_flags & MNT_TAGID);
23547 +       if (propagate)
23548 +               new_tag = mnt->mnt_tag;
23549 +
23550 +       vxdprintk(VXD_CBIT(tag, 7),
23551 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
23552 +               inode, inode->i_ino, inode->i_tag,
23553 +               new_tag, (propagate) ? 1 : 0);
23554 +
23555 +       if (propagate)
23556 +               inode->i_tag = new_tag;
23557 +}
23558 +
23559 +#include <linux/module.h>
23560 +
23561 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
23562 +
23563 +#endif /* CONFIG_PROPAGATE */
23564 +
23565 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
23566 --- linux-2.6.22.10/kernel/vserver/limit.c      1970-01-01 01:00:00 +0100
23567 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit.c   2007-08-19 00:08:19 +0200
23568 @@ -0,0 +1,318 @@
23569 +/*
23570 + *  linux/kernel/vserver/limit.c
23571 + *
23572 + *  Virtual Server: Context Limits
23573 + *
23574 + *  Copyright (C) 2004-2007  Herbert Pötzl
23575 + *
23576 + *  V0.01  broken out from vcontext V0.05
23577 + *  V0.02  changed vcmds to vxi arg
23578 + *
23579 + */
23580 +
23581 +#include <linux/module.h>
23582 +#include <linux/vs_limit.h>
23583 +#include <linux/vserver/limit.h>
23584 +#include <linux/vserver/limit_cmd.h>
23585 +
23586 +#include <asm/uaccess.h>
23587 +
23588 +
23589 +const char *vlimit_name[NUM_LIMITS] = {
23590 +       [RLIMIT_CPU]            = "CPU",
23591 +       [RLIMIT_RSS]            = "RSS",
23592 +       [RLIMIT_NPROC]          = "NPROC",
23593 +       [RLIMIT_NOFILE]         = "NOFILE",
23594 +       [RLIMIT_MEMLOCK]        = "VML",
23595 +       [RLIMIT_AS]             = "VM",
23596 +       [RLIMIT_LOCKS]          = "LOCKS",
23597 +       [RLIMIT_SIGPENDING]     = "SIGP",
23598 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
23599 +
23600 +       [VLIMIT_NSOCK]          = "NSOCK",
23601 +       [VLIMIT_OPENFD]         = "OPENFD",
23602 +       [VLIMIT_ANON]           = "ANON",
23603 +       [VLIMIT_SHMEM]          = "SHMEM",
23604 +       [VLIMIT_DENTRY]         = "DENTRY",
23605 +};
23606 +
23607 +EXPORT_SYMBOL_GPL(vlimit_name);
23608 +
23609 +#define MASK_ENTRY(x)  (1 << (x))
23610 +
23611 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
23612 +               /* minimum */
23613 +       0
23614 +       ,       /* softlimit */
23615 +       MASK_ENTRY( RLIMIT_RSS          ) |
23616 +       MASK_ENTRY( VLIMIT_ANON         ) |
23617 +       0
23618 +       ,       /* maximum */
23619 +       MASK_ENTRY( RLIMIT_RSS          ) |
23620 +       MASK_ENTRY( RLIMIT_NPROC        ) |
23621 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
23622 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
23623 +       MASK_ENTRY( RLIMIT_AS           ) |
23624 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
23625 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
23626 +
23627 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
23628 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
23629 +       MASK_ENTRY( VLIMIT_ANON         ) |
23630 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
23631 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
23632 +       0
23633 +};
23634 +               /* accounting only */
23635 +uint32_t account_mask =
23636 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
23637 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
23638 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
23639 +       0;
23640 +
23641 +
23642 +static int is_valid_vlimit(int id)
23643 +{
23644 +       uint32_t mask = vlimit_mask.minimum |
23645 +               vlimit_mask.softlimit | vlimit_mask.maximum;
23646 +       return mask & (1 << id);
23647 +}
23648 +
23649 +static int is_accounted_vlimit(int id)
23650 +{
23651 +       if (is_valid_vlimit(id))
23652 +               return 1;
23653 +       return account_mask & (1 << id);
23654 +}
23655 +
23656 +
23657 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
23658 +{
23659 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
23660 +       return VX_VLIM(limit);
23661 +}
23662 +
23663 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
23664 +{
23665 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
23666 +       return VX_VLIM(limit);
23667 +}
23668 +
23669 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
23670 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
23671 +{
23672 +       if (!is_valid_vlimit(id))
23673 +               return -EINVAL;
23674 +
23675 +       if (minimum)
23676 +               *minimum = CRLIM_UNSET;
23677 +       if (softlimit)
23678 +               *softlimit = vc_get_soft(vxi, id);
23679 +       if (maximum)
23680 +               *maximum = vc_get_hard(vxi, id);
23681 +       return 0;
23682 +}
23683 +
23684 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
23685 +{
23686 +       struct vcmd_ctx_rlimit_v0 vc_data;
23687 +       int ret;
23688 +
23689 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23690 +               return -EFAULT;
23691 +
23692 +       ret = do_get_rlimit(vxi, vc_data.id,
23693 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23694 +       if (ret)
23695 +               return ret;
23696 +
23697 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23698 +               return -EFAULT;
23699 +       return 0;
23700 +}
23701 +
23702 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
23703 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
23704 +{
23705 +       if (!is_valid_vlimit(id))
23706 +               return -EINVAL;
23707 +
23708 +       if (maximum != CRLIM_KEEP)
23709 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
23710 +       if (softlimit != CRLIM_KEEP)
23711 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
23712 +
23713 +       /* clamp soft limit */
23714 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
23715 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
23716 +
23717 +       return 0;
23718 +}
23719 +
23720 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
23721 +{
23722 +       struct vcmd_ctx_rlimit_v0 vc_data;
23723 +
23724 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23725 +               return -EFAULT;
23726 +
23727 +       return do_set_rlimit(vxi, vc_data.id,
23728 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23729 +}
23730 +
23731 +#ifdef CONFIG_IA32_EMULATION
23732 +
23733 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
23734 +{
23735 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23736 +
23737 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23738 +               return -EFAULT;
23739 +
23740 +       return do_set_rlimit(vxi, vc_data.id,
23741 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
23742 +}
23743 +
23744 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
23745 +{
23746 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
23747 +       int ret;
23748 +
23749 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23750 +               return -EFAULT;
23751 +
23752 +       ret = do_get_rlimit(vxi, vc_data.id,
23753 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
23754 +       if (ret)
23755 +               return ret;
23756 +
23757 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23758 +               return -EFAULT;
23759 +       return 0;
23760 +}
23761 +
23762 +#endif /* CONFIG_IA32_EMULATION */
23763 +
23764 +
23765 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
23766 +{
23767 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
23768 +               return -EFAULT;
23769 +       return 0;
23770 +}
23771 +
23772 +
23773 +static inline void vx_reset_minmax(struct _vx_limit *limit)
23774 +{
23775 +       rlim_t value;
23776 +       int lim;
23777 +
23778 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23779 +               value = __rlim_get(limit, lim);
23780 +               __rlim_rmax(limit, lim) = value;
23781 +               __rlim_rmin(limit, lim) = value;
23782 +       }
23783 +}
23784 +
23785 +
23786 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
23787 +{
23788 +       vx_reset_minmax(&vxi->limit);
23789 +       return 0;
23790 +}
23791 +
23792 +
23793 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
23794 +{
23795 +       struct vcmd_rlimit_stat_v0 vc_data;
23796 +       struct _vx_limit *limit = &vxi->limit;
23797 +       int id;
23798 +
23799 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23800 +               return -EFAULT;
23801 +
23802 +       id = vc_data.id;
23803 +       if (!is_accounted_vlimit(id))
23804 +               return -EINVAL;
23805 +
23806 +       vx_limit_fixup(limit, id);
23807 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
23808 +       vc_data.value = __rlim_get(limit, id);
23809 +       vc_data.minimum = __rlim_rmin(limit, id);
23810 +       vc_data.maximum = __rlim_rmax(limit, id);
23811 +
23812 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23813 +               return -EFAULT;
23814 +       return 0;
23815 +}
23816 +
23817 +
23818 +void vx_vsi_meminfo(struct sysinfo *val)
23819 +{
23820 +       struct vx_info *vxi = current->vx_info;
23821 +       unsigned long totalram, freeram;
23822 +       rlim_t v;
23823 +
23824 +       /* we blindly accept the max */
23825 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23826 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
23827 +
23828 +       /* total minus used equals free */
23829 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23830 +       freeram = (v < totalram) ? totalram - v : 0;
23831 +
23832 +       val->totalram = totalram;
23833 +       val->freeram = freeram;
23834 +       val->bufferram = 0;
23835 +       val->totalhigh = 0;
23836 +       val->freehigh = 0;
23837 +       return;
23838 +}
23839 +
23840 +void vx_vsi_swapinfo(struct sysinfo *val)
23841 +{
23842 +       struct vx_info *vxi = current->vx_info;
23843 +       unsigned long totalswap, freeswap;
23844 +       rlim_t v, w;
23845 +
23846 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23847 +       if (v == RLIM_INFINITY) {
23848 +               val->freeswap = val->totalswap;
23849 +               return;
23850 +       }
23851 +
23852 +       /* we blindly accept the max */
23853 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
23854 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
23855 +
23856 +       /* currently 'used' swap */
23857 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23858 +       w -= (w > v) ? v : w;
23859 +
23860 +       /* total minus used equals free */
23861 +       freeswap = (w < totalswap) ? totalswap - w : 0;
23862 +
23863 +       val->totalswap = totalswap;
23864 +       val->freeswap = freeswap;
23865 +       return;
23866 +}
23867 +
23868 +
23869 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
23870 +{
23871 +       struct vx_info *vxi = mm->mm_vx_info;
23872 +       unsigned long points;
23873 +       rlim_t v, w;
23874 +
23875 +       if (!vxi)
23876 +               return 0;
23877 +
23878 +       points = vxi->vx_badness_bias;
23879 +
23880 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
23881 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
23882 +       points += (v > w) ? (v - w) : 0;
23883 +
23884 +       return points;
23885 +}
23886 +
23887 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
23888 --- linux-2.6.22.10/kernel/vserver/limit_init.h 1970-01-01 01:00:00 +0100
23889 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit_init.h      2007-10-25 17:05:55 +0200
23890 @@ -0,0 +1,33 @@
23891 +
23892 +
23893 +static inline void vx_info_init_limit(struct _vx_limit *limit)
23894 +{
23895 +       int lim;
23896 +
23897 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23898 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
23899 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
23900 +               __rlim_set(limit, lim, 0);
23901 +               atomic_set(&__rlim_lhit(limit, lim), 0);
23902 +               __rlim_rmin(limit, lim) = 0;
23903 +               __rlim_rmax(limit, lim) = 0;
23904 +       }
23905 +}
23906 +
23907 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
23908 +{
23909 +#ifdef CONFIG_VSERVER_WARN
23910 +       rlim_t value;
23911 +       int lim;
23912 +
23913 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
23914 +               if ((1 << lim) & VLIM_NOCHECK)
23915 +                       continue;
23916 +               value = __rlim_get(limit, lim);
23917 +               vxwprintk_xid(value,
23918 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
23919 +                       limit, vlimit_name[lim], lim, (long)value);
23920 +       }
23921 +#endif
23922 +}
23923 +
23924 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
23925 --- linux-2.6.22.10/kernel/vserver/limit_proc.h 1970-01-01 01:00:00 +0100
23926 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/limit_proc.h      2007-08-05 20:53:13 +0200
23927 @@ -0,0 +1,57 @@
23928 +#ifndef _VX_LIMIT_PROC_H
23929 +#define _VX_LIMIT_PROC_H
23930 +
23931 +#include <linux/vserver/limit_int.h>
23932 +
23933 +
23934 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
23935 +#define VX_LIMIT_TOP   \
23936 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
23937 +
23938 +#define VX_LIMIT_ARG(r)                                \
23939 +       (unsigned long)__rlim_get(limit, r),    \
23940 +       (unsigned long)__rlim_rmin(limit, r),   \
23941 +       (unsigned long)__rlim_rmax(limit, r),   \
23942 +       VX_VLIM(__rlim_soft(limit, r)),         \
23943 +       VX_VLIM(__rlim_hard(limit, r)),         \
23944 +       atomic_read(&__rlim_lhit(limit, r))
23945 +
23946 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
23947 +{
23948 +       vx_limit_fixup(limit, -1);
23949 +       return sprintf(buffer, VX_LIMIT_TOP
23950 +               "PROC"  VX_LIMIT_FMT
23951 +               "VM"    VX_LIMIT_FMT
23952 +               "VML"   VX_LIMIT_FMT
23953 +               "RSS"   VX_LIMIT_FMT
23954 +               "ANON"  VX_LIMIT_FMT
23955 +               "RMAP"  VX_LIMIT_FMT
23956 +               "FILES" VX_LIMIT_FMT
23957 +               "OFD"   VX_LIMIT_FMT
23958 +               "LOCKS" VX_LIMIT_FMT
23959 +               "SOCK"  VX_LIMIT_FMT
23960 +               "MSGQ"  VX_LIMIT_FMT
23961 +               "SHM"   VX_LIMIT_FMT
23962 +               "SEMA"  VX_LIMIT_FMT
23963 +               "SEMS"  VX_LIMIT_FMT
23964 +               "DENT"  VX_LIMIT_FMT,
23965 +               VX_LIMIT_ARG(RLIMIT_NPROC),
23966 +               VX_LIMIT_ARG(RLIMIT_AS),
23967 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
23968 +               VX_LIMIT_ARG(RLIMIT_RSS),
23969 +               VX_LIMIT_ARG(VLIMIT_ANON),
23970 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
23971 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
23972 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
23973 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
23974 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
23975 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
23976 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
23977 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
23978 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
23979 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
23980 +}
23981 +
23982 +#endif /* _VX_LIMIT_PROC_H */
23983 +
23984 +
23985 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
23986 --- linux-2.6.22.10/kernel/vserver/monitor.c    1970-01-01 01:00:00 +0100
23987 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/monitor.c 2007-08-15 23:18:20 +0200
23988 @@ -0,0 +1,138 @@
23989 +/*
23990 + *  kernel/vserver/monitor.c
23991 + *
23992 + *  Virtual Context Scheduler Monitor
23993 + *
23994 + *  Copyright (C) 2006-2007 Herbert Pötzl
23995 + *
23996 + *  V0.01  basic design
23997 + *
23998 + */
23999 +
24000 +#include <linux/module.h>
24001 +#include <linux/jiffies.h>
24002 +#include <asm/uaccess.h>
24003 +#include <asm/atomic.h>
24004 +
24005 +#include <linux/vserver/monitor.h>
24006 +#include <linux/vserver/debug_cmd.h>
24007 +
24008 +
24009 +#ifdef CONFIG_VSERVER_MONITOR
24010 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
24011 +#else
24012 +#define VXM_SIZE       64
24013 +#endif
24014 +
24015 +struct _vx_monitor {
24016 +       unsigned int counter;
24017 +
24018 +       struct _vx_mon_entry entry[VXM_SIZE+1];
24019 +};
24020 +
24021 +
24022 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
24023 +
24024 +unsigned volatile int vxm_active = 1;
24025 +
24026 +static atomic_t sequence = ATOMIC_INIT(0);
24027 +
24028 +
24029 +/*     vxm_advance()
24030 +
24031 +       * requires disabled preemption                          */
24032 +
24033 +struct _vx_mon_entry *vxm_advance(int cpu)
24034 +{
24035 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24036 +       struct _vx_mon_entry *entry;
24037 +       unsigned int index;
24038 +
24039 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
24040 +       entry = &mon->entry[index];
24041 +
24042 +       entry->ev.seq = atomic_inc_return(&sequence);
24043 +       entry->ev.jif = jiffies;
24044 +       return entry;
24045 +}
24046 +
24047 +EXPORT_SYMBOL_GPL(vxm_advance);
24048 +
24049 +
24050 +int do_read_monitor(struct __user _vx_mon_entry *data,
24051 +       int cpu, uint32_t *index, uint32_t *count)
24052 +{
24053 +       int pos, ret = 0;
24054 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
24055 +       int end = mon->counter;
24056 +       int start = end - VXM_SIZE + 2;
24057 +       int idx = *index;
24058 +
24059 +       /* special case: get current pos */
24060 +       if (!*count) {
24061 +               *index = end;
24062 +               return 0;
24063 +       }
24064 +
24065 +       /* have we lost some data? */
24066 +       if (idx < start)
24067 +               idx = start;
24068 +
24069 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
24070 +               struct _vx_mon_entry *entry =
24071 +                       &mon->entry[idx % VXM_SIZE];
24072 +
24073 +               /* send entry to userspace */
24074 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
24075 +               if (ret)
24076 +                       break;
24077 +       }
24078 +       /* save new index and count */
24079 +       *index = idx;
24080 +       *count = pos;
24081 +       return ret ? ret : (*index < end);
24082 +}
24083 +
24084 +int vc_read_monitor(uint32_t id, void __user *data)
24085 +{
24086 +       struct vcmd_read_monitor_v0 vc_data;
24087 +       int ret;
24088 +
24089 +       if (id >= NR_CPUS)
24090 +               return -EINVAL;
24091 +
24092 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24093 +               return -EFAULT;
24094 +
24095 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
24096 +               id, &vc_data.index, &vc_data.count);
24097 +
24098 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24099 +               return -EFAULT;
24100 +       return ret;
24101 +}
24102 +
24103 +#ifdef CONFIG_COMPAT
24104 +
24105 +int vc_read_monitor_x32(uint32_t id, void __user *data)
24106 +{
24107 +       struct vcmd_read_monitor_v0_x32 vc_data;
24108 +       int ret;
24109 +
24110 +       if (id >= NR_CPUS)
24111 +               return -EINVAL;
24112 +
24113 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24114 +               return -EFAULT;
24115 +
24116 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
24117 +               compat_ptr(vc_data.data_ptr),
24118 +               id, &vc_data.index, &vc_data.count);
24119 +
24120 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24121 +               return -EFAULT;
24122 +       return ret;
24123 +}
24124 +
24125 +#endif /* CONFIG_COMPAT */
24126 +
24127 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
24128 --- linux-2.6.22.10/kernel/vserver/network.c    1970-01-01 01:00:00 +0100
24129 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/network.c 2007-10-05 14:54:36 +0200
24130 @@ -0,0 +1,862 @@
24131 +/*
24132 + *  linux/kernel/vserver/network.c
24133 + *
24134 + *  Virtual Server: Network Support
24135 + *
24136 + *  Copyright (C) 2003-2007  Herbert Pötzl
24137 + *
24138 + *  V0.01  broken out from vcontext V0.05
24139 + *  V0.02  cleaned up implementation
24140 + *  V0.03  added equiv nx commands
24141 + *  V0.04  switch to RCU based hash
24142 + *  V0.05  and back to locking again
24143 + *  V0.06  changed vcmds to nxi arg
24144 + *  V0.07  have __create claim() the nxi
24145 + *
24146 + */
24147 +
24148 +#include <linux/err.h>
24149 +#include <linux/slab.h>
24150 +#include <linux/rcupdate.h>
24151 +
24152 +#include <linux/vs_network.h>
24153 +#include <linux/vserver/network_cmd.h>
24154 +
24155 +
24156 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
24157 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
24158 +
24159 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
24160 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
24161 +
24162 +
24163 +static int __init init_network(void)
24164 +{
24165 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
24166 +               sizeof(struct nx_addr_v4), 0, SLAB_PANIC, NULL, NULL);
24167 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
24168 +               sizeof(struct nx_addr_v6), 0, SLAB_PANIC, NULL, NULL);
24169 +       return 0;
24170 +}
24171 +
24172 +
24173 +/*     __alloc_nx_addr_v4()                                    */
24174 +
24175 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
24176 +{
24177 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
24178 +               nx_addr_v4_cachep, GFP_KERNEL);
24179 +
24180 +       if (!IS_ERR(nxa))
24181 +               memset(nxa, 0, sizeof(*nxa));
24182 +       return nxa;
24183 +}
24184 +
24185 +/*     __dealloc_nx_addr_v4()                                  */
24186 +
24187 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
24188 +{
24189 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
24190 +}
24191 +
24192 +/*     __dealloc_nx_addr_v4_all()                              */
24193 +
24194 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
24195 +{
24196 +       while (nxa) {
24197 +               struct nx_addr_v4 *next = nxa->next;
24198 +
24199 +               __dealloc_nx_addr_v4(nxa);
24200 +               nxa = next;
24201 +       }
24202 +}
24203 +
24204 +
24205 +#ifdef CONFIG_IPV6
24206 +
24207 +/*     __alloc_nx_addr_v6()                                    */
24208 +
24209 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
24210 +{
24211 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
24212 +               nx_addr_v6_cachep, GFP_KERNEL);
24213 +
24214 +       if (!IS_ERR(nxa))
24215 +               memset(nxa, 0, sizeof(*nxa));
24216 +       return nxa;
24217 +}
24218 +
24219 +/*     __dealloc_nx_addr_v6()                                  */
24220 +
24221 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
24222 +{
24223 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
24224 +}
24225 +
24226 +/*     __dealloc_nx_addr_v6_all()                              */
24227 +
24228 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
24229 +{
24230 +       while (nxa) {
24231 +               struct nx_addr_v6 *next = nxa->next;
24232 +
24233 +               __dealloc_nx_addr_v6(nxa);
24234 +               nxa = next;
24235 +       }
24236 +}
24237 +
24238 +#endif /* CONFIG_IPV6 */
24239 +
24240 +
24241 +/*     __alloc_nx_info()
24242 +
24243 +       * allocate an initialized nx_info struct
24244 +       * doesn't make it visible (hash)                        */
24245 +
24246 +static struct nx_info *__alloc_nx_info(nid_t nid)
24247 +{
24248 +       struct nx_info *new = NULL;
24249 +
24250 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
24251 +
24252 +       /* would this benefit from a slab cache? */
24253 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
24254 +       if (!new)
24255 +               return 0;
24256 +
24257 +       memset(new, 0, sizeof(struct nx_info));
24258 +       new->nx_id = nid;
24259 +       INIT_HLIST_NODE(&new->nx_hlist);
24260 +       atomic_set(&new->nx_usecnt, 0);
24261 +       atomic_set(&new->nx_tasks, 0);
24262 +       new->nx_state = 0;
24263 +
24264 +       new->nx_flags = NXF_INIT_SET;
24265 +
24266 +       /* rest of init goes here */
24267 +
24268 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
24269 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
24270 +
24271 +       vxdprintk(VXD_CBIT(nid, 0),
24272 +               "alloc_nx_info(%d) = %p", nid, new);
24273 +       atomic_inc(&nx_global_ctotal);
24274 +       return new;
24275 +}
24276 +
24277 +/*     __dealloc_nx_info()
24278 +
24279 +       * final disposal of nx_info                             */
24280 +
24281 +static void __dealloc_nx_info(struct nx_info *nxi)
24282 +{
24283 +       vxdprintk(VXD_CBIT(nid, 0),
24284 +               "dealloc_nx_info(%p)", nxi);
24285 +
24286 +       nxi->nx_hlist.next = LIST_POISON1;
24287 +       nxi->nx_id = -1;
24288 +
24289 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24290 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24291 +
24292 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
24293 +
24294 +       nxi->nx_state |= NXS_RELEASED;
24295 +       kfree(nxi);
24296 +       atomic_dec(&nx_global_ctotal);
24297 +}
24298 +
24299 +static void __shutdown_nx_info(struct nx_info *nxi)
24300 +{
24301 +       nxi->nx_state |= NXS_SHUTDOWN;
24302 +       vs_net_change(nxi, VSC_NETDOWN);
24303 +}
24304 +
24305 +/*     exported stuff                                          */
24306 +
24307 +void free_nx_info(struct nx_info *nxi)
24308 +{
24309 +       /* context shutdown is mandatory */
24310 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
24311 +
24312 +       /* context must not be hashed */
24313 +       BUG_ON(nxi->nx_state & NXS_HASHED);
24314 +
24315 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
24316 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24317 +
24318 +       __dealloc_nx_info(nxi);
24319 +}
24320 +
24321 +
24322 +void __nx_set_lback(struct nx_info *nxi)
24323 +{
24324 +       int nid = nxi->nx_id;
24325 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
24326 +
24327 +       nxi->v4_lback.s_addr = lback;
24328 +}
24329 +
24330 +extern int __nx_inet_add_lback(__be32 addr);
24331 +extern int __nx_inet_del_lback(__be32 addr);
24332 +
24333 +
24334 +/*     hash table for nx_info hash */
24335 +
24336 +#define NX_HASH_SIZE   13
24337 +
24338 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
24339 +
24340 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
24341 +
24342 +
24343 +static inline unsigned int __hashval(nid_t nid)
24344 +{
24345 +       return (nid % NX_HASH_SIZE);
24346 +}
24347 +
24348 +
24349 +
24350 +/*     __hash_nx_info()
24351 +
24352 +       * add the nxi to the global hash table
24353 +       * requires the hash_lock to be held                     */
24354 +
24355 +static inline void __hash_nx_info(struct nx_info *nxi)
24356 +{
24357 +       struct hlist_head *head;
24358 +
24359 +       vxd_assert_lock(&nx_info_hash_lock);
24360 +       vxdprintk(VXD_CBIT(nid, 4),
24361 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
24362 +
24363 +       /* context must not be hashed */
24364 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
24365 +
24366 +       nxi->nx_state |= NXS_HASHED;
24367 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
24368 +       hlist_add_head(&nxi->nx_hlist, head);
24369 +       atomic_inc(&nx_global_cactive);
24370 +}
24371 +
24372 +/*     __unhash_nx_info()
24373 +
24374 +       * remove the nxi from the global hash table
24375 +       * requires the hash_lock to be held                     */
24376 +
24377 +static inline void __unhash_nx_info(struct nx_info *nxi)
24378 +{
24379 +       vxd_assert_lock(&nx_info_hash_lock);
24380 +       vxdprintk(VXD_CBIT(nid, 4),
24381 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
24382 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
24383 +
24384 +       /* context must be hashed */
24385 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
24386 +       /* but without tasks */
24387 +       BUG_ON(atomic_read(&nxi->nx_tasks));
24388 +
24389 +       nxi->nx_state &= ~NXS_HASHED;
24390 +       hlist_del(&nxi->nx_hlist);
24391 +       atomic_dec(&nx_global_cactive);
24392 +}
24393 +
24394 +
24395 +/*     __lookup_nx_info()
24396 +
24397 +       * requires the hash_lock to be held
24398 +       * doesn't increment the nx_refcnt                       */
24399 +
24400 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
24401 +{
24402 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
24403 +       struct hlist_node *pos;
24404 +       struct nx_info *nxi;
24405 +
24406 +       vxd_assert_lock(&nx_info_hash_lock);
24407 +       hlist_for_each(pos, head) {
24408 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24409 +
24410 +               if (nxi->nx_id == nid)
24411 +                       goto found;
24412 +       }
24413 +       nxi = NULL;
24414 +found:
24415 +       vxdprintk(VXD_CBIT(nid, 0),
24416 +               "__lookup_nx_info(#%u): %p[#%u]",
24417 +               nid, nxi, nxi ? nxi->nx_id : 0);
24418 +       return nxi;
24419 +}
24420 +
24421 +
24422 +/*     __create_nx_info()
24423 +
24424 +       * create the requested context
24425 +       * get(), claim() and hash it                            */
24426 +
24427 +static struct nx_info *__create_nx_info(int id)
24428 +{
24429 +       struct nx_info *new, *nxi = NULL;
24430 +
24431 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
24432 +
24433 +       if (!(new = __alloc_nx_info(id)))
24434 +               return ERR_PTR(-ENOMEM);
24435 +
24436 +       /* required to make dynamic xids unique */
24437 +       spin_lock(&nx_info_hash_lock);
24438 +
24439 +       /* static context requested */
24440 +       if ((nxi = __lookup_nx_info(id))) {
24441 +               vxdprintk(VXD_CBIT(nid, 0),
24442 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
24443 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24444 +                       nxi = ERR_PTR(-EBUSY);
24445 +               else
24446 +                       nxi = ERR_PTR(-EEXIST);
24447 +               goto out_unlock;
24448 +       }
24449 +       /* new context */
24450 +       vxdprintk(VXD_CBIT(nid, 0),
24451 +               "create_nx_info(%d) = %p (new)", id, new);
24452 +       claim_nx_info(new, NULL);
24453 +       __nx_set_lback(new);
24454 +       __hash_nx_info(get_nx_info(new));
24455 +       nxi = new, new = NULL;
24456 +
24457 +out_unlock:
24458 +       spin_unlock(&nx_info_hash_lock);
24459 +       if (new)
24460 +               __dealloc_nx_info(new);
24461 +       return nxi;
24462 +}
24463 +
24464 +
24465 +
24466 +/*     exported stuff                                          */
24467 +
24468 +
24469 +void unhash_nx_info(struct nx_info *nxi)
24470 +{
24471 +       __shutdown_nx_info(nxi);
24472 +       spin_lock(&nx_info_hash_lock);
24473 +       __unhash_nx_info(nxi);
24474 +       spin_unlock(&nx_info_hash_lock);
24475 +}
24476 +
24477 +/*     lookup_nx_info()
24478 +
24479 +       * search for a nx_info and get() it
24480 +       * negative id means current                             */
24481 +
24482 +struct nx_info *lookup_nx_info(int id)
24483 +{
24484 +       struct nx_info *nxi = NULL;
24485 +
24486 +       if (id < 0) {
24487 +               nxi = get_nx_info(current->nx_info);
24488 +       } else if (id > 1) {
24489 +               spin_lock(&nx_info_hash_lock);
24490 +               nxi = get_nx_info(__lookup_nx_info(id));
24491 +               spin_unlock(&nx_info_hash_lock);
24492 +       }
24493 +       return nxi;
24494 +}
24495 +
24496 +/*     nid_is_hashed()
24497 +
24498 +       * verify that nid is still hashed                       */
24499 +
24500 +int nid_is_hashed(nid_t nid)
24501 +{
24502 +       int hashed;
24503 +
24504 +       spin_lock(&nx_info_hash_lock);
24505 +       hashed = (__lookup_nx_info(nid) != NULL);
24506 +       spin_unlock(&nx_info_hash_lock);
24507 +       return hashed;
24508 +}
24509 +
24510 +
24511 +#ifdef CONFIG_PROC_FS
24512 +
24513 +/*     get_nid_list()
24514 +
24515 +       * get a subset of hashed nids for proc
24516 +       * assumes size is at least one                          */
24517 +
24518 +int get_nid_list(int index, unsigned int *nids, int size)
24519 +{
24520 +       int hindex, nr_nids = 0;
24521 +
24522 +       /* only show current and children */
24523 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
24524 +               if (index > 0)
24525 +                       return 0;
24526 +               nids[nr_nids] = nx_current_nid();
24527 +               return 1;
24528 +       }
24529 +
24530 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
24531 +               struct hlist_head *head = &nx_info_hash[hindex];
24532 +               struct hlist_node *pos;
24533 +
24534 +               spin_lock(&nx_info_hash_lock);
24535 +               hlist_for_each(pos, head) {
24536 +                       struct nx_info *nxi;
24537 +
24538 +                       if (--index > 0)
24539 +                               continue;
24540 +
24541 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
24542 +                       nids[nr_nids] = nxi->nx_id;
24543 +                       if (++nr_nids >= size) {
24544 +                               spin_unlock(&nx_info_hash_lock);
24545 +                               goto out;
24546 +                       }
24547 +               }
24548 +               /* keep the lock time short */
24549 +               spin_unlock(&nx_info_hash_lock);
24550 +       }
24551 +out:
24552 +       return nr_nids;
24553 +}
24554 +#endif
24555 +
24556 +
24557 +/*
24558 + *     migrate task to new network
24559 + *     gets nxi, puts old_nxi on change
24560 + */
24561 +
24562 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
24563 +{
24564 +       struct nx_info *old_nxi;
24565 +       int ret = 0;
24566 +
24567 +       if (!p || !nxi)
24568 +               BUG();
24569 +
24570 +       vxdprintk(VXD_CBIT(nid, 5),
24571 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
24572 +               p, nxi, nxi->nx_id,
24573 +               atomic_read(&nxi->nx_usecnt),
24574 +               atomic_read(&nxi->nx_tasks));
24575 +
24576 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
24577 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
24578 +               return -EACCES;
24579 +
24580 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
24581 +               return -EFAULT;
24582 +
24583 +       /* maybe disallow this completely? */
24584 +       old_nxi = task_get_nx_info(p);
24585 +       if (old_nxi == nxi)
24586 +               goto out;
24587 +
24588 +       task_lock(p);
24589 +       if (old_nxi)
24590 +               clr_nx_info(&p->nx_info);
24591 +       claim_nx_info(nxi, p);
24592 +       set_nx_info(&p->nx_info, nxi);
24593 +       p->nid = nxi->nx_id;
24594 +       task_unlock(p);
24595 +
24596 +       vxdprintk(VXD_CBIT(nid, 5),
24597 +               "moved task %p into nxi:%p[#%d]",
24598 +               p, nxi, nxi->nx_id);
24599 +
24600 +       if (old_nxi)
24601 +               release_nx_info(old_nxi, p);
24602 +       ret = 0;
24603 +out:
24604 +       put_nx_info(old_nxi);
24605 +       return ret;
24606 +}
24607 +
24608 +
24609 +void nx_set_persistent(struct nx_info *nxi)
24610 +{
24611 +       vxdprintk(VXD_CBIT(nid, 6),
24612 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
24613 +
24614 +       get_nx_info(nxi);
24615 +       claim_nx_info(nxi, NULL);
24616 +}
24617 +
24618 +void nx_clear_persistent(struct nx_info *nxi)
24619 +{
24620 +       vxdprintk(VXD_CBIT(nid, 6),
24621 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
24622 +
24623 +       release_nx_info(nxi, NULL);
24624 +       put_nx_info(nxi);
24625 +}
24626 +
24627 +void nx_update_persistent(struct nx_info *nxi)
24628 +{
24629 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
24630 +               nx_set_persistent(nxi);
24631 +       else
24632 +               nx_clear_persistent(nxi);
24633 +}
24634 +
24635 +/* vserver syscall commands below here */
24636 +
24637 +/* taks nid and nx_info functions */
24638 +
24639 +#include <asm/uaccess.h>
24640 +
24641 +
24642 +int vc_task_nid(uint32_t id)
24643 +{
24644 +       nid_t nid;
24645 +
24646 +       if (id) {
24647 +               struct task_struct *tsk;
24648 +
24649 +               read_lock(&tasklist_lock);
24650 +               tsk = find_task_by_real_pid(id);
24651 +               nid = (tsk) ? tsk->nid : -ESRCH;
24652 +               read_unlock(&tasklist_lock);
24653 +       } else
24654 +               nid = nx_current_nid();
24655 +       return nid;
24656 +}
24657 +
24658 +
24659 +int vc_nx_info(struct nx_info *nxi, void __user *data)
24660 +{
24661 +       struct vcmd_nx_info_v0 vc_data;
24662 +
24663 +       vc_data.nid = nxi->nx_id;
24664 +
24665 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24666 +               return -EFAULT;
24667 +       return 0;
24668 +}
24669 +
24670 +
24671 +/* network functions */
24672 +
24673 +int vc_net_create(uint32_t nid, void __user *data)
24674 +{
24675 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
24676 +       struct nx_info *new_nxi;
24677 +       int ret;
24678 +
24679 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24680 +               return -EFAULT;
24681 +
24682 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
24683 +               return -EINVAL;
24684 +
24685 +       new_nxi = __create_nx_info(nid);
24686 +       if (IS_ERR(new_nxi))
24687 +               return PTR_ERR(new_nxi);
24688 +
24689 +       /* initial flags */
24690 +       new_nxi->nx_flags = vc_data.flagword;
24691 +
24692 +       ret = -ENOEXEC;
24693 +       if (vs_net_change(new_nxi, VSC_NETUP))
24694 +               goto out;
24695 +
24696 +       ret = nx_migrate_task(current, new_nxi);
24697 +       if (ret)
24698 +               goto out;
24699 +
24700 +       /* return context id on success */
24701 +       ret = new_nxi->nx_id;
24702 +
24703 +       /* get a reference for persistent contexts */
24704 +       if ((vc_data.flagword & NXF_PERSISTENT))
24705 +               nx_set_persistent(new_nxi);
24706 +out:
24707 +       release_nx_info(new_nxi, NULL);
24708 +       put_nx_info(new_nxi);
24709 +       return ret;
24710 +}
24711 +
24712 +
24713 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
24714 +{
24715 +       return nx_migrate_task(current, nxi);
24716 +}
24717 +
24718 +
24719 +
24720 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
24721 +       uint16_t type, uint16_t flags)
24722 +{
24723 +       struct nx_addr_v4 *nxa = &nxi->v4;
24724 +
24725 +       if (NX_IPV4(nxi)) {
24726 +               /* locate last entry */
24727 +               for (; nxa->next; nxa = nxa->next);
24728 +               nxa->next = __alloc_nx_addr_v4();
24729 +               nxa = nxa->next;
24730 +
24731 +               if (IS_ERR(nxa))
24732 +                       return PTR_ERR(nxa);
24733 +       }
24734 +
24735 +       if (nxi->v4.next)
24736 +               /* remove single ip for ip list */
24737 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
24738 +
24739 +       nxa->ip[0].s_addr = ip;
24740 +       nxa->ip[1].s_addr = ip2;
24741 +       nxa->mask.s_addr = mask;
24742 +       nxa->type = type;
24743 +       nxa->flags = flags;
24744 +       return 0;
24745 +}
24746 +
24747 +
24748 +int vc_net_add(struct nx_info *nxi, void __user *data)
24749 +{
24750 +       struct vcmd_net_addr_v0 vc_data;
24751 +       int index, ret = 0;
24752 +
24753 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24754 +               return -EFAULT;
24755 +
24756 +       switch (vc_data.type) {
24757 +       case NXA_TYPE_IPV4:
24758 +               if ((vc_data.count < 1) || (vc_data.count > 4))
24759 +                       return -EINVAL;
24760 +
24761 +               index = 0;
24762 +               while (index < vc_data.count) {
24763 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
24764 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
24765 +                       if (ret)
24766 +                               return ret;
24767 +                       index++;
24768 +               }
24769 +               ret = index;
24770 +               break;
24771 +
24772 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
24773 +               nxi->v4_bcast = vc_data.ip[0];
24774 +               ret = 1;
24775 +               break;
24776 +
24777 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
24778 +               nxi->v4_lback = vc_data.ip[0];
24779 +               ret = 1;
24780 +               break;
24781 +
24782 +       default:
24783 +               ret = -EINVAL;
24784 +               break;
24785 +       }
24786 +       return ret;
24787 +}
24788 +
24789 +int vc_net_remove(struct nx_info *nxi, void __user *data)
24790 +{
24791 +       struct vcmd_net_addr_v0 vc_data;
24792 +
24793 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24794 +               return -EFAULT;
24795 +
24796 +       switch (vc_data.type) {
24797 +       case NXA_TYPE_ANY:
24798 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24799 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24800 +               break;
24801 +
24802 +       default:
24803 +               return -EINVAL;
24804 +       }
24805 +       return 0;
24806 +}
24807 +
24808 +
24809 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
24810 +{
24811 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24812 +
24813 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24814 +               return -EFAULT;
24815 +
24816 +       switch (vc_data.type) {
24817 +       case NXA_TYPE_ADDR:
24818 +       case NXA_TYPE_RANGE:
24819 +       case NXA_TYPE_MASK:
24820 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
24821 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
24822 +
24823 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
24824 +               nxi->v4_bcast = vc_data.ip;
24825 +               break;
24826 +
24827 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
24828 +               nxi->v4_lback = vc_data.ip;
24829 +               break;
24830 +
24831 +       default:
24832 +               return -EINVAL;
24833 +       }
24834 +       return 0;
24835 +}
24836 +
24837 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
24838 +{
24839 +       struct vcmd_net_addr_ipv4_v1 vc_data;
24840 +
24841 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24842 +               return -EFAULT;
24843 +
24844 +       switch (vc_data.type) {
24845 +/*     case NXA_TYPE_ADDR:
24846 +               break;          */
24847 +
24848 +       case NXA_TYPE_ANY:
24849 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
24850 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
24851 +               break;
24852 +
24853 +       default:
24854 +               return -EINVAL;
24855 +       }
24856 +       return 0;
24857 +}
24858 +
24859 +
24860 +#ifdef CONFIG_IPV6
24861 +
24862 +int do_add_v6_addr(struct nx_info *nxi,
24863 +       struct in6_addr *ip, struct in6_addr *mask,
24864 +       uint32_t prefix, uint16_t type, uint16_t flags)
24865 +{
24866 +       struct nx_addr_v6 *nxa = &nxi->v6;
24867 +
24868 +       if (NX_IPV6(nxi)) {
24869 +               /* locate last entry */
24870 +               for (; nxa->next; nxa = nxa->next);
24871 +               nxa->next = __alloc_nx_addr_v6();
24872 +               nxa = nxa->next;
24873 +
24874 +               if (IS_ERR(nxa))
24875 +                       return PTR_ERR(nxa);
24876 +       }
24877 +
24878 +       nxa->ip = *ip;
24879 +       nxa->mask = *mask;
24880 +       nxa->prefix = prefix;
24881 +       nxa->type = type;
24882 +       nxa->flags = flags;
24883 +       return 0;
24884 +}
24885 +
24886 +
24887 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
24888 +{
24889 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24890 +
24891 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24892 +               return -EFAULT;
24893 +
24894 +       switch (vc_data.type) {
24895 +       case NXA_TYPE_ADDR:
24896 +       case NXA_TYPE_MASK:
24897 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
24898 +                       vc_data.prefix, vc_data.type, vc_data.flags);
24899 +       default:
24900 +               return -EINVAL;
24901 +       }
24902 +       return 0;
24903 +}
24904 +
24905 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
24906 +{
24907 +       struct vcmd_net_addr_ipv6_v1 vc_data;
24908 +
24909 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24910 +               return -EFAULT;
24911 +
24912 +       switch (vc_data.type) {
24913 +       case NXA_TYPE_ANY:
24914 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
24915 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
24916 +               break;
24917 +
24918 +       default:
24919 +               return -EINVAL;
24920 +       }
24921 +       return 0;
24922 +}
24923 +
24924 +#endif /* CONFIG_IPV6 */
24925 +
24926 +
24927 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
24928 +{
24929 +       struct vcmd_net_flags_v0 vc_data;
24930 +
24931 +       vc_data.flagword = nxi->nx_flags;
24932 +
24933 +       /* special STATE flag handling */
24934 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
24935 +
24936 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24937 +               return -EFAULT;
24938 +       return 0;
24939 +}
24940 +
24941 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
24942 +{
24943 +       struct vcmd_net_flags_v0 vc_data;
24944 +       uint64_t mask, trigger;
24945 +
24946 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24947 +               return -EFAULT;
24948 +
24949 +       /* special STATE flag handling */
24950 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
24951 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
24952 +
24953 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
24954 +               vc_data.flagword, mask);
24955 +       if (trigger & NXF_PERSISTENT)
24956 +               nx_update_persistent(nxi);
24957 +
24958 +       return 0;
24959 +}
24960 +
24961 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
24962 +{
24963 +       struct vcmd_net_caps_v0 vc_data;
24964 +
24965 +       vc_data.ncaps = nxi->nx_ncaps;
24966 +       vc_data.cmask = ~0ULL;
24967 +
24968 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24969 +               return -EFAULT;
24970 +       return 0;
24971 +}
24972 +
24973 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
24974 +{
24975 +       struct vcmd_net_caps_v0 vc_data;
24976 +
24977 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24978 +               return -EFAULT;
24979 +
24980 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
24981 +               vc_data.ncaps, vc_data.cmask);
24982 +       return 0;
24983 +}
24984 +
24985 +
24986 +#include <linux/module.h>
24987 +
24988 +module_init(init_network);
24989 +
24990 +EXPORT_SYMBOL_GPL(free_nx_info);
24991 +EXPORT_SYMBOL_GPL(unhash_nx_info);
24992 +
24993 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
24994 --- linux-2.6.22.10/kernel/vserver/proc.c       1970-01-01 01:00:00 +0100
24995 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/proc.c    2007-10-05 14:54:36 +0200
24996 @@ -0,0 +1,1065 @@
24997 +/*
24998 + *  linux/kernel/vserver/proc.c
24999 + *
25000 + *  Virtual Context Support
25001 + *
25002 + *  Copyright (C) 2003-2007  Herbert Pötzl
25003 + *
25004 + *  V0.01  basic structure
25005 + *  V0.02  adaptation vs1.3.0
25006 + *  V0.03  proc permissions
25007 + *  V0.04  locking/generic
25008 + *  V0.05  next generation procfs
25009 + *  V0.06  inode validation
25010 + *  V0.07  generic rewrite vid
25011 + *  V0.08  remove inode type
25012 + *
25013 + */
25014 +
25015 +#include <linux/proc_fs.h>
25016 +#include <asm/unistd.h>
25017 +
25018 +#include <linux/vs_context.h>
25019 +#include <linux/vs_network.h>
25020 +#include <linux/vs_cvirt.h>
25021 +#include <linux/vs_inet.h>
25022 +#include <linux/vs_inet6.h>
25023 +
25024 +#include <linux/vserver/global.h>
25025 +
25026 +#include "cvirt_proc.h"
25027 +#include "cacct_proc.h"
25028 +#include "limit_proc.h"
25029 +#include "sched_proc.h"
25030 +#include "vci_config.h"
25031 +
25032 +static struct proc_dir_entry *proc_virtual;
25033 +
25034 +static struct proc_dir_entry *proc_virtnet;
25035 +
25036 +
25037 +/* first the actual feeds */
25038 +
25039 +
25040 +static int proc_vci(char *buffer)
25041 +{
25042 +       return sprintf(buffer,
25043 +               "VCIVersion:\t%04x:%04x\n"
25044 +               "VCISyscall:\t%d\n"
25045 +               "VCIKernel:\t%08x\n",
25046 +               VCI_VERSION >> 16,
25047 +               VCI_VERSION & 0xFFFF,
25048 +               __NR_vserver,
25049 +               vci_kernel_config());
25050 +}
25051 +
25052 +static int proc_virtual_info(char *buffer)
25053 +{
25054 +       return proc_vci(buffer);
25055 +}
25056 +
25057 +static int proc_virtual_status(char *buffer)
25058 +{
25059 +       return sprintf(buffer,
25060 +               "#CTotal:\t%d\n"
25061 +               "#CActive:\t%d\n"
25062 +               "#NSProxy:\t%d\t%d %d %d %d\n",
25063 +               atomic_read(&vx_global_ctotal),
25064 +               atomic_read(&vx_global_cactive),
25065 +               atomic_read(&vs_global_nsproxy),
25066 +               atomic_read(&vs_global_fs),
25067 +               atomic_read(&vs_global_mnt_ns),
25068 +               atomic_read(&vs_global_uts_ns),
25069 +               atomic_read(&vs_global_ipc_ns));
25070 +}
25071 +
25072 +
25073 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
25074 +{
25075 +       int length;
25076 +
25077 +       length = sprintf(buffer,
25078 +               "ID:\t%d\n"
25079 +               "Info:\t%p\n"
25080 +               "Init:\t%d\n"
25081 +               "OOM:\t%lld\n",
25082 +               vxi->vx_id,
25083 +               vxi,
25084 +               vxi->vx_initpid,
25085 +               vxi->vx_badness_bias);
25086 +       return length;
25087 +}
25088 +
25089 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
25090 +{
25091 +       int length;
25092 +
25093 +       length = sprintf(buffer,
25094 +               "UseCnt:\t%d\n"
25095 +               "Tasks:\t%d\n"
25096 +               "Flags:\t%016llx\n"
25097 +               "BCaps:\t%016llx\n"
25098 +               "CCaps:\t%016llx\n"
25099 +               "Spaces:\t%08lx\n",
25100 +               atomic_read(&vxi->vx_usecnt),
25101 +               atomic_read(&vxi->vx_tasks),
25102 +               (unsigned long long)vxi->vx_flags,
25103 +               (unsigned long long)vxi->vx_bcaps,
25104 +               (unsigned long long)vxi->vx_ccaps,
25105 +               vxi->vx_nsmask);
25106 +       return length;
25107 +}
25108 +
25109 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
25110 +{
25111 +       return vx_info_proc_limit(&vxi->limit, buffer);
25112 +}
25113 +
25114 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
25115 +{
25116 +       int cpu, length;
25117 +
25118 +       length = vx_info_proc_sched(&vxi->sched, buffer);
25119 +       for_each_online_cpu(cpu) {
25120 +               length += vx_info_proc_sched_pc(
25121 +                       &vx_per_cpu(vxi, sched_pc, cpu),
25122 +                       buffer + length, cpu);
25123 +       }
25124 +       return length;
25125 +}
25126 +
25127 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
25128 +{
25129 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
25130 +}
25131 +
25132 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
25133 +{
25134 +       int cpu, length;
25135 +
25136 +       vx_update_load(vxi);
25137 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
25138 +       for_each_online_cpu(cpu) {
25139 +               length += vx_info_proc_cvirt_pc(
25140 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
25141 +                       buffer + length, cpu);
25142 +       }
25143 +       return length;
25144 +}
25145 +
25146 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
25147 +{
25148 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
25149 +}
25150 +
25151 +
25152 +static int proc_virtnet_info(char *buffer)
25153 +{
25154 +       return proc_vci(buffer);
25155 +}
25156 +
25157 +static int proc_virtnet_status(char *buffer)
25158 +{
25159 +       return sprintf(buffer,
25160 +               "#CTotal:\t%d\n"
25161 +               "#CActive:\t%d\n",
25162 +               atomic_read(&nx_global_ctotal),
25163 +               atomic_read(&nx_global_cactive));
25164 +}
25165 +
25166 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
25167 +{
25168 +       struct nx_addr_v4 *v4a;
25169 +#ifdef CONFIG_IPV6
25170 +       struct nx_addr_v6 *v6a;
25171 +#endif
25172 +       int length, i;
25173 +
25174 +       length = sprintf(buffer,
25175 +               "ID:\t%d\n"
25176 +               "Info:\t%p\n"
25177 +               "Bcast:\t" NIPQUAD_FMT "\n"
25178 +               "Lback:\t" NIPQUAD_FMT "\n",
25179 +               nxi->nx_id,
25180 +               nxi,
25181 +               NIPQUAD(nxi->v4_bcast.s_addr),
25182 +               NIPQUAD(nxi->v4_lback.s_addr));
25183 +
25184 +       if (!NX_IPV4(nxi))
25185 +               goto skip_v4;
25186 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
25187 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
25188 +                       i, NXAV4(v4a));
25189 +skip_v4:
25190 +#ifdef CONFIG_IPV6
25191 +       if (!NX_IPV6(nxi))
25192 +               goto skip_v6;
25193 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
25194 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
25195 +                       i, NXAV6(v6a));
25196 +skip_v6:
25197 +#endif
25198 +       return length;
25199 +}
25200 +
25201 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
25202 +{
25203 +       int length;
25204 +
25205 +       length = sprintf(buffer,
25206 +               "UseCnt:\t%d\n"
25207 +               "Tasks:\t%d\n"
25208 +               "Flags:\t%016llx\n"
25209 +               "NCaps:\t%016llx\n",
25210 +               atomic_read(&nxi->nx_usecnt),
25211 +               atomic_read(&nxi->nx_tasks),
25212 +               (unsigned long long)nxi->nx_flags,
25213 +               (unsigned long long)nxi->nx_ncaps);
25214 +       return length;
25215 +}
25216 +
25217 +
25218 +
25219 +/* here the inode helpers */
25220 +
25221 +struct vs_entry {
25222 +       int len;
25223 +       char *name;
25224 +       mode_t mode;
25225 +       struct inode_operations *iop;
25226 +       struct file_operations *fop;
25227 +       union proc_op op;
25228 +};
25229 +
25230 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
25231 +{
25232 +       struct inode *inode = new_inode(sb);
25233 +
25234 +       if (!inode)
25235 +               goto out;
25236 +
25237 +       inode->i_mode = p->mode;
25238 +       if (p->iop)
25239 +               inode->i_op = p->iop;
25240 +       if (p->fop)
25241 +               inode->i_fop = p->fop;
25242 +
25243 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
25244 +       inode->i_flags |= S_IMMUTABLE;
25245 +
25246 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
25247 +
25248 +       inode->i_uid = 0;
25249 +       inode->i_gid = 0;
25250 +       inode->i_tag = 0;
25251 +out:
25252 +       return inode;
25253 +}
25254 +
25255 +static struct dentry *vs_proc_instantiate(struct inode *dir,
25256 +       struct dentry *dentry, int id, void *ptr)
25257 +{
25258 +       struct vs_entry *p = ptr;
25259 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
25260 +       struct dentry *error = ERR_PTR(-EINVAL);
25261 +
25262 +       if (!inode)
25263 +               goto out;
25264 +
25265 +       PROC_I(inode)->op = p->op;
25266 +       PROC_I(inode)->fd = id;
25267 +       d_add(dentry, inode);
25268 +       error = NULL;
25269 +out:
25270 +       return error;
25271 +}
25272 +
25273 +/* Lookups */
25274 +
25275 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
25276 +
25277 +/*
25278 + * Fill a directory entry.
25279 + *
25280 + * If possible create the dcache entry and derive our inode number and
25281 + * file type from dcache entry.
25282 + *
25283 + * Since all of the proc inode numbers are dynamically generated, the inode
25284 + * numbers do not exist until the inode is cache.  This means creating the
25285 + * the dcache entry in readdir is necessary to keep the inode numbers
25286 + * reported by readdir in sync with the inode numbers reported
25287 + * by stat.
25288 + */
25289 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
25290 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
25291 +{
25292 +       struct dentry *child, *dir = filp->f_dentry;
25293 +       struct inode *inode;
25294 +       struct qstr qname;
25295 +       ino_t ino = 0;
25296 +       unsigned type = DT_UNKNOWN;
25297 +
25298 +       qname.name = name;
25299 +       qname.len  = len;
25300 +       qname.hash = full_name_hash(name, len);
25301 +
25302 +       child = d_lookup(dir, &qname);
25303 +       if (!child) {
25304 +               struct dentry *new;
25305 +               new = d_alloc(dir, &qname);
25306 +               if (new) {
25307 +                       child = instantiate(dir->d_inode, new, id, ptr);
25308 +                       if (child)
25309 +                               dput(new);
25310 +                       else
25311 +                               child = new;
25312 +               }
25313 +       }
25314 +       if (!child || IS_ERR(child) || !child->d_inode)
25315 +               goto end_instantiate;
25316 +       inode = child->d_inode;
25317 +       if (inode) {
25318 +               ino = inode->i_ino;
25319 +               type = inode->i_mode >> 12;
25320 +       }
25321 +       dput(child);
25322 +end_instantiate:
25323 +       if (!ino)
25324 +               ino = find_inode_number(dir, &qname);
25325 +       if (!ino)
25326 +               ino = 1;
25327 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
25328 +}
25329 +
25330 +
25331 +
25332 +/* get and revalidate vx_info/xid */
25333 +
25334 +static inline
25335 +struct vx_info *get_proc_vx_info(struct inode *inode)
25336 +{
25337 +       return lookup_vx_info(PROC_I(inode)->fd);
25338 +}
25339 +
25340 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
25341 +{
25342 +       struct inode *inode = dentry->d_inode;
25343 +       xid_t xid = PROC_I(inode)->fd;
25344 +
25345 +       if (!xid || xid_is_hashed(xid))
25346 +               return 1;
25347 +       d_drop(dentry);
25348 +       return 0;
25349 +}
25350 +
25351 +
25352 +/* get and revalidate nx_info/nid */
25353 +
25354 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
25355 +{
25356 +       struct inode *inode = dentry->d_inode;
25357 +       nid_t nid = PROC_I(inode)->fd;
25358 +
25359 +       if (!nid || nid_is_hashed(nid))
25360 +               return 1;
25361 +       d_drop(dentry);
25362 +       return 0;
25363 +}
25364 +
25365 +
25366 +
25367 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
25368 +
25369 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
25370 +                         size_t count, loff_t *ppos)
25371 +{
25372 +       struct inode *inode = file->f_dentry->d_inode;
25373 +       unsigned long page;
25374 +       ssize_t length = 0;
25375 +
25376 +       if (count > PROC_BLOCK_SIZE)
25377 +               count = PROC_BLOCK_SIZE;
25378 +
25379 +       /* fade that out as soon as stable */
25380 +       WARN_ON(PROC_I(inode)->fd);
25381 +
25382 +       if (!(page = __get_free_page(GFP_KERNEL)))
25383 +               return -ENOMEM;
25384 +
25385 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
25386 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
25387 +
25388 +       if (length >= 0)
25389 +               length = simple_read_from_buffer(buf, count, ppos,
25390 +                       (char *)page, length);
25391 +
25392 +       free_page(page);
25393 +       return length;
25394 +}
25395 +
25396 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
25397 +                         size_t count, loff_t *ppos)
25398 +{
25399 +       struct inode *inode = file->f_dentry->d_inode;
25400 +       struct vx_info *vxi = NULL;
25401 +       xid_t xid = PROC_I(inode)->fd;
25402 +       unsigned long page;
25403 +       ssize_t length = 0;
25404 +
25405 +       if (count > PROC_BLOCK_SIZE)
25406 +               count = PROC_BLOCK_SIZE;
25407 +
25408 +       /* fade that out as soon as stable */
25409 +       WARN_ON(!xid);
25410 +       vxi = lookup_vx_info(xid);
25411 +       if (!vxi)
25412 +               goto out;
25413 +
25414 +       length = -ENOMEM;
25415 +       if (!(page = __get_free_page(GFP_KERNEL)))
25416 +               goto out_put;
25417 +
25418 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
25419 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
25420 +
25421 +       if (length >= 0)
25422 +               length = simple_read_from_buffer(buf, count, ppos,
25423 +                       (char *)page, length);
25424 +
25425 +       free_page(page);
25426 +out_put:
25427 +       put_vx_info(vxi);
25428 +out:
25429 +       return length;
25430 +}
25431 +
25432 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
25433 +                         size_t count, loff_t *ppos)
25434 +{
25435 +       struct inode *inode = file->f_dentry->d_inode;
25436 +       struct nx_info *nxi = NULL;
25437 +       nid_t nid = PROC_I(inode)->fd;
25438 +       unsigned long page;
25439 +       ssize_t length = 0;
25440 +
25441 +       if (count > PROC_BLOCK_SIZE)
25442 +               count = PROC_BLOCK_SIZE;
25443 +
25444 +       /* fade that out as soon as stable */
25445 +       WARN_ON(!nid);
25446 +       nxi = lookup_nx_info(nid);
25447 +       if (!nxi)
25448 +               goto out;
25449 +
25450 +       length = -ENOMEM;
25451 +       if (!(page = __get_free_page(GFP_KERNEL)))
25452 +               goto out_put;
25453 +
25454 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
25455 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
25456 +
25457 +       if (length >= 0)
25458 +               length = simple_read_from_buffer(buf, count, ppos,
25459 +                       (char *)page, length);
25460 +
25461 +       free_page(page);
25462 +out_put:
25463 +       put_nx_info(nxi);
25464 +out:
25465 +       return length;
25466 +}
25467 +
25468 +
25469 +
25470 +/* here comes the lower level */
25471 +
25472 +
25473 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
25474 +       .len  = sizeof(NAME) - 1,       \
25475 +       .name = (NAME),                 \
25476 +       .mode = MODE,                   \
25477 +       .iop  = IOP,                    \
25478 +       .fop  = FOP,                    \
25479 +       .op   = OP,                     \
25480 +}
25481 +
25482 +
25483 +#define DIR(NAME, MODE, OTYPE)                         \
25484 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
25485 +               &proc_ ## OTYPE ## _inode_operations,   \
25486 +               &proc_ ## OTYPE ## _file_operations, { } )
25487 +
25488 +#define INF(NAME, MODE, OTYPE)                         \
25489 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25490 +               &proc_vs_info_file_operations,          \
25491 +               { .proc_vs_read = &proc_##OTYPE } )
25492 +
25493 +#define VINF(NAME, MODE, OTYPE)                                \
25494 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25495 +               &proc_vx_info_file_operations,          \
25496 +               { .proc_vxi_read = &proc_##OTYPE } )
25497 +
25498 +#define NINF(NAME, MODE, OTYPE)                                \
25499 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
25500 +               &proc_nx_info_file_operations,          \
25501 +               { .proc_nxi_read = &proc_##OTYPE } )
25502 +
25503 +
25504 +static struct file_operations proc_vs_info_file_operations = {
25505 +       .read =         proc_vs_info_read,
25506 +};
25507 +
25508 +static struct file_operations proc_vx_info_file_operations = {
25509 +       .read =         proc_vx_info_read,
25510 +};
25511 +
25512 +static struct dentry_operations proc_xid_dentry_operations = {
25513 +       .d_revalidate = proc_xid_revalidate,
25514 +};
25515 +
25516 +static struct vs_entry vx_base_stuff[] = {
25517 +       VINF("info",    S_IRUGO, vxi_info),
25518 +       VINF("status",  S_IRUGO, vxi_status),
25519 +       VINF("limit",   S_IRUGO, vxi_limit),
25520 +       VINF("sched",   S_IRUGO, vxi_sched),
25521 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
25522 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
25523 +       VINF("cacct",   S_IRUGO, vxi_cacct),
25524 +       {}
25525 +};
25526 +
25527 +
25528 +
25529 +
25530 +static struct dentry *proc_xid_instantiate(struct inode *dir,
25531 +       struct dentry *dentry, int id, void *ptr)
25532 +{
25533 +       dentry->d_op = &proc_xid_dentry_operations;
25534 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25535 +}
25536 +
25537 +static struct dentry *proc_xid_lookup(struct inode *dir,
25538 +       struct dentry *dentry, struct nameidata *nd)
25539 +{
25540 +       struct vs_entry *p = vx_base_stuff;
25541 +       struct dentry *error = ERR_PTR(-ENOENT);
25542 +
25543 +       for (; p->name; p++) {
25544 +               if (p->len != dentry->d_name.len)
25545 +                       continue;
25546 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25547 +                       break;
25548 +       }
25549 +       if (!p->name)
25550 +               goto out;
25551 +
25552 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25553 +out:
25554 +       return error;
25555 +}
25556 +
25557 +static int proc_xid_readdir(struct file *filp,
25558 +       void *dirent, filldir_t filldir)
25559 +{
25560 +       struct dentry *dentry = filp->f_dentry;
25561 +       struct inode *inode = dentry->d_inode;
25562 +       struct vs_entry *p = vx_base_stuff;
25563 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
25564 +       int pos, index;
25565 +       u64 ino;
25566 +
25567 +       pos = filp->f_pos;
25568 +       switch (pos) {
25569 +       case 0:
25570 +               ino = inode->i_ino;
25571 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25572 +                       goto out;
25573 +               pos++;
25574 +               /* fall through */
25575 +       case 1:
25576 +               ino = parent_ino(dentry);
25577 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25578 +                       goto out;
25579 +               pos++;
25580 +               /* fall through */
25581 +       default:
25582 +               index = pos - 2;
25583 +               if (index >= size)
25584 +                       goto out;
25585 +               for (p += index; p->name; p++) {
25586 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25587 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25588 +                               goto out;
25589 +                       pos++;
25590 +               }
25591 +       }
25592 +out:
25593 +       filp->f_pos = pos;
25594 +       return 1;
25595 +}
25596 +
25597 +
25598 +
25599 +static struct file_operations proc_nx_info_file_operations = {
25600 +       .read =         proc_nx_info_read,
25601 +};
25602 +
25603 +static struct dentry_operations proc_nid_dentry_operations = {
25604 +       .d_revalidate = proc_nid_revalidate,
25605 +};
25606 +
25607 +static struct vs_entry nx_base_stuff[] = {
25608 +       NINF("info",    S_IRUGO, nxi_info),
25609 +       NINF("status",  S_IRUGO, nxi_status),
25610 +       {}
25611 +};
25612 +
25613 +
25614 +static struct dentry *proc_nid_instantiate(struct inode *dir,
25615 +       struct dentry *dentry, int id, void *ptr)
25616 +{
25617 +       dentry->d_op = &proc_nid_dentry_operations;
25618 +       return vs_proc_instantiate(dir, dentry, id, ptr);
25619 +}
25620 +
25621 +static struct dentry *proc_nid_lookup(struct inode *dir,
25622 +       struct dentry *dentry, struct nameidata *nd)
25623 +{
25624 +       struct vs_entry *p = nx_base_stuff;
25625 +       struct dentry *error = ERR_PTR(-ENOENT);
25626 +
25627 +       for (; p->name; p++) {
25628 +               if (p->len != dentry->d_name.len)
25629 +                       continue;
25630 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25631 +                       break;
25632 +       }
25633 +       if (!p->name)
25634 +               goto out;
25635 +
25636 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
25637 +out:
25638 +       return error;
25639 +}
25640 +
25641 +static int proc_nid_readdir(struct file *filp,
25642 +       void *dirent, filldir_t filldir)
25643 +{
25644 +       struct dentry *dentry = filp->f_dentry;
25645 +       struct inode *inode = dentry->d_inode;
25646 +       struct vs_entry *p = nx_base_stuff;
25647 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
25648 +       int pos, index;
25649 +       u64 ino;
25650 +
25651 +       pos = filp->f_pos;
25652 +       switch (pos) {
25653 +       case 0:
25654 +               ino = inode->i_ino;
25655 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25656 +                       goto out;
25657 +               pos++;
25658 +               /* fall through */
25659 +       case 1:
25660 +               ino = parent_ino(dentry);
25661 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25662 +                       goto out;
25663 +               pos++;
25664 +               /* fall through */
25665 +       default:
25666 +               index = pos - 2;
25667 +               if (index >= size)
25668 +                       goto out;
25669 +               for (p += index; p->name; p++) {
25670 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25671 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
25672 +                               goto out;
25673 +                       pos++;
25674 +               }
25675 +       }
25676 +out:
25677 +       filp->f_pos = pos;
25678 +       return 1;
25679 +}
25680 +
25681 +
25682 +#define MAX_MULBY10    ((~0U - 9) / 10)
25683 +
25684 +static inline int atovid(const char *str, int len)
25685 +{
25686 +       int vid, c;
25687 +
25688 +       vid = 0;
25689 +       while (len-- > 0) {
25690 +               c = *str - '0';
25691 +               str++;
25692 +               if (c > 9)
25693 +                       return -1;
25694 +               if (vid >= MAX_MULBY10)
25695 +                       return -1;
25696 +               vid *= 10;
25697 +               vid += c;
25698 +               if (!vid)
25699 +                       return -1;
25700 +       }
25701 +       return vid;
25702 +}
25703 +
25704 +/* now the upper level (virtual) */
25705 +
25706 +
25707 +static struct file_operations proc_xid_file_operations = {
25708 +       .read =         generic_read_dir,
25709 +       .readdir =      proc_xid_readdir,
25710 +};
25711 +
25712 +static struct inode_operations proc_xid_inode_operations = {
25713 +       .lookup =       proc_xid_lookup,
25714 +};
25715 +
25716 +static struct vs_entry vx_virtual_stuff[] = {
25717 +       INF("info",     S_IRUGO, virtual_info),
25718 +       INF("status",   S_IRUGO, virtual_status),
25719 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
25720 +};
25721 +
25722 +
25723 +static struct dentry *proc_virtual_lookup(struct inode *dir,
25724 +       struct dentry *dentry, struct nameidata *nd)
25725 +{
25726 +       struct vs_entry *p = vx_virtual_stuff;
25727 +       struct dentry *error = ERR_PTR(-ENOENT);
25728 +       int id = 0;
25729 +
25730 +       for (; p->name; p++) {
25731 +               if (p->len != dentry->d_name.len)
25732 +                       continue;
25733 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25734 +                       break;
25735 +       }
25736 +       if (p->name)
25737 +               goto instantiate;
25738 +
25739 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25740 +       if ((id < 0) || !xid_is_hashed(id))
25741 +               goto out;
25742 +
25743 +instantiate:
25744 +       error = proc_xid_instantiate(dir, dentry, id, p);
25745 +out:
25746 +       return error;
25747 +}
25748 +
25749 +static struct file_operations proc_nid_file_operations = {
25750 +       .read =         generic_read_dir,
25751 +       .readdir =      proc_nid_readdir,
25752 +};
25753 +
25754 +static struct inode_operations proc_nid_inode_operations = {
25755 +       .lookup =       proc_nid_lookup,
25756 +};
25757 +
25758 +static struct vs_entry nx_virtnet_stuff[] = {
25759 +       INF("info",     S_IRUGO, virtnet_info),
25760 +       INF("status",   S_IRUGO, virtnet_status),
25761 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
25762 +};
25763 +
25764 +
25765 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
25766 +       struct dentry *dentry, struct nameidata *nd)
25767 +{
25768 +       struct vs_entry *p = nx_virtnet_stuff;
25769 +       struct dentry *error = ERR_PTR(-ENOENT);
25770 +       int id = 0;
25771 +
25772 +       for (; p->name; p++) {
25773 +               if (p->len != dentry->d_name.len)
25774 +                       continue;
25775 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
25776 +                       break;
25777 +       }
25778 +       if (p->name)
25779 +               goto instantiate;
25780 +
25781 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
25782 +       if ((id < 0) || !nid_is_hashed(id))
25783 +               goto out;
25784 +
25785 +instantiate:
25786 +       error = proc_nid_instantiate(dir, dentry, id, p);
25787 +out:
25788 +       return error;
25789 +}
25790 +
25791 +
25792 +
25793 +#define PROC_NUMBUF 10
25794 +#define PROC_MAXVIDS 32
25795 +
25796 +int proc_virtual_readdir(struct file *filp,
25797 +       void *dirent, filldir_t filldir)
25798 +{
25799 +       struct dentry *dentry = filp->f_dentry;
25800 +       struct inode *inode = dentry->d_inode;
25801 +       struct vs_entry *p = vx_virtual_stuff;
25802 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
25803 +       int pos, index;
25804 +       unsigned int xid_array[PROC_MAXVIDS];
25805 +       char buf[PROC_NUMBUF];
25806 +       unsigned int nr_xids, i;
25807 +       u64 ino;
25808 +
25809 +       pos = filp->f_pos;
25810 +       switch (pos) {
25811 +       case 0:
25812 +               ino = inode->i_ino;
25813 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25814 +                       goto out;
25815 +               pos++;
25816 +               /* fall through */
25817 +       case 1:
25818 +               ino = parent_ino(dentry);
25819 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25820 +                       goto out;
25821 +               pos++;
25822 +               /* fall through */
25823 +       default:
25824 +               index = pos - 2;
25825 +               if (index >= size)
25826 +                       goto entries;
25827 +               for (p += index; p->name; p++) {
25828 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25829 +                               vs_proc_instantiate, 0, p))
25830 +                               goto out;
25831 +                       pos++;
25832 +               }
25833 +       entries:
25834 +               index = pos - size;
25835 +               p = &vx_virtual_stuff[size - 1];
25836 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
25837 +               for (i = 0; i < nr_xids; i++) {
25838 +                       int n, xid = xid_array[i];
25839 +                       unsigned int j = PROC_NUMBUF;
25840 +
25841 +                       n = xid;
25842 +                       do
25843 +                               buf[--j] = '0' + (n % 10);
25844 +                       while (n /= 10);
25845 +
25846 +                       if (proc_fill_cache(filp, dirent, filldir,
25847 +                               buf + j, PROC_NUMBUF - j,
25848 +                               vs_proc_instantiate, xid, p))
25849 +                               goto out;
25850 +                       pos++;
25851 +               }
25852 +       }
25853 +out:
25854 +       filp->f_pos = pos;
25855 +       return 0;
25856 +}
25857 +
25858 +static int proc_virtual_getattr(struct vfsmount *mnt,
25859 +       struct dentry *dentry, struct kstat *stat)
25860 +{
25861 +       struct inode *inode = dentry->d_inode;
25862 +
25863 +       generic_fillattr(inode, stat);
25864 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
25865 +       return 0;
25866 +}
25867 +
25868 +static struct file_operations proc_virtual_dir_operations = {
25869 +       .read =         generic_read_dir,
25870 +       .readdir =      proc_virtual_readdir,
25871 +};
25872 +
25873 +static struct inode_operations proc_virtual_dir_inode_operations = {
25874 +       .getattr =      proc_virtual_getattr,
25875 +       .lookup =       proc_virtual_lookup,
25876 +};
25877 +
25878 +
25879 +
25880 +
25881 +
25882 +int proc_virtnet_readdir(struct file *filp,
25883 +       void *dirent, filldir_t filldir)
25884 +{
25885 +       struct dentry *dentry = filp->f_dentry;
25886 +       struct inode *inode = dentry->d_inode;
25887 +       struct vs_entry *p = nx_virtnet_stuff;
25888 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
25889 +       int pos, index;
25890 +       unsigned int nid_array[PROC_MAXVIDS];
25891 +       char buf[PROC_NUMBUF];
25892 +       unsigned int nr_nids, i;
25893 +       u64 ino;
25894 +
25895 +       pos = filp->f_pos;
25896 +       switch (pos) {
25897 +       case 0:
25898 +               ino = inode->i_ino;
25899 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
25900 +                       goto out;
25901 +               pos++;
25902 +               /* fall through */
25903 +       case 1:
25904 +               ino = parent_ino(dentry);
25905 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
25906 +                       goto out;
25907 +               pos++;
25908 +               /* fall through */
25909 +       default:
25910 +               index = pos - 2;
25911 +               if (index >= size)
25912 +                       goto entries;
25913 +               for (p += index; p->name; p++) {
25914 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
25915 +                               vs_proc_instantiate, 0, p))
25916 +                               goto out;
25917 +                       pos++;
25918 +               }
25919 +       entries:
25920 +               index = pos - size;
25921 +               p = &nx_virtnet_stuff[size - 1];
25922 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
25923 +               for (i = 0; i < nr_nids; i++) {
25924 +                       int n, nid = nid_array[i];
25925 +                       unsigned int j = PROC_NUMBUF;
25926 +
25927 +                       n = nid;
25928 +                       do
25929 +                               buf[--j] = '0' + (n % 10);
25930 +                       while (n /= 10);
25931 +
25932 +                       if (proc_fill_cache(filp, dirent, filldir,
25933 +                               buf + j, PROC_NUMBUF - j,
25934 +                               vs_proc_instantiate, nid, p))
25935 +                               goto out;
25936 +                       pos++;
25937 +               }
25938 +       }
25939 +out:
25940 +       filp->f_pos = pos;
25941 +       return 0;
25942 +}
25943 +
25944 +static int proc_virtnet_getattr(struct vfsmount *mnt,
25945 +       struct dentry *dentry, struct kstat *stat)
25946 +{
25947 +       struct inode *inode = dentry->d_inode;
25948 +
25949 +       generic_fillattr(inode, stat);
25950 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
25951 +       return 0;
25952 +}
25953 +
25954 +static struct file_operations proc_virtnet_dir_operations = {
25955 +       .read =         generic_read_dir,
25956 +       .readdir =      proc_virtnet_readdir,
25957 +};
25958 +
25959 +static struct inode_operations proc_virtnet_dir_inode_operations = {
25960 +       .getattr =      proc_virtnet_getattr,
25961 +       .lookup =       proc_virtnet_lookup,
25962 +};
25963 +
25964 +
25965 +
25966 +void proc_vx_init(void)
25967 +{
25968 +       struct proc_dir_entry *ent;
25969 +
25970 +       ent = proc_mkdir("virtual", 0);
25971 +       if (ent) {
25972 +               ent->proc_fops = &proc_virtual_dir_operations;
25973 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
25974 +       }
25975 +       proc_virtual = ent;
25976 +
25977 +       ent = proc_mkdir("virtnet", 0);
25978 +       if (ent) {
25979 +               ent->proc_fops = &proc_virtnet_dir_operations;
25980 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
25981 +       }
25982 +       proc_virtnet = ent;
25983 +}
25984 +
25985 +
25986 +
25987 +
25988 +/* per pid info */
25989 +
25990 +
25991 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
25992 +{
25993 +       struct vx_info *vxi;
25994 +       char *orig = buffer;
25995 +
25996 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
25997 +
25998 +       vxi = task_get_vx_info(p);
25999 +       if (!vxi)
26000 +               goto out;
26001 +
26002 +       buffer += sprintf(buffer, "BCaps:\t%016llx\n",
26003 +               (unsigned long long)vxi->vx_bcaps);
26004 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
26005 +               (unsigned long long)vxi->vx_ccaps);
26006 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
26007 +               (unsigned long long)vxi->vx_flags);
26008 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
26009 +
26010 +       put_vx_info(vxi);
26011 +out:
26012 +       return buffer - orig;
26013 +}
26014 +
26015 +
26016 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
26017 +{
26018 +       struct nx_info *nxi;
26019 +       struct nx_addr_v4 *v4a;
26020 +#ifdef CONFIG_IPV6
26021 +       struct nx_addr_v6 *v6a;
26022 +#endif
26023 +       char *orig = buffer;
26024 +       int i;
26025 +
26026 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
26027 +
26028 +       nxi = task_get_nx_info(p);
26029 +       if (!nxi)
26030 +               goto out;
26031 +
26032 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
26033 +               (unsigned long long)nxi->nx_ncaps);
26034 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
26035 +               (unsigned long long)nxi->nx_flags);
26036 +
26037 +       buffer += sprintf(buffer,
26038 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
26039 +               NIPQUAD(nxi->v4_bcast.s_addr));
26040 +       buffer += sprintf (buffer,
26041 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
26042 +               NIPQUAD(nxi->v4_lback.s_addr));
26043 +       if (!NX_IPV4(nxi))
26044 +               goto skip_v4;
26045 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
26046 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
26047 +                       i, NXAV4(v4a));
26048 +skip_v4:
26049 +#ifdef CONFIG_IPV6
26050 +       if (!NX_IPV6(nxi))
26051 +               goto skip_v6;
26052 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
26053 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
26054 +                       i, NXAV6(v6a));
26055 +skip_v6:
26056 +#endif
26057 +       put_nx_info(nxi);
26058 +out:
26059 +       return buffer - orig;
26060 +}
26061 +
26062 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
26063 --- linux-2.6.22.10/kernel/vserver/sched.c      1970-01-01 01:00:00 +0100
26064 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched.c   2007-08-15 23:32:49 +0200
26065 @@ -0,0 +1,413 @@
26066 +/*
26067 + *  linux/kernel/vserver/sched.c
26068 + *
26069 + *  Virtual Server: Scheduler Support
26070 + *
26071 + *  Copyright (C) 2004-2007  Herbert Pötzl
26072 + *
26073 + *  V0.01  adapted Sam Vilains version to 2.6.3
26074 + *  V0.02  removed legacy interface
26075 + *  V0.03  changed vcmds to vxi arg
26076 + *  V0.04  removed older and legacy interfaces
26077 + *
26078 + */
26079 +
26080 +#include <linux/vs_context.h>
26081 +#include <linux/vs_sched.h>
26082 +#include <linux/vserver/sched_cmd.h>
26083 +
26084 +#include <asm/uaccess.h>
26085 +
26086 +
26087 +#define vxd_check_range(val, min, max) do {            \
26088 +       vxlprintk((val < min) || (val > max),           \
26089 +               "check_range(%ld,%ld,%ld)",             \
26090 +               (long)val, (long)min, (long)max,        \
26091 +               __FILE__, __LINE__);                    \
26092 +       } while (0)
26093 +
26094 +
26095 +void vx_update_sched_param(struct _vx_sched *sched,
26096 +       struct _vx_sched_pc *sched_pc)
26097 +{
26098 +       unsigned int set_mask = sched->update_mask;
26099 +
26100 +       if (set_mask & VXSM_FILL_RATE)
26101 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
26102 +       if (set_mask & VXSM_INTERVAL)
26103 +               sched_pc->interval[0] = sched->interval[0];
26104 +       if (set_mask & VXSM_FILL_RATE2)
26105 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
26106 +       if (set_mask & VXSM_INTERVAL2)
26107 +               sched_pc->interval[1] = sched->interval[1];
26108 +       if (set_mask & VXSM_TOKENS)
26109 +               sched_pc->tokens = sched->tokens;
26110 +       if (set_mask & VXSM_TOKENS_MIN)
26111 +               sched_pc->tokens_min = sched->tokens_min;
26112 +       if (set_mask & VXSM_TOKENS_MAX)
26113 +               sched_pc->tokens_max = sched->tokens_max;
26114 +       if (set_mask & VXSM_PRIO_BIAS)
26115 +               sched_pc->prio_bias = sched->prio_bias;
26116 +
26117 +       if (set_mask & VXSM_IDLE_TIME)
26118 +               sched_pc->flags |= VXSF_IDLE_TIME;
26119 +       else
26120 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
26121 +
26122 +       /* reset time */
26123 +       sched_pc->norm_time = jiffies;
26124 +}
26125 +
26126 +
26127 +/*
26128 + * recalculate the context's scheduling tokens
26129 + *
26130 + * ret > 0 : number of tokens available
26131 + * ret < 0 : on hold, check delta_min[]
26132 + *          -1 only jiffies
26133 + *          -2 also idle time
26134 + *
26135 + */
26136 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
26137 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
26138 +{
26139 +       long delta;
26140 +       long tokens = 0;
26141 +       int flags = sched_pc->flags;
26142 +
26143 +       /* how much time did pass? */
26144 +       delta = *norm_time - sched_pc->norm_time;
26145 +       vxd_check_range(delta, 0, INT_MAX);
26146 +
26147 +       if (delta >= sched_pc->interval[0]) {
26148 +               long tokens, integral;
26149 +
26150 +               /* calc integral token part */
26151 +               tokens = delta / sched_pc->interval[0];
26152 +               integral = tokens * sched_pc->interval[0];
26153 +               tokens *= sched_pc->fill_rate[0];
26154 +#ifdef CONFIG_VSERVER_HARDCPU
26155 +               delta_min[0] = delta - integral;
26156 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
26157 +#endif
26158 +               /* advance time */
26159 +               sched_pc->norm_time += delta;
26160 +
26161 +               /* add tokens */
26162 +               sched_pc->tokens += tokens;
26163 +               sched_pc->token_time += tokens;
26164 +       } else
26165 +               delta_min[0] = delta;
26166 +
26167 +#ifdef CONFIG_VSERVER_IDLETIME
26168 +       if (!(flags & VXSF_IDLE_TIME))
26169 +               goto skip_idle;
26170 +
26171 +       /* how much was the idle skip? */
26172 +       delta = *idle_time - sched_pc->idle_time;
26173 +       vxd_check_range(delta, 0, INT_MAX);
26174 +
26175 +       if (delta >= sched_pc->interval[1]) {
26176 +               long tokens, integral;
26177 +
26178 +               /* calc fair share token part */
26179 +               tokens = delta / sched_pc->interval[1];
26180 +               integral = tokens * sched_pc->interval[1];
26181 +               tokens *= sched_pc->fill_rate[1];
26182 +               delta_min[1] = delta - integral;
26183 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
26184 +
26185 +               /* advance idle time */
26186 +               sched_pc->idle_time += integral;
26187 +
26188 +               /* add tokens */
26189 +               sched_pc->tokens += tokens;
26190 +               sched_pc->token_time += tokens;
26191 +       } else
26192 +               delta_min[1] = delta;
26193 +skip_idle:
26194 +#endif
26195 +
26196 +       /* clip at maximum */
26197 +       if (sched_pc->tokens > sched_pc->tokens_max)
26198 +               sched_pc->tokens = sched_pc->tokens_max;
26199 +       tokens = sched_pc->tokens;
26200 +
26201 +       if ((flags & VXSF_ONHOLD)) {
26202 +               /* can we unhold? */
26203 +               if (tokens >= sched_pc->tokens_min) {
26204 +                       flags &= ~VXSF_ONHOLD;
26205 +                       sched_pc->hold_ticks +=
26206 +                               *norm_time - sched_pc->onhold;
26207 +               } else
26208 +                       goto on_hold;
26209 +       } else {
26210 +               /* put on hold? */
26211 +               if (tokens <= 0) {
26212 +                       flags |= VXSF_ONHOLD;
26213 +                       sched_pc->onhold = *norm_time;
26214 +                       goto on_hold;
26215 +               }
26216 +       }
26217 +       sched_pc->flags = flags;
26218 +       return tokens;
26219 +
26220 +on_hold:
26221 +       tokens = sched_pc->tokens_min - tokens;
26222 +       sched_pc->flags = flags;
26223 +       BUG_ON(tokens < 0);
26224 +
26225 +#ifdef CONFIG_VSERVER_HARDCPU
26226 +       /* next interval? */
26227 +       if (!sched_pc->fill_rate[0])
26228 +               delta_min[0] = HZ;
26229 +       else if (tokens > sched_pc->fill_rate[0])
26230 +               delta_min[0] += sched_pc->interval[0] *
26231 +                       tokens / sched_pc->fill_rate[0];
26232 +       else
26233 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
26234 +       vxd_check_range(delta_min[0], 0, INT_MAX);
26235 +
26236 +#ifdef CONFIG_VSERVER_IDLETIME
26237 +       if (!(flags & VXSF_IDLE_TIME))
26238 +               return -1;
26239 +
26240 +       /* next interval? */
26241 +       if (!sched_pc->fill_rate[1])
26242 +               delta_min[1] = HZ;
26243 +       else if (tokens > sched_pc->fill_rate[1])
26244 +               delta_min[1] += sched_pc->interval[1] *
26245 +                       tokens / sched_pc->fill_rate[1];
26246 +       else
26247 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
26248 +       vxd_check_range(delta_min[1], 0, INT_MAX);
26249 +
26250 +       return -2;
26251 +#else
26252 +       return -1;
26253 +#endif /* CONFIG_VSERVER_IDLETIME */
26254 +#else
26255 +       return 0;
26256 +#endif /* CONFIG_VSERVER_HARDCPU */
26257 +}
26258 +
26259 +static inline unsigned long msec_to_ticks(unsigned long msec)
26260 +{
26261 +       return msecs_to_jiffies(msec);
26262 +}
26263 +
26264 +static inline unsigned long ticks_to_msec(unsigned long ticks)
26265 +{
26266 +       return jiffies_to_msecs(ticks);
26267 +}
26268 +
26269 +static inline unsigned long ticks_to_usec(unsigned long ticks)
26270 +{
26271 +       return jiffies_to_usecs(ticks);
26272 +}
26273 +
26274 +
26275 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
26276 +{
26277 +       unsigned int set_mask = data->mask;
26278 +       unsigned int update_mask;
26279 +       int i, cpu;
26280 +
26281 +       /* Sanity check data values */
26282 +       if (data->tokens_max <= 0)
26283 +               data->tokens_max = HZ;
26284 +       if (data->tokens_min < 0)
26285 +               data->tokens_min = HZ / 3;
26286 +       if (data->tokens_min >= data->tokens_max)
26287 +               data->tokens_min = data->tokens_max;
26288 +
26289 +       if (data->prio_bias > MAX_PRIO_BIAS)
26290 +               data->prio_bias = MAX_PRIO_BIAS;
26291 +       if (data->prio_bias < MIN_PRIO_BIAS)
26292 +               data->prio_bias = MIN_PRIO_BIAS;
26293 +
26294 +       spin_lock(&vxi->sched.tokens_lock);
26295 +
26296 +       /* sync up on delayed updates */
26297 +       for_each_cpu_mask(cpu, vxi->sched.update)
26298 +               vx_update_sched_param(&vxi->sched,
26299 +                       &vx_per_cpu(vxi, sched_pc, cpu));
26300 +
26301 +       if (set_mask & VXSM_FILL_RATE)
26302 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
26303 +       if (set_mask & VXSM_FILL_RATE2)
26304 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
26305 +       if (set_mask & VXSM_INTERVAL)
26306 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
26307 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
26308 +       if (set_mask & VXSM_INTERVAL2)
26309 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
26310 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
26311 +       if (set_mask & VXSM_TOKENS)
26312 +               vxi->sched.tokens = data->tokens;
26313 +       if (set_mask & VXSM_TOKENS_MIN)
26314 +               vxi->sched.tokens_min = data->tokens_min;
26315 +       if (set_mask & VXSM_TOKENS_MAX)
26316 +               vxi->sched.tokens_max = data->tokens_max;
26317 +       if (set_mask & VXSM_PRIO_BIAS)
26318 +               vxi->sched.prio_bias = data->prio_bias;
26319 +
26320 +       /* Sanity check rate/interval */
26321 +       for (i = 0; i < 2; i++) {
26322 +               if (data->fill_rate[i] < 0)
26323 +                       data->fill_rate[i] = 0;
26324 +               if (data->interval[i] <= 0)
26325 +                       data->interval[i] = HZ;
26326 +       }
26327 +
26328 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
26329 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
26330 +       vxi->sched.update_mask = update_mask;
26331 +
26332 +#ifdef CONFIG_SMP
26333 +       rmb();
26334 +       if (set_mask & VXSM_CPU_ID) {
26335 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
26336 +               cpus_and(vxi->sched.update, cpu_online_map,
26337 +                       vxi->sched.update);
26338 +       } else
26339 +               vxi->sched.update = cpu_online_map;
26340 +
26341 +       /* forced reload? */
26342 +       if (set_mask & VXSM_FORCE) {
26343 +               for_each_cpu_mask(cpu, vxi->sched.update)
26344 +                       vx_update_sched_param(&vxi->sched,
26345 +                               &vx_per_cpu(vxi, sched_pc, cpu));
26346 +               vxi->sched.update = CPU_MASK_NONE;
26347 +       }
26348 +#else
26349 +       /* on UP we update immediately */
26350 +       vx_update_sched_param(&vxi->sched,
26351 +               &vx_per_cpu(vxi, sched_pc, 0));
26352 +#endif
26353 +
26354 +       spin_unlock(&vxi->sched.tokens_lock);
26355 +       return 0;
26356 +}
26357 +
26358 +
26359 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
26360 +#define COPY_PRI(C) C(prio_bias)
26361 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26362 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
26363 +                   C(fill_rate[1]); C(interval[1]);
26364 +
26365 +#define COPY_VALUE(name) vc_data.name = data->name
26366 +
26367 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
26368 +{
26369 +       struct vcmd_sched_v5 vc_data;
26370 +
26371 +       vc_data.mask = data->set_mask;
26372 +       COPY_IDS(COPY_VALUE);
26373 +       COPY_PRI(COPY_VALUE);
26374 +       COPY_TOK(COPY_VALUE);
26375 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
26376 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
26377 +       return do_set_sched(vxi, &vc_data);
26378 +}
26379 +
26380 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
26381 +{
26382 +       struct vcmd_set_sched_v4 vc_data;
26383 +
26384 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26385 +               return -EFAULT;
26386 +
26387 +       return do_set_sched_v4(vxi, &vc_data);
26388 +}
26389 +
26390 +       /* latest interface is v5 */
26391 +
26392 +int vc_set_sched(struct vx_info *vxi, void __user *data)
26393 +{
26394 +       struct vcmd_sched_v5 vc_data;
26395 +
26396 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26397 +               return -EFAULT;
26398 +
26399 +       return do_set_sched(vxi, &vc_data);
26400 +}
26401 +
26402 +
26403 +#define COPY_PRI(C) C(prio_bias)
26404 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
26405 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
26406 +                   C(fill_rate[1]); C(interval[1]);
26407 +
26408 +#define COPY_VALUE(name) vc_data.name = data->name
26409 +
26410 +
26411 +int vc_get_sched(struct vx_info *vxi, void __user *data)
26412 +{
26413 +       struct vcmd_sched_v5 vc_data;
26414 +
26415 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26416 +               return -EFAULT;
26417 +
26418 +       if (vc_data.mask & VXSM_CPU_ID) {
26419 +               int cpu = vc_data.cpu_id;
26420 +               struct _vx_sched_pc *data;
26421 +
26422 +               if (!cpu_possible(cpu))
26423 +                       return -EINVAL;
26424 +
26425 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
26426 +               COPY_TOK(COPY_VALUE);
26427 +               COPY_PRI(COPY_VALUE);
26428 +               COPY_FRI(COPY_VALUE);
26429 +
26430 +               if (data->flags & VXSF_IDLE_TIME)
26431 +                       vc_data.mask |= VXSM_IDLE_TIME;
26432 +       } else {
26433 +               struct _vx_sched *data = &vxi->sched;
26434 +
26435 +               COPY_TOK(COPY_VALUE);
26436 +               COPY_PRI(COPY_VALUE);
26437 +               COPY_FRI(COPY_VALUE);
26438 +       }
26439 +
26440 +       if (vc_data.mask & VXSM_MSEC) {
26441 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
26442 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
26443 +       }
26444 +
26445 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26446 +               return -EFAULT;
26447 +       return 0;
26448 +}
26449 +
26450 +
26451 +int vc_sched_info(struct vx_info *vxi, void __user *data)
26452 +{
26453 +       struct vcmd_sched_info vc_data;
26454 +       int cpu;
26455 +
26456 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26457 +               return -EFAULT;
26458 +
26459 +       cpu = vc_data.cpu_id;
26460 +       if (!cpu_possible(cpu))
26461 +               return -EINVAL;
26462 +
26463 +       if (vxi) {
26464 +               struct _vx_sched_pc *sched_pc =
26465 +                       &vx_per_cpu(vxi, sched_pc, cpu);
26466 +
26467 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
26468 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
26469 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
26470 +               vc_data.vavavoom = sched_pc->vavavoom;
26471 +       }
26472 +       vc_data.token_usec = ticks_to_usec(1);
26473 +
26474 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26475 +               return -EFAULT;
26476 +       return 0;
26477 +}
26478 +
26479 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
26480 --- linux-2.6.22.10/kernel/vserver/sched_init.h 1970-01-01 01:00:00 +0100
26481 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched_init.h      2007-08-05 20:53:13 +0200
26482 @@ -0,0 +1,50 @@
26483 +
26484 +static inline void vx_info_init_sched(struct _vx_sched *sched)
26485 +{
26486 +       static struct lock_class_key tokens_lock_key;
26487 +
26488 +       /* scheduling; hard code starting values as constants */
26489 +       sched->fill_rate[0]     = 1;
26490 +       sched->interval[0]      = 4;
26491 +       sched->fill_rate[1]     = 1;
26492 +       sched->interval[1]      = 8;
26493 +       sched->tokens           = HZ >> 2;
26494 +       sched->tokens_min       = HZ >> 4;
26495 +       sched->tokens_max       = HZ >> 1;
26496 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
26497 +       sched->prio_bias        = 0;
26498 +
26499 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
26500 +}
26501 +
26502 +static inline
26503 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26504 +{
26505 +       sched_pc->fill_rate[0]  = 1;
26506 +       sched_pc->interval[0]   = 4;
26507 +       sched_pc->fill_rate[1]  = 1;
26508 +       sched_pc->interval[1]   = 8;
26509 +       sched_pc->tokens        = HZ >> 2;
26510 +       sched_pc->tokens_min    = HZ >> 4;
26511 +       sched_pc->tokens_max    = HZ >> 1;
26512 +       sched_pc->prio_bias     = 0;
26513 +       sched_pc->vavavoom      = 0;
26514 +       sched_pc->token_time    = 0;
26515 +       sched_pc->idle_time     = 0;
26516 +       sched_pc->norm_time     = jiffies;
26517 +
26518 +       sched_pc->user_ticks = 0;
26519 +       sched_pc->sys_ticks = 0;
26520 +       sched_pc->hold_ticks = 0;
26521 +}
26522 +
26523 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
26524 +{
26525 +       return;
26526 +}
26527 +
26528 +static inline
26529 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
26530 +{
26531 +       return;
26532 +}
26533 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
26534 --- linux-2.6.22.10/kernel/vserver/sched_proc.h 1970-01-01 01:00:00 +0100
26535 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sched_proc.h      2007-08-05 20:53:13 +0200
26536 @@ -0,0 +1,57 @@
26537 +#ifndef _VX_SCHED_PROC_H
26538 +#define _VX_SCHED_PROC_H
26539 +
26540 +
26541 +static inline
26542 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
26543 +{
26544 +       int length = 0;
26545 +
26546 +       length += sprintf(buffer,
26547 +               "FillRate:\t%8d,%d\n"
26548 +               "Interval:\t%8d,%d\n"
26549 +               "TokensMin:\t%8d\n"
26550 +               "TokensMax:\t%8d\n"
26551 +               "PrioBias:\t%8d\n",
26552 +               sched->fill_rate[0],
26553 +               sched->fill_rate[1],
26554 +               sched->interval[0],
26555 +               sched->interval[1],
26556 +               sched->tokens_min,
26557 +               sched->tokens_max,
26558 +               sched->prio_bias);
26559 +       return length;
26560 +}
26561 +
26562 +static inline
26563 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
26564 +       char *buffer, int cpu)
26565 +{
26566 +       int length = 0;
26567 +
26568 +       length += sprintf(buffer + length,
26569 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
26570 +               (unsigned long long)sched_pc->user_ticks,
26571 +               (unsigned long long)sched_pc->sys_ticks,
26572 +               (unsigned long long)sched_pc->hold_ticks,
26573 +               sched_pc->token_time,
26574 +               sched_pc->idle_time);
26575 +       length += sprintf(buffer + length,
26576 +               " %c%c %d %d %d %d/%d %d/%d",
26577 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
26578 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
26579 +               sched_pc->tokens,
26580 +               sched_pc->tokens_min,
26581 +               sched_pc->tokens_max,
26582 +               sched_pc->fill_rate[0],
26583 +               sched_pc->interval[0],
26584 +               sched_pc->fill_rate[1],
26585 +               sched_pc->interval[1]);
26586 +       length += sprintf(buffer + length,
26587 +               " %d %d\n",
26588 +               sched_pc->prio_bias,
26589 +               sched_pc->vavavoom);
26590 +       return length;
26591 +}
26592 +
26593 +#endif /* _VX_SCHED_PROC_H */
26594 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
26595 --- linux-2.6.22.10/kernel/vserver/signal.c     1970-01-01 01:00:00 +0100
26596 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/signal.c  2007-08-15 23:34:41 +0200
26597 @@ -0,0 +1,131 @@
26598 +/*
26599 + *  linux/kernel/vserver/signal.c
26600 + *
26601 + *  Virtual Server: Signal Support
26602 + *
26603 + *  Copyright (C) 2003-2007  Herbert Pötzl
26604 + *
26605 + *  V0.01  broken out from vcontext V0.05
26606 + *  V0.02  changed vcmds to vxi arg
26607 + *  V0.03  adjusted siginfo for kill
26608 + *
26609 + */
26610 +
26611 +#include <asm/uaccess.h>
26612 +
26613 +#include <linux/vs_context.h>
26614 +#include <linux/vserver/signal_cmd.h>
26615 +
26616 +
26617 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
26618 +{
26619 +       int retval, count = 0;
26620 +       struct task_struct *p;
26621 +       struct siginfo *sip = SEND_SIG_PRIV;
26622 +
26623 +       retval = -ESRCH;
26624 +       vxdprintk(VXD_CBIT(misc, 4),
26625 +               "vx_info_kill(%p[#%d],%d,%d)*",
26626 +               vxi, vxi->vx_id, pid, sig);
26627 +       read_lock(&tasklist_lock);
26628 +       switch (pid) {
26629 +       case  0:
26630 +       case -1:
26631 +               for_each_process(p) {
26632 +                       int err = 0;
26633 +
26634 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
26635 +                               (pid && vxi->vx_initpid == p->pid))
26636 +                               continue;
26637 +
26638 +                       err = group_send_sig_info(sig, sip, p);
26639 +                       ++count;
26640 +                       if (err != -EPERM)
26641 +                               retval = err;
26642 +               }
26643 +               break;
26644 +
26645 +       case 1:
26646 +               if (vxi->vx_initpid) {
26647 +                       pid = vxi->vx_initpid;
26648 +                       /* for now, only SIGINT to private init ... */
26649 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26650 +                               /* ... as long as there are tasks left */
26651 +                               (atomic_read(&vxi->vx_tasks) > 1))
26652 +                               sig = SIGINT;
26653 +               }
26654 +               /* fallthrough */
26655 +       default:
26656 +               p = find_task_by_real_pid(pid);
26657 +               if (p) {
26658 +                       if (vx_task_xid(p) == vxi->vx_id)
26659 +                               retval = group_send_sig_info(sig, sip, p);
26660 +               }
26661 +               break;
26662 +       }
26663 +       read_unlock(&tasklist_lock);
26664 +       vxdprintk(VXD_CBIT(misc, 4),
26665 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
26666 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
26667 +       return retval;
26668 +}
26669 +
26670 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
26671 +{
26672 +       struct vcmd_ctx_kill_v0 vc_data;
26673 +
26674 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
26675 +               return -EFAULT;
26676 +
26677 +       /* special check to allow guest shutdown */
26678 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
26679 +               /* forbid killall pid=0 when init is present */
26680 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
26681 +               (vc_data.pid > 1)))
26682 +               return -EACCES;
26683 +
26684 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
26685 +}
26686 +
26687 +
26688 +static int __wait_exit(struct vx_info *vxi)
26689 +{
26690 +       DECLARE_WAITQUEUE(wait, current);
26691 +       int ret = 0;
26692 +
26693 +       add_wait_queue(&vxi->vx_wait, &wait);
26694 +       set_current_state(TASK_INTERRUPTIBLE);
26695 +
26696 +wait:
26697 +       if (vx_info_state(vxi,
26698 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
26699 +               goto out;
26700 +       if (signal_pending(current)) {
26701 +               ret = -ERESTARTSYS;
26702 +               goto out;
26703 +       }
26704 +       schedule();
26705 +       goto wait;
26706 +
26707 +out:
26708 +       set_current_state(TASK_RUNNING);
26709 +       remove_wait_queue(&vxi->vx_wait, &wait);
26710 +       return ret;
26711 +}
26712 +
26713 +
26714 +
26715 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
26716 +{
26717 +       struct vcmd_wait_exit_v0 vc_data;
26718 +       int ret;
26719 +
26720 +       ret = __wait_exit(vxi);
26721 +       vc_data.reboot_cmd = vxi->reboot_cmd;
26722 +       vc_data.exit_code = vxi->exit_code;
26723 +
26724 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
26725 +               ret = -EFAULT;
26726 +       return ret;
26727 +}
26728 +
26729 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
26730 --- linux-2.6.22.10/kernel/vserver/space.c      1970-01-01 01:00:00 +0100
26731 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/space.c   2007-08-15 23:39:13 +0200
26732 @@ -0,0 +1,277 @@
26733 +/*
26734 + *  linux/kernel/vserver/space.c
26735 + *
26736 + *  Virtual Server: Context Space Support
26737 + *
26738 + *  Copyright (C) 2003-2007  Herbert Pötzl
26739 + *
26740 + *  V0.01  broken out from context.c 0.07
26741 + *  V0.02  added task locking for namespace
26742 + *  V0.03  broken out vx_enter_namespace
26743 + *  V0.04  added *space support and commands
26744 + *
26745 + */
26746 +
26747 +#include <linux/utsname.h>
26748 +#include <linux/nsproxy.h>
26749 +#include <linux/err.h>
26750 +#include <asm/uaccess.h>
26751 +
26752 +#include <linux/vs_context.h>
26753 +#include <linux/vserver/space.h>
26754 +#include <linux/vserver/space_cmd.h>
26755 +
26756 +
26757 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
26758 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
26759 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
26760 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
26761 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
26762 +
26763 +
26764 +/* namespace functions */
26765 +
26766 +#include <linux/mnt_namespace.h>
26767 +
26768 +const struct vcmd_space_mask space_mask = {
26769 +       .mask = CLONE_NEWNS |
26770 +               CLONE_NEWUTS |
26771 +               CLONE_NEWIPC |
26772 +               CLONE_FS
26773 +};
26774 +
26775 +
26776 +/*
26777 + *     build a new nsproxy mix
26778 + *      assumes that both proxies are 'const'
26779 + *     does not touch nsproxy refcounts
26780 + *     will hold a reference on the result.
26781 + */
26782 +
26783 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
26784 +       struct nsproxy *new_nsproxy, unsigned long mask)
26785 +{
26786 +       struct mnt_namespace *old_ns;
26787 +       struct uts_namespace *old_uts;
26788 +       struct ipc_namespace *old_ipc;
26789 +       struct nsproxy *nsproxy;
26790 +
26791 +       nsproxy = copy_nsproxy(old_nsproxy);
26792 +       if (!nsproxy)
26793 +               goto out;
26794 +
26795 +       if (mask & CLONE_NEWNS) {
26796 +               old_ns = nsproxy->mnt_ns;
26797 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
26798 +               if (nsproxy->mnt_ns)
26799 +                       get_mnt_ns(nsproxy->mnt_ns);
26800 +       } else
26801 +               old_ns = NULL;
26802 +
26803 +       if (mask & CLONE_NEWUTS) {
26804 +               old_uts = nsproxy->uts_ns;
26805 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
26806 +               if (nsproxy->uts_ns)
26807 +                       get_uts_ns(nsproxy->uts_ns);
26808 +       } else
26809 +               old_uts = NULL;
26810 +
26811 +       if (mask & CLONE_NEWIPC) {
26812 +               old_ipc = nsproxy->ipc_ns;
26813 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
26814 +               if (nsproxy->ipc_ns)
26815 +                       get_ipc_ns(nsproxy->ipc_ns);
26816 +       } else
26817 +               old_ipc = NULL;
26818 +
26819 +       if (old_ns)
26820 +               put_mnt_ns(old_ns);
26821 +       if (old_uts)
26822 +               put_uts_ns(old_uts);
26823 +       if (old_ipc)
26824 +               put_ipc_ns(old_ipc);
26825 +out:
26826 +       return nsproxy;
26827 +}
26828 +
26829 +
26830 +/*
26831 + *     merge two nsproxy structs into a new one.
26832 + *     will hold a reference on the result.
26833 + */
26834 +
26835 +static inline
26836 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
26837 +       struct nsproxy *proxy, unsigned long mask)
26838 +{
26839 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
26840 +
26841 +       if (!proxy)
26842 +               return NULL;
26843 +
26844 +       if (mask) {
26845 +               /* vs_mix_nsproxy returns with reference */
26846 +               return vs_mix_nsproxy(old ? old : &null_proxy,
26847 +                       proxy, mask);
26848 +       }
26849 +       get_nsproxy(proxy);
26850 +       return proxy;
26851 +}
26852 +
26853 +/*
26854 + *     merge two fs structs into a new one.
26855 + *     will take a reference on the result.
26856 + */
26857 +
26858 +static inline
26859 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
26860 +       struct fs_struct *fs, unsigned long mask)
26861 +{
26862 +       if (!(mask & CLONE_FS)) {
26863 +               if (old)
26864 +                       atomic_inc(&old->count);
26865 +               return old;
26866 +       }
26867 +
26868 +       if (!fs)
26869 +               return NULL;
26870 +
26871 +       return copy_fs_struct(fs);
26872 +}
26873 +
26874 +
26875 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
26876 +{
26877 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
26878 +       struct fs_struct *fs, *fs_cur, *fs_new;
26879 +       int ret;
26880 +
26881 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
26882 +               return -EACCES;
26883 +
26884 +       if (!mask)
26885 +               mask = vxi->vx_nsmask;
26886 +
26887 +       if ((mask & vxi->vx_nsmask) != mask)
26888 +               return -EINVAL;
26889 +
26890 +       proxy = vxi->vx_nsproxy;
26891 +       fs = vxi->vx_fs;
26892 +
26893 +       task_lock(current);
26894 +       fs_cur = current->fs;
26895 +       atomic_inc(&fs_cur->count);
26896 +       proxy_cur = current->nsproxy;
26897 +       get_nsproxy(proxy_cur);
26898 +       task_unlock(current);
26899 +
26900 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
26901 +       if (IS_ERR(fs_new)) {
26902 +               ret = PTR_ERR(fs_new);
26903 +               goto out_put;
26904 +       }
26905 +
26906 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
26907 +       if (IS_ERR(proxy_new)) {
26908 +               ret = PTR_ERR(proxy_new);
26909 +               goto out_put_fs;
26910 +       }
26911 +
26912 +       fs_new = xchg(&current->fs, fs_new);
26913 +       proxy_new = xchg(&current->nsproxy, proxy_new);
26914 +       ret = 0;
26915 +
26916 +       if (proxy_new)
26917 +               put_nsproxy(proxy_new);
26918 +out_put_fs:
26919 +       if (fs_new)
26920 +               put_fs_struct(fs_new);
26921 +out_put:
26922 +       if (proxy_cur)
26923 +               put_nsproxy(proxy_cur);
26924 +       if (fs_cur)
26925 +               put_fs_struct(fs_cur);
26926 +       return ret;
26927 +}
26928 +
26929 +
26930 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
26931 +{
26932 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
26933 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
26934 +       int ret;
26935 +
26936 +       if (!mask)
26937 +               mask = space_mask.mask;
26938 +
26939 +       if ((mask & space_mask.mask) != mask)
26940 +               return -EINVAL;
26941 +
26942 +       proxy_vxi = vxi->vx_nsproxy;
26943 +       fs_vxi = vxi->vx_fs;
26944 +
26945 +       task_lock(current);
26946 +       fs_cur = current->fs;
26947 +       atomic_inc(&fs_cur->count);
26948 +       proxy_cur = current->nsproxy;
26949 +       get_nsproxy(proxy_cur);
26950 +       task_unlock(current);
26951 +
26952 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
26953 +       if (IS_ERR(fs_new)) {
26954 +               ret = PTR_ERR(fs_new);
26955 +               goto out_put;
26956 +       }
26957 +
26958 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
26959 +       if (IS_ERR(proxy_new)) {
26960 +               ret = PTR_ERR(proxy_new);
26961 +               goto out_put_fs;
26962 +       }
26963 +
26964 +       fs_new = xchg(&vxi->vx_fs, fs_new);
26965 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
26966 +       vxi->vx_nsmask |= mask;
26967 +       ret = 0;
26968 +
26969 +       if (proxy_new)
26970 +               put_nsproxy(proxy_new);
26971 +out_put_fs:
26972 +       if (fs_new)
26973 +               put_fs_struct(fs_new);
26974 +out_put:
26975 +       if (proxy_cur)
26976 +               put_nsproxy(proxy_cur);
26977 +       if (fs_cur)
26978 +               put_fs_struct(fs_cur);
26979 +       return ret;
26980 +}
26981 +
26982 +
26983 +int vc_enter_space(struct vx_info *vxi, void __user *data)
26984 +{
26985 +       struct vcmd_space_mask vc_data = { .mask = 0 };
26986 +
26987 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26988 +               return -EFAULT;
26989 +
26990 +       return vx_enter_space(vxi, vc_data.mask);
26991 +}
26992 +
26993 +int vc_set_space(struct vx_info *vxi, void __user *data)
26994 +{
26995 +       struct vcmd_space_mask vc_data = { .mask = 0 };
26996 +
26997 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
26998 +               return -EFAULT;
26999 +
27000 +       return vx_set_space(vxi, vc_data.mask);
27001 +}
27002 +
27003 +int vc_get_space_mask(struct vx_info *vxi, void __user *data)
27004 +{
27005 +       if (copy_to_user(data, &space_mask, sizeof(space_mask)))
27006 +               return -EFAULT;
27007 +       return 0;
27008 +}
27009 +
27010 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
27011 --- linux-2.6.22.10/kernel/vserver/switch.c     1970-01-01 01:00:00 +0100
27012 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/switch.c  2007-10-25 17:05:55 +0200
27013 @@ -0,0 +1,529 @@
27014 +/*
27015 + *  linux/kernel/vserver/switch.c
27016 + *
27017 + *  Virtual Server: Syscall Switch
27018 + *
27019 + *  Copyright (C) 2003-2007  Herbert Pötzl
27020 + *
27021 + *  V0.01  syscall switch
27022 + *  V0.02  added signal to context
27023 + *  V0.03  added rlimit functions
27024 + *  V0.04  added iattr, task/xid functions
27025 + *  V0.05  added debug/history stuff
27026 + *  V0.06  added compat32 layer
27027 + *  V0.07  vcmd args and perms
27028 + *  V0.08  added status commands
27029 + *  V0.09  added tag commands
27030 + *  V0.10  added oom bias
27031 + *  V0.11  added device commands
27032 + *
27033 + */
27034 +
27035 +#include <linux/vs_context.h>
27036 +#include <linux/vs_network.h>
27037 +#include <linux/vserver/switch.h>
27038 +
27039 +#include "vci_config.h"
27040 +
27041 +
27042 +static inline
27043 +int vc_get_version(uint32_t id)
27044 +{
27045 +       return VCI_VERSION;
27046 +}
27047 +
27048 +static inline
27049 +int vc_get_vci(uint32_t id)
27050 +{
27051 +       return vci_kernel_config();
27052 +}
27053 +
27054 +#include <linux/vserver/context_cmd.h>
27055 +#include <linux/vserver/cvirt_cmd.h>
27056 +#include <linux/vserver/cacct_cmd.h>
27057 +#include <linux/vserver/limit_cmd.h>
27058 +#include <linux/vserver/network_cmd.h>
27059 +#include <linux/vserver/sched_cmd.h>
27060 +#include <linux/vserver/debug_cmd.h>
27061 +#include <linux/vserver/inode_cmd.h>
27062 +#include <linux/vserver/dlimit_cmd.h>
27063 +#include <linux/vserver/signal_cmd.h>
27064 +#include <linux/vserver/space_cmd.h>
27065 +#include <linux/vserver/tag_cmd.h>
27066 +#include <linux/vserver/device_cmd.h>
27067 +
27068 +#include <linux/vserver/inode.h>
27069 +#include <linux/vserver/dlimit.h>
27070 +
27071 +
27072 +#ifdef CONFIG_COMPAT
27073 +#define __COMPAT(name, id, data, compat)       \
27074 +       (compat) ? name ## _x32(id, data) : name(id, data)
27075 +#define __COMPAT_NO_ID(name, data, compat)     \
27076 +       (compat) ? name ## _x32(data) : name(data)
27077 +#else
27078 +#define __COMPAT(name, id, data, compat)       \
27079 +       name(id, data)
27080 +#define __COMPAT_NO_ID(name, data, compat)     \
27081 +       name(data)
27082 +#endif
27083 +
27084 +
27085 +static inline
27086 +long do_vcmd(uint32_t cmd, uint32_t id,
27087 +       struct vx_info *vxi, struct nx_info *nxi,
27088 +       void __user *data, int compat)
27089 +{
27090 +       switch (cmd) {
27091 +
27092 +       case VCMD_get_version:
27093 +               return vc_get_version(id);
27094 +       case VCMD_get_vci:
27095 +               return vc_get_vci(id);
27096 +
27097 +       case VCMD_task_xid:
27098 +               return vc_task_xid(id);
27099 +       case VCMD_vx_info:
27100 +               return vc_vx_info(vxi, data);
27101 +
27102 +       case VCMD_task_nid:
27103 +               return vc_task_nid(id);
27104 +       case VCMD_nx_info:
27105 +               return vc_nx_info(nxi, data);
27106 +
27107 +       case VCMD_task_tag:
27108 +               return vc_task_tag(id);
27109 +
27110 +       /* this is version 1 */
27111 +       case VCMD_set_space:
27112 +               return vc_set_space(vxi, data);
27113 +
27114 +       case VCMD_get_space_mask:
27115 +               return vc_get_space_mask(vxi, data);
27116 +
27117 +#ifdef CONFIG_IA32_EMULATION
27118 +       case VCMD_get_rlimit:
27119 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
27120 +       case VCMD_set_rlimit:
27121 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
27122 +#else
27123 +       case VCMD_get_rlimit:
27124 +               return vc_get_rlimit(vxi, data);
27125 +       case VCMD_set_rlimit:
27126 +               return vc_set_rlimit(vxi, data);
27127 +#endif
27128 +       case VCMD_get_rlimit_mask:
27129 +               return vc_get_rlimit_mask(id, data);
27130 +       case VCMD_reset_minmax:
27131 +               return vc_reset_minmax(vxi, data);
27132 +
27133 +       case VCMD_get_vhi_name:
27134 +               return vc_get_vhi_name(vxi, data);
27135 +       case VCMD_set_vhi_name:
27136 +               return vc_set_vhi_name(vxi, data);
27137 +
27138 +       case VCMD_ctx_stat:
27139 +               return vc_ctx_stat(vxi, data);
27140 +       case VCMD_virt_stat:
27141 +               return vc_virt_stat(vxi, data);
27142 +       case VCMD_sock_stat:
27143 +               return vc_sock_stat(vxi, data);
27144 +       case VCMD_rlimit_stat:
27145 +               return vc_rlimit_stat(vxi, data);
27146 +
27147 +       case VCMD_set_cflags:
27148 +               return vc_set_cflags(vxi, data);
27149 +       case VCMD_get_cflags:
27150 +               return vc_get_cflags(vxi, data);
27151 +
27152 +       /* this is version 1 */
27153 +       case VCMD_set_ccaps:
27154 +               return vc_set_ccaps(vxi, data);
27155 +       /* this is version 1 */
27156 +       case VCMD_get_ccaps:
27157 +               return vc_get_ccaps(vxi, data);
27158 +       case VCMD_set_bcaps:
27159 +               return vc_set_bcaps(vxi, data);
27160 +       case VCMD_get_bcaps:
27161 +               return vc_get_bcaps(vxi, data);
27162 +
27163 +       case VCMD_set_badness:
27164 +               return vc_set_badness(vxi, data);
27165 +       case VCMD_get_badness:
27166 +               return vc_get_badness(vxi, data);
27167 +
27168 +       case VCMD_set_nflags:
27169 +               return vc_set_nflags(nxi, data);
27170 +       case VCMD_get_nflags:
27171 +               return vc_get_nflags(nxi, data);
27172 +
27173 +       case VCMD_set_ncaps:
27174 +               return vc_set_ncaps(nxi, data);
27175 +       case VCMD_get_ncaps:
27176 +               return vc_get_ncaps(nxi, data);
27177 +
27178 +       case VCMD_set_sched_v4:
27179 +               return vc_set_sched_v4(vxi, data);
27180 +       /* this is version 5 */
27181 +       case VCMD_set_sched:
27182 +               return vc_set_sched(vxi, data);
27183 +       case VCMD_get_sched:
27184 +               return vc_get_sched(vxi, data);
27185 +       case VCMD_sched_info:
27186 +               return vc_sched_info(vxi, data);
27187 +
27188 +       case VCMD_add_dlimit:
27189 +               return __COMPAT(vc_add_dlimit, id, data, compat);
27190 +       case VCMD_rem_dlimit:
27191 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
27192 +       case VCMD_set_dlimit:
27193 +               return __COMPAT(vc_set_dlimit, id, data, compat);
27194 +       case VCMD_get_dlimit:
27195 +               return __COMPAT(vc_get_dlimit, id, data, compat);
27196 +
27197 +       case VCMD_ctx_kill:
27198 +               return vc_ctx_kill(vxi, data);
27199 +
27200 +       case VCMD_wait_exit:
27201 +               return vc_wait_exit(vxi, data);
27202 +
27203 +       case VCMD_get_iattr:
27204 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
27205 +       case VCMD_set_iattr:
27206 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
27207 +
27208 +       case VCMD_fget_iattr:
27209 +               return vc_fget_iattr(id, data);
27210 +       case VCMD_fset_iattr:
27211 +               return vc_fset_iattr(id, data);
27212 +
27213 +       case VCMD_enter_space_v0:
27214 +               return vc_enter_space(vxi, NULL);
27215 +       /* this is version 1 */
27216 +       case VCMD_enter_space:
27217 +               return vc_enter_space(vxi, data);
27218 +
27219 +       case VCMD_ctx_create_v0:
27220 +               return vc_ctx_create(id, NULL);
27221 +       case VCMD_ctx_create:
27222 +               return vc_ctx_create(id, data);
27223 +       case VCMD_ctx_migrate_v0:
27224 +               return vc_ctx_migrate(vxi, NULL);
27225 +       case VCMD_ctx_migrate:
27226 +               return vc_ctx_migrate(vxi, data);
27227 +
27228 +       case VCMD_net_create_v0:
27229 +               return vc_net_create(id, NULL);
27230 +       case VCMD_net_create:
27231 +               return vc_net_create(id, data);
27232 +       case VCMD_net_migrate:
27233 +               return vc_net_migrate(nxi, data);
27234 +
27235 +       case VCMD_tag_migrate:
27236 +               return vc_tag_migrate(id);
27237 +
27238 +       case VCMD_net_add:
27239 +               return vc_net_add(nxi, data);
27240 +       case VCMD_net_remove:
27241 +               return vc_net_remove(nxi, data);
27242 +
27243 +       case VCMD_net_add_ipv4:
27244 +               return vc_net_add_ipv4(nxi, data);
27245 +       case VCMD_net_remove_ipv4:
27246 +               return vc_net_remove_ipv4(nxi, data);
27247 +#ifdef CONFIG_IPV6
27248 +       case VCMD_net_add_ipv6:
27249 +               return vc_net_add_ipv6(nxi, data);
27250 +       case VCMD_net_remove_ipv6:
27251 +               return vc_net_remove_ipv6(nxi, data);
27252 +#endif
27253 +/*     case VCMD_add_match_ipv4:
27254 +               return vc_add_match_ipv4(nxi, data);
27255 +       case VCMD_get_match_ipv4:
27256 +               return vc_get_match_ipv4(nxi, data);
27257 +#ifdef CONFIG_IPV6
27258 +       case VCMD_add_match_ipv6:
27259 +               return vc_add_match_ipv6(nxi, data);
27260 +       case VCMD_get_match_ipv6:
27261 +               return vc_get_match_ipv6(nxi, data);
27262 +#endif */
27263 +
27264 +#ifdef CONFIG_VSERVER_DEVICE
27265 +       case VCMD_set_mapping:
27266 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
27267 +       case VCMD_unset_mapping:
27268 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
27269 +#endif
27270 +#ifdef CONFIG_VSERVER_HISTORY
27271 +       case VCMD_dump_history:
27272 +               return vc_dump_history(id);
27273 +       case VCMD_read_history:
27274 +               return __COMPAT(vc_read_history, id, data, compat);
27275 +#endif
27276 +#ifdef CONFIG_VSERVER_MONITOR
27277 +       case VCMD_read_monitor:
27278 +               return __COMPAT(vc_read_monitor, id, data, compat);
27279 +#endif
27280 +       default:
27281 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
27282 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
27283 +       }
27284 +       return -ENOSYS;
27285 +}
27286 +
27287 +
27288 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
27289 +       case VCMD_ ## vcmd: perm = _perm;               \
27290 +               args = _args; flags = _flags; break
27291 +
27292 +
27293 +#define VCA_NONE       0x00
27294 +#define VCA_VXI                0x01
27295 +#define VCA_NXI                0x02
27296 +
27297 +#define VCF_NONE       0x00
27298 +#define VCF_INFO       0x01
27299 +#define VCF_ADMIN      0x02
27300 +#define VCF_ARES       0x06    /* includes admin */
27301 +#define VCF_SETUP      0x08
27302 +
27303 +#define VCF_ZIDOK      0x10    /* zero id okay */
27304 +
27305 +
27306 +static inline
27307 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
27308 +{
27309 +       long ret;
27310 +       int permit = -1, state = 0;
27311 +       int perm = -1, args = 0, flags = 0;
27312 +       struct vx_info *vxi = NULL;
27313 +       struct nx_info *nxi = NULL;
27314 +
27315 +       switch (cmd) {
27316 +       /* unpriviledged commands */
27317 +       __VCMD(get_version,      0, VCA_NONE,   0);
27318 +       __VCMD(get_vci,          0, VCA_NONE,   0);
27319 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
27320 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
27321 +
27322 +       /* info commands */
27323 +       __VCMD(task_xid,         2, VCA_NONE,   0);
27324 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
27325 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
27326 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
27327 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
27328 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
27329 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
27330 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
27331 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
27332 +
27333 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
27334 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
27335 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
27336 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
27337 +
27338 +       __VCMD(task_nid,         2, VCA_NONE,   0);
27339 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
27340 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
27341 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
27342 +
27343 +       __VCMD(task_tag,         2, VCA_NONE,   0);
27344 +
27345 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
27346 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
27347 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
27348 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
27349 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
27350 +
27351 +       /* lower admin commands */
27352 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
27353 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
27354 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
27355 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
27356 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
27357 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
27358 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
27359 +
27360 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
27361 +       __VCMD(net_create,       5, VCA_NONE,   0);
27362 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
27363 +
27364 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
27365 +
27366 +       /* higher admin commands */
27367 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
27368 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27369 +
27370 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27371 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27372 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27373 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27374 +
27375 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27376 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27377 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27378 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
27379 +
27380 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27381 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
27382 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27383 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27384 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27385 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27386 +#ifdef CONFIG_IPV6
27387 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27388 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
27389 +#endif
27390 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
27391 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
27392 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
27393 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
27394 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
27395 +
27396 +#ifdef CONFIG_VSERVER_DEVICE
27397 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27398 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
27399 +#endif
27400 +       /* debug level admin commands */
27401 +#ifdef CONFIG_VSERVER_HISTORY
27402 +       __VCMD(dump_history,     9, VCA_NONE,   0);
27403 +       __VCMD(read_history,     9, VCA_NONE,   0);
27404 +#endif
27405 +#ifdef CONFIG_VSERVER_MONITOR
27406 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
27407 +#endif
27408 +
27409 +       default:
27410 +               perm = -1;
27411 +       }
27412 +
27413 +       vxdprintk(VXD_CBIT(switch, 0),
27414 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
27415 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27416 +               VC_VERSION(cmd), id, data, compat,
27417 +               perm, args, flags);
27418 +
27419 +       ret = -ENOSYS;
27420 +       if (perm < 0)
27421 +               goto out;
27422 +
27423 +       state = 1;
27424 +       if (!capable(CAP_CONTEXT))
27425 +               goto out;
27426 +
27427 +       state = 2;
27428 +       /* moved here from the individual commands */
27429 +       ret = -EPERM;
27430 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
27431 +               goto out;
27432 +
27433 +       state = 3;
27434 +       /* vcmd involves resource management  */
27435 +       ret = -EPERM;
27436 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
27437 +               goto out;
27438 +
27439 +       state = 4;
27440 +       /* various legacy exceptions */
27441 +       switch (cmd) {
27442 +       /* will go away when spectator is a cap */
27443 +       case VCMD_ctx_migrate_v0:
27444 +       case VCMD_ctx_migrate:
27445 +               if (id == 1) {
27446 +                       current->xid = 1;
27447 +                       ret = 1;
27448 +                       goto out;
27449 +               }
27450 +               break;
27451 +
27452 +       /* will go away when spectator is a cap */
27453 +       case VCMD_net_migrate:
27454 +               if (id == 1) {
27455 +                       current->nid = 1;
27456 +                       ret = 1;
27457 +                       goto out;
27458 +               }
27459 +               break;
27460 +       }
27461 +
27462 +       /* vcmds are fine by default */
27463 +       permit = 1;
27464 +
27465 +       /* admin type vcmds require admin ... */
27466 +       if (flags & VCF_ADMIN)
27467 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
27468 +
27469 +       /* ... but setup type vcmds override that */
27470 +       if (!permit && (flags & VCF_SETUP))
27471 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
27472 +
27473 +       state = 5;
27474 +       ret = -EPERM;
27475 +       if (!permit)
27476 +               goto out;
27477 +
27478 +       state = 6;
27479 +       if (!id && (flags & VCF_ZIDOK))
27480 +               goto skip_id;
27481 +
27482 +       ret = -ESRCH;
27483 +       if (args & VCA_VXI) {
27484 +               vxi = lookup_vx_info(id);
27485 +               if (!vxi)
27486 +                       goto out;
27487 +
27488 +               if ((flags & VCF_ADMIN) &&
27489 +                       /* special case kill for shutdown */
27490 +                       (cmd != VCMD_ctx_kill) &&
27491 +                       /* can context be administrated? */
27492 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
27493 +                       ret = -EACCES;
27494 +                       goto out_vxi;
27495 +               }
27496 +       }
27497 +       state = 7;
27498 +       if (args & VCA_NXI) {
27499 +               nxi = lookup_nx_info(id);
27500 +               if (!nxi)
27501 +                       goto out_vxi;
27502 +
27503 +               if ((flags & VCF_ADMIN) &&
27504 +                       /* can context be administrated? */
27505 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
27506 +                       ret = -EACCES;
27507 +                       goto out_nxi;
27508 +               }
27509 +       }
27510 +skip_id:
27511 +       state = 8;
27512 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
27513 +
27514 +out_nxi:
27515 +       if ((args & VCA_NXI) && nxi)
27516 +               put_nx_info(nxi);
27517 +out_vxi:
27518 +       if ((args & VCA_VXI) && vxi)
27519 +               put_vx_info(vxi);
27520 +out:
27521 +       vxdprintk(VXD_CBIT(switch, 1),
27522 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
27523 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
27524 +               VC_VERSION(cmd), ret, ret, state, permit);
27525 +       return ret;
27526 +}
27527 +
27528 +asmlinkage long
27529 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
27530 +{
27531 +       return do_vserver(cmd, id, data, 0);
27532 +}
27533 +
27534 +#ifdef CONFIG_COMPAT
27535 +
27536 +asmlinkage long
27537 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
27538 +{
27539 +       return do_vserver(cmd, id, data, 1);
27540 +}
27541 +
27542 +#endif /* CONFIG_COMPAT */
27543 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
27544 --- linux-2.6.22.10/kernel/vserver/sysctl.c     1970-01-01 01:00:00 +0100
27545 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/sysctl.c  2007-08-15 23:42:57 +0200
27546 @@ -0,0 +1,243 @@
27547 +/*
27548 + *  kernel/vserver/sysctl.c
27549 + *
27550 + *  Virtual Context Support
27551 + *
27552 + *  Copyright (C) 2004-2007  Herbert Pötzl
27553 + *
27554 + *  V0.01  basic structure
27555 + *
27556 + */
27557 +
27558 +#include <linux/module.h>
27559 +#include <linux/ctype.h>
27560 +#include <linux/sysctl.h>
27561 +#include <linux/parser.h>
27562 +#include <asm/uaccess.h>
27563 +
27564 +
27565 +#define CTL_VSERVER    4242    /* unused? */
27566 +
27567 +enum {
27568 +       CTL_DEBUG_ERROR         = 0,
27569 +       CTL_DEBUG_SWITCH        = 1,
27570 +       CTL_DEBUG_XID,
27571 +       CTL_DEBUG_NID,
27572 +       CTL_DEBUG_TAG,
27573 +       CTL_DEBUG_NET,
27574 +       CTL_DEBUG_LIMIT,
27575 +       CTL_DEBUG_CRES,
27576 +       CTL_DEBUG_DLIM,
27577 +       CTL_DEBUG_QUOTA,
27578 +       CTL_DEBUG_CVIRT,
27579 +       CTL_DEBUG_SPACE,
27580 +       CTL_DEBUG_MISC,
27581 +};
27582 +
27583 +
27584 +unsigned int vx_debug_switch   = 0;
27585 +unsigned int vx_debug_xid      = 0;
27586 +unsigned int vx_debug_nid      = 0;
27587 +unsigned int vx_debug_tag      = 0;
27588 +unsigned int vx_debug_net      = 0;
27589 +unsigned int vx_debug_limit    = 0;
27590 +unsigned int vx_debug_cres     = 0;
27591 +unsigned int vx_debug_dlim     = 0;
27592 +unsigned int vx_debug_quota    = 0;
27593 +unsigned int vx_debug_cvirt    = 0;
27594 +unsigned int vx_debug_space    = 0;
27595 +unsigned int vx_debug_misc     = 0;
27596 +
27597 +
27598 +static struct ctl_table_header *vserver_table_header;
27599 +static ctl_table vserver_table[];
27600 +
27601 +
27602 +void vserver_register_sysctl(void)
27603 +{
27604 +       if (!vserver_table_header) {
27605 +               vserver_table_header = register_sysctl_table(vserver_table);
27606 +       }
27607 +
27608 +}
27609 +
27610 +void vserver_unregister_sysctl(void)
27611 +{
27612 +       if (vserver_table_header) {
27613 +               unregister_sysctl_table(vserver_table_header);
27614 +               vserver_table_header = NULL;
27615 +       }
27616 +}
27617 +
27618 +
27619 +static int proc_dodebug(ctl_table *table, int write,
27620 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
27621 +{
27622 +       char            tmpbuf[20], *p, c;
27623 +       unsigned int    value;
27624 +       size_t          left, len;
27625 +
27626 +       if ((*ppos && !write) || !*lenp) {
27627 +               *lenp = 0;
27628 +               return 0;
27629 +       }
27630 +
27631 +       left = *lenp;
27632 +
27633 +       if (write) {
27634 +               if (!access_ok(VERIFY_READ, buffer, left))
27635 +                       return -EFAULT;
27636 +               p = (char *)buffer;
27637 +               while (left && __get_user(c, p) >= 0 && isspace(c))
27638 +                       left--, p++;
27639 +               if (!left)
27640 +                       goto done;
27641 +
27642 +               if (left > sizeof(tmpbuf) - 1)
27643 +                       return -EINVAL;
27644 +               if (copy_from_user(tmpbuf, p, left))
27645 +                       return -EFAULT;
27646 +               tmpbuf[left] = '\0';
27647 +
27648 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
27649 +                       value = 10 * value + (*p - '0');
27650 +               if (*p && !isspace(*p))
27651 +                       return -EINVAL;
27652 +               while (left && isspace(*p))
27653 +                       left--, p++;
27654 +               *(unsigned int *)table->data = value;
27655 +       } else {
27656 +               if (!access_ok(VERIFY_WRITE, buffer, left))
27657 +                       return -EFAULT;
27658 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
27659 +               if (len > left)
27660 +                       len = left;
27661 +               if (__copy_to_user(buffer, tmpbuf, len))
27662 +                       return -EFAULT;
27663 +               if ((left -= len) > 0) {
27664 +                       if (put_user('\n', (char *)buffer + len))
27665 +                               return -EFAULT;
27666 +                       left--;
27667 +               }
27668 +       }
27669 +
27670 +done:
27671 +       *lenp -= left;
27672 +       *ppos += *lenp;
27673 +       return 0;
27674 +}
27675 +
27676 +
27677 +#define        CTL_ENTRY(ctl, name)                            \
27678 +       {                                               \
27679 +               .ctl_name       = ctl,                  \
27680 +               .procname       = #name,                \
27681 +               .data           = &vx_ ## name,         \
27682 +               .maxlen         = sizeof(int),          \
27683 +               .mode           = 0644,                 \
27684 +               .proc_handler   = &proc_dodebug         \
27685 +       }
27686 +
27687 +static ctl_table debug_table[] = {
27688 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
27689 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
27690 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
27691 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
27692 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
27693 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
27694 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
27695 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
27696 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
27697 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
27698 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
27699 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
27700 +       { .ctl_name = 0 }
27701 +};
27702 +
27703 +static ctl_table vserver_table[] = {
27704 +       {
27705 +               .ctl_name       = CTL_VSERVER,
27706 +               .procname       = "vserver",
27707 +               .mode           = 0555,
27708 +               .child          = debug_table
27709 +       },
27710 +       { .ctl_name = 0 }
27711 +};
27712 +
27713 +
27714 +static match_table_t tokens = {
27715 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
27716 +       { CTL_DEBUG_XID,        "xid=%x"        },
27717 +       { CTL_DEBUG_NID,        "nid=%x"        },
27718 +       { CTL_DEBUG_TAG,        "tag=%x"        },
27719 +       { CTL_DEBUG_NET,        "net=%x"        },
27720 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
27721 +       { CTL_DEBUG_CRES,       "cres=%x"       },
27722 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
27723 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
27724 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
27725 +       { CTL_DEBUG_SPACE,      "space=%x"      },
27726 +       { CTL_DEBUG_MISC,       "misc=%x"       },
27727 +       { CTL_DEBUG_ERROR,      NULL            }
27728 +};
27729 +
27730 +#define        HANDLE_CASE(id, name, val)                              \
27731 +       case CTL_DEBUG_ ## id:                                  \
27732 +               vx_debug_ ## name = val;                        \
27733 +               printk("vs_debug_" #name "=0x%x\n", val);       \
27734 +               break
27735 +
27736 +
27737 +static int __init vs_debug_setup(char *str)
27738 +{
27739 +       char *p;
27740 +       int token;
27741 +
27742 +       printk("vs_debug_setup(%s)\n", str);
27743 +       while ((p = strsep(&str, ",")) != NULL) {
27744 +               substring_t args[MAX_OPT_ARGS];
27745 +               unsigned int value;
27746 +
27747 +               if (!*p)
27748 +                       continue;
27749 +
27750 +               token = match_token(p, tokens, args);
27751 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
27752 +
27753 +               switch (token) {
27754 +               HANDLE_CASE(SWITCH, switch, value);
27755 +               HANDLE_CASE(XID,    xid,    value);
27756 +               HANDLE_CASE(NID,    nid,    value);
27757 +               HANDLE_CASE(TAG,    tag,    value);
27758 +               HANDLE_CASE(NET,    net,    value);
27759 +               HANDLE_CASE(LIMIT,  limit,  value);
27760 +               HANDLE_CASE(CRES,   cres,   value);
27761 +               HANDLE_CASE(DLIM,   dlim,   value);
27762 +               HANDLE_CASE(QUOTA,  quota,  value);
27763 +               HANDLE_CASE(CVIRT,  cvirt,  value);
27764 +               HANDLE_CASE(SPACE,  space,  value);
27765 +               HANDLE_CASE(MISC,   misc,   value);
27766 +               default:
27767 +                       return -EINVAL;
27768 +                       break;
27769 +               }
27770 +       }
27771 +       return 1;
27772 +}
27773 +
27774 +__setup("vsdebug=", vs_debug_setup);
27775 +
27776 +
27777 +
27778 +EXPORT_SYMBOL_GPL(vx_debug_switch);
27779 +EXPORT_SYMBOL_GPL(vx_debug_xid);
27780 +EXPORT_SYMBOL_GPL(vx_debug_nid);
27781 +EXPORT_SYMBOL_GPL(vx_debug_net);
27782 +EXPORT_SYMBOL_GPL(vx_debug_limit);
27783 +EXPORT_SYMBOL_GPL(vx_debug_cres);
27784 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
27785 +EXPORT_SYMBOL_GPL(vx_debug_quota);
27786 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
27787 +EXPORT_SYMBOL_GPL(vx_debug_space);
27788 +EXPORT_SYMBOL_GPL(vx_debug_misc);
27789 +
27790 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
27791 --- linux-2.6.22.10/kernel/vserver/tag.c        1970-01-01 01:00:00 +0100
27792 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/tag.c     2007-10-05 14:54:36 +0200
27793 @@ -0,0 +1,62 @@
27794 +/*
27795 + *  linux/kernel/vserver/tag.c
27796 + *
27797 + *  Virtual Server: Shallow Tag Space
27798 + *
27799 + *  Copyright (C) 2007  Herbert Pötzl
27800 + *
27801 + *  V0.01  basic implementation
27802 + *
27803 + */
27804 +
27805 +#include <linux/sched.h>
27806 +#include <linux/vserver/debug.h>
27807 +#include <linux/vs_tag.h>
27808 +
27809 +#include <linux/vserver/tag_cmd.h>
27810 +
27811 +
27812 +int dx_migrate_task(struct task_struct *p, tag_t tag)
27813 +{
27814 +       if (!p)
27815 +               BUG();
27816 +
27817 +       vxdprintk(VXD_CBIT(tag, 5),
27818 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
27819 +
27820 +       task_lock(p);
27821 +       p->tag = tag;
27822 +       task_unlock(p);
27823 +
27824 +       vxdprintk(VXD_CBIT(tag, 5),
27825 +               "moved task %p into [#%d]", p, tag);
27826 +       return 0;
27827 +}
27828 +
27829 +/* vserver syscall commands below here */
27830 +
27831 +/* taks xid and vx_info functions */
27832 +
27833 +
27834 +int vc_task_tag(uint32_t id)
27835 +{
27836 +       tag_t tag;
27837 +
27838 +       if (id) {
27839 +               struct task_struct *tsk;
27840 +               read_lock(&tasklist_lock);
27841 +               tsk = find_task_by_real_pid(id);
27842 +               tag = (tsk) ? tsk->tag : -ESRCH;
27843 +               read_unlock(&tasklist_lock);
27844 +       } else
27845 +               tag = dx_current_tag();
27846 +       return tag;
27847 +}
27848 +
27849 +
27850 +int vc_tag_migrate(uint32_t tag)
27851 +{
27852 +       return dx_migrate_task(current, tag & 0xFFFF);
27853 +}
27854 +
27855 +
27856 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
27857 --- linux-2.6.22.10/kernel/vserver/vci_config.h 1970-01-01 01:00:00 +0100
27858 +++ linux-2.6.22.10-vs2.3.0.29/kernel/vserver/vci_config.h      2007-08-16 03:56:22 +0200
27859 @@ -0,0 +1,81 @@
27860 +
27861 +/*  interface version */
27862 +
27863 +#define VCI_VERSION            0x00020302
27864 +
27865 +
27866 +enum {
27867 +       VCI_KCBIT_NO_DYNAMIC = 0,
27868 +
27869 +       VCI_KCBIT_PROC_SECURE = 4,
27870 +       VCI_KCBIT_HARDCPU = 5,
27871 +       VCI_KCBIT_IDLELIMIT = 6,
27872 +       VCI_KCBIT_IDLETIME = 7,
27873 +
27874 +       VCI_KCBIT_COWBL = 8,
27875 +       VCI_KCBIT_FULLCOWBL = 9,
27876 +       VCI_KCBIT_SPACES = 10,
27877 +       VCI_KCBIT_NETV2 = 11,
27878 +
27879 +       VCI_KCBIT_DEBUG = 16,
27880 +       VCI_KCBIT_HISTORY = 20,
27881 +       VCI_KCBIT_TAGGED = 24,
27882 +       VCI_KCBIT_PPTAG = 28,
27883 +
27884 +       VCI_KCBIT_MORE = 31,
27885 +};
27886 +
27887 +
27888 +static inline uint32_t vci_kernel_config(void)
27889 +{
27890 +       return
27891 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
27892 +
27893 +       /* configured features */
27894 +#ifdef CONFIG_VSERVER_PROC_SECURE
27895 +       (1 << VCI_KCBIT_PROC_SECURE) |
27896 +#endif
27897 +#ifdef CONFIG_VSERVER_HARDCPU
27898 +       (1 << VCI_KCBIT_HARDCPU) |
27899 +#endif
27900 +#ifdef CONFIG_VSERVER_IDLELIMIT
27901 +       (1 << VCI_KCBIT_IDLELIMIT) |
27902 +#endif
27903 +#ifdef CONFIG_VSERVER_IDLETIME
27904 +       (1 << VCI_KCBIT_IDLETIME) |
27905 +#endif
27906 +#ifdef CONFIG_VSERVER_COWBL
27907 +       (1 << VCI_KCBIT_COWBL) |
27908 +       (1 << VCI_KCBIT_FULLCOWBL) |
27909 +#endif
27910 +       (1 << VCI_KCBIT_SPACES) |
27911 +       (1 << VCI_KCBIT_NETV2) |
27912 +
27913 +       /* debug options */
27914 +#ifdef CONFIG_VSERVER_DEBUG
27915 +       (1 << VCI_KCBIT_DEBUG) |
27916 +#endif
27917 +#ifdef CONFIG_VSERVER_HISTORY
27918 +       (1 << VCI_KCBIT_HISTORY) |
27919 +#endif
27920 +
27921 +       /* inode context tagging */
27922 +#if    defined(CONFIG_TAGGING_NONE)
27923 +       (0 << VCI_KCBIT_TAGGED) |
27924 +#elif  defined(CONFIG_TAGGING_UID16)
27925 +       (1 << VCI_KCBIT_TAGGED) |
27926 +#elif  defined(CONFIG_TAGGING_GID16)
27927 +       (2 << VCI_KCBIT_TAGGED) |
27928 +#elif  defined(CONFIG_TAGGING_ID24)
27929 +       (3 << VCI_KCBIT_TAGGED) |
27930 +#elif  defined(CONFIG_TAGGING_INTERN)
27931 +       (4 << VCI_KCBIT_TAGGED) |
27932 +#elif  defined(CONFIG_TAGGING_RUNTIME)
27933 +       (5 << VCI_KCBIT_TAGGED) |
27934 +#else
27935 +       (7 << VCI_KCBIT_TAGGED) |
27936 +#endif
27937 +       (1 << VCI_KCBIT_PPTAG) |
27938 +       0;
27939 +}
27940 +
27941 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
27942 --- linux-2.6.22.10/mm/filemap_xip.c    2007-07-09 13:20:04 +0200
27943 +++ linux-2.6.22.10-vs2.3.0.29/mm/filemap_xip.c 2007-08-05 20:53:13 +0200
27944 @@ -14,6 +14,7 @@
27945  #include <linux/uio.h>
27946  #include <linux/rmap.h>
27947  #include <linux/sched.h>
27948 +#include <linux/vs_memory.h>
27949  #include <asm/tlbflush.h>
27950  #include "filemap.h"
27951  
27952 diff -NurpP --minimal linux-2.6.22.10/mm/fremap.c linux-2.6.22.10-vs2.3.0.29/mm/fremap.c
27953 --- linux-2.6.22.10/mm/fremap.c 2007-02-06 03:01:56 +0100
27954 +++ linux-2.6.22.10-vs2.3.0.29/mm/fremap.c      2007-08-05 20:53:13 +0200
27955 @@ -15,6 +15,7 @@
27956  #include <linux/rmap.h>
27957  #include <linux/module.h>
27958  #include <linux/syscalls.h>
27959 +#include <linux/vs_memory.h>
27960  
27961  #include <asm/mmu_context.h>
27962  #include <asm/cacheflush.h>
27963 @@ -74,6 +75,8 @@ int install_page(struct mm_struct *mm, s
27964         err = -ENOMEM;
27965         if (page_mapcount(page) > INT_MAX/2)
27966                 goto unlock;
27967 +       if (!vx_rss_avail(mm, 1))
27968 +               goto unlock;
27969  
27970         if (pte_none(*pte) || !zap_pte(mm, vma, addr, pte))
27971                 inc_mm_counter(mm, file_rss);
27972 diff -NurpP --minimal linux-2.6.22.10/mm/hugetlb.c linux-2.6.22.10-vs2.3.0.29/mm/hugetlb.c
27973 --- linux-2.6.22.10/mm/hugetlb.c        2007-10-30 01:57:15 +0100
27974 +++ linux-2.6.22.10-vs2.3.0.29/mm/hugetlb.c     2007-08-11 22:41:51 +0200
27975 @@ -19,6 +19,7 @@
27976  #include <asm/pgtable.h>
27977  
27978  #include <linux/hugetlb.h>
27979 +#include <linux/vs_memory.h>
27980  #include "internal.h"
27981  
27982  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
27983 diff -NurpP --minimal linux-2.6.22.10/mm/memory.c linux-2.6.22.10-vs2.3.0.29/mm/memory.c
27984 --- linux-2.6.22.10/mm/memory.c 2007-07-09 13:20:04 +0200
27985 +++ linux-2.6.22.10-vs2.3.0.29/mm/memory.c      2007-08-05 20:53:13 +0200
27986 @@ -498,6 +498,9 @@ static int copy_pte_range(struct mm_stru
27987         int progress = 0;
27988         int rss[2];
27989  
27990 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
27991 +               return -ENOMEM;
27992 +
27993  again:
27994         rss[1] = rss[0] = 0;
27995         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
27996 @@ -2157,6 +2160,11 @@ static int do_swap_page(struct mm_struct
27997                 count_vm_event(PGMAJFAULT);
27998         }
27999  
28000 +       if (!vx_rss_avail(mm, 1)) {
28001 +               ret = VM_FAULT_OOM;
28002 +               goto out;
28003 +       }
28004 +
28005         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
28006         mark_page_accessed(page);
28007         lock_page(page);
28008 @@ -2229,6 +2237,8 @@ static int do_anonymous_page(struct mm_s
28009                 /* Allocate our own private page. */
28010                 pte_unmap(page_table);
28011  
28012 +               if (!vx_rss_avail(mm, 1))
28013 +                       goto oom;
28014                 if (unlikely(anon_vma_prepare(vma)))
28015                         goto oom;
28016                 page = alloc_zeroed_user_highpage(vma, address);
28017 @@ -2302,6 +2312,9 @@ static int do_no_page(struct mm_struct *
28018         pte_unmap(page_table);
28019         BUG_ON(vma->vm_flags & VM_PFNMAP);
28020  
28021 +       if (!vx_rss_avail(mm, 1))
28022 +               return VM_FAULT_OOM;
28023 +
28024         if (vma->vm_file) {
28025                 mapping = vma->vm_file->f_mapping;
28026                 sequence = mapping->truncate_count;
28027 @@ -2527,6 +2540,7 @@ static inline int handle_pte_fault(struc
28028  {
28029         pte_t entry;
28030         spinlock_t *ptl;
28031 +       int ret, type = VXPT_UNKNOWN;
28032  
28033         entry = *pte;
28034         if (!pte_present(entry)) {
28035 @@ -2555,9 +2569,12 @@ static inline int handle_pte_fault(struc
28036         if (unlikely(!pte_same(*pte, entry)))
28037                 goto unlock;
28038         if (write_access) {
28039 -               if (!pte_write(entry))
28040 -                       return do_wp_page(mm, vma, address,
28041 +               if (!pte_write(entry)) {
28042 +                       ret = do_wp_page(mm, vma, address,
28043                                         pte, pmd, ptl, entry);
28044 +                       type = VXPT_WRITE;
28045 +                       goto out;
28046 +               }
28047                 entry = pte_mkdirty(entry);
28048         }
28049         entry = pte_mkyoung(entry);
28050 @@ -2576,7 +2593,10 @@ static inline int handle_pte_fault(struc
28051         }
28052  unlock:
28053         pte_unmap_unlock(pte, ptl);
28054 -       return VM_FAULT_MINOR;
28055 +       ret = VM_FAULT_MINOR;
28056 +out:
28057 +       vx_page_fault(mm, vma, type, ret);
28058 +       return ret;
28059  }
28060  
28061  /*
28062 diff -NurpP --minimal linux-2.6.22.10/mm/mlock.c linux-2.6.22.10-vs2.3.0.29/mm/mlock.c
28063 --- linux-2.6.22.10/mm/mlock.c  2007-10-30 01:57:15 +0100
28064 +++ linux-2.6.22.10-vs2.3.0.29/mm/mlock.c       2007-08-11 22:41:51 +0200
28065 @@ -12,6 +12,7 @@
28066  #include <linux/syscalls.h>
28067  #include <linux/sched.h>
28068  #include <linux/module.h>
28069 +#include <linux/vs_memory.h>
28070  
28071  int can_do_mlock(void)
28072  {
28073 @@ -76,7 +77,7 @@ success:
28074                         ret = make_pages_present(start, end);
28075         }
28076  
28077 -       mm->locked_vm -= pages;
28078 +       vx_vmlocked_sub(mm, pages);
28079  out:
28080         if (ret == -ENOMEM)
28081                 ret = -EAGAIN;
28082 @@ -134,7 +135,7 @@ static int do_mlock(unsigned long start,
28083  
28084  asmlinkage long sys_mlock(unsigned long start, size_t len)
28085  {
28086 -       unsigned long locked;
28087 +       unsigned long locked, grow;
28088         unsigned long lock_limit;
28089         int error = -ENOMEM;
28090  
28091 @@ -145,8 +146,10 @@ asmlinkage long sys_mlock(unsigned long 
28092         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
28093         start &= PAGE_MASK;
28094  
28095 -       locked = len >> PAGE_SHIFT;
28096 -       locked += current->mm->locked_vm;
28097 +       grow = len >> PAGE_SHIFT;
28098 +       if (!vx_vmlocked_avail(current->mm, grow))
28099 +               goto out;
28100 +       locked = current->mm->locked_vm + grow;
28101  
28102         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
28103         lock_limit >>= PAGE_SHIFT;
28104 @@ -154,6 +157,7 @@ asmlinkage long sys_mlock(unsigned long 
28105         /* check against resource limits */
28106         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
28107                 error = do_mlock(start, len, 1);
28108 +out:
28109         up_write(&current->mm->mmap_sem);
28110         return error;
28111  }
28112 @@ -213,6 +217,8 @@ asmlinkage long sys_mlockall(int flags)
28113         lock_limit >>= PAGE_SHIFT;
28114  
28115         ret = -ENOMEM;
28116 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
28117 +               goto out;
28118         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
28119             capable(CAP_IPC_LOCK))
28120                 ret = do_mlockall(flags);
28121 diff -NurpP --minimal linux-2.6.22.10/mm/mmap.c linux-2.6.22.10-vs2.3.0.29/mm/mmap.c
28122 --- linux-2.6.22.10/mm/mmap.c   2007-07-09 13:20:04 +0200
28123 +++ linux-2.6.22.10-vs2.3.0.29/mm/mmap.c        2007-08-05 20:53:13 +0200
28124 @@ -1144,10 +1144,10 @@ munmap_back:
28125                 kmem_cache_free(vm_area_cachep, vma);
28126         }
28127  out:   
28128 -       mm->total_vm += len >> PAGE_SHIFT;
28129 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28130         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
28131         if (vm_flags & VM_LOCKED) {
28132 -               mm->locked_vm += len >> PAGE_SHIFT;
28133 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28134                 make_pages_present(addr, addr + len);
28135         }
28136         if (flags & MAP_POPULATE) {
28137 @@ -1502,9 +1502,9 @@ static int acct_stack_growth(struct vm_a
28138                 return -ENOMEM;
28139  
28140         /* Ok, everything looks good - let it rip */
28141 -       mm->total_vm += grow;
28142 +       vx_vmpages_add(mm, grow);
28143         if (vma->vm_flags & VM_LOCKED)
28144 -               mm->locked_vm += grow;
28145 +               vx_vmlocked_add(mm, grow);
28146         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
28147         return 0;
28148  }
28149 @@ -1662,9 +1662,9 @@ static void remove_vma_list(struct mm_st
28150         do {
28151                 long nrpages = vma_pages(vma);
28152  
28153 -               mm->total_vm -= nrpages;
28154 +               vx_vmpages_sub(mm, nrpages);
28155                 if (vma->vm_flags & VM_LOCKED)
28156 -                       mm->locked_vm -= nrpages;
28157 +                       vx_vmlocked_sub(mm, nrpages);
28158                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
28159                 vma = remove_vma(vma);
28160         } while (vma);
28161 @@ -1903,6 +1903,8 @@ unsigned long do_brk(unsigned long addr,
28162                 lock_limit >>= PAGE_SHIFT;
28163                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28164                         return -EAGAIN;
28165 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
28166 +                       return -ENOMEM;
28167         }
28168  
28169         /*
28170 @@ -1929,7 +1931,8 @@ unsigned long do_brk(unsigned long addr,
28171         if (mm->map_count > sysctl_max_map_count)
28172                 return -ENOMEM;
28173  
28174 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
28175 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
28176 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
28177                 return -ENOMEM;
28178  
28179         /* Can we just expand an old private anonymous mapping? */
28180 @@ -1955,9 +1958,9 @@ unsigned long do_brk(unsigned long addr,
28181                                 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
28182         vma_link(mm, vma, prev, rb_link, rb_parent);
28183  out:
28184 -       mm->total_vm += len >> PAGE_SHIFT;
28185 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28186         if (flags & VM_LOCKED) {
28187 -               mm->locked_vm += len >> PAGE_SHIFT;
28188 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
28189                 make_pages_present(addr, addr + len);
28190         }
28191         return addr;
28192 @@ -1986,6 +1989,11 @@ void exit_mmap(struct mm_struct *mm)
28193         free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
28194         tlb_finish_mmu(tlb, 0, end);
28195  
28196 +       set_mm_counter(mm, file_rss, 0);
28197 +       set_mm_counter(mm, anon_rss, 0);
28198 +       vx_vmpages_sub(mm, mm->total_vm);
28199 +       vx_vmlocked_sub(mm, mm->locked_vm);
28200 +
28201         /*
28202          * Walk the list again, actually closing and freeing it,
28203          * with preemption enabled, without holding any MM locks.
28204 @@ -2025,7 +2033,8 @@ int insert_vm_struct(struct mm_struct * 
28205         if (__vma && __vma->vm_start < vma->vm_end)
28206                 return -ENOMEM;
28207         if ((vma->vm_flags & VM_ACCOUNT) &&
28208 -            security_vm_enough_memory(vma_pages(vma)))
28209 +               (security_vm_enough_memory(vma_pages(vma)) ||
28210 +               !vx_vmpages_avail(mm, vma_pages(vma))))
28211                 return -ENOMEM;
28212         vma_link(mm, vma, prev, rb_link, rb_parent);
28213         return 0;
28214 @@ -2098,6 +2107,8 @@ int may_expand_vm(struct mm_struct *mm, 
28215  
28216         if (cur + npages > lim)
28217                 return 0;
28218 +       if (!vx_vmpages_avail(mm, npages))
28219 +               return 0;
28220         return 1;
28221  }
28222  
28223 @@ -2168,7 +2179,6 @@ int install_special_mapping(struct mm_st
28224                 return -ENOMEM;
28225         }
28226  
28227 -       mm->total_vm += len >> PAGE_SHIFT;
28228 -
28229 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
28230         return 0;
28231  }
28232 diff -NurpP --minimal linux-2.6.22.10/mm/mremap.c linux-2.6.22.10-vs2.3.0.29/mm/mremap.c
28233 --- linux-2.6.22.10/mm/mremap.c 2007-02-06 03:01:56 +0100
28234 +++ linux-2.6.22.10-vs2.3.0.29/mm/mremap.c      2007-08-05 20:53:13 +0200
28235 @@ -18,6 +18,7 @@
28236  #include <linux/highmem.h>
28237  #include <linux/security.h>
28238  #include <linux/syscalls.h>
28239 +#include <linux/vs_memory.h>
28240  
28241  #include <asm/uaccess.h>
28242  #include <asm/cacheflush.h>
28243 @@ -212,7 +213,7 @@ static unsigned long move_vma(struct vm_
28244          * If this were a serious issue, we'd add a flag to do_munmap().
28245          */
28246         hiwater_vm = mm->hiwater_vm;
28247 -       mm->total_vm += new_len >> PAGE_SHIFT;
28248 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
28249         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
28250  
28251         if (do_munmap(mm, old_addr, old_len) < 0) {
28252 @@ -230,7 +231,7 @@ static unsigned long move_vma(struct vm_
28253         }
28254  
28255         if (vm_flags & VM_LOCKED) {
28256 -               mm->locked_vm += new_len >> PAGE_SHIFT;
28257 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
28258                 if (new_len > old_len)
28259                         make_pages_present(new_addr + old_len,
28260                                            new_addr + new_len);
28261 @@ -337,6 +338,9 @@ unsigned long do_mremap(unsigned long ad
28262                 ret = -EAGAIN;
28263                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
28264                         goto out;
28265 +               if (!vx_vmlocked_avail(current->mm,
28266 +                       (new_len - old_len) >> PAGE_SHIFT))
28267 +                       goto out;
28268         }
28269         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
28270                 ret = -ENOMEM;
28271 @@ -365,10 +369,10 @@ unsigned long do_mremap(unsigned long ad
28272                         vma_adjust(vma, vma->vm_start,
28273                                 addr + new_len, vma->vm_pgoff, NULL);
28274  
28275 -                       mm->total_vm += pages;
28276 +                       vx_vmpages_add(mm, pages);
28277                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
28278                         if (vma->vm_flags & VM_LOCKED) {
28279 -                               mm->locked_vm += pages;
28280 +                               vx_vmlocked_add(mm, pages);
28281                                 make_pages_present(addr + old_len,
28282                                                    addr + new_len);
28283                         }
28284 diff -NurpP --minimal linux-2.6.22.10/mm/nommu.c linux-2.6.22.10-vs2.3.0.29/mm/nommu.c
28285 --- linux-2.6.22.10/mm/nommu.c  2007-07-09 13:20:04 +0200
28286 +++ linux-2.6.22.10-vs2.3.0.29/mm/nommu.c       2007-08-05 20:53:13 +0200
28287 @@ -936,7 +936,7 @@ unsigned long do_mmap_pgoff(struct file 
28288         realalloc += kobjsize(vma);
28289         askedalloc += sizeof(*vma);
28290  
28291 -       current->mm->total_vm += len >> PAGE_SHIFT;
28292 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
28293  
28294         add_nommu_vma(vma);
28295  
28296 @@ -1061,7 +1061,7 @@ int do_munmap(struct mm_struct *mm, unsi
28297         kfree(vml);
28298  
28299         update_hiwater_vm(mm);
28300 -       mm->total_vm -= len >> PAGE_SHIFT;
28301 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
28302  
28303  #ifdef DEBUG
28304         show_process_blocks();
28305 @@ -1093,7 +1093,7 @@ void exit_mmap(struct mm_struct * mm)
28306                 printk("Exit_mmap:\n");
28307  #endif
28308  
28309 -               mm->total_vm = 0;
28310 +               vx_vmpages_sub(mm, mm->total_vm);
28311  
28312                 while ((tmp = mm->context.vmlist)) {
28313                         mm->context.vmlist = tmp->next;
28314 diff -NurpP --minimal linux-2.6.22.10/mm/oom_kill.c linux-2.6.22.10-vs2.3.0.29/mm/oom_kill.c
28315 --- linux-2.6.22.10/mm/oom_kill.c       2007-07-09 13:20:04 +0200
28316 +++ linux-2.6.22.10-vs2.3.0.29/mm/oom_kill.c    2007-08-05 20:53:13 +0200
28317 @@ -24,6 +24,7 @@
28318  #include <linux/cpuset.h>
28319  #include <linux/module.h>
28320  #include <linux/notifier.h>
28321 +#include <linux/vs_memory.h>
28322  
28323  int sysctl_panic_on_oom;
28324  /* #define DEBUG */
28325 @@ -66,6 +67,12 @@ unsigned long badness(struct task_struct
28326         points = mm->total_vm;
28327  
28328         /*
28329 +        * add points for context badness
28330 +        */
28331 +
28332 +       points += vx_badness(p, mm);
28333 +
28334 +       /*
28335          * After this unlock we can no longer dereference local variable `mm'
28336          */
28337         task_unlock(p);
28338 @@ -156,8 +163,8 @@ unsigned long badness(struct task_struct
28339         }
28340  
28341  #ifdef DEBUG
28342 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
28343 -       p->pid, p->comm, points);
28344 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
28345 +               p->pid, p->xid, p->comm, points);
28346  #endif
28347         return points;
28348  }
28349 @@ -288,7 +295,8 @@ static void __oom_kill_task(struct task_
28350         }
28351  
28352         if (verbose)
28353 -               printk(KERN_ERR "Killed process %d (%s)\n", p->pid, p->comm);
28354 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
28355 +                               p->pid, p->xid, p->comm);
28356  
28357         /*
28358          * We give our sacrificial lamb high priority and access to
28359 @@ -358,8 +366,8 @@ static int oom_kill_process(struct task_
28360                 return 0;
28361         }
28362  
28363 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
28364 -                                       message, p->pid, p->comm, points);
28365 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
28366 +                               message, p->pid, p->xid, p->comm, points);
28367  
28368         /* Try to kill a child first */
28369         list_for_each(tsk, &p->children) {
28370 diff -NurpP --minimal linux-2.6.22.10/mm/page_alloc.c linux-2.6.22.10-vs2.3.0.29/mm/page_alloc.c
28371 --- linux-2.6.22.10/mm/page_alloc.c     2007-07-09 13:20:04 +0200
28372 +++ linux-2.6.22.10-vs2.3.0.29/mm/page_alloc.c  2007-08-05 20:53:13 +0200
28373 @@ -41,6 +41,8 @@
28374  #include <linux/pfn.h>
28375  #include <linux/backing-dev.h>
28376  #include <linux/fault-inject.h>
28377 +#include <linux/vs_base.h>
28378 +#include <linux/vs_limit.h>
28379  
28380  #include <asm/tlbflush.h>
28381  #include <asm/div64.h>
28382 @@ -1488,6 +1490,9 @@ void si_meminfo(struct sysinfo *val)
28383         val->totalhigh = totalhigh_pages;
28384         val->freehigh = nr_free_highpages();
28385         val->mem_unit = PAGE_SIZE;
28386 +
28387 +       if (vx_flags(VXF_VIRT_MEM, 0))
28388 +               vx_vsi_meminfo(val);
28389  }
28390  
28391  EXPORT_SYMBOL(si_meminfo);
28392 @@ -1508,6 +1513,9 @@ void si_meminfo_node(struct sysinfo *val
28393         val->freehigh = 0;
28394  #endif
28395         val->mem_unit = PAGE_SIZE;
28396 +
28397 +       if (vx_flags(VXF_VIRT_MEM, 0))
28398 +               vx_vsi_meminfo(val);
28399  }
28400  #endif
28401  
28402 diff -NurpP --minimal linux-2.6.22.10/mm/rmap.c linux-2.6.22.10-vs2.3.0.29/mm/rmap.c
28403 --- linux-2.6.22.10/mm/rmap.c   2007-07-09 13:20:04 +0200
28404 +++ linux-2.6.22.10-vs2.3.0.29/mm/rmap.c        2007-08-05 20:53:13 +0200
28405 @@ -48,6 +48,7 @@
28406  #include <linux/rcupdate.h>
28407  #include <linux/module.h>
28408  #include <linux/kallsyms.h>
28409 +#include <linux/vs_memory.h>
28410  
28411  #include <asm/tlbflush.h>
28412  
28413 diff -NurpP --minimal linux-2.6.22.10/mm/shmem.c linux-2.6.22.10-vs2.3.0.29/mm/shmem.c
28414 --- linux-2.6.22.10/mm/shmem.c  2007-07-09 13:20:04 +0200
28415 +++ linux-2.6.22.10-vs2.3.0.29/mm/shmem.c       2007-08-05 20:53:13 +0200
28416 @@ -55,7 +55,6 @@
28417  #include <asm/pgtable.h>
28418  
28419  /* This magic number is used in glibc for posix shared memory */
28420 -#define TMPFS_MAGIC    0x01021994
28421  
28422  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
28423  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
28424 @@ -1734,7 +1733,7 @@ static int shmem_statfs(struct dentry *d
28425  {
28426         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
28427  
28428 -       buf->f_type = TMPFS_MAGIC;
28429 +       buf->f_type = TMPFS_SUPER_MAGIC;
28430         buf->f_bsize = PAGE_CACHE_SIZE;
28431         buf->f_namelen = NAME_MAX;
28432         spin_lock(&sbinfo->stat_lock);
28433 @@ -2308,7 +2307,7 @@ static int shmem_fill_super(struct super
28434         sb->s_maxbytes = SHMEM_MAX_BYTES;
28435         sb->s_blocksize = PAGE_CACHE_SIZE;
28436         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
28437 -       sb->s_magic = TMPFS_MAGIC;
28438 +       sb->s_magic = TMPFS_SUPER_MAGIC;
28439         sb->s_op = &shmem_ops;
28440         sb->s_time_gran = 1;
28441  #ifdef CONFIG_TMPFS_POSIX_ACL
28442 diff -NurpP --minimal linux-2.6.22.10/mm/slab.c linux-2.6.22.10-vs2.3.0.29/mm/slab.c
28443 --- linux-2.6.22.10/mm/slab.c   2007-07-09 13:20:04 +0200
28444 +++ linux-2.6.22.10-vs2.3.0.29/mm/slab.c        2007-08-05 20:53:13 +0200
28445 @@ -510,6 +510,8 @@ struct kmem_cache {
28446  #define STATS_INC_FREEMISS(x)  do { } while (0)
28447  #endif
28448  
28449 +#include "slab_vs.h"
28450 +
28451  #if DEBUG
28452  
28453  /*
28454 @@ -3314,6 +3316,7 @@ retry:
28455  
28456         obj = slab_get_obj(cachep, slabp, nodeid);
28457         check_slabp(cachep, slabp);
28458 +       vx_slab_alloc(cachep, flags);
28459         l3->free_objects--;
28460         /* move slabp to correct slabp list: */
28461         list_del(&slabp->list);
28462 @@ -3386,6 +3389,7 @@ __cache_alloc_node(struct kmem_cache *ca
28463         /* ___cache_alloc_node can fall back to other nodes */
28464         ptr = ____cache_alloc_node(cachep, flags, nodeid);
28465    out:
28466 +       vx_slab_alloc(cachep, flags);
28467         local_irq_restore(save_flags);
28468         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
28469  
28470 @@ -3551,6 +3555,7 @@ static inline void __cache_free(struct k
28471  
28472         check_irq_off();
28473         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
28474 +       vx_slab_free(cachep);
28475  
28476         if (cache_free_alien(cachep, objp))
28477                 return;
28478 diff -NurpP --minimal linux-2.6.22.10/mm/slab_vs.h linux-2.6.22.10-vs2.3.0.29/mm/slab_vs.h
28479 --- linux-2.6.22.10/mm/slab_vs.h        1970-01-01 01:00:00 +0100
28480 +++ linux-2.6.22.10-vs2.3.0.29/mm/slab_vs.h     2007-08-05 20:53:13 +0200
28481 @@ -0,0 +1,27 @@
28482 +
28483 +#include <linux/vserver/context.h>
28484 +
28485 +#include <linux/vs_context.h>
28486 +
28487 +static inline
28488 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
28489 +{
28490 +       int what = gfp_zone(cachep->gfpflags);
28491 +
28492 +       if (!current->vx_info)
28493 +               return;
28494 +
28495 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28496 +}
28497 +
28498 +static inline
28499 +void vx_slab_free(struct kmem_cache *cachep)
28500 +{
28501 +       int what = gfp_zone(cachep->gfpflags);
28502 +
28503 +       if (!current->vx_info)
28504 +               return;
28505 +
28506 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
28507 +}
28508 +
28509 diff -NurpP --minimal linux-2.6.22.10/mm/swapfile.c linux-2.6.22.10-vs2.3.0.29/mm/swapfile.c
28510 --- linux-2.6.22.10/mm/swapfile.c       2007-07-09 13:20:04 +0200
28511 +++ linux-2.6.22.10-vs2.3.0.29/mm/swapfile.c    2007-08-05 20:53:13 +0200
28512 @@ -31,6 +31,8 @@
28513  #include <asm/pgtable.h>
28514  #include <asm/tlbflush.h>
28515  #include <linux/swapops.h>
28516 +#include <linux/vs_base.h>
28517 +#include <linux/vs_memory.h>
28518  
28519  DEFINE_SPINLOCK(swap_lock);
28520  unsigned int nr_swapfiles;
28521 @@ -1712,6 +1714,8 @@ void si_swapinfo(struct sysinfo *val)
28522         val->freeswap = nr_swap_pages + nr_to_be_unused;
28523         val->totalswap = total_swap_pages + nr_to_be_unused;
28524         spin_unlock(&swap_lock);
28525 +       if (vx_flags(VXF_VIRT_MEM, 0))
28526 +               vx_vsi_swapinfo(val);
28527  }
28528  
28529  /*
28530 diff -NurpP --minimal linux-2.6.22.10/net/core/dev.c linux-2.6.22.10-vs2.3.0.29/net/core/dev.c
28531 --- linux-2.6.22.10/net/core/dev.c      2007-10-30 01:57:15 +0100
28532 +++ linux-2.6.22.10-vs2.3.0.29/net/core/dev.c   2007-09-05 03:06:12 +0200
28533 @@ -117,6 +117,7 @@
28534  #include <linux/err.h>
28535  #include <linux/ctype.h>
28536  #include <linux/if_arp.h>
28537 +#include <linux/vs_inet.h>
28538  
28539  /*
28540   *     The list of packet types we will receive (as opposed to discard)
28541 @@ -2120,6 +2121,8 @@ static int dev_ifconf(char __user *arg)
28542  
28543         total = 0;
28544         for_each_netdev(dev) {
28545 +               if (!nx_dev_visible(current->nx_info, dev))
28546 +                       continue;
28547                 for (i = 0; i < NPROTO; i++) {
28548                         if (gifconf_list[i]) {
28549                                 int done;
28550 @@ -2184,6 +2187,9 @@ static void dev_seq_printf_stats(struct 
28551  {
28552         struct net_device_stats *stats = dev->get_stats(dev);
28553  
28554 +       if (!nx_dev_visible(current->nx_info, dev))
28555 +               return;
28556 +
28557         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
28558                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
28559                    dev->name, stats->rx_bytes, stats->rx_packets,
28560 diff -NurpP --minimal linux-2.6.22.10/net/core/rtnetlink.c linux-2.6.22.10-vs2.3.0.29/net/core/rtnetlink.c
28561 --- linux-2.6.22.10/net/core/rtnetlink.c        2007-07-09 13:20:05 +0200
28562 +++ linux-2.6.22.10-vs2.3.0.29/net/core/rtnetlink.c     2007-08-05 20:53:13 +0200
28563 @@ -537,6 +537,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
28564  
28565         idx = 0;
28566         for_each_netdev(dev) {
28567 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
28568 +                       continue;
28569                 if (idx < s_idx)
28570                         goto cont;
28571                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
28572 @@ -797,6 +799,9 @@ void rtmsg_ifinfo(int type, struct net_d
28573         struct sk_buff *skb;
28574         int err = -ENOBUFS;
28575  
28576 +       if (!nx_dev_visible(current->nx_info, dev))
28577 +               return;
28578 +
28579         skb = nlmsg_new(if_nlmsg_size(), GFP_KERNEL);
28580         if (skb == NULL)
28581                 goto errout;
28582 diff -NurpP --minimal linux-2.6.22.10/net/core/sock.c linux-2.6.22.10-vs2.3.0.29/net/core/sock.c
28583 --- linux-2.6.22.10/net/core/sock.c     2007-07-09 13:20:05 +0200
28584 +++ linux-2.6.22.10-vs2.3.0.29/net/core/sock.c  2007-10-01 14:57:43 +0200
28585 @@ -125,6 +125,10 @@
28586  #include <linux/ipsec.h>
28587  
28588  #include <linux/filter.h>
28589 +#include <linux/vs_socket.h>
28590 +#include <linux/vs_limit.h>
28591 +#include <linux/vs_context.h>
28592 +#include <linux/vs_network.h>
28593  
28594  #ifdef CONFIG_INET
28595  #include <net/tcp.h>
28596 @@ -812,6 +816,9 @@ int sock_getsockopt(struct socket *sock,
28597         case SO_PEERSEC:
28598                 return security_socket_getpeersec_stream(sock, optval, optlen, len);
28599  
28600 +               case SO_PEERTAG:
28601 +                       return vx_socket_peer_tag(sock, level, optval, optlen, len);
28602 +
28603         default:
28604                 return -ENOPROTOOPT;
28605         }
28606 @@ -869,6 +876,8 @@ struct sock *sk_alloc(int family, gfp_t 
28607                         sk->sk_prot = sk->sk_prot_creator = prot;
28608                         sock_lock_init(sk);
28609                 }
28610 +               sock_vx_init(sk);
28611 +               sock_nx_init(sk);
28612  
28613                 if (security_sk_alloc(sk, family, priority))
28614                         goto out_free;
28615 @@ -907,6 +916,11 @@ void sk_free(struct sock *sk)
28616                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
28617  
28618         security_sk_free(sk);
28619 +       vx_sock_dec(sk);
28620 +       clr_vx_info(&sk->sk_vx_info);
28621 +       sk->sk_xid = -1;
28622 +       clr_nx_info(&sk->sk_nx_info);
28623 +       sk->sk_nid = -1;
28624         if (sk->sk_prot_creator->slab != NULL)
28625                 kmem_cache_free(sk->sk_prot_creator->slab, sk);
28626         else
28627 @@ -924,6 +938,8 @@ struct sock *sk_clone(const struct sock 
28628                 sock_copy(newsk, sk);
28629  
28630                 /* SANITY */
28631 +               sock_vx_init(newsk);
28632 +               sock_nx_init(newsk);
28633                 sk_node_init(&newsk->sk_node);
28634                 sock_lock_init(newsk);
28635                 bh_lock_sock(newsk);
28636 @@ -969,6 +985,12 @@ struct sock *sk_clone(const struct sock 
28637                 newsk->sk_priority = 0;
28638                 atomic_set(&newsk->sk_refcnt, 2);
28639  
28640 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
28641 +               newsk->sk_xid = sk->sk_xid;
28642 +               vx_sock_inc(newsk);
28643 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
28644 +               newsk->sk_nid = sk->sk_nid;
28645 +
28646                 /*
28647                  * Increment the counter in the same struct proto as the master
28648                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
28649 @@ -1551,6 +1573,11 @@ void sock_init_data(struct socket *sock,
28650  
28651         sk->sk_stamp = ktime_set(-1L, -1L);
28652  
28653 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
28654 +       sk->sk_xid = vx_current_xid();
28655 +       vx_sock_inc(sk);
28656 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
28657 +       sk->sk_nid = nx_current_nid();
28658         atomic_set(&sk->sk_refcnt, 1);
28659  }
28660  
28661 diff -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
28662 --- linux-2.6.22.10/net/ipv4/af_inet.c  2007-10-30 01:57:15 +0100
28663 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/af_inet.c       2007-10-05 14:54:36 +0200
28664 @@ -115,6 +115,7 @@
28665  #ifdef CONFIG_IP_MROUTE
28666  #include <linux/mroute.h>
28667  #endif
28668 +#include <linux/vs_limit.h>
28669  
28670  DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
28671  
28672 @@ -308,9 +309,12 @@ lookup_protocol:
28673         }
28674  
28675         err = -EPERM;
28676 +       if ((protocol == IPPROTO_ICMP) &&
28677 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28678 +               goto override;
28679         if (answer->capability > 0 && !capable(answer->capability))
28680                 goto out_rcu_unlock;
28681 -
28682 +override:
28683         sock->ops = answer->ops;
28684         answer_prot = answer->prot;
28685         answer_no_check = answer->no_check;
28686 @@ -424,6 +428,7 @@ int inet_bind(struct socket *sock, struc
28687         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
28688         struct sock *sk = sock->sk;
28689         struct inet_sock *inet = inet_sk(sk);
28690 +       struct nx_v4_sock_addr nsa;
28691         unsigned short snum;
28692         int chk_addr_ret;
28693         int err;
28694 @@ -437,7 +442,11 @@ int inet_bind(struct socket *sock, struc
28695         if (addr_len < sizeof(struct sockaddr_in))
28696                 goto out;
28697  
28698 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
28699 +       err = v4_map_sock_addr(inet, addr, &nsa);
28700 +       if (err)
28701 +               goto out;
28702 +
28703 +       chk_addr_ret = inet_addr_type(nsa.saddr);
28704  
28705         /* Not specified by any standard per-se, however it breaks too
28706          * many applications when removed.  It is unfortunate since
28707 @@ -449,7 +458,7 @@ int inet_bind(struct socket *sock, struc
28708         err = -EADDRNOTAVAIL;
28709         if (!sysctl_ip_nonlocal_bind &&
28710             !inet->freebind &&
28711 -           addr->sin_addr.s_addr != INADDR_ANY &&
28712 +           nsa.saddr != INADDR_ANY &&
28713             chk_addr_ret != RTN_LOCAL &&
28714             chk_addr_ret != RTN_MULTICAST &&
28715             chk_addr_ret != RTN_BROADCAST)
28716 @@ -474,7 +483,7 @@ int inet_bind(struct socket *sock, struc
28717         if (sk->sk_state != TCP_CLOSE || inet->num)
28718                 goto out_release_sock;
28719  
28720 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
28721 +       v4_set_sock_addr(inet, &nsa);
28722         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
28723                 inet->saddr = 0;  /* Use device */
28724  
28725 @@ -667,11 +676,13 @@ int inet_getname(struct socket *sock, st
28726                      peer == 1))
28727                         return -ENOTCONN;
28728                 sin->sin_port = inet->dport;
28729 -               sin->sin_addr.s_addr = inet->daddr;
28730 +               sin->sin_addr.s_addr =
28731 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28732         } else {
28733                 __be32 addr = inet->rcv_saddr;
28734                 if (!addr)
28735                         addr = inet->saddr;
28736 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
28737                 sin->sin_port = inet->sport;
28738                 sin->sin_addr.s_addr = addr;
28739         }
28740 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/devinet.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/devinet.c
28741 --- linux-2.6.22.10/net/ipv4/devinet.c  2007-10-30 01:57:15 +0100
28742 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/devinet.c       2007-09-30 14:58:01 +0200
28743 @@ -427,6 +427,7 @@ struct in_device *inetdev_by_index(int i
28744         return in_dev;
28745  }
28746  
28747 +
28748  /* Called only from RTNL semaphored context. No locks. */
28749  
28750  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
28751 @@ -676,6 +677,8 @@ int devinet_ioctl(unsigned int cmd, void
28752                 *colon = ':';
28753  
28754         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
28755 +               struct nx_info *nxi = current->nx_info;
28756 +
28757                 if (tryaddrmatch) {
28758                         /* Matthias Andree */
28759                         /* compare label and address (4.4BSD style) */
28760 @@ -684,6 +687,8 @@ int devinet_ioctl(unsigned int cmd, void
28761                            This is checked above. */
28762                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28763                              ifap = &ifa->ifa_next) {
28764 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28765 +                                       continue;
28766                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
28767                                     sin_orig.sin_addr.s_addr ==
28768                                                         ifa->ifa_address) {
28769 @@ -696,9 +701,12 @@ int devinet_ioctl(unsigned int cmd, void
28770                    comparing just the label */
28771                 if (!ifa) {
28772                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
28773 -                            ifap = &ifa->ifa_next)
28774 +                            ifap = &ifa->ifa_next) {
28775 +                               if (!nx_v4_ifa_visible(nxi, ifa))
28776 +                                       continue;
28777                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
28778                                         break;
28779 +                       }
28780                 }
28781         }
28782  
28783 @@ -849,6 +857,8 @@ static int inet_gifconf(struct net_devic
28784                 goto out;
28785  
28786         for (; ifa; ifa = ifa->ifa_next) {
28787 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
28788 +                       continue;
28789                 if (!buf) {
28790                         done += sizeof(ifr);
28791                         continue;
28792 @@ -1179,6 +1189,7 @@ static int inet_dump_ifaddr(struct sk_bu
28793         struct net_device *dev;
28794         struct in_device *in_dev;
28795         struct in_ifaddr *ifa;
28796 +       struct sock *sk = skb->sk;
28797         int s_ip_idx, s_idx = cb->args[0];
28798  
28799         s_ip_idx = ip_idx = cb->args[1];
28800 @@ -1193,6 +1204,8 @@ static int inet_dump_ifaddr(struct sk_bu
28801  
28802                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
28803                      ifa = ifa->ifa_next, ip_idx++) {
28804 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
28805 +                               continue;
28806                         if (ip_idx < s_ip_idx)
28807                                 continue;
28808                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
28809 diff -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
28810 --- linux-2.6.22.10/net/ipv4/fib_hash.c 2007-07-09 13:20:05 +0200
28811 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/fib_hash.c      2007-08-05 20:53:13 +0200
28812 @@ -1012,7 +1012,7 @@ static int fib_seq_show(struct seq_file 
28813         prefix  = f->fn_key;
28814         mask    = FZ_MASK(iter->zone);
28815         flags   = fib_flag_trans(fa->fa_type, mask, fi);
28816 -       if (fi)
28817 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
28818                 snprintf(bf, sizeof(bf),
28819                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
28820                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
28821 diff -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
28822 --- linux-2.6.22.10/net/ipv4/inet_connection_sock.c     2007-07-09 13:20:05 +0200
28823 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_connection_sock.c  2007-10-18 01:28:12 +0200
28824 @@ -34,10 +34,40 @@ EXPORT_SYMBOL(inet_csk_timer_bug_msg);
28825   */
28826  int sysctl_local_port_range[2] = { 32768, 61000 };
28827  
28828 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
28829 +{
28830 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
28831 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
28832 +
28833 +       if (inet_v6_ipv6only(sk2))
28834 +               return 0;
28835 +
28836 +       if (sk1_rcv_saddr &&
28837 +           sk2_rcv_saddr &&
28838 +           sk1_rcv_saddr == sk2_rcv_saddr)
28839 +               return 1;
28840 +
28841 +       if (sk1_rcv_saddr &&
28842 +           !sk2_rcv_saddr &&
28843 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
28844 +               return 1;
28845 +
28846 +       if (sk2_rcv_saddr &&
28847 +           !sk1_rcv_saddr &&
28848 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
28849 +               return 1;
28850 +
28851 +       if (!sk1_rcv_saddr &&
28852 +           !sk2_rcv_saddr &&
28853 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
28854 +               return 1;
28855 +
28856 +       return 0;
28857 +}
28858 +
28859  int inet_csk_bind_conflict(const struct sock *sk,
28860                            const struct inet_bind_bucket *tb)
28861  {
28862 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
28863         struct sock *sk2;
28864         struct hlist_node *node;
28865         int reuse = sk->sk_reuse;
28866 @@ -50,9 +80,7 @@ int inet_csk_bind_conflict(const struct 
28867                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
28868                         if (!reuse || !sk2->sk_reuse ||
28869                             sk2->sk_state == TCP_LISTEN) {
28870 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
28871 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
28872 -                                   sk2_rcv_saddr == sk_rcv_saddr)
28873 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
28874                                         break;
28875                         }
28876                 }
28877 diff -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
28878 --- linux-2.6.22.10/net/ipv4/inet_diag.c        2007-10-30 01:57:15 +0100
28879 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_diag.c     2007-10-30 02:36:32 +0100
28880 @@ -98,8 +98,8 @@ static int inet_csk_diag_fill(struct soc
28881  
28882         r->id.idiag_sport = inet->sport;
28883         r->id.idiag_dport = inet->dport;
28884 -       r->id.idiag_src[0] = inet->rcv_saddr;
28885 -       r->id.idiag_dst[0] = inet->daddr;
28886 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
28887 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
28888  
28889  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28890         if (r->idiag_family == AF_INET6) {
28891 @@ -186,8 +186,8 @@ static int inet_twsk_diag_fill(struct in
28892         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
28893         r->id.idiag_sport     = tw->tw_sport;
28894         r->id.idiag_dport     = tw->tw_dport;
28895 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
28896 -       r->id.idiag_dst[0]    = tw->tw_daddr;
28897 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
28898 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
28899         r->idiag_state        = tw->tw_substate;
28900         r->idiag_timer        = 3;
28901         r->idiag_expires      = (tmo * 1000 + HZ - 1) / HZ;
28902 @@ -239,6 +239,7 @@ static int inet_diag_get_exact(struct sk
28903         hashinfo = handler->idiag_hashinfo;
28904  
28905         if (req->idiag_family == AF_INET) {
28906 +               /* TODO: lback */
28907                 sk = inet_lookup(hashinfo, req->id.idiag_dst[0],
28908                                  req->id.idiag_dport, req->id.idiag_src[0],
28909                                  req->id.idiag_sport, req->id.idiag_if);
28910 @@ -478,6 +479,7 @@ static int inet_csk_diag_dump(struct soc
28911                 } else
28912  #endif
28913                 {
28914 +                       /* TODO: lback */
28915                         entry.saddr = &inet->rcv_saddr;
28916                         entry.daddr = &inet->daddr;
28917                 }
28918 @@ -514,6 +516,7 @@ static int inet_twsk_diag_dump(struct in
28919                 } else
28920  #endif
28921                 {
28922 +                       /* TODO: lback */
28923                         entry.saddr = &tw->tw_rcv_saddr;
28924                         entry.daddr = &tw->tw_daddr;
28925                 }
28926 @@ -560,8 +563,8 @@ static int inet_diag_fill_req(struct sk_
28927  
28928         r->id.idiag_sport = inet->sport;
28929         r->id.idiag_dport = ireq->rmt_port;
28930 -       r->id.idiag_src[0] = ireq->loc_addr;
28931 -       r->id.idiag_dst[0] = ireq->rmt_addr;
28932 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
28933 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
28934         r->idiag_expires = jiffies_to_msecs(tmo);
28935         r->idiag_rqueue = 0;
28936         r->idiag_wqueue = 0;
28937 @@ -631,6 +634,7 @@ static int inet_diag_dump_reqs(struct sk
28938                                 continue;
28939  
28940                         if (bc) {
28941 +                               /* TODO: lback */
28942                                 entry.saddr =
28943  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
28944                                         (entry.family == AF_INET6) ?
28945 @@ -697,6 +701,8 @@ static int inet_diag_dump(struct sk_buff
28946                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
28947                                 struct inet_sock *inet = inet_sk(sk);
28948  
28949 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28950 +                                       continue;
28951                                 if (num < s_num) {
28952                                         num++;
28953                                         continue;
28954 @@ -757,6 +763,8 @@ skip_listen_ht:
28955                 sk_for_each(sk, node, &head->chain) {
28956                         struct inet_sock *inet = inet_sk(sk);
28957  
28958 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
28959 +                               continue;
28960                         if (num < s_num)
28961                                 goto next_normal;
28962                         if (!(r->idiag_states & (1 << sk->sk_state)))
28963 @@ -781,6 +789,8 @@ next_normal:
28964                         inet_twsk_for_each(tw, node,
28965                                     &head->twchain) {
28966  
28967 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
28968 +                                       continue;
28969                                 if (num < s_num)
28970                                         goto next_dying;
28971                                 if (r->id.idiag_sport != tw->tw_sport &&
28972 diff -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
28973 --- linux-2.6.22.10/net/ipv4/inet_hashtables.c  2007-05-02 19:25:40 +0200
28974 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/inet_hashtables.c       2007-08-05 20:53:13 +0200
28975 @@ -140,11 +140,10 @@ static struct sock *inet_lookup_listener
28976                         const __be32 rcv_saddr = inet->rcv_saddr;
28977                         int score = sk->sk_family == PF_INET ? 1 : 0;
28978  
28979 -                       if (rcv_saddr) {
28980 -                               if (rcv_saddr != daddr)
28981 -                                       continue;
28982 +                       if (v4_inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
28983                                 score += 2;
28984 -                       }
28985 +                       else
28986 +                               continue;
28987                         if (sk->sk_bound_dev_if) {
28988                                 if (sk->sk_bound_dev_if != dif)
28989                                         continue;
28990 @@ -175,7 +174,7 @@ struct sock *__inet_lookup_listener(stru
28991                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
28992  
28993                 if (inet->num == hnum && !sk->sk_node.next &&
28994 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
28995 +                   v4_inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
28996                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
28997                     !sk->sk_bound_dev_if)
28998                         goto sherry_cache;
28999 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/raw.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/raw.c
29000 --- linux-2.6.22.10/net/ipv4/raw.c      2007-07-09 13:20:06 +0200
29001 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/raw.c   2007-10-05 12:29:05 +0200
29002 @@ -112,7 +112,7 @@ struct sock *__raw_v4_lookup(struct sock
29003  
29004                 if (inet->num == num                                    &&
29005                     !(inet->daddr && inet->daddr != raddr)              &&
29006 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
29007 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
29008                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
29009                         goto found; /* gotcha */
29010         }
29011 @@ -314,6 +314,12 @@ static int raw_send_hdrinc(struct sock *
29012                 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
29013         }
29014  
29015 +       err = -EPERM;
29016 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
29017 +               sk->sk_nx_info &&
29018 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
29019 +               goto error_free;
29020 +
29021         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
29022                       dst_output);
29023         if (err > 0)
29024 @@ -325,6 +331,7 @@ out:
29025  
29026  error_fault:
29027         err = -EFAULT;
29028 +error_free:
29029         kfree_skb(skb);
29030  error:
29031         IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
29032 @@ -491,6 +498,12 @@ static int raw_sendmsg(struct kiocb *ioc
29033                 }
29034  
29035                 security_sk_classify_flow(sk, &fl);
29036 +               if (sk->sk_nx_info) {
29037 +                       err = ip_v4_find_src(sk->sk_nx_info, &rt, &fl);
29038 +
29039 +                       if (err)
29040 +                               goto done;
29041 +               }
29042                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29043         }
29044         if (err)
29045 @@ -553,17 +566,19 @@ static int raw_bind(struct sock *sk, str
29046  {
29047         struct inet_sock *inet = inet_sk(sk);
29048         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
29049 +       struct nx_v4_sock_addr nsa = { 0 };
29050         int ret = -EINVAL;
29051         int chk_addr_ret;
29052  
29053         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
29054                 goto out;
29055 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
29056 +       v4_map_sock_addr(inet, addr, &nsa);
29057 +       chk_addr_ret = inet_addr_type(nsa.saddr);
29058         ret = -EADDRNOTAVAIL;
29059 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
29060 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
29061             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
29062                 goto out;
29063 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
29064 +       v4_set_sock_addr(inet, &nsa);
29065         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
29066                 inet->saddr = 0;  /* Use device */
29067         sk_dst_reset(sk);
29068 @@ -615,7 +630,8 @@ static int raw_recvmsg(struct kiocb *ioc
29069         /* Copy the address. */
29070         if (sin) {
29071                 sin->sin_family = AF_INET;
29072 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29073 +               sin->sin_addr.s_addr =
29074 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
29075                 sin->sin_port = 0;
29076                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
29077         }
29078 @@ -795,7 +811,8 @@ static struct sock *raw_get_first(struct
29079                 struct hlist_node *node;
29080  
29081                 sk_for_each(sk, node, &raw_v4_htable[state->bucket])
29082 -                       if (sk->sk_family == PF_INET)
29083 +                       if (sk->sk_family == PF_INET &&
29084 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29085                                 goto found;
29086         }
29087         sk = NULL;
29088 @@ -811,7 +828,8 @@ static struct sock *raw_get_next(struct 
29089                 sk = sk_next(sk);
29090  try_again:
29091                 ;
29092 -       } while (sk && sk->sk_family != PF_INET);
29093 +       } while (sk && (sk->sk_family != PF_INET ||
29094 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29095  
29096         if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
29097                 sk = sk_head(&raw_v4_htable[state->bucket]);
29098 @@ -863,7 +881,10 @@ static __inline__ char *get_raw_sock(str
29099  
29100         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29101                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29102 -               i, src, srcp, dest, destp, sp->sk_state,
29103 +               i,
29104 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29105 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29106 +               sp->sk_state,
29107                 atomic_read(&sp->sk_wmem_alloc),
29108                 atomic_read(&sp->sk_rmem_alloc),
29109                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29110 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/tcp.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp.c
29111 --- linux-2.6.22.10/net/ipv4/tcp.c      2007-10-30 01:57:15 +0100
29112 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp.c   2007-09-05 03:06:12 +0200
29113 @@ -258,6 +258,7 @@
29114  #include <linux/cache.h>
29115  #include <linux/err.h>
29116  #include <linux/crypto.h>
29117 +#include <linux/in.h>
29118  
29119  #include <net/icmp.h>
29120  #include <net/tcp.h>
29121 diff -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
29122 --- linux-2.6.22.10/net/ipv4/tcp_ipv4.c 2007-10-30 01:57:15 +0100
29123 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp_ipv4.c      2007-09-05 03:06:12 +0200
29124 @@ -1975,6 +1975,12 @@ static void *listening_get_next(struct s
29125                 req = req->dl_next;
29126                 while (1) {
29127                         while (req) {
29128 +                               vxdprintk(VXD_CBIT(net, 6),
29129 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
29130 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
29131 +                               if (req->sk &&
29132 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
29133 +                                       continue;
29134                                 if (req->rsk_ops->family == st->family) {
29135                                         cur = req;
29136                                         goto out;
29137 @@ -1999,6 +2005,10 @@ get_req:
29138         }
29139  get_sk:
29140         sk_for_each_from(sk, node) {
29141 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
29142 +                       sk, sk->sk_nid, nx_current_nid());
29143 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29144 +                       continue;
29145                 if (sk->sk_family == st->family) {
29146                         cur = sk;
29147                         goto out;
29148 @@ -2050,18 +2060,26 @@ static void *established_get_first(struc
29149  
29150                 read_lock(&tcp_hashinfo.ehash[st->bucket].lock);
29151                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
29152 -                       if (sk->sk_family != st->family) {
29153 +                       vxdprintk(VXD_CBIT(net, 6),
29154 +                               "sk,egf: %p [#%d] (from %d)",
29155 +                               sk, sk->sk_nid, nx_current_nid());
29156 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29157 +                               continue;
29158 +                       if (sk->sk_family != st->family)
29159                                 continue;
29160 -                       }
29161                         rc = sk;
29162                         goto out;
29163                 }
29164                 st->state = TCP_SEQ_STATE_TIME_WAIT;
29165                 inet_twsk_for_each(tw, node,
29166                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
29167 -                       if (tw->tw_family != st->family) {
29168 +                       vxdprintk(VXD_CBIT(net, 6),
29169 +                               "tw: %p [#%d] (from %d)",
29170 +                               tw, tw->tw_nid, nx_current_nid());
29171 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
29172 +                               continue;
29173 +                       if (tw->tw_family != st->family)
29174                                 continue;
29175 -                       }
29176                         rc = tw;
29177                         goto out;
29178                 }
29179 @@ -2085,7 +2103,8 @@ static void *established_get_next(struct
29180                 tw = cur;
29181                 tw = tw_next(tw);
29182  get_tw:
29183 -               while (tw && tw->tw_family != st->family) {
29184 +               while (tw && (tw->tw_family != st->family ||
29185 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
29186                         tw = tw_next(tw);
29187                 }
29188                 if (tw) {
29189 @@ -2109,6 +2128,11 @@ get_tw:
29190                 sk = sk_next(sk);
29191  
29192         sk_for_each_from(sk, node) {
29193 +               vxdprintk(VXD_CBIT(net, 6),
29194 +                       "sk,egn: %p [#%d] (from %d)",
29195 +                       sk, sk->sk_nid, nx_current_nid());
29196 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29197 +                       continue;
29198                 if (sk->sk_family == st->family)
29199                         goto found;
29200         }
29201 @@ -2284,9 +2308,9 @@ static void get_openreq4(struct sock *sk
29202         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29203                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p",
29204                 i,
29205 -               ireq->loc_addr,
29206 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
29207                 ntohs(inet_sk(sk)->sport),
29208 -               ireq->rmt_addr,
29209 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
29210                 ntohs(ireq->rmt_port),
29211                 TCP_SYN_RECV,
29212                 0, 0, /* could print option size, but that is af dependent. */
29213 @@ -2328,7 +2352,10 @@ static void get_tcp4_sock(struct sock *s
29214  
29215         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
29216                         "%08X %5d %8d %lu %d %p %u %u %u %u %d",
29217 -               i, src, srcp, dest, destp, sk->sk_state,
29218 +               i,
29219 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29220 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29221 +               sk->sk_state,
29222                 tp->write_seq - tp->snd_una,
29223                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
29224                                              (tp->rcv_nxt - tp->copied_seq),
29225 @@ -2363,7 +2390,10 @@ static void get_timewait4_sock(struct in
29226  
29227         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29228                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p",
29229 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
29230 +               i,
29231 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29232 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29233 +               tw->tw_substate, 0, 0,
29234                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
29235                 atomic_read(&tw->tw_refcnt), tw);
29236  }
29237 diff -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
29238 --- linux-2.6.22.10/net/ipv4/tcp_minisocks.c    2007-07-09 13:20:06 +0200
29239 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/tcp_minisocks.c 2007-08-05 20:53:13 +0200
29240 @@ -28,6 +28,10 @@
29241  #include <net/inet_common.h>
29242  #include <net/xfrm.h>
29243  
29244 +#include <linux/vs_limit.h>
29245 +#include <linux/vs_socket.h>
29246 +#include <linux/vs_context.h>
29247 +
29248  #ifdef CONFIG_SYSCTL
29249  #define SYNC_INIT 0 /* let the user enable it */
29250  #else
29251 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
29252                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
29253                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
29254  
29255 +               tw->tw_xid              = sk->sk_xid;
29256 +               tw->tw_vx_info          = NULL;
29257 +               tw->tw_nid              = sk->sk_nid;
29258 +               tw->tw_nx_info          = NULL;
29259 +
29260  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
29261                 if (tw->tw_family == PF_INET6) {
29262                         struct ipv6_pinfo *np = inet6_sk(sk);
29263 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/udp.c linux-2.6.22.10-vs2.3.0.29/net/ipv4/udp.c
29264 --- linux-2.6.22.10/net/ipv4/udp.c      2007-07-09 13:20:06 +0200
29265 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv4/udp.c   2007-10-09 14:09:19 +0200
29266 @@ -219,14 +219,7 @@ int udp_get_port(struct sock *sk, unsign
29267         return  __udp_lib_get_port(sk, snum, udp_hash, &udp_port_rover, scmp);
29268  }
29269  
29270 -int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
29271 -{
29272 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
29273 -
29274 -       return  ( !ipv6_only_sock(sk2)  &&
29275 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
29276 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
29277 -}
29278 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29279  
29280  static inline int udp_v4_get_port(struct sock *sk, unsigned short snum)
29281  {
29282 @@ -246,15 +239,22 @@ static struct sock *__udp4_lib_lookup(__
29283         int badness = -1;
29284  
29285         read_lock(&udp_hash_lock);
29286 +
29287         sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
29288                 struct inet_sock *inet = inet_sk(sk);
29289  
29290                 if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
29291                         int score = (sk->sk_family == PF_INET ? 1 : 0);
29292 +
29293                         if (inet->rcv_saddr) {
29294                                 if (inet->rcv_saddr != daddr)
29295                                         continue;
29296                                 score+=2;
29297 +                       } else {
29298 +                               /* block non nx_info ips */
29299 +                               if (!v4_addr_in_nx_info(sk->sk_nx_info,
29300 +                                       daddr, NXA_MASK_BIND))
29301 +                                       continue;
29302                         }
29303                         if (inet->daddr) {
29304                                 if (inet->daddr != saddr)
29305 @@ -280,6 +280,7 @@ static struct sock *__udp4_lib_lookup(__
29306                         }
29307                 }
29308         }
29309 +
29310         if (result)
29311                 sock_hold(result);
29312         read_unlock(&udp_hash_lock);
29313 @@ -301,7 +302,7 @@ static inline struct sock *udp_v4_mcast_
29314                 if (s->sk_hash != hnum                                  ||
29315                     (inet->daddr && inet->daddr != rmt_addr)            ||
29316                     (inet->dport != rmt_port && inet->dport)            ||
29317 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
29318 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
29319                     ipv6_only_sock(s)                                   ||
29320                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
29321                         continue;
29322 @@ -631,7 +632,14 @@ int udp_sendmsg(struct kiocb *iocb, stru
29323                                     .uli_u = { .ports =
29324                                                { .sport = inet->sport,
29325                                                  .dport = dport } } };
29326 +               struct nx_info *nxi = sk->sk_nx_info;
29327 +
29328                 security_sk_classify_flow(sk, &fl);
29329 +
29330 +               err = ip_v4_find_src(nxi, &rt, &fl);
29331 +               if (err)
29332 +                       goto out;
29333 +
29334                 err = ip_route_output_flow(&rt, &fl, sk, 1);
29335                 if (err) {
29336                         if (err == -ENETUNREACH)
29337 @@ -871,7 +879,8 @@ try_again:
29338         {
29339                 sin->sin_family = AF_INET;
29340                 sin->sin_port = udp_hdr(skb)->source;
29341 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
29342 +               sin->sin_addr.s_addr = nx_map_sock_lback(
29343 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
29344                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
29345         }
29346         if (inet->cmsg_flags)
29347 @@ -1551,7 +1560,8 @@ static struct sock *udp_get_first(struct
29348         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
29349                 struct hlist_node *node;
29350                 sk_for_each(sk, node, state->hashtable + state->bucket) {
29351 -                       if (sk->sk_family == state->family)
29352 +                       if (sk->sk_family == state->family &&
29353 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
29354                                 goto found;
29355                 }
29356         }
29357 @@ -1568,7 +1578,8 @@ static struct sock *udp_get_next(struct 
29358                 sk = sk_next(sk);
29359  try_again:
29360                 ;
29361 -       } while (sk && sk->sk_family != state->family);
29362 +       } while (sk && (sk->sk_family != state->family ||
29363 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
29364  
29365         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
29366                 sk = sk_head(state->hashtable + state->bucket);
29367 @@ -1681,7 +1692,10 @@ static void udp4_format_sock(struct sock
29368  
29369         sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
29370                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p",
29371 -               bucket, src, srcp, dest, destp, sp->sk_state,
29372 +               bucket,
29373 +               nx_map_sock_lback(current_nx_info(), src), srcp,
29374 +               nx_map_sock_lback(current_nx_info(), dest), destp,
29375 +               sp->sk_state,
29376                 atomic_read(&sp->sk_wmem_alloc),
29377                 atomic_read(&sp->sk_rmem_alloc),
29378                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
29379 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/Kconfig linux-2.6.22.10-vs2.3.0.29/net/ipv6/Kconfig
29380 --- linux-2.6.22.10/net/ipv6/Kconfig    2007-07-09 13:20:06 +0200
29381 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/Kconfig 2007-08-05 20:53:13 +0200
29382 @@ -4,8 +4,8 @@
29383  
29384  #   IPv6 as module will cause a CRASH if you try to unload it
29385  config IPV6
29386 -       tristate "The IPv6 protocol"
29387 -       default m
29388 +       bool "The IPv6 protocol"
29389 +       default n
29390         ---help---
29391           This is complemental support for the IP version 6.
29392           You will still be able to do traditional IPv4 networking as well.
29393 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
29394 --- linux-2.6.22.10/net/ipv6/addrconf.c 2007-10-30 01:57:15 +0100
29395 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/addrconf.c      2007-10-05 14:54:36 +0200
29396 @@ -85,6 +85,7 @@
29397  
29398  #include <linux/proc_fs.h>
29399  #include <linux/seq_file.h>
29400 +#include <linux/vs_inet6.h>
29401  
29402  /* Set to 3 to get tracing... */
29403  #define ACONF_DEBUG 2
29404 @@ -897,7 +898,8 @@ static inline int ipv6_saddr_label(const
29405  }
29406  
29407  int ipv6_dev_get_saddr(struct net_device *daddr_dev,
29408 -                      struct in6_addr *daddr, struct in6_addr *saddr)
29409 +                      struct in6_addr *daddr, struct in6_addr *saddr,
29410 +                      struct nx_info *nxi)
29411  {
29412         struct ipv6_saddr_score hiscore;
29413         struct inet6_ifaddr *ifa_result = NULL;
29414 @@ -942,6 +944,10 @@ int ipv6_dev_get_saddr(struct net_device
29415  
29416                         score.addr_type = __ipv6_addr_type(&ifa->addr);
29417  
29418 +                       /* Use only addresses assigned to the context */
29419 +                       if (!v6_ifa_in_nx_info(ifa, nxi))
29420 +                               continue;
29421 +
29422                         /* Rule 0:
29423                          * - Tentative Address (RFC2462 section 5.4)
29424                          *  - A tentative address is not considered
29425 @@ -1155,9 +1161,10 @@ record_it:
29426  
29427  
29428  int ipv6_get_saddr(struct dst_entry *dst,
29429 -                  struct in6_addr *daddr, struct in6_addr *saddr)
29430 +                  struct in6_addr *daddr, struct in6_addr *saddr,
29431 +                  struct nx_info *nxi)
29432  {
29433 -       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
29434 +       return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr, nxi);
29435  }
29436  
29437  EXPORT_SYMBOL(ipv6_get_saddr);
29438 @@ -1253,35 +1260,46 @@ struct inet6_ifaddr * ipv6_get_ifaddr(st
29439         return ifp;
29440  }
29441  
29442 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
29443 +
29444  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
29445  {
29446         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
29447         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
29448 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
29449         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
29450         int sk_ipv6only = ipv6_only_sock(sk);
29451         int sk2_ipv6only = inet_v6_ipv6only(sk2);
29452         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
29453         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
29454  
29455 -       if (!sk2_rcv_saddr && !sk_ipv6only)
29456 +       /* FIXME: needs handling for v4 ANY */
29457 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
29458                 return 1;
29459  
29460         if (addr_type2 == IPV6_ADDR_ANY &&
29461 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
29462 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
29463 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
29464                 return 1;
29465  
29466         if (addr_type == IPV6_ADDR_ANY &&
29467 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
29468 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
29469 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
29470 +               return 1;
29471 +
29472 +       if (addr_type == IPV6_ADDR_ANY &&
29473 +           addr_type2 == IPV6_ADDR_ANY &&
29474 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
29475                 return 1;
29476  
29477         if (sk2_rcv_saddr6 &&
29478 +           addr_type != IPV6_ADDR_ANY &&
29479 +           addr_type != IPV6_ADDR_ANY &&
29480             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
29481                 return 1;
29482  
29483         if (addr_type == IPV6_ADDR_MAPPED &&
29484             !sk2_ipv6only &&
29485 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
29486 +           ipv4_rcv_saddr_equal(sk, sk2))
29487                 return 1;
29488  
29489         return 0;
29490 @@ -2772,7 +2790,10 @@ static void if6_seq_stop(struct seq_file
29491  static int if6_seq_show(struct seq_file *seq, void *v)
29492  {
29493         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
29494 -       seq_printf(seq,
29495 +
29496 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
29497 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
29498 +               seq_printf(seq,
29499                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
29500                    NIP6(ifp->addr),
29501                    ifp->idev->dev->ifindex,
29502 @@ -3254,6 +3275,11 @@ static int inet6_dump_addr(struct sk_buf
29503         struct inet6_ifaddr *ifa;
29504         struct ifmcaddr6 *ifmca;
29505         struct ifacaddr6 *ifaca;
29506 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29507 +
29508 +       /* disable ipv6 on non v6 guests */
29509 +       if (nxi && !nx_info_has_v6(nxi))
29510 +               return skb->len;
29511  
29512         s_idx = cb->args[0];
29513         s_ip_idx = ip_idx = cb->args[1];
29514 @@ -3275,6 +3301,8 @@ static int inet6_dump_addr(struct sk_buf
29515                              ifa = ifa->if_next, ip_idx++) {
29516                                 if (ip_idx < s_ip_idx)
29517                                         continue;
29518 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
29519 +                                       continue;
29520                                 if ((err = inet6_fill_ifaddr(skb, ifa,
29521                                     NETLINK_CB(cb->skb).pid,
29522                                     cb->nlh->nlmsg_seq, RTM_NEWADDR,
29523 @@ -3288,6 +3316,8 @@ static int inet6_dump_addr(struct sk_buf
29524                              ifmca = ifmca->next, ip_idx++) {
29525                                 if (ip_idx < s_ip_idx)
29526                                         continue;
29527 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
29528 +                                       continue;
29529                                 if ((err = inet6_fill_ifmcaddr(skb, ifmca,
29530                                     NETLINK_CB(cb->skb).pid,
29531                                     cb->nlh->nlmsg_seq, RTM_GETMULTICAST,
29532 @@ -3301,6 +3331,8 @@ static int inet6_dump_addr(struct sk_buf
29533                              ifaca = ifaca->aca_next, ip_idx++) {
29534                                 if (ip_idx < s_ip_idx)
29535                                         continue;
29536 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
29537 +                                       continue;
29538                                 if ((err = inet6_fill_ifacaddr(skb, ifaca,
29539                                     NETLINK_CB(cb->skb).pid,
29540                                     cb->nlh->nlmsg_seq, RTM_GETANYCAST,
29541 @@ -3577,12 +3609,19 @@ static int inet6_dump_ifinfo(struct sk_b
29542         int s_idx = cb->args[0];
29543         struct net_device *dev;
29544         struct inet6_dev *idev;
29545 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
29546 +
29547 +       /* FIXME: maybe disable ipv6 on non v6 guests?
29548 +       if (skb->sk && skb->sk->sk_vx_info)
29549 +               return skb->len;        */
29550  
29551         read_lock(&dev_base_lock);
29552         idx = 0;
29553         for_each_netdev(dev) {
29554                 if (idx < s_idx)
29555                         goto cont;
29556 +               if (!v6_dev_in_nx_info(dev, nxi))
29557 +                       goto cont;
29558                 if ((idev = in6_dev_get(dev)) == NULL)
29559                         goto cont;
29560                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
29561 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
29562 --- linux-2.6.22.10/net/ipv6/af_inet6.c 2007-10-30 01:57:15 +0100
29563 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/af_inet6.c      2007-10-05 12:29:05 +0200
29564 @@ -43,6 +43,7 @@
29565  #include <linux/netdevice.h>
29566  #include <linux/icmpv6.h>
29567  #include <linux/netfilter_ipv6.h>
29568 +#include <linux/vs_inet6.h>
29569  
29570  #include <net/ip.h>
29571  #include <net/ipv6.h>
29572 @@ -150,9 +151,12 @@ lookup_protocol:
29573         }
29574  
29575         err = -EPERM;
29576 +       if ((protocol == IPPROTO_ICMPV6) &&
29577 +               nx_capable(answer->capability, NXC_RAW_ICMP))
29578 +               goto override;
29579         if (answer->capability > 0 && !capable(answer->capability))
29580                 goto out_rcu_unlock;
29581 -
29582 +override:
29583         sock->ops = answer->ops;
29584         answer_prot = answer->prot;
29585         answer_no_check = answer->no_check;
29586 @@ -250,6 +254,7 @@ int inet6_bind(struct socket *sock, stru
29587         struct sock *sk = sock->sk;
29588         struct inet_sock *inet = inet_sk(sk);
29589         struct ipv6_pinfo *np = inet6_sk(sk);
29590 +       struct nx_v6_sock_addr nsa;
29591         __be32 v4addr = 0;
29592         unsigned short snum;
29593         int addr_type = 0;
29594 @@ -261,6 +266,11 @@ int inet6_bind(struct socket *sock, stru
29595  
29596         if (addr_len < SIN6_LEN_RFC2133)
29597                 return -EINVAL;
29598 +
29599 +       err = v6_map_sock_addr(inet, addr, &nsa);
29600 +       if (err)
29601 +               return err;
29602 +
29603         addr_type = ipv6_addr_type(&addr->sin6_addr);
29604         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
29605                 return -EINVAL;
29606 @@ -284,6 +294,10 @@ int inet6_bind(struct socket *sock, stru
29607                         err = -EADDRNOTAVAIL;
29608                         goto out;
29609                 }
29610 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
29611 +                       err = -EADDRNOTAVAIL;
29612 +                       goto out;
29613 +               }
29614         } else {
29615                 if (addr_type != IPV6_ADDR_ANY) {
29616                         struct net_device *dev = NULL;
29617 @@ -309,6 +323,11 @@ int inet6_bind(struct socket *sock, stru
29618                                 }
29619                         }
29620  
29621 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
29622 +                               err = -EADDRNOTAVAIL;
29623 +                               goto out;
29624 +                       }
29625 +
29626                         /* ipv4 addr of the socket is invalid.  Only the
29627                          * unspecified and mapped address have a v4 equivalent.
29628                          */
29629 @@ -326,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
29630                 }
29631         }
29632  
29633 +       v6_set_sock_addr(inet, &nsa);
29634 +
29635         inet->rcv_saddr = v4addr;
29636         inet->saddr = v4addr;
29637  
29638 @@ -420,9 +441,11 @@ int inet6_getname(struct socket *sock, s
29639                         return -ENOTCONN;
29640                 sin->sin6_port = inet->dport;
29641                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
29642 +               /* FIXME: remap lback? */
29643                 if (np->sndflow)
29644                         sin->sin6_flowinfo = np->flow_label;
29645         } else {
29646 +               /* FIXME: remap lback? */
29647                 if (ipv6_addr_any(&np->rcv_saddr))
29648                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
29649                 else
29650 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
29651 --- linux-2.6.22.10/net/ipv6/fib6_rules.c       2007-07-09 13:20:06 +0200
29652 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/fib6_rules.c    2007-08-12 00:22:19 +0200
29653 @@ -107,7 +107,7 @@ static int fib6_rule_action(struct fib_r
29654                     r->src.plen && !(flags & RT6_LOOKUP_F_HAS_SADDR)) {
29655                         struct in6_addr saddr;
29656                         if (ipv6_get_saddr(&rt->u.dst, &flp->fl6_dst,
29657 -                                          &saddr))
29658 +                                          &saddr, NULL))
29659                                 goto again;
29660                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
29661                                                r->src.plen))
29662 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
29663 --- linux-2.6.22.10/net/ipv6/inet6_hashtables.c 2007-05-02 19:25:45 +0200
29664 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/inet6_hashtables.c      2007-08-05 20:53:13 +0200
29665 @@ -16,6 +16,7 @@
29666  
29667  #include <linux/module.h>
29668  #include <linux/random.h>
29669 +#include <linux/vs_inet6.h>
29670  
29671  #include <net/inet_connection_sock.h>
29672  #include <net/inet_hashtables.h>
29673 @@ -121,6 +122,9 @@ struct sock *inet6_lookup_listener(struc
29674                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29675                                         continue;
29676                                 score++;
29677 +                       } else {
29678 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29679 +                                       continue;
29680                         }
29681                         if (sk->sk_bound_dev_if) {
29682                                 if (sk->sk_bound_dev_if != dif)
29683 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
29684 --- linux-2.6.22.10/net/ipv6/ip6_output.c       2007-10-30 01:57:15 +0100
29685 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/ip6_output.c    2007-09-30 14:58:01 +0200
29686 @@ -884,7 +884,7 @@ static int ip6_dst_lookup_tail(struct so
29687                 goto out_err_release;
29688  
29689         if (ipv6_addr_any(&fl->fl6_src)) {
29690 -               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src);
29691 +               err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src, sk->sk_nx_info);
29692                 if (err)
29693                         goto out_err_release;
29694         }
29695 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
29696 --- linux-2.6.22.10/net/ipv6/ndisc.c    2007-10-30 01:57:15 +0100
29697 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/ndisc.c 2007-09-30 14:58:01 +0200
29698 @@ -531,7 +531,7 @@ static void ndisc_send_na(struct net_dev
29699                         override = 0;
29700                 in6_ifa_put(ifp);
29701         } else {
29702 -               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr))
29703 +               if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr, NULL))
29704                         return;
29705                 src_addr = &tmpaddr;
29706         }
29707 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/route.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/route.c
29708 --- linux-2.6.22.10/net/ipv6/route.c    2007-07-09 13:20:06 +0200
29709 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/route.c 2007-08-12 00:22:19 +0200
29710 @@ -2182,7 +2182,7 @@ static int rt6_fill_node(struct sk_buff 
29711                 NLA_PUT_U32(skb, RTA_IIF, iif);
29712         else if (dst) {
29713                 struct in6_addr saddr_buf;
29714 -               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf) == 0)
29715 +               if (ipv6_get_saddr(&rt->u.dst, dst, &saddr_buf, skb->sk->sk_nx_info) == 0)
29716                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
29717         }
29718  
29719 diff -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
29720 --- linux-2.6.22.10/net/ipv6/tcp_ipv6.c 2007-10-30 01:57:15 +0100
29721 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/tcp_ipv6.c      2007-09-18 12:32:20 +0200
29722 @@ -68,6 +68,7 @@
29723  
29724  #include <linux/crypto.h>
29725  #include <linux/scatterlist.h>
29726 +#include <linux/vs_inet6.h>
29727  
29728  /* Socket used for sending RSTs and ACKs */
29729  static struct socket *tcp6_socket;
29730 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
29731          *      connect() to INADDR_ANY means loopback (BSD'ism).
29732          */
29733  
29734 -       if(ipv6_addr_any(&usin->sin6_addr))
29735 -               usin->sin6_addr.s6_addr[15] = 0x1;
29736 +       if(ipv6_addr_any(&usin->sin6_addr)) {
29737 +               struct nx_info *nxi =  sk->sk_nx_info;
29738 +
29739 +               if (nxi && nx_info_has_v6(nxi))
29740 +                       /* FIXME: remap lback? */
29741 +                       usin->sin6_addr = nxi->v6.ip;
29742 +               else
29743 +                       usin->sin6_addr.s6_addr[15] = 0x1;
29744 +       }
29745  
29746         addr_type = ipv6_addr_type(&usin->sin6_addr);
29747  
29748 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/udp.c linux-2.6.22.10-vs2.3.0.29/net/ipv6/udp.c
29749 --- linux-2.6.22.10/net/ipv6/udp.c      2007-07-09 13:20:06 +0200
29750 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/udp.c   2007-08-12 03:34:32 +0200
29751 @@ -48,6 +48,7 @@
29752  
29753  #include <linux/proc_fs.h>
29754  #include <linux/seq_file.h>
29755 +#include <linux/vs_inet6.h>
29756  #include "udp_impl.h"
29757  
29758  DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly;
29759 @@ -82,6 +83,10 @@ static struct sock *__udp6_lib_lookup(st
29760                                 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
29761                                         continue;
29762                                 score++;
29763 +                       } else {
29764 +                               /* block non nx_info ips */
29765 +                               if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
29766 +                                       continue;
29767                         }
29768                         if (!ipv6_addr_any(&np->daddr)) {
29769                                 if (!ipv6_addr_equal(&np->daddr, saddr))
29770 diff -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
29771 --- linux-2.6.22.10/net/ipv6/xfrm6_policy.c     2007-07-09 13:20:06 +0200
29772 +++ linux-2.6.22.10-vs2.3.0.29/net/ipv6/xfrm6_policy.c  2007-08-12 00:22:19 +0200
29773 @@ -49,7 +49,7 @@ static int xfrm6_get_saddr(xfrm_address_
29774  
29775         if (!xfrm6_dst_lookup((struct xfrm_dst **)&rt, &fl_tunnel)) {
29776                 ipv6_get_saddr(&rt->u.dst, (struct in6_addr *)&daddr->a6,
29777 -                              (struct in6_addr *)&saddr->a6);
29778 +                              (struct in6_addr *)&saddr->a6, NULL);
29779                 dst_release(&rt->u.dst);
29780                 return 0;
29781         }
29782 diff -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
29783 --- linux-2.6.22.10/net/netlink/af_netlink.c    2007-07-09 13:20:07 +0200
29784 +++ linux-2.6.22.10-vs2.3.0.29/net/netlink/af_netlink.c 2007-08-05 20:53:13 +0200
29785 @@ -56,6 +56,9 @@
29786  #include <linux/audit.h>
29787  #include <linux/selinux.h>
29788  #include <linux/mutex.h>
29789 +#include <linux/vs_context.h>
29790 +#include <linux/vs_network.h>
29791 +#include <linux/vs_limit.h>
29792  
29793  #include <net/sock.h>
29794  #include <net/scm.h>
29795 diff -NurpP --minimal linux-2.6.22.10/net/sctp/ipv6.c linux-2.6.22.10-vs2.3.0.29/net/sctp/ipv6.c
29796 --- linux-2.6.22.10/net/sctp/ipv6.c     2007-10-30 01:57:15 +0100
29797 +++ linux-2.6.22.10-vs2.3.0.29/net/sctp/ipv6.c  2007-08-12 00:22:19 +0200
29798 @@ -303,7 +303,7 @@ static void sctp_v6_get_saddr(struct sct
29799                           __FUNCTION__, asoc, dst, NIP6(daddr->v6.sin6_addr));
29800  
29801         if (!asoc) {
29802 -               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr);
29803 +               ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr, asoc->base.sk->sk_nx_info);
29804                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
29805                                   NIP6(saddr->v6.sin6_addr));
29806                 return;
29807 diff -NurpP --minimal linux-2.6.22.10/net/socket.c linux-2.6.22.10-vs2.3.0.29/net/socket.c
29808 --- linux-2.6.22.10/net/socket.c        2007-10-30 01:57:15 +0100
29809 +++ linux-2.6.22.10-vs2.3.0.29/net/socket.c     2007-09-05 03:06:12 +0200
29810 @@ -92,6 +92,10 @@
29811  
29812  #include <net/sock.h>
29813  #include <linux/netfilter.h>
29814 +#include <linux/vs_base.h>
29815 +#include <linux/vs_socket.h>
29816 +#include <linux/vs_inet.h>
29817 +#include <linux/vs_inet6.h>
29818  
29819  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
29820  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
29821 @@ -543,7 +547,7 @@ static inline int __sock_sendmsg(struct 
29822                                  struct msghdr *msg, size_t size)
29823  {
29824         struct sock_iocb *si = kiocb_to_siocb(iocb);
29825 -       int err;
29826 +       int err, len;
29827  
29828         si->sock = sock;
29829         si->scm = NULL;
29830 @@ -554,7 +558,22 @@ static inline int __sock_sendmsg(struct 
29831         if (err)
29832                 return err;
29833  
29834 -       return sock->ops->sendmsg(iocb, sock, msg, size);
29835 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
29836 +       if (sock->sk) {
29837 +               if (len == size)
29838 +                       vx_sock_send(sock->sk, size);
29839 +               else
29840 +                       vx_sock_fail(sock->sk, size);
29841 +       }
29842 +       vxdprintk(VXD_CBIT(net, 7),
29843 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29844 +               sock, sock->sk,
29845 +               (sock->sk)?sock->sk->sk_nx_info:0,
29846 +               (sock->sk)?sock->sk->sk_vx_info:0,
29847 +               (sock->sk)?sock->sk->sk_xid:0,
29848 +               (sock->sk)?sock->sk->sk_nid:0,
29849 +               (unsigned int)size, len);
29850 +       return len;
29851  }
29852  
29853  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
29854 @@ -623,7 +642,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
29855  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
29856                                  struct msghdr *msg, size_t size, int flags)
29857  {
29858 -       int err;
29859 +       int err, len;
29860         struct sock_iocb *si = kiocb_to_siocb(iocb);
29861  
29862         si->sock = sock;
29863 @@ -636,7 +655,18 @@ static inline int __sock_recvmsg(struct 
29864         if (err)
29865                 return err;
29866  
29867 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
29868 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
29869 +       if ((len >= 0) && sock->sk)
29870 +               vx_sock_recv(sock->sk, len);
29871 +       vxdprintk(VXD_CBIT(net, 7),
29872 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
29873 +               sock, sock->sk,
29874 +               (sock->sk)?sock->sk->sk_nx_info:0,
29875 +               (sock->sk)?sock->sk->sk_vx_info:0,
29876 +               (sock->sk)?sock->sk->sk_xid:0,
29877 +               (sock->sk)?sock->sk->sk_nid:0,
29878 +               (unsigned int)size, len);
29879 +       return len;
29880  }
29881  
29882  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
29883 @@ -1090,6 +1120,13 @@ static int __sock_create(int family, int
29884         if (type < 0 || type >= SOCK_MAX)
29885                 return -EINVAL;
29886  
29887 +       if (!nx_check(0, VS_ADMIN)) {
29888 +               if (family == PF_INET && !current_nx_info_has_v4())
29889 +                       return -EAFNOSUPPORT;
29890 +               if (family == PF_INET6 && !current_nx_info_has_v6())
29891 +                       return -EAFNOSUPPORT;
29892 +       }
29893 +
29894         /* Compatibility.
29895  
29896            This uglymoron is moved from INET layer to here to avoid
29897 @@ -1207,6 +1244,7 @@ asmlinkage long sys_socket(int family, i
29898         if (retval < 0)
29899                 goto out;
29900  
29901 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
29902         retval = sock_map_fd(sock);
29903         if (retval < 0)
29904                 goto out_release;
29905 @@ -1239,10 +1277,12 @@ asmlinkage long sys_socketpair(int famil
29906         err = sock_create(family, type, protocol, &sock1);
29907         if (err < 0)
29908                 goto out;
29909 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
29910  
29911         err = sock_create(family, type, protocol, &sock2);
29912         if (err < 0)
29913                 goto out_release_1;
29914 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
29915  
29916         err = sock1->ops->socketpair(sock1, sock2);
29917         if (err < 0)
29918 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
29919 --- linux-2.6.22.10/net/sunrpc/auth.c   2007-05-02 19:25:48 +0200
29920 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/auth.c        2007-08-05 20:53:13 +0200
29921 @@ -13,6 +13,7 @@
29922  #include <linux/errno.h>
29923  #include <linux/sunrpc/clnt.h>
29924  #include <linux/spinlock.h>
29925 +#include <linux/vs_tag.h>
29926  
29927  #ifdef RPC_DEBUG
29928  # define RPCDBG_FACILITY       RPCDBG_AUTH
29929 @@ -263,6 +264,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
29930         struct auth_cred acred = {
29931                 .uid = current->fsuid,
29932                 .gid = current->fsgid,
29933 +               .tag = dx_current_tag(),
29934                 .group_info = current->group_info,
29935         };
29936         struct rpc_cred *ret;
29937 @@ -282,6 +284,7 @@ rpcauth_bindcred(struct rpc_task *task)
29938         struct auth_cred acred = {
29939                 .uid = current->fsuid,
29940                 .gid = current->fsgid,
29941 +               .tag = dx_current_tag(),
29942                 .group_info = current->group_info,
29943         };
29944         struct rpc_cred *ret;
29945 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
29946 --- linux-2.6.22.10/net/sunrpc/auth_unix.c      2007-05-02 19:25:48 +0200
29947 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/auth_unix.c   2007-08-05 20:53:13 +0200
29948 @@ -11,12 +11,14 @@
29949  #include <linux/module.h>
29950  #include <linux/sunrpc/clnt.h>
29951  #include <linux/sunrpc/auth.h>
29952 +#include <linux/vs_tag.h>
29953  
29954  #define NFS_NGROUPS    16
29955  
29956  struct unx_cred {
29957         struct rpc_cred         uc_base;
29958         gid_t                   uc_gid;
29959 +       tag_t                   uc_tag;
29960         gid_t                   uc_gids[NFS_NGROUPS];
29961  };
29962  #define uc_uid                 uc_base.cr_uid
29963 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
29964         if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
29965                 cred->uc_uid = 0;
29966                 cred->uc_gid = 0;
29967 +               cred->uc_tag = dx_current_tag();
29968                 cred->uc_gids[0] = NOGROUP;
29969         } else {
29970                 int groups = acred->group_info->ngroups;
29971 @@ -87,6 +90,7 @@ unx_create_cred(struct rpc_auth *auth, s
29972  
29973                 cred->uc_uid = acred->uid;
29974                 cred->uc_gid = acred->gid;
29975 +               cred->uc_tag = acred->tag;
29976                 for (i = 0; i < groups; i++)
29977                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
29978                 if (i < NFS_NGROUPS)
29979 @@ -118,7 +122,8 @@ unx_match(struct auth_cred *acred, struc
29980                 int groups;
29981  
29982                 if (cred->uc_uid != acred->uid
29983 -                || cred->uc_gid != acred->gid)
29984 +                || cred->uc_gid != acred->gid
29985 +                || cred->uc_tag != acred->tag)
29986                         return 0;
29987  
29988                 groups = acred->group_info->ngroups;
29989 @@ -144,7 +149,7 @@ unx_marshal(struct rpc_task *task, __be3
29990         struct rpc_clnt *clnt = task->tk_client;
29991         struct unx_cred *cred = (struct unx_cred *) task->tk_msg.rpc_cred;
29992         __be32          *base, *hold;
29993 -       int             i;
29994 +       int             i, tag;
29995  
29996         *p++ = htonl(RPC_AUTH_UNIX);
29997         base = p++;
29998 @@ -154,9 +159,12 @@ unx_marshal(struct rpc_task *task, __be3
29999          * Copy the UTS nodename captured when the client was created.
30000          */
30001         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
30002 +       tag = task->tk_client->cl_tag;
30003  
30004 -       *p++ = htonl((u32) cred->uc_uid);
30005 -       *p++ = htonl((u32) cred->uc_gid);
30006 +       *p++ = htonl((u32) TAGINO_UID(tag,
30007 +               cred->uc_uid, cred->uc_tag));
30008 +       *p++ = htonl((u32) TAGINO_GID(tag,
30009 +               cred->uc_gid, cred->uc_tag));
30010         hold = p++;
30011         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
30012                 *p++ = htonl((u32) cred->uc_gids[i]);
30013 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
30014 --- linux-2.6.22.10/net/sunrpc/clnt.c   2007-07-09 13:20:13 +0200
30015 +++ linux-2.6.22.10-vs2.3.0.29/net/sunrpc/clnt.c        2007-08-05 20:53:13 +0200
30016 @@ -30,6 +30,7 @@
30017  #include <linux/smp_lock.h>
30018  #include <linux/utsname.h>
30019  #include <linux/workqueue.h>
30020 +#include <linux/vs_cvirt.h>
30021  
30022  #include <linux/sunrpc/clnt.h>
30023  #include <linux/sunrpc/rpc_pipe_fs.h>
30024 @@ -249,7 +250,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
30025                 clnt->cl_oneshot = 1;
30026         if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
30027                 clnt->cl_discrtry = 1;
30028 -
30029 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
30030 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
30031 +               clnt->cl_tag = 1; */
30032         return clnt;
30033  }
30034  EXPORT_SYMBOL_GPL(rpc_create);
30035 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
30036 --- linux-2.6.22.10/net/unix/af_unix.c  2007-07-09 13:20:13 +0200
30037 +++ linux-2.6.22.10-vs2.3.0.29/net/unix/af_unix.c       2007-08-05 20:53:13 +0200
30038 @@ -115,6 +115,8 @@
30039  #include <linux/mount.h>
30040  #include <net/checksum.h>
30041  #include <linux/security.h>
30042 +#include <linux/vs_context.h>
30043 +#include <linux/vs_limit.h>
30044  
30045  int sysctl_unix_max_dgram_qlen __read_mostly = 10;
30046  
30047 @@ -252,6 +254,8 @@ static struct sock *__unix_find_socket_b
30048         sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
30049                 struct unix_sock *u = unix_sk(s);
30050  
30051 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
30052 +                       continue;
30053                 if (u->addr->len == len &&
30054                     !memcmp(u->addr->name, sunname, len))
30055                         goto found;
30056 @@ -807,7 +811,7 @@ static int unix_bind(struct socket *sock
30057                  */
30058                 mode = S_IFSOCK |
30059                        (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
30060 -               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
30061 +               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0, NULL);
30062                 if (err)
30063                         goto out_mknod_dput;
30064                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
30065 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
30066 --- linux-2.6.22.10/net/x25/af_x25.c    2007-07-09 13:20:13 +0200
30067 +++ linux-2.6.22.10-vs2.3.0.29/net/x25/af_x25.c 2007-08-05 20:53:13 +0200
30068 @@ -500,7 +500,10 @@ static int x25_create(struct socket *soc
30069  
30070         x25 = x25_sk(sk);
30071  
30072 -       sock_init_data(sock, sk);
30073 +       sk->sk_socket = sock;
30074 +       sk->sk_type = sock->type;
30075 +       sk->sk_sleep = &sock->wait;
30076 +       sock->sk = sk;
30077  
30078         x25_init_timers(sk);
30079  
30080 diff -NurpP --minimal linux-2.6.22.10/security/Kconfig linux-2.6.22.10-vs2.3.0.29/security/Kconfig
30081 --- linux-2.6.22.10/security/Kconfig    2006-11-30 21:19:47 +0100
30082 +++ linux-2.6.22.10-vs2.3.0.29/security/Kconfig 2007-08-05 20:53:13 +0200
30083 @@ -6,6 +6,7 @@ menu "Security options"
30084  
30085  config KEYS
30086         bool "Enable access key retention support"
30087 +       depends on !VSERVER_SECURITY
30088         help
30089           This option provides support for retaining authentication tokens and
30090           access keys in the kernel.
30091 diff -NurpP --minimal linux-2.6.22.10/security/commoncap.c linux-2.6.22.10-vs2.3.0.29/security/commoncap.c
30092 --- linux-2.6.22.10/security/commoncap.c        2007-07-09 13:20:14 +0200
30093 +++ linux-2.6.22.10-vs2.3.0.29/security/commoncap.c     2007-08-05 20:53:13 +0200
30094 @@ -22,10 +22,11 @@
30095  #include <linux/ptrace.h>
30096  #include <linux/xattr.h>
30097  #include <linux/hugetlb.h>
30098 +#include <linux/vs_context.h>
30099  
30100  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
30101  {
30102 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30103 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30104         return 0;
30105  }
30106  
30107 @@ -43,7 +44,7 @@ EXPORT_SYMBOL(cap_netlink_recv);
30108  int cap_capable (struct task_struct *tsk, int cap)
30109  {
30110         /* Derived from include/linux/sched.h:capable. */
30111 -       if (cap_raised(tsk->cap_effective, cap))
30112 +       if (vx_cap_raised(tsk->vx_info, tsk->cap_effective, cap))
30113                 return 0;
30114         return -EPERM;
30115  }
30116 @@ -141,7 +142,8 @@ void cap_bprm_apply_creds (struct linux_
30117         /* Derived from fs/exec.c:compute_creds. */
30118         kernel_cap_t new_permitted, working;
30119  
30120 -       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
30121 +       new_permitted = cap_intersect (bprm->cap_permitted,
30122 +                                       vx_current_cap_bset());
30123         working = cap_intersect (bprm->cap_inheritable,
30124                                  current->cap_inheritable);
30125         new_permitted = cap_combine (new_permitted, working);
30126 @@ -310,7 +312,8 @@ void cap_task_reparent_to_init (struct t
30127  
30128  int cap_syslog (int type)
30129  {
30130 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
30131 +       if ((type != 3 && type != 10) &&
30132 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
30133                 return -EPERM;
30134         return 0;
30135  }
30136 diff -NurpP --minimal linux-2.6.22.10/security/dummy.c linux-2.6.22.10-vs2.3.0.29/security/dummy.c
30137 --- linux-2.6.22.10/security/dummy.c    2007-05-02 19:25:51 +0200
30138 +++ linux-2.6.22.10-vs2.3.0.29/security/dummy.c 2007-08-05 20:53:13 +0200
30139 @@ -28,6 +28,7 @@
30140  #include <linux/hugetlb.h>
30141  #include <linux/ptrace.h>
30142  #include <linux/file.h>
30143 +#include <linux/vs_context.h>
30144  
30145  static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
30146  {
30147 @@ -678,7 +679,7 @@ static int dummy_sem_semop (struct sem_a
30148  
30149  static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
30150  {
30151 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
30152 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
30153         return 0;
30154  }
30155  
30156 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
30157 --- linux-2.6.22.10/security/selinux/hooks.c    2007-10-30 01:57:15 +0100
30158 +++ linux-2.6.22.10-vs2.3.0.29/security/selinux/hooks.c 2007-10-30 01:21:54 +0100
30159 @@ -60,7 +60,6 @@
30160  #include <linux/dccp.h>
30161  #include <linux/quota.h>
30162  #include <linux/un.h>          /* for Unix socket types */
30163 -#include <net/af_unix.h>       /* for Unix socket types */
30164  #include <linux/parser.h>
30165  #include <linux/nfs_mount.h>
30166  #include <net/ipv6.h>