]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs2.2.patch
- typo
[packages/kernel.git] / linux-2.6-vs2.2.patch
1 diff -NurpP --minimal linux-2.6.22.10/Documentation/vserver/debug.txt linux-2.6.22.10-vs2.2.0.5/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.2.0.5/Documentation/vserver/debug.txt   2007-06-15 02:37:02 +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.2.0.5/Makefile
160 --- linux-2.6.22.10/Makefile    2007-10-30 01:57:11 +0100
161 +++ linux-2.6.22.10-vs2.2.0.5/Makefile  2007-10-30 02:42:06 +0100
162 @@ -1,7 +1,7 @@
163  VERSION = 2
164  PATCHLEVEL = 6
165  SUBLEVEL = 22
166 -EXTRAVERSION = .12
167 +EXTRAVERSION = .12-vs2.2.0.5
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.2.0.5/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.2.0.5/arch/alpha/Kconfig        2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/alpha/kernel/asm-offsets.c   2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/alpha/kernel/entry.S 2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/alpha/kernel/osf_sys.c       2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/alpha/kernel/ptrace.c        2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/alpha/kernel/semaphore.c     2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/alpha/kernel/systbls.S       2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/alpha/kernel/traps.c 2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/alpha/mm/fault.c     2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/arm/Kconfig  2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/arm/kernel/calls.S   2007-07-07 03:52:53 +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.2.0.5/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.2.0.5/arch/arm/kernel/process.c 2007-07-07 03:52:53 +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.2.0.5/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.2.0.5/arch/arm/kernel/traps.c   2007-07-09 13:11:53 +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.2.0.5/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.2.0.5/arch/arm/mm/fault.c       2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/arm26/Kconfig        2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/arm26/kernel/calls.S 2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/arm26/kernel/process.c       2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/arm26/kernel/traps.c 2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/cris/Kconfig 2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/cris/arch-v10/kernel/process.c       2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/cris/arch-v32/kernel/process.c       2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/frv/kernel/kernel_thread.S   2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/h8300/Kconfig        2007-06-15 02:37:02 +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.2.0.5/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.2.0.5/arch/h8300/kernel/process.c       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/i386/Kconfig 2007-07-09 13:11:53 +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.2.0.5/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.2.0.5/arch/i386/kernel/process.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/i386/kernel/syscall_table.S  2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/i386/kernel/sysenter.c       2007-09-05 03:05:52 +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.2.0.5/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.2.0.5/arch/i386/kernel/traps.c  2007-06-15 02:38:37 +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.2.0.5/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.2.0.5/arch/i386/mm/fault.c      2007-09-05 03:05:52 +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.2.0.5/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.2.0.5/arch/ia64/Kconfig 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/ia32/binfmt_elf32.c     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/ia32/ia32_entry.S       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/ia32/sys_ia32.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/kernel/asm-offsets.c    2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/kernel/entry.S  2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/kernel/perfmon.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/kernel/process.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/kernel/ptrace.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/kernel/traps.c  2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ia64/mm/fault.c      2007-06-15 02:39:01 +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.2.0.5/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.2.0.5/arch/m32r/kernel/process.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/m32r/kernel/traps.c  2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/m68k/Kconfig 2007-07-07 03:52:53 +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.2.0.5/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.2.0.5/arch/m68k/kernel/process.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/m68k/kernel/ptrace.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/m68k/kernel/traps.c  2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/m68knommu/Kconfig    2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/m68knommu/kernel/process.c   2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/m68knommu/kernel/traps.c     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/mips/Kconfig 2007-07-07 03:52:53 +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.2.0.5/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.2.0.5/arch/mips/kernel/linux32.c        2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/mips/kernel/process.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/mips/kernel/ptrace.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/mips/kernel/scall32-o32.S    2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/mips/kernel/scall64-64.S     2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/mips/kernel/scall64-n32.S    2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/mips/kernel/scall64-o32.S    2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/mips/kernel/traps.c  2007-07-09 13:11:53 +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.2.0.5/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.2.0.5/arch/mips/mm/fault.c      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/parisc/Kconfig       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/parisc/kernel/entry.S        2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/parisc/kernel/process.c      2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/parisc/kernel/sys_parisc32.c 2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/parisc/kernel/syscall_table.S        2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/parisc/kernel/traps.c        2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/parisc/mm/fault.c    2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/powerpc/Kconfig      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/powerpc/kernel/asm-offsets.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/powerpc/kernel/irq.c 2007-07-09 13:11:53 +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.2.0.5/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.2.0.5/arch/powerpc/kernel/misc_32.S     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/powerpc/kernel/misc_64.S     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/powerpc/kernel/process.c     2007-10-01 15:25:34 +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.2.0.5/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.2.0.5/arch/powerpc/kernel/sys_ppc32.c   2007-07-07 03:52:53 +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.2.0.5/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.2.0.5/arch/powerpc/kernel/traps.c       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/powerpc/kernel/vdso.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/powerpc/mm/fault.c   2007-07-07 03:52:53 +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.2.0.5/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.2.0.5/arch/ppc/Kconfig  2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ppc/kernel/asm-offsets.c     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ppc/kernel/misc.S    2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ppc/kernel/traps.c   2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/ppc/mm/fault.c       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/s390/Kconfig 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/s390/kernel/compat_linux.c   2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/s390/kernel/process.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/s390/kernel/ptrace.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/s390/kernel/syscalls.S       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/s390/mm/fault.c      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sh/Kconfig   2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sh/kernel/irq.c      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sh/kernel/process.c  2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sh/kernel/vsyscall/vsyscall.c        2007-06-15 02:39:24 +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.2.0.5/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.2.0.5/arch/sh/mm/fault.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sh64/kernel/process.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sh64/mm/fault.c      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc/Kconfig        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc/kernel/process.c       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc/kernel/ptrace.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc/kernel/systbls.S       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc/kernel/traps.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc/mm/fault.c     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc64/Kconfig      2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/sparc64/kernel/binfmt_aout32.c       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc64/kernel/process.c     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc64/kernel/ptrace.c      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc64/kernel/sys_sparc32.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc64/kernel/systbls.S     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/sparc64/kernel/traps.c       2007-09-05 03:05:52 +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.2.0.5/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.2.0.5/arch/sparc64/mm/fault.c   2007-09-05 03:05:52 +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.2.0.5/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.2.0.5/arch/sparc64/solaris/fs.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/um/Kconfig   2007-06-17 05:54:16 +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.2.0.5/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.2.0.5/arch/um/kernel/trap.c     2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/v850/Kconfig 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/v850/kernel/process.c        2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/v850/kernel/ptrace.c 2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/x86_64/Kconfig       2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/x86_64/ia32/ia32_aout.c      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/x86_64/ia32/ia32_binfmt.c    2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/x86_64/ia32/ia32entry.S      2007-10-01 15:25:34 +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.2.0.5/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.2.0.5/arch/x86_64/ia32/sys_ia32.c       2007-07-07 03:52:53 +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.2.0.5/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.2.0.5/arch/x86_64/ia32/syscall32.c      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/x86_64/kernel/process.c      2007-06-15 02:37:03 +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.2.0.5/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.2.0.5/arch/x86_64/kernel/traps.c        2007-06-17 05:54:16 +0200
2010 @@ -413,8 +413,9 @@ void show_registers(struct pt_regs *regs
2011         rsp = regs->rsp;
2012         printk("CPU %d ", cpu);
2013         __show_regs(regs);
2014 -       printk("Process %s (pid: %d, threadinfo %p, task %p)\n",
2015 -               cur->comm, cur->pid, task_thread_info(cur), cur);
2016 +       printk("Process %s (pid: %d[#%u], threadinfo %p, task %p)\n",
2017 +               cur->comm, cur->pid, cur->xid,
2018 +               task_thread_info(cur), cur);
2019  
2020         /*
2021          * When in-kernel, we also print out the stack and code at the
2022 @@ -580,8 +581,8 @@ static void __kprobes do_trap(int trapnr
2023  
2024                 if (exception_trace && unhandled_signal(tsk, signr))
2025                         printk(KERN_INFO
2026 -                              "%s[%d] trap %s rip:%lx rsp:%lx error:%lx\n",
2027 -                              tsk->comm, tsk->pid, str,
2028 +                              "%s[%d:#%u] trap %s rip:%lx rsp:%lx error:%lx\n",
2029 +                              tsk->comm, tsk->pid, tsk->xid, str,
2030                                regs->rip, regs->rsp, error_code); 
2031  
2032                 if (info)
2033 @@ -684,8 +685,8 @@ asmlinkage void __kprobes do_general_pro
2034  
2035                 if (exception_trace && unhandled_signal(tsk, SIGSEGV))
2036                         printk(KERN_INFO
2037 -                      "%s[%d] general protection rip:%lx rsp:%lx error:%lx\n",
2038 -                              tsk->comm, tsk->pid,
2039 +                      "%s[%d:#%u] general protection rip:%lx rsp:%lx error:%lx\n",
2040 +                              tsk->comm, tsk->pid, tsk->xid,
2041                                regs->rip, regs->rsp, error_code); 
2042  
2043                 force_sig(SIGSEGV, tsk);
2044 diff -NurpP --minimal linux-2.6.22.10/arch/x86_64/mm/fault.c linux-2.6.22.10-vs2.2.0.5/arch/x86_64/mm/fault.c
2045 --- linux-2.6.22.10/arch/x86_64/mm/fault.c      2007-07-09 13:18:08 +0200
2046 +++ linux-2.6.22.10-vs2.2.0.5/arch/x86_64/mm/fault.c    2007-06-17 05:54:16 +0200
2047 @@ -497,10 +497,10 @@ bad_area_nosemaphore:
2048  
2049                 if (exception_trace && unhandled_signal(tsk, SIGSEGV)) {
2050                         printk(
2051 -                      "%s%s[%d]: segfault at %016lx rip %016lx rsp %016lx error %lx\n",
2052 +                      "%s%s[%d:#%u]: segfault at %016lx rip %016lx rsp %016lx error %lx\n",
2053                                         tsk->pid > 1 ? KERN_INFO : KERN_EMERG,
2054 -                                       tsk->comm, tsk->pid, address, regs->rip,
2055 -                                       regs->rsp, error_code);
2056 +                                       tsk->comm, tsk->pid, tsk->xid, address,
2057 +                                       regs->rip, regs->rsp, error_code);
2058                 }
2059         
2060                 tsk->thread.cr2 = address;
2061 @@ -567,7 +567,8 @@ out_of_memory:
2062                 yield();
2063                 goto again;
2064         }
2065 -       printk("VM: killing process %s\n", tsk->comm);
2066 +       printk("VM: killing process %s(%d:#%u)\n",
2067 +               tsk->comm, tsk->pid, tsk->xid);
2068         if (error_code & 4)
2069                 do_exit(SIGKILL);
2070         goto no_context;
2071 diff -NurpP --minimal linux-2.6.22.10/drivers/block/Kconfig linux-2.6.22.10-vs2.2.0.5/drivers/block/Kconfig
2072 --- linux-2.6.22.10/drivers/block/Kconfig       2007-07-09 13:18:16 +0200
2073 +++ linux-2.6.22.10-vs2.2.0.5/drivers/block/Kconfig     2007-06-15 02:37:03 +0200
2074 @@ -311,6 +311,13 @@ config BLK_DEV_CRYPTOLOOP
2075           instead, which can be configured to be on-disk compatible with the
2076           cryptoloop device.
2077  
2078 +config BLK_DEV_VROOT
2079 +       tristate "Virtual Root device support"
2080 +       depends on QUOTACTL
2081 +       ---help---
2082 +         Saying Y here will allow you to use quota/fs ioctls on a shared
2083 +         partition within a virtual server without compromising security.
2084 +
2085  config BLK_DEV_NBD
2086         tristate "Network block device support"
2087         depends on NET
2088 diff -NurpP --minimal linux-2.6.22.10/drivers/block/Makefile linux-2.6.22.10-vs2.2.0.5/drivers/block/Makefile
2089 --- linux-2.6.22.10/drivers/block/Makefile      2007-02-06 03:00:26 +0100
2090 +++ linux-2.6.22.10-vs2.2.0.5/drivers/block/Makefile    2007-06-15 02:37:03 +0200
2091 @@ -28,4 +28,5 @@ obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryp
2092  obj-$(CONFIG_VIODASD)          += viodasd.o
2093  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
2094  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
2095 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
2096  
2097 diff -NurpP --minimal linux-2.6.22.10/drivers/block/loop.c linux-2.6.22.10-vs2.2.0.5/drivers/block/loop.c
2098 --- linux-2.6.22.10/drivers/block/loop.c        2007-07-09 13:18:16 +0200
2099 +++ linux-2.6.22.10-vs2.2.0.5/drivers/block/loop.c      2007-08-16 04:07:14 +0200
2100 @@ -74,6 +74,7 @@
2101  #include <linux/highmem.h>
2102  #include <linux/gfp.h>
2103  #include <linux/kthread.h>
2104 +#include <linux/vs_context.h>
2105  
2106  #include <asm/uaccess.h>
2107  
2108 @@ -790,6 +791,7 @@ static int loop_set_fd(struct loop_devic
2109         lo->lo_blocksize = lo_blocksize;
2110         lo->lo_device = bdev;
2111         lo->lo_flags = lo_flags;
2112 +       lo->lo_xid = vx_current_xid();
2113         lo->lo_backing_file = file;
2114         lo->transfer = transfer_none;
2115         lo->ioctl = NULL;
2116 @@ -909,6 +911,7 @@ static int loop_clr_fd(struct loop_devic
2117         lo->lo_encrypt_key_size = 0;
2118         lo->lo_flags = 0;
2119         lo->lo_thread = NULL;
2120 +       lo->lo_xid = 0;
2121         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
2122         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
2123         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
2124 @@ -930,7 +933,7 @@ loop_set_status(struct loop_device *lo, 
2125         struct loop_func_table *xfer;
2126  
2127         if (lo->lo_encrypt_key_size && lo->lo_key_owner != current->uid &&
2128 -           !capable(CAP_SYS_ADMIN))
2129 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
2130                 return -EPERM;
2131         if (lo->lo_state != Lo_bound)
2132                 return -ENXIO;
2133 @@ -1010,7 +1013,8 @@ loop_get_status(struct loop_device *lo, 
2134         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
2135         info->lo_encrypt_type =
2136                 lo->lo_encryption ? lo->lo_encryption->number : 0;
2137 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
2138 +       if (lo->lo_encrypt_key_size &&
2139 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
2140                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
2141                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
2142                        lo->lo_encrypt_key_size);
2143 @@ -1321,6 +1325,9 @@ static int lo_open(struct inode *inode, 
2144  {
2145         struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
2146  
2147 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID))
2148 +               return -EACCES;
2149 +
2150         mutex_lock(&lo->lo_ctl_mutex);
2151         lo->lo_refcnt++;
2152         mutex_unlock(&lo->lo_ctl_mutex);
2153 diff -NurpP --minimal linux-2.6.22.10/drivers/block/vroot.c linux-2.6.22.10-vs2.2.0.5/drivers/block/vroot.c
2154 --- linux-2.6.22.10/drivers/block/vroot.c       1970-01-01 01:00:00 +0100
2155 +++ linux-2.6.22.10-vs2.2.0.5/drivers/block/vroot.c     2007-06-15 02:37:03 +0200
2156 @@ -0,0 +1,281 @@
2157 +/*
2158 + *  linux/drivers/block/vroot.c
2159 + *
2160 + *  written by Herbert Pötzl, 9/11/2002
2161 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
2162 + *
2163 + *  based on the loop.c code by Theodore Ts'o.
2164 + *
2165 + * Copyright (C) 2002-2007 by Herbert Pötzl.
2166 + * Redistribution of this file is permitted under the
2167 + * GNU General Public License.
2168 + *
2169 + */
2170 +
2171 +#include <linux/module.h>
2172 +#include <linux/moduleparam.h>
2173 +#include <linux/file.h>
2174 +#include <linux/major.h>
2175 +#include <linux/blkdev.h>
2176 +
2177 +#include <linux/vroot.h>
2178 +#include <linux/vs_context.h>
2179 +
2180 +
2181 +static int max_vroot = 8;
2182 +
2183 +static struct vroot_device *vroot_dev;
2184 +static struct gendisk **disks;
2185 +
2186 +
2187 +static int vroot_set_dev(
2188 +       struct vroot_device *vr,
2189 +       struct file *vr_file,
2190 +       struct block_device *bdev,
2191 +       unsigned int arg)
2192 +{
2193 +       struct block_device *real_bdev;
2194 +       struct file *file;
2195 +       struct inode *inode;
2196 +       int error;
2197 +
2198 +       error = -EBUSY;
2199 +       if (vr->vr_state != Vr_unbound)
2200 +               goto out;
2201 +
2202 +       error = -EBADF;
2203 +       file = fget(arg);
2204 +       if (!file)
2205 +               goto out;
2206 +
2207 +       error = -EINVAL;
2208 +       inode = file->f_dentry->d_inode;
2209 +
2210 +
2211 +       if (S_ISBLK(inode->i_mode)) {
2212 +               real_bdev = inode->i_bdev;
2213 +               vr->vr_device = real_bdev;
2214 +               __iget(real_bdev->bd_inode);
2215 +       } else
2216 +               goto out_fput;
2217 +
2218 +       vxdprintk(VXD_CBIT(misc, 0),
2219 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
2220 +               vr->vr_number, VXD_DEV(real_bdev));
2221 +
2222 +       vr->vr_state = Vr_bound;
2223 +       error = 0;
2224 +
2225 + out_fput:
2226 +       fput(file);
2227 + out:
2228 +       return error;
2229 +}
2230 +
2231 +static int vroot_clr_dev(
2232 +       struct vroot_device *vr,
2233 +       struct file *vr_file,
2234 +       struct block_device *bdev)
2235 +{
2236 +       struct block_device *real_bdev;
2237 +
2238 +       if (vr->vr_state != Vr_bound)
2239 +               return -ENXIO;
2240 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
2241 +               return -EBUSY;
2242 +
2243 +       real_bdev = vr->vr_device;
2244 +
2245 +       vxdprintk(VXD_CBIT(misc, 0),
2246 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
2247 +               vr->vr_number, VXD_DEV(real_bdev));
2248 +
2249 +       bdput(real_bdev);
2250 +       vr->vr_state = Vr_unbound;
2251 +       vr->vr_device = NULL;
2252 +       return 0;
2253 +}
2254 +
2255 +
2256 +static int vr_ioctl(struct inode *inode, struct file *file,
2257 +       unsigned int cmd, unsigned long arg)
2258 +{
2259 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2260 +       int err;
2261 +
2262 +       down(&vr->vr_ctl_mutex);
2263 +       switch (cmd) {
2264 +       case VROOT_SET_DEV:
2265 +               err = vroot_set_dev(vr, file, inode->i_bdev, arg);
2266 +               break;
2267 +       case VROOT_CLR_DEV:
2268 +               err = vroot_clr_dev(vr, file, inode->i_bdev);
2269 +               break;
2270 +       default:
2271 +               err = -EINVAL;
2272 +               break;
2273 +       }
2274 +       up(&vr->vr_ctl_mutex);
2275 +       return err;
2276 +}
2277 +
2278 +static int vr_open(struct inode *inode, struct file *file)
2279 +{
2280 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2281 +
2282 +       down(&vr->vr_ctl_mutex);
2283 +       vr->vr_refcnt++;
2284 +       up(&vr->vr_ctl_mutex);
2285 +       return 0;
2286 +}
2287 +
2288 +static int vr_release(struct inode *inode, struct file *file)
2289 +{
2290 +       struct vroot_device *vr = inode->i_bdev->bd_disk->private_data;
2291 +
2292 +       down(&vr->vr_ctl_mutex);
2293 +       --vr->vr_refcnt;
2294 +       up(&vr->vr_ctl_mutex);
2295 +       return 0;
2296 +}
2297 +
2298 +static struct block_device_operations vr_fops = {
2299 +       .owner =        THIS_MODULE,
2300 +       .open =         vr_open,
2301 +       .release =      vr_release,
2302 +       .ioctl =        vr_ioctl,
2303 +};
2304 +
2305 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
2306 +{
2307 +       struct inode *inode = bdev->bd_inode;
2308 +       struct vroot_device *vr;
2309 +       struct block_device *real_bdev;
2310 +       int minor = iminor(inode);
2311 +
2312 +       vr = &vroot_dev[minor];
2313 +       real_bdev = vr->vr_device;
2314 +
2315 +       vxdprintk(VXD_CBIT(misc, 0),
2316 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
2317 +               vr->vr_number, VXD_DEV(real_bdev));
2318 +
2319 +       if (vr->vr_state != Vr_bound)
2320 +               return ERR_PTR(-ENXIO);
2321 +
2322 +       __iget(real_bdev->bd_inode);
2323 +       return real_bdev;
2324 +}
2325 +
2326 +/*
2327 + * And now the modules code and kernel interface.
2328 + */
2329 +
2330 +module_param(max_vroot, int, 0);
2331 +
2332 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
2333 +MODULE_LICENSE("GPL");
2334 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
2335 +
2336 +MODULE_AUTHOR ("Herbert Pötzl");
2337 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
2338 +
2339 +
2340 +int __init vroot_init(void)
2341 +{
2342 +       int err, i;
2343 +
2344 +       if (max_vroot < 1 || max_vroot > 256) {
2345 +               max_vroot = MAX_VROOT_DEFAULT;
2346 +               printk(KERN_WARNING "vroot: invalid max_vroot "
2347 +                       "(must be between 1 and 256), "
2348 +                       "using default (%d)\n", max_vroot);
2349 +       }
2350 +
2351 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
2352 +               return -EIO;
2353 +
2354 +       err = -ENOMEM;
2355 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
2356 +       if (!vroot_dev)
2357 +               goto out_mem1;
2358 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
2359 +
2360 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
2361 +       if (!disks)
2362 +               goto out_mem2;
2363 +
2364 +       for (i = 0; i < max_vroot; i++) {
2365 +               disks[i] = alloc_disk(1);
2366 +               if (!disks[i])
2367 +                       goto out_mem3;
2368 +       }
2369 +
2370 +       for (i = 0; i < max_vroot; i++) {
2371 +               struct vroot_device *vr = &vroot_dev[i];
2372 +               struct gendisk *disk = disks[i];
2373 +
2374 +               memset(vr, 0, sizeof(*vr));
2375 +               init_MUTEX(&vr->vr_ctl_mutex);
2376 +               vr->vr_number = i;
2377 +               disk->major = VROOT_MAJOR;
2378 +               disk->first_minor = i;
2379 +               disk->fops = &vr_fops;
2380 +               sprintf(disk->disk_name, "vroot%d", i);
2381 +               disk->private_data = vr;
2382 +       }
2383 +
2384 +       err = register_vroot_grb(&__vroot_get_real_bdev);
2385 +       if (err)
2386 +               goto out_mem3;
2387 +
2388 +       for (i = 0; i < max_vroot; i++)
2389 +               add_disk(disks[i]);
2390 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
2391 +       return 0;
2392 +
2393 +out_mem3:
2394 +       while (i--)
2395 +               put_disk(disks[i]);
2396 +       kfree(disks);
2397 +out_mem2:
2398 +       kfree(vroot_dev);
2399 +out_mem1:
2400 +       unregister_blkdev(VROOT_MAJOR, "vroot");
2401 +       printk(KERN_ERR "vroot: ran out of memory\n");
2402 +       return err;
2403 +}
2404 +
2405 +void vroot_exit(void)
2406 +{
2407 +       int i;
2408 +
2409 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
2410 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
2411 +
2412 +       for (i = 0; i < max_vroot; i++) {
2413 +               del_gendisk(disks[i]);
2414 +               put_disk(disks[i]);
2415 +       }
2416 +       if (unregister_blkdev(VROOT_MAJOR, "vroot"))
2417 +               printk(KERN_WARNING "vroot: cannot unregister blkdev\n");
2418 +
2419 +       kfree(disks);
2420 +       kfree(vroot_dev);
2421 +}
2422 +
2423 +module_init(vroot_init);
2424 +module_exit(vroot_exit);
2425 +
2426 +#ifndef MODULE
2427 +
2428 +static int __init max_vroot_setup(char *str)
2429 +{
2430 +       max_vroot = simple_strtol(str, NULL, 0);
2431 +       return 1;
2432 +}
2433 +
2434 +__setup("max_vroot=", max_vroot_setup);
2435 +
2436 +#endif
2437 +
2438 diff -NurpP --minimal linux-2.6.22.10/drivers/char/sysrq.c linux-2.6.22.10-vs2.2.0.5/drivers/char/sysrq.c
2439 --- linux-2.6.22.10/drivers/char/sysrq.c        2007-07-09 13:18:20 +0200
2440 +++ linux-2.6.22.10-vs2.2.0.5/drivers/char/sysrq.c      2007-06-15 02:37:03 +0200
2441 @@ -36,6 +36,7 @@
2442  #include <linux/kexec.h>
2443  #include <linux/irq.h>
2444  #include <linux/hrtimer.h>
2445 +#include <linux/vserver/debug.h>
2446  
2447  #include <asm/ptrace.h>
2448  #include <asm/irq_regs.h>
2449 @@ -309,6 +310,21 @@ static struct sysrq_key_op sysrq_unrt_op
2450         .enable_mask    = SYSRQ_ENABLE_RTNICE,
2451  };
2452  
2453 +
2454 +#ifdef CONFIG_VSERVER_DEBUG
2455 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
2456 +{
2457 +       dump_vx_info_inactive((key == 'x')?0:1);
2458 +}
2459 +
2460 +static struct sysrq_key_op sysrq_showvxinfo_op = {
2461 +       .handler        = sysrq_handle_vxinfo,
2462 +       .help_msg       = "conteXt",
2463 +       .action_msg     = "Show Context Info",
2464 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
2465 +};
2466 +#endif
2467 +
2468  /* Key Operations table and lock */
2469  static DEFINE_SPINLOCK(sysrq_key_table_lock);
2470  
2471 @@ -357,7 +373,11 @@ static struct sysrq_key_op *sysrq_key_ta
2472         /* x: May be registered on ppc/powerpc for xmon */
2473         NULL,                           /* x */
2474         NULL,                           /* y */
2475 -       NULL                            /* z */
2476 +#ifdef CONFIG_VSERVER_DEBUG
2477 +       &sysrq_showvxinfo_op,           /* z */
2478 +#else
2479 +       NULL,                           /* z */
2480 +#endif
2481  };
2482  
2483  /* key2index calculation, -1 on invalid index */
2484 @@ -369,6 +389,8 @@ static int sysrq_key_table_key2index(int
2485                 retval = key - '0';
2486         else if ((key >= 'a') && (key <= 'z'))
2487                 retval = key + 10 - 'a';
2488 +       else if ((key >= 'A') && (key <= 'Z'))
2489 +               retval = key + 10 - 'A';
2490         else
2491                 retval = -1;
2492         return retval;
2493 diff -NurpP --minimal linux-2.6.22.10/drivers/char/tty_io.c linux-2.6.22.10-vs2.2.0.5/drivers/char/tty_io.c
2494 --- linux-2.6.22.10/drivers/char/tty_io.c       2007-07-09 13:18:20 +0200
2495 +++ linux-2.6.22.10-vs2.2.0.5/drivers/char/tty_io.c     2007-07-17 03:02:15 +0200
2496 @@ -103,6 +103,7 @@
2497  #include <linux/selection.h>
2498  
2499  #include <linux/kmod.h>
2500 +#include <linux/vs_pid.h>
2501  
2502  #undef TTY_DEBUG_HANGUP
2503  
2504 @@ -3049,13 +3050,15 @@ unlock:
2505  
2506  static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
2507  {
2508 +       pid_t pgrp;
2509         /*
2510          * (tty == real_tty) is a cheap way of
2511          * testing if the tty is NOT a master pty.
2512          */
2513         if (tty == real_tty && current->signal->tty != real_tty)
2514                 return -ENOTTY;
2515 -       return put_user(pid_nr(real_tty->pgrp), p);
2516 +       pgrp = vx_map_pid(pid_nr(real_tty->pgrp));
2517 +       return put_user(pgrp, p);
2518  }
2519  
2520  /**
2521 @@ -3086,6 +3089,7 @@ static int tiocspgrp(struct tty_struct *
2522                 return -ENOTTY;
2523         if (get_user(pgrp_nr, p))
2524                 return -EFAULT;
2525 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2526         if (pgrp_nr < 0)
2527                 return -EINVAL;
2528         rcu_read_lock();
2529 diff -NurpP --minimal linux-2.6.22.10/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.22.10-vs2.2.0.5/drivers/infiniband/hw/ipath/ipath_user_pages.c
2530 --- linux-2.6.22.10/drivers/infiniband/hw/ipath/ipath_user_pages.c      2007-02-06 03:00:37 +0100
2531 +++ linux-2.6.22.10-vs2.2.0.5/drivers/infiniband/hw/ipath/ipath_user_pages.c    2007-06-15 02:37:03 +0200
2532 @@ -33,6 +33,7 @@
2533  
2534  #include <linux/mm.h>
2535  #include <linux/device.h>
2536 +#include <linux/vs_memory.h>
2537  
2538  #include "ipath_kernel.h"
2539  
2540 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
2541         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
2542                 PAGE_SHIFT;
2543  
2544 -       if (num_pages > lock_limit) {
2545 +       if (num_pages > lock_limit ||
2546 +               !vx_vmlocked_avail(current->mm, num_pages)) {
2547                 ret = -ENOMEM;
2548                 goto bail;
2549         }
2550 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
2551                         goto bail_release;
2552         }
2553  
2554 -       current->mm->locked_vm += num_pages;
2555 +       vx_vmlocked_add(current->mm, num_pages);
2556  
2557         ret = 0;
2558         goto bail;
2559 @@ -203,7 +205,7 @@ void ipath_release_user_pages(struct pag
2560  
2561         __ipath_release_user_pages(p, num_pages, 1);
2562  
2563 -       current->mm->locked_vm -= num_pages;
2564 +       vx_vmlocked_sub(current->mm, num_pages);
2565  
2566         up_write(&current->mm->mmap_sem);
2567  }
2568 @@ -220,7 +222,7 @@ static void user_pages_account(struct wo
2569                 container_of(_work, struct ipath_user_pages_work, work);
2570  
2571         down_write(&work->mm->mmap_sem);
2572 -       work->mm->locked_vm -= work->num_pages;
2573 +       vx_vmlocked_sub(work->mm, work->num_pages);
2574         up_write(&work->mm->mmap_sem);
2575         mmput(work->mm);
2576         kfree(work);
2577 diff -NurpP --minimal linux-2.6.22.10/drivers/md/dm-ioctl.c linux-2.6.22.10-vs2.2.0.5/drivers/md/dm-ioctl.c
2578 --- linux-2.6.22.10/drivers/md/dm-ioctl.c       2007-05-02 19:24:50 +0200
2579 +++ linux-2.6.22.10-vs2.2.0.5/drivers/md/dm-ioctl.c     2007-06-15 02:37:03 +0200
2580 @@ -15,6 +15,7 @@
2581  #include <linux/slab.h>
2582  #include <linux/dm-ioctl.h>
2583  #include <linux/hdreg.h>
2584 +#include <linux/vs_context.h>
2585  
2586  #include <asm/uaccess.h>
2587  
2588 @@ -100,7 +101,8 @@ static struct hash_cell *__get_name_cell
2589         unsigned int h = hash_str(str);
2590  
2591         list_for_each_entry (hc, _name_buckets + h, name_list)
2592 -               if (!strcmp(hc->name, str)) {
2593 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2594 +                       !strcmp(hc->name, str)) {
2595                         dm_get(hc->md);
2596                         return hc;
2597                 }
2598 @@ -114,7 +116,8 @@ static struct hash_cell *__get_uuid_cell
2599         unsigned int h = hash_str(str);
2600  
2601         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
2602 -               if (!strcmp(hc->uuid, str)) {
2603 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
2604 +                       !strcmp(hc->uuid, str)) {
2605                         dm_get(hc->md);
2606                         return hc;
2607                 }
2608 @@ -349,6 +352,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
2609  
2610  static int remove_all(struct dm_ioctl *param, size_t param_size)
2611  {
2612 +       if (!vx_check(0, VS_ADMIN))
2613 +               return -EPERM;
2614 +
2615         dm_hash_remove_all(1);
2616         param->data_size = 0;
2617         return 0;
2618 @@ -396,6 +402,8 @@ static int list_devices(struct dm_ioctl 
2619          */
2620         for (i = 0; i < NUM_BUCKETS; i++) {
2621                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2622 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2623 +                               continue;
2624                         needed += sizeof(struct dm_name_list);
2625                         needed += strlen(hc->name) + 1;
2626                         needed += ALIGN_MASK;
2627 @@ -419,6 +427,8 @@ static int list_devices(struct dm_ioctl 
2628          */
2629         for (i = 0; i < NUM_BUCKETS; i++) {
2630                 list_for_each_entry (hc, _name_buckets + i, name_list) {
2631 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
2632 +                               continue;
2633                         if (old_nl)
2634                                 old_nl->next = (uint32_t) ((void *) nl -
2635                                                            (void *) old_nl);
2636 @@ -609,10 +619,11 @@ static struct hash_cell *__find_device_h
2637         if (!md)
2638                 goto out;
2639  
2640 -       mdptr = dm_get_mdptr(md);
2641 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
2642 +               mdptr = dm_get_mdptr(md);
2643 +
2644         if (!mdptr)
2645                 dm_put(md);
2646 -
2647  out:
2648         return mdptr;
2649  }
2650 @@ -1409,8 +1420,8 @@ static int ctl_ioctl(struct inode *inode
2651         ioctl_fn fn = NULL;
2652         size_t param_size;
2653  
2654 -       /* only root can play with this */
2655 -       if (!capable(CAP_SYS_ADMIN))
2656 +       /* only root and certain contexts can play with this */
2657 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
2658                 return -EACCES;
2659  
2660         if (_IOC_TYPE(command) != DM_IOCTL)
2661 diff -NurpP --minimal linux-2.6.22.10/drivers/md/dm.c linux-2.6.22.10-vs2.2.0.5/drivers/md/dm.c
2662 --- linux-2.6.22.10/drivers/md/dm.c     2007-10-30 01:57:13 +0100
2663 +++ linux-2.6.22.10-vs2.2.0.5/drivers/md/dm.c   2007-08-12 12:21:50 +0200
2664 @@ -21,6 +21,7 @@
2665  #include <linux/hdreg.h>
2666  #include <linux/blktrace_api.h>
2667  #include <linux/smp_lock.h>
2668 +#include <linux/vs_base.h>
2669  
2670  #define DM_MSG_PREFIX "core"
2671  
2672 @@ -77,6 +78,7 @@ struct mapped_device {
2673         rwlock_t map_lock;
2674         atomic_t holders;
2675         atomic_t open_count;
2676 +       xid_t xid;
2677  
2678         unsigned long flags;
2679  
2680 @@ -223,6 +225,7 @@ static void __exit dm_exit(void)
2681  static int dm_blk_open(struct inode *inode, struct file *file)
2682  {
2683         struct mapped_device *md;
2684 +       int ret = -ENXIO;
2685  
2686         spin_lock(&_minor_lock);
2687  
2688 @@ -231,18 +234,19 @@ static int dm_blk_open(struct inode *ino
2689                 goto out;
2690  
2691         if (test_bit(DMF_FREEING, &md->flags) ||
2692 -           test_bit(DMF_DELETING, &md->flags)) {
2693 -               md = NULL;
2694 +           test_bit(DMF_DELETING, &md->flags))
2695 +               goto out;
2696 +
2697 +       ret = -EACCES;
2698 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
2699                 goto out;
2700 -       }
2701  
2702         dm_get(md);
2703         atomic_inc(&md->open_count);
2704 -
2705 +       ret = 0;
2706  out:
2707         spin_unlock(&_minor_lock);
2708 -
2709 -       return md ? 0 : -ENXIO;
2710 +       return ret;
2711  }
2712  
2713  static int dm_blk_close(struct inode *inode, struct file *file)
2714 @@ -438,6 +442,14 @@ int dm_set_geometry(struct mapped_device
2715         return 0;
2716  }
2717  
2718 +/*
2719 + * Get the xid associated with a dm device
2720 + */
2721 +xid_t dm_get_xid(struct mapped_device *md)
2722 +{
2723 +       return md->xid;
2724 +}
2725 +
2726  /*-----------------------------------------------------------------
2727   * CRUD START:
2728   *   A more elegant soln is in the works that uses the queue
2729 @@ -1000,6 +1012,7 @@ static struct mapped_device *alloc_dev(i
2730         atomic_set(&md->holders, 1);
2731         atomic_set(&md->open_count, 0);
2732         atomic_set(&md->event_nr, 0);
2733 +       md->xid = vx_current_xid();
2734  
2735         md->queue = blk_alloc_queue(GFP_KERNEL);
2736         if (!md->queue)
2737 diff -NurpP --minimal linux-2.6.22.10/drivers/md/dm.h linux-2.6.22.10-vs2.2.0.5/drivers/md/dm.h
2738 --- linux-2.6.22.10/drivers/md/dm.h     2007-02-06 03:00:41 +0100
2739 +++ linux-2.6.22.10-vs2.2.0.5/drivers/md/dm.h   2007-06-15 02:37:03 +0200
2740 @@ -91,6 +91,8 @@ void dm_put_target_type(struct target_ty
2741  int dm_target_iterate(void (*iter_func)(struct target_type *tt,
2742                                         void *param), void *param);
2743  
2744 +xid_t dm_get_xid(struct mapped_device *md);
2745 +
2746  /*-----------------------------------------------------------------
2747   * Useful inlines.
2748   *---------------------------------------------------------------*/
2749 diff -NurpP --minimal linux-2.6.22.10/fs/attr.c linux-2.6.22.10-vs2.2.0.5/fs/attr.c
2750 --- linux-2.6.22.10/fs/attr.c   2007-07-09 13:19:22 +0200
2751 +++ linux-2.6.22.10-vs2.2.0.5/fs/attr.c 2007-10-29 23:34:23 +0100
2752 @@ -14,6 +14,9 @@
2753  #include <linux/fcntl.h>
2754  #include <linux/quotaops.h>
2755  #include <linux/security.h>
2756 +#include <linux/proc_fs.h>
2757 +#include <linux/devpts_fs.h>
2758 +#include <linux/vs_base.h>
2759  
2760  /* Taken over from the old code... */
2761  
2762 @@ -55,6 +58,27 @@ int inode_change_ok(struct inode *inode,
2763                 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
2764                         goto error;
2765         }
2766 +
2767 +       /* Check for evil vserver activity */
2768 +       if (vx_check(0, VS_ADMIN))
2769 +               goto fine;
2770 +
2771 +       if (IS_BARRIER(inode)) {
2772 +               vxwprintk_task(1, "messing with the barrier.");
2773 +               goto error;
2774 +       }
2775 +       switch (inode->i_sb->s_magic) {
2776 +               case PROC_SUPER_MAGIC:
2777 +                       /* maybe allow that in the future? */
2778 +                       vxwprintk_task(1, "messing with the procfs.");
2779 +                       goto error;
2780 +               case DEVPTS_SUPER_MAGIC:
2781 +                       /* devpts is xid tagged */
2782 +                       if (vx_check((xid_t)inode->i_tag, VS_IDENT))
2783 +                               goto fine;
2784 +                       vxwprintk_task(1, "messing with the devpts.");
2785 +                       goto error;
2786 +       }
2787  fine:
2788         retval = 0;
2789  error:
2790 @@ -78,6 +102,8 @@ int inode_setattr(struct inode * inode, 
2791                 inode->i_uid = attr->ia_uid;
2792         if (ia_valid & ATTR_GID)
2793                 inode->i_gid = attr->ia_gid;
2794 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2795 +               inode->i_tag = attr->ia_tag;
2796         if (ia_valid & ATTR_ATIME)
2797                 inode->i_atime = timespec_trunc(attr->ia_atime,
2798                                                 inode->i_sb->s_time_gran);
2799 @@ -152,7 +178,8 @@ int notify_change(struct dentry * dentry
2800                         error = security_inode_setattr(dentry, attr);
2801                 if (!error) {
2802                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2803 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2804 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2805 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2806                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2807                         if (!error)
2808                                 error = inode_setattr(inode, attr);
2809 diff -NurpP --minimal linux-2.6.22.10/fs/binfmt_aout.c linux-2.6.22.10-vs2.2.0.5/fs/binfmt_aout.c
2810 --- linux-2.6.22.10/fs/binfmt_aout.c    2007-02-06 03:01:16 +0100
2811 +++ linux-2.6.22.10-vs2.2.0.5/fs/binfmt_aout.c  2007-06-15 02:37:03 +0200
2812 @@ -24,6 +24,7 @@
2813  #include <linux/binfmts.h>
2814  #include <linux/personality.h>
2815  #include <linux/init.h>
2816 +#include <linux/vs_memory.h>
2817  
2818  #include <asm/system.h>
2819  #include <asm/uaccess.h>
2820 diff -NurpP --minimal linux-2.6.22.10/fs/binfmt_elf.c linux-2.6.22.10-vs2.2.0.5/fs/binfmt_elf.c
2821 --- linux-2.6.22.10/fs/binfmt_elf.c     2007-07-09 13:19:22 +0200
2822 +++ linux-2.6.22.10-vs2.2.0.5/fs/binfmt_elf.c   2007-07-09 13:11:54 +0200
2823 @@ -39,6 +39,7 @@
2824  #include <linux/random.h>
2825  #include <linux/elf.h>
2826  #include <linux/utsname.h>
2827 +#include <linux/vs_memory.h>
2828  #include <asm/uaccess.h>
2829  #include <asm/param.h>
2830  #include <asm/page.h>
2831 diff -NurpP --minimal linux-2.6.22.10/fs/binfmt_flat.c linux-2.6.22.10-vs2.2.0.5/fs/binfmt_flat.c
2832 --- linux-2.6.22.10/fs/binfmt_flat.c    2007-07-09 13:19:22 +0200
2833 +++ linux-2.6.22.10-vs2.2.0.5/fs/binfmt_flat.c  2007-06-17 05:54:17 +0200
2834 @@ -36,6 +36,7 @@
2835  #include <linux/init.h>
2836  #include <linux/flat.h>
2837  #include <linux/syscalls.h>
2838 +#include <linux/vs_memory.h>
2839  
2840  #include <asm/byteorder.h>
2841  #include <asm/system.h>
2842 diff -NurpP --minimal linux-2.6.22.10/fs/binfmt_som.c linux-2.6.22.10-vs2.2.0.5/fs/binfmt_som.c
2843 --- linux-2.6.22.10/fs/binfmt_som.c     2006-11-30 21:19:19 +0100
2844 +++ linux-2.6.22.10-vs2.2.0.5/fs/binfmt_som.c   2007-06-15 02:37:03 +0200
2845 @@ -28,6 +28,7 @@
2846  #include <linux/shm.h>
2847  #include <linux/personality.h>
2848  #include <linux/init.h>
2849 +#include <linux/vs_memory.h>
2850  
2851  #include <asm/a.out.h>
2852  #include <asm/uaccess.h>
2853 diff -NurpP --minimal linux-2.6.22.10/fs/dcache.c linux-2.6.22.10-vs2.2.0.5/fs/dcache.c
2854 --- linux-2.6.22.10/fs/dcache.c 2007-07-09 13:19:23 +0200
2855 +++ linux-2.6.22.10-vs2.2.0.5/fs/dcache.c       2007-06-15 02:37:03 +0200
2856 @@ -31,6 +31,7 @@
2857  #include <linux/seqlock.h>
2858  #include <linux/swap.h>
2859  #include <linux/bootmem.h>
2860 +#include <linux/vs_limit.h>
2861  #include "internal.h"
2862  
2863  
2864 @@ -176,6 +177,7 @@ void dput(struct dentry *dentry)
2865         if (!dentry)
2866                 return;
2867  
2868 +       vx_dentry_dec(dentry);
2869  repeat:
2870         if (atomic_read(&dentry->d_count) == 1)
2871                 might_sleep();
2872 @@ -189,6 +191,8 @@ repeat:
2873                 return;
2874         }
2875  
2876 +       vx_dentry_dec(dentry);
2877 +
2878         /*
2879          * AV: ->d_delete() is _NOT_ allowed to block now.
2880          */
2881 @@ -288,6 +292,7 @@ static inline struct dentry * __dget_loc
2882         if (!list_empty(&dentry->d_lru)) {
2883                 dentry_stat.nr_unused--;
2884                 list_del_init(&dentry->d_lru);
2885 +               vx_dentry_inc(dentry);
2886         }
2887         return dentry;
2888  }
2889 @@ -898,6 +903,9 @@ struct dentry *d_alloc(struct dentry * p
2890         struct dentry *dentry;
2891         char *dname;
2892  
2893 +       if (!vx_dentry_avail(1))
2894 +               return NULL;
2895 +
2896         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); 
2897         if (!dentry)
2898                 return NULL;
2899 @@ -946,6 +954,7 @@ struct dentry *d_alloc(struct dentry * p
2900         if (parent)
2901                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2902         dentry_stat.nr_dentry++;
2903 +       vx_dentry_inc(dentry);
2904         spin_unlock(&dcache_lock);
2905  
2906         return dentry;
2907 @@ -1295,6 +1304,7 @@ struct dentry * __d_lookup(struct dentry
2908  
2909                 if (!d_unhashed(dentry)) {
2910                         atomic_inc(&dentry->d_count);
2911 +                       vx_dentry_inc(dentry);
2912                         found = dentry;
2913                 }
2914                 spin_unlock(&dentry->d_lock);
2915 diff -NurpP --minimal linux-2.6.22.10/fs/devpts/inode.c linux-2.6.22.10-vs2.2.0.5/fs/devpts/inode.c
2916 --- linux-2.6.22.10/fs/devpts/inode.c   2007-07-09 13:19:23 +0200
2917 +++ linux-2.6.22.10-vs2.2.0.5/fs/devpts/inode.c 2007-06-15 02:41:30 +0200
2918 @@ -20,8 +20,22 @@
2919  #include <linux/devpts_fs.h>
2920  #include <linux/parser.h>
2921  #include <linux/fsnotify.h>
2922 +#include <linux/vs_base.h>
2923 +
2924  
2925 -#define DEVPTS_SUPER_MAGIC 0x1cd1
2926 +static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
2927 +{
2928 +       int ret = -EACCES;
2929 +
2930 +       /* devpts is xid tagged */
2931 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2932 +               ret = generic_permission(inode, mask, NULL);
2933 +       return ret;
2934 +}
2935 +
2936 +static struct inode_operations devpts_file_inode_operations = {
2937 +       .permission     = devpts_permission,
2938 +};
2939  
2940  static struct vfsmount *devpts_mnt;
2941  static struct dentry *devpts_root;
2942 @@ -92,6 +106,25 @@ static int devpts_remount(struct super_b
2943         return 0;
2944  }
2945  
2946 +static int devpts_filter(struct dentry *de)
2947 +{
2948 +       /* devpts is xid tagged */
2949 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2950 +}
2951 +
2952 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2953 +{
2954 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2955 +}
2956 +
2957 +static struct file_operations devpts_dir_operations = {
2958 +       .open           = dcache_dir_open,
2959 +       .release        = dcache_dir_close,
2960 +       .llseek         = dcache_dir_lseek,
2961 +       .read           = generic_read_dir,
2962 +       .readdir        = devpts_readdir,
2963 +};
2964 +
2965  static const struct super_operations devpts_sops = {
2966         .statfs         = simple_statfs,
2967         .remount_fs     = devpts_remount,
2968 @@ -117,8 +150,10 @@ devpts_fill_super(struct super_block *s,
2969         inode->i_uid = inode->i_gid = 0;
2970         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2971         inode->i_op = &simple_dir_inode_operations;
2972 -       inode->i_fop = &simple_dir_operations;
2973 +       inode->i_fop = &devpts_dir_operations;
2974         inode->i_nlink = 2;
2975 +       /* devpts is xid tagged */
2976 +       inode->i_tag = (tag_t)vx_current_xid();
2977  
2978         devpts_root = s->s_root = d_alloc_root(inode);
2979         if (s->s_root)
2980 @@ -176,6 +211,9 @@ int devpts_pty_new(struct tty_struct *tt
2981         inode->i_gid = config.setgid ? config.gid : current->fsgid;
2982         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2983         init_special_inode(inode, S_IFCHR|config.mode, device);
2984 +       /* devpts is xid tagged */
2985 +       inode->i_tag = (tag_t)vx_current_xid();
2986 +       inode->i_op = &devpts_file_inode_operations;
2987         inode->i_private = tty;
2988  
2989         dentry = get_node(number);
2990 diff -NurpP --minimal linux-2.6.22.10/fs/ecryptfs/inode.c linux-2.6.22.10-vs2.2.0.5/fs/ecryptfs/inode.c
2991 --- linux-2.6.22.10/fs/ecryptfs/inode.c 2007-10-30 01:57:14 +0100
2992 +++ linux-2.6.22.10-vs2.2.0.5/fs/ecryptfs/inode.c       2007-08-12 12:21:51 +0200
2993 @@ -423,7 +423,7 @@ static int ecryptfs_link(struct dentry *
2994         dget(lower_new_dentry);
2995         lower_dir_dentry = lock_parent(lower_new_dentry);
2996         rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
2997 -                     lower_new_dentry);
2998 +                     lower_new_dentry, NULL);
2999         if (rc || !lower_new_dentry->d_inode)
3000                 goto out_lock;
3001         rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
3002 @@ -451,7 +451,7 @@ static int ecryptfs_unlink(struct inode 
3003         struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
3004  
3005         lock_parent(lower_dentry);
3006 -       rc = vfs_unlink(lower_dir_inode, lower_dentry);
3007 +       rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
3008         if (rc) {
3009                 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
3010                 goto out_unlock;
3011 @@ -488,7 +488,7 @@ static int ecryptfs_symlink(struct inode
3012                 goto out_lock;
3013         }
3014         rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
3015 -                        encoded_symname, mode);
3016 +                        encoded_symname, mode, NULL);
3017         kfree(encoded_symname);
3018         if (rc || !lower_dentry->d_inode)
3019                 goto out_lock;
3020 @@ -513,7 +513,7 @@ static int ecryptfs_mkdir(struct inode *
3021  
3022         lower_dentry = ecryptfs_dentry_to_lower(dentry);
3023         lower_dir_dentry = lock_parent(lower_dentry);
3024 -       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
3025 +       rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode, NULL);
3026         if (rc || !lower_dentry->d_inode)
3027                 goto out;
3028         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
3029 @@ -539,7 +539,7 @@ static int ecryptfs_rmdir(struct inode *
3030         dget(dentry);
3031         lower_dir_dentry = lock_parent(lower_dentry);
3032         dget(lower_dentry);
3033 -       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
3034 +       rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry, NULL);
3035         dput(lower_dentry);
3036         if (!rc)
3037                 d_delete(lower_dentry);
3038 @@ -561,7 +561,7 @@ ecryptfs_mknod(struct inode *dir, struct
3039  
3040         lower_dentry = ecryptfs_dentry_to_lower(dentry);
3041         lower_dir_dentry = lock_parent(lower_dentry);
3042 -       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
3043 +       rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev, NULL);
3044         if (rc || !lower_dentry->d_inode)
3045                 goto out;
3046         rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
3047 diff -NurpP --minimal linux-2.6.22.10/fs/exec.c linux-2.6.22.10-vs2.2.0.5/fs/exec.c
3048 --- linux-2.6.22.10/fs/exec.c   2007-10-30 01:57:14 +0100
3049 +++ linux-2.6.22.10-vs2.2.0.5/fs/exec.c 2007-09-05 03:05:52 +0200
3050 @@ -51,6 +51,7 @@
3051  #include <linux/cn_proc.h>
3052  #include <linux/audit.h>
3053  #include <linux/signalfd.h>
3054 +#include <linux/vs_memory.h>
3055  
3056  #include <asm/uaccess.h>
3057  #include <asm/mmu_context.h>
3058 @@ -440,7 +441,8 @@ int setup_arg_pages(struct linux_binprm 
3059                         kmem_cache_free(vm_area_cachep, mpnt);
3060                         return ret;
3061                 }
3062 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
3063 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
3064 +               mm->stack_vm = mm->total_vm;
3065         }
3066  
3067         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
3068 @@ -1336,7 +1338,7 @@ static int format_corename(char *corenam
3069                         /* UNIX time of coredump */
3070                         case 't': {
3071                                 struct timeval tv;
3072 -                               do_gettimeofday(&tv);
3073 +                               vx_gettimeofday(&tv);
3074                                 rc = snprintf(out_ptr, out_end - out_ptr,
3075                                               "%lu", tv.tv_sec);
3076                                 if (rc > out_end - out_ptr)
3077 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/balloc.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/balloc.c
3078 --- linux-2.6.22.10/fs/ext2/balloc.c    2007-05-02 19:25:17 +0200
3079 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/balloc.c  2007-06-15 02:37:03 +0200
3080 @@ -16,6 +16,8 @@
3081  #include <linux/sched.h>
3082  #include <linux/buffer_head.h>
3083  #include <linux/capability.h>
3084 +#include <linux/vs_dlimit.h>
3085 +#include <linux/vs_tag.h>
3086  
3087  /*
3088   * balloc.c contains the blocks allocation and deallocation routines
3089 @@ -102,12 +104,13 @@ static int reserve_blocks(struct super_b
3090  {
3091         struct ext2_sb_info *sbi = EXT2_SB(sb);
3092         struct ext2_super_block *es = sbi->s_es;
3093 -       unsigned free_blocks;
3094 -       unsigned root_blocks;
3095 +       unsigned long long free_blocks, root_blocks;
3096  
3097         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3098         root_blocks = le32_to_cpu(es->s_r_blocks_count);
3099  
3100 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3101 +
3102         if (free_blocks < count)
3103                 count = free_blocks;
3104  
3105 @@ -258,6 +261,7 @@ do_more:
3106         }
3107  error_return:
3108         brelse(bitmap_bh);
3109 +       DLIMIT_FREE_BLOCK(inode, freed);
3110         release_blocks(sb, freed);
3111         DQUOT_FREE_BLOCK(inode, freed);
3112  }
3113 @@ -361,6 +365,10 @@ int ext2_new_block(struct inode *inode, 
3114                 *err = -ENOSPC;
3115                 goto out_dquot;
3116         }
3117 +       if (DLIMIT_ALLOC_BLOCK(inode, es_alloc)) {
3118 +               *err = -ENOSPC;
3119 +               goto out_dlimit;
3120 +       }
3121  
3122         ext2_debug ("goal=%lu.\n", goal);
3123  
3124 @@ -508,6 +516,8 @@ got_block:
3125         *err = 0;
3126  out_release:
3127         group_release_blocks(sb, group_no, desc, gdp_bh, group_alloc);
3128 +       DLIMIT_FREE_BLOCK(inode, es_alloc);
3129 +out_dlimit:
3130         release_blocks(sb, es_alloc);
3131  out_dquot:
3132         DQUOT_FREE_BLOCK(inode, dq_alloc);
3133 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/ext2.h linux-2.6.22.10-vs2.2.0.5/fs/ext2/ext2.h
3134 --- linux-2.6.22.10/fs/ext2/ext2.h      2007-07-09 13:19:23 +0200
3135 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/ext2.h    2007-06-15 02:37:03 +0200
3136 @@ -167,6 +167,7 @@ extern const struct file_operations ext2
3137  extern const struct address_space_operations ext2_aops;
3138  extern const struct address_space_operations ext2_aops_xip;
3139  extern const struct address_space_operations ext2_nobh_aops;
3140 +extern int ext2_sync_flags(struct inode *inode);
3141  
3142  /* namei.c */
3143  extern const struct inode_operations ext2_dir_inode_operations;
3144 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/file.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/file.c
3145 --- linux-2.6.22.10/fs/ext2/file.c      2007-05-02 19:25:17 +0200
3146 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/file.c    2007-10-29 23:24:21 +0100
3147 @@ -85,4 +85,5 @@ const struct inode_operations ext2_file_
3148  #endif
3149         .setattr        = ext2_setattr,
3150         .permission     = ext2_permission,
3151 +       .sync_flags     = ext2_sync_flags,
3152  };
3153 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/ialloc.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/ialloc.c
3154 --- linux-2.6.22.10/fs/ext2/ialloc.c    2006-11-30 21:19:19 +0100
3155 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/ialloc.c  2007-06-15 02:37:03 +0200
3156 @@ -17,6 +17,8 @@
3157  #include <linux/backing-dev.h>
3158  #include <linux/buffer_head.h>
3159  #include <linux/random.h>
3160 +#include <linux/vs_dlimit.h>
3161 +#include <linux/vs_tag.h>
3162  #include "ext2.h"
3163  #include "xattr.h"
3164  #include "acl.h"
3165 @@ -125,6 +127,7 @@ void ext2_free_inode (struct inode * ino
3166                 ext2_xattr_delete_inode(inode);
3167                 DQUOT_FREE_INODE(inode);
3168                 DQUOT_DROP(inode);
3169 +               DLIMIT_FREE_INODE(inode);
3170         }
3171  
3172         es = EXT2_SB(sb)->s_es;
3173 @@ -464,6 +467,11 @@ struct inode *ext2_new_inode(struct inod
3174         if (!inode)
3175                 return ERR_PTR(-ENOMEM);
3176  
3177 +       inode->i_tag = dx_current_fstag(sb);
3178 +       if (DLIMIT_ALLOC_INODE(inode)) {
3179 +               err = -ENOSPC;
3180 +               goto fail_dlim;
3181 +       }
3182         ei = EXT2_I(inode);
3183         sbi = EXT2_SB(sb);
3184         es = sbi->s_es;
3185 @@ -577,7 +585,8 @@ got:
3186         inode->i_blocks = 0;
3187         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME_SEC;
3188         memset(ei->i_data, 0, sizeof(ei->i_data));
3189 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
3190 +       ei->i_flags = EXT2_I(dir)->i_flags &
3191 +               ~(EXT2_BTREE_FL|EXT2_IUNLINK_FL|EXT2_BARRIER_FL);
3192         if (S_ISLNK(mode))
3193                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
3194         /* dirsync is only applied to directories */
3195 @@ -625,12 +634,15 @@ fail_free_drop:
3196  
3197  fail_drop:
3198         DQUOT_DROP(inode);
3199 +       DLIMIT_FREE_INODE(inode);
3200         inode->i_flags |= S_NOQUOTA;
3201         inode->i_nlink = 0;
3202         iput(inode);
3203         return ERR_PTR(err);
3204  
3205  fail:
3206 +       DLIMIT_FREE_INODE(inode);
3207 +fail_dlim:
3208         make_bad_inode(inode);
3209         iput(inode);
3210         return ERR_PTR(err);
3211 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/inode.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/inode.c
3212 --- linux-2.6.22.10/fs/ext2/inode.c     2007-07-09 13:19:23 +0200
3213 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/inode.c   2007-06-15 02:57:56 +0200
3214 @@ -31,6 +31,7 @@
3215  #include <linux/writeback.h>
3216  #include <linux/buffer_head.h>
3217  #include <linux/mpage.h>
3218 +#include <linux/vs_tag.h>
3219  #include "ext2.h"
3220  #include "acl.h"
3221  #include "xip.h"
3222 @@ -913,7 +914,7 @@ void ext2_truncate (struct inode * inode
3223                 return;
3224         if (ext2_inode_is_fast_symlink(inode))
3225                 return;
3226 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3227 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3228                 return;
3229  
3230         ext2_discard_prealloc(inode);
3231 @@ -1042,13 +1043,20 @@ void ext2_set_inode_flags(struct inode *
3232  {
3233         unsigned int flags = EXT2_I(inode)->i_flags;
3234  
3235 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3236 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3237 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3238 +
3239 +       if (flags & EXT2_IMMUTABLE_FL)
3240 +               inode->i_flags |= S_IMMUTABLE;
3241 +       if (flags & EXT2_IUNLINK_FL)
3242 +               inode->i_flags |= S_IUNLINK;
3243 +       if (flags & EXT2_BARRIER_FL)
3244 +               inode->i_flags |= S_BARRIER;
3245 +
3246         if (flags & EXT2_SYNC_FL)
3247                 inode->i_flags |= S_SYNC;
3248         if (flags & EXT2_APPEND_FL)
3249                 inode->i_flags |= S_APPEND;
3250 -       if (flags & EXT2_IMMUTABLE_FL)
3251 -               inode->i_flags |= S_IMMUTABLE;
3252         if (flags & EXT2_NOATIME_FL)
3253                 inode->i_flags |= S_NOATIME;
3254         if (flags & EXT2_DIRSYNC_FL)
3255 @@ -1074,12 +1082,37 @@ void ext2_get_inode_flags(struct ext2_in
3256                 ei->i_flags |= EXT2_DIRSYNC_FL;
3257  }
3258  
3259 +int ext2_sync_flags(struct inode *inode)
3260 +{
3261 +       unsigned int oldflags, newflags;
3262 +
3263 +       oldflags = EXT2_I(inode)->i_flags;
3264 +       newflags = oldflags & ~(EXT2_IMMUTABLE_FL |
3265 +               EXT2_IUNLINK_FL | EXT2_BARRIER_FL);
3266 +
3267 +       if (IS_IMMUTABLE(inode))
3268 +               newflags |= EXT2_IMMUTABLE_FL;
3269 +       if (IS_IUNLINK(inode))
3270 +               newflags |= EXT2_IUNLINK_FL;
3271 +       if (IS_BARRIER(inode))
3272 +               newflags |= EXT2_BARRIER_FL;
3273 +
3274 +       if (oldflags ^ newflags) {
3275 +               EXT2_I(inode)->i_flags = newflags;
3276 +               inode->i_ctime = CURRENT_TIME;
3277 +               mark_inode_dirty(inode);
3278 +       }
3279 +       return 0;
3280 +}
3281 +
3282  void ext2_read_inode (struct inode * inode)
3283  {
3284         struct ext2_inode_info *ei = EXT2_I(inode);
3285         ino_t ino = inode->i_ino;
3286         struct buffer_head * bh;
3287         struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
3288 +       uid_t uid;
3289 +       gid_t gid;
3290         int n;
3291  
3292  #ifdef CONFIG_EXT2_FS_POSIX_ACL
3293 @@ -1090,12 +1123,17 @@ void ext2_read_inode (struct inode * ino
3294                 goto bad_inode;
3295  
3296         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3297 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3298 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3299 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3300 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3301         if (!(test_opt (inode->i_sb, NO_UID32))) {
3302 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3303 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3304 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3305 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3306         }
3307 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3308 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3309 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3310 +               le16_to_cpu(raw_inode->i_raw_tag));
3311 +
3312         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3313         inode->i_size = le32_to_cpu(raw_inode->i_size);
3314         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3315 @@ -1192,8 +1230,8 @@ static int ext2_update_inode(struct inod
3316         struct ext2_inode_info *ei = EXT2_I(inode);
3317         struct super_block *sb = inode->i_sb;
3318         ino_t ino = inode->i_ino;
3319 -       uid_t uid = inode->i_uid;
3320 -       gid_t gid = inode->i_gid;
3321 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3322 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3323         struct buffer_head * bh;
3324         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
3325         int n;
3326 @@ -1229,6 +1267,9 @@ static int ext2_update_inode(struct inod
3327                 raw_inode->i_uid_high = 0;
3328                 raw_inode->i_gid_high = 0;
3329         }
3330 +#ifdef CONFIG_TAGGING_INTERN
3331 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3332 +#endif
3333         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3334         raw_inode->i_size = cpu_to_le32(inode->i_size);
3335         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3336 @@ -1315,7 +1356,8 @@ int ext2_setattr(struct dentry *dentry, 
3337         if (error)
3338                 return error;
3339         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3340 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3341 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3342 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3343                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
3344                 if (error)
3345                         return error;
3346 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/ioctl.c
3347 --- linux-2.6.22.10/fs/ext2/ioctl.c     2007-07-09 13:19:23 +0200
3348 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/ioctl.c   2007-06-15 02:37:03 +0200
3349 @@ -13,6 +13,7 @@
3350  #include <linux/sched.h>
3351  #include <linux/compat.h>
3352  #include <linux/smp_lock.h>
3353 +#include <linux/mount.h>
3354  #include <asm/current.h>
3355  #include <asm/uaccess.h>
3356  
3357 @@ -33,7 +34,8 @@ int ext2_ioctl (struct inode * inode, st
3358         case EXT2_IOC_SETFLAGS: {
3359                 unsigned int oldflags;
3360  
3361 -               if (IS_RDONLY(inode))
3362 +               if (IS_RDONLY(inode) ||
3363 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3364                         return -EROFS;
3365  
3366                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3367 @@ -54,7 +56,9 @@ int ext2_ioctl (struct inode * inode, st
3368                  *
3369                  * This test looks nicer. Thanks to Pauline Middelink
3370                  */
3371 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
3372 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
3373 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
3374 +                       EXT2_IMMUTABLE_FL | EXT2_IUNLINK_FL))) {
3375                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3376                                 mutex_unlock(&inode->i_mutex);
3377                                 return -EPERM;
3378 @@ -76,7 +80,8 @@ int ext2_ioctl (struct inode * inode, st
3379         case EXT2_IOC_SETVERSION:
3380                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3381                         return -EPERM;
3382 -               if (IS_RDONLY(inode))
3383 +               if (IS_RDONLY(inode) ||
3384 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3385                         return -EROFS;
3386                 if (get_user(inode->i_generation, (int __user *) arg))
3387                         return -EFAULT; 
3388 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/namei.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/namei.c
3389 --- linux-2.6.22.10/fs/ext2/namei.c     2007-05-02 19:25:17 +0200
3390 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/namei.c   2007-06-15 02:37:03 +0200
3391 @@ -31,6 +31,7 @@
3392   */
3393  
3394  #include <linux/pagemap.h>
3395 +#include <linux/vs_tag.h>
3396  #include "ext2.h"
3397  #include "xattr.h"
3398  #include "acl.h"
3399 @@ -66,6 +67,7 @@ static struct dentry *ext2_lookup(struct
3400                 inode = iget(dir->i_sb, ino);
3401                 if (!inode)
3402                         return ERR_PTR(-EACCES);
3403 +               dx_propagate_tag(nd, inode);
3404         }
3405         return d_splice_alias(inode, dentry);
3406  }
3407 @@ -391,6 +393,7 @@ const struct inode_operations ext2_dir_i
3408  #endif
3409         .setattr        = ext2_setattr,
3410         .permission     = ext2_permission,
3411 +       .sync_flags     = ext2_sync_flags,
3412  };
3413  
3414  const struct inode_operations ext2_special_inode_operations = {
3415 @@ -402,4 +405,5 @@ const struct inode_operations ext2_speci
3416  #endif
3417         .setattr        = ext2_setattr,
3418         .permission     = ext2_permission,
3419 +       .sync_flags     = ext2_sync_flags,
3420  };
3421 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/super.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/super.c
3422 --- linux-2.6.22.10/fs/ext2/super.c     2007-07-09 13:19:23 +0200
3423 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/super.c   2007-07-07 03:52:53 +0200
3424 @@ -321,7 +321,7 @@ enum {
3425         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3426         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3427         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3428 -       Opt_usrquota, Opt_grpquota
3429 +       Opt_usrquota, Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3430  };
3431  
3432  static match_table_t tokens = {
3433 @@ -349,6 +349,10 @@ static match_table_t tokens = {
3434         {Opt_acl, "acl"},
3435         {Opt_noacl, "noacl"},
3436         {Opt_xip, "xip"},
3437 +       {Opt_tag, "tag"},
3438 +       {Opt_notag, "notag"},
3439 +       {Opt_tagid, "tagid=%u"},
3440 +       {Opt_tag, "tagxid"},
3441         {Opt_grpquota, "grpquota"},
3442         {Opt_ignore, "noquota"},
3443         {Opt_quota, "quota"},
3444 @@ -417,6 +421,20 @@ static int parse_options (char * options
3445                 case Opt_nouid32:
3446                         set_opt (sbi->s_mount_opt, NO_UID32);
3447                         break;
3448 +#ifndef CONFIG_TAGGING_NONE
3449 +               case Opt_tag:
3450 +                       set_opt (sbi->s_mount_opt, TAGGED);
3451 +                       break;
3452 +               case Opt_notag:
3453 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3454 +                       break;
3455 +#endif
3456 +#ifdef CONFIG_PROPAGATE
3457 +               case Opt_tagid:
3458 +                       /* use args[0] */
3459 +                       set_opt (sbi->s_mount_opt, TAGGED);
3460 +                       break;
3461 +#endif
3462                 case Opt_nocheck:
3463                         clear_opt (sbi->s_mount_opt, CHECK);
3464                         break;
3465 @@ -727,6 +745,8 @@ static int ext2_fill_super(struct super_
3466         if (!parse_options ((char *) data, sbi))
3467                 goto failed_mount;
3468  
3469 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3470 +               sb->s_flags |= MS_TAGGED;
3471         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3472                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3473                  MS_POSIXACL : 0);
3474 @@ -1035,6 +1055,13 @@ static int ext2_remount (struct super_bl
3475                 goto restore_opts;
3476         }
3477  
3478 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3479 +               !(sb->s_flags & MS_TAGGED)) {
3480 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3481 +                      sb->s_id);
3482 +               return -EINVAL;
3483 +       }
3484 +
3485         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3486                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3487  
3488 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/symlink.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/symlink.c
3489 --- linux-2.6.22.10/fs/ext2/symlink.c   2007-05-02 19:25:17 +0200
3490 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/symlink.c 2007-06-15 02:37:03 +0200
3491 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
3492         .listxattr      = ext2_listxattr,
3493         .removexattr    = generic_removexattr,
3494  #endif
3495 +       .sync_flags     = ext2_sync_flags,
3496  };
3497   
3498  const struct inode_operations ext2_fast_symlink_inode_operations = {
3499 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
3500         .listxattr      = ext2_listxattr,
3501         .removexattr    = generic_removexattr,
3502  #endif
3503 +       .sync_flags     = ext2_sync_flags,
3504  };
3505 diff -NurpP --minimal linux-2.6.22.10/fs/ext2/xattr.c linux-2.6.22.10-vs2.2.0.5/fs/ext2/xattr.c
3506 --- linux-2.6.22.10/fs/ext2/xattr.c     2007-02-06 03:01:18 +0100
3507 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext2/xattr.c   2007-06-15 02:37:03 +0200
3508 @@ -60,6 +60,7 @@
3509  #include <linux/mbcache.h>
3510  #include <linux/quotaops.h>
3511  #include <linux/rwsem.h>
3512 +#include <linux/vs_dlimit.h>
3513  #include "ext2.h"
3514  #include "xattr.h"
3515  #include "acl.h"
3516 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
3517                                    the inode.  */
3518                                 ea_bdebug(new_bh, "reusing block");
3519  
3520 +                               error = -ENOSPC;
3521 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3522 +                                       goto cleanup;
3523                                 error = -EDQUOT;
3524                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
3525 +                                       DLIMIT_FREE_BLOCK(inode, 1);
3526                                         unlock_buffer(new_bh);
3527                                         goto cleanup;
3528                                 }
3529 @@ -736,6 +741,7 @@ ext2_xattr_set2(struct inode *inode, str
3530                                 le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
3531                         if (ce)
3532                                 mb_cache_entry_release(ce);
3533 +                       DLIMIT_FREE_BLOCK(inode, 1);
3534                         DQUOT_FREE_BLOCK(inode, 1);
3535                         mark_buffer_dirty(old_bh);
3536                         ea_bdebug(old_bh, "refcount now=%d",
3537 @@ -800,6 +806,7 @@ ext2_xattr_delete_inode(struct inode *in
3538                 mark_buffer_dirty(bh);
3539                 if (IS_SYNC(inode))
3540                         sync_dirty_buffer(bh);
3541 +               DLIMIT_FREE_BLOCK(inode, 1);
3542                 DQUOT_FREE_BLOCK(inode, 1);
3543         }
3544         EXT2_I(inode)->i_file_acl = 0;
3545 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/balloc.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/balloc.c
3546 --- linux-2.6.22.10/fs/ext3/balloc.c    2007-05-02 19:25:17 +0200
3547 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/balloc.c  2007-07-16 06:31:34 +0200
3548 @@ -19,6 +19,8 @@
3549  #include <linux/ext3_jbd.h>
3550  #include <linux/quotaops.h>
3551  #include <linux/buffer_head.h>
3552 +#include <linux/vs_dlimit.h>
3553 +#include <linux/vs_tag.h>
3554  
3555  /*
3556   * balloc.c contains the blocks allocation and deallocation routines
3557 @@ -613,8 +615,10 @@ void ext3_free_blocks(handle_t *handle, 
3558                 return;
3559         }
3560         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
3561 -       if (dquot_freed_blocks)
3562 +       if (dquot_freed_blocks) {
3563 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3564                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3565 +       }
3566         return;
3567  }
3568  
3569 @@ -1353,18 +1357,33 @@ out:
3570   *
3571   * Check if filesystem has at least 1 free block available for allocation.
3572   */
3573 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
3574 +static int ext3_has_free_blocks(struct super_block *sb)
3575  {
3576 -       ext3_fsblk_t free_blocks, root_blocks;
3577 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
3578 +       unsigned long long free_blocks, root_blocks;
3579 +       int cond;
3580  
3581         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
3582         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
3583 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
3584 +
3585 +       vxdprintk(VXD_CBIT(dlim, 3),
3586 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
3587 +               sb, free_blocks, root_blocks);
3588 +
3589 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
3590 +
3591 +       cond = (free_blocks < root_blocks + 1 &&
3592 +               !capable(CAP_SYS_RESOURCE) &&
3593                 sbi->s_resuid != current->fsuid &&
3594 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
3595 -               return 0;
3596 -       }
3597 -       return 1;
3598 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
3599 +
3600 +       vxdprintk(VXD_CBIT(dlim, 3),
3601 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
3602 +               sb, free_blocks, root_blocks,
3603 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
3604 +               sbi->s_resuid, current->fsuid, cond?0:1);
3605 +
3606 +       return (cond ? 0 : 1);
3607  }
3608  
3609  /**
3610 @@ -1381,7 +1400,7 @@ static int ext3_has_free_blocks(struct e
3611   */
3612  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
3613  {
3614 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
3615 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
3616                 return 0;
3617  
3618         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
3619 @@ -1444,6 +1463,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3620                 *errp = -EDQUOT;
3621                 return 0;
3622         }
3623 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
3624 +           goto out_dlimit;
3625  
3626         sbi = EXT3_SB(sb);
3627         es = EXT3_SB(sb)->s_es;
3628 @@ -1460,7 +1481,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
3629         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
3630                 my_rsv = &block_i->rsv_window_node;
3631  
3632 -       if (!ext3_has_free_blocks(sbi)) {
3633 +       if (!ext3_has_free_blocks(sb)) {
3634                 *errp = -ENOSPC;
3635                 goto out;
3636         }
3637 @@ -1647,12 +1668,16 @@ allocated:
3638         *errp = 0;
3639         brelse(bitmap_bh);
3640         DQUOT_FREE_BLOCK(inode, *count-num);
3641 +       DLIMIT_FREE_BLOCK(inode, *count-num);
3642         *count = num;
3643         return ret_block;
3644  
3645  io_error:
3646         *errp = -EIO;
3647  out:
3648 +       if (!performed_allocation)
3649 +               DLIMIT_FREE_BLOCK(inode, *count);
3650 +out_dlimit:
3651         if (fatal) {
3652                 *errp = fatal;
3653                 ext3_std_error(sb, fatal);
3654 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/file.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/file.c
3655 --- linux-2.6.22.10/fs/ext3/file.c      2007-05-02 19:25:17 +0200
3656 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/file.c    2007-10-29 23:24:21 +0100
3657 @@ -135,5 +135,6 @@ const struct inode_operations ext3_file_
3658         .removexattr    = generic_removexattr,
3659  #endif
3660         .permission     = ext3_permission,
3661 +       .sync_flags     = ext3_sync_flags,
3662  };
3663  
3664 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/ialloc.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/ialloc.c
3665 --- linux-2.6.22.10/fs/ext3/ialloc.c    2006-11-30 21:19:19 +0100
3666 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/ialloc.c  2007-06-15 02:37:03 +0200
3667 @@ -23,6 +23,8 @@
3668  #include <linux/buffer_head.h>
3669  #include <linux/random.h>
3670  #include <linux/bitops.h>
3671 +#include <linux/vs_dlimit.h>
3672 +#include <linux/vs_tag.h>
3673  
3674  #include <asm/byteorder.h>
3675  
3676 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
3677         ext3_xattr_delete_inode(handle, inode);
3678         DQUOT_FREE_INODE(inode);
3679         DQUOT_DROP(inode);
3680 +       DLIMIT_FREE_INODE(inode);
3681  
3682         is_directory = S_ISDIR(inode->i_mode);
3683  
3684 @@ -445,6 +448,12 @@ struct inode *ext3_new_inode(handle_t *h
3685         inode = new_inode(sb);
3686         if (!inode)
3687                 return ERR_PTR(-ENOMEM);
3688 +
3689 +       inode->i_tag = dx_current_fstag(sb);
3690 +       if (DLIMIT_ALLOC_INODE(inode)) {
3691 +               err = -ENOSPC;
3692 +               goto out_dlimit;
3693 +       }
3694         ei = EXT3_I(inode);
3695  
3696         sbi = EXT3_SB(sb);
3697 @@ -566,7 +575,8 @@ got:
3698         ei->i_dir_start_lookup = 0;
3699         ei->i_disksize = 0;
3700  
3701 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
3702 +       ei->i_flags = EXT3_I(dir)->i_flags &
3703 +               ~(EXT3_INDEX_FL|EXT3_IUNLINK_FL|EXT3_BARRIER_FL);
3704         if (S_ISLNK(mode))
3705                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
3706         /* dirsync only applies to directories */
3707 @@ -621,6 +631,8 @@ got:
3708  fail:
3709         ext3_std_error(sb, err);
3710  out:
3711 +       DLIMIT_FREE_INODE(inode);
3712 +out_dlimit:
3713         iput(inode);
3714         ret = ERR_PTR(err);
3715  really_out:
3716 @@ -632,6 +644,7 @@ fail_free_drop:
3717  
3718  fail_drop:
3719         DQUOT_DROP(inode);
3720 +       DLIMIT_FREE_INODE(inode);
3721         inode->i_flags |= S_NOQUOTA;
3722         inode->i_nlink = 0;
3723         iput(inode);
3724 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/inode.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/inode.c
3725 --- linux-2.6.22.10/fs/ext3/inode.c     2007-07-09 13:19:23 +0200
3726 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/inode.c   2007-07-07 03:52:53 +0200
3727 @@ -36,6 +36,7 @@
3728  #include <linux/mpage.h>
3729  #include <linux/uio.h>
3730  #include <linux/bio.h>
3731 +#include <linux/vs_tag.h>
3732  #include "xattr.h"
3733  #include "acl.h"
3734  
3735 @@ -2237,7 +2238,7 @@ void ext3_truncate(struct inode *inode)
3736                 return;
3737         if (ext3_inode_is_fast_symlink(inode))
3738                 return;
3739 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3740 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3741                 return;
3742  
3743         /*
3744 @@ -2559,13 +2560,20 @@ void ext3_set_inode_flags(struct inode *
3745  {
3746         unsigned int flags = EXT3_I(inode)->i_flags;
3747  
3748 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3749 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
3750 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3751 +
3752 +       if (flags & EXT3_IMMUTABLE_FL)
3753 +               inode->i_flags |= S_IMMUTABLE;
3754 +       if (flags & EXT3_IUNLINK_FL)
3755 +               inode->i_flags |= S_IUNLINK;
3756 +       if (flags & EXT3_BARRIER_FL)
3757 +               inode->i_flags |= S_BARRIER;
3758 +
3759         if (flags & EXT3_SYNC_FL)
3760                 inode->i_flags |= S_SYNC;
3761         if (flags & EXT3_APPEND_FL)
3762                 inode->i_flags |= S_APPEND;
3763 -       if (flags & EXT3_IMMUTABLE_FL)
3764 -               inode->i_flags |= S_IMMUTABLE;
3765         if (flags & EXT3_NOATIME_FL)
3766                 inode->i_flags |= S_NOATIME;
3767         if (flags & EXT3_DIRSYNC_FL)
3768 @@ -2591,6 +2599,45 @@ void ext3_get_inode_flags(struct ext3_in
3769                 ei->i_flags |= EXT3_DIRSYNC_FL;
3770  }
3771  
3772 +int ext3_sync_flags(struct inode *inode)
3773 +{
3774 +       unsigned int oldflags, newflags;
3775 +       int err = 0;
3776 +
3777 +       oldflags = EXT3_I(inode)->i_flags;
3778 +       newflags = oldflags & ~(EXT3_IMMUTABLE_FL |
3779 +               EXT3_IUNLINK_FL | EXT3_BARRIER_FL);
3780 +
3781 +       if (IS_IMMUTABLE(inode))
3782 +               newflags |= EXT3_IMMUTABLE_FL;
3783 +       if (IS_IUNLINK(inode))
3784 +               newflags |= EXT3_IUNLINK_FL;
3785 +       if (IS_BARRIER(inode))
3786 +               newflags |= EXT3_BARRIER_FL;
3787 +
3788 +       if (oldflags ^ newflags) {
3789 +               handle_t *handle;
3790 +               struct ext3_iloc iloc;
3791 +
3792 +               handle = ext3_journal_start(inode, 1);
3793 +               if (IS_ERR(handle))
3794 +                       return PTR_ERR(handle);
3795 +               if (IS_SYNC(inode))
3796 +                       handle->h_sync = 1;
3797 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3798 +               if (err)
3799 +                       goto flags_err;
3800 +
3801 +               EXT3_I(inode)->i_flags = newflags;
3802 +               inode->i_ctime = CURRENT_TIME;
3803 +
3804 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3805 +       flags_err:
3806 +               ext3_journal_stop(handle);
3807 +       }
3808 +       return err;
3809 +}
3810 +
3811  void ext3_read_inode(struct inode * inode)
3812  {
3813         struct ext3_iloc iloc;
3814 @@ -2598,6 +2645,8 @@ void ext3_read_inode(struct inode * inod
3815         struct ext3_inode_info *ei = EXT3_I(inode);
3816         struct buffer_head *bh;
3817         int block;
3818 +       uid_t uid;
3819 +       gid_t gid;
3820  
3821  #ifdef CONFIG_EXT3_FS_POSIX_ACL
3822         ei->i_acl = EXT3_ACL_NOT_CACHED;
3823 @@ -2610,12 +2659,17 @@ void ext3_read_inode(struct inode * inod
3824         bh = iloc.bh;
3825         raw_inode = ext3_raw_inode(&iloc);
3826         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3827 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3828 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3829 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3830 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3831         if(!(test_opt (inode->i_sb, NO_UID32))) {
3832 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3833 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3834 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3835 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3836         }
3837 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3838 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3839 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3840 +               le16_to_cpu(raw_inode->i_raw_tag));
3841 +
3842         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3843         inode->i_size = le32_to_cpu(raw_inode->i_size);
3844         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3845 @@ -2741,6 +2795,8 @@ static int ext3_do_update_inode(handle_t
3846         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3847         struct ext3_inode_info *ei = EXT3_I(inode);
3848         struct buffer_head *bh = iloc->bh;
3849 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3850 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3851         int err = 0, rc, block;
3852  
3853         /* For fields not not tracking in the in-memory inode,
3854 @@ -2751,29 +2807,32 @@ static int ext3_do_update_inode(handle_t
3855         ext3_get_inode_flags(ei);
3856         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3857         if(!(test_opt(inode->i_sb, NO_UID32))) {
3858 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3859 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3860 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3861 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3862  /*
3863   * Fix up interoperability with old kernels. Otherwise, old inodes get
3864   * re-used with the upper 16 bits of the uid/gid intact
3865   */
3866                 if(!ei->i_dtime) {
3867                         raw_inode->i_uid_high =
3868 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3869 +                               cpu_to_le16(high_16_bits(uid));
3870                         raw_inode->i_gid_high =
3871 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3872 +                               cpu_to_le16(high_16_bits(gid));
3873                 } else {
3874                         raw_inode->i_uid_high = 0;
3875                         raw_inode->i_gid_high = 0;
3876                 }
3877         } else {
3878                 raw_inode->i_uid_low =
3879 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3880 +                       cpu_to_le16(fs_high2lowuid(uid));
3881                 raw_inode->i_gid_low =
3882 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3883 +                       cpu_to_le16(fs_high2lowgid(gid));
3884                 raw_inode->i_uid_high = 0;
3885                 raw_inode->i_gid_high = 0;
3886         }
3887 +#ifdef CONFIG_TAGGING_INTERN
3888 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3889 +#endif
3890         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3891         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3892         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3893 @@ -2926,7 +2985,8 @@ int ext3_setattr(struct dentry *dentry, 
3894                 return error;
3895  
3896         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3897 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3898 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3899 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3900                 handle_t *handle;
3901  
3902                 /* (user+group)*(old+new) structure, inode write (sb,
3903 @@ -2948,6 +3008,8 @@ int ext3_setattr(struct dentry *dentry, 
3904                         inode->i_uid = attr->ia_uid;
3905                 if (attr->ia_valid & ATTR_GID)
3906                         inode->i_gid = attr->ia_gid;
3907 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3908 +                       inode->i_tag = attr->ia_tag;
3909                 error = ext3_mark_inode_dirty(handle, inode);
3910                 ext3_journal_stop(handle);
3911         }
3912 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/ioctl.c
3913 --- linux-2.6.22.10/fs/ext3/ioctl.c     2007-07-09 13:19:23 +0200
3914 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/ioctl.c   2007-06-15 02:37:03 +0200
3915 @@ -8,6 +8,7 @@
3916   */
3917  
3918  #include <linux/fs.h>
3919 +#include <linux/mount.h>
3920  #include <linux/jbd.h>
3921  #include <linux/capability.h>
3922  #include <linux/ext3_fs.h>
3923 @@ -15,6 +16,7 @@
3924  #include <linux/time.h>
3925  #include <linux/compat.h>
3926  #include <linux/smp_lock.h>
3927 +#include <linux/vs_tag.h>
3928  #include <asm/uaccess.h>
3929  
3930  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
3931 @@ -38,7 +40,8 @@ int ext3_ioctl (struct inode * inode, st
3932                 unsigned int oldflags;
3933                 unsigned int jflag;
3934  
3935 -               if (IS_RDONLY(inode))
3936 +               if (IS_RDONLY(inode) ||
3937 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3938                         return -EROFS;
3939  
3940                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3941 @@ -62,7 +65,9 @@ int ext3_ioctl (struct inode * inode, st
3942                  *
3943                  * This test looks nicer. Thanks to Pauline Middelink
3944                  */
3945 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3946 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3947 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3948 +                       EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL))) {
3949                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3950                                 mutex_unlock(&inode->i_mutex);
3951                                 return -EPERM;
3952 @@ -124,7 +129,8 @@ flags_err:
3953  
3954                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3955                         return -EPERM;
3956 -               if (IS_RDONLY(inode))
3957 +               if (IS_RDONLY(inode) ||
3958 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3959                         return -EROFS;
3960                 if (get_user(generation, (int __user *) arg))
3961                         return -EFAULT;
3962 @@ -178,7 +184,8 @@ flags_err:
3963                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
3964                         return -ENOTTY;
3965  
3966 -               if (IS_RDONLY(inode))
3967 +               if (IS_RDONLY(inode) ||
3968 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3969                         return -EROFS;
3970  
3971                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
3972 @@ -213,7 +220,8 @@ flags_err:
3973                 if (!capable(CAP_SYS_RESOURCE))
3974                         return -EPERM;
3975  
3976 -               if (IS_RDONLY(inode))
3977 +               if (IS_RDONLY(inode) ||
3978 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3979                         return -EROFS;
3980  
3981                 if (get_user(n_blocks_count, (__u32 __user *)arg))
3982 @@ -234,7 +242,8 @@ flags_err:
3983                 if (!capable(CAP_SYS_RESOURCE))
3984                         return -EPERM;
3985  
3986 -               if (IS_RDONLY(inode))
3987 +               if (IS_RDONLY(inode) ||
3988 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
3989                         return -EROFS;
3990  
3991                 if (copy_from_user(&input, (struct ext3_new_group_input __user *)arg,
3992 @@ -249,6 +258,38 @@ flags_err:
3993                 return err;
3994         }
3995  
3996 +#if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_TAGGING_NONE)
3997 +       case EXT3_IOC_SETTAG: {
3998 +               handle_t *handle;
3999 +               struct ext3_iloc iloc;
4000 +               int tag;
4001 +               int err;
4002 +
4003 +               /* fixme: if stealth, return -ENOTTY */
4004 +               if (!capable(CAP_CONTEXT))
4005 +                       return -EPERM;
4006 +               if (IS_RDONLY(inode))
4007 +                       return -EROFS;
4008 +               if (!(inode->i_sb->s_flags & MS_TAGGED))
4009 +                       return -ENOSYS;
4010 +               if (get_user(tag, (int __user *) arg))
4011 +                       return -EFAULT;
4012 +
4013 +               handle = ext3_journal_start(inode, 1);
4014 +               if (IS_ERR(handle))
4015 +                       return PTR_ERR(handle);
4016 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
4017 +               if (err)
4018 +                       return err;
4019 +
4020 +               inode->i_tag = (tag & 0xFFFF);
4021 +               inode->i_ctime = CURRENT_TIME;
4022 +
4023 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
4024 +               ext3_journal_stop(handle);
4025 +               return err;
4026 +       }
4027 +#endif
4028  
4029         default:
4030                 return -ENOTTY;
4031 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/namei.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/namei.c
4032 --- linux-2.6.22.10/fs/ext3/namei.c     2007-10-30 01:57:14 +0100
4033 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/namei.c   2007-10-01 15:25:35 +0200
4034 @@ -36,6 +36,7 @@
4035  #include <linux/quotaops.h>
4036  #include <linux/buffer_head.h>
4037  #include <linux/bio.h>
4038 +#include <linux/vs_tag.h>
4039  
4040  #include "namei.h"
4041  #include "xattr.h"
4042 @@ -1052,6 +1053,7 @@ static struct dentry *ext3_lookup(struct
4043  
4044                 if (!inode)
4045                         return ERR_PTR(-EACCES);
4046 +               dx_propagate_tag(nd, inode);
4047         }
4048         return d_splice_alias(inode, dentry);
4049  }
4050 @@ -2443,6 +2445,7 @@ const struct inode_operations ext3_dir_i
4051         .removexattr    = generic_removexattr,
4052  #endif
4053         .permission     = ext3_permission,
4054 +       .sync_flags     = ext3_sync_flags,
4055  };
4056  
4057  const struct inode_operations ext3_special_inode_operations = {
4058 @@ -2454,4 +2457,5 @@ const struct inode_operations ext3_speci
4059         .removexattr    = generic_removexattr,
4060  #endif
4061         .permission     = ext3_permission,
4062 +       .sync_flags     = ext3_sync_flags,
4063  };
4064 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/super.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/super.c
4065 --- linux-2.6.22.10/fs/ext3/super.c     2007-07-09 13:19:23 +0200
4066 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/super.c   2007-06-15 02:37:03 +0200
4067 @@ -674,7 +674,7 @@ enum {
4068         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4069         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4070         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4071 -       Opt_grpquota
4072 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
4073  };
4074  
4075  static match_table_t tokens = {
4076 @@ -724,6 +724,10 @@ static match_table_t tokens = {
4077         {Opt_quota, "quota"},
4078         {Opt_usrquota, "usrquota"},
4079         {Opt_barrier, "barrier=%u"},
4080 +       {Opt_tag, "tag"},
4081 +       {Opt_notag, "notag"},
4082 +       {Opt_tagid, "tagid=%u"},
4083 +       {Opt_tag, "tagxid"},
4084         {Opt_err, NULL},
4085         {Opt_resize, "resize"},
4086  };
4087 @@ -817,6 +821,20 @@ static int parse_options (char *options,
4088                 case Opt_nouid32:
4089                         set_opt (sbi->s_mount_opt, NO_UID32);
4090                         break;
4091 +#ifndef CONFIG_TAGGING_NONE
4092 +               case Opt_tag:
4093 +                       set_opt (sbi->s_mount_opt, TAGGED);
4094 +                       break;
4095 +               case Opt_notag:
4096 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4097 +                       break;
4098 +#endif
4099 +#ifdef CONFIG_PROPAGATE
4100 +               case Opt_tagid:
4101 +                       /* use args[0] */
4102 +                       set_opt (sbi->s_mount_opt, TAGGED);
4103 +                       break;
4104 +#endif
4105                 case Opt_nocheck:
4106                         clear_opt (sbi->s_mount_opt, CHECK);
4107                         break;
4108 @@ -1487,6 +1505,9 @@ static int ext3_fill_super (struct super
4109                             NULL, 0))
4110                 goto failed_mount;
4111  
4112 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
4113 +               sb->s_flags |= MS_TAGGED;
4114 +
4115         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4116                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4117  
4118 @@ -2302,6 +2323,12 @@ static int ext3_remount (struct super_bl
4119  
4120         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
4121                 ext3_abort(sb, __FUNCTION__, "Abort forced by user");
4122 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
4123 +               !(sb->s_flags & MS_TAGGED)) {
4124 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
4125 +                       sb->s_id);
4126 +               return -EINVAL;
4127 +       }
4128  
4129         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4130                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4131 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/symlink.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/symlink.c
4132 --- linux-2.6.22.10/fs/ext3/symlink.c   2007-05-02 19:25:17 +0200
4133 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/symlink.c 2007-06-15 02:37:03 +0200
4134 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
4135         .listxattr      = ext3_listxattr,
4136         .removexattr    = generic_removexattr,
4137  #endif
4138 +       .sync_flags     = ext3_sync_flags,
4139  };
4140  
4141  const struct inode_operations ext3_fast_symlink_inode_operations = {
4142 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
4143         .listxattr      = ext3_listxattr,
4144         .removexattr    = generic_removexattr,
4145  #endif
4146 +       .sync_flags     = ext3_sync_flags,
4147  };
4148 diff -NurpP --minimal linux-2.6.22.10/fs/ext3/xattr.c linux-2.6.22.10-vs2.2.0.5/fs/ext3/xattr.c
4149 --- linux-2.6.22.10/fs/ext3/xattr.c     2007-05-02 19:25:17 +0200
4150 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext3/xattr.c   2007-06-15 02:37:03 +0200
4151 @@ -58,6 +58,7 @@
4152  #include <linux/mbcache.h>
4153  #include <linux/quotaops.h>
4154  #include <linux/rwsem.h>
4155 +#include <linux/vs_dlimit.h>
4156  #include "xattr.h"
4157  #include "acl.h"
4158  
4159 @@ -497,6 +498,7 @@ ext3_xattr_release_block(handle_t *handl
4160                 error = ext3_journal_dirty_metadata(handle, bh);
4161                 if (IS_SYNC(inode))
4162                         handle->h_sync = 1;
4163 +                       DLIMIT_FREE_BLOCK(inode, 1);
4164                 DQUOT_FREE_BLOCK(inode, 1);
4165                 ea_bdebug(bh, "refcount now=%d; releasing",
4166                           le32_to_cpu(BHDR(bh)->h_refcount));
4167 @@ -771,11 +773,14 @@ inserted:
4168                         if (new_bh == bs->bh)
4169                                 ea_bdebug(new_bh, "keeping");
4170                         else {
4171 +                               error = -ENOSPC;
4172 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4173 +                                       goto cleanup;
4174                                 /* The old block is released after updating
4175                                    the inode. */
4176                                 error = -EDQUOT;
4177                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4178 -                                       goto cleanup;
4179 +                                       goto cleanup_dlimit;
4180                                 error = ext3_journal_get_write_access(handle,
4181                                                                       new_bh);
4182                                 if (error)
4183 @@ -852,6 +857,8 @@ cleanup:
4184  
4185  cleanup_dquot:
4186         DQUOT_FREE_BLOCK(inode, 1);
4187 +cleanup_dlimit:
4188 +       DLIMIT_FREE_BLOCK(inode, 1);
4189         goto cleanup;
4190  
4191  bad_block:
4192 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/balloc.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/balloc.c
4193 --- linux-2.6.22.10/fs/ext4/balloc.c    2007-07-09 13:19:23 +0200
4194 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/balloc.c  2007-07-16 06:31:34 +0200
4195 @@ -19,6 +19,8 @@
4196  #include <linux/ext4_jbd2.h>
4197  #include <linux/quotaops.h>
4198  #include <linux/buffer_head.h>
4199 +#include <linux/vs_dlimit.h>
4200 +#include <linux/vs_tag.h>
4201  
4202  /*
4203   * balloc.c contains the blocks allocation and deallocation routines
4204 @@ -630,8 +632,10 @@ void ext4_free_blocks(handle_t *handle, 
4205                 return;
4206         }
4207         ext4_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
4208 -       if (dquot_freed_blocks)
4209 +       if (dquot_freed_blocks) {
4210 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
4211                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
4212 +       }
4213         return;
4214  }
4215  
4216 @@ -1370,18 +1374,33 @@ out:
4217   *
4218   * Check if filesystem has at least 1 free block available for allocation.
4219   */
4220 -static int ext4_has_free_blocks(struct ext4_sb_info *sbi)
4221 +static int ext4_has_free_blocks(struct super_block *sb)
4222  {
4223 +       struct ext4_sb_info *sbi = EXT4_SB(sb);
4224         ext4_fsblk_t free_blocks, root_blocks;
4225 +       int cond;
4226  
4227         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
4228         root_blocks = ext4_r_blocks_count(sbi->s_es);
4229 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
4230 +
4231 +       vxdprintk(VXD_CBIT(dlim, 3),
4232 +               "ext4_has_free_blocks(%p): free=%llu, root=%llu",
4233 +               sb, free_blocks, root_blocks);
4234 +
4235 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
4236 +
4237 +       cond = (free_blocks < root_blocks + 1 &&
4238 +               !capable(CAP_SYS_RESOURCE) &&
4239                 sbi->s_resuid != current->fsuid &&
4240 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
4241 -               return 0;
4242 -       }
4243 -       return 1;
4244 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
4245 +
4246 +       vxdprintk(VXD_CBIT(dlim, 3),
4247 +               "ext4_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
4248 +               sb, free_blocks, root_blocks,
4249 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
4250 +               sbi->s_resuid, current->fsuid, cond?0:1);
4251 +
4252 +       return (cond ? 0 : 1);
4253  }
4254  
4255  /**
4256 @@ -1398,7 +1417,7 @@ static int ext4_has_free_blocks(struct e
4257   */
4258  int ext4_should_retry_alloc(struct super_block *sb, int *retries)
4259  {
4260 -       if (!ext4_has_free_blocks(EXT4_SB(sb)) || (*retries)++ > 3)
4261 +       if (!ext4_has_free_blocks(sb) || (*retries)++ > 3)
4262                 return 0;
4263  
4264         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
4265 @@ -1461,6 +1480,8 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
4266                 *errp = -EDQUOT;
4267                 return 0;
4268         }
4269 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
4270 +           goto out_dlimit;
4271  
4272         sbi = EXT4_SB(sb);
4273         es = EXT4_SB(sb)->s_es;
4274 @@ -1477,7 +1498,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *h
4275         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
4276                 my_rsv = &block_i->rsv_window_node;
4277  
4278 -       if (!ext4_has_free_blocks(sbi)) {
4279 +       if (!ext4_has_free_blocks(sb)) {
4280                 *errp = -ENOSPC;
4281                 goto out;
4282         }
4283 @@ -1661,12 +1682,16 @@ allocated:
4284         *errp = 0;
4285         brelse(bitmap_bh);
4286         DQUOT_FREE_BLOCK(inode, *count-num);
4287 +       DLIMIT_FREE_BLOCK(inode, *count-num);
4288         *count = num;
4289         return ret_block;
4290  
4291  io_error:
4292         *errp = -EIO;
4293  out:
4294 +       if (!performed_allocation)
4295 +               DLIMIT_FREE_BLOCK(inode, *count);
4296 +out_dlimit:
4297         if (fatal) {
4298                 *errp = fatal;
4299                 ext4_std_error(sb, fatal);
4300 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/file.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/file.c
4301 --- linux-2.6.22.10/fs/ext4/file.c      2007-05-02 19:25:17 +0200
4302 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/file.c    2007-10-29 23:24:21 +0100
4303 @@ -135,5 +135,6 @@ const struct inode_operations ext4_file_
4304         .removexattr    = generic_removexattr,
4305  #endif
4306         .permission     = ext4_permission,
4307 +       .sync_flags     = ext4_sync_flags,
4308  };
4309  
4310 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/ialloc.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/ialloc.c
4311 --- linux-2.6.22.10/fs/ext4/ialloc.c    2006-11-30 21:19:20 +0100
4312 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/ialloc.c  2007-06-15 02:37:03 +0200
4313 @@ -24,6 +24,8 @@
4314  #include <linux/random.h>
4315  #include <linux/bitops.h>
4316  #include <linux/blkdev.h>
4317 +#include <linux/vs_dlimit.h>
4318 +#include <linux/vs_tag.h>
4319  #include <asm/byteorder.h>
4320  
4321  #include "xattr.h"
4322 @@ -127,6 +129,7 @@ void ext4_free_inode (handle_t *handle, 
4323         ext4_xattr_delete_inode(handle, inode);
4324         DQUOT_FREE_INODE(inode);
4325         DQUOT_DROP(inode);
4326 +       DLIMIT_FREE_INODE(inode);
4327  
4328         is_directory = S_ISDIR(inode->i_mode);
4329  
4330 @@ -448,6 +451,12 @@ struct inode *ext4_new_inode(handle_t *h
4331         inode = new_inode(sb);
4332         if (!inode)
4333                 return ERR_PTR(-ENOMEM);
4334 +
4335 +       inode->i_tag = dx_current_fstag(sb);
4336 +       if (DLIMIT_ALLOC_INODE(inode)) {
4337 +               err = -ENOSPC;
4338 +               goto out_dlimit;
4339 +       }
4340         ei = EXT4_I(inode);
4341  
4342         sbi = EXT4_SB(sb);
4343 @@ -569,7 +578,8 @@ got:
4344         ei->i_dir_start_lookup = 0;
4345         ei->i_disksize = 0;
4346  
4347 -       ei->i_flags = EXT4_I(dir)->i_flags & ~EXT4_INDEX_FL;
4348 +       ei->i_flags = EXT4_I(dir)->i_flags &
4349 +               ~(EXT4_INDEX_FL|EXT4_IUNLINK_FL|EXT4_BARRIER_FL);
4350         if (S_ISLNK(mode))
4351                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
4352         /* dirsync only applies to directories */
4353 @@ -635,6 +645,8 @@ got:
4354  fail:
4355         ext4_std_error(sb, err);
4356  out:
4357 +       DLIMIT_FREE_INODE(inode);
4358 +out_dlimit:
4359         iput(inode);
4360         ret = ERR_PTR(err);
4361  really_out:
4362 @@ -646,6 +658,7 @@ fail_free_drop:
4363  
4364  fail_drop:
4365         DQUOT_DROP(inode);
4366 +       DLIMIT_FREE_INODE(inode);
4367         inode->i_flags |= S_NOQUOTA;
4368         inode->i_nlink = 0;
4369         iput(inode);
4370 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/inode.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/inode.c
4371 --- linux-2.6.22.10/fs/ext4/inode.c     2007-07-09 13:19:23 +0200
4372 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/inode.c   2007-07-07 03:52:53 +0200
4373 @@ -36,6 +36,7 @@
4374  #include <linux/mpage.h>
4375  #include <linux/uio.h>
4376  #include <linux/bio.h>
4377 +#include <linux/vs_tag.h>
4378  #include "xattr.h"
4379  #include "acl.h"
4380  
4381 @@ -2244,7 +2245,7 @@ void ext4_truncate(struct inode *inode)
4382                 return;
4383         if (ext4_inode_is_fast_symlink(inode))
4384                 return;
4385 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4386 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4387                 return;
4388  
4389         /*
4390 @@ -2570,19 +2571,65 @@ void ext4_set_inode_flags(struct inode *
4391  {
4392         unsigned int flags = EXT4_I(inode)->i_flags;
4393  
4394 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4395 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
4396 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4397 +
4398 +       if (flags & EXT4_IMMUTABLE_FL)
4399 +               inode->i_flags |= S_IMMUTABLE;
4400 +       if (flags & EXT4_IUNLINK_FL)
4401 +               inode->i_flags |= S_IUNLINK;
4402 +       if (flags & EXT4_BARRIER_FL)
4403 +               inode->i_flags |= S_BARRIER;
4404 +
4405         if (flags & EXT4_SYNC_FL)
4406                 inode->i_flags |= S_SYNC;
4407         if (flags & EXT4_APPEND_FL)
4408                 inode->i_flags |= S_APPEND;
4409 -       if (flags & EXT4_IMMUTABLE_FL)
4410 -               inode->i_flags |= S_IMMUTABLE;
4411         if (flags & EXT4_NOATIME_FL)
4412                 inode->i_flags |= S_NOATIME;
4413         if (flags & EXT4_DIRSYNC_FL)
4414                 inode->i_flags |= S_DIRSYNC;
4415  }
4416  
4417 +int ext4_sync_flags(struct inode *inode)
4418 +{
4419 +       unsigned int oldflags, newflags;
4420 +       int err = 0;
4421 +
4422 +       oldflags = EXT4_I(inode)->i_flags;
4423 +       newflags = oldflags & ~(EXT4_IMMUTABLE_FL |
4424 +               EXT4_IUNLINK_FL | EXT4_BARRIER_FL);
4425 +
4426 +       if (IS_IMMUTABLE(inode))
4427 +               newflags |= EXT4_IMMUTABLE_FL;
4428 +       if (IS_IUNLINK(inode))
4429 +               newflags |= EXT4_IUNLINK_FL;
4430 +       if (IS_BARRIER(inode))
4431 +               newflags |= EXT4_BARRIER_FL;
4432 +
4433 +       if (oldflags ^ newflags) {
4434 +               handle_t *handle;
4435 +               struct ext4_iloc iloc;
4436 +
4437 +               handle = ext4_journal_start(inode, 1);
4438 +               if (IS_ERR(handle))
4439 +                       return PTR_ERR(handle);
4440 +               if (IS_SYNC(inode))
4441 +                       handle->h_sync = 1;
4442 +               err = ext4_reserve_inode_write(handle, inode, &iloc);
4443 +               if (err)
4444 +                       goto flags_err;
4445 +
4446 +               EXT4_I(inode)->i_flags = newflags;
4447 +               inode->i_ctime = CURRENT_TIME;
4448 +
4449 +               err = ext4_mark_iloc_dirty(handle, inode, &iloc);
4450 +       flags_err:
4451 +               ext4_journal_stop(handle);
4452 +       }
4453 +       return err;
4454 +}
4455 +
4456  void ext4_read_inode(struct inode * inode)
4457  {
4458         struct ext4_iloc iloc;
4459 @@ -2590,6 +2637,8 @@ void ext4_read_inode(struct inode * inod
4460         struct ext4_inode_info *ei = EXT4_I(inode);
4461         struct buffer_head *bh;
4462         int block;
4463 +       uid_t uid;
4464 +       gid_t gid;
4465  
4466  #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
4467         ei->i_acl = EXT4_ACL_NOT_CACHED;
4468 @@ -2602,12 +2651,17 @@ void ext4_read_inode(struct inode * inod
4469         bh = iloc.bh;
4470         raw_inode = ext4_raw_inode(&iloc);
4471         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
4472 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4473 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4474 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
4475 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
4476         if(!(test_opt (inode->i_sb, NO_UID32))) {
4477 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4478 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4479 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
4480 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
4481         }
4482 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
4483 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
4484 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
4485 +               le16_to_cpu(raw_inode->i_raw_tag));
4486 +
4487         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4488         inode->i_size = le32_to_cpu(raw_inode->i_size);
4489         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
4490 @@ -2737,6 +2791,8 @@ static int ext4_do_update_inode(handle_t
4491         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
4492         struct ext4_inode_info *ei = EXT4_I(inode);
4493         struct buffer_head *bh = iloc->bh;
4494 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
4495 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
4496         int err = 0, rc, block;
4497  
4498         /* For fields not not tracking in the in-memory inode,
4499 @@ -2746,29 +2802,32 @@ static int ext4_do_update_inode(handle_t
4500  
4501         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
4502         if(!(test_opt(inode->i_sb, NO_UID32))) {
4503 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
4504 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
4505 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
4506 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
4507  /*
4508   * Fix up interoperability with old kernels. Otherwise, old inodes get
4509   * re-used with the upper 16 bits of the uid/gid intact
4510   */
4511                 if(!ei->i_dtime) {
4512                         raw_inode->i_uid_high =
4513 -                               cpu_to_le16(high_16_bits(inode->i_uid));
4514 +                               cpu_to_le16(high_16_bits(uid));
4515                         raw_inode->i_gid_high =
4516 -                               cpu_to_le16(high_16_bits(inode->i_gid));
4517 +                               cpu_to_le16(high_16_bits(gid));
4518                 } else {
4519                         raw_inode->i_uid_high = 0;
4520                         raw_inode->i_gid_high = 0;
4521                 }
4522         } else {
4523                 raw_inode->i_uid_low =
4524 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
4525 +                       cpu_to_le16(fs_high2lowuid(uid));
4526                 raw_inode->i_gid_low =
4527 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
4528 +                       cpu_to_le16(fs_high2lowgid(gid));
4529                 raw_inode->i_uid_high = 0;
4530                 raw_inode->i_gid_high = 0;
4531         }
4532 +#ifdef CONFIG_TAGGING_INTERN
4533 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
4534 +#endif
4535         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
4536         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
4537         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
4538 @@ -2925,7 +2984,8 @@ int ext4_setattr(struct dentry *dentry, 
4539                 return error;
4540  
4541         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
4542 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
4543 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
4544 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
4545                 handle_t *handle;
4546  
4547                 /* (user+group)*(old+new) structure, inode write (sb,
4548 @@ -2947,6 +3007,8 @@ int ext4_setattr(struct dentry *dentry, 
4549                         inode->i_uid = attr->ia_uid;
4550                 if (attr->ia_valid & ATTR_GID)
4551                         inode->i_gid = attr->ia_gid;
4552 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
4553 +                       inode->i_tag = attr->ia_tag;
4554                 error = ext4_mark_inode_dirty(handle, inode);
4555                 ext4_journal_stop(handle);
4556         }
4557 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/ioctl.c
4558 --- linux-2.6.22.10/fs/ext4/ioctl.c     2007-02-06 03:01:18 +0100
4559 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/ioctl.c   2007-06-15 02:37:03 +0200
4560 @@ -8,6 +8,7 @@
4561   */
4562  
4563  #include <linux/fs.h>
4564 +#include <linux/mount.h>
4565  #include <linux/jbd2.h>
4566  #include <linux/capability.h>
4567  #include <linux/ext4_fs.h>
4568 @@ -15,6 +16,7 @@
4569  #include <linux/time.h>
4570  #include <linux/compat.h>
4571  #include <linux/smp_lock.h>
4572 +#include <linux/vs_tag.h>
4573  #include <asm/uaccess.h>
4574  
4575  int ext4_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
4576 @@ -37,7 +39,8 @@ int ext4_ioctl (struct inode * inode, st
4577                 unsigned int oldflags;
4578                 unsigned int jflag;
4579  
4580 -               if (IS_RDONLY(inode))
4581 +               if (IS_RDONLY(inode) ||
4582 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4583                         return -EROFS;
4584  
4585                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4586 @@ -61,7 +64,9 @@ int ext4_ioctl (struct inode * inode, st
4587                  *
4588                  * This test looks nicer. Thanks to Pauline Middelink
4589                  */
4590 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
4591 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
4592 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
4593 +                       EXT4_IMMUTABLE_FL | EXT4_IUNLINK_FL))) {
4594                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4595                                 mutex_unlock(&inode->i_mutex);
4596                                 return -EPERM;
4597 @@ -123,7 +128,8 @@ flags_err:
4598  
4599                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4600                         return -EPERM;
4601 -               if (IS_RDONLY(inode))
4602 +               if (IS_RDONLY(inode) ||
4603 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4604                         return -EROFS;
4605                 if (get_user(generation, (int __user *) arg))
4606                         return -EFAULT;
4607 @@ -177,7 +183,8 @@ flags_err:
4608                 if (!test_opt(inode->i_sb, RESERVATION) ||!S_ISREG(inode->i_mode))
4609                         return -ENOTTY;
4610  
4611 -               if (IS_RDONLY(inode))
4612 +               if (IS_RDONLY(inode) ||
4613 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4614                         return -EROFS;
4615  
4616                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4617 @@ -212,7 +219,8 @@ flags_err:
4618                 if (!capable(CAP_SYS_RESOURCE))
4619                         return -EPERM;
4620  
4621 -               if (IS_RDONLY(inode))
4622 +               if (IS_RDONLY(inode) ||
4623 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4624                         return -EROFS;
4625  
4626                 if (get_user(n_blocks_count, (__u32 __user *)arg))
4627 @@ -233,7 +241,8 @@ flags_err:
4628                 if (!capable(CAP_SYS_RESOURCE))
4629                         return -EPERM;
4630  
4631 -               if (IS_RDONLY(inode))
4632 +               if (IS_RDONLY(inode) ||
4633 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4634                         return -EROFS;
4635  
4636                 if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
4637 @@ -248,6 +257,39 @@ flags_err:
4638                 return err;
4639         }
4640  
4641 +#if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_TAGGING_NONE)
4642 +       case EXT4_IOC_SETTAG: {
4643 +               handle_t *handle;
4644 +               struct ext4_iloc iloc;
4645 +               int tag;
4646 +               int err;
4647 +
4648 +               /* fixme: if stealth, return -ENOTTY */
4649 +               if (!capable(CAP_CONTEXT))
4650 +                       return -EPERM;
4651 +               if (IS_RDONLY(inode))
4652 +                       return -EROFS;
4653 +               if (!(inode->i_sb->s_flags & MS_TAGGED))
4654 +                       return -ENOSYS;
4655 +               if (get_user(tag, (int __user *) arg))
4656 +                       return -EFAULT;
4657 +
4658 +               handle = ext4_journal_start(inode, 1);
4659 +               if (IS_ERR(handle))
4660 +                       return PTR_ERR(handle);
4661 +               err = ext4_reserve_inode_write(handle, inode, &iloc);
4662 +               if (err)
4663 +                       return err;
4664 +
4665 +               inode->i_tag = (tag & 0xFFFF);
4666 +               inode->i_ctime = CURRENT_TIME;
4667 +
4668 +               err = ext4_mark_iloc_dirty(handle, inode, &iloc);
4669 +               ext4_journal_stop(handle);
4670 +               return err;
4671 +       }
4672 +#endif
4673 +
4674         default:
4675                 return -ENOTTY;
4676         }
4677 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/namei.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/namei.c
4678 --- linux-2.6.22.10/fs/ext4/namei.c     2007-10-30 01:57:14 +0100
4679 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/namei.c   2007-10-01 15:25:35 +0200
4680 @@ -36,6 +36,7 @@
4681  #include <linux/quotaops.h>
4682  #include <linux/buffer_head.h>
4683  #include <linux/bio.h>
4684 +#include <linux/vs_tag.h>
4685  
4686  #include "namei.h"
4687  #include "xattr.h"
4688 @@ -1050,6 +1051,7 @@ static struct dentry *ext4_lookup(struct
4689  
4690                 if (!inode)
4691                         return ERR_PTR(-EACCES);
4692 +               dx_propagate_tag(nd, inode);
4693         }
4694         return d_splice_alias(inode, dentry);
4695  }
4696 @@ -2441,6 +2443,7 @@ const struct inode_operations ext4_dir_i
4697         .removexattr    = generic_removexattr,
4698  #endif
4699         .permission     = ext4_permission,
4700 +       .sync_flags     = ext4_sync_flags,
4701  };
4702  
4703  const struct inode_operations ext4_special_inode_operations = {
4704 @@ -2452,4 +2455,5 @@ const struct inode_operations ext4_speci
4705         .removexattr    = generic_removexattr,
4706  #endif
4707         .permission     = ext4_permission,
4708 +       .sync_flags     = ext4_sync_flags,
4709  };
4710 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/super.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/super.c
4711 --- linux-2.6.22.10/fs/ext4/super.c     2007-07-09 13:19:23 +0200
4712 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/super.c   2007-06-15 02:37:03 +0200
4713 @@ -725,7 +725,7 @@ enum {
4714         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
4715         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
4716         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
4717 -       Opt_grpquota, Opt_extents,
4718 +       Opt_grpquota, Opt_extents, Opt_tag, Opt_notag, Opt_tagid
4719  };
4720  
4721  static match_table_t tokens = {
4722 @@ -776,6 +776,10 @@ static match_table_t tokens = {
4723         {Opt_usrquota, "usrquota"},
4724         {Opt_barrier, "barrier=%u"},
4725         {Opt_extents, "extents"},
4726 +       {Opt_tag, "tag"},
4727 +       {Opt_notag, "notag"},
4728 +       {Opt_tagid, "tagid=%u"},
4729 +       {Opt_tag, "tagxid"},
4730         {Opt_err, NULL},
4731         {Opt_resize, "resize"},
4732  };
4733 @@ -869,6 +873,20 @@ static int parse_options (char *options,
4734                 case Opt_nouid32:
4735                         set_opt (sbi->s_mount_opt, NO_UID32);
4736                         break;
4737 +#ifndef CONFIG_TAGGING_NONE
4738 +               case Opt_tag:
4739 +                       set_opt (sbi->s_mount_opt, TAGGED);
4740 +                       break;
4741 +               case Opt_notag:
4742 +                       clear_opt (sbi->s_mount_opt, TAGGED);
4743 +                       break;
4744 +#endif
4745 +#ifdef CONFIG_PROPAGATE
4746 +               case Opt_tagid:
4747 +                       /* use args[0] */
4748 +                       set_opt (sbi->s_mount_opt, TAGGED);
4749 +                       break;
4750 +#endif
4751                 case Opt_nocheck:
4752                         clear_opt (sbi->s_mount_opt, CHECK);
4753                         break;
4754 @@ -1546,6 +1564,9 @@ static int ext4_fill_super (struct super
4755                             NULL, 0))
4756                 goto failed_mount;
4757  
4758 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
4759 +               sb->s_flags |= MS_TAGGED;
4760 +
4761         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4762                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4763  
4764 @@ -2377,6 +2398,12 @@ static int ext4_remount (struct super_bl
4765  
4766         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
4767                 ext4_abort(sb, __FUNCTION__, "Abort forced by user");
4768 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
4769 +               !(sb->s_flags & MS_TAGGED)) {
4770 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
4771 +                       sb->s_id);
4772 +               return -EINVAL;
4773 +       }
4774  
4775         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
4776                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
4777 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/symlink.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/symlink.c
4778 --- linux-2.6.22.10/fs/ext4/symlink.c   2007-05-02 19:25:17 +0200
4779 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/symlink.c 2007-06-15 02:37:03 +0200
4780 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
4781         .listxattr      = ext4_listxattr,
4782         .removexattr    = generic_removexattr,
4783  #endif
4784 +       .sync_flags     = ext4_sync_flags,
4785  };
4786  
4787  const struct inode_operations ext4_fast_symlink_inode_operations = {
4788 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
4789         .listxattr      = ext4_listxattr,
4790         .removexattr    = generic_removexattr,
4791  #endif
4792 +       .sync_flags     = ext4_sync_flags,
4793  };
4794 diff -NurpP --minimal linux-2.6.22.10/fs/ext4/xattr.c linux-2.6.22.10-vs2.2.0.5/fs/ext4/xattr.c
4795 --- linux-2.6.22.10/fs/ext4/xattr.c     2007-05-02 19:25:17 +0200
4796 +++ linux-2.6.22.10-vs2.2.0.5/fs/ext4/xattr.c   2007-06-15 02:37:03 +0200
4797 @@ -58,6 +58,7 @@
4798  #include <linux/mbcache.h>
4799  #include <linux/quotaops.h>
4800  #include <linux/rwsem.h>
4801 +#include <linux/vs_dlimit.h>
4802  #include "xattr.h"
4803  #include "acl.h"
4804  
4805 @@ -496,6 +497,7 @@ ext4_xattr_release_block(handle_t *handl
4806                 error = ext4_journal_dirty_metadata(handle, bh);
4807                 if (IS_SYNC(inode))
4808                         handle->h_sync = 1;
4809 +                       DLIMIT_FREE_BLOCK(inode, 1);
4810                 DQUOT_FREE_BLOCK(inode, 1);
4811                 ea_bdebug(bh, "refcount now=%d; releasing",
4812                           le32_to_cpu(BHDR(bh)->h_refcount));
4813 @@ -769,11 +771,14 @@ inserted:
4814                         if (new_bh == bs->bh)
4815                                 ea_bdebug(new_bh, "keeping");
4816                         else {
4817 +                               error = -ENOSPC;
4818 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
4819 +                                       goto cleanup;
4820                                 /* The old block is released after updating
4821                                    the inode. */
4822                                 error = -EDQUOT;
4823                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
4824 -                                       goto cleanup;
4825 +                                       goto cleanup_dlimit;
4826                                 error = ext4_journal_get_write_access(handle,
4827                                                                       new_bh);
4828                                 if (error)
4829 @@ -850,6 +855,8 @@ cleanup:
4830  
4831  cleanup_dquot:
4832         DQUOT_FREE_BLOCK(inode, 1);
4833 +cleanup_dlimit:
4834 +       DLIMIT_FREE_BLOCK(inode, 1);
4835         goto cleanup;
4836  
4837  bad_block:
4838 diff -NurpP --minimal linux-2.6.22.10/fs/fcntl.c linux-2.6.22.10-vs2.2.0.5/fs/fcntl.c
4839 --- linux-2.6.22.10/fs/fcntl.c  2007-02-06 03:01:18 +0100
4840 +++ linux-2.6.22.10-vs2.2.0.5/fs/fcntl.c        2007-06-15 02:37:03 +0200
4841 @@ -18,6 +18,7 @@
4842  #include <linux/ptrace.h>
4843  #include <linux/signal.h>
4844  #include <linux/rcupdate.h>
4845 +#include <linux/vs_limit.h>
4846  
4847  #include <asm/poll.h>
4848  #include <asm/siginfo.h>
4849 @@ -84,6 +85,8 @@ repeat:
4850         error = -EMFILE;
4851         if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
4852                 goto out;
4853 +       if (!vx_files_avail(1))
4854 +               goto out;
4855  
4856         error = expand_files(files, newfd);
4857         if (error < 0)
4858 @@ -124,6 +127,7 @@ static int dupfd(struct file *file, unsi
4859                 FD_SET(fd, fdt->open_fds);
4860                 FD_CLR(fd, fdt->close_on_exec);
4861                 spin_unlock(&files->file_lock);
4862 +               vx_openfd_inc(fd);
4863                 fd_install(fd, file);
4864         } else {
4865                 spin_unlock(&files->file_lock);
4866 @@ -176,6 +180,9 @@ asmlinkage long sys_dup2(unsigned int ol
4867  
4868         if (tofree)
4869                 filp_close(tofree, files);
4870 +       else
4871 +               vx_openfd_inc(newfd);   /* fd was unused */
4872 +
4873         err = newfd;
4874  out:
4875         return err;
4876 diff -NurpP --minimal linux-2.6.22.10/fs/file_table.c linux-2.6.22.10-vs2.2.0.5/fs/file_table.c
4877 --- linux-2.6.22.10/fs/file_table.c     2007-07-09 13:19:23 +0200
4878 +++ linux-2.6.22.10-vs2.2.0.5/fs/file_table.c   2007-06-15 02:37:03 +0200
4879 @@ -20,6 +20,8 @@
4880  #include <linux/fsnotify.h>
4881  #include <linux/sysctl.h>
4882  #include <linux/percpu_counter.h>
4883 +#include <linux/vs_limit.h>
4884 +#include <linux/vs_context.h>
4885  
4886  #include <asm/atomic.h>
4887  
4888 @@ -119,6 +121,8 @@ struct file *get_empty_filp(void)
4889         f->f_gid = tsk->fsgid;
4890         eventpoll_init_file(f);
4891         /* f->f_version: 0 */
4892 +       f->f_xid = vx_current_xid();
4893 +       vx_files_inc(f);
4894         return f;
4895  
4896  over:
4897 @@ -174,6 +178,8 @@ void fastcall __fput(struct file *file)
4898         if (file->f_mode & FMODE_WRITE)
4899                 put_write_access(inode);
4900         put_pid(file->f_owner.pid);
4901 +       vx_files_dec(file);
4902 +       file->f_xid = 0;
4903         file_kill(file);
4904         file->f_path.dentry = NULL;
4905         file->f_path.mnt = NULL;
4906 @@ -239,6 +245,8 @@ void put_filp(struct file *file)
4907  {
4908         if (atomic_dec_and_test(&file->f_count)) {
4909                 security_file_free(file);
4910 +               vx_files_dec(file);
4911 +               file->f_xid = 0;
4912                 file_kill(file);
4913                 file_free(file);
4914         }
4915 diff -NurpP --minimal linux-2.6.22.10/fs/hfsplus/ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/hfsplus/ioctl.c
4916 --- linux-2.6.22.10/fs/hfsplus/ioctl.c  2006-11-30 21:19:25 +0100
4917 +++ linux-2.6.22.10-vs2.2.0.5/fs/hfsplus/ioctl.c        2007-06-15 02:37:03 +0200
4918 @@ -16,6 +16,7 @@
4919  #include <linux/fs.h>
4920  #include <linux/sched.h>
4921  #include <linux/xattr.h>
4922 +#include <linux/mount.h>
4923  #include <asm/uaccess.h>
4924  #include "hfsplus_fs.h"
4925  
4926 @@ -35,7 +36,8 @@ int hfsplus_ioctl(struct inode *inode, s
4927                         flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
4928                 return put_user(flags, (int __user *)arg);
4929         case HFSPLUS_IOC_EXT2_SETFLAGS: {
4930 -               if (IS_RDONLY(inode))
4931 +               if (IS_RDONLY(inode) ||
4932 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
4933                         return -EROFS;
4934  
4935                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
4936 diff -NurpP --minimal linux-2.6.22.10/fs/inode.c linux-2.6.22.10-vs2.2.0.5/fs/inode.c
4937 --- linux-2.6.22.10/fs/inode.c  2007-07-09 13:19:24 +0200
4938 +++ linux-2.6.22.10-vs2.2.0.5/fs/inode.c        2007-06-15 02:37:03 +0200
4939 @@ -115,6 +115,9 @@ static struct inode *alloc_inode(struct 
4940                 struct address_space * const mapping = &inode->i_data;
4941  
4942                 inode->i_sb = sb;
4943 +
4944 +               /* essential because of inode slab reuse */
4945 +               inode->i_tag = 0;
4946                 inode->i_blkbits = sb->s_blocksize_bits;
4947                 inode->i_flags = 0;
4948                 atomic_set(&inode->i_count, 1);
4949 @@ -231,6 +234,8 @@ void __iget(struct inode * inode)
4950         inodes_stat.nr_unused--;
4951  }
4952  
4953 +EXPORT_SYMBOL_GPL(__iget);
4954 +
4955  /**
4956   * clear_inode - clear an inode
4957   * @inode: inode to clear
4958 diff -NurpP --minimal linux-2.6.22.10/fs/ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/ioctl.c
4959 --- linux-2.6.22.10/fs/ioctl.c  2007-07-09 13:19:24 +0200
4960 +++ linux-2.6.22.10-vs2.2.0.5/fs/ioctl.c        2007-06-15 03:12:40 +0200
4961 @@ -13,10 +13,19 @@
4962  #include <linux/security.h>
4963  #include <linux/module.h>
4964  #include <linux/kallsyms.h>
4965 +#include <linux/proc_fs.h>
4966 +#include <linux/vserver/inode.h>
4967 +#include <linux/vs_tag.h>
4968  
4969  #include <asm/uaccess.h>
4970  #include <asm/ioctls.h>
4971  
4972 +
4973 +#ifdef CONFIG_VSERVER_LEGACY
4974 +extern int vx_proc_ioctl(struct inode *, struct file *,
4975 +       unsigned int, unsigned long);
4976 +#endif
4977 +
4978  static long do_ioctl(struct file *filp, unsigned int cmd,
4979                 unsigned long arg)
4980  {
4981 @@ -152,6 +161,48 @@ int vfs_ioctl(struct file *filp, unsigne
4982                         else
4983                                 error = -ENOTTY;
4984                         break;
4985 +#ifdef CONFIG_VSERVER_LEGACY
4986 +#ifndef CONFIG_TAGGING_NONE
4987 +               case FIOC_GETTAG: {
4988 +                       struct inode *inode = filp->f_dentry->d_inode;
4989 +
4990 +                       /* fixme: if stealth, return -ENOTTY */
4991 +                       error = -EPERM;
4992 +                       if (capable(CAP_CONTEXT))
4993 +                               error = put_user(inode->i_tag, (int __user *) arg);
4994 +                       break;
4995 +               }
4996 +               case FIOC_SETTAG: {
4997 +                       struct inode *inode = filp->f_dentry->d_inode;
4998 +                       int tag;
4999 +
5000 +                       /* fixme: if stealth, return -ENOTTY */
5001 +                       error = -EPERM;
5002 +                       if (!capable(CAP_CONTEXT))
5003 +                               break;
5004 +                       error = -EROFS;
5005 +                       if (IS_RDONLY(inode))
5006 +                               break;
5007 +                       error = -ENOSYS;
5008 +                       if (!(inode->i_sb->s_flags & MS_TAGGED))
5009 +                               break;
5010 +                       error = -EFAULT;
5011 +                       if (get_user(tag, (int __user *) arg))
5012 +                               break;
5013 +                       error = 0;
5014 +                       inode->i_tag = (tag & 0xFFFF);
5015 +                       inode->i_ctime = CURRENT_TIME;
5016 +                       mark_inode_dirty(inode);
5017 +                       break;
5018 +               }
5019 +#endif
5020 +               case FIOC_GETXFLG:
5021 +               case FIOC_SETXFLG:
5022 +                       error = -ENOTTY;
5023 +                       if (filp->f_dentry->d_inode->i_sb->s_magic == PROC_SUPER_MAGIC)
5024 +                               error = vx_proc_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
5025 +                       break;
5026 +#endif
5027                 default:
5028                         if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
5029                                 error = file_ioctl(filp, cmd, arg);
5030 diff -NurpP --minimal linux-2.6.22.10/fs/ioprio.c linux-2.6.22.10-vs2.2.0.5/fs/ioprio.c
5031 --- linux-2.6.22.10/fs/ioprio.c 2007-05-02 19:25:18 +0200
5032 +++ linux-2.6.22.10-vs2.2.0.5/fs/ioprio.c       2007-06-15 02:37:03 +0200
5033 @@ -25,6 +25,7 @@
5034  #include <linux/capability.h>
5035  #include <linux/syscalls.h>
5036  #include <linux/security.h>
5037 +#include <linux/vs_base.h>
5038  
5039  static int set_task_ioprio(struct task_struct *task, int ioprio)
5040  {
5041 @@ -103,6 +104,8 @@ asmlinkage long sys_ioprio_set(int which
5042                         else
5043                                 pgrp = find_pid(who);
5044                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
5045 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5046 +                                       continue;
5047                                 ret = set_task_ioprio(p, ioprio);
5048                                 if (ret)
5049                                         break;
5050 @@ -112,7 +115,7 @@ asmlinkage long sys_ioprio_set(int which
5051                         if (!who)
5052                                 user = current->user;
5053                         else
5054 -                               user = find_user(who);
5055 +                               user = find_user(vx_current_xid(), who);
5056  
5057                         if (!user)
5058                                 break;
5059 @@ -190,6 +193,8 @@ asmlinkage long sys_ioprio_get(int which
5060                         else
5061                                 pgrp = find_pid(who);
5062                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
5063 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
5064 +                                       continue;
5065                                 tmpio = get_task_ioprio(p);
5066                                 if (tmpio < 0)
5067                                         continue;
5068 @@ -203,7 +208,7 @@ asmlinkage long sys_ioprio_get(int which
5069                         if (!who)
5070                                 user = current->user;
5071                         else
5072 -                               user = find_user(who);
5073 +                               user = find_user(vx_current_xid(), who);
5074  
5075                         if (!user)
5076                                 break;
5077 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/acl.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/acl.c
5078 --- linux-2.6.22.10/fs/jfs/acl.c        2006-11-30 21:19:25 +0100
5079 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/acl.c      2007-06-15 02:37:03 +0200
5080 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
5081                 return rc;
5082  
5083         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
5084 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
5085 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
5086 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
5087                 if (DQUOT_TRANSFER(inode, iattr))
5088                         return -EDQUOT;
5089         }
5090 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/file.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/file.c
5091 --- linux-2.6.22.10/fs/jfs/file.c       2007-05-02 19:25:18 +0200
5092 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/file.c     2007-10-29 23:24:21 +0100
5093 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
5094         .setattr        = jfs_setattr,
5095         .permission     = jfs_permission,
5096  #endif
5097 +       .sync_flags     = jfs_sync_flags,
5098  };
5099  
5100  const struct file_operations jfs_file_operations = {
5101 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/inode.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/inode.c
5102 --- linux-2.6.22.10/fs/jfs/inode.c      2007-07-09 13:19:26 +0200
5103 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/inode.c    2007-06-15 02:37:03 +0200
5104 @@ -22,6 +22,7 @@
5105  #include <linux/buffer_head.h>
5106  #include <linux/pagemap.h>
5107  #include <linux/quotaops.h>
5108 +#include <linux/vs_dlimit.h>
5109  #include "jfs_incore.h"
5110  #include "jfs_inode.h"
5111  #include "jfs_filsys.h"
5112 @@ -143,6 +144,7 @@ void jfs_delete_inode(struct inode *inod
5113                 DQUOT_INIT(inode);
5114                 DQUOT_FREE_INODE(inode);
5115                 DQUOT_DROP(inode);
5116 +               DLIMIT_FREE_INODE(inode);
5117         }
5118  
5119         clear_inode(inode);
5120 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/ioctl.c
5121 --- linux-2.6.22.10/fs/jfs/ioctl.c      2007-07-09 13:19:27 +0200
5122 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/ioctl.c    2007-06-15 02:37:03 +0200
5123 @@ -10,6 +10,7 @@
5124  #include <linux/capability.h>
5125  #include <linux/time.h>
5126  #include <linux/sched.h>
5127 +#include <linux/mount.h>
5128  #include <asm/current.h>
5129  #include <asm/uaccess.h>
5130  
5131 @@ -66,7 +67,8 @@ int jfs_ioctl(struct inode * inode, stru
5132         case JFS_IOC_SETFLAGS: {
5133                 unsigned int oldflags;
5134  
5135 -               if (IS_RDONLY(inode))
5136 +               if (IS_RDONLY(inode) ||
5137 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
5138                         return -EROFS;
5139  
5140                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
5141 @@ -87,8 +89,8 @@ int jfs_ioctl(struct inode * inode, stru
5142                  * the relevant capability.
5143                  */
5144                 if ((oldflags & JFS_IMMUTABLE_FL) ||
5145 -                       ((flags ^ oldflags) &
5146 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
5147 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
5148 +                       JFS_IMMUTABLE_FL | JFS_IUNLINK_FL))) {
5149                         if (!capable(CAP_LINUX_IMMUTABLE))
5150                                 return -EPERM;
5151                 }
5152 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_dinode.h linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_dinode.h
5153 --- linux-2.6.22.10/fs/jfs/jfs_dinode.h 2006-11-30 21:19:25 +0100
5154 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_dinode.h       2007-06-15 02:37:03 +0200
5155 @@ -162,9 +162,12 @@ struct dinode {
5156  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
5157  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
5158  
5159 -#define JFS_FL_USER_VISIBLE    0x03F80000
5160 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
5161 +#define JFS_IUNLINK_FL         0x08000000 /* Immutable unlink */
5162 +
5163 +#define JFS_FL_USER_VISIBLE    0x0FF80000
5164  #define JFS_FL_USER_MODIFIABLE 0x03F80000
5165 -#define JFS_FL_INHERIT         0x03C80000
5166 +#define JFS_FL_INHERIT         0x0BC80000
5167  
5168  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
5169  #define JFS_IOC_GETFLAGS       _IOR('f', 1, long)
5170 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_dtree.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_dtree.c
5171 --- linux-2.6.22.10/fs/jfs/jfs_dtree.c  2007-02-06 03:01:24 +0100
5172 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_dtree.c        2007-06-15 02:37:03 +0200
5173 @@ -102,6 +102,7 @@
5174  
5175  #include <linux/fs.h>
5176  #include <linux/quotaops.h>
5177 +#include <linux/vs_dlimit.h>
5178  #include "jfs_incore.h"
5179  #include "jfs_superblock.h"
5180  #include "jfs_filsys.h"
5181 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
5182                  */
5183                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
5184                         goto clean_up;
5185 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
5186 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
5187 -                       goto clean_up;
5188 -               }
5189 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
5190 +                       goto clean_up_dquot;
5191 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
5192 +                       goto clean_up_dlimit;
5193  
5194                 /*
5195                  * Save the table, we're going to overwrite it with the
5196 @@ -479,6 +480,12 @@ static u32 add_index(tid_t tid, struct i
5197  
5198         return index;
5199  
5200 +      clean_up_dlimit:
5201 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
5202 +
5203 +      clean_up_dquot:
5204 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
5205 +
5206        clean_up:
5207  
5208         jfs_ip->next_index--;
5209 @@ -952,6 +959,7 @@ static int dtSplitUp(tid_t tid,
5210         struct tlock *tlck;
5211         struct lv *lv;
5212         int quota_allocation = 0;
5213 +       int dlimit_allocation = 0;
5214  
5215         /* get split page */
5216         smp = split->mp;
5217 @@ -1036,6 +1044,12 @@ static int dtSplitUp(tid_t tid,
5218                 }
5219                 quota_allocation += n;
5220  
5221 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
5222 +                       rc = -ENOSPC;
5223 +                       goto extendOut;
5224 +               }
5225 +               dlimit_allocation += n;
5226 +
5227                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
5228                                     (s64) n, &nxaddr)))
5229                         goto extendOut;
5230 @@ -1309,6 +1323,9 @@ static int dtSplitUp(tid_t tid,
5231        freeKeyName:
5232         kfree(key.name);
5233  
5234 +       /* Rollback dlimit allocation */
5235 +       if (rc && dlimit_allocation)
5236 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
5237         /* Rollback quota allocation */
5238         if (rc && quota_allocation)
5239                 DQUOT_FREE_BLOCK(ip, quota_allocation);
5240 @@ -1376,6 +1393,12 @@ static int dtSplitPage(tid_t tid, struct
5241                 release_metapage(rmp);
5242                 return -EDQUOT;
5243         }
5244 +       /* Allocate blocks to dlimit. */
5245 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5246 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5247 +               release_metapage(rmp);
5248 +               return -ENOSPC;
5249 +       }
5250  
5251         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
5252  
5253 @@ -1926,6 +1949,12 @@ static int dtSplitRoot(tid_t tid,
5254                 release_metapage(rmp);
5255                 return -EDQUOT;
5256         }
5257 +       /* Allocate blocks to dlimit. */
5258 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5259 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5260 +               release_metapage(rmp);
5261 +               return -ENOSPC;
5262 +       }
5263  
5264         BT_MARK_DIRTY(rmp, ip);
5265         /*
5266 @@ -2292,6 +2321,8 @@ static int dtDeleteUp(tid_t tid, struct 
5267  
5268         xlen = lengthPXD(&fp->header.self);
5269  
5270 +       /* Free dlimit allocation. */
5271 +       DLIMIT_FREE_BLOCK(ip, xlen);
5272         /* Free quota allocation. */
5273         DQUOT_FREE_BLOCK(ip, xlen);
5274  
5275 @@ -2368,6 +2399,8 @@ static int dtDeleteUp(tid_t tid, struct 
5276  
5277                                 xlen = lengthPXD(&p->header.self);
5278  
5279 +                               /* Free dlimit allocation */
5280 +                               DLIMIT_FREE_BLOCK(ip, xlen);
5281                                 /* Free quota allocation */
5282                                 DQUOT_FREE_BLOCK(ip, xlen);
5283  
5284 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_extent.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_extent.c
5285 --- linux-2.6.22.10/fs/jfs/jfs_extent.c 2006-11-30 21:19:25 +0100
5286 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_extent.c       2007-06-15 02:37:03 +0200
5287 @@ -18,6 +18,7 @@
5288  
5289  #include <linux/fs.h>
5290  #include <linux/quotaops.h>
5291 +#include <linux/vs_dlimit.h>
5292  #include "jfs_incore.h"
5293  #include "jfs_inode.h"
5294  #include "jfs_superblock.h"
5295 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
5296                 return -EDQUOT;
5297         }
5298  
5299 +       /* Allocate blocks to dlimit. */
5300 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
5301 +               DQUOT_FREE_BLOCK(ip, nxlen);
5302 +               dbFree(ip, nxaddr, (s64) nxlen);
5303 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
5304 +               return -ENOSPC;
5305 +       }
5306 +
5307         /* determine the value of the extent flag */
5308         xflag = abnr ? XAD_NOTRECORDED : 0;
5309  
5310 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
5311          */
5312         if (rc) {
5313                 dbFree(ip, nxaddr, nxlen);
5314 +               DLIMIT_FREE_BLOCK(ip, nxlen);
5315                 DQUOT_FREE_BLOCK(ip, nxlen);
5316                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
5317                 return (rc);
5318 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
5319                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
5320                 return -EDQUOT;
5321         }
5322 +       /* Allocate blocks to dlimit. */
5323 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
5324 +               DQUOT_FREE_BLOCK(ip, nxlen);
5325 +               dbFree(ip, nxaddr, (s64) nxlen);
5326 +               up(&JFS_IP(ip)->commit_sem);
5327 +               return -ENOSPC;
5328 +       }
5329  
5330         delta = nxlen - xlen;
5331  
5332 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
5333                 /* extend the extent */
5334                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
5335                         dbFree(ip, xaddr + xlen, delta);
5336 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
5337                         DQUOT_FREE_BLOCK(ip, nxlen);
5338                         goto exit;
5339                 }
5340 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
5341                  */
5342                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
5343                         dbFree(ip, nxaddr, nxlen);
5344 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
5345                         DQUOT_FREE_BLOCK(ip, nxlen);
5346                         goto exit;
5347                 }
5348 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_filsys.h linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_filsys.h
5349 --- linux-2.6.22.10/fs/jfs/jfs_filsys.h 2007-02-06 03:01:24 +0100
5350 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_filsys.h       2007-06-15 02:37:03 +0200
5351 @@ -264,6 +264,7 @@
5352  #define JFS_NAME_MAX   255
5353  #define JFS_PATH_MAX   BPSIZE
5354  
5355 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
5356  
5357  /*
5358   *     file system state (superblock state)
5359 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_imap.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_imap.c
5360 --- linux-2.6.22.10/fs/jfs/jfs_imap.c   2007-07-09 13:19:27 +0200
5361 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_imap.c 2007-06-15 03:01:50 +0200
5362 @@ -45,6 +45,7 @@
5363  #include <linux/buffer_head.h>
5364  #include <linux/pagemap.h>
5365  #include <linux/quotaops.h>
5366 +#include <linux/vs_tag.h>
5367  
5368  #include "jfs_incore.h"
5369  #include "jfs_inode.h"
5370 @@ -3075,6 +3076,8 @@ static int copy_from_dinode(struct dinod
5371  {
5372         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
5373         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
5374 +       uid_t uid;
5375 +       gid_t gid;
5376  
5377         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
5378         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
5379 @@ -3095,14 +3098,18 @@ static int copy_from_dinode(struct dinod
5380         }
5381         ip->i_nlink = le32_to_cpu(dip->di_nlink);
5382  
5383 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
5384 +       uid = le32_to_cpu(dip->di_uid);
5385 +       gid = le32_to_cpu(dip->di_gid);
5386 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
5387 +
5388 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
5389         if (sbi->uid == -1)
5390                 ip->i_uid = jfs_ip->saved_uid;
5391         else {
5392                 ip->i_uid = sbi->uid;
5393         }
5394  
5395 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
5396 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
5397         if (sbi->gid == -1)
5398                 ip->i_gid = jfs_ip->saved_gid;
5399         else {
5400 @@ -3167,14 +3174,12 @@ static void copy_to_dinode(struct dinode
5401         dip->di_size = cpu_to_le64(ip->i_size);
5402         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
5403         dip->di_nlink = cpu_to_le32(ip->i_nlink);
5404 -       if (sbi->uid == -1)
5405 -               dip->di_uid = cpu_to_le32(ip->i_uid);
5406 -       else
5407 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
5408 -       if (sbi->gid == -1)
5409 -               dip->di_gid = cpu_to_le32(ip->i_gid);
5410 -       else
5411 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
5412 +
5413 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
5414 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
5415 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
5416 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
5417 +
5418         jfs_get_inode_flags(jfs_ip);
5419         /*
5420          * mode2 is only needed for storing the higher order bits.
5421 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_inode.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_inode.c
5422 --- linux-2.6.22.10/fs/jfs/jfs_inode.c  2007-07-09 13:19:27 +0200
5423 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_inode.c        2007-07-19 08:09:20 +0200
5424 @@ -18,6 +18,8 @@
5425  
5426  #include <linux/fs.h>
5427  #include <linux/quotaops.h>
5428 +#include <linux/vs_dlimit.h>
5429 +#include <linux/vs_tag.h>
5430  #include "jfs_incore.h"
5431  #include "jfs_inode.h"
5432  #include "jfs_filsys.h"
5433 @@ -30,19 +32,47 @@ void jfs_set_inode_flags(struct inode *i
5434  {
5435         unsigned int flags = JFS_IP(inode)->mode2;
5436  
5437 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
5438 -               S_NOATIME | S_DIRSYNC | S_SYNC);
5439 +       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
5440 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5441  
5442         if (flags & JFS_IMMUTABLE_FL)
5443                 inode->i_flags |= S_IMMUTABLE;
5444 +       if (flags & JFS_IUNLINK_FL)
5445 +               inode->i_flags |= S_IUNLINK;
5446 +       if (flags & JFS_BARRIER_FL)
5447 +               inode->i_flags |= S_BARRIER;
5448 +
5449 +       if (flags & JFS_SYNC_FL)
5450 +               inode->i_flags |= S_SYNC;
5451         if (flags & JFS_APPEND_FL)
5452                 inode->i_flags |= S_APPEND;
5453         if (flags & JFS_NOATIME_FL)
5454                 inode->i_flags |= S_NOATIME;
5455         if (flags & JFS_DIRSYNC_FL)
5456                 inode->i_flags |= S_DIRSYNC;
5457 -       if (flags & JFS_SYNC_FL)
5458 -               inode->i_flags |= S_SYNC;
5459 +}
5460 +
5461 +int jfs_sync_flags(struct inode *inode)
5462 +{
5463 +       unsigned int oldflags, newflags;
5464 +
5465 +       oldflags = JFS_IP(inode)->mode2;
5466 +       newflags = oldflags & ~(JFS_IMMUTABLE_FL |
5467 +               JFS_IUNLINK_FL | JFS_BARRIER_FL);
5468 +
5469 +       if (IS_IMMUTABLE(inode))
5470 +               newflags |= JFS_IMMUTABLE_FL;
5471 +       if (IS_IUNLINK(inode))
5472 +               newflags |= JFS_IUNLINK_FL;
5473 +       if (IS_BARRIER(inode))
5474 +               newflags |= JFS_BARRIER_FL;
5475 +
5476 +       if (oldflags ^ newflags) {
5477 +               JFS_IP(inode)->mode2 = newflags;
5478 +               inode->i_ctime = CURRENT_TIME;
5479 +               mark_inode_dirty(inode);
5480 +       }
5481 +       return 0;
5482  }
5483  
5484  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
5485 @@ -108,10 +138,17 @@ struct inode *ialloc(struct inode *paren
5486         jfs_inode->saved_uid = inode->i_uid;
5487         jfs_inode->saved_gid = inode->i_gid;
5488  
5489 +       inode->i_tag = dx_current_fstag(sb);
5490 +       if (DLIMIT_ALLOC_INODE(inode)) {
5491 +               iput(inode);
5492 +               return ERR_PTR(-ENOSPC);
5493 +       }
5494 +
5495         /*
5496          * Allocate inode to quota.
5497          */
5498         if (DQUOT_ALLOC_INODE(inode)) {
5499 +               DLIMIT_FREE_INODE(inode);
5500                 DQUOT_DROP(inode);
5501                 inode->i_flags |= S_NOQUOTA;
5502                 inode->i_nlink = 0;
5503 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_inode.h linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_inode.h
5504 --- linux-2.6.22.10/fs/jfs/jfs_inode.h  2007-07-09 13:19:27 +0200
5505 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_inode.h        2007-06-15 03:02:28 +0200
5506 @@ -33,6 +33,7 @@ extern void jfs_free_zero_link(struct in
5507  extern struct dentry *jfs_get_parent(struct dentry *dentry);
5508  extern void jfs_get_inode_flags(struct jfs_inode_info *);
5509  extern void jfs_set_inode_flags(struct inode *);
5510 +extern int jfs_sync_flags(struct inode *);
5511  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
5512  
5513  extern const struct address_space_operations jfs_aops;
5514 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/jfs_xtree.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_xtree.c
5515 --- linux-2.6.22.10/fs/jfs/jfs_xtree.c  2007-05-02 19:25:18 +0200
5516 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/jfs_xtree.c        2007-06-15 02:37:03 +0200
5517 @@ -21,6 +21,7 @@
5518  
5519  #include <linux/fs.h>
5520  #include <linux/quotaops.h>
5521 +#include <linux/vs_dlimit.h>
5522  #include "jfs_incore.h"
5523  #include "jfs_filsys.h"
5524  #include "jfs_metapage.h"
5525 @@ -846,7 +847,12 @@ int xtInsert(tid_t tid,            /* transaction 
5526                         hint = 0;
5527                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
5528                         goto out;
5529 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
5530 +                       DQUOT_FREE_BLOCK(ip, xlen);
5531 +                       goto out;
5532 +               }
5533                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
5534 +                       DLIMIT_FREE_BLOCK(ip, xlen);
5535                         DQUOT_FREE_BLOCK(ip, xlen);
5536                         goto out;
5537                 }
5538 @@ -876,6 +882,7 @@ int xtInsert(tid_t tid,             /* transaction 
5539                         /* undo data extent allocation */
5540                         if (*xaddrp == 0) {
5541                                 dbFree(ip, xaddr, (s64) xlen);
5542 +                               DLIMIT_FREE_BLOCK(ip, xlen);
5543                                 DQUOT_FREE_BLOCK(ip, xlen);
5544                         }
5545                         return rc;
5546 @@ -1236,6 +1243,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
5547         struct tlock *tlck;
5548         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
5549         int quota_allocation = 0;
5550 +       int dlimit_allocation = 0;
5551  
5552         smp = split->mp;
5553         sp = XT_PAGE(ip, smp);
5554 @@ -1255,6 +1263,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
5555  
5556         quota_allocation += lengthPXD(pxd);
5557  
5558 +       /* Allocate blocks to dlimit. */
5559 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5560 +              rc = -ENOSPC;
5561 +              goto clean_up;
5562 +       }
5563 +       dlimit_allocation += lengthPXD(pxd);
5564 +
5565         /*
5566          * allocate the new right page for the split
5567          */
5568 @@ -1456,6 +1471,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
5569  
5570        clean_up:
5571  
5572 +       /* Rollback dlimit allocation. */
5573 +       if (dlimit_allocation)
5574 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
5575         /* Rollback quota allocation. */
5576         if (quota_allocation)
5577                 DQUOT_FREE_BLOCK(ip, quota_allocation);
5578 @@ -1520,6 +1538,12 @@ xtSplitRoot(tid_t tid,
5579                 release_metapage(rmp);
5580                 return -EDQUOT;
5581         }
5582 +       /* Allocate blocks to dlimit. */
5583 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
5584 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
5585 +               release_metapage(rmp);
5586 +               return -ENOSPC;
5587 +       }
5588  
5589         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
5590  
5591 @@ -3951,6 +3975,8 @@ s64 xtTruncate(tid_t tid, struct inode *
5592         else
5593                 ip->i_size = newsize;
5594  
5595 +       /* update dlimit allocation to reflect freed blocks */
5596 +       DLIMIT_FREE_BLOCK(ip, nfreed);
5597         /* update quota allocation to reflect freed blocks */
5598         DQUOT_FREE_BLOCK(ip, nfreed);
5599  
5600 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/namei.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/namei.c
5601 --- linux-2.6.22.10/fs/jfs/namei.c      2007-05-02 19:25:18 +0200
5602 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/namei.c    2007-06-15 02:37:03 +0200
5603 @@ -20,6 +20,7 @@
5604  #include <linux/fs.h>
5605  #include <linux/ctype.h>
5606  #include <linux/quotaops.h>
5607 +#include <linux/vs_tag.h>
5608  #include "jfs_incore.h"
5609  #include "jfs_superblock.h"
5610  #include "jfs_inode.h"
5611 @@ -1469,6 +1470,7 @@ static struct dentry *jfs_lookup(struct 
5612                 return ERR_PTR(-EACCES);
5613         }
5614  
5615 +       dx_propagate_tag(nd, ip);
5616         dentry = d_splice_alias(ip, dentry);
5617  
5618         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
5619 @@ -1521,6 +1523,7 @@ const struct inode_operations jfs_dir_in
5620         .setattr        = jfs_setattr,
5621         .permission     = jfs_permission,
5622  #endif
5623 +       .sync_flags     = jfs_sync_flags,
5624  };
5625  
5626  const struct file_operations jfs_dir_operations = {
5627 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/super.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/super.c
5628 --- linux-2.6.22.10/fs/jfs/super.c      2007-07-09 13:19:27 +0200
5629 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/super.c    2007-06-15 02:37:03 +0200
5630 @@ -194,7 +194,8 @@ static void jfs_put_super(struct super_b
5631  enum {
5632         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
5633         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
5634 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
5635 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
5636 +       Opt_tag, Opt_notag, Opt_tagid
5637  };
5638  
5639  static match_table_t tokens = {
5640 @@ -204,6 +205,10 @@ static match_table_t tokens = {
5641         {Opt_resize, "resize=%u"},
5642         {Opt_resize_nosize, "resize"},
5643         {Opt_errors, "errors=%s"},
5644 +       {Opt_tag, "tag"},
5645 +       {Opt_notag, "notag"},
5646 +       {Opt_tagid, "tagid=%u"},
5647 +       {Opt_tag, "tagxid"},
5648         {Opt_ignore, "noquota"},
5649         {Opt_ignore, "quota"},
5650         {Opt_usrquota, "usrquota"},
5651 @@ -338,6 +343,20 @@ static int parse_options(char *options, 
5652                         }
5653                         break;
5654                 }
5655 +#ifndef CONFIG_TAGGING_NONE
5656 +               case Opt_tag:
5657 +                       *flag |= JFS_TAGGED;
5658 +                       break;
5659 +               case Opt_notag:
5660 +                       *flag &= JFS_TAGGED;
5661 +                       break;
5662 +#endif
5663 +#ifdef CONFIG_PROPAGATE
5664 +               case Opt_tagid:
5665 +                       /* use args[0] */
5666 +                       *flag |= JFS_TAGGED;
5667 +                       break;
5668 +#endif
5669                 default:
5670                         printk("jfs: Unrecognized mount option \"%s\" "
5671                                         " or missing value\n", p);
5672 @@ -368,6 +387,13 @@ static int jfs_remount(struct super_bloc
5673         if (!parse_options(data, sb, &newLVSize, &flag)) {
5674                 return -EINVAL;
5675         }
5676 +
5677 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
5678 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
5679 +                       sb->s_id);
5680 +               return -EINVAL;
5681 +       }
5682 +
5683         if (newLVSize) {
5684                 if (sb->s_flags & MS_RDONLY) {
5685                         printk(KERN_ERR
5686 @@ -439,6 +465,9 @@ static int jfs_fill_super(struct super_b
5687  #ifdef CONFIG_JFS_POSIX_ACL
5688         sb->s_flags |= MS_POSIXACL;
5689  #endif
5690 +       /* map mount option tagxid */
5691 +       if (sbi->flag & JFS_TAGGED)
5692 +               sb->s_flags |= MS_TAGGED;
5693  
5694         if (newLVSize) {
5695                 printk(KERN_ERR "resize option for remount only\n");
5696 diff -NurpP --minimal linux-2.6.22.10/fs/jfs/xattr.c linux-2.6.22.10-vs2.2.0.5/fs/jfs/xattr.c
5697 --- linux-2.6.22.10/fs/jfs/xattr.c      2006-11-30 21:19:26 +0100
5698 +++ linux-2.6.22.10-vs2.2.0.5/fs/jfs/xattr.c    2007-06-15 02:37:03 +0200
5699 @@ -23,6 +23,7 @@
5700  #include <linux/posix_acl_xattr.h>
5701  #include <linux/quotaops.h>
5702  #include <linux/security.h>
5703 +#include <linux/vs_dlimit.h>
5704  #include "jfs_incore.h"
5705  #include "jfs_superblock.h"
5706  #include "jfs_dmap.h"
5707 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
5708         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
5709                 return -EDQUOT;
5710         }
5711 +       /* Allocate new blocks to dlimit. */
5712 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
5713 +               DQUOT_FREE_BLOCK(ip, nblocks);
5714 +               return -ENOSPC;
5715 +       }
5716  
5717         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
5718         if (rc) {
5719 +               /*Rollback dlimit allocation. */
5720 +               DLIMIT_FREE_BLOCK(ip, nblocks);
5721                 /*Rollback quota allocation. */
5722                 DQUOT_FREE_BLOCK(ip, nblocks);
5723                 return rc;
5724 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
5725  
5726        failed:
5727         /* Rollback quota allocation. */
5728 +       DLIMIT_FREE_BLOCK(ip, nblocks);
5729 +       /* Rollback quota allocation. */
5730         DQUOT_FREE_BLOCK(ip, nblocks);
5731  
5732         dbFree(ip, blkno, nblocks);
5733 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
5734         s64 blkno;
5735         int rc;
5736         int quota_allocation = 0;
5737 +       int dlimit_allocation = 0;
5738  
5739         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
5740         if (ji->ea.flag == 0)
5741 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
5742  
5743                 quota_allocation = blocks_needed;
5744  
5745 +               /* Allocate new blocks to dlimit. */
5746 +               rc = -ENOSPC;
5747 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
5748 +                       goto clean_up;
5749 +               dlimit_allocation = blocks_needed;
5750 +
5751                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
5752                              &blkno);
5753                 if (rc)
5754 @@ -599,6 +616,9 @@ static int ea_get(struct inode *inode, s
5755         return ea_size;
5756  
5757        clean_up:
5758 +       /* Rollback dlimit allocation */
5759 +       if (dlimit_allocation)
5760 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
5761         /* Rollback quota allocation */
5762         if (quota_allocation)
5763                 DQUOT_FREE_BLOCK(inode, quota_allocation);
5764 @@ -675,8 +695,10 @@ static int ea_put(tid_t tid, struct inod
5765         }
5766  
5767         /* If old blocks exist, they must be removed from quota allocation. */
5768 -       if (old_blocks)
5769 +       if (old_blocks) {
5770 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
5771                 DQUOT_FREE_BLOCK(inode, old_blocks);
5772 +       }
5773  
5774         inode->i_ctime = CURRENT_TIME;
5775  
5776 diff -NurpP --minimal linux-2.6.22.10/fs/libfs.c linux-2.6.22.10-vs2.2.0.5/fs/libfs.c
5777 --- linux-2.6.22.10/fs/libfs.c  2007-07-09 13:19:27 +0200
5778 +++ linux-2.6.22.10-vs2.2.0.5/fs/libfs.c        2007-06-15 02:37:03 +0200
5779 @@ -124,7 +124,8 @@ static inline unsigned char dt_type(stru
5780   * both impossible due to the lock on directory.
5781   */
5782  
5783 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
5784 +static inline int do_dcache_readdir_filter(struct file *filp,
5785 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
5786  {
5787         struct dentry *dentry = filp->f_path.dentry;
5788         struct dentry *cursor = filp->private_data;
5789 @@ -157,6 +158,8 @@ int dcache_readdir(struct file * filp, v
5790                                 next = list_entry(p, struct dentry, d_u.d_child);
5791                                 if (d_unhashed(next) || !next->d_inode)
5792                                         continue;
5793 +                               if (filter && !filter(next))
5794 +                                       continue;
5795  
5796                                 spin_unlock(&dcache_lock);
5797                                 if (filldir(dirent, next->d_name.name, 
5798 @@ -175,6 +178,18 @@ int dcache_readdir(struct file * filp, v
5799         return 0;
5800  }
5801  
5802 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
5803 +{
5804 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
5805 +}
5806 +
5807 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
5808 +       int (*filter)(struct dentry *))
5809 +{
5810 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
5811 +}
5812 +
5813 +
5814  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
5815  {
5816         return -EISDIR;
5817 @@ -640,6 +655,7 @@ EXPORT_SYMBOL(dcache_dir_close);
5818  EXPORT_SYMBOL(dcache_dir_lseek);
5819  EXPORT_SYMBOL(dcache_dir_open);
5820  EXPORT_SYMBOL(dcache_readdir);
5821 +EXPORT_SYMBOL(dcache_readdir_filter);
5822  EXPORT_SYMBOL(generic_read_dir);
5823  EXPORT_SYMBOL(get_sb_pseudo);
5824  EXPORT_SYMBOL(simple_commit_write);
5825 diff -NurpP --minimal linux-2.6.22.10/fs/locks.c linux-2.6.22.10-vs2.2.0.5/fs/locks.c
5826 --- linux-2.6.22.10/fs/locks.c  2007-10-30 01:57:14 +0100
5827 +++ linux-2.6.22.10-vs2.2.0.5/fs/locks.c        2007-10-01 15:26:40 +0200
5828 @@ -125,6 +125,8 @@
5829  #include <linux/syscalls.h>
5830  #include <linux/time.h>
5831  #include <linux/rcupdate.h>
5832 +#include <linux/vs_base.h>
5833 +#include <linux/vs_limit.h>
5834  
5835  #include <asm/semaphore.h>
5836  #include <asm/uaccess.h>
5837 @@ -147,6 +149,8 @@ static struct kmem_cache *filelock_cache
5838  /* Allocate an empty lock structure. */
5839  static struct file_lock *locks_alloc_lock(void)
5840  {
5841 +       if (!vx_locks_avail(1))
5842 +               return NULL;
5843         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
5844  }
5845  
5846 @@ -172,6 +176,7 @@ static void locks_free_lock(struct file_
5847         BUG_ON(!list_empty(&fl->fl_block));
5848         BUG_ON(!list_empty(&fl->fl_link));
5849  
5850 +       vx_locks_dec(fl);
5851         locks_release_private(fl);
5852         kmem_cache_free(filelock_cache, fl);
5853  }
5854 @@ -191,6 +196,7 @@ void locks_init_lock(struct file_lock *f
5855         fl->fl_start = fl->fl_end = 0;
5856         fl->fl_ops = NULL;
5857         fl->fl_lmops = NULL;
5858 +       fl->fl_xid = -1;
5859  }
5860  
5861  EXPORT_SYMBOL(locks_init_lock);
5862 @@ -244,6 +250,7 @@ void locks_copy_lock(struct file_lock *n
5863         new->fl_file = fl->fl_file;
5864         new->fl_ops = fl->fl_ops;
5865         new->fl_lmops = fl->fl_lmops;
5866 +       new->fl_xid = fl->fl_xid;
5867  
5868         locks_copy_private(new, fl);
5869  }
5870 @@ -282,6 +289,11 @@ static int flock_make_lock(struct file *
5871         fl->fl_flags = FL_FLOCK;
5872         fl->fl_type = type;
5873         fl->fl_end = OFFSET_MAX;
5874 +
5875 +       vxd_assert(filp->f_xid == vx_current_xid(),
5876 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5877 +       fl->fl_xid = filp->f_xid;
5878 +       vx_locks_inc(fl);
5879         
5880         *lock = fl;
5881         return 0;
5882 @@ -447,6 +459,7 @@ static int lease_init(struct file *filp,
5883  
5884         fl->fl_owner = current->files;
5885         fl->fl_pid = current->tgid;
5886 +       fl->fl_xid = vx_current_xid();
5887  
5888         fl->fl_file = filp;
5889         fl->fl_flags = FL_LEASE;
5890 @@ -466,6 +479,11 @@ static int lease_alloc(struct file *filp
5891         if (fl == NULL)
5892                 goto out;
5893  
5894 +       fl->fl_xid = vx_current_xid();
5895 +       if (filp)
5896 +               vxd_assert(filp->f_xid == fl->fl_xid,
5897 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
5898 +       vx_locks_inc(fl);
5899         error = lease_init(filp, type, fl);
5900         if (error) {
5901                 locks_free_lock(fl);
5902 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
5903         if (found)
5904                 cond_resched();
5905  
5906 +       new_fl->fl_xid = -1;
5907  find_conflict:
5908         for_each_lock(inode, before) {
5909                 struct file_lock *fl = *before;
5910 @@ -787,6 +806,7 @@ find_conflict:
5911                 goto out;
5912         locks_copy_lock(new_fl, request);
5913         locks_insert_lock(before, new_fl);
5914 +       vx_locks_inc(new_fl);
5915         new_fl = NULL;
5916         error = 0;
5917  
5918 @@ -797,7 +817,8 @@ out:
5919         return error;
5920  }
5921  
5922 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
5923 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
5924 +       struct file_lock *conflock, xid_t xid)
5925  {
5926         struct file_lock *fl;
5927         struct file_lock *new_fl = NULL;
5928 @@ -807,6 +828,8 @@ static int __posix_lock_file(struct inod
5929         struct file_lock **before;
5930         int error, added = 0;
5931  
5932 +       vxd_assert(xid == vx_current_xid(),
5933 +               "xid(%d) == current(%d)", xid, vx_current_xid());
5934         /*
5935          * We may need two file_lock structures for this operation,
5936          * so we get them in advance to avoid races.
5937 @@ -817,7 +840,11 @@ static int __posix_lock_file(struct inod
5938             (request->fl_type != F_UNLCK ||
5939              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
5940                 new_fl = locks_alloc_lock();
5941 +               new_fl->fl_xid = xid;
5942 +               vx_locks_inc(new_fl);
5943                 new_fl2 = locks_alloc_lock();
5944 +               new_fl2->fl_xid = xid;
5945 +               vx_locks_inc(new_fl2);
5946         }
5947  
5948         lock_kernel();
5949 @@ -1016,7 +1043,8 @@ static int __posix_lock_file(struct inod
5950  int posix_lock_file(struct file *filp, struct file_lock *fl,
5951                         struct file_lock *conflock)
5952  {
5953 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
5954 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
5955 +               fl, conflock, filp->f_xid);
5956  }
5957  EXPORT_SYMBOL(posix_lock_file);
5958  
5959 @@ -1106,7 +1134,7 @@ int locks_mandatory_area(int read_write,
5960         fl.fl_end = offset + count - 1;
5961  
5962         for (;;) {
5963 -               error = __posix_lock_file(inode, &fl, NULL);
5964 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
5965                 if (error != -EAGAIN)
5966                         break;
5967                 if (!(fl.fl_flags & FL_SLEEP))
5968 @@ -1410,8 +1438,8 @@ static int __setlease(struct file *filp,
5969                 goto out;
5970  
5971         locks_copy_lock(fl, lease);
5972 -
5973         locks_insert_lock(before, fl);
5974 +       vx_locks_inc(fl);
5975  
5976         *flp = fl;
5977         error = 0;
5978 @@ -1738,6 +1766,11 @@ int fcntl_setlk(unsigned int fd, struct 
5979         if (file_lock == NULL)
5980                 return -ENOLCK;
5981  
5982 +       vxd_assert(filp->f_xid == vx_current_xid(),
5983 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5984 +       file_lock->fl_xid = filp->f_xid;
5985 +       vx_locks_inc(file_lock);
5986 +
5987         /*
5988          * This might block, so we do it before checking the inode.
5989          */
5990 @@ -1864,6 +1897,11 @@ int fcntl_setlk64(unsigned int fd, struc
5991         if (file_lock == NULL)
5992                 return -ENOLCK;
5993  
5994 +       vxd_assert(filp->f_xid == vx_current_xid(),
5995 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
5996 +       file_lock->fl_xid = filp->f_xid;
5997 +       vx_locks_inc(file_lock);
5998 +
5999         /*
6000          * This might block, so we do it before checking the inode.
6001          */
6002 @@ -2168,6 +2206,10 @@ int get_locks_status(char *buffer, char 
6003         list_for_each(tmp, &file_lock_list) {
6004                 struct list_head *btmp;
6005                 struct file_lock *fl = list_entry(tmp, struct file_lock, fl_link);
6006 +
6007 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
6008 +                       continue;
6009 +
6010                 lock_get_status(q, fl, ++i, "");
6011                 move_lock_status(&q, &pos, offset);
6012  
6013 diff -NurpP --minimal linux-2.6.22.10/fs/namei.c linux-2.6.22.10-vs2.2.0.5/fs/namei.c
6014 --- linux-2.6.22.10/fs/namei.c  2007-07-09 13:19:27 +0200
6015 +++ linux-2.6.22.10-vs2.2.0.5/fs/namei.c        2007-10-30 02:31:28 +0100
6016 @@ -31,6 +31,12 @@
6017  #include <linux/file.h>
6018  #include <linux/fcntl.h>
6019  #include <linux/namei.h>
6020 +#include <linux/proc_fs.h>
6021 +#include <linux/vserver/inode.h>
6022 +#include <linux/vs_base.h>
6023 +#include <linux/vs_tag.h>
6024 +#include <linux/vs_cowbl.h>
6025 +#include <linux/vs_context.h>
6026  #include <asm/namei.h>
6027  #include <asm/uaccess.h>
6028  
6029 @@ -224,6 +230,29 @@ int generic_permission(struct inode *ino
6030         return -EACCES;
6031  }
6032  
6033 +static inline int dx_barrier(struct inode *inode)
6034 +{
6035 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN)) {
6036 +               vxwprintk_task(1, "did hit the barrier.");
6037 +               return 1;
6038 +       }
6039 +       return 0;
6040 +}
6041 +
6042 +static inline int dx_permission(struct inode *inode, int mask, struct nameidata *nd)
6043 +{
6044 +       if (dx_barrier(inode))
6045 +               return -EACCES;
6046 +       if (inode->i_tag == 0)
6047 +               return 0;
6048 +       if (dx_check(inode->i_tag, DX_ADMIN|DX_WATCH|DX_IDENT))
6049 +               return 0;
6050 +
6051 +       vxwprintk_task(1, "denied access to %p[#%d,%lu] »%s«.",
6052 +               inode, inode->i_tag, inode->i_ino, vxd_cond_path(nd));
6053 +       return -EACCES;
6054 +}
6055 +
6056  int permission(struct inode *inode, int mask, struct nameidata *nd)
6057  {
6058         umode_t mode = inode->i_mode;
6059 @@ -234,14 +263,14 @@ int permission(struct inode *inode, int 
6060                 /*
6061                  * Nobody gets write access to a read-only fs.
6062                  */
6063 -               if (IS_RDONLY(inode) &&
6064 +               if ((IS_RDONLY(inode) || (nd && MNT_IS_RDONLY(nd->mnt))) &&
6065                     (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
6066                         return -EROFS;
6067  
6068                 /*
6069                  * Nobody gets write access to an immutable file.
6070                  */
6071 -               if (IS_IMMUTABLE(inode))
6072 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
6073                         return -EACCES;
6074         }
6075  
6076 @@ -257,6 +286,8 @@ int permission(struct inode *inode, int 
6077  
6078         /* Ordinary permission routines do not understand MAY_APPEND. */
6079         submask = mask & ~MAY_APPEND;
6080 +       if ((retval = dx_permission(inode, mask, nd)))
6081 +               return retval;
6082         if (inode->i_op && inode->i_op->permission)
6083                 retval = inode->i_op->permission(inode, submask, nd);
6084         else
6085 @@ -432,6 +463,8 @@ static int exec_permission_lite(struct i
6086  {
6087         umode_t mode = inode->i_mode;
6088  
6089 +       if (dx_barrier(inode))
6090 +               return -EACCES;
6091         if (inode->i_op && inode->i_op->permission)
6092                 return -EAGAIN;
6093  
6094 @@ -732,7 +765,8 @@ static __always_inline void follow_dotdo
6095                 if (nd->dentry == fs->root &&
6096                     nd->mnt == fs->rootmnt) {
6097                          read_unlock(&fs->lock);
6098 -                       break;
6099 +                       /* for sane '/' avoid follow_mount() */
6100 +                       return;
6101                 }
6102                  read_unlock(&fs->lock);
6103                 spin_lock(&dcache_lock);
6104 @@ -769,16 +803,33 @@ static int do_lookup(struct nameidata *n
6105  {
6106         struct vfsmount *mnt = nd->mnt;
6107         struct dentry *dentry = __d_lookup(nd->dentry, name);
6108 +       struct inode *inode;
6109  
6110         if (!dentry)
6111                 goto need_lookup;
6112         if (dentry->d_op && dentry->d_op->d_revalidate)
6113                 goto need_revalidate;
6114 +       inode = dentry->d_inode;
6115 +       if (!inode)
6116 +               goto done;
6117 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
6118 +               struct proc_dir_entry *de = PDE(inode);
6119 +
6120 +               if (de && !vx_hide_check(0, de->vx_flags))
6121 +                       goto hidden;
6122 +       }
6123 +       if (!dx_check(inode->i_tag, DX_WATCH|DX_ADMIN|DX_HOSTID|DX_IDENT))
6124 +               goto hidden;
6125  done:
6126         path->mnt = mnt;
6127         path->dentry = dentry;
6128         __follow_mount(path);
6129         return 0;
6130 +hidden:
6131 +       vxwprintk_task(1, "did lookup hidden %p[#%d,%lu] »%s«.",
6132 +               inode, inode->i_tag, inode->i_ino, vxd_path(dentry, mnt));
6133 +       dput(dentry);
6134 +       return -ENOENT;
6135  
6136  need_lookup:
6137         dentry = real_lookup(nd->dentry, name, nd);
6138 @@ -1399,7 +1450,8 @@ static inline int check_sticky(struct in
6139   * 10. We don't allow removal of NFS sillyrenamed files; it's handled by
6140   *     nfs_async_unlink().
6141   */
6142 -static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
6143 +static int may_delete(struct inode *dir, struct dentry *victim,
6144 +       int isdir, struct nameidata *nd)
6145  {
6146         int error;
6147  
6148 @@ -1409,13 +1461,13 @@ static int may_delete(struct inode *dir,
6149         BUG_ON(victim->d_parent->d_inode != dir);
6150         audit_inode_child(victim->d_name.name, victim->d_inode, dir);
6151  
6152 -       error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
6153 +       error = permission(dir,MAY_WRITE | MAY_EXEC, nd);
6154         if (error)
6155                 return error;
6156         if (IS_APPEND(dir))
6157                 return -EPERM;
6158         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
6159 -           IS_IMMUTABLE(victim->d_inode))
6160 +               IS_IXORUNLINK(victim->d_inode))
6161                 return -EPERM;
6162         if (isdir) {
6163                 if (!S_ISDIR(victim->d_inode->i_mode))
6164 @@ -1546,6 +1598,14 @@ int may_open(struct nameidata *nd, int a
6165         if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
6166                 return -EISDIR;
6167  
6168 +#ifdef CONFIG_VSERVER_COWBL
6169 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
6170 +               if (IS_COW_LINK(inode))
6171 +                       return -EMLINK;
6172 +               inode->i_flags &= ~(S_IUNLINK|S_IMMUTABLE);
6173 +               mark_inode_dirty(inode);
6174 +       }
6175 +#endif
6176         error = vfs_permission(nd, acc_mode);
6177         if (error)
6178                 return error;
6179 @@ -1562,7 +1622,8 @@ int may_open(struct nameidata *nd, int a
6180                         return -EACCES;
6181  
6182                 flag &= ~O_TRUNC;
6183 -       } else if (IS_RDONLY(inode) && (flag & FMODE_WRITE))
6184 +       } else if ((IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
6185 +               && (flag & FMODE_WRITE))
6186                 return -EROFS;
6187         /*
6188          * An append-only file must be opened in append mode for writing.
6189 @@ -1650,6 +1711,11 @@ int open_namei(int dfd, const char *path
6190         struct dentry *dir;
6191         int count = 0;
6192  
6193 +#ifdef CONFIG_VSERVER_COWBL
6194 +       int rflag = flag;
6195 +       int rmode = mode;
6196 +restart:
6197 +#endif
6198         acc_mode = ACC_MODE(flag);
6199  
6200         /* O_TRUNC implies we need access checks for write permissions */
6201 @@ -1743,6 +1809,22 @@ do_last:
6202                 goto exit;
6203  ok:
6204         error = may_open(nd, acc_mode, flag);
6205 +#ifdef CONFIG_VSERVER_COWBL
6206 +       if (error == -EMLINK) {
6207 +               struct dentry *dentry;
6208 +               dentry = cow_break_link(pathname);
6209 +               if (IS_ERR(dentry)) {
6210 +                       error = PTR_ERR(dentry);
6211 +                       goto exit;
6212 +               }
6213 +               dput(dentry);
6214 +               release_open_intent(nd);
6215 +               path_release(nd);
6216 +               flag = rflag;
6217 +               mode = rmode;
6218 +               goto restart;
6219 +       }
6220 +#endif
6221         if (error)
6222                 goto exit;
6223         return 0;
6224 @@ -1854,9 +1936,10 @@ fail:
6225  }
6226  EXPORT_SYMBOL_GPL(lookup_create);
6227  
6228 -int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
6229 +int vfs_mknod(struct inode *dir, struct dentry *dentry,
6230 +       int mode, dev_t dev, struct nameidata *nd)
6231  {
6232 -       int error = may_create(dir, dentry, NULL);
6233 +       int error = may_create(dir, dentry, nd);
6234  
6235         if (error)
6236                 return error;
6237 @@ -1906,11 +1989,12 @@ asmlinkage long sys_mknodat(int dfd, con
6238                         error = vfs_create(nd.dentry->d_inode,dentry,mode,&nd);
6239                         break;
6240                 case S_IFCHR: case S_IFBLK:
6241 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,
6242 -                                       new_decode_dev(dev));
6243 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6244 +                                       new_decode_dev(dev), &nd);
6245                         break;
6246                 case S_IFIFO: case S_IFSOCK:
6247 -                       error = vfs_mknod(nd.dentry->d_inode,dentry,mode,0);
6248 +                       error = vfs_mknod(nd.dentry->d_inode, dentry, mode,
6249 +                                       0, &nd);
6250                         break;
6251                 case S_IFDIR:
6252                         error = -EPERM;
6253 @@ -1933,9 +2017,10 @@ asmlinkage long sys_mknod(const char __u
6254         return sys_mknodat(AT_FDCWD, filename, mode, dev);
6255  }
6256  
6257 -int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
6258 +int vfs_mkdir(struct inode *dir, struct dentry *dentry,
6259 +       int mode, struct nameidata *nd)
6260  {
6261 -       int error = may_create(dir, dentry, NULL);
6262 +       int error = may_create(dir, dentry, nd);
6263  
6264         if (error)
6265                 return error;
6266 @@ -1977,7 +2062,7 @@ asmlinkage long sys_mkdirat(int dfd, con
6267  
6268         if (!IS_POSIXACL(nd.dentry->d_inode))
6269                 mode &= ~current->fs->umask;
6270 -       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode);
6271 +       error = vfs_mkdir(nd.dentry->d_inode, dentry, mode, &nd);
6272         dput(dentry);
6273  out_unlock:
6274         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6275 @@ -2020,9 +2105,10 @@ void dentry_unhash(struct dentry *dentry
6276         spin_unlock(&dcache_lock);
6277  }
6278  
6279 -int vfs_rmdir(struct inode *dir, struct dentry *dentry)
6280 +int vfs_rmdir(struct inode *dir, struct dentry *dentry,
6281 +       struct nameidata *nd)
6282  {
6283 -       int error = may_delete(dir, dentry, 1);
6284 +       int error = may_delete(dir, dentry, 1, nd);
6285  
6286         if (error)
6287                 return error;
6288 @@ -2084,7 +2170,7 @@ static long do_rmdir(int dfd, const char
6289         error = PTR_ERR(dentry);
6290         if (IS_ERR(dentry))
6291                 goto exit2;
6292 -       error = vfs_rmdir(nd.dentry->d_inode, dentry);
6293 +       error = vfs_rmdir(nd.dentry->d_inode, dentry, &nd);
6294         dput(dentry);
6295  exit2:
6296         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6297 @@ -2100,9 +2186,10 @@ asmlinkage long sys_rmdir(const char __u
6298         return do_rmdir(AT_FDCWD, pathname);
6299  }
6300  
6301 -int vfs_unlink(struct inode *dir, struct dentry *dentry)
6302 +int vfs_unlink(struct inode *dir, struct dentry *dentry,
6303 +       struct nameidata *nd)
6304  {
6305 -       int error = may_delete(dir, dentry, 0);
6306 +       int error = may_delete(dir, dentry, 0, nd);
6307  
6308         if (error)
6309                 return error;
6310 @@ -2164,7 +2251,7 @@ static long do_unlinkat(int dfd, const c
6311                 inode = dentry->d_inode;
6312                 if (inode)
6313                         atomic_inc(&inode->i_count);
6314 -               error = vfs_unlink(nd.dentry->d_inode, dentry);
6315 +               error = vfs_unlink(nd.dentry->d_inode, dentry, &nd);
6316         exit2:
6317                 dput(dentry);
6318         }
6319 @@ -2199,9 +2286,10 @@ asmlinkage long sys_unlink(const char __
6320         return do_unlinkat(AT_FDCWD, pathname);
6321  }
6322  
6323 -int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname, int mode)
6324 +int vfs_symlink(struct inode *dir, struct dentry *dentry,
6325 +       const char *oldname, int mode, struct nameidata *nd)
6326  {
6327 -       int error = may_create(dir, dentry, NULL);
6328 +       int error = may_create(dir, dentry, nd);
6329  
6330         if (error)
6331                 return error;
6332 @@ -2245,7 +2333,7 @@ asmlinkage long sys_symlinkat(const char
6333         if (IS_ERR(dentry))
6334                 goto out_unlock;
6335  
6336 -       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO);
6337 +       error = vfs_symlink(nd.dentry->d_inode, dentry, from, S_IALLUGO, &nd);
6338         dput(dentry);
6339  out_unlock:
6340         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6341 @@ -2262,7 +2350,8 @@ asmlinkage long sys_symlink(const char _
6342         return sys_symlinkat(oldname, AT_FDCWD, newname);
6343  }
6344  
6345 -int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry)
6346 +int vfs_link(struct dentry *old_dentry, struct inode *dir,
6347 +       struct dentry *new_dentry, struct nameidata *nd)
6348  {
6349         struct inode *inode = old_dentry->d_inode;
6350         int error;
6351 @@ -2270,7 +2359,7 @@ int vfs_link(struct dentry *old_dentry, 
6352         if (!inode)
6353                 return -ENOENT;
6354  
6355 -       error = may_create(dir, new_dentry, NULL);
6356 +       error = may_create(dir, new_dentry, nd);
6357         if (error)
6358                 return error;
6359  
6360 @@ -2280,7 +2369,7 @@ int vfs_link(struct dentry *old_dentry, 
6361         /*
6362          * A link to an append-only or immutable file cannot be created.
6363          */
6364 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
6365 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
6366                 return -EPERM;
6367         if (!dir->i_op || !dir->i_op->link)
6368                 return -EPERM;
6369 @@ -2340,7 +2429,7 @@ asmlinkage long sys_linkat(int olddfd, c
6370         error = PTR_ERR(new_dentry);
6371         if (IS_ERR(new_dentry))
6372                 goto out_unlock;
6373 -       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry);
6374 +       error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry, &nd);
6375         dput(new_dentry);
6376  out_unlock:
6377         mutex_unlock(&nd.dentry->d_inode->i_mutex);
6378 @@ -2472,14 +2561,14 @@ int vfs_rename(struct inode *old_dir, st
6379         if (old_dentry->d_inode == new_dentry->d_inode)
6380                 return 0;
6381   
6382 -       error = may_delete(old_dir, old_dentry, is_dir);
6383 +       error = may_delete(old_dir, old_dentry, is_dir, NULL);
6384         if (error)
6385                 return error;
6386  
6387         if (!new_dentry->d_inode)
6388                 error = may_create(new_dir, new_dentry, NULL);
6389         else
6390 -               error = may_delete(new_dir, new_dentry, is_dir);
6391 +               error = may_delete(new_dir, new_dentry, is_dir, NULL);
6392         if (error)
6393                 return error;
6394  
6395 @@ -2557,6 +2646,9 @@ static int do_rename(int olddfd, const c
6396         error = -EINVAL;
6397         if (old_dentry == trap)
6398                 goto exit4;
6399 +       error = -EROFS;
6400 +       if (MNT_IS_RDONLY(newnd.mnt))
6401 +               goto exit4;
6402         new_dentry = lookup_hash(&newnd);
6403         error = PTR_ERR(new_dentry);
6404         if (IS_ERR(new_dentry))
6405 @@ -2650,6 +2742,217 @@ int vfs_follow_link(struct nameidata *nd
6406         return __vfs_follow_link(nd, link);
6407  }
6408  
6409 +
6410 +#ifdef CONFIG_VSERVER_COWBL
6411 +
6412 +#include <linux/file.h>
6413 +
6414 +static inline
6415 +long do_cow_splice(struct file *in, struct file *out, size_t len)
6416 +{
6417 +       loff_t ppos = 0;
6418 +
6419 +       return do_splice_direct(in, &ppos, out, len, 0);
6420 +}
6421 +
6422 +struct dentry *cow_break_link(const char *pathname)
6423 +{
6424 +       int ret, mode, pathlen, redo = 0;
6425 +       struct nameidata old_nd, dir_nd;
6426 +       struct dentry *old_dentry, *new_dentry;
6427 +       struct dentry *dir, *res = NULL;
6428 +       struct vfsmount *old_mnt, *new_mnt;
6429 +       struct file *old_file;
6430 +       struct file *new_file;
6431 +       char *to, *path, pad='\251';
6432 +       loff_t ppos, size;
6433 +
6434 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
6435 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
6436 +       ret = -ENOMEM;
6437 +       if (!path)
6438 +               goto out;
6439 +
6440 +       /* old_nd will have refs to dentry and mnt */
6441 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
6442 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
6443 +       if (ret < 0)
6444 +               goto out_free_path;
6445 +
6446 +       old_dentry = old_nd.dentry;
6447 +       old_mnt = old_nd.mnt;
6448 +       mode = old_dentry->d_inode->i_mode;
6449 +
6450 +       to = d_path(old_dentry, old_mnt, path, PATH_MAX-2);
6451 +       pathlen = strlen(to);
6452 +       vxdprintk(VXD_CBIT(misc, 2), "old path »%s« [»%.*s«:%d]", to,
6453 +               old_dentry->d_name.len, old_dentry->d_name.name,
6454 +               old_dentry->d_name.len);
6455 +
6456 +       to[pathlen + 1] = 0;
6457 +retry:
6458 +       to[pathlen] = pad--;
6459 +       ret = -EMLINK;
6460 +       if (pad <= '\240')
6461 +               goto out_rel_old;
6462 +
6463 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
6464 +       /* dir_nd will have refs to dentry and mnt */
6465 +       ret = path_lookup(to,
6466 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
6467 +       vxdprintk(VXD_CBIT(misc, 2),
6468 +               "path_lookup(new): %d", ret);
6469 +       if (ret < 0)
6470 +               goto retry;
6471 +
6472 +       /* this puppy downs the inode mutex */
6473 +       new_dentry = lookup_create(&dir_nd, 0);
6474 +       vxdprintk(VXD_CBIT(misc, 2),
6475 +               "lookup_create(new): %p [»%.*s«:%d]", new_dentry,
6476 +               new_dentry->d_name.len, new_dentry->d_name.name,
6477 +               new_dentry->d_name.len);
6478 +       if (!new_dentry || IS_ERR(new_dentry)) {
6479 +               path_release(&dir_nd);
6480 +               goto retry;
6481 +       }
6482 +       dir = dir_nd.dentry;
6483 +
6484 +       ret = vfs_create(dir_nd.dentry->d_inode, new_dentry, mode, &dir_nd);
6485 +       vxdprintk(VXD_CBIT(misc, 2),
6486 +               "vfs_create(new): %d", ret);
6487 +       if (ret == -EEXIST) {
6488 +               mutex_unlock(&dir->d_inode->i_mutex);
6489 +               dput(new_dentry);
6490 +               path_release(&dir_nd);
6491 +               goto retry;
6492 +       }
6493 +       else if (ret < 0)
6494 +               goto out_unlock_new;
6495 +
6496 +       /* drop out early, ret passes ENOENT */
6497 +       ret = -ENOENT;
6498 +       if ((redo = d_unhashed(old_dentry)))
6499 +               goto out_unlock_new;
6500 +
6501 +       new_mnt = dir_nd.mnt;
6502 +       dget(old_dentry);
6503 +       mntget(old_mnt);
6504 +       /* this one cleans up the dentry/mnt in case of failure */
6505 +       old_file = dentry_open(old_dentry, old_mnt, O_RDONLY);
6506 +       vxdprintk(VXD_CBIT(misc, 2),
6507 +               "dentry_open(old): %p", old_file);
6508 +       if (!old_file || IS_ERR(old_file)) {
6509 +               res = IS_ERR(old_file) ? (void *) old_file : res;
6510 +               goto out_unlock_new;
6511 +       }
6512 +
6513 +       dget(new_dentry);
6514 +       mntget(new_mnt);
6515 +       /* this one cleans up the dentry/mnt in case of failure */
6516 +       new_file = dentry_open(new_dentry, new_mnt, O_WRONLY);
6517 +       vxdprintk(VXD_CBIT(misc, 2),
6518 +               "dentry_open(new): %p", new_file);
6519 +
6520 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
6521 +       if (!new_file || IS_ERR(new_file))
6522 +               goto out_fput_old;
6523 +
6524 +       size = i_size_read(old_file->f_dentry->d_inode);
6525 +       ppos = 0;
6526 +       ret = do_cow_splice(old_file, new_file, size);
6527 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
6528 +       if (ret < 0) {
6529 +               goto out_fput_both;
6530 +       } else if (ret < size) {
6531 +               ret = -ENOSPC;
6532 +               goto out_fput_both;
6533 +       } else {
6534 +               struct inode *old_inode = old_dentry->d_inode;
6535 +               struct inode *new_inode = new_dentry->d_inode;
6536 +               struct iattr attr = {
6537 +                       .ia_uid = old_inode->i_uid,
6538 +                       .ia_gid = old_inode->i_gid,
6539 +                       .ia_valid = ATTR_UID | ATTR_GID
6540 +                       };
6541 +
6542 +               ret = inode_setattr(new_inode, &attr);
6543 +               if (ret)
6544 +                       goto out_fput_both;
6545 +       }
6546 +
6547 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
6548 +
6549 +       /* drop out late */
6550 +       ret = -ENOENT;
6551 +       if ((redo = d_unhashed(old_dentry)))
6552 +               goto out_unlock;
6553 +
6554 +       vxdprintk(VXD_CBIT(misc, 2),
6555 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
6556 +               new_dentry->d_name.len, new_dentry->d_name.name,
6557 +               new_dentry->d_name.len,
6558 +               old_dentry->d_name.len, old_dentry->d_name.name,
6559 +               old_dentry->d_name.len);
6560 +       ret = vfs_rename(dir_nd.dentry->d_inode, new_dentry,
6561 +               old_nd.dentry->d_parent->d_inode, old_dentry);
6562 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
6563 +       res = new_dentry;
6564 +
6565 +out_unlock:
6566 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
6567 +
6568 +out_fput_both:
6569 +       vxdprintk(VXD_CBIT(misc, 3),
6570 +               "fput(new_file=%p[#%d])", new_file,
6571 +               atomic_read(&new_file->f_count));
6572 +       fput(new_file);
6573 +
6574 +out_fput_old:
6575 +       vxdprintk(VXD_CBIT(misc, 3),
6576 +               "fput(old_file=%p[#%d])", old_file,
6577 +               atomic_read(&old_file->f_count));
6578 +       fput(old_file);
6579 +
6580 +out_unlock_new:
6581 +       mutex_unlock(&dir->d_inode->i_mutex);
6582 +       if (!ret)
6583 +               goto out_redo;
6584 +
6585 +       /* error path cleanup */
6586 +       vfs_unlink(dir->d_inode, new_dentry, &dir_nd);
6587 +       dput(new_dentry);
6588 +
6589 +out_redo:
6590 +       if (!redo)
6591 +               goto out_rel_both;
6592 +       /* lookup dentry once again */
6593 +       path_release(&old_nd);
6594 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
6595 +       if (ret)
6596 +               goto out_rel_both;
6597 +
6598 +       new_dentry = old_nd.dentry;
6599 +       vxdprintk(VXD_CBIT(misc, 2),
6600 +               "path_lookup(redo): %p [»%.*s«:%d]", new_dentry,
6601 +               new_dentry->d_name.len, new_dentry->d_name.name,
6602 +               new_dentry->d_name.len);
6603 +       dget(new_dentry);
6604 +       res = new_dentry;
6605 +
6606 +out_rel_both:
6607 +       path_release(&dir_nd);
6608 +out_rel_old:
6609 +       path_release(&old_nd);
6610 +out_free_path:
6611 +       kfree(path);
6612 +out:
6613 +       if (ret)
6614 +               res = ERR_PTR(ret);
6615 +       return res;
6616 +}
6617 +
6618 +#endif
6619 +
6620  /* get the link contents into pagecache */
6621  static char *page_getlink(struct dentry * dentry, struct page **ppage)
6622  {
6623 diff -NurpP --minimal linux-2.6.22.10/fs/namespace.c linux-2.6.22.10-vs2.2.0.5/fs/namespace.c
6624 --- linux-2.6.22.10/fs/namespace.c      2007-07-09 13:19:27 +0200
6625 +++ linux-2.6.22.10-vs2.2.0.5/fs/namespace.c    2007-06-15 03:24:51 +0200
6626 @@ -25,6 +25,11 @@
6627  #include <linux/security.h>
6628  #include <linux/mount.h>
6629  #include <linux/ramfs.h>
6630 +#include <linux/vs_base.h>
6631 +#include <linux/vs_context.h>
6632 +#include <linux/vs_tag.h>
6633 +#include <linux/vserver/space.h>
6634 +#include <linux/vserver/global.h>
6635  #include <asm/uaccess.h>
6636  #include <asm/unistd.h>
6637  #include "pnode.h"
6638 @@ -240,6 +245,7 @@ static struct vfsmount *clone_mnt(struct
6639                 mnt->mnt_root = dget(root);
6640                 mnt->mnt_mountpoint = mnt->mnt_root;
6641                 mnt->mnt_parent = mnt;
6642 +               mnt->mnt_tag = old->mnt_tag;
6643  
6644                 if (flag & CL_SLAVE) {
6645                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
6646 @@ -348,48 +354,91 @@ static inline void mangle(struct seq_fil
6647         seq_escape(m, s, " \t\n\\");
6648  }
6649  
6650 +static int mnt_is_reachable(struct vfsmount *mnt)
6651 +{
6652 +       struct vfsmount *root_mnt;
6653 +       struct dentry *root, *point;
6654 +       int ret;
6655 +
6656 +       if (mnt == mnt->mnt_ns->root)
6657 +               return 1;
6658 +
6659 +       spin_lock(&vfsmount_lock);
6660 +       root_mnt = current->fs->rootmnt;
6661 +       root = current->fs->root;
6662 +       point = root;
6663 +
6664 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6665 +               point = mnt->mnt_mountpoint;
6666 +               mnt = mnt->mnt_parent;
6667 +       }
6668 +
6669 +       ret = (mnt == root_mnt) && is_subdir(point, root);
6670 +
6671 +       spin_unlock(&vfsmount_lock);
6672 +
6673 +       return ret;
6674 +}
6675 +
6676  static int show_vfsmnt(struct seq_file *m, void *v)
6677  {
6678         struct vfsmount *mnt = v;
6679         int err = 0;
6680         static struct proc_fs_info {
6681 -               int flag;
6682 -               char *str;
6683 +               int s_flag;
6684 +               int mnt_flag;
6685 +               char *set_str;
6686 +               char *unset_str;
6687         } fs_info[] = {
6688 -               { MS_SYNCHRONOUS, ",sync" },
6689 -               { MS_DIRSYNC, ",dirsync" },
6690 -               { MS_MANDLOCK, ",mand" },
6691 -               { 0, NULL }
6692 -       };
6693 -       static struct proc_fs_info mnt_info[] = {
6694 -               { MNT_NOSUID, ",nosuid" },
6695 -               { MNT_NODEV, ",nodev" },
6696 -               { MNT_NOEXEC, ",noexec" },
6697 -               { MNT_NOATIME, ",noatime" },
6698 -               { MNT_NODIRATIME, ",nodiratime" },
6699 -               { MNT_RELATIME, ",relatime" },
6700 -               { 0, NULL }
6701 +               { MS_RDONLY, MNT_RDONLY, "ro", "rw" },
6702 +               { MS_SYNCHRONOUS, 0, ",sync", NULL },
6703 +               { MS_DIRSYNC, 0, ",dirsync", NULL },
6704 +               { MS_MANDLOCK, 0, ",mand", NULL },
6705 +               { MS_TAGGED, 0, ",tag", NULL },
6706 +               { MS_NOATIME, MNT_NOATIME, ",noatime", NULL },
6707 +               { MS_NODIRATIME, MNT_NODIRATIME, ",nodiratime", NULL },
6708 +               { MS_RELATIME, MNT_RELATIME, ",relatime", NULL },
6709 +               { 0, MNT_NOSUID, ",nosuid", NULL },
6710 +               { 0, MNT_NODEV, ",nodev", NULL },
6711 +               { 0, MNT_NOEXEC, ",noexec", NULL },
6712 +               { 0, 0, NULL, NULL }
6713         };
6714 -       struct proc_fs_info *fs_infop;
6715 +       struct proc_fs_info *p;
6716 +       unsigned long s_flags = mnt->mnt_sb->s_flags;
6717 +       int mnt_flags = mnt->mnt_flags;
6718  
6719 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6720 -       seq_putc(m, ' ');
6721 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
6722 -       seq_putc(m, ' ');
6723 -       mangle(m, mnt->mnt_sb->s_type->name);
6724 -       if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
6725 -               seq_putc(m, '.');
6726 -               mangle(m, mnt->mnt_sb->s_subtype);
6727 -       }
6728 -       seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? " ro" : " rw");
6729 -       for (fs_infop = fs_info; fs_infop->flag; fs_infop++) {
6730 -               if (mnt->mnt_sb->s_flags & fs_infop->flag)
6731 -                       seq_puts(m, fs_infop->str);
6732 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6733 +               return 0;
6734 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6735 +               return 0;
6736 +
6737 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6738 +               mnt == current->fs->rootmnt) {
6739 +               seq_puts(m, "/dev/root / ");
6740 +       } else {
6741 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
6742 +               seq_putc(m, ' ');
6743 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
6744 +               seq_putc(m, ' ');
6745 +
6746 +               if (mnt->mnt_sb->s_subtype && mnt->mnt_sb->s_subtype[0]) {
6747 +                       seq_putc(m, '.');
6748 +                       mangle(m, mnt->mnt_sb->s_subtype);
6749 +               }
6750         }
6751 -       for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) {
6752 -               if (mnt->mnt_flags & fs_infop->flag)
6753 -                       seq_puts(m, fs_infop->str);
6754 +       mangle(m, mnt->mnt_sb->s_type->name);
6755 +       seq_putc(m, ' ');
6756 +       for (p = fs_info; (p->s_flag | p->mnt_flag) ; p++) {
6757 +               if ((s_flags & p->s_flag) || (mnt_flags & p->mnt_flag)) {
6758 +                       if (p->set_str)
6759 +                               seq_puts(m, p->set_str);
6760 +               } else {
6761 +                       if (p->unset_str)
6762 +                               seq_puts(m, p->unset_str);
6763 +               }
6764         }
6765 +       if (mnt->mnt_flags & MNT_TAGID)
6766 +               seq_printf(m, ",tag=%d", mnt->mnt_tag);
6767         if (mnt->mnt_sb->s_op->show_options)
6768                 err = mnt->mnt_sb->s_op->show_options(m, mnt);
6769         seq_puts(m, " 0 0\n");
6770 @@ -408,17 +457,27 @@ static int show_vfsstat(struct seq_file 
6771         struct vfsmount *mnt = v;
6772         int err = 0;
6773  
6774 -       /* device */
6775 -       if (mnt->mnt_devname) {
6776 -               seq_puts(m, "device ");
6777 -               mangle(m, mnt->mnt_devname);
6778 -       } else
6779 -               seq_puts(m, "no device");
6780 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6781 +               return 0;
6782 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6783 +               return 0;
6784  
6785 -       /* mount point */
6786 -       seq_puts(m, " mounted on ");
6787 -       seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
6788 -       seq_putc(m, ' ');
6789 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6790 +               mnt == current->fs->rootmnt) {
6791 +               seq_puts(m, "device /dev/root mounted on / ");
6792 +       } else {
6793 +               /* device */
6794 +               if (mnt->mnt_devname) {
6795 +                       seq_puts(m, "device ");
6796 +                       mangle(m, mnt->mnt_devname);
6797 +               } else
6798 +                       seq_puts(m, "no device");
6799 +
6800 +               /* mount point */
6801 +               seq_puts(m, " mounted on ");
6802 +               seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
6803 +               seq_putc(m, ' ');
6804 +       }
6805  
6806         /* file system type */
6807         seq_puts(m, "with fstype ");
6808 @@ -648,7 +707,7 @@ asmlinkage long sys_umount(char __user *
6809                 goto dput_and_out;
6810  
6811         retval = -EPERM;
6812 -       if (!capable(CAP_SYS_ADMIN))
6813 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6814                 goto dput_and_out;
6815  
6816         retval = do_umount(nd.mnt, flags);
6817 @@ -672,7 +731,7 @@ asmlinkage long sys_oldumount(char __use
6818  
6819  static int mount_is_safe(struct nameidata *nd)
6820  {
6821 -       if (capable(CAP_SYS_ADMIN))
6822 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6823                 return 0;
6824         return -EPERM;
6825  #ifdef notyet
6826 @@ -904,11 +963,13 @@ static int do_change_type(struct nameida
6827  /*
6828   * do loopback mount.
6829   */
6830 -static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
6831 +static int do_loopback(struct nameidata *nd, char *old_name, tag_t tag,
6832 +       unsigned long flags, int mnt_flags)
6833  {
6834         struct nameidata old_nd;
6835         struct vfsmount *mnt = NULL;
6836         int err = mount_is_safe(nd);
6837 +       int recurse = flags & MS_REC;
6838         if (err)
6839                 return err;
6840         if (!old_name || !*old_name)
6841 @@ -934,6 +995,12 @@ static int do_loopback(struct nameidata 
6842         if (!mnt)
6843                 goto out;
6844  
6845 +       mnt->mnt_flags = mnt_flags;
6846 +       if (flags & MS_TAGID) {
6847 +               mnt->mnt_tag = tag;
6848 +               mnt->mnt_flags |= MNT_TAGID;
6849 +       }
6850 +
6851         err = graft_tree(mnt, nd);
6852         if (err) {
6853                 LIST_HEAD(umount_list);
6854 @@ -942,6 +1009,7 @@ static int do_loopback(struct nameidata 
6855                 spin_unlock(&vfsmount_lock);
6856                 release_mounts(&umount_list);
6857         }
6858 +       mnt->mnt_flags = mnt_flags;
6859  
6860  out:
6861         up_write(&namespace_sem);
6862 @@ -955,12 +1023,12 @@ out:
6863   * on it - tough luck.
6864   */
6865  static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
6866 -                     void *data)
6867 +                     void *data, xid_t xid)
6868  {
6869         int err;
6870         struct super_block *sb = nd->mnt->mnt_sb;
6871  
6872 -       if (!capable(CAP_SYS_ADMIN))
6873 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
6874                 return -EPERM;
6875  
6876         if (!check_mnt(nd->mnt))
6877 @@ -994,7 +1062,7 @@ static int do_move_mount(struct nameidat
6878         struct nameidata old_nd, parent_nd;
6879         struct vfsmount *p;
6880         int err = 0;
6881 -       if (!capable(CAP_SYS_ADMIN))
6882 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6883                 return -EPERM;
6884         if (!old_name || !*old_name)
6885                 return -EINVAL;
6886 @@ -1074,7 +1142,7 @@ static int do_new_mount(struct nameidata
6887                 return -EINVAL;
6888  
6889         /* we need capabilities... */
6890 -       if (!capable(CAP_SYS_ADMIN))
6891 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6892                 return -EPERM;
6893  
6894         mnt = do_kern_mount(type, flags, name, data);
6895 @@ -1386,6 +1454,7 @@ long do_mount(char *dev_name, char *dir_
6896         struct nameidata nd;
6897         int retval = 0;
6898         int mnt_flags = 0;
6899 +       tag_t tag = 0;
6900  
6901         /* Discard magic */
6902         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
6903 @@ -1401,7 +1470,19 @@ long do_mount(char *dev_name, char *dir_
6904         if (data_page)
6905                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
6906  
6907 +#ifdef CONFIG_PROPAGATE
6908 +       retval = dx_parse_tag(data_page, &tag, 1);
6909 +       if (retval) {
6910 +               mnt_flags |= MNT_TAGID;
6911 +               /* bind and re-mounts get the tag flag */
6912 +               if (flags & (MS_BIND|MS_REMOUNT))
6913 +                       flags |= MS_TAGID;
6914 +       }
6915 +#endif
6916 +
6917         /* Separate the per-mountpoint flags */
6918 +       if (flags & MS_RDONLY)
6919 +               mnt_flags |= MNT_RDONLY;
6920         if (flags & MS_NOSUID)
6921                 mnt_flags |= MNT_NOSUID;
6922         if (flags & MS_NODEV)
6923 @@ -1415,6 +1496,8 @@ long do_mount(char *dev_name, char *dir_
6924         if (flags & MS_RELATIME)
6925                 mnt_flags |= MNT_RELATIME;
6926  
6927 +       if (!capable(CAP_SYS_ADMIN))
6928 +               mnt_flags |= MNT_NODEV;
6929         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
6930                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME);
6931  
6932 @@ -1429,9 +1512,9 @@ long do_mount(char *dev_name, char *dir_
6933  
6934         if (flags & MS_REMOUNT)
6935                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
6936 -                                   data_page);
6937 +                                   data_page, tag);
6938         else if (flags & MS_BIND)
6939 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
6940 +               retval = do_loopback(&nd, dev_name, tag, flags, mnt_flags);
6941         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
6942                 retval = do_change_type(&nd, flags);
6943         else if (flags & MS_MOVE)
6944 @@ -1504,6 +1587,7 @@ static struct mnt_namespace *dup_mnt_ns(
6945                 q = next_mnt(q, new_ns->root);
6946         }
6947         up_write(&namespace_sem);
6948 +       atomic_inc(&vs_global_mnt_ns);
6949  
6950         if (rootmnt)
6951                 mntput(rootmnt);
6952 @@ -1866,5 +1950,6 @@ void __put_mnt_ns(struct mnt_namespace *
6953         spin_unlock(&vfsmount_lock);
6954         up_write(&namespace_sem);
6955         release_mounts(&umount_list);
6956 +       atomic_dec(&vs_global_mnt_ns);
6957         kfree(ns);
6958  }
6959 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/client.c linux-2.6.22.10-vs2.2.0.5/fs/nfs/client.c
6960 --- linux-2.6.22.10/fs/nfs/client.c     2007-07-09 13:19:27 +0200
6961 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfs/client.c   2007-06-15 02:37:03 +0200
6962 @@ -521,6 +521,9 @@ static int nfs_init_server_rpcclient(str
6963         if (server->flags & NFS4_MOUNT_INTR)
6964                 server->client->cl_intr = 1;
6965  
6966 +       server->client->cl_tag = 0;
6967 +       if (server->flags & NFS_MOUNT_TAGGED)
6968 +               server->client->cl_tag = 1;
6969         return 0;
6970  }
6971  
6972 @@ -678,6 +681,10 @@ static void nfs_server_set_fsinfo(struct
6973                 server->acdirmin = server->acdirmax = 0;
6974         }
6975  
6976 +       /* FIXME: needs fsinfo
6977 +       if (server->flags & NFS_MOUNT_TAGGED)
6978 +               sb->s_flags |= MS_TAGGED;       */
6979 +
6980         server->maxfilesize = fsinfo->maxfilesize;
6981  
6982         /* We're airborne Set socket buffersize */
6983 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/dir.c linux-2.6.22.10-vs2.2.0.5/fs/nfs/dir.c
6984 --- linux-2.6.22.10/fs/nfs/dir.c        2007-07-09 13:19:27 +0200
6985 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfs/dir.c      2007-06-15 03:02:49 +0200
6986 @@ -34,6 +34,7 @@
6987  #include <linux/namei.h>
6988  #include <linux/mount.h>
6989  #include <linux/sched.h>
6990 +#include <linux/vs_tag.h>
6991  
6992  #include "nfs4_fs.h"
6993  #include "delegation.h"
6994 @@ -956,6 +957,7 @@ static struct dentry *nfs_lookup(struct 
6995         if (IS_ERR(res))
6996                 goto out_unlock;
6997  
6998 +       dx_propagate_tag(nd, inode);
6999  no_entry:
7000         res = d_materialise_unique(dentry, inode);
7001         if (res != NULL) {
7002 @@ -998,7 +1000,8 @@ static int is_atomic_open(struct inode *
7003         if (nd->flags & LOOKUP_DIRECTORY)
7004                 return 0;
7005         /* Are we trying to write to a read only partition? */
7006 -       if (IS_RDONLY(dir) && (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7007 +       if ((IS_RDONLY(dir) || MNT_IS_RDONLY(nd->mnt)) &&
7008 +               (nd->intent.open.flags & (O_CREAT|O_TRUNC|FMODE_WRITE)))
7009                 return 0;
7010         return 1;
7011  }
7012 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/inode.c linux-2.6.22.10-vs2.2.0.5/fs/nfs/inode.c
7013 --- linux-2.6.22.10/fs/nfs/inode.c      2007-07-09 13:19:27 +0200
7014 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfs/inode.c    2007-06-15 02:37:03 +0200
7015 @@ -37,6 +37,7 @@
7016  #include <linux/vfs.h>
7017  #include <linux/inet.h>
7018  #include <linux/nfs_xdr.h>
7019 +#include <linux/vs_tag.h>
7020  
7021  #include <asm/system.h>
7022  #include <asm/uaccess.h>
7023 @@ -285,8 +286,10 @@ nfs_fhget(struct super_block *sb, struct
7024                         nfsi->change_attr = fattr->change_attr;
7025                 inode->i_size = nfs_size_to_loff_t(fattr->size);
7026                 inode->i_nlink = fattr->nlink;
7027 -               inode->i_uid = fattr->uid;
7028 -               inode->i_gid = fattr->gid;
7029 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7030 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7031 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7032 +                                        /* maybe fattr->xid someday */
7033                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7034                         /*
7035                          * report the blocks in 512byte units
7036 @@ -377,6 +380,8 @@ void nfs_setattr_update_inode(struct ino
7037                         inode->i_uid = attr->ia_uid;
7038                 if ((attr->ia_valid & ATTR_GID) != 0)
7039                         inode->i_gid = attr->ia_gid;
7040 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
7041 +                       inode->i_tag = attr->ia_tag;
7042                 spin_lock(&inode->i_lock);
7043                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7044                 spin_unlock(&inode->i_lock);
7045 @@ -825,6 +830,9 @@ static int nfs_check_inode_attributes(st
7046         struct nfs_inode *nfsi = NFS_I(inode);
7047         loff_t cur_size, new_isize;
7048         int data_unstable;
7049 +       uid_t uid;
7050 +       gid_t gid;
7051 +       tag_t tag;
7052  
7053  
7054         /* Has the inode gone and changed behind our back? */
7055 @@ -852,10 +860,15 @@ static int nfs_check_inode_attributes(st
7056         if (cur_size != new_isize && nfsi->npages == 0)
7057                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
7058  
7059 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7060 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7061 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7062 +
7063         /* Have any file permissions changed? */
7064         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
7065 -                       || inode->i_uid != fattr->uid
7066 -                       || inode->i_gid != fattr->gid)
7067 +                       || inode->i_uid != uid
7068 +                       || inode->i_gid != gid
7069 +                       || inode->i_tag != tag)
7070                 nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
7071  
7072         /* Has the link count changed? */
7073 @@ -946,6 +959,9 @@ static int nfs_update_inode(struct inode
7074         unsigned int    invalid = 0;
7075         unsigned long now = jiffies;
7076         int data_stable;
7077 +       uid_t uid;
7078 +       gid_t gid;
7079 +       tag_t tag;
7080  
7081         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
7082                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
7083 @@ -1022,15 +1038,21 @@ static int nfs_update_inode(struct inode
7084         }
7085         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
7086  
7087 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
7088 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
7089 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
7090 +
7091         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
7092 -           inode->i_uid != fattr->uid ||
7093 -           inode->i_gid != fattr->gid)
7094 +           inode->i_uid != uid ||
7095 +           inode->i_gid != gid ||
7096 +           inode->i_tag != tag)
7097                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
7098  
7099         inode->i_mode = fattr->mode;
7100         inode->i_nlink = fattr->nlink;
7101 -       inode->i_uid = fattr->uid;
7102 -       inode->i_gid = fattr->gid;
7103 +       inode->i_uid = uid;
7104 +       inode->i_gid = gid;
7105 +       inode->i_tag = tag;
7106  
7107         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
7108                 /*
7109 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/nfs3xdr.c linux-2.6.22.10-vs2.2.0.5/fs/nfs/nfs3xdr.c
7110 --- linux-2.6.22.10/fs/nfs/nfs3xdr.c    2007-07-09 13:19:27 +0200
7111 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfs/nfs3xdr.c  2007-06-15 02:37:03 +0200
7112 @@ -22,6 +22,7 @@
7113  #include <linux/nfs3.h>
7114  #include <linux/nfs_fs.h>
7115  #include <linux/nfsacl.h>
7116 +#include <linux/vs_tag.h>
7117  #include "internal.h"
7118  
7119  #define NFSDBG_FACILITY                NFSDBG_XDR
7120 @@ -178,7 +179,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
7121  }
7122  
7123  static inline __be32 *
7124 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
7125 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
7126  {
7127         if (attr->ia_valid & ATTR_MODE) {
7128                 *p++ = xdr_one;
7129 @@ -186,15 +187,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
7130         } else {
7131                 *p++ = xdr_zero;
7132         }
7133 -       if (attr->ia_valid & ATTR_UID) {
7134 +       if (attr->ia_valid & ATTR_UID ||
7135 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7136                 *p++ = xdr_one;
7137 -               *p++ = htonl(attr->ia_uid);
7138 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
7139         } else {
7140                 *p++ = xdr_zero;
7141         }
7142 -       if (attr->ia_valid & ATTR_GID) {
7143 +       if (attr->ia_valid & ATTR_GID ||
7144 +               (tag && (attr->ia_valid & ATTR_TAG))) {
7145                 *p++ = xdr_one;
7146 -               *p++ = htonl(attr->ia_gid);
7147 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
7148         } else {
7149                 *p++ = xdr_zero;
7150         }
7151 @@ -279,7 +282,8 @@ static int
7152  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
7153  {
7154         p = xdr_encode_fhandle(p, args->fh);
7155 -       p = xdr_encode_sattr(p, args->sattr);
7156 +       p = xdr_encode_sattr(p, args->sattr,
7157 +               req->rq_task->tk_client->cl_tag);
7158         *p++ = htonl(args->guard);
7159         if (args->guard)
7160                 p = xdr_encode_time3(p, &args->guardtime);
7161 @@ -370,7 +374,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
7162                 *p++ = args->verifier[0];
7163                 *p++ = args->verifier[1];
7164         } else
7165 -               p = xdr_encode_sattr(p, args->sattr);
7166 +               p = xdr_encode_sattr(p, args->sattr,
7167 +                       req->rq_task->tk_client->cl_tag);
7168  
7169         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7170         return 0;
7171 @@ -384,7 +389,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
7172  {
7173         p = xdr_encode_fhandle(p, args->fh);
7174         p = xdr_encode_array(p, args->name, args->len);
7175 -       p = xdr_encode_sattr(p, args->sattr);
7176 +       p = xdr_encode_sattr(p, args->sattr,
7177 +               req->rq_task->tk_client->cl_tag);
7178         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7179         return 0;
7180  }
7181 @@ -397,7 +403,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
7182  {
7183         p = xdr_encode_fhandle(p, args->fromfh);
7184         p = xdr_encode_array(p, args->fromname, args->fromlen);
7185 -       p = xdr_encode_sattr(p, args->sattr);
7186 +       p = xdr_encode_sattr(p, args->sattr,
7187 +               req->rq_task->tk_client->cl_tag);
7188         *p++ = htonl(args->pathlen);
7189         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
7190  
7191 @@ -415,7 +422,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
7192         p = xdr_encode_fhandle(p, args->fh);
7193         p = xdr_encode_array(p, args->name, args->len);
7194         *p++ = htonl(args->type);
7195 -       p = xdr_encode_sattr(p, args->sattr);
7196 +       p = xdr_encode_sattr(p, args->sattr,
7197 +               req->rq_task->tk_client->cl_tag);
7198         if (args->type == NF3CHR || args->type == NF3BLK) {
7199                 *p++ = htonl(MAJOR(args->rdev));
7200                 *p++ = htonl(MINOR(args->rdev));
7201 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/nfsroot.c linux-2.6.22.10-vs2.2.0.5/fs/nfs/nfsroot.c
7202 --- linux-2.6.22.10/fs/nfs/nfsroot.c    2007-07-09 13:19:27 +0200
7203 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfs/nfsroot.c  2007-06-15 02:37:03 +0200
7204 @@ -118,12 +118,12 @@ static int mount_port __initdata = 0;             /
7205  enum {
7206         /* Options that take integer arguments */
7207         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
7208 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
7209 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
7210         /* Options that take no arguments */
7211         Opt_soft, Opt_hard, Opt_intr,
7212         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
7213         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
7214 -       Opt_acl, Opt_noacl,
7215 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
7216         /* Error token */
7217         Opt_err
7218  };
7219 @@ -160,6 +160,10 @@ static match_table_t __initdata tokens =
7220         {Opt_tcp, "tcp"},
7221         {Opt_acl, "acl"},
7222         {Opt_noacl, "noacl"},
7223 +       {Opt_tag, "tag"},
7224 +       {Opt_notag, "notag"},
7225 +       {Opt_tagid, "tagid=%u"},
7226 +       {Opt_tag, "tagxid"},
7227         {Opt_err, NULL}
7228         
7229  };
7230 @@ -274,6 +278,20 @@ static int __init root_nfs_parse(char *n
7231                         case Opt_noacl:
7232                                 nfs_data.flags |= NFS_MOUNT_NOACL;
7233                                 break;
7234 +#ifndef CONFIG_TAGGING_NONE
7235 +                       case Opt_tag:
7236 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7237 +                               break;
7238 +                       case Opt_notag:
7239 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
7240 +                               break;
7241 +#endif
7242 +#ifdef CONFIG_PROPAGATE
7243 +                       case Opt_tagid:
7244 +                               /* use args[0] */
7245 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
7246 +                               break;
7247 +#endif
7248                         default:
7249                                 printk(KERN_WARNING "Root-NFS: unknown "
7250                                         "option: %s\n", p);
7251 diff -NurpP --minimal linux-2.6.22.10/fs/nfs/super.c linux-2.6.22.10-vs2.2.0.5/fs/nfs/super.c
7252 --- linux-2.6.22.10/fs/nfs/super.c      2007-10-30 01:57:14 +0100
7253 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfs/super.c    2007-10-01 15:25:35 +0200
7254 @@ -49,6 +49,7 @@
7255  #include <linux/nfs_xdr.h>
7256  #include <linux/magic.h>
7257  #include <linux/parser.h>
7258 +#include <linux/vs_tag.h>
7259  
7260  #include <asm/system.h>
7261  #include <asm/uaccess.h>
7262 @@ -452,6 +453,7 @@ static void nfs_show_mount_options(struc
7263                 { NFS_MOUNT_NOACL, ",noacl", "" },
7264                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
7265                 { NFS_MOUNT_UNSHARED, ",nosharecache", ""},
7266 +               { NFS_MOUNT_TAGGED, ",tag", "" },
7267                 { 0, NULL, NULL }
7268         };
7269         const struct proc_nfs_info *nfs_infop;
7270 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/auth.c linux-2.6.22.10-vs2.2.0.5/fs/nfsd/auth.c
7271 --- linux-2.6.22.10/fs/nfsd/auth.c      2006-06-18 04:54:42 +0200
7272 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfsd/auth.c    2007-06-15 02:37:03 +0200
7273 @@ -9,6 +9,7 @@
7274  #include <linux/sunrpc/svc.h>
7275  #include <linux/sunrpc/svcauth.h>
7276  #include <linux/nfsd/nfsd.h>
7277 +#include <linux/vs_tag.h>
7278  
7279  #define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
7280  
7281 @@ -41,19 +42,22 @@ int nfsd_setuser(struct svc_rqst *rqstp,
7282                 get_group_info(cred.cr_group_info);
7283  
7284         if (cred.cr_uid != (uid_t) -1)
7285 -               current->fsuid = cred.cr_uid;
7286 +               current->fsuid = INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7287         else
7288                 current->fsuid = exp->ex_anon_uid;
7289         if (cred.cr_gid != (gid_t) -1)
7290 -               current->fsgid = cred.cr_gid;
7291 +               current->fsgid = INOTAG_GID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid);
7292         else
7293                 current->fsgid = exp->ex_anon_gid;
7294  
7295 +       /* this desperately needs a tag :) */
7296 +       current->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
7297 +
7298         if (!cred.cr_group_info)
7299                 return -ENOMEM;
7300         ret = set_current_groups(cred.cr_group_info);
7301         put_group_info(cred.cr_group_info);
7302 -       if ((cred.cr_uid)) {
7303 +       if (INOTAG_UID(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid)) {
7304                 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
7305         } else {
7306                 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
7307 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs3xdr.c linux-2.6.22.10-vs2.2.0.5/fs/nfsd/nfs3xdr.c
7308 --- linux-2.6.22.10/fs/nfsd/nfs3xdr.c   2007-07-09 13:19:27 +0200
7309 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfsd/nfs3xdr.c 2007-06-15 02:37:03 +0200
7310 @@ -21,6 +21,7 @@
7311  #include <linux/sunrpc/svc.h>
7312  #include <linux/nfsd/nfsd.h>
7313  #include <linux/nfsd/xdr3.h>
7314 +#include <linux/vs_tag.h>
7315  
7316  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7317  
7318 @@ -107,6 +108,8 @@ static __be32 *
7319  decode_sattr3(__be32 *p, struct iattr *iap)
7320  {
7321         u32     tmp;
7322 +       uid_t   uid = 0;
7323 +       gid_t   gid = 0;
7324  
7325         iap->ia_valid = 0;
7326  
7327 @@ -116,12 +119,15 @@ decode_sattr3(__be32 *p, struct iattr *i
7328         }
7329         if (*p++) {
7330                 iap->ia_valid |= ATTR_UID;
7331 -               iap->ia_uid = ntohl(*p++);
7332 +               uid = ntohl(*p++);
7333         }
7334         if (*p++) {
7335                 iap->ia_valid |= ATTR_GID;
7336 -               iap->ia_gid = ntohl(*p++);
7337 +               gid = ntohl(*p++);
7338         }
7339 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7340 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7341 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7342         if (*p++) {
7343                 u64     newsize;
7344  
7345 @@ -180,8 +186,10 @@ encode_fattr3(struct svc_rqst *rqstp, __
7346         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
7347         *p++ = htonl((u32) stat->mode);
7348         *p++ = htonl((u32) stat->nlink);
7349 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7350 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7351 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7352 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7353 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7354 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7355         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
7356                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
7357         } else {
7358 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs4recover.c linux-2.6.22.10-vs2.2.0.5/fs/nfsd/nfs4recover.c
7359 --- linux-2.6.22.10/fs/nfsd/nfs4recover.c       2007-07-09 13:19:27 +0200
7360 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfsd/nfs4recover.c     2007-06-15 02:37:03 +0200
7361 @@ -156,7 +156,7 @@ nfsd4_create_clid_dir(struct nfs4_client
7362                 dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
7363                 goto out_put;
7364         }
7365 -       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU);
7366 +       status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU, NULL);
7367  out_put:
7368         dput(dentry);
7369  out_unlock:
7370 @@ -260,7 +260,7 @@ nfsd4_remove_clid_file(struct dentry *di
7371                 return -EINVAL;
7372         }
7373         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7374 -       status = vfs_unlink(dir->d_inode, dentry);
7375 +       status = vfs_unlink(dir->d_inode, dentry, NULL);
7376         mutex_unlock(&dir->d_inode->i_mutex);
7377         return status;
7378  }
7379 @@ -275,7 +275,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,
7380          * a kernel from the future.... */
7381         nfsd4_list_rec_dir(dentry, nfsd4_remove_clid_file);
7382         mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
7383 -       status = vfs_rmdir(dir->d_inode, dentry);
7384 +       status = vfs_rmdir(dir->d_inode, dentry, NULL);
7385         mutex_unlock(&dir->d_inode->i_mutex);
7386         return status;
7387  }
7388 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfs4xdr.c linux-2.6.22.10-vs2.2.0.5/fs/nfsd/nfs4xdr.c
7389 --- linux-2.6.22.10/fs/nfsd/nfs4xdr.c   2007-07-09 13:19:27 +0200
7390 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfsd/nfs4xdr.c 2007-06-15 02:37:03 +0200
7391 @@ -61,6 +61,7 @@
7392  #include <linux/nfs4_acl.h>
7393  #include <linux/sunrpc/gss_api.h>
7394  #include <linux/sunrpc/svcauth_gss.h>
7395 +#include <linux/vs_tag.h>
7396  
7397  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7398  
7399 @@ -1727,14 +1728,18 @@ out_acl:
7400                 WRITE32(stat.nlink);
7401         }
7402         if (bmval1 & FATTR4_WORD1_OWNER) {
7403 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
7404 +               status = nfsd4_encode_user(rqstp,
7405 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
7406 +                       stat.uid, stat.tag), &p, &buflen);
7407                 if (status == nfserr_resource)
7408                         goto out_resource;
7409                 if (status)
7410                         goto out;
7411         }
7412         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
7413 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
7414 +               status = nfsd4_encode_group(rqstp,
7415 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
7416 +                       stat.gid, stat.tag), &p, &buflen);
7417                 if (status == nfserr_resource)
7418                         goto out_resource;
7419                 if (status)
7420 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/nfsxdr.c linux-2.6.22.10-vs2.2.0.5/fs/nfsd/nfsxdr.c
7421 --- linux-2.6.22.10/fs/nfsd/nfsxdr.c    2007-07-09 13:19:27 +0200
7422 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfsd/nfsxdr.c  2007-06-15 02:37:03 +0200
7423 @@ -15,6 +15,7 @@
7424  #include <linux/nfsd/nfsd.h>
7425  #include <linux/nfsd/xdr.h>
7426  #include <linux/mm.h>
7427 +#include <linux/vs_tag.h>
7428  
7429  #define NFSDDBG_FACILITY               NFSDDBG_XDR
7430  
7431 @@ -97,6 +98,8 @@ static __be32 *
7432  decode_sattr(__be32 *p, struct iattr *iap)
7433  {
7434         u32     tmp, tmp1;
7435 +       uid_t   uid = 0;
7436 +       gid_t   gid = 0;
7437  
7438         iap->ia_valid = 0;
7439  
7440 @@ -110,12 +113,15 @@ decode_sattr(__be32 *p, struct iattr *ia
7441         }
7442         if ((tmp = ntohl(*p++)) != (u32)-1) {
7443                 iap->ia_valid |= ATTR_UID;
7444 -               iap->ia_uid = tmp;
7445 +               uid = tmp;
7446         }
7447         if ((tmp = ntohl(*p++)) != (u32)-1) {
7448                 iap->ia_valid |= ATTR_GID;
7449 -               iap->ia_gid = tmp;
7450 +               gid = tmp;
7451         }
7452 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
7453 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
7454 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
7455         if ((tmp = ntohl(*p++)) != (u32)-1) {
7456                 iap->ia_valid |= ATTR_SIZE;
7457                 iap->ia_size = tmp;
7458 @@ -160,8 +166,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
7459         *p++ = htonl(nfs_ftypes[type >> 12]);
7460         *p++ = htonl((u32) stat->mode);
7461         *p++ = htonl((u32) stat->nlink);
7462 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
7463 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
7464 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
7465 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
7466 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
7467 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
7468  
7469         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
7470                 *p++ = htonl(NFS_MAXPATHLEN);
7471 diff -NurpP --minimal linux-2.6.22.10/fs/nfsd/vfs.c linux-2.6.22.10-vs2.2.0.5/fs/nfsd/vfs.c
7472 --- linux-2.6.22.10/fs/nfsd/vfs.c       2007-10-30 01:57:14 +0100
7473 +++ linux-2.6.22.10-vs2.2.0.5/fs/nfsd/vfs.c     2007-08-12 12:21:51 +0200
7474 @@ -1186,13 +1186,13 @@ nfsd_create(struct svc_rqst *rqstp, stru
7475                 host_err = vfs_create(dirp, dchild, iap->ia_mode, NULL);
7476                 break;
7477         case S_IFDIR:
7478 -               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode);
7479 +               host_err = vfs_mkdir(dirp, dchild, iap->ia_mode, NULL);
7480                 break;
7481         case S_IFCHR:
7482         case S_IFBLK:
7483         case S_IFIFO:
7484         case S_IFSOCK:
7485 -               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev);
7486 +               host_err = vfs_mknod(dirp, dchild, iap->ia_mode, rdev, NULL);
7487                 break;
7488         default:
7489                 printk("nfsd: bad file type %o in nfsd_create\n", type);
7490 @@ -1466,11 +1466,13 @@ nfsd_symlink(struct svc_rqst *rqstp, str
7491                 else {
7492                         strncpy(path_alloced, path, plen);
7493                         path_alloced[plen] = 0;
7494 -                       host_err = vfs_symlink(dentry->d_inode, dnew, path_alloced, mode);
7495 +                       host_err = vfs_symlink(dentry->d_inode, dnew,
7496 +                               path_alloced, mode, NULL);
7497                         kfree(path_alloced);
7498                 }
7499         } else
7500 -               host_err = vfs_symlink(dentry->d_inode, dnew, path, mode);
7501 +               host_err = vfs_symlink(dentry->d_inode, dnew,
7502 +                       path, mode, NULL);
7503  
7504         if (!host_err) {
7505                 if (EX_ISSYNC(fhp->fh_export))
7506 @@ -1529,7 +1531,7 @@ nfsd_link(struct svc_rqst *rqstp, struct
7507         dold = tfhp->fh_dentry;
7508         dest = dold->d_inode;
7509  
7510 -       host_err = vfs_link(dold, dirp, dnew);
7511 +       host_err = vfs_link(dold, dirp, dnew, NULL);
7512         if (!host_err) {
7513                 if (EX_ISSYNC(ffhp->fh_export)) {
7514                         err = nfserrno(nfsd_sync_dir(ddir));
7515 @@ -1694,9 +1696,9 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
7516                         host_err = -EPERM;
7517                 } else
7518  #endif
7519 -               host_err = vfs_unlink(dirp, rdentry);
7520 +               host_err = vfs_unlink(dirp, rdentry, NULL);
7521         } else { /* It's RMDIR */
7522 -               host_err = vfs_rmdir(dirp, rdentry);
7523 +               host_err = vfs_rmdir(dirp, rdentry, NULL);
7524         }
7525  
7526         dput(rdentry);
7527 @@ -1818,6 +1820,7 @@ nfsd_permission(struct svc_export *exp, 
7528         if (!(acc & MAY_LOCAL_ACCESS))
7529                 if (acc & (MAY_WRITE | MAY_SATTR | MAY_TRUNC)) {
7530 -                       if (EX_RDONLY(exp, rqstp) || IS_RDONLY(inode))
7531 +                       if (EX_RDONLY(exp, rqstp) || IS_RDONLY(inode)
7532 +                               || MNT_IS_RDONLY(exp->ex_mnt))
7533                                 return nfserr_rofs;
7534                         if (/* (acc & MAY_WRITE) && */ IS_IMMUTABLE(inode))
7535                                 return nfserr_perm;
7536 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/dlm/dlmfs.c linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/dlm/dlmfs.c
7537 --- linux-2.6.22.10/fs/ocfs2/dlm/dlmfs.c        2007-07-09 13:19:28 +0200
7538 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/dlm/dlmfs.c      2007-06-15 02:37:03 +0200
7539 @@ -43,6 +43,7 @@
7540  #include <linux/init.h>
7541  #include <linux/string.h>
7542  #include <linux/backing-dev.h>
7543 +#include <linux/vs_tag.h>
7544  
7545  #include <asm/uaccess.h>
7546  
7547 @@ -331,6 +332,7 @@ static struct inode *dlmfs_get_root_inod
7548                 inode->i_mode = mode;
7549                 inode->i_uid = current->fsuid;
7550                 inode->i_gid = current->fsgid;
7551 +               inode->i_tag = dx_current_fstag(sb);
7552                 inode->i_blocks = 0;
7553                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
7554                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
7555 @@ -357,6 +359,7 @@ static struct inode *dlmfs_get_inode(str
7556         inode->i_mode = mode;
7557         inode->i_uid = current->fsuid;
7558         inode->i_gid = current->fsgid;
7559 +       inode->i_tag = dx_current_fstag(sb);
7560         inode->i_blocks = 0;
7561         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
7562         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
7563 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/dlmglue.c linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/dlmglue.c
7564 --- linux-2.6.22.10/fs/ocfs2/dlmglue.c  2007-07-09 13:19:28 +0200
7565 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/dlmglue.c        2007-06-15 02:37:03 +0200
7566 @@ -1475,6 +1475,7 @@ static void __ocfs2_stuff_meta_lvb(struc
7567         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
7568         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
7569         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
7570 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
7571         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
7572         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
7573         lvb->lvb_iatime_packed  =
7574 @@ -1527,6 +1528,7 @@ static void ocfs2_refresh_inode_from_lvb
7575  
7576         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
7577         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
7578 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
7579         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
7580         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
7581         ocfs2_unpack_timespec(&inode->i_atime,
7582 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/dlmglue.h linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/dlmglue.h
7583 --- linux-2.6.22.10/fs/ocfs2/dlmglue.h  2007-07-09 13:19:28 +0200
7584 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/dlmglue.h        2007-06-15 02:37:03 +0200
7585 @@ -34,7 +34,7 @@
7586  struct ocfs2_meta_lvb {
7587         __u8         lvb_version;
7588         __u8         lvb_reserved0;
7589 -       __be16       lvb_reserved1;
7590 +       __be16       lvb_itag;
7591         __be32       lvb_iclusters;
7592         __be32       lvb_iuid;
7593         __be32       lvb_igid;
7594 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/file.c linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/file.c
7595 --- linux-2.6.22.10/fs/ocfs2/file.c     2007-10-30 01:57:14 +0100
7596 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/file.c   2007-09-05 03:05:52 +0200
7597 @@ -943,13 +943,15 @@ int ocfs2_setattr(struct dentry *dentry,
7598                 mlog(0, "uid change: %d\n", attr->ia_uid);
7599         if (attr->ia_valid & ATTR_GID)
7600                 mlog(0, "gid change: %d\n", attr->ia_gid);
7601 +       if (attr->ia_valid & ATTR_TAG)
7602 +               mlog(0, "tag change: %d\n", attr->ia_tag);
7603         if (attr->ia_valid & ATTR_SIZE)
7604                 mlog(0, "size change...\n");
7605         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
7606                 mlog(0, "time change...\n");
7607  
7608  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
7609 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
7610 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
7611         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
7612                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
7613                 return 0;
7614 @@ -1805,6 +1807,7 @@ bail:
7615  const struct inode_operations ocfs2_file_iops = {
7616         .setattr        = ocfs2_setattr,
7617         .getattr        = ocfs2_getattr,
7618 +       .sync_flags     = ocfs2_sync_flags,
7619         .permission     = ocfs2_permission,
7620  };
7621  
7622 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/inode.c linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/inode.c
7623 --- linux-2.6.22.10/fs/ocfs2/inode.c    2007-07-09 13:19:28 +0200
7624 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/inode.c  2007-06-15 03:10:27 +0200
7625 @@ -28,6 +28,7 @@
7626  #include <linux/slab.h>
7627  #include <linux/highmem.h>
7628  #include <linux/pagemap.h>
7629 +#include <linux/vs_tag.h>
7630  
7631  #include <asm/byteorder.h>
7632  
7633 @@ -42,6 +43,7 @@
7634  #include "file.h"
7635  #include "heartbeat.h"
7636  #include "inode.h"
7637 +#include "ioctl.h"
7638  #include "journal.h"
7639  #include "namei.h"
7640  #include "suballoc.h"
7641 @@ -77,6 +79,10 @@ void ocfs2_set_inode_flags(struct inode 
7642  
7643         if (flags & OCFS2_IMMUTABLE_FL)
7644                 inode->i_flags |= S_IMMUTABLE;
7645 +       if (flags & OCFS2_IUNLINK_FL)
7646 +               inode->i_flags |= S_IUNLINK;
7647 +       if (flags & OCFS2_BARRIER_FL)
7648 +               inode->i_flags |= S_BARRIER;
7649  
7650         if (flags & OCFS2_SYNC_FL)
7651                 inode->i_flags |= S_SYNC;
7652 @@ -107,6 +113,27 @@ void ocfs2_get_inode_flags(struct ocfs2_
7653                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
7654  }
7655  
7656 +int ocfs2_sync_flags(struct inode *inode)
7657 +{
7658 +       unsigned int oldflags, newflags;
7659 +
7660 +       oldflags = OCFS2_I(inode)->ip_flags;
7661 +       newflags = oldflags & ~(OCFS2_IMMUTABLE_FL |
7662 +               OCFS2_IUNLINK_FL | OCFS2_BARRIER_FL);
7663 +
7664 +       if (IS_IMMUTABLE(inode))
7665 +               newflags |= OCFS2_IMMUTABLE_FL;
7666 +       if (IS_IUNLINK(inode))
7667 +               newflags |= OCFS2_IUNLINK_FL;
7668 +       if (IS_BARRIER(inode))
7669 +               newflags |= OCFS2_BARRIER_FL;
7670 +
7671 +       if (oldflags ^ newflags)
7672 +               return ocfs2_set_inode_attr(inode,
7673 +                       newflags, OCFS2_FL_MASK);
7674 +       return 0;
7675 +}
7676 +
7677  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, int flags)
7678  {
7679         struct inode *inode = NULL;
7680 @@ -212,6 +239,8 @@ int ocfs2_populate_inode(struct inode *i
7681         struct super_block *sb;
7682         struct ocfs2_super *osb;
7683         int status = -EINVAL;
7684 +       uid_t uid;
7685 +       gid_t gid;
7686  
7687         mlog_entry("(0x%p, size:%llu)\n", inode,
7688                    (unsigned long long)le64_to_cpu(fe->i_size));
7689 @@ -246,8 +275,12 @@ int ocfs2_populate_inode(struct inode *i
7690         inode->i_generation = le32_to_cpu(fe->i_generation);
7691         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
7692         inode->i_mode = le16_to_cpu(fe->i_mode);
7693 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7694 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7695 +       uid = le32_to_cpu(fe->i_uid);
7696 +       gid = le32_to_cpu(fe->i_gid);
7697 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7698 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7699 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7700 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7701  
7702         /* Fast symlinks will have i_size but no allocated clusters. */
7703         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
7704 @@ -1224,8 +1257,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
7705  
7706         fe->i_size = cpu_to_le64(i_size_read(inode));
7707         fe->i_links_count = cpu_to_le16(inode->i_nlink);
7708 -       fe->i_uid = cpu_to_le32(inode->i_uid);
7709 -       fe->i_gid = cpu_to_le32(inode->i_gid);
7710 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
7711 +               inode->i_uid, inode->i_tag));
7712 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
7713 +               inode->i_gid, inode->i_tag));
7714 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
7715         fe->i_mode = cpu_to_le16(inode->i_mode);
7716         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
7717         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
7718 @@ -1253,15 +1289,24 @@ leave:
7719  void ocfs2_refresh_inode(struct inode *inode,
7720                          struct ocfs2_dinode *fe)
7721  {
7722 +       uid_t uid;
7723 +       gid_t gid;
7724 +
7725         spin_lock(&OCFS2_I(inode)->ip_lock);
7726  
7727         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
7728         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
7729 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
7730 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
7731         ocfs2_set_inode_flags(inode);
7732         i_size_write(inode, le64_to_cpu(fe->i_size));
7733         inode->i_nlink = le16_to_cpu(fe->i_links_count);
7734 -       inode->i_uid = le32_to_cpu(fe->i_uid);
7735 -       inode->i_gid = le32_to_cpu(fe->i_gid);
7736 +       uid = le32_to_cpu(fe->i_uid);
7737 +       gid = le32_to_cpu(fe->i_gid);
7738 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7739 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7740 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
7741 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
7742         inode->i_mode = le16_to_cpu(fe->i_mode);
7743         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
7744                 inode->i_blocks = 0;
7745 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/inode.h linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/inode.h
7746 --- linux-2.6.22.10/fs/ocfs2/inode.h    2007-07-09 13:19:28 +0200
7747 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/inode.h  2007-06-15 03:10:53 +0200
7748 @@ -142,6 +142,7 @@ int ocfs2_aio_write(struct file *file, s
7749  
7750  void ocfs2_set_inode_flags(struct inode *inode);
7751  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
7752 +int ocfs2_sync_flags(struct inode *inode);
7753  
7754  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
7755  {
7756 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/ioctl.c
7757 --- linux-2.6.22.10/fs/ocfs2/ioctl.c    2007-07-09 13:19:28 +0200
7758 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/ioctl.c  2007-06-15 02:37:03 +0200
7759 @@ -39,7 +39,7 @@ static int ocfs2_get_inode_attr(struct i
7760         return status;
7761  }
7762  
7763 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7764 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7765                                 unsigned mask)
7766  {
7767         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
7768 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ioctl.h linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/ioctl.h
7769 --- linux-2.6.22.10/fs/ocfs2/ioctl.h    2007-07-09 13:19:28 +0200
7770 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/ioctl.h  2007-06-15 02:37:03 +0200
7771 @@ -10,6 +10,9 @@
7772  #ifndef OCFS2_IOCTL_H
7773  #define OCFS2_IOCTL_H
7774  
7775 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
7776 +                               unsigned mask);
7777 +
7778  int ocfs2_ioctl(struct inode * inode, struct file * filp,
7779         unsigned int cmd, unsigned long arg);
7780  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
7781 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/namei.c linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/namei.c
7782 --- linux-2.6.22.10/fs/ocfs2/namei.c    2007-07-09 13:19:28 +0200
7783 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/namei.c  2007-06-15 02:37:03 +0200
7784 @@ -40,6 +40,7 @@
7785  #include <linux/types.h>
7786  #include <linux/slab.h>
7787  #include <linux/highmem.h>
7788 +#include <linux/vs_tag.h>
7789  
7790  #define MLOG_MASK_PREFIX ML_NAMEI
7791  #include <cluster/masklog.h>
7792 @@ -483,6 +484,9 @@ static int ocfs2_mknod_locked(struct ocf
7793         u64 fe_blkno = 0;
7794         u16 suballoc_bit;
7795         struct inode *inode = NULL;
7796 +       uid_t uid;
7797 +       gid_t gid;
7798 +       tag_t tag;
7799  
7800         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry, mode,
7801                    (unsigned long)dev, dentry->d_name.len,
7802 @@ -542,13 +546,19 @@ static int ocfs2_mknod_locked(struct ocf
7803         fe->i_blkno = cpu_to_le64(fe_blkno);
7804         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
7805         fe->i_suballoc_slot = cpu_to_le16(osb->slot_num);
7806 -       fe->i_uid = cpu_to_le32(current->fsuid);
7807 +
7808 +       tag = dx_current_fstag(osb->sb);
7809 +       uid = current->fsuid;
7810         if (dir->i_mode & S_ISGID) {
7811 -               fe->i_gid = cpu_to_le32(dir->i_gid);
7812 +               gid = dir->i_gid;
7813                 if (S_ISDIR(mode))
7814                         mode |= S_ISGID;
7815         } else
7816 -               fe->i_gid = cpu_to_le32(current->fsgid);
7817 +               gid = current->fsgid;
7818 +
7819 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), uid, tag));
7820 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), gid, tag));
7821 +       inode->i_tag = tag;
7822         fe->i_mode = cpu_to_le16(mode);
7823         if (S_ISCHR(mode) || S_ISBLK(mode))
7824                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
7825 @@ -2316,5 +2326,6 @@ const struct inode_operations ocfs2_dir_
7826         .rename         = ocfs2_rename,
7827         .setattr        = ocfs2_setattr,
7828         .getattr        = ocfs2_getattr,
7829 +       .sync_flags     = ocfs2_sync_flags,
7830         .permission     = ocfs2_permission,
7831  };
7832 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ocfs2.h linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/ocfs2.h
7833 --- linux-2.6.22.10/fs/ocfs2/ocfs2.h    2007-07-09 13:19:28 +0200
7834 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/ocfs2.h  2007-06-15 02:37:03 +0200
7835 @@ -170,6 +170,7 @@ enum ocfs2_mount_options
7836         OCFS2_MOUNT_NOINTR  = 1 << 2,   /* Don't catch signals */
7837         OCFS2_MOUNT_ERRORS_PANIC = 1 << 3, /* Panic on errors */
7838         OCFS2_MOUNT_DATA_WRITEBACK = 1 << 4, /* No data ordering */
7839 +       OCFS2_MOUNT_TAGGED = 1 << 8, /* use tagging */
7840  };
7841  
7842  #define OCFS2_OSB_SOFT_RO      0x0001
7843 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/ocfs2_fs.h linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/ocfs2_fs.h
7844 --- linux-2.6.22.10/fs/ocfs2/ocfs2_fs.h 2007-07-09 13:19:28 +0200
7845 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/ocfs2_fs.h       2007-06-15 02:37:03 +0200
7846 @@ -152,8 +152,12 @@
7847  #define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
7848  #define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
7849  
7850 +#define OCFS2_BARRIER_FL       (0x04000000)    /* Barrier for chroot() */
7851 +#define OCFS2_IUNLINK_FL       (0x08000000)    /* Immutable unlink */
7852 +
7853  #define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
7854  #define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
7855 +#define OCFS2_FL_MASK          (0x0F0100FF)
7856  
7857  /*
7858   * Extent record flags (e_node.leaf.flags)
7859 diff -NurpP --minimal linux-2.6.22.10/fs/ocfs2/super.c linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/super.c
7860 --- linux-2.6.22.10/fs/ocfs2/super.c    2007-07-09 13:19:28 +0200
7861 +++ linux-2.6.22.10-vs2.2.0.5/fs/ocfs2/super.c  2007-06-15 02:37:03 +0200
7862 @@ -140,6 +140,7 @@ enum {
7863         Opt_data_ordered,
7864         Opt_data_writeback,
7865         Opt_atime_quantum,
7866 +       Opt_tag, Opt_notag, Opt_tagid,
7867         Opt_err,
7868  };
7869  
7870 @@ -154,6 +155,10 @@ static match_table_t tokens = {
7871         {Opt_data_ordered, "data=ordered"},
7872         {Opt_data_writeback, "data=writeback"},
7873         {Opt_atime_quantum, "atime_quantum=%u"},
7874 +       {Opt_tag, "tag"},
7875 +       {Opt_tag, "tagxid"},
7876 +       {Opt_notag, "notag"},
7877 +       {Opt_tagid, "tagid=%u"},
7878         {Opt_err, NULL}
7879  };
7880  
7881 @@ -362,6 +367,14 @@ static int ocfs2_remount(struct super_bl
7882                 goto out;
7883         }
7884  
7885 +       printk("ocfs2_remount: %lx,%lx\n", osb->s_mount_opt, sb->s_flags);
7886 +       if ((parsed_options & OCFS2_MOUNT_TAGGED) &&
7887 +               !(sb->s_flags & MS_TAGGED)) {
7888 +               ret = -EINVAL;
7889 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
7890 +               goto out;
7891 +       }
7892 +
7893         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
7894             (parsed_options & OCFS2_MOUNT_HB_LOCAL)) {
7895                 ret = -EINVAL;
7896 @@ -654,6 +667,9 @@ static int ocfs2_fill_super(struct super
7897  
7898         ocfs2_complete_mount_recovery(osb);
7899  
7900 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
7901 +               sb->s_flags |= MS_TAGGED;
7902 +
7903         if (ocfs2_mount_local(osb))
7904                 snprintf(nodestr, sizeof(nodestr), "local");
7905         else
7906 @@ -782,6 +798,20 @@ static int ocfs2_parse_options(struct su
7907                         else
7908                                 osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
7909                         break;
7910 +#ifndef CONFIG_TAGGING_NONE
7911 +               case Opt_tag:
7912 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
7913 +                       break;
7914 +               case Opt_notag:
7915 +                       *mount_opt &= ~OCFS2_MOUNT_TAGGED;
7916 +                       break;
7917 +#endif
7918 +#ifdef CONFIG_PROPAGATE
7919 +               case Opt_tagid:
7920 +                       /* use args[0] */
7921 +                       *mount_opt |= OCFS2_MOUNT_TAGGED;
7922 +                       break;
7923 +#endif
7924                 default:
7925                         mlog(ML_ERROR,
7926                              "Unrecognized mount option \"%s\" "
7927 diff -NurpP --minimal linux-2.6.22.10/fs/open.c linux-2.6.22.10-vs2.2.0.5/fs/open.c
7928 --- linux-2.6.22.10/fs/open.c   2007-07-09 13:19:28 +0200
7929 +++ linux-2.6.22.10-vs2.2.0.5/fs/open.c 2007-06-15 02:37:03 +0200
7930 @@ -26,22 +26,31 @@
7931  #include <linux/syscalls.h>
7932  #include <linux/rcupdate.h>
7933  #include <linux/audit.h>
7934 +#include <linux/vs_base.h>
7935 +#include <linux/vs_limit.h>
7936 +#include <linux/vs_dlimit.h>
7937 +#include <linux/vs_tag.h>
7938 +#include <linux/vs_cowbl.h>
7939  
7940  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
7941  {
7942         int retval = -ENODEV;
7943  
7944         if (dentry) {
7945 +               struct super_block *sb = dentry->d_sb;
7946 +
7947                 retval = -ENOSYS;
7948 -               if (dentry->d_sb->s_op->statfs) {
7949 +               if (sb->s_op->statfs) {
7950                         memset(buf, 0, sizeof(*buf));
7951                         retval = security_sb_statfs(dentry);
7952                         if (retval)
7953                                 return retval;
7954 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
7955 +                       retval = sb->s_op->statfs(dentry, buf);
7956                         if (retval == 0 && buf->f_frsize == 0)
7957                                 buf->f_frsize = buf->f_bsize;
7958                 }
7959 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
7960 +                       vx_vsi_statfs(sb, buf);
7961         }
7962         return retval;
7963  }
7964 @@ -248,7 +257,7 @@ static long do_sys_truncate(const char _
7965                 goto dput_and_out;
7966  
7967         error = -EROFS;
7968 -       if (IS_RDONLY(inode))
7969 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd.mnt))
7970                 goto dput_and_out;
7971  
7972         error = -EPERM;
7973 @@ -397,7 +406,7 @@ asmlinkage long sys_faccessat(int dfd, c
7974            special_file(nd.dentry->d_inode->i_mode))
7975                 goto out_path_release;
7976  
7977 -       if(IS_RDONLY(nd.dentry->d_inode))
7978 +       if(IS_RDONLY(nd.dentry->d_inode) || MNT_IS_RDONLY(nd.mnt))
7979                 res = -EROFS;
7980  
7981  out_path_release:
7982 @@ -511,7 +520,7 @@ asmlinkage long sys_fchmod(unsigned int 
7983         audit_inode(NULL, inode);
7984  
7985         err = -EROFS;
7986 -       if (IS_RDONLY(inode))
7987 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(file->f_vfsmnt))
7988                 goto out_putf;
7989         err = -EPERM;
7990         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
7991 @@ -541,11 +550,11 @@ asmlinkage long sys_fchmodat(int dfd, co
7992         error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
7993         if (error)
7994                 goto out;
7995 -       inode = nd.dentry->d_inode;
7996  
7997 -       error = -EROFS;
7998 -       if (IS_RDONLY(inode))
7999 +       error = cow_check_and_break(&nd);
8000 +       if (error)
8001                 goto dput_and_out;
8002 +       inode = nd.dentry->d_inode;
8003  
8004         error = -EPERM;
8005         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8006 @@ -570,7 +579,8 @@ asmlinkage long sys_chmod(const char __u
8007         return sys_fchmodat(AT_FDCWD, filename, mode);
8008  }
8009  
8010 -static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
8011 +static int chown_common(struct dentry *dentry, struct vfsmount *mnt,
8012 +       uid_t user, gid_t group)
8013  {
8014         struct inode * inode;
8015         int error;
8016 @@ -582,7 +592,7 @@ static int chown_common(struct dentry * 
8017                 goto out;
8018         }
8019         error = -EROFS;
8020 -       if (IS_RDONLY(inode))
8021 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(mnt))
8022                 goto out;
8023         error = -EPERM;
8024         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
8025 @@ -590,11 +600,11 @@ static int chown_common(struct dentry * 
8026         newattrs.ia_valid =  ATTR_CTIME;
8027         if (user != (uid_t) -1) {
8028                 newattrs.ia_valid |= ATTR_UID;
8029 -               newattrs.ia_uid = user;
8030 +               newattrs.ia_uid = dx_map_uid(user);
8031         }
8032         if (group != (gid_t) -1) {
8033                 newattrs.ia_valid |= ATTR_GID;
8034 -               newattrs.ia_gid = group;
8035 +               newattrs.ia_gid = dx_map_gid(group);
8036         }
8037         if (!S_ISDIR(inode->i_mode))
8038                 newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID;
8039 @@ -613,7 +623,11 @@ asmlinkage long sys_chown(const char __u
8040         error = user_path_walk(filename, &nd);
8041         if (error)
8042                 goto out;
8043 -       error = chown_common(nd.dentry, user, group);
8044 +#ifdef CONFIG_VSERVER_COWBL
8045 +       error = cow_check_and_break(&nd);
8046 +       if (!error)
8047 +#endif
8048 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8049         path_release(&nd);
8050  out:
8051         return error;
8052 @@ -633,7 +647,11 @@ asmlinkage long sys_fchownat(int dfd, co
8053         error = __user_walk_fd(dfd, filename, follow, &nd);
8054         if (error)
8055                 goto out;
8056 -       error = chown_common(nd.dentry, user, group);
8057 +#ifdef CONFIG_VSERVER_COWBL
8058 +       error = cow_check_and_break(&nd);
8059 +       if (!error)
8060 +#endif
8061 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8062         path_release(&nd);
8063  out:
8064         return error;
8065 @@ -647,7 +665,11 @@ asmlinkage long sys_lchown(const char __
8066         error = user_path_walk_link(filename, &nd);
8067         if (error)
8068                 goto out;
8069 -       error = chown_common(nd.dentry, user, group);
8070 +#ifdef CONFIG_VSERVER_COWBL
8071 +       error = cow_check_and_break(&nd);
8072 +       if (!error)
8073 +#endif
8074 +               error = chown_common(nd.dentry, nd.mnt, user, group);
8075         path_release(&nd);
8076  out:
8077         return error;
8078 @@ -666,7 +688,7 @@ asmlinkage long sys_fchown(unsigned int 
8079  
8080         dentry = file->f_path.dentry;
8081         audit_inode(NULL, dentry->d_inode);
8082 -       error = chown_common(dentry, user, group);
8083 +       error = chown_common(dentry, file->f_vfsmnt, user, group);
8084         fput(file);
8085  out:
8086         return error;
8087 @@ -893,6 +915,7 @@ repeat:
8088         FD_SET(fd, fdt->open_fds);
8089         FD_CLR(fd, fdt->close_on_exec);
8090         files->next_fd = fd + 1;
8091 +       vx_openfd_inc(fd);
8092  #if 1
8093         /* Sanity check */
8094         if (fdt->fd[fd] != NULL) {
8095 @@ -915,6 +938,7 @@ static void __put_unused_fd(struct files
8096         __FD_CLR(fd, fdt->open_fds);
8097         if (fd < files->next_fd)
8098                 files->next_fd = fd;
8099 +       vx_openfd_dec(fd);
8100  }
8101  
8102  void fastcall put_unused_fd(unsigned int fd)
8103 diff -NurpP --minimal linux-2.6.22.10/fs/proc/array.c linux-2.6.22.10-vs2.2.0.5/fs/proc/array.c
8104 --- linux-2.6.22.10/fs/proc/array.c     2007-07-09 13:19:28 +0200
8105 +++ linux-2.6.22.10-vs2.2.0.5/fs/proc/array.c   2007-06-15 03:04:38 +0200
8106 @@ -75,6 +75,8 @@
8107  #include <linux/cpuset.h>
8108  #include <linux/rcupdate.h>
8109  #include <linux/delayacct.h>
8110 +#include <linux/vs_context.h>
8111 +#include <linux/vs_network.h>
8112  
8113  #include <asm/uaccess.h>
8114  #include <asm/pgtable.h>
8115 @@ -134,8 +136,9 @@ static const char *task_state_array[] = 
8116         "D (disk sleep)",       /*  2 */
8117         "T (stopped)",          /*  4 */
8118         "T (tracing stop)",     /*  8 */
8119 -       "Z (zombie)",           /* 16 */
8120 -       "X (dead)"              /* 32 */
8121 +       "H (on hold)",          /* 16 */
8122 +       "Z (zombie)",           /* 32 */
8123 +       "X (dead)",             /* 64 */
8124  };
8125  
8126  static inline const char * get_task_state(struct task_struct *tsk)
8127 @@ -144,7 +147,8 @@ static inline const char * get_task_stat
8128                                             TASK_INTERRUPTIBLE |
8129                                             TASK_UNINTERRUPTIBLE |
8130                                             TASK_STOPPED |
8131 -                                           TASK_TRACED)) |
8132 +                                          TASK_TRACED |
8133 +                                          TASK_ONHOLD)) |
8134                         (tsk->exit_state & (EXIT_ZOMBIE |
8135                                             EXIT_DEAD));
8136         const char **p = &task_state_array[0];
8137 @@ -161,8 +165,16 @@ static inline char * task_state(struct t
8138         struct group_info *group_info;
8139         int g;
8140         struct fdtable *fdt = NULL;
8141 +       pid_t pid, ptgid, tppid, tgid;
8142  
8143         rcu_read_lock();
8144 +       tgid = vx_map_tgid(p->tgid);
8145 +       pid = vx_map_pid(p->pid);
8146 +       ptgid = vx_map_pid(pid_alive(p) ?
8147 +               rcu_dereference(p->real_parent)->tgid : 0);
8148 +       tppid = vx_map_pid(pid_alive(p) && p->ptrace ?
8149 +               rcu_dereference(p->parent)->pid : 0);
8150 +
8151         buffer += sprintf(buffer,
8152                 "State:\t%s\n"
8153                 "SleepAVG:\t%lu%%\n"
8154 @@ -174,9 +186,7 @@ static inline char * task_state(struct t
8155                 "Gid:\t%d\t%d\t%d\t%d\n",
8156                 get_task_state(p),
8157                 (p->sleep_avg/1024)*100/(1020000000/1024),
8158 -               p->tgid, p->pid,
8159 -               pid_alive(p) ? rcu_dereference(p->real_parent)->tgid : 0,
8160 -               pid_alive(p) && p->ptrace ? rcu_dereference(p->parent)->pid : 0,
8161 +               tgid, pid, (pid > 1) ? ptgid : 0, tppid,
8162                 p->uid, p->euid, p->suid, p->fsuid,
8163                 p->gid, p->egid, p->sgid, p->fsgid);
8164  
8165 @@ -283,17 +293,26 @@ static inline char * task_sig(struct tas
8166  
8167  static inline char *task_cap(struct task_struct *p, char *buffer)
8168  {
8169 -    return buffer + sprintf(buffer, "CapInh:\t%016x\n"
8170 -                           "CapPrm:\t%016x\n"
8171 -                           "CapEff:\t%016x\n",
8172 -                           cap_t(p->cap_inheritable),
8173 -                           cap_t(p->cap_permitted),
8174 -                           cap_t(p->cap_effective));
8175 +       struct vx_info *vxi = p->vx_info;
8176 +
8177 +       return buffer + sprintf(buffer,
8178 +               "CapInh:\t%016x\n"
8179 +               "CapPrm:\t%016x\n"
8180 +               "CapEff:\t%016x\n",
8181 +               (unsigned)vx_info_mbcap(vxi, p->cap_inheritable),
8182 +               (unsigned)vx_info_mbcap(vxi, p->cap_permitted),
8183 +               (unsigned)vx_info_mbcap(vxi, p->cap_effective));
8184  }
8185  
8186  int proc_pid_status(struct task_struct *task, char * buffer)
8187  {
8188         char * orig = buffer;
8189 +#ifdef CONFIG_VSERVER_LEGACY
8190 +       struct vx_info *vxi;
8191 +#endif
8192 +#ifdef CONFIG_VSERVER_LEGACYNET
8193 +       struct nx_info *nxi;
8194 +#endif
8195         struct mm_struct *mm = get_task_mm(task);
8196  
8197         buffer = task_name(task, buffer);
8198 @@ -306,6 +325,46 @@ int proc_pid_status(struct task_struct *
8199         buffer = task_sig(task, buffer);
8200         buffer = task_cap(task, buffer);
8201         buffer = cpuset_task_status_allowed(task, buffer);
8202 +
8203 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
8204 +               goto skip;
8205 +#ifdef CONFIG_VSERVER_LEGACY
8206 +       buffer += sprintf (buffer,"s_context: %d\n", vx_task_xid(task));
8207 +       vxi = task_get_vx_info(task);
8208 +       if (vxi) {
8209 +               buffer += sprintf (buffer,"ctxflags: %08llx\n"
8210 +                       ,(unsigned long long)vxi->vx_flags);
8211 +               buffer += sprintf (buffer,"initpid: %d\n"
8212 +                       ,vxi->vx_initpid);
8213 +       } else {
8214 +               buffer += sprintf (buffer,"ctxflags: none\n");
8215 +               buffer += sprintf (buffer,"initpid: none\n");
8216 +       }
8217 +       put_vx_info(vxi);
8218 +#else
8219 +       buffer += sprintf (buffer,"VxID: %d\n", vx_task_xid(task));
8220 +#endif
8221 +#ifdef CONFIG_VSERVER_LEGACYNET
8222 +       nxi = task_get_nx_info(task);
8223 +       if (nxi) {
8224 +               int i;
8225 +
8226 +               buffer += sprintf (buffer,"ipv4root:");
8227 +               for (i=0; i<nxi->nbipv4; i++){
8228 +                       buffer += sprintf (buffer," %08x/%08x"
8229 +                               ,nxi->ipv4[i]
8230 +                               ,nxi->mask[i]);
8231 +               }
8232 +               *buffer++ = '\n';
8233 +               buffer += sprintf (buffer,"ipv4root_bcast: %08x\n"
8234 +                       ,nxi->v4_bcast);
8235 +       } else {
8236 +               buffer += sprintf (buffer,"ipv4root: 0\n");
8237 +               buffer += sprintf (buffer,"ipv4root_bcast: 0\n");
8238 +       }
8239 +       put_nx_info(nxi);
8240 +#endif
8241 +skip:
8242  #if defined(CONFIG_S390)
8243         buffer = task_show_regs(task, buffer);
8244  #endif
8245 @@ -320,7 +379,7 @@ static int do_task_stat(struct task_stru
8246         sigset_t sigign, sigcatch;
8247         char state;
8248         int res;
8249 -       pid_t ppid = 0, pgid = -1, sid = -1;
8250 +       pid_t pid = 0, ppid = 0, pgid = -1, sid = -1;
8251         int num_threads = 0;
8252         struct mm_struct *mm;
8253         unsigned long long start_time;
8254 @@ -382,8 +441,10 @@ static int do_task_stat(struct task_stru
8255                 }
8256  
8257                 sid = signal_session(sig);
8258 -               pgid = process_group(task);
8259 -               ppid = rcu_dereference(task->real_parent)->tgid;
8260 +               pid = vx_info_map_pid(task->vx_info, task->pid);
8261 +               pgid = vx_info_map_pid(task->vx_info, process_group(task));
8262 +               ppid = (pid > 1) ? vx_info_map_tgid(task->vx_info,
8263 +                       rcu_dereference(task->real_parent)->tgid) : 0;
8264  
8265                 unlock_task_sighand(task, &flags);
8266         }
8267 @@ -410,10 +471,21 @@ static int do_task_stat(struct task_stru
8268         /* convert nsec -> ticks */
8269         start_time = nsec_to_clock_t(start_time);
8270  
8271 +       /* fixup start time for virt uptime */
8272 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
8273 +               unsigned long long bias =
8274 +                       current->vx_info->cvirt.bias_clock;
8275 +
8276 +               if (start_time > bias)
8277 +                       start_time -= bias;
8278 +               else
8279 +                       start_time = 0;
8280 +       }
8281 +
8282         res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %u %lu \
8283  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
8284  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu\n",
8285 -               task->pid,
8286 +               pid,
8287                 tcomm,
8288                 state,
8289                 ppid,
8290 diff -NurpP --minimal linux-2.6.22.10/fs/proc/base.c linux-2.6.22.10-vs2.2.0.5/fs/proc/base.c
8291 --- linux-2.6.22.10/fs/proc/base.c      2007-07-09 13:19:28 +0200
8292 +++ linux-2.6.22.10-vs2.2.0.5/fs/proc/base.c    2007-06-15 03:06:14 +0200
8293 @@ -73,6 +73,9 @@
8294  #include <linux/poll.h>
8295  #include <linux/nsproxy.h>
8296  #include <linux/oom.h>
8297 +#include <linux/vs_context.h>
8298 +#include <linux/vs_network.h>
8299 +
8300  #include "internal.h"
8301  
8302  /* NOTE:
8303 @@ -1049,6 +1052,8 @@ static struct inode *proc_pid_make_inode
8304                 inode->i_uid = task->euid;
8305                 inode->i_gid = task->egid;
8306         }
8307 +       /* procfs is xid tagged */
8308 +       inode->i_tag = (tag_t)vx_task_xid(task);
8309         security_task_to_inode(task, inode);
8310  
8311  out:
8312 @@ -1115,6 +1128,7 @@ static int pid_revalidate(struct dentry 
8313                 put_task_struct(task);
8314                 return 1;
8315         }
8316 +drop:
8317         d_drop(dentry);
8318         return 0;
8319  }
8320 @@ -1595,6 +1600,13 @@ static struct dentry *proc_pident_lookup
8321         if (!task)
8322                 goto out_no_task;
8323  
8324 +       /* TODO: maybe we can come up with a generic approach? */
8325 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
8326 +               (dentry->d_name.len == 5) &&
8327 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
8328 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
8329 +               goto out;
8330 +
8331         /*
8332          * Yes, it does not scale. And it should not. Don't add
8333          * new entries into /proc/<tgid>/ without very good reasons.
8334 @@ -1790,14 +1802,14 @@ static int proc_self_readlink(struct den
8335                               int buflen)
8336  {
8337         char tmp[PROC_NUMBUF];
8338 -       sprintf(tmp, "%d", current->tgid);
8339 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8340         return vfs_readlink(dentry,buffer,buflen,tmp);
8341  }
8342  
8343  static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
8344  {
8345         char tmp[PROC_NUMBUF];
8346 -       sprintf(tmp, "%d", current->tgid);
8347 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
8348         return ERR_PTR(vfs_follow_link(nd,tmp));
8349  }
8350  
8351 @@ -1891,7 +1903,7 @@ out_iput:
8352  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
8353  {
8354         struct dentry *error;
8355 -       struct task_struct *task = get_proc_task(dir);
8356 +       struct task_struct *task = get_proc_task_real(dir);
8357         const struct pid_entry *p, *last;
8358  
8359         error = ERR_PTR(-ENOENT);
8360 @@ -1956,6 +1968,9 @@ static int proc_pid_io_accounting(struct
8361  static const struct file_operations proc_task_operations;
8362  static const struct inode_operations proc_task_inode_operations;
8363  
8364 +extern int proc_pid_vx_info(struct task_struct *, char *);
8365 +extern int proc_pid_nx_info(struct task_struct *, char *);
8366 +
8367  static const struct pid_entry tgid_base_stuff[] = {
8368         DIR("task",       S_IRUGO|S_IXUGO, task),
8369         DIR("fd",         S_IRUSR|S_IXUSR, fd),
8370 @@ -1995,6 +2010,8 @@ static const struct pid_entry tgid_base_
8371  #ifdef CONFIG_CPUSETS
8372         REG("cpuset",     S_IRUGO, cpuset),
8373  #endif
8374 +       INF("vinfo",      S_IRUGO, pid_vx_info),
8375 +       INF("ninfo",      S_IRUGO, pid_nx_info),
8376         INF("oom_score",  S_IRUGO, oom_score),
8377         REG("oom_adj",    S_IRUGO|S_IWUSR, oom_adjust),
8378  #ifdef CONFIG_AUDITSYSCALL
8379 @@ -2143,7 +2160,7 @@ struct dentry *proc_pid_lookup(struct in
8380                 goto out;
8381  
8382         rcu_read_lock();
8383 -       task = find_task_by_pid(tgid);
8384 +       task = vx_find_proc_task_by_pid(tgid);
8385         if (task)
8386                 get_task_struct(task);
8387         rcu_read_unlock();
8388 @@ -2207,7 +2224,7 @@ static int proc_pid_fill_cache(struct fi
8389  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
8390  {
8391         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
8392 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
8393 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
8394         struct task_struct *task;
8395         int tgid;
8396  
8397 @@ -2226,6 +2243,8 @@ int proc_pid_readdir(struct file * filp,
8398              put_task_struct(task), task = next_tgid(tgid + 1)) {
8399                 tgid = task->pid;
8400                 filp->f_pos = tgid + TGID_OFFSET;
8401 +               if (!vx_proc_task_visible(task))
8402 +                       continue;
8403                 if (proc_pid_fill_cache(filp, dirent, filldir, task, tgid) < 0) {
8404                         put_task_struct(task);
8405                         goto out;
8406 @@ -2352,9 +2371,11 @@ static struct dentry *proc_task_lookup(s
8407         tid = name_to_int(dentry);
8408         if (tid == ~0U)
8409                 goto out;
8410 +       if (vx_current_initpid(tid))
8411 +               goto out;
8412  
8413         rcu_read_lock();
8414 -       task = find_task_by_pid(tid);
8415 +       task = vx_find_proc_task_by_pid(tid);
8416         if (task)
8417                 get_task_struct(task);
8418         rcu_read_unlock();
8419 @@ -2499,7 +2520,7 @@ static int proc_task_readdir(struct file
8420         for (task = first_tid(leader, tid, pos - 2);
8421              task;
8422              task = next_tid(task), pos++) {
8423 -               tid = task->pid;
8424 +               tid = vx_map_pid(task->pid);
8425                 if (proc_task_fill_cache(filp, dirent, filldir, task, tid) < 0) {
8426                         /* returning this tgid failed, save it as the first
8427                          * pid for the next readir call */
8428 diff -NurpP --minimal linux-2.6.22.10/fs/proc/generic.c linux-2.6.22.10-vs2.2.0.5/fs/proc/generic.c
8429 --- linux-2.6.22.10/fs/proc/generic.c   2007-07-09 13:19:28 +0200
8430 +++ linux-2.6.22.10-vs2.2.0.5/fs/proc/generic.c 2007-06-15 03:08:54 +0200
8431 @@ -20,6 +20,7 @@
8432  #include <linux/namei.h>
8433  #include <linux/bitops.h>
8434  #include <linux/spinlock.h>
8435 +#include <linux/vserver/inode.h>
8436  #include <asm/uaccess.h>
8437  
8438  #include "internal.h"
8439 @@ -395,6 +396,8 @@ struct dentry *proc_lookup(struct inode 
8440                 for (de = de->subdir; de ; de = de->next) {
8441                         if (de->namelen != dentry->d_name.len)
8442                                 continue;
8443 +                       if (!vx_hide_check(0, de->vx_flags))
8444 +                               continue;
8445                         if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
8446                                 unsigned int ino = de->low_ino;
8447  
8448 @@ -402,6 +405,8 @@ struct dentry *proc_lookup(struct inode 
8449                                 spin_unlock(&proc_subdir_lock);
8450                                 error = -EINVAL;
8451                                 inode = proc_get_inode(dir->i_sb, ino, de);
8452 +                               /* generic proc entries belong to the host */
8453 +                               inode->i_tag = 0;
8454                                 spin_lock(&proc_subdir_lock);
8455                                 break;
8456                         }
8457 @@ -482,6 +487,8 @@ int proc_readdir(struct file * filp,
8458  
8459                                 /* filldir passes info to user space */
8460                                 de_get(de);
8461 +                               if (!vx_hide_check(0, de->vx_flags))
8462 +                                       goto skip;
8463                                 spin_unlock(&proc_subdir_lock);
8464                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
8465                                             de->low_ino, de->mode >> 12) < 0) {
8466 @@ -489,6 +496,7 @@ int proc_readdir(struct file * filp,
8467                                         goto out;
8468                                 }
8469                                 spin_lock(&proc_subdir_lock);
8470 +                       skip:
8471                                 filp->f_pos++;
8472                                 next = de->next;
8473                                 de_put(de);
8474 @@ -613,6 +621,7 @@ static struct proc_dir_entry *proc_creat
8475         ent->namelen = len;
8476         ent->mode = mode;
8477         ent->nlink = nlink;
8478 +       ent->vx_flags = IATTR_PROC_DEFAULT;
8479   out:
8480         return ent;
8481  }
8482 @@ -633,7 +642,8 @@ struct proc_dir_entry *proc_symlink(cons
8483                                 kfree(ent->data);
8484                                 kfree(ent);
8485                                 ent = NULL;
8486 -                       }
8487 +                       } else
8488 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
8489                 } else {
8490                         kfree(ent);
8491                         ent = NULL;
8492 diff -NurpP --minimal linux-2.6.22.10/fs/proc/inode.c linux-2.6.22.10-vs2.2.0.5/fs/proc/inode.c
8493 --- linux-2.6.22.10/fs/proc/inode.c     2007-07-09 13:19:28 +0200
8494 +++ linux-2.6.22.10-vs2.2.0.5/fs/proc/inode.c   2007-06-15 02:37:03 +0200
8495 @@ -160,6 +160,8 @@ struct inode *proc_get_inode(struct supe
8496                         inode->i_uid = de->uid;
8497                         inode->i_gid = de->gid;
8498                 }
8499 +               if (de->vx_flags)
8500 +                       PROC_I(inode)->vx_flags = de->vx_flags;
8501                 if (de->size)
8502                         inode->i_size = de->size;
8503                 if (de->nlink)
8504 diff -NurpP --minimal linux-2.6.22.10/fs/proc/internal.h linux-2.6.22.10-vs2.2.0.5/fs/proc/internal.h
8505 --- linux-2.6.22.10/fs/proc/internal.h  2007-07-09 13:19:28 +0200
8506 +++ linux-2.6.22.10-vs2.2.0.5/fs/proc/internal.h        2007-06-15 02:37:03 +0200
8507 @@ -10,6 +10,7 @@
8508   */
8509  
8510  #include <linux/proc_fs.h>
8511 +#include <linux/vs_pid.h>
8512  
8513  #ifdef CONFIG_PROC_SYSCTL
8514  extern int proc_sys_init(void);
8515 @@ -64,11 +65,16 @@ static inline struct pid *proc_pid(struc
8516         return PROC_I(inode)->pid;
8517  }
8518  
8519 -static inline struct task_struct *get_proc_task(struct inode *inode)
8520 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
8521  {
8522         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
8523  }
8524  
8525 +static inline struct task_struct *get_proc_task(struct inode *inode)
8526 +{
8527 +       return vx_get_proc_task(inode, proc_pid(inode));
8528 +}
8529 +
8530  static inline int proc_fd(struct inode *inode)
8531  {
8532         return PROC_I(inode)->fd;
8533 diff -NurpP --minimal linux-2.6.22.10/fs/proc/proc_misc.c linux-2.6.22.10-vs2.2.0.5/fs/proc/proc_misc.c
8534 --- linux-2.6.22.10/fs/proc/proc_misc.c 2007-07-09 13:19:28 +0200
8535 +++ linux-2.6.22.10-vs2.2.0.5/fs/proc/proc_misc.c       2007-06-15 02:37:03 +0200
8536 @@ -53,6 +53,8 @@
8537  #include <asm/div64.h>
8538  #include "internal.h"
8539  
8540 +#include <linux/vs_cvirt.h>
8541 +
8542  #define LOAD_INT(x) ((x) >> FSHIFT)
8543  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
8544  /*
8545 @@ -82,17 +84,32 @@ static int proc_calc_metrics(char *page,
8546  static int loadavg_read_proc(char *page, char **start, off_t off,
8547                                  int count, int *eof, void *data)
8548  {
8549 +       unsigned int running, threads;
8550         int a, b, c;
8551         int len;
8552  
8553 -       a = avenrun[0] + (FIXED_1/200);
8554 -       b = avenrun[1] + (FIXED_1/200);
8555 -       c = avenrun[2] + (FIXED_1/200);
8556 -       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
8557 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
8558 +               struct vx_info *vxi = current->vx_info;
8559 +
8560 +               a = vxi->cvirt.load[0] + (FIXED_1/200);
8561 +               b = vxi->cvirt.load[1] + (FIXED_1/200);
8562 +               c = vxi->cvirt.load[2] + (FIXED_1/200);
8563 +
8564 +               running = atomic_read(&vxi->cvirt.nr_running);
8565 +               threads = atomic_read(&vxi->cvirt.nr_threads);
8566 +       } else {
8567 +               a = avenrun[0] + (FIXED_1/200);
8568 +               b = avenrun[1] + (FIXED_1/200);
8569 +               c = avenrun[2] + (FIXED_1/200);
8570 +
8571 +               running = nr_running();
8572 +               threads = nr_threads;
8573 +       }
8574 +       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",
8575                 LOAD_INT(a), LOAD_FRAC(a),
8576                 LOAD_INT(b), LOAD_FRAC(b),
8577                 LOAD_INT(c), LOAD_FRAC(c),
8578 -               nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);
8579 +               running, threads, current->nsproxy->pid_ns->last_pid);
8580         return proc_calc_metrics(page, start, off, count, eof, len);
8581  }
8582  
8583 @@ -106,6 +123,9 @@ static int uptime_read_proc(char *page, 
8584  
8585         do_posix_clock_monotonic_gettime(&uptime);
8586         cputime_to_timespec(idletime, &idle);
8587 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
8588 +               vx_vsi_uptime(&uptime, &idle);
8589 +
8590         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
8591                         (unsigned long) uptime.tv_sec,
8592                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
8593 @@ -137,7 +157,7 @@ static int meminfo_read_proc(char *page,
8594  
8595         cached = global_page_state(NR_FILE_PAGES) -
8596                         total_swapcache_pages - i.bufferram;
8597 -       if (cached < 0)
8598 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
8599                 cached = 0;
8600  
8601         get_vmalloc_info(&vmi);
8602 diff -NurpP --minimal linux-2.6.22.10/fs/proc/root.c linux-2.6.22.10-vs2.2.0.5/fs/proc/root.c
8603 --- linux-2.6.22.10/fs/proc/root.c      2007-05-02 19:25:21 +0200
8604 +++ linux-2.6.22.10-vs2.2.0.5/fs/proc/root.c    2007-06-15 02:37:03 +0200
8605 @@ -22,6 +22,9 @@
8606  #include "internal.h"
8607  
8608  struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver;
8609 +struct proc_dir_entry *proc_virtual;
8610 +
8611 +extern void proc_vx_init(void);
8612  
8613  static int proc_get_sb(struct file_system_type *fs_type,
8614         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
8615 @@ -79,6 +82,7 @@ void __init proc_root_init(void)
8616         proc_device_tree_init();
8617  #endif
8618         proc_bus = proc_mkdir("bus", NULL);
8619 +       proc_vx_init();
8620         proc_sys_init();
8621  }
8622  
8623 diff -NurpP --minimal linux-2.6.22.10/fs/quota.c linux-2.6.22.10-vs2.2.0.5/fs/quota.c
8624 --- linux-2.6.22.10/fs/quota.c  2007-07-09 13:19:28 +0200
8625 +++ linux-2.6.22.10-vs2.2.0.5/fs/quota.c        2007-06-15 02:37:03 +0200
8626 @@ -16,6 +16,7 @@
8627  #include <linux/buffer_head.h>
8628  #include <linux/capability.h>
8629  #include <linux/quotaops.h>
8630 +#include <linux/vs_context.h>
8631  
8632  /* Check validity of generic quotactl commands */
8633  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
8634 @@ -80,11 +81,11 @@ static int generic_quotactl_valid(struct
8635         if (cmd == Q_GETQUOTA) {
8636                 if (((type == USRQUOTA && current->euid != id) ||
8637                      (type == GRPQUOTA && !in_egroup_p(id))) &&
8638 -                   !capable(CAP_SYS_ADMIN))
8639 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8640                         return -EPERM;
8641         }
8642         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
8643 -               if (!capable(CAP_SYS_ADMIN))
8644 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8645                         return -EPERM;
8646  
8647         return 0;
8648 @@ -131,10 +132,10 @@ static int xqm_quotactl_valid(struct sup
8649         if (cmd == Q_XGETQUOTA) {
8650                 if (((type == XQM_USRQUOTA && current->euid != id) ||
8651                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
8652 -                    !capable(CAP_SYS_ADMIN))
8653 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8654                         return -EPERM;
8655         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
8656 -               if (!capable(CAP_SYS_ADMIN))
8657 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8658                         return -EPERM;
8659         }
8660  
8661 @@ -327,6 +328,46 @@ static int do_quotactl(struct super_bloc
8662         return 0;
8663  }
8664  
8665 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8666 +
8667 +#include <linux/vroot.h>
8668 +#include <linux/major.h>
8669 +#include <linux/module.h>
8670 +#include <linux/kallsyms.h>
8671 +#include <linux/vserver/debug.h>
8672 +
8673 +static vroot_grb_func *vroot_get_real_bdev = NULL;
8674 +
8675 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
8676 +
8677 +int register_vroot_grb(vroot_grb_func *func) {
8678 +       int ret = -EBUSY;
8679 +
8680 +       spin_lock(&vroot_grb_lock);
8681 +       if (!vroot_get_real_bdev) {
8682 +               vroot_get_real_bdev = func;
8683 +               ret = 0;
8684 +       }
8685 +       spin_unlock(&vroot_grb_lock);
8686 +       return ret;
8687 +}
8688 +EXPORT_SYMBOL(register_vroot_grb);
8689 +
8690 +int unregister_vroot_grb(vroot_grb_func *func) {
8691 +       int ret = -EINVAL;
8692 +
8693 +       spin_lock(&vroot_grb_lock);
8694 +       if (vroot_get_real_bdev) {
8695 +               vroot_get_real_bdev = NULL;
8696 +               ret = 0;
8697 +       }
8698 +       spin_unlock(&vroot_grb_lock);
8699 +       return ret;
8700 +}
8701 +EXPORT_SYMBOL(unregister_vroot_grb);
8702 +
8703 +#endif
8704 +
8705  /*
8706   * look up a superblock on which quota ops will be performed
8707   * - use the name of a block device to find the superblock thereon
8708 @@ -344,6 +385,22 @@ static inline struct super_block *quotac
8709         putname(tmp);
8710         if (IS_ERR(bdev))
8711                 return ERR_PTR(PTR_ERR(bdev));
8712 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
8713 +       if (bdev && bdev->bd_inode &&
8714 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
8715 +               struct block_device *bdnew = (void *)-EINVAL;
8716 +
8717 +               if (vroot_get_real_bdev)
8718 +                       bdnew = vroot_get_real_bdev(bdev);
8719 +               else
8720 +                       vxdprintk(VXD_CBIT(misc, 0),
8721 +                                       "vroot_get_real_bdev not set");
8722 +               bdput(bdev);
8723 +               if (IS_ERR(bdnew))
8724 +                       return ERR_PTR(PTR_ERR(bdnew));
8725 +               bdev = bdnew;
8726 +       }
8727 +#endif
8728         sb = get_super(bdev);
8729         bdput(bdev);
8730         if (!sb)
8731 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/bitmap.c linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/bitmap.c
8732 --- linux-2.6.22.10/fs/reiserfs/bitmap.c        2007-02-06 03:01:29 +0100
8733 +++ linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/bitmap.c      2007-06-15 02:37:03 +0200
8734 @@ -13,6 +13,7 @@
8735  #include <linux/reiserfs_fs_sb.h>
8736  #include <linux/reiserfs_fs_i.h>
8737  #include <linux/quotaops.h>
8738 +#include <linux/vs_dlimit.h>
8739  
8740  #define PREALLOCATION_SIZE 9
8741  
8742 @@ -425,8 +426,10 @@ static void _reiserfs_free_block(struct 
8743         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
8744  
8745         journal_mark_dirty(th, s, sbh);
8746 -       if (for_unformatted)
8747 +       if (for_unformatted) {
8748 +               DLIMIT_FREE_BLOCK(inode, 1);
8749                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
8750 +       }
8751  }
8752  
8753  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
8754 @@ -1034,6 +1037,7 @@ static inline int blocknrs_and_prealloc_
8755         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
8756         int passno = 0;
8757         int nr_allocated = 0;
8758 +       int blocks;
8759  
8760         determine_prealloc_size(hint);
8761         if (!hint->formatted_node) {
8762 @@ -1043,19 +1047,30 @@ static inline int blocknrs_and_prealloc_
8763                                "reiserquota: allocating %d blocks id=%u",
8764                                amount_needed, hint->inode->i_uid);
8765  #endif
8766 -               quota_ret =
8767 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
8768 -               if (quota_ret)  /* Quota exceeded? */
8769 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
8770 +                       amount_needed);
8771 +               if (quota_ret)
8772                         return QUOTA_EXCEEDED;
8773 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
8774 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
8775 +                               amount_needed);
8776 +                       return NO_DISK_SPACE;
8777 +               }
8778 +
8779                 if (hint->preallocate && hint->prealloc_size) {
8780  #ifdef REISERQUOTA_DEBUG
8781                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
8782                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
8783                                        hint->prealloc_size, hint->inode->i_uid);
8784  #endif
8785 -                       quota_ret =
8786 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
8787 -                                                        hint->prealloc_size);
8788 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
8789 +                               hint->prealloc_size);
8790 +                       if (!quota_ret &&
8791 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
8792 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
8793 +                                       hint->prealloc_size);
8794 +                               quota_ret = 1;
8795 +                       }
8796                         if (quota_ret)
8797                                 hint->preallocate = hint->prealloc_size = 0;
8798                 }
8799 @@ -1087,7 +1102,10 @@ static inline int blocknrs_and_prealloc_
8800                                                nr_allocated,
8801                                                hint->inode->i_uid);
8802  #endif
8803 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
8804 +                               /* Free not allocated blocks */
8805 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
8806 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
8807 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
8808                         }
8809                         while (nr_allocated--)
8810                                 reiserfs_free_block(hint->th, hint->inode,
8811 @@ -1118,10 +1136,10 @@ static inline int blocknrs_and_prealloc_
8812                                REISERFS_I(hint->inode)->i_prealloc_count,
8813                                hint->inode->i_uid);
8814  #endif
8815 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
8816 -                                        hint->prealloc_size - nr_allocated -
8817 -                                        REISERFS_I(hint->inode)->
8818 -                                        i_prealloc_count);
8819 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
8820 +                       REISERFS_I(hint->inode)->i_prealloc_count;
8821 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
8822 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
8823         }
8824  
8825         return CARRY_ON;
8826 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/file.c linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/file.c
8827 --- linux-2.6.22.10/fs/reiserfs/file.c  2007-07-09 13:19:28 +0200
8828 +++ linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/file.c        2007-10-29 23:24:21 +0100
8829 @@ -1546,4 +1546,5 @@ const struct inode_operations reiserfs_f
8830         .listxattr = reiserfs_listxattr,
8831         .removexattr = reiserfs_removexattr,
8832         .permission = reiserfs_permission,
8833 +       .sync_flags = reiserfs_sync_flags,
8834  };
8835 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/inode.c linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/inode.c
8836 --- linux-2.6.22.10/fs/reiserfs/inode.c 2007-07-09 13:19:28 +0200
8837 +++ linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/inode.c       2007-06-15 02:37:03 +0200
8838 @@ -16,6 +16,8 @@
8839  #include <linux/mpage.h>
8840  #include <linux/writeback.h>
8841  #include <linux/quotaops.h>
8842 +#include <linux/vs_dlimit.h>
8843 +#include <linux/vs_tag.h>
8844  
8845  static int reiserfs_commit_write(struct file *f, struct page *page,
8846                                  unsigned from, unsigned to);
8847 @@ -50,6 +52,7 @@ void reiserfs_delete_inode(struct inode 
8848                  * stat data deletion */
8849                 if (!err) 
8850                         DQUOT_FREE_INODE(inode);
8851 +               DLIMIT_FREE_INODE(inode);
8852  
8853                 if (journal_end(&th, inode->i_sb, jbegin_count))
8854                         goto out;
8855 @@ -1112,6 +1115,8 @@ static void init_inode(struct inode *ino
8856         struct buffer_head *bh;
8857         struct item_head *ih;
8858         __u32 rdev;
8859 +       uid_t uid;
8860 +       gid_t gid;
8861         //int version = ITEM_VERSION_1;
8862  
8863         bh = PATH_PLAST_BUFFER(path);
8864 @@ -1135,12 +1140,13 @@ static void init_inode(struct inode *ino
8865                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
8866                 unsigned long blocks;
8867  
8868 +               uid = sd_v1_uid(sd);
8869 +               gid = sd_v1_gid(sd);
8870 +
8871                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
8872                 set_inode_sd_version(inode, STAT_DATA_V1);
8873                 inode->i_mode = sd_v1_mode(sd);
8874                 inode->i_nlink = sd_v1_nlink(sd);
8875 -               inode->i_uid = sd_v1_uid(sd);
8876 -               inode->i_gid = sd_v1_gid(sd);
8877                 inode->i_size = sd_v1_size(sd);
8878                 inode->i_atime.tv_sec = sd_v1_atime(sd);
8879                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
8880 @@ -1182,11 +1188,12 @@ static void init_inode(struct inode *ino
8881                 // (directories and symlinks)
8882                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
8883  
8884 +               uid    = sd_v2_uid(sd);
8885 +               gid    = sd_v2_gid(sd);
8886 +
8887                 inode->i_mode = sd_v2_mode(sd);
8888                 inode->i_nlink = sd_v2_nlink(sd);
8889 -               inode->i_uid = sd_v2_uid(sd);
8890                 inode->i_size = sd_v2_size(sd);
8891 -               inode->i_gid = sd_v2_gid(sd);
8892                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
8893                 inode->i_atime.tv_sec = sd_v2_atime(sd);
8894                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
8895 @@ -1216,6 +1223,10 @@ static void init_inode(struct inode *ino
8896                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
8897         }
8898  
8899 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
8900 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
8901 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
8902 +
8903         pathrelse(path);
8904         if (S_ISREG(inode->i_mode)) {
8905                 inode->i_op = &reiserfs_file_inode_operations;
8906 @@ -1238,13 +1249,15 @@ static void init_inode(struct inode *ino
8907  static void inode2sd(void *sd, struct inode *inode, loff_t size)
8908  {
8909         struct stat_data *sd_v2 = (struct stat_data *)sd;
8910 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
8911 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
8912         __u16 flags;
8913  
8914 +       set_sd_v2_uid(sd_v2, uid);
8915 +       set_sd_v2_gid(sd_v2, gid);
8916         set_sd_v2_mode(sd_v2, inode->i_mode);
8917         set_sd_v2_nlink(sd_v2, inode->i_nlink);
8918 -       set_sd_v2_uid(sd_v2, inode->i_uid);
8919         set_sd_v2_size(sd_v2, size);
8920 -       set_sd_v2_gid(sd_v2, inode->i_gid);
8921         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
8922         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
8923         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
8924 @@ -1775,6 +1788,10 @@ int reiserfs_new_inode(struct reiserfs_t
8925  
8926         BUG_ON(!th->t_trans_id);
8927  
8928 +       if (DLIMIT_ALLOC_INODE(inode)) {
8929 +               err = -ENOSPC;
8930 +               goto out_bad_dlimit;
8931 +       }
8932         if (DQUOT_ALLOC_INODE(inode)) {
8933                 err = -EDQUOT;
8934                 goto out_end_trans;
8935 @@ -1960,6 +1977,9 @@ int reiserfs_new_inode(struct reiserfs_t
8936         DQUOT_FREE_INODE(inode);
8937  
8938        out_end_trans:
8939 +       DLIMIT_FREE_INODE(inode);
8940 +
8941 +      out_bad_dlimit:
8942         journal_end(th, th->t_super, th->t_blocks_allocated);
8943         /* Drop can be outside and it needs more credits so it's better to have it outside */
8944         DQUOT_DROP(inode);
8945 @@ -2690,6 +2710,14 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
8946                         inode->i_flags |= S_IMMUTABLE;
8947                 else
8948                         inode->i_flags &= ~S_IMMUTABLE;
8949 +               if (sd_attrs & REISERFS_IUNLINK_FL)
8950 +                       inode->i_flags |= S_IUNLINK;
8951 +               else
8952 +                       inode->i_flags &= ~S_IUNLINK;
8953 +               if (sd_attrs & REISERFS_BARRIER_FL)
8954 +                       inode->i_flags |= S_BARRIER;
8955 +               else
8956 +                       inode->i_flags &= ~S_BARRIER;
8957                 if (sd_attrs & REISERFS_APPEND_FL)
8958                         inode->i_flags |= S_APPEND;
8959                 else
8960 @@ -2712,6 +2740,14 @@ void i_attrs_to_sd_attrs(struct inode *i
8961                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
8962                 else
8963                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
8964 +               if (inode->i_flags & S_IUNLINK)
8965 +                       *sd_attrs |= REISERFS_IUNLINK_FL;
8966 +               else
8967 +                       *sd_attrs &= ~REISERFS_IUNLINK_FL;
8968 +               if (inode->i_flags & S_BARRIER)
8969 +                       *sd_attrs |= REISERFS_BARRIER_FL;
8970 +               else
8971 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
8972                 if (inode->i_flags & S_SYNC)
8973                         *sd_attrs |= REISERFS_SYNC_FL;
8974                 else
8975 @@ -2891,6 +2927,22 @@ static ssize_t reiserfs_direct_IO(int rw
8976                                   reiserfs_get_blocks_direct_io, NULL);
8977  }
8978  
8979 +int reiserfs_sync_flags(struct inode *inode)
8980 +{
8981 +       u16 oldflags, newflags;
8982 +
8983 +       oldflags = REISERFS_I(inode)->i_attrs;
8984 +       newflags = oldflags;
8985 +       i_attrs_to_sd_attrs(inode, &newflags);
8986 +
8987 +       if (oldflags ^ newflags) {
8988 +               REISERFS_I(inode)->i_attrs = newflags;
8989 +               inode->i_ctime = CURRENT_TIME_SEC;
8990 +               mark_inode_dirty(inode);
8991 +       }
8992 +       return 0;
8993 +}
8994 +
8995  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
8996  {
8997         struct inode *inode = dentry->d_inode;
8998 @@ -2940,9 +2992,11 @@ int reiserfs_setattr(struct dentry *dent
8999         }
9000  
9001         error = inode_change_ok(inode, attr);
9002 +
9003         if (!error) {
9004                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
9005 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
9006 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
9007 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
9008                         error = reiserfs_chown_xattrs(inode, attr);
9009  
9010                         if (!error) {
9011 @@ -2972,6 +3026,9 @@ int reiserfs_setattr(struct dentry *dent
9012                                         inode->i_uid = attr->ia_uid;
9013                                 if (attr->ia_valid & ATTR_GID)
9014                                         inode->i_gid = attr->ia_gid;
9015 +                               if ((attr->ia_valid & ATTR_TAG) &&
9016 +                                       IS_TAGGED(inode))
9017 +                                       inode->i_tag = attr->ia_tag;
9018                                 mark_inode_dirty(inode);
9019                                 error =
9020                                     journal_end(&th, inode->i_sb, jbegin_count);
9021 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/ioctl.c
9022 --- linux-2.6.22.10/fs/reiserfs/ioctl.c 2007-02-06 03:01:29 +0100
9023 +++ linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/ioctl.c       2007-06-15 02:37:03 +0200
9024 @@ -4,6 +4,7 @@
9025  
9026  #include <linux/capability.h>
9027  #include <linux/fs.h>
9028 +#include <linux/mount.h>
9029  #include <linux/reiserfs_fs.h>
9030  #include <linux/time.h>
9031  #include <asm/uaccess.h>
9032 @@ -24,7 +25,7 @@ static int reiserfs_unpack(struct inode 
9033  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
9034                    unsigned long arg)
9035  {
9036 -       unsigned int flags;
9037 +       unsigned int flags, oldflags;
9038  
9039         switch (cmd) {
9040         case REISERFS_IOC_UNPACK:
9041 @@ -43,12 +44,14 @@ int reiserfs_ioctl(struct inode *inode, 
9042  
9043                 flags = REISERFS_I(inode)->i_attrs;
9044                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
9045 +               flags &= REISERFS_FL_USER_VISIBLE;
9046                 return put_user(flags, (int __user *)arg);
9047         case REISERFS_IOC_SETFLAGS:{
9048                         if (!reiserfs_attrs(inode->i_sb))
9049                                 return -ENOTTY;
9050  
9051 -                       if (IS_RDONLY(inode))
9052 +                       if (IS_RDONLY(inode) ||
9053 +                               (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9054                                 return -EROFS;
9055  
9056                         if ((current->fsuid != inode->i_uid)
9057 @@ -58,10 +61,12 @@ int reiserfs_ioctl(struct inode *inode, 
9058                         if (get_user(flags, (int __user *)arg))
9059                                 return -EFAULT;
9060  
9061 -                       if (((flags ^ REISERFS_I(inode)->
9062 -                             i_attrs) & (REISERFS_IMMUTABLE_FL |
9063 -                                         REISERFS_APPEND_FL))
9064 -                           && !capable(CAP_LINUX_IMMUTABLE))
9065 +                       oldflags = REISERFS_I(inode) -> i_attrs;
9066 +                       if (((oldflags & REISERFS_IMMUTABLE_FL) ||
9067 +                               ((flags ^ oldflags) &
9068 +                               (REISERFS_IMMUTABLE_FL | REISERFS_IUNLINK_FL |
9069 +                                REISERFS_APPEND_FL))) &&
9070 +                               !capable(CAP_LINUX_IMMUTABLE))
9071                                 return -EPERM;
9072  
9073                         if ((flags & REISERFS_NOTAIL_FL) &&
9074 @@ -72,6 +77,9 @@ int reiserfs_ioctl(struct inode *inode, 
9075                                 if (result)
9076                                         return result;
9077                         }
9078 +
9079 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
9080 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
9081                         sd_attrs_to_i_attrs(flags, inode);
9082                         REISERFS_I(inode)->i_attrs = flags;
9083                         inode->i_ctime = CURRENT_TIME_SEC;
9084 @@ -83,7 +91,8 @@ int reiserfs_ioctl(struct inode *inode, 
9085         case REISERFS_IOC_SETVERSION:
9086                 if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
9087                         return -EPERM;
9088 -               if (IS_RDONLY(inode))
9089 +               if (IS_RDONLY(inode) ||
9090 +                       (filp && MNT_IS_RDONLY(filp->f_vfsmnt)))
9091                         return -EROFS;
9092                 if (get_user(inode->i_generation, (int __user *)arg))
9093                         return -EFAULT;
9094 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/namei.c linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/namei.c
9095 --- linux-2.6.22.10/fs/reiserfs/namei.c 2007-07-09 13:19:28 +0200
9096 +++ linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/namei.c       2007-06-15 02:37:03 +0200
9097 @@ -17,6 +17,7 @@
9098  #include <linux/reiserfs_acl.h>
9099  #include <linux/reiserfs_xattr.h>
9100  #include <linux/quotaops.h>
9101 +#include <linux/vs_tag.h>
9102  
9103  #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; }
9104  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
9105 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
9106                         reiserfs_write_unlock(dir->i_sb);
9107                         return ERR_PTR(-EACCES);
9108                 }
9109 +               dx_propagate_tag(nd, inode);
9110  
9111                 /* Propogate the priv_object flag so we know we're in the priv tree */
9112                 if (is_reiserfs_priv_object(dir))
9113 @@ -595,6 +597,7 @@ static int new_inode_init(struct inode *
9114         } else {
9115                 inode->i_gid = current->fsgid;
9116         }
9117 +       inode->i_tag = dx_current_fstag(inode->i_sb);
9118         DQUOT_INIT(inode);
9119         return 0;
9120  }
9121 @@ -1541,6 +1544,7 @@ const struct inode_operations reiserfs_d
9122         .listxattr = reiserfs_listxattr,
9123         .removexattr = reiserfs_removexattr,
9124         .permission = reiserfs_permission,
9125 +       .sync_flags = reiserfs_sync_flags,
9126  };
9127  
9128  /*
9129 @@ -1557,6 +1561,7 @@ const struct inode_operations reiserfs_s
9130         .listxattr = reiserfs_listxattr,
9131         .removexattr = reiserfs_removexattr,
9132         .permission = reiserfs_permission,
9133 +       .sync_flags = reiserfs_sync_flags,
9134  
9135  };
9136  
9137 @@ -1570,5 +1575,6 @@ const struct inode_operations reiserfs_s
9138         .listxattr = reiserfs_listxattr,
9139         .removexattr = reiserfs_removexattr,
9140         .permission = reiserfs_permission,
9141 +       .sync_flags = reiserfs_sync_flags,
9142  
9143  };
9144 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/stree.c linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/stree.c
9145 --- linux-2.6.22.10/fs/reiserfs/stree.c 2007-07-09 13:19:28 +0200
9146 +++ linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/stree.c       2007-06-15 02:37:03 +0200
9147 @@ -55,6 +55,7 @@
9148  #include <linux/reiserfs_fs.h>
9149  #include <linux/buffer_head.h>
9150  #include <linux/quotaops.h>
9151 +#include <linux/vs_dlimit.h>
9152  
9153  /* Does the buffer contain a disk block which is in the tree. */
9154  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
9155 @@ -1296,6 +1297,7 @@ int reiserfs_delete_item(struct reiserfs
9156                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
9157                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
9158  #endif
9159 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9160         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9161  
9162         /* Return deleted body length */
9163 @@ -1384,6 +1386,7 @@ void reiserfs_delete_solid_item(struct r
9164  #endif
9165                                 DQUOT_FREE_SPACE_NODIRTY(inode,
9166                                                          quota_cut_bytes);
9167 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
9168                         }
9169                         break;
9170                 }
9171 @@ -1737,6 +1740,7 @@ int reiserfs_cut_from_item(struct reiser
9172                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
9173                        quota_cut_bytes, p_s_inode->i_uid, '?');
9174  #endif
9175 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
9176         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
9177         return n_ret_value;
9178  }
9179 @@ -1978,6 +1982,11 @@ int reiserfs_paste_into_item(struct reis
9180                 pathrelse(p_s_search_path);
9181                 return -EDQUOT;
9182         }
9183 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
9184 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9185 +               pathrelse(p_s_search_path);
9186 +               return -ENOSPC;
9187 +       }
9188         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
9189                        n_pasted_size);
9190  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
9191 @@ -2030,6 +2039,7 @@ int reiserfs_paste_into_item(struct reis
9192                        n_pasted_size, inode->i_uid,
9193                        key2type(&(p_s_key->on_disk_key)));
9194  #endif
9195 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
9196         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
9197         return retval;
9198  }
9199 @@ -2067,6 +2077,11 @@ int reiserfs_insert_item(struct reiserfs
9200                         pathrelse(p_s_path);
9201                         return -EDQUOT;
9202                 }
9203 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
9204 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9205 +                       pathrelse(p_s_path);
9206 +                       return -ENOSPC;
9207 +               }
9208         }
9209         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
9210                        IH_SIZE + ih_item_len(p_s_ih));
9211 @@ -2114,7 +2129,9 @@ int reiserfs_insert_item(struct reiserfs
9212                        "reiserquota insert_item(): freeing %u id=%u type=%c",
9213                        quota_bytes, inode->i_uid, head2type(p_s_ih));
9214  #endif
9215 -       if (inode)
9216 +       if (inode) {
9217 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
9218                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
9219 +       }
9220         return retval;
9221  }
9222 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/super.c linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/super.c
9223 --- linux-2.6.22.10/fs/reiserfs/super.c 2007-07-09 13:19:28 +0200
9224 +++ linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/super.c       2007-06-15 02:37:03 +0200
9225 @@ -882,6 +882,14 @@ static int reiserfs_parse_options(struct
9226                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
9227                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
9228  #endif
9229 +#ifndef CONFIG_TAGGING_NONE
9230 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
9231 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
9232 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
9233 +#endif
9234 +#ifdef CONFIG_PROPAGATE
9235 +               {"tag",.arg_required = 'T',.values = NULL},
9236 +#endif
9237  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
9238                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
9239                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
9240 @@ -1143,6 +1151,12 @@ static int reiserfs_remount(struct super
9241                 return -EINVAL;
9242         }
9243  
9244 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
9245 +               !(s->s_flags & MS_TAGGED)) {
9246 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
9247 +               return -EINVAL;
9248 +       }
9249 +
9250         handle_attrs(s);
9251  
9252         /* Add options that are safe here */
9253 @@ -1591,6 +1605,10 @@ static int reiserfs_fill_super(struct su
9254                 goto error;
9255         }
9256  
9257 +       /* map mount option tagxid */
9258 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
9259 +               s->s_flags |= MS_TAGGED;
9260 +
9261         rs = SB_DISK_SUPER_BLOCK(s);
9262         /* Let's do basic sanity check to verify that underlying device is not
9263            smaller than the filesystem. If the check fails then abort and scream,
9264 diff -NurpP --minimal linux-2.6.22.10/fs/reiserfs/xattr.c linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/xattr.c
9265 --- linux-2.6.22.10/fs/reiserfs/xattr.c 2007-07-09 13:19:28 +0200
9266 +++ linux-2.6.22.10-vs2.2.0.5/fs/reiserfs/xattr.c       2007-06-15 02:37:04 +0200
9267 @@ -35,6 +35,7 @@
9268  #include <linux/namei.h>
9269  #include <linux/errno.h>
9270  #include <linux/fs.h>
9271 +#include <linux/mount.h>
9272  #include <linux/file.h>
9273  #include <linux/pagemap.h>
9274  #include <linux/xattr.h>
9275 @@ -775,7 +776,7 @@ int reiserfs_delete_xattrs(struct inode 
9276         if (dir->d_inode->i_nlink <= 2) {
9277                 root = get_xa_root(inode->i_sb, XATTR_REPLACE);
9278                 reiserfs_write_lock_xattrs(inode->i_sb);
9279 -               err = vfs_rmdir(root->d_inode, dir);
9280 +               err = vfs_rmdir(root->d_inode, dir, NULL);
9281                 reiserfs_write_unlock_xattrs(inode->i_sb);
9282                 dput(root);
9283         } else {
9284 diff -NurpP --minimal linux-2.6.22.10/fs/stat.c linux-2.6.22.10-vs2.2.0.5/fs/stat.c
9285 --- linux-2.6.22.10/fs/stat.c   2007-07-09 13:19:28 +0200
9286 +++ linux-2.6.22.10-vs2.2.0.5/fs/stat.c 2007-06-15 02:37:04 +0200
9287 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
9288         stat->nlink = inode->i_nlink;
9289         stat->uid = inode->i_uid;
9290         stat->gid = inode->i_gid;
9291 +       stat->tag = inode->i_tag;
9292         stat->rdev = inode->i_rdev;
9293         stat->atime = inode->i_atime;
9294         stat->mtime = inode->i_mtime;
9295 diff -NurpP --minimal linux-2.6.22.10/fs/super.c linux-2.6.22.10-vs2.2.0.5/fs/super.c
9296 --- linux-2.6.22.10/fs/super.c  2007-07-09 13:19:28 +0200
9297 +++ linux-2.6.22.10-vs2.2.0.5/fs/super.c        2007-06-15 03:26:55 +0200
9298 @@ -37,6 +37,9 @@
9299  #include <linux/idr.h>
9300  #include <linux/kobject.h>
9301  #include <linux/mutex.h>
9302 +#include <linux/devpts_fs.h>
9303 +#include <linux/proc_fs.h>
9304 +#include <linux/vs_context.h>
9305  #include <asm/uaccess.h>
9306  
9307  
9308 @@ -860,12 +863,18 @@ struct vfsmount *
9309  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
9310  {
9311         struct vfsmount *mnt;
9312 +       struct super_block *sb;
9313         char *secdata = NULL;
9314         int error;
9315  
9316         if (!type)
9317                 return ERR_PTR(-ENODEV);
9318  
9319 +       error = -EPERM;
9320 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
9321 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
9322 +               goto out;
9323 +
9324         error = -ENOMEM;
9325         mnt = alloc_vfsmnt(name);
9326         if (!mnt)
9327 @@ -885,7 +894,14 @@ vfs_kern_mount(struct file_system_type *
9328         if (error < 0)
9329                 goto out_free_secdata;
9330  
9331 -       error = security_sb_kern_mount(mnt->mnt_sb, secdata);
9332 +       sb = mnt->mnt_sb;
9333 +       error = -EPERM;
9334 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
9335 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
9336 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
9337 +               goto out_sb;
9338 +
9339 +       error = security_sb_kern_mount(sb, secdata);
9340         if (error)
9341                 goto out_sb;
9342  
9343 diff -NurpP --minimal linux-2.6.22.10/fs/sysfs/mount.c linux-2.6.22.10-vs2.2.0.5/fs/sysfs/mount.c
9344 --- linux-2.6.22.10/fs/sysfs/mount.c    2007-07-09 13:19:28 +0200
9345 +++ linux-2.6.22.10-vs2.2.0.5/fs/sysfs/mount.c  2007-06-17 05:54:17 +0200
9346 @@ -12,8 +12,6 @@
9347  
9348  #include "sysfs.h"
9349  
9350 -/* Random magic number */
9351 -#define SYSFS_MAGIC 0x62656572
9352  
9353  struct vfsmount *sysfs_mount;
9354  struct super_block * sysfs_sb = NULL;
9355 @@ -48,7 +46,7 @@ static int sysfs_fill_super(struct super
9356  
9357         sb->s_blocksize = PAGE_CACHE_SIZE;
9358         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
9359 -       sb->s_magic = SYSFS_MAGIC;
9360 +       sb->s_magic = SYSFS_SUPER_MAGIC;
9361         sb->s_op = &sysfs_ops;
9362         sb->s_time_gran = 1;
9363         sysfs_sb = sb;
9364 diff -NurpP --minimal linux-2.6.22.10/fs/utimes.c linux-2.6.22.10-vs2.2.0.5/fs/utimes.c
9365 --- linux-2.6.22.10/fs/utimes.c 2007-07-09 13:19:29 +0200
9366 +++ linux-2.6.22.10-vs2.2.0.5/fs/utimes.c       2007-07-09 13:11:54 +0200
9367 @@ -6,6 +6,8 @@
9368  #include <linux/sched.h>
9369  #include <linux/stat.h>
9370  #include <linux/utime.h>
9371 +#include <linux/mount.h>
9372 +#include <linux/vs_cowbl.h>
9373  #include <asm/uaccess.h>
9374  #include <asm/unistd.h>
9375  
9376 @@ -70,14 +72,16 @@ long do_utimes(int dfd, char __user *fil
9377                 if (error)
9378                         goto out;
9379  
9380 +               error = cow_check_and_break(&nd);
9381 +               if (error)
9382 +                       goto dput_and_out;
9383                 dentry = nd.dentry;
9384         }
9385  
9386         inode = dentry->d_inode;
9387 -
9388         error = -EROFS;
9389         if (IS_RDONLY(inode))
9390 -               goto dput_and_out;
9391 +               goto dput_and_out;
9392  
9393         /* Don't worry, the checks are done in inode_change_ok() */
9394         newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
9395 diff -NurpP --minimal linux-2.6.22.10/fs/xattr.c linux-2.6.22.10-vs2.2.0.5/fs/xattr.c
9396 --- linux-2.6.22.10/fs/xattr.c  2007-07-09 13:19:29 +0200
9397 +++ linux-2.6.22.10-vs2.2.0.5/fs/xattr.c        2007-06-15 02:37:04 +0200
9398 @@ -17,6 +17,7 @@
9399  #include <linux/module.h>
9400  #include <linux/fsnotify.h>
9401  #include <linux/audit.h>
9402 +#include <linux/mount.h>
9403  #include <asm/uaccess.h>
9404  
9405  
9406 @@ -194,7 +195,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
9407   */
9408  static long
9409  setxattr(struct dentry *d, char __user *name, void __user *value,
9410 -        size_t size, int flags)
9411 +        size_t size, int flags, struct vfsmount *mnt)
9412  {
9413         int error;
9414         void *kvalue = NULL;
9415 @@ -221,6 +222,9 @@ setxattr(struct dentry *d, char __user *
9416                 }
9417         }
9418  
9419 +       if (MNT_IS_RDONLY(mnt))
9420 +               return -EROFS;
9421 +
9422         error = vfs_setxattr(d, kname, kvalue, size, flags);
9423         kfree(kvalue);
9424         return error;
9425 @@ -236,7 +240,7 @@ sys_setxattr(char __user *path, char __u
9426         error = user_path_walk(path, &nd);
9427         if (error)
9428                 return error;
9429 -       error = setxattr(nd.dentry, name, value, size, flags);
9430 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
9431         path_release(&nd);
9432         return error;
9433  }
9434 @@ -251,7 +255,7 @@ sys_lsetxattr(char __user *path, char __
9435         error = user_path_walk_link(path, &nd);
9436         if (error)
9437                 return error;
9438 -       error = setxattr(nd.dentry, name, value, size, flags);
9439 +       error = setxattr(nd.dentry, name, value, size, flags, nd.mnt);
9440         path_release(&nd);
9441         return error;
9442  }
9443 @@ -269,7 +273,7 @@ sys_fsetxattr(int fd, char __user *name,
9444                 return error;
9445         dentry = f->f_path.dentry;
9446         audit_inode(NULL, dentry->d_inode);
9447 -       error = setxattr(dentry, name, value, size, flags);
9448 +       error = setxattr(dentry, name, value, size, flags, f->f_vfsmnt);
9449         fput(f);
9450         return error;
9451  }
9452 @@ -433,7 +437,7 @@ sys_flistxattr(int fd, char __user *list
9453   * Extended attribute REMOVE operations
9454   */
9455  static long
9456 -removexattr(struct dentry *d, char __user *name)
9457 +removexattr(struct dentry *d, char __user *name, struct vfsmount *mnt)
9458  {
9459         int error;
9460         char kname[XATTR_NAME_MAX + 1];
9461 @@ -444,6 +448,9 @@ removexattr(struct dentry *d, char __use
9462         if (error < 0)
9463                 return error;
9464  
9465 +       if (MNT_IS_RDONLY(mnt))
9466 +               return -EROFS;
9467 +
9468         return vfs_removexattr(d, kname);
9469  }
9470  
9471 @@ -456,7 +463,7 @@ sys_removexattr(char __user *path, char 
9472         error = user_path_walk(path, &nd);
9473         if (error)
9474                 return error;
9475 -       error = removexattr(nd.dentry, name);
9476 +       error = removexattr(nd.dentry, name, nd.mnt);
9477         path_release(&nd);
9478         return error;
9479  }
9480 @@ -470,7 +477,7 @@ sys_lremovexattr(char __user *path, char
9481         error = user_path_walk_link(path, &nd);
9482         if (error)
9483                 return error;
9484 -       error = removexattr(nd.dentry, name);
9485 +       error = removexattr(nd.dentry, name, nd.mnt);
9486         path_release(&nd);
9487         return error;
9488  }
9489 @@ -487,7 +494,7 @@ sys_fremovexattr(int fd, char __user *na
9490                 return error;
9491         dentry = f->f_path.dentry;
9492         audit_inode(NULL, dentry->d_inode);
9493 -       error = removexattr(dentry, name);
9494 +       error = removexattr(dentry, name, f->f_vfsmnt);
9495         fput(f);
9496         return error;
9497  }
9498 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_ioctl.c
9499 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_ioctl.c        2007-05-02 19:25:22 +0200
9500 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_ioctl.c      2007-06-15 02:37:04 +0200
9501 @@ -1128,6 +1128,10 @@ xfs_di2lxflags(
9502  
9503         if (di_flags & XFS_DIFLAG_IMMUTABLE)
9504                 flags |= FS_IMMUTABLE_FL;
9505 +       if (di_flags & XFS_DIFLAG_IUNLINK)
9506 +               flags |= FS_IUNLINK_FL;
9507 +       if (di_flags & XFS_DIFLAG_BARRIER)
9508 +               flags |= FS_BARRIER_FL;
9509         if (di_flags & XFS_DIFLAG_APPEND)
9510                 flags |= FS_APPEND_FL;
9511         if (di_flags & XFS_DIFLAG_SYNC)
9512 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_iops.c
9513 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_iops.c 2007-05-02 19:25:22 +0200
9514 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_iops.c       2007-06-15 02:37:04 +0200
9515 @@ -51,6 +51,7 @@
9516  #include <linux/xattr.h>
9517  #include <linux/namei.h>
9518  #include <linux/security.h>
9519 +#include <linux/vs_tag.h>
9520  
9521  /*
9522   * Get a XFS inode from a given vnode.
9523 @@ -400,6 +401,7 @@ xfs_vn_lookup(
9524                 d_add(dentry, NULL);
9525                 return NULL;
9526         }
9527 +       dx_propagate_tag(nd, vn_to_inode(cvp));
9528  
9529         return d_splice_alias(vn_to_inode(cvp), dentry);
9530  }
9531 @@ -657,6 +659,10 @@ xfs_vn_setattr(
9532         int             flags = 0;
9533         int             error;
9534  
9535 +       error = inode_change_ok(inode, attr);
9536 +       if (error)
9537 +               return error;
9538 +
9539         if (ia_valid & ATTR_UID) {
9540                 vattr.va_mask |= XFS_AT_UID;
9541                 vattr.va_uid = attr->ia_uid;
9542 @@ -665,6 +671,10 @@ xfs_vn_setattr(
9543                 vattr.va_mask |= XFS_AT_GID;
9544                 vattr.va_gid = attr->ia_gid;
9545         }
9546 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode)) {
9547 +               vattr.va_mask |= XFS_AT_TAG;
9548 +               vattr.va_tag = attr->ia_tag;
9549 +       }
9550         if (ia_valid & ATTR_SIZE) {
9551                 vattr.va_mask |= XFS_AT_SIZE;
9552                 vattr.va_size = attr->ia_size;
9553 @@ -710,6 +720,42 @@ xfs_vn_truncate(
9554  }
9555  
9556  STATIC int
9557 +xfs_vn_sync_flags(struct inode *inode)
9558 +{
9559 +       unsigned int oldflags, newflags;
9560 +       int             flags = 0;
9561 +       int             error;
9562 +       bhv_vattr_t     vattr;
9563 +       bhv_vnode_t     *vp = vn_from_inode(inode);
9564 +
9565 +       memset(&vattr, 0, sizeof vattr);
9566 +
9567 +       vattr.va_mask = XFS_AT_XFLAGS;
9568 +       error = bhv_vop_getattr(vp, &vattr, 0, NULL);
9569 +
9570 +       if (error)
9571 +               return error;
9572 +       oldflags = vattr.va_xflags;
9573 +       newflags = oldflags & ~(XFS_XFLAG_IMMUTABLE |
9574 +               XFS_XFLAG_IUNLINK | XFS_XFLAG_BARRIER);
9575 +
9576 +       if (IS_IMMUTABLE(inode))
9577 +               newflags |= XFS_XFLAG_IMMUTABLE;
9578 +       if (IS_IUNLINK(inode))
9579 +               newflags |= XFS_XFLAG_IUNLINK;
9580 +       if (IS_BARRIER(inode))
9581 +               newflags |= XFS_XFLAG_BARRIER;
9582 +
9583 +       if (oldflags ^ newflags) {
9584 +               vattr.va_xflags = newflags;
9585 +               vattr.va_mask |= XFS_AT_XFLAGS;
9586 +               error = bhv_vop_setattr(vp, &vattr, flags, NULL);
9587 +       }
9588 +       vn_revalidate(vp);
9589 +       return error;
9590 +}
9591 +
9592 +STATIC int
9593  xfs_vn_setxattr(
9594         struct dentry   *dentry,
9595         const char      *name,
9596 @@ -822,6 +868,7 @@ const struct inode_operations xfs_inode_
9597         .getxattr               = xfs_vn_getxattr,
9598         .listxattr              = xfs_vn_listxattr,
9599         .removexattr            = xfs_vn_removexattr,
9600 +       .sync_flags             = xfs_vn_sync_flags,
9601  };
9602  
9603  const struct inode_operations xfs_dir_inode_operations = {
9604 @@ -841,6 +888,7 @@ const struct inode_operations xfs_dir_in
9605         .getxattr               = xfs_vn_getxattr,
9606         .listxattr              = xfs_vn_listxattr,
9607         .removexattr            = xfs_vn_removexattr,
9608 +       .sync_flags             = xfs_vn_sync_flags,
9609  };
9610  
9611  const struct inode_operations xfs_symlink_inode_operations = {
9612 @@ -854,4 +902,5 @@ const struct inode_operations xfs_symlin
9613         .getxattr               = xfs_vn_getxattr,
9614         .listxattr              = xfs_vn_listxattr,
9615         .removexattr            = xfs_vn_removexattr,
9616 +       .sync_flags             = xfs_vn_sync_flags,
9617  };
9618 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_linux.h
9619 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_linux.h        2007-05-02 19:25:22 +0200
9620 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_linux.h      2007-06-15 02:37:04 +0200
9621 @@ -129,6 +129,7 @@
9622  #define current_pid()          (current->pid)
9623  #define current_fsuid(cred)    (current->fsuid)
9624  #define current_fsgid(cred)    (current->fsgid)
9625 +#define current_fstag(cred,vp) (dx_current_fstag(vn_to_inode(vp)->i_sb))
9626  #define current_test_flags(f)  (current->flags & (f))
9627  #define current_set_flags_nested(sp, f)                \
9628                 (*(sp) = current->flags, current->flags |= (f))
9629 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_super.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_super.c
9630 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_super.c        2007-07-09 13:19:29 +0200
9631 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_super.c      2007-06-15 02:37:04 +0200
9632 @@ -157,6 +157,7 @@ xfs_revalidate_inode(
9633         inode->i_nlink  = ip->i_d.di_nlink;
9634         inode->i_uid    = ip->i_d.di_uid;
9635         inode->i_gid    = ip->i_d.di_gid;
9636 +       inode->i_tag    = ip->i_d.di_tag;
9637  
9638         switch (inode->i_mode & S_IFMT) {
9639         case S_IFBLK:
9640 @@ -184,6 +185,14 @@ xfs_revalidate_inode(
9641                 inode->i_flags |= S_IMMUTABLE;
9642         else
9643                 inode->i_flags &= ~S_IMMUTABLE;
9644 +       if (ip->i_d.di_flags & XFS_DIFLAG_IUNLINK)
9645 +               inode->i_flags |= S_IUNLINK;
9646 +       else
9647 +               inode->i_flags &= ~S_IUNLINK;
9648 +       if (ip->i_d.di_flags & XFS_DIFLAG_BARRIER)
9649 +               inode->i_flags |= S_BARRIER;
9650 +       else
9651 +               inode->i_flags &= ~S_BARRIER;
9652         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
9653                 inode->i_flags |= S_APPEND;
9654         else
9655 @@ -712,6 +721,12 @@ xfs_fs_remount(
9656         int                     error;
9657  
9658         error = bhv_vfs_parseargs(vfsp, options, args, 1);
9659 +       if ((args->flags2 & XFSMNT2_TAGGED) &&
9660 +               !(sb->s_flags & MS_TAGGED)) {
9661 +               printk("XFS: %s: tagging not permitted on remount.\n",
9662 +                       sb->s_id);
9663 +               error = EINVAL;
9664 +       }
9665         if (!error)
9666                 error = bhv_vfs_mntupdate(vfsp, flags, args);
9667         kmem_free(args, sizeof(*args));
9668 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_vnode.c
9669 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.c        2007-05-02 19:25:22 +0200
9670 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_vnode.c      2007-06-15 02:37:04 +0200
9671 @@ -119,6 +119,7 @@ vn_revalidate_core(
9672         inode->i_nlink      = vap->va_nlink;
9673         inode->i_uid        = vap->va_uid;
9674         inode->i_gid        = vap->va_gid;
9675 +       inode->i_tag        = vap->va_tag;
9676         inode->i_blocks     = vap->va_nblocks;
9677         inode->i_mtime      = vap->va_mtime;
9678         inode->i_ctime      = vap->va_ctime;
9679 @@ -126,6 +127,14 @@ vn_revalidate_core(
9680                 inode->i_flags |= S_IMMUTABLE;
9681         else
9682                 inode->i_flags &= ~S_IMMUTABLE;
9683 +       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
9684 +               inode->i_flags |= S_IUNLINK;
9685 +       else
9686 +               inode->i_flags &= ~S_IUNLINK;
9687 +       if (vap->va_xflags & XFS_XFLAG_BARRIER)
9688 +               inode->i_flags |= S_BARRIER;
9689 +       else
9690 +               inode->i_flags &= ~S_BARRIER;
9691         if (vap->va_xflags & XFS_XFLAG_APPEND)
9692                 inode->i_flags |= S_APPEND;
9693         else
9694 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.h linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_vnode.h
9695 --- linux-2.6.22.10/fs/xfs/linux-2.6/xfs_vnode.h        2007-07-09 13:19:29 +0200
9696 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/linux-2.6/xfs_vnode.h      2007-06-15 02:37:04 +0200
9697 @@ -350,6 +350,7 @@ typedef struct bhv_vattr {
9698         xfs_nlink_t     va_nlink;       /* number of references to file */
9699         uid_t           va_uid;         /* owner user id */
9700         gid_t           va_gid;         /* owner group id */
9701 +       tag_t           va_tag;         /* owner group id */
9702         xfs_ino_t       va_nodeid;      /* file id */
9703         xfs_off_t       va_size;        /* file size in bytes */
9704         u_long          va_blocksize;   /* blocksize preferred for i/o */
9705 @@ -398,13 +399,15 @@ typedef struct bhv_vattr {
9706  #define XFS_AT_PROJID          0x04000000
9707  #define XFS_AT_SIZE_NOPERM     0x08000000
9708  #define XFS_AT_GENCOUNT                0x10000000
9709 +#define XFS_AT_TAG             0x20000000
9710  
9711  #define XFS_AT_ALL     (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
9712                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
9713                 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
9714                 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
9715                 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
9716 -               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
9717 +               XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT\
9718 +               XFS_AT_TAG)
9719  
9720  #define XFS_AT_STAT    (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
9721                 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
9722 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/quota/xfs_qm_syscalls.c
9723 --- linux-2.6.22.10/fs/xfs/quota/xfs_qm_syscalls.c      2007-07-09 13:19:29 +0200
9724 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/quota/xfs_qm_syscalls.c    2007-06-15 02:37:04 +0200
9725 @@ -17,6 +17,7 @@
9726   */
9727  
9728  #include <linux/capability.h>
9729 +#include <linux/vs_context.h>
9730  
9731  #include "xfs.h"
9732  #include "xfs_fs.h"
9733 @@ -211,7 +212,7 @@ xfs_qm_scall_quotaoff(
9734         xfs_qoff_logitem_t      *qoffstart;
9735         int                     nculprits;
9736  
9737 -       if (!force && !capable(CAP_SYS_ADMIN))
9738 +       if (!force && !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9739                 return XFS_ERROR(EPERM);
9740         /*
9741          * No file system can have quotas enabled on disk but not in core.
9742 @@ -380,7 +381,7 @@ xfs_qm_scall_trunc_qfiles(
9743         int             error;
9744         xfs_inode_t     *qip;
9745  
9746 -       if (!capable(CAP_SYS_ADMIN))
9747 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9748                 return XFS_ERROR(EPERM);
9749         error = 0;
9750         if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) {
9751 @@ -425,7 +426,7 @@ xfs_qm_scall_quotaon(
9752         uint            accflags;
9753         __int64_t       sbflags;
9754  
9755 -       if (!capable(CAP_SYS_ADMIN))
9756 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9757                 return XFS_ERROR(EPERM);
9758  
9759         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
9760 @@ -594,7 +595,7 @@ xfs_qm_scall_setqlim(
9761         int                     error;
9762         xfs_qcnt_t              hard, soft;
9763  
9764 -       if (!capable(CAP_SYS_ADMIN))
9765 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
9766                 return XFS_ERROR(EPERM);
9767  
9768         if ((newlim->d_fieldmask &
9769 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_clnt.h linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_clnt.h
9770 --- linux-2.6.22.10/fs/xfs/xfs_clnt.h   2006-06-18 04:54:50 +0200
9771 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_clnt.h 2007-06-15 02:37:04 +0200
9772 @@ -99,5 +99,7 @@ struct xfs_mount_args {
9773   */
9774  #define XFSMNT2_COMPAT_IOSIZE  0x00000001      /* don't report large preferred
9775                                                  * I/O size in stat(2) */
9776 +#define XFSMNT2_TAGGED         0x80000000      /* context tagging */
9777 +
9778  
9779  #endif /* __XFS_CLNT_H__ */
9780 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_dinode.h linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_dinode.h
9781 --- linux-2.6.22.10/fs/xfs/xfs_dinode.h 2006-09-20 16:58:40 +0200
9782 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_dinode.h       2007-06-15 02:37:04 +0200
9783 @@ -53,7 +53,8 @@ typedef struct xfs_dinode_core
9784         __uint32_t      di_gid;         /* owner's group id */
9785         __uint32_t      di_nlink;       /* number of links to file */
9786         __uint16_t      di_projid;      /* owner's project id */
9787 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
9788 +       __uint16_t      di_tag;         /* context tagging */
9789 +       __uint8_t       di_pad[6];      /* unused, zeroed space */
9790         __uint16_t      di_flushiter;   /* incremented on flush */
9791         xfs_timestamp_t di_atime;       /* time last accessed */
9792         xfs_timestamp_t di_mtime;       /* time last modified */
9793 @@ -257,6 +258,9 @@ typedef enum xfs_dinode_fmt
9794  #define XFS_DIFLAG_EXTSIZE_BIT      11 /* inode extent size allocator hint */
9795  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
9796  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
9797 +#define XFS_DIFLAG_BARRIER_BIT 14      /* chroot() barrier */
9798 +#define XFS_DIFLAG_IUNLINK_BIT 15      /* immutable unlink */
9799 +
9800  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
9801  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
9802  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
9803 @@ -271,12 +275,15 @@ typedef enum xfs_dinode_fmt
9804  #define XFS_DIFLAG_EXTSIZE       (1 << XFS_DIFLAG_EXTSIZE_BIT)
9805  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
9806  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
9807 +#define XFS_DIFLAG_BARRIER      (1 << XFS_DIFLAG_BARRIER_BIT)
9808 +#define XFS_DIFLAG_IUNLINK      (1 << XFS_DIFLAG_IUNLINK_BIT)
9809  
9810  #define XFS_DIFLAG_ANY \
9811         (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
9812          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
9813          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
9814          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
9815 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG)
9816 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_BARRIER | \
9817 +        XFS_DIFLAG_IUNLINK)
9818  
9819  #endif /* __XFS_DINODE_H__ */
9820 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_fs.h linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_fs.h
9821 --- linux-2.6.22.10/fs/xfs/xfs_fs.h     2006-11-30 21:19:29 +0100
9822 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_fs.h   2007-06-15 02:37:04 +0200
9823 @@ -66,6 +66,8 @@ struct fsxattr {
9824  #define XFS_XFLAG_EXTSIZE      0x00000800      /* extent size allocator hint */
9825  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
9826  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
9827 +#define XFS_XFLAG_BARRIER      0x00004000      /* chroot() barrier */
9828 +#define XFS_XFLAG_IUNLINK      0x00008000      /* immutable unlink */
9829  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
9830  
9831  /*
9832 @@ -294,7 +296,8 @@ typedef struct xfs_bstat {
9833         __s32           bs_extents;     /* number of extents            */
9834         __u32           bs_gen;         /* generation count             */
9835         __u16           bs_projid;      /* project id                   */
9836 -       unsigned char   bs_pad[14];     /* pad space, unused            */
9837 +       __u16           bs_tag;         /* context tagging              */
9838 +       unsigned char   bs_pad[12];     /* pad space, unused            */
9839         __u32           bs_dmevmask;    /* DMIG event mask              */
9840         __u16           bs_dmstate;     /* DMIG state info              */
9841         __u16           bs_aextents;    /* attribute number of extents  */
9842 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_inode.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_inode.c
9843 --- linux-2.6.22.10/fs/xfs/xfs_inode.c  2007-07-09 13:19:34 +0200
9844 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_inode.c        2007-06-15 02:37:04 +0200
9845 @@ -49,6 +49,7 @@
9846  #include "xfs_quota.h"
9847  #include "xfs_acl.h"
9848  
9849 +#include <linux/vs_tag.h>
9850  
9851  kmem_zone_t *xfs_ifork_zone;
9852  kmem_zone_t *xfs_inode_zone;
9853 @@ -736,20 +737,35 @@ xfs_xlate_dinode_core(
9854         xfs_dinode_core_t       *buf_core = (xfs_dinode_core_t *)buf;
9855         xfs_dinode_core_t       *mem_core = (xfs_dinode_core_t *)dip;
9856         xfs_arch_t              arch = ARCH_CONVERT;
9857 +       uint32_t                uid = 0, gid = 0;
9858 +       uint16_t                tag = 0;
9859  
9860         ASSERT(dir);
9861  
9862 +       if (dir < 0) {
9863 +               tag = mem_core->di_tag;
9864 +               /* FIXME: supposed to use superblock flag */
9865 +               uid = TAGINO_UID(1, mem_core->di_uid, tag);
9866 +               gid = TAGINO_GID(1, mem_core->di_gid, tag);
9867 +               tag = TAGINO_TAG(1, tag);
9868 +       }
9869 +
9870         INT_XLATE(buf_core->di_magic, mem_core->di_magic, dir, arch);
9871         INT_XLATE(buf_core->di_mode, mem_core->di_mode, dir, arch);
9872         INT_XLATE(buf_core->di_version, mem_core->di_version, dir, arch);
9873         INT_XLATE(buf_core->di_format, mem_core->di_format, dir, arch);
9874         INT_XLATE(buf_core->di_onlink, mem_core->di_onlink, dir, arch);
9875 -       INT_XLATE(buf_core->di_uid, mem_core->di_uid, dir, arch);
9876 -       INT_XLATE(buf_core->di_gid, mem_core->di_gid, dir, arch);
9877 +       INT_XLATE(buf_core->di_uid, uid, dir, arch);
9878 +       INT_XLATE(buf_core->di_gid, gid, dir, arch);
9879 +       INT_XLATE(buf_core->di_tag, tag, dir, arch);
9880         INT_XLATE(buf_core->di_nlink, mem_core->di_nlink, dir, arch);
9881         INT_XLATE(buf_core->di_projid, mem_core->di_projid, dir, arch);
9882  
9883         if (dir > 0) {
9884 +               /* FIXME: supposed to use superblock flag */
9885 +               mem_core->di_uid = INOTAG_UID(1, uid, gid);
9886 +               mem_core->di_gid = INOTAG_GID(1, uid, gid);
9887 +               mem_core->di_tag = INOTAG_TAG(1, uid, gid, tag);
9888                 memcpy(mem_core->di_pad, buf_core->di_pad,
9889                         sizeof(buf_core->di_pad));
9890         } else {
9891 @@ -797,6 +813,10 @@ _xfs_dic2xflags(
9892                         flags |= XFS_XFLAG_PREALLOC;
9893                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
9894                         flags |= XFS_XFLAG_IMMUTABLE;
9895 +               if (di_flags & XFS_DIFLAG_IUNLINK)
9896 +                       flags |= XFS_XFLAG_IUNLINK;
9897 +               if (di_flags & XFS_DIFLAG_BARRIER)
9898 +                       flags |= XFS_XFLAG_BARRIER;
9899                 if (di_flags & XFS_DIFLAG_APPEND)
9900                         flags |= XFS_XFLAG_APPEND;
9901                 if (di_flags & XFS_DIFLAG_SYNC)
9902 @@ -1129,6 +1149,7 @@ xfs_ialloc(
9903         ASSERT(ip->i_d.di_nlink == nlink);
9904         ip->i_d.di_uid = current_fsuid(cr);
9905         ip->i_d.di_gid = current_fsgid(cr);
9906 +       ip->i_d.di_tag = current_fstag(cr, vp);
9907         ip->i_d.di_projid = prid;
9908         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
9909  
9910 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_itable.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_itable.c
9911 --- linux-2.6.22.10/fs/xfs/xfs_itable.c 2007-07-09 13:19:34 +0200
9912 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_itable.c       2007-06-15 02:37:04 +0200
9913 @@ -89,6 +89,7 @@ xfs_bulkstat_one_iget(
9914         buf->bs_mode = dic->di_mode;
9915         buf->bs_uid = dic->di_uid;
9916         buf->bs_gid = dic->di_gid;
9917 +       buf->bs_tag = dic->di_tag;
9918         buf->bs_size = dic->di_size;
9919         vn_atime_to_bstime(vp, &buf->bs_atime);
9920         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
9921 @@ -163,6 +164,7 @@ xfs_bulkstat_one_dinode(
9922         buf->bs_mode = INT_GET(dic->di_mode, ARCH_CONVERT);
9923         buf->bs_uid = INT_GET(dic->di_uid, ARCH_CONVERT);
9924         buf->bs_gid = INT_GET(dic->di_gid, ARCH_CONVERT);
9925 +       buf->bs_tag = INT_GET(dic->di_tag, ARCH_CONVERT);
9926         buf->bs_size = INT_GET(dic->di_size, ARCH_CONVERT);
9927         buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
9928         buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
9929 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_mount.h linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_mount.h
9930 --- linux-2.6.22.10/fs/xfs/xfs_mount.h  2007-05-02 19:25:23 +0200
9931 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_mount.h        2007-06-15 02:37:04 +0200
9932 @@ -464,6 +464,7 @@ typedef struct xfs_mount {
9933  #define XFS_MOUNT_NO_PERCPU_SB (1ULL << 23)    /* don't use per-cpu superblock
9934                                                    counters */
9935  
9936 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
9937  
9938  /*
9939   * Default minimum read and write sizes.
9940 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_vfsops.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_vfsops.c
9941 --- linux-2.6.22.10/fs/xfs/xfs_vfsops.c 2007-07-09 13:19:34 +0200
9942 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_vfsops.c       2007-06-15 02:37:04 +0200
9943 @@ -300,6 +300,8 @@ xfs_start_flags(
9944  
9945         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
9946                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
9947 +       if (ap->flags2 & XFSMNT2_TAGGED)
9948 +               mp->m_flags |= XFS_MOUNT_TAGGED;
9949  
9950         /*
9951          * no recovery flag requires a read-only mount
9952 @@ -394,6 +396,8 @@ xfs_finish_flags(
9953                         return XFS_ERROR(EINVAL);
9954         }
9955  
9956 +       if (ap->flags2 & XFSMNT2_TAGGED)
9957 +               vfs->vfs_super->s_flags |= MS_TAGGED;
9958         return 0;
9959  }
9960  
9961 @@ -1645,6 +1649,9 @@ xfs_vget(
9962                                          * in stat(). */
9963  #define MNTOPT_ATTR2   "attr2"         /* do use attr2 attribute format */
9964  #define MNTOPT_NOATTR2 "noattr2"       /* do not use attr2 attribute format */
9965 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
9966 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
9967 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
9968  
9969  STATIC unsigned long
9970  suffix_strtoul(char *s, char **endp, unsigned int base)
9971 @@ -1831,6 +1838,19 @@ xfs_parseargs(
9972                         args->flags |= XFSMNT_ATTR2;
9973                 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
9974                         args->flags &= ~XFSMNT_ATTR2;
9975 +#ifndef CONFIG_TAGGING_NONE
9976 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9977 +                       args->flags2 |= XFSMNT2_TAGGED;
9978 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
9979 +                       args->flags2 &= ~XFSMNT2_TAGGED;
9980 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
9981 +                       args->flags2 |= XFSMNT2_TAGGED;
9982 +#endif
9983 +#ifdef CONFIG_PROPAGATE
9984 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
9985 +                       /* use value */
9986 +                       args->flags2 |= XFSMNT2_TAGGED;
9987 +#endif
9988                 } else if (!strcmp(this_char, "osyncisdsync")) {
9989                         /* no-op, this is now the default */
9990                         cmn_err(CE_WARN,
9991 diff -NurpP --minimal linux-2.6.22.10/fs/xfs/xfs_vnodeops.c linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_vnodeops.c
9992 --- linux-2.6.22.10/fs/xfs/xfs_vnodeops.c       2007-07-09 13:19:34 +0200
9993 +++ linux-2.6.22.10-vs2.2.0.5/fs/xfs/xfs_vnodeops.c     2007-06-15 02:37:04 +0200
9994 @@ -159,6 +159,7 @@ xfs_getattr(
9995         vap->va_mode = ip->i_d.di_mode;
9996         vap->va_uid = ip->i_d.di_uid;
9997         vap->va_gid = ip->i_d.di_gid;
9998 +       vap->va_tag = ip->i_d.di_tag;
9999         vap->va_projid = ip->i_d.di_projid;
10000  
10001         /*
10002 @@ -259,6 +260,7 @@ xfs_setattr(
10003         uint                    commit_flags=0;
10004         uid_t                   uid=0, iuid=0;
10005         gid_t                   gid=0, igid=0;
10006 +       tag_t                   tag=0, itag=0;
10007         int                     timeflags = 0;
10008         bhv_vnode_t             *vp;
10009         xfs_prid_t              projid=0, iprojid=0;
10010 @@ -315,6 +317,7 @@ xfs_setattr(
10011             (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID))) {
10012                 uint    qflags = 0;
10013  
10014 +               /* TODO: handle tagging? */
10015                 if ((mask & XFS_AT_UID) && XFS_IS_UQUOTA_ON(mp)) {
10016                         uid = vap->va_uid;
10017                         qflags |= XFS_QMOPT_UQUOTA;
10018 @@ -394,6 +397,8 @@ xfs_setattr(
10019         if (mask &
10020             (XFS_AT_MODE|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|XFS_AT_UID|
10021              XFS_AT_GID|XFS_AT_PROJID)) {
10022 +               /* TODO: handle tagging? */
10023 +
10024                 /*
10025                  * CAP_FOWNER overrides the following restrictions:
10026                  *
10027 @@ -442,7 +447,7 @@ xfs_setattr(
10028          * and can change the group id only to a group of which he
10029          * or she is a member.
10030          */
10031 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10032 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10033                 /*
10034                  * These IDs could have changed since we last looked at them.
10035                  * But, we're assured that if the ownership did change
10036 @@ -450,10 +455,12 @@ xfs_setattr(
10037                  * would have changed also.
10038                  */
10039                 iuid = ip->i_d.di_uid;
10040 -               iprojid = ip->i_d.di_projid;
10041                 igid = ip->i_d.di_gid;
10042 -               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10043 +               itag = ip->i_d.di_tag;
10044 +               iprojid = ip->i_d.di_projid;
10045                 uid = (mask & XFS_AT_UID) ? vap->va_uid : iuid;
10046 +               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
10047 +               tag = (mask & XFS_AT_TAG) ? vap->va_tag : itag;
10048                 projid = (mask & XFS_AT_PROJID) ? (xfs_prid_t)vap->va_projid :
10049                          iprojid;
10050  
10051 @@ -481,6 +488,7 @@ xfs_setattr(
10052                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
10053                     (XFS_IS_PQUOTA_ON(mp) && iprojid != projid) ||
10054                     (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
10055 +                       /* TODO: handle tagging? */
10056                         ASSERT(tp);
10057                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
10058                                                 capable(CAP_FOWNER) ?
10059 @@ -706,7 +714,7 @@ xfs_setattr(
10060          * and can change the group id only to a group of which he
10061          * or she is a member.
10062          */
10063 -       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_PROJID)) {
10064 +       if (mask & (XFS_AT_UID|XFS_AT_GID|XFS_AT_TAG|XFS_AT_PROJID)) {
10065                 /*
10066                  * CAP_FSETID overrides the following restrictions:
10067                  *
10068 @@ -722,6 +730,9 @@ xfs_setattr(
10069                  * Change the ownerships and register quota modifications
10070                  * in the transaction.
10071                  */
10072 +               if (itag != tag) {
10073 +                       ip->i_d.di_tag = tag;
10074 +               }
10075                 if (iuid != uid) {
10076                         if (XFS_IS_UQUOTA_ON(mp)) {
10077                                 ASSERT(mask & XFS_AT_UID);
10078 @@ -802,6 +813,10 @@ xfs_setattr(
10079                         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
10080                         if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
10081                                 di_flags |= XFS_DIFLAG_IMMUTABLE;
10082 +                       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
10083 +                               di_flags |= XFS_DIFLAG_IUNLINK;
10084 +                       if (vap->va_xflags & XFS_XFLAG_BARRIER)
10085 +                               di_flags |= XFS_DIFLAG_BARRIER;
10086                         if (vap->va_xflags & XFS_XFLAG_APPEND)
10087                                 di_flags |= XFS_DIFLAG_APPEND;
10088                         if (vap->va_xflags & XFS_XFLAG_SYNC)
10089 diff -NurpP --minimal linux-2.6.22.10/include/asm-arm/tlb.h linux-2.6.22.10-vs2.2.0.5/include/asm-arm/tlb.h
10090 --- linux-2.6.22.10/include/asm-arm/tlb.h       2006-06-18 04:54:58 +0200
10091 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-arm/tlb.h     2007-06-15 02:37:04 +0200
10092 @@ -28,6 +28,7 @@
10093  #else /* !CONFIG_MMU */
10094  
10095  #include <asm/pgalloc.h>
10096 +#include <linux/vs_memory.h>
10097  
10098  /*
10099   * TLB handling.  This allows us to remove pages from the page
10100 diff -NurpP --minimal linux-2.6.22.10/include/asm-arm26/tlb.h linux-2.6.22.10-vs2.2.0.5/include/asm-arm26/tlb.h
10101 --- linux-2.6.22.10/include/asm-arm26/tlb.h     2006-01-03 17:30:02 +0100
10102 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-arm26/tlb.h   2007-06-15 02:37:04 +0200
10103 @@ -3,6 +3,7 @@
10104  
10105  #include <asm/pgalloc.h>
10106  #include <asm/tlbflush.h>
10107 +#include <linux/vs_memory.h>
10108  
10109  /*
10110   * TLB handling.  This allows us to remove pages from the page
10111 diff -NurpP --minimal linux-2.6.22.10/include/asm-arm26/unistd.h linux-2.6.22.10-vs2.2.0.5/include/asm-arm26/unistd.h
10112 --- linux-2.6.22.10/include/asm-arm26/unistd.h  2007-02-06 03:01:35 +0100
10113 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-arm26/unistd.h        2007-06-15 02:37:04 +0200
10114 @@ -302,6 +302,8 @@
10115  #define __NR_mq_getsetattr             (__NR_SYSCALL_BASE+279)
10116  #define __NR_waitid                    (__NR_SYSCALL_BASE+280)
10117  
10118 +#define __NR_vserver                   (__NR_SYSCALL_BASE+313)
10119 +
10120  /*
10121   * The following SWIs are ARM private. FIXME - make appropriate for arm26
10122   */
10123 diff -NurpP --minimal linux-2.6.22.10/include/asm-generic/tlb.h linux-2.6.22.10-vs2.2.0.5/include/asm-generic/tlb.h
10124 --- linux-2.6.22.10/include/asm-generic/tlb.h   2006-11-30 21:19:31 +0100
10125 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-generic/tlb.h 2007-06-15 02:37:04 +0200
10126 @@ -14,6 +14,7 @@
10127  #define _ASM_GENERIC__TLB_H
10128  
10129  #include <linux/swap.h>
10130 +#include <linux/vs_memory.h>
10131  #include <asm/pgalloc.h>
10132  #include <asm/tlbflush.h>
10133  
10134 diff -NurpP --minimal linux-2.6.22.10/include/asm-ia64/tlb.h linux-2.6.22.10-vs2.2.0.5/include/asm-ia64/tlb.h
10135 --- linux-2.6.22.10/include/asm-ia64/tlb.h      2006-09-20 16:58:40 +0200
10136 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-ia64/tlb.h    2007-06-15 02:37:04 +0200
10137 @@ -40,6 +40,7 @@
10138  #include <linux/mm.h>
10139  #include <linux/pagemap.h>
10140  #include <linux/swap.h>
10141 +#include <linux/vs_memory.h>
10142  
10143  #include <asm/pgalloc.h>
10144  #include <asm/processor.h>
10145 diff -NurpP --minimal linux-2.6.22.10/include/asm-powerpc/systbl.h linux-2.6.22.10-vs2.2.0.5/include/asm-powerpc/systbl.h
10146 --- linux-2.6.22.10/include/asm-powerpc/systbl.h        2007-07-09 13:19:44 +0200
10147 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-powerpc/systbl.h      2007-07-07 03:52:53 +0200
10148 @@ -260,7 +260,7 @@ COMPAT_SYS_SPU(fstatfs64)
10149  SYSX(sys_ni_syscall, ppc_fadvise64_64, ppc_fadvise64_64)
10150  PPC_SYS_SPU(rtas)
10151  OLDSYS(debug_setcontext)
10152 -SYSCALL(ni_syscall)
10153 +SYSX(sys_vserver, sys32_vserver, sys_vserver)
10154  COMPAT_SYS(migrate_pages)
10155  COMPAT_SYS(mbind)
10156  COMPAT_SYS(get_mempolicy)
10157 diff -NurpP --minimal linux-2.6.22.10/include/asm-powerpc/unistd.h linux-2.6.22.10-vs2.2.0.5/include/asm-powerpc/unistd.h
10158 --- linux-2.6.22.10/include/asm-powerpc/unistd.h        2007-07-09 13:19:45 +0200
10159 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-powerpc/unistd.h      2007-07-07 03:52:53 +0200
10160 @@ -275,7 +275,7 @@
10161  #endif
10162  #define __NR_rtas              255
10163  #define __NR_sys_debug_setcontext 256
10164 -/* Number 257 is reserved for vserver */
10165 +#define __NR_vserver           257
10166  #define __NR_migrate_pages     258
10167  #define __NR_mbind             259
10168  #define __NR_get_mempolicy     260
10169 diff -NurpP --minimal linux-2.6.22.10/include/asm-s390/unistd.h linux-2.6.22.10-vs2.2.0.5/include/asm-s390/unistd.h
10170 --- linux-2.6.22.10/include/asm-s390/unistd.h   2007-07-09 13:19:45 +0200
10171 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-s390/unistd.h 2007-06-15 02:37:04 +0200
10172 @@ -202,7 +202,7 @@
10173  #define __NR_clock_gettime     (__NR_timer_create+6)
10174  #define __NR_clock_getres      (__NR_timer_create+7)
10175  #define __NR_clock_nanosleep   (__NR_timer_create+8)
10176 -/* Number 263 is reserved for vserver */
10177 +#define __NR_vserver           263
10178  #define __NR_statfs64          265
10179  #define __NR_fstatfs64         266
10180  #define __NR_remap_file_pages  267
10181 diff -NurpP --minimal linux-2.6.22.10/include/asm-sparc/unistd.h linux-2.6.22.10-vs2.2.0.5/include/asm-sparc/unistd.h
10182 --- linux-2.6.22.10/include/asm-sparc/unistd.h  2007-07-09 13:19:54 +0200
10183 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-sparc/unistd.h        2007-06-15 02:37:04 +0200
10184 @@ -283,7 +283,7 @@
10185  #define __NR_timer_getoverrun  264
10186  #define __NR_timer_delete      265
10187  #define __NR_timer_create      266
10188 -/* #define __NR_vserver                267 Reserved for VSERVER */
10189 +#define __NR_vserver           267
10190  #define __NR_io_setup          268
10191  #define __NR_io_destroy                269
10192  #define __NR_io_submit         270
10193 diff -NurpP --minimal linux-2.6.22.10/include/asm-sparc64/tlb.h linux-2.6.22.10-vs2.2.0.5/include/asm-sparc64/tlb.h
10194 --- linux-2.6.22.10/include/asm-sparc64/tlb.h   2007-07-09 13:19:54 +0200
10195 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-sparc64/tlb.h 2007-07-07 03:54:19 +0200
10196 @@ -3,6 +3,7 @@
10197  
10198  #include <linux/swap.h>
10199  #include <linux/pagemap.h>
10200 +#include <linux/vs_memory.h>
10201  #include <asm/pgalloc.h>
10202  #include <asm/tlbflush.h>
10203  #include <asm/mmu_context.h>
10204 diff -NurpP --minimal linux-2.6.22.10/include/asm-sparc64/unistd.h linux-2.6.22.10-vs2.2.0.5/include/asm-sparc64/unistd.h
10205 --- linux-2.6.22.10/include/asm-sparc64/unistd.h        2007-07-09 13:19:54 +0200
10206 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-sparc64/unistd.h      2007-06-15 02:37:04 +0200
10207 @@ -285,7 +285,7 @@
10208  #define __NR_timer_getoverrun  264
10209  #define __NR_timer_delete      265
10210  #define __NR_timer_create      266
10211 -/* #define __NR_vserver                267 Reserved for VSERVER */
10212 +#define __NR_vserver           267
10213  #define __NR_io_setup          268
10214  #define __NR_io_destroy                269
10215  #define __NR_io_submit         270
10216 diff -NurpP --minimal linux-2.6.22.10/include/asm-x86_64/unistd.h linux-2.6.22.10-vs2.2.0.5/include/asm-x86_64/unistd.h
10217 --- linux-2.6.22.10/include/asm-x86_64/unistd.h 2007-07-09 13:19:55 +0200
10218 +++ linux-2.6.22.10-vs2.2.0.5/include/asm-x86_64/unistd.h       2007-07-07 03:52:53 +0200
10219 @@ -532,7 +532,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
10220  #define __NR_utimes            235
10221  __SYSCALL(__NR_utimes, sys_utimes)
10222  #define __NR_vserver           236
10223 -__SYSCALL(__NR_vserver, sys_ni_syscall)
10224 +__SYSCALL(__NR_vserver, sys_vserver)
10225  #define __NR_mbind             237
10226  __SYSCALL(__NR_mbind, sys_mbind)
10227  #define __NR_set_mempolicy     238
10228 diff -NurpP --minimal linux-2.6.22.10/include/linux/Kbuild linux-2.6.22.10-vs2.2.0.5/include/linux/Kbuild
10229 --- linux-2.6.22.10/include/linux/Kbuild        2007-10-30 01:57:14 +0100
10230 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/Kbuild      2007-10-01 15:25:35 +0200
10231 @@ -351,3 +351,6 @@ unifdef-y += xattr.h
10232  unifdef-y += xfrm.h
10233  
10234  objhdr-y += version.h
10235 +
10236 +header-y += vserver/
10237 +
10238 diff -NurpP --minimal linux-2.6.22.10/include/linux/capability.h linux-2.6.22.10-vs2.2.0.5/include/linux/capability.h
10239 --- linux-2.6.22.10/include/linux/capability.h  2007-07-09 13:19:55 +0200
10240 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/capability.h        2007-06-15 02:37:04 +0200
10241 @@ -237,6 +237,7 @@ typedef __u32 kernel_cap_t;
10242     arbitrary SCSI commands */
10243  /* Allow setting encryption key on loopback filesystem */
10244  /* Allow setting zone reclaim policy */
10245 +/* Allow the selection of a security context */
10246  
10247  #define CAP_SYS_ADMIN        21
10248  
10249 @@ -290,6 +291,11 @@ typedef __u32 kernel_cap_t;
10250  
10251  #define CAP_AUDIT_CONTROL    30
10252  
10253 +/* Allow context manipulations */
10254 +/* Allow changing context info on files */
10255 +
10256 +#define CAP_CONTEXT         31
10257 +
10258  #ifdef __KERNEL__
10259  /* 
10260   * Bounding set
10261 diff -NurpP --minimal linux-2.6.22.10/include/linux/devpts_fs.h linux-2.6.22.10-vs2.2.0.5/include/linux/devpts_fs.h
10262 --- linux-2.6.22.10/include/linux/devpts_fs.h   2004-08-14 12:55:59 +0200
10263 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/devpts_fs.h 2007-06-15 02:37:04 +0200
10264 @@ -30,5 +30,7 @@ static inline void devpts_pty_kill(int n
10265  
10266  #endif
10267  
10268 +#define DEVPTS_SUPER_MAGIC     0x00001cd1
10269 +
10270  
10271  #endif /* _LINUX_DEVPTS_FS_H */
10272 diff -NurpP --minimal linux-2.6.22.10/include/linux/ext2_fs.h linux-2.6.22.10-vs2.2.0.5/include/linux/ext2_fs.h
10273 --- linux-2.6.22.10/include/linux/ext2_fs.h     2006-11-30 21:19:37 +0100
10274 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/ext2_fs.h   2007-06-15 02:37:04 +0200
10275 @@ -188,6 +188,8 @@ struct ext2_group_desc
10276  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
10277  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
10278  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
10279 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
10280 +#define EXT2_IUNLINK_FL                        FS_IUNLINK_FL   /* Immutable unlink */
10281  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
10282  
10283  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
10284 @@ -244,7 +246,7 @@ struct ext2_inode {
10285                 struct {
10286                         __u8    l_i_frag;       /* Fragment number */
10287                         __u8    l_i_fsize;      /* Fragment size */
10288 -                       __u16   i_pad1;
10289 +                       __u16   l_i_tag;        /* Context Tag */
10290                         __le16  l_i_uid_high;   /* these 2 fields    */
10291                         __le16  l_i_gid_high;   /* were reserved2[0] */
10292                         __u32   l_i_reserved2;
10293 @@ -276,6 +278,7 @@ struct ext2_inode {
10294  #define i_gid_low      i_gid
10295  #define i_uid_high     osd2.linux2.l_i_uid_high
10296  #define i_gid_high     osd2.linux2.l_i_gid_high
10297 +#define i_raw_tag      osd2.linux2.l_i_tag
10298  #define i_reserved2    osd2.linux2.l_i_reserved2
10299  #endif
10300  
10301 @@ -317,8 +320,9 @@ struct ext2_inode {
10302  #define EXT2_MOUNT_XATTR_USER          0x004000  /* Extended user attributes */
10303  #define EXT2_MOUNT_POSIX_ACL           0x008000  /* POSIX Access Control Lists */
10304  #define EXT2_MOUNT_XIP                 0x010000  /* Execute in place */
10305 -#define EXT2_MOUNT_USRQUOTA            0x020000 /* user quota */
10306 -#define EXT2_MOUNT_GRPQUOTA            0x040000 /* group quota */
10307 +#define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
10308 +#define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
10309 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
10310  
10311  
10312  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
10313 diff -NurpP --minimal linux-2.6.22.10/include/linux/ext3_fs.h linux-2.6.22.10-vs2.2.0.5/include/linux/ext3_fs.h
10314 --- linux-2.6.22.10/include/linux/ext3_fs.h     2007-07-09 13:19:56 +0200
10315 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/ext3_fs.h   2007-06-15 02:37:04 +0200
10316 @@ -177,10 +177,20 @@ struct ext3_group_desc
10317  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
10318  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
10319  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
10320 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
10321 +#define EXT3_IUNLINK_FL                        0x08000000 /* Immutable unlink */
10322  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
10323  
10324 +#ifdef CONFIG_VSERVER_LEGACY
10325 +#define EXT3_FL_USER_VISIBLE           0x0803DFFF /* User visible flags */
10326 +#define EXT3_FL_USER_MODIFIABLE                0x080380FF /* User modifiable flags */
10327 +#else
10328  #define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
10329  #define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
10330 +#endif
10331 +#ifdef CONFIG_VSERVER_LEGACY
10332 +#define EXT3_IOC_SETTAG                        FIOC_SETTAGJ
10333 +#endif
10334  
10335  /*
10336   * Inode dynamic state flags
10337 @@ -296,7 +306,7 @@ struct ext3_inode {
10338                 struct {
10339                         __u8    l_i_frag;       /* Fragment number */
10340                         __u8    l_i_fsize;      /* Fragment size */
10341 -                       __u16   i_pad1;
10342 +                       __u16   l_i_tag;        /* Context Tag */
10343                         __le16  l_i_uid_high;   /* these 2 fields    */
10344                         __le16  l_i_gid_high;   /* were reserved2[0] */
10345                         __u32   l_i_reserved2;
10346 @@ -330,6 +340,7 @@ struct ext3_inode {
10347  #define i_gid_low      i_gid
10348  #define i_uid_high     osd2.linux2.l_i_uid_high
10349  #define i_gid_high     osd2.linux2.l_i_gid_high
10350 +#define i_raw_tag      osd2.linux2.l_i_tag
10351  #define i_reserved2    osd2.linux2.l_i_reserved2
10352  
10353  #elif defined(__GNU__)
10354 @@ -384,6 +395,7 @@ struct ext3_inode {
10355  #define EXT3_MOUNT_QUOTA               0x80000 /* Some quota option set */
10356  #define EXT3_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
10357  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
10358 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
10359  
10360  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
10361  #ifndef _LINUX_EXT2_FS_H
10362 @@ -812,6 +824,7 @@ struct buffer_head * ext3_bread (handle_
10363  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
10364         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
10365         int create, int extend_disksize);
10366 +extern int ext3_sync_flags(struct inode *inode);
10367  
10368  extern void ext3_read_inode (struct inode *);
10369  extern int  ext3_write_inode (struct inode *, int);
10370 diff -NurpP --minimal linux-2.6.22.10/include/linux/ext4_fs.h linux-2.6.22.10-vs2.2.0.5/include/linux/ext4_fs.h
10371 --- linux-2.6.22.10/include/linux/ext4_fs.h     2007-07-09 13:19:56 +0200
10372 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/ext4_fs.h   2007-06-15 02:37:04 +0200
10373 @@ -189,11 +189,21 @@ struct ext4_group_desc
10374  #define EXT4_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
10375  #define EXT4_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
10376  #define EXT4_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
10377 -#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
10378  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
10379 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
10380 +#define EXT4_IUNLINK_FL                        0x08000000 /* Immutable unlink */
10381 +#define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
10382  
10383 +#ifdef CONFIG_VSERVER_LEGACY
10384 +#define EXT4_FL_USER_VISIBLE           0x080BDFFF /* User visible flags */
10385 +#define EXT4_FL_USER_MODIFIABLE                0x080380FF /* User modifiable flags */
10386 +#else
10387  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
10388  #define EXT4_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
10389 +#endif
10390 +#ifdef CONFIG_VSERVER_LEGACY
10391 +#define EXT4_IOC_SETTAG                        FIOC_SETTAGJ
10392 +#endif
10393  
10394  /*
10395   * Inode dynamic state flags
10396 @@ -312,7 +322,8 @@ struct ext4_inode {
10397                         __le16  l_i_file_acl_high;
10398                         __le16  l_i_uid_high;   /* these 2 fields */
10399                         __le16  l_i_gid_high;   /* were reserved2[0] */
10400 -                       __u32   l_i_reserved2;
10401 +                       __u16   l_i_tag;        /* Context Tag */
10402 +                       __u16   l_i_reserved2;
10403                 } linux2;
10404                 struct {
10405                         __u8    h_i_frag;       /* Fragment number */
10406 @@ -344,6 +355,7 @@ struct ext4_inode {
10407  #define i_gid_low      i_gid
10408  #define i_uid_high     osd2.linux2.l_i_uid_high
10409  #define i_gid_high     osd2.linux2.l_i_gid_high
10410 +#define i_raw_tag      osd2.linux2.l_i_tag
10411  #define i_reserved2    osd2.linux2.l_i_reserved2
10412  
10413  #elif defined(__GNU__)
10414 @@ -400,6 +412,7 @@ struct ext4_inode {
10415  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
10416  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
10417  #define EXT4_MOUNT_EXTENTS             0x400000 /* Extents support */
10418 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
10419  
10420  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
10421  #ifndef _LINUX_EXT2_FS_H
10422 @@ -850,6 +863,7 @@ struct buffer_head * ext4_bread (handle_
10423  int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
10424         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
10425         int create, int extend_disksize);
10426 +extern int ext4_sync_flags(struct inode *inode);
10427  
10428  extern void ext4_read_inode (struct inode *);
10429  extern int  ext4_write_inode (struct inode *, int);
10430 diff -NurpP --minimal linux-2.6.22.10/include/linux/fs.h linux-2.6.22.10-vs2.2.0.5/include/linux/fs.h
10431 --- linux-2.6.22.10/include/linux/fs.h  2007-07-09 13:19:56 +0200
10432 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/fs.h        2007-10-29 23:24:21 +0100
10433 @@ -123,6 +123,8 @@ extern int dir_notify_enable;
10434  #define MS_SLAVE       (1<<19) /* change to slave */
10435  #define MS_SHARED      (1<<20) /* change to shared */
10436  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
10437 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
10438 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
10439  #define MS_ACTIVE      (1<<30)
10440  #define MS_NOUSER      (1<<31)
10441  
10442 @@ -149,6 +151,8 @@ extern int dir_notify_enable;
10443  #define S_NOCMTIME     128     /* Do not update file c/mtime */
10444  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
10445  #define S_PRIVATE      512     /* Inode is fs-internal */
10446 +#define S_BARRIER      1024    /* Barrier for chroot() */
10447 +#define S_IUNLINK      2048    /* Immutable unlink */
10448  
10449  /*
10450   * Note that nosuid etc flags are inode-specific: setting some file-system
10451 @@ -165,24 +169,36 @@ extern int dir_notify_enable;
10452   */
10453  #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
10454  
10455 -#define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
10456 +#define IS_RDONLY(inode)       __IS_FLG(inode, MS_RDONLY)
10457  #define IS_SYNC(inode)         (__IS_FLG(inode, MS_SYNCHRONOUS) || \
10458                                         ((inode)->i_flags & S_SYNC))
10459  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
10460                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
10461  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
10462 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
10463 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
10464 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
10465  
10466  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
10467  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
10468  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
10469 +#define IS_IUNLINK(inode)      ((inode)->i_flags & S_IUNLINK)
10470 +#define IS_IXORUNLINK(inode)   ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
10471  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
10472  
10473 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
10474  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
10475  #define IS_NOCMTIME(inode)     ((inode)->i_flags & S_NOCMTIME)
10476  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
10477  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
10478  
10479 +#ifdef CONFIG_VSERVER_COWBL
10480 +#  define IS_COW(inode)                (IS_IUNLINK(inode) && IS_IMMUTABLE(inode))
10481 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
10482 +#else
10483 +#  define IS_COW(inode)                (0)
10484 +#  define IS_COW_LINK(inode)   (0)
10485 +#endif
10486 +
10487  /* the read-only stuff doesn't really belong here, but any other place is
10488     probably as bad and I don't want to create yet another include file. */
10489  
10490 @@ -256,11 +272,17 @@ extern int dir_notify_enable;
10491  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
10492  #define FS_EXTENT_FL                   0x00080000 /* Extents */
10493  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
10494 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
10495 +#define FS_IUNLINK_FL                  0x08000000 /* Immutable unlink */
10496  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
10497  
10498 +#ifdef CONFIG_VSERVER_LEGACY
10499 +#define FS_FL_USER_VISIBLE             0x0803DFFF /* User visible flags */
10500 +#define FS_FL_USER_MODIFIABLE          0x080380FF /* User modifiable flags */
10501 +#else
10502  #define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
10503  #define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
10504 -
10505 +#endif
10506  
10507  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
10508  #define SYNC_FILE_RANGE_WRITE          2
10509 @@ -327,6 +349,7 @@ typedef void (dio_iodone_t)(struct kiocb
10510  #define ATTR_KILL_SUID 2048
10511  #define ATTR_KILL_SGID 4096
10512  #define ATTR_FILE      8192
10513 +#define ATTR_TAG       16384
10514  
10515  /*
10516   * This is the Inode Attributes structure, used for notify_change().  It
10517 @@ -342,6 +365,7 @@ struct iattr {
10518         umode_t         ia_mode;
10519         uid_t           ia_uid;
10520         gid_t           ia_gid;
10521 +       tag_t           ia_tag;
10522         loff_t          ia_size;
10523         struct timespec ia_atime;
10524         struct timespec ia_mtime;
10525 @@ -355,6 +379,9 @@ struct iattr {
10526         struct file     *ia_file;
10527  };
10528  
10529 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
10530 +#define ATTR_FLAG_IUNLINK      1024    /* Immutable unlink */
10531 +
10532  /*
10533   * Includes for diskquotas.
10534   */
10535 @@ -537,6 +564,7 @@ struct inode {
10536         unsigned int            i_nlink;
10537         uid_t                   i_uid;
10538         gid_t                   i_gid;
10539 +       tag_t                   i_tag;
10540         dev_t                   i_rdev;
10541         unsigned long           i_version;
10542         loff_t                  i_size;
10543 @@ -728,6 +756,7 @@ struct file {
10544         loff_t                  f_pos;
10545         struct fown_struct      f_owner;
10546         unsigned int            f_uid, f_gid;
10547 +       xid_t                   f_xid;
10548         struct file_ra_state    f_ra;
10549  
10550         unsigned long           f_version;
10551 @@ -811,6 +840,7 @@ struct file_lock {
10552         unsigned char fl_type;
10553         loff_t fl_start;
10554         loff_t fl_end;
10555 +       xid_t fl_xid;
10556  
10557         struct fasync_struct *  fl_fasync; /* for lease break notifications */
10558         unsigned long fl_break_time;    /* for nonblocking lease breaks */
10559 @@ -993,12 +1023,12 @@ extern void unlock_super(struct super_bl
10560   */
10561  extern int vfs_permission(struct nameidata *, int);
10562  extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
10563 -extern int vfs_mkdir(struct inode *, struct dentry *, int);
10564 -extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
10565 -extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
10566 -extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
10567 -extern int vfs_rmdir(struct inode *, struct dentry *);
10568 -extern int vfs_unlink(struct inode *, struct dentry *);
10569 +extern int vfs_mkdir(struct inode *, struct dentry *, int, struct nameidata *);
10570 +extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t, struct nameidata *);
10571 +extern int vfs_symlink(struct inode *, struct dentry *, const char *, int, struct nameidata *);
10572 +extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct nameidata *);
10573 +extern int vfs_rmdir(struct inode *, struct dentry *, struct nameidata *);
10574 +extern int vfs_unlink(struct inode *, struct dentry *, struct nameidata *);
10575  extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
10576  
10577  /*
10578 @@ -1138,6 +1168,7 @@ struct inode_operations {
10579         ssize_t (*listxattr) (struct dentry *, char *, size_t);
10580         int (*removexattr) (struct dentry *, const char *);
10581         void (*truncate_range)(struct inode *, loff_t, loff_t);
10582 +       int (*sync_flags) (struct inode *);
10583  };
10584  
10585  struct seq_file;
10586 @@ -1153,6 +1184,7 @@ extern ssize_t vfs_readv(struct file *, 
10587                 unsigned long, loff_t *);
10588  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
10589                 unsigned long, loff_t *);
10590 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
10591  
10592  /*
10593   * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
10594 @@ -1898,6 +1930,7 @@ extern int dcache_dir_open(struct inode 
10595  extern int dcache_dir_close(struct inode *, struct file *);
10596  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
10597  extern int dcache_readdir(struct file *, void *, filldir_t);
10598 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
10599  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
10600  extern int simple_statfs(struct dentry *, struct kstatfs *);
10601  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
10602 diff -NurpP --minimal linux-2.6.22.10/include/linux/init_task.h linux-2.6.22.10-vs2.2.0.5/include/linux/init_task.h
10603 --- linux-2.6.22.10/include/linux/init_task.h   2007-07-09 13:19:56 +0200
10604 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/init_task.h 2007-06-15 02:37:04 +0200
10605 @@ -169,6 +169,10 @@ extern struct group_info init_groups;
10606         },                                                              \
10607         INIT_TRACE_IRQFLAGS                                             \
10608         INIT_LOCKDEP                                                    \
10609 +       .xid            = 0,                                            \
10610 +       .vx_info        = NULL,                                         \
10611 +       .nid            = 0,                                            \
10612 +       .nx_info        = NULL,                                         \
10613  }
10614  
10615  
10616 diff -NurpP --minimal linux-2.6.22.10/include/linux/ipc.h linux-2.6.22.10-vs2.2.0.5/include/linux/ipc.h
10617 --- linux-2.6.22.10/include/linux/ipc.h 2007-07-09 13:19:56 +0200
10618 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/ipc.h       2007-06-15 02:37:04 +0200
10619 @@ -63,6 +63,7 @@ struct kern_ipc_perm
10620         key_t           key;
10621         uid_t           uid;
10622         gid_t           gid;
10623 +       xid_t           xid;
10624         uid_t           cuid;
10625         gid_t           cgid;
10626         mode_t          mode; 
10627 diff -NurpP --minimal linux-2.6.22.10/include/linux/loop.h linux-2.6.22.10-vs2.2.0.5/include/linux/loop.h
10628 --- linux-2.6.22.10/include/linux/loop.h        2007-07-09 13:19:56 +0200
10629 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/loop.h      2007-06-15 02:37:04 +0200
10630 @@ -45,6 +45,7 @@ struct loop_device {
10631         struct loop_func_table *lo_encryption;
10632         __u32           lo_init[2];
10633         uid_t           lo_key_owner;   /* Who set the key */
10634 +       xid_t           lo_xid;
10635         int             (*ioctl)(struct loop_device *, int cmd, 
10636                                  unsigned long arg); 
10637  
10638 diff -NurpP --minimal linux-2.6.22.10/include/linux/major.h linux-2.6.22.10-vs2.2.0.5/include/linux/major.h
10639 --- linux-2.6.22.10/include/linux/major.h       2007-07-09 13:19:56 +0200
10640 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/major.h     2007-06-15 02:37:04 +0200
10641 @@ -15,6 +15,7 @@
10642  #define HD_MAJOR               IDE0_MAJOR
10643  #define PTY_SLAVE_MAJOR                3
10644  #define TTY_MAJOR              4
10645 +#define VROOT_MAJOR            4
10646  #define TTYAUX_MAJOR           5
10647  #define LP_MAJOR               6
10648  #define VCS_MAJOR              7
10649 diff -NurpP --minimal linux-2.6.22.10/include/linux/mount.h linux-2.6.22.10-vs2.2.0.5/include/linux/mount.h
10650 --- linux-2.6.22.10/include/linux/mount.h       2007-07-09 13:19:56 +0200
10651 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/mount.h     2007-06-15 03:54:15 +0200
10652 @@ -28,12 +28,16 @@ struct mnt_namespace;
10653  #define MNT_NOATIME    0x08
10654  #define MNT_NODIRATIME 0x10
10655  #define MNT_RELATIME   0x20
10656 +#define MNT_RDONLY     0x40
10657 +
10658 +#define MNT_IS_RDONLY(m)       ((m) && ((m)->mnt_flags & MNT_RDONLY))
10659  
10660  #define MNT_SHRINKABLE 0x100
10661  
10662  #define MNT_SHARED     0x1000  /* if the vfsmount is a shared mount */
10663  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
10664  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
10665 +#define MNT_TAGID      0x8000
10666  
10667  struct vfsmount {
10668         struct list_head mnt_hash;
10669 @@ -61,6 +65,7 @@ struct vfsmount {
10670         atomic_t mnt_count;
10671         int mnt_expiry_mark;            /* true if marked for expiry */
10672         int mnt_pinned;
10673 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
10674  };
10675  
10676  static inline struct vfsmount *mntget(struct vfsmount *mnt)
10677 diff -NurpP --minimal linux-2.6.22.10/include/linux/net.h linux-2.6.22.10-vs2.2.0.5/include/linux/net.h
10678 --- linux-2.6.22.10/include/linux/net.h 2007-07-09 13:19:56 +0200
10679 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/net.h       2007-06-15 02:37:04 +0200
10680 @@ -63,6 +63,7 @@ typedef enum {
10681  #define SOCK_NOSPACE           2
10682  #define SOCK_PASSCRED          3
10683  #define SOCK_PASSSEC           4
10684 +#define SOCK_USER_SOCKET       5
10685  
10686  #ifndef ARCH_HAS_SOCKET_TYPES
10687  /**
10688 diff -NurpP --minimal linux-2.6.22.10/include/linux/nfs_mount.h linux-2.6.22.10-vs2.2.0.5/include/linux/nfs_mount.h
10689 --- linux-2.6.22.10/include/linux/nfs_mount.h   2007-07-09 13:20:00 +0200
10690 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/nfs_mount.h 2007-06-15 03:54:39 +0200
10691 @@ -63,6 +63,7 @@
10692  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
10693  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
10694  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
10695 +#define NFS_MOUNT_TAGGED       0x8000  /* context tagging */
10696  #define NFS_MOUNT_FLAGMASK     0xFFFF
10697  
10698  #endif
10699 diff -NurpP --minimal linux-2.6.22.10/include/linux/nsproxy.h linux-2.6.22.10-vs2.2.0.5/include/linux/nsproxy.h
10700 --- linux-2.6.22.10/include/linux/nsproxy.h     2007-07-09 13:20:00 +0200
10701 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/nsproxy.h   2007-07-17 03:02:15 +0200
10702 @@ -3,6 +3,7 @@
10703  
10704  #include <linux/spinlock.h>
10705  #include <linux/sched.h>
10706 +#include <linux/vserver/debug.h>
10707  
10708  struct mnt_namespace;
10709  struct uts_namespace;
10710 @@ -32,26 +33,46 @@ struct nsproxy {
10711  extern struct nsproxy init_nsproxy;
10712  
10713  int copy_namespaces(int flags, struct task_struct *tsk);
10714 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
10715  void get_task_namespaces(struct task_struct *tsk);
10716  void free_nsproxy(struct nsproxy *ns);
10717  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
10718         struct fs_struct *);
10719  
10720 -static inline void put_nsproxy(struct nsproxy *ns)
10721 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
10722 +
10723 +static inline void __get_nsproxy(struct nsproxy *ns,
10724 +       const char *_file, int _line)
10725  {
10726 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
10727 +               ns, atomic_read(&ns->count), _file, _line);
10728 +       atomic_inc(&ns->count);
10729 +}
10730 +
10731 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
10732 +
10733 +static inline void __put_nsproxy(struct nsproxy *ns,
10734 +       const char *_file, int _line)
10735 +{
10736 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
10737 +               ns, atomic_read(&ns->count), _file, _line);
10738         if (atomic_dec_and_test(&ns->count)) {
10739                 free_nsproxy(ns);
10740         }
10741  }
10742  
10743 -static inline void exit_task_namespaces(struct task_struct *p)
10744 +#define        exit_task_namespaces(p) __exit_task_namespaces(p, __FILE__, __LINE__)
10745 +
10746 +static inline void __exit_task_namespaces(struct task_struct *p,
10747 +       const char *_file, int _line)
10748  {
10749         struct nsproxy *ns = p->nsproxy;
10750         if (ns) {
10751                 task_lock(p);
10752                 p->nsproxy = NULL;
10753                 task_unlock(p);
10754 -               put_nsproxy(ns);
10755 +               __put_nsproxy(ns, _file, _line);
10756         }
10757  }
10758 +
10759  #endif
10760 diff -NurpP --minimal linux-2.6.22.10/include/linux/pid.h linux-2.6.22.10-vs2.2.0.5/include/linux/pid.h
10761 --- linux-2.6.22.10/include/linux/pid.h 2007-07-09 13:20:00 +0200
10762 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/pid.h       2007-06-15 02:37:04 +0200
10763 @@ -8,7 +8,8 @@ enum pid_type
10764         PIDTYPE_PID,
10765         PIDTYPE_PGID,
10766         PIDTYPE_SID,
10767 -       PIDTYPE_MAX
10768 +       PIDTYPE_MAX,
10769 +       PIDTYPE_REALPID
10770  };
10771  
10772  /*
10773 diff -NurpP --minimal linux-2.6.22.10/include/linux/proc_fs.h linux-2.6.22.10-vs2.2.0.5/include/linux/proc_fs.h
10774 --- linux-2.6.22.10/include/linux/proc_fs.h     2007-07-09 13:20:00 +0200
10775 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/proc_fs.h   2007-06-15 02:37:04 +0200
10776 @@ -54,6 +54,7 @@ struct proc_dir_entry {
10777         nlink_t nlink;
10778         uid_t uid;
10779         gid_t gid;
10780 +       int vx_flags;
10781         loff_t size;
10782         const struct inode_operations *proc_iops;
10783         const struct file_operations *proc_fops;
10784 @@ -246,13 +247,20 @@ static inline void kclist_add(struct kco
10785  extern void kclist_add(struct kcore_list *, void *, size_t);
10786  #endif
10787  
10788 +struct vx_info;
10789 +struct nx_info;
10790 +
10791  union proc_op {
10792         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
10793         int (*proc_read)(struct task_struct *task, char *page);
10794 +       int (*proc_vs_read)(char *page);
10795 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
10796 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
10797  };
10798  
10799  struct proc_inode {
10800         struct pid *pid;
10801 +       int vx_flags;
10802         int fd;
10803         union proc_op op;
10804         struct proc_dir_entry *pde;
10805 diff -NurpP --minimal linux-2.6.22.10/include/linux/reiserfs_fs.h linux-2.6.22.10-vs2.2.0.5/include/linux/reiserfs_fs.h
10806 --- linux-2.6.22.10/include/linux/reiserfs_fs.h 2007-05-02 19:25:34 +0200
10807 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/reiserfs_fs.h       2007-06-15 02:37:04 +0200
10808 @@ -821,6 +821,10 @@ struct stat_data_v1 {
10809  #define REISERFS_COMPR_FL     FS_COMPR_FL
10810  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
10811  
10812 +/* unfortunately reiserfs sdattr is only 16 bit */
10813 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
10814 +#define REISERFS_IUNLINK_FL   (FS_IUNLINK_FL >> 16)
10815 +
10816  /* persistent flags that file inherits from the parent directory */
10817  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
10818                                 REISERFS_SYNC_FL |      \
10819 @@ -830,6 +834,14 @@ struct stat_data_v1 {
10820                                 REISERFS_COMPR_FL |     \
10821                                 REISERFS_NOTAIL_FL )
10822  
10823 +#ifdef CONFIG_VSERVER_LEGACY
10824 +#define REISERFS_FL_USER_VISIBLE       (REISERFS_IUNLINK_FL|0x80FF)
10825 +#define REISERFS_FL_USER_MODIFIABLE    (REISERFS_IUNLINK_FL|0x80FF)
10826 +#else
10827 +#define REISERFS_FL_USER_VISIBLE       0x80FF
10828 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
10829 +#endif
10830 +
10831  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
10832     address blocks) */
10833  struct stat_data {
10834 @@ -1901,6 +1913,7 @@ static inline void reiserfs_update_sd(st
10835  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
10836  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
10837  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
10838 +int reiserfs_sync_flags(struct inode *inode);
10839  
10840  /* namei.c */
10841  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
10842 diff -NurpP --minimal linux-2.6.22.10/include/linux/reiserfs_fs_sb.h linux-2.6.22.10-vs2.2.0.5/include/linux/reiserfs_fs_sb.h
10843 --- linux-2.6.22.10/include/linux/reiserfs_fs_sb.h      2007-07-09 13:20:00 +0200
10844 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/reiserfs_fs_sb.h    2007-06-15 02:37:04 +0200
10845 @@ -458,6 +458,7 @@ enum reiserfs_mount_options {
10846         REISERFS_POSIXACL,
10847         REISERFS_BARRIER_NONE,
10848         REISERFS_BARRIER_FLUSH,
10849 +       REISERFS_TAGGED,
10850  
10851         /* Actions on error */
10852         REISERFS_ERROR_PANIC,
10853 diff -NurpP --minimal linux-2.6.22.10/include/linux/sched.h linux-2.6.22.10-vs2.2.0.5/include/linux/sched.h
10854 --- linux-2.6.22.10/include/linux/sched.h       2007-07-09 13:20:01 +0200
10855 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/sched.h     2007-06-17 05:54:19 +0200
10856 @@ -26,6 +26,7 @@
10857  #define CLONE_STOPPED          0x02000000      /* Start in stopped state */
10858  #define CLONE_NEWUTS           0x04000000      /* New utsname group? */
10859  #define CLONE_NEWIPC           0x08000000      /* New ipcs */
10860 +#define CLONE_KTHREAD          0x10000000      /* clone a kernel thread */
10861  
10862  /*
10863   * Scheduling policies
10864 @@ -94,7 +95,7 @@ struct bio;
10865   * List of flags we want to share for kernel threads,
10866   * if only because they are not used by them anyway.
10867   */
10868 -#define CLONE_KERNEL   (CLONE_FS | CLONE_FILES | CLONE_SIGHAND)
10869 +#define CLONE_KERNEL   (CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_KTHREAD)
10870  
10871  /*
10872   * These are the constant used to fake the fixed-point load-average
10873 @@ -146,12 +147,13 @@ extern unsigned long weighted_cpuload(co
10874  #define TASK_UNINTERRUPTIBLE   2
10875  #define TASK_STOPPED           4
10876  #define TASK_TRACED            8
10877 +#define TASK_ONHOLD            16
10878  /* in tsk->exit_state */
10879 -#define EXIT_ZOMBIE            16
10880 -#define EXIT_DEAD              32
10881 +#define EXIT_ZOMBIE            32
10882 +#define EXIT_DEAD              64
10883  /* in tsk->state again */
10884 -#define TASK_NONINTERACTIVE    64
10885 -#define TASK_DEAD              128
10886 +#define TASK_NONINTERACTIVE    128
10887 +#define TASK_DEAD              256
10888  
10889  #define __set_task_state(tsk, state_value)             \
10890         do { (tsk)->state = (state_value); } while (0)
10891 @@ -287,27 +289,30 @@ extern void arch_unmap_area_topdown(stru
10892   * The mm counters are not protected by its page_table_lock,
10893   * so must be incremented atomically.
10894   */
10895 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
10896 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
10897 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
10898 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
10899 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
10900  typedef atomic_long_t mm_counter_t;
10901 +#define __set_mm_counter(mm, member, value) \
10902 +       atomic_long_set(&(mm)->_##member, value)
10903 +#define get_mm_counter(mm, member) \
10904 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
10905  
10906  #else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
10907  /*
10908   * The mm counters are protected by its page_table_lock,
10909   * so can be incremented directly.
10910   */
10911 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
10912 -#define get_mm_counter(mm, member) ((mm)->_##member)
10913 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
10914 -#define inc_mm_counter(mm, member) (mm)->_##member++
10915 -#define dec_mm_counter(mm, member) (mm)->_##member--
10916  typedef unsigned long mm_counter_t;
10917 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
10918 +#define get_mm_counter(mm, member) ((mm)->_##member)
10919  
10920  #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
10921  
10922 +#define set_mm_counter(mm, member, value) \
10923 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
10924 +#define add_mm_counter(mm, member, value) \
10925 +       vx_ ## member ## pages_add((mm), (value))
10926 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
10927 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
10928 +
10929  #define get_mm_rss(mm)                                 \
10930         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
10931  #define update_hiwater_rss(mm) do {                    \
10932 @@ -365,6 +370,7 @@ struct mm_struct {
10933  
10934         /* Architecture-specific MM context */
10935         mm_context_t context;
10936 +       struct vx_info *mm_vx_info;
10937  
10938         /* Swap token stuff */
10939         /*
10940 @@ -570,9 +576,10 @@ struct user_struct {
10941         /* Hash table maintenance information */
10942         struct list_head uidhash_list;
10943         uid_t uid;
10944 +       xid_t xid;
10945  };
10946  
10947 -extern struct user_struct *find_user(uid_t);
10948 +extern struct user_struct *find_user(xid_t, uid_t);
10949  
10950  extern struct user_struct root_user;
10951  #define INIT_USER (&root_user)
10952 @@ -969,6 +976,14 @@ struct task_struct {
10953         
10954         void *security;
10955         struct audit_context *audit_context;
10956 +
10957 +/* vserver context data */
10958 +       struct vx_info *vx_info;
10959 +       struct nx_info *nx_info;
10960 +
10961 +       xid_t xid;
10962 +       nid_t nid;
10963 +
10964         seccomp_t seccomp;
10965  
10966  /* Thread group tracking */
10967 @@ -1290,12 +1305,16 @@ extern struct task_struct init_task;
10968  
10969  extern struct   mm_struct init_mm;
10970  
10971 -#define find_task_by_pid(nr)   find_task_by_pid_type(PIDTYPE_PID, nr)
10972 +#define find_task_by_real_pid(nr) \
10973 +       find_task_by_pid_type(PIDTYPE_REALPID, nr)
10974 +#define find_task_by_pid(nr) \
10975 +       find_task_by_pid_type(PIDTYPE_PID, nr)
10976 +
10977  extern struct task_struct *find_task_by_pid_type(int type, int pid);
10978  extern void __set_special_pids(pid_t session, pid_t pgrp);
10979  
10980  /* per-UID process charging. */
10981 -extern struct user_struct * alloc_uid(uid_t);
10982 +extern struct user_struct * alloc_uid(xid_t, uid_t);
10983  static inline struct user_struct *get_uid(struct user_struct *u)
10984  {
10985         atomic_inc(&u->__count);
10986 diff -NurpP --minimal linux-2.6.22.10/include/linux/shmem_fs.h linux-2.6.22.10-vs2.2.0.5/include/linux/shmem_fs.h
10987 --- linux-2.6.22.10/include/linux/shmem_fs.h    2006-11-30 21:19:39 +0100
10988 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/shmem_fs.h  2007-06-15 02:37:04 +0200
10989 @@ -8,6 +8,9 @@
10990  
10991  #define SHMEM_NR_DIRECT 16
10992  
10993 +#define TMPFS_SUPER_MAGIC      0x01021994
10994 +
10995 +
10996  struct shmem_inode_info {
10997         spinlock_t              lock;
10998         unsigned long           flags;
10999 diff -NurpP --minimal linux-2.6.22.10/include/linux/stat.h linux-2.6.22.10-vs2.2.0.5/include/linux/stat.h
11000 --- linux-2.6.22.10/include/linux/stat.h        2007-07-09 13:20:01 +0200
11001 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/stat.h      2007-06-15 02:37:04 +0200
11002 @@ -66,6 +66,7 @@ struct kstat {
11003         unsigned int    nlink;
11004         uid_t           uid;
11005         gid_t           gid;
11006 +       tag_t           tag;
11007         dev_t           rdev;
11008         loff_t          size;
11009         struct timespec  atime;
11010 diff -NurpP --minimal linux-2.6.22.10/include/linux/sunrpc/auth.h linux-2.6.22.10-vs2.2.0.5/include/linux/sunrpc/auth.h
11011 --- linux-2.6.22.10/include/linux/sunrpc/auth.h 2006-11-30 21:19:40 +0100
11012 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/sunrpc/auth.h       2007-06-15 02:37:04 +0200
11013 @@ -24,6 +24,7 @@
11014  struct auth_cred {
11015         uid_t   uid;
11016         gid_t   gid;
11017 +       tag_t   tag;
11018         struct group_info *group_info;
11019  };
11020  
11021 diff -NurpP --minimal linux-2.6.22.10/include/linux/sunrpc/clnt.h linux-2.6.22.10-vs2.2.0.5/include/linux/sunrpc/clnt.h
11022 --- linux-2.6.22.10/include/linux/sunrpc/clnt.h 2007-07-09 13:20:01 +0200
11023 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/sunrpc/clnt.h       2007-06-15 02:37:04 +0200
11024 @@ -43,7 +43,8 @@
11025         unsigned int            cl_softrtry : 1,/* soft timeouts */
11026                                 cl_intr     : 1,/* interruptible */
11027                                 cl_discrtry : 1,/* disconnect before retry */
11028 -                               cl_autobind : 1;/* use getport() */
11029 +                               cl_autobind : 1,/* use getport() */
11030 +                               cl_tag      : 1;/* context tagging */
11031  
11032         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
11033  
11034
11035 diff -NurpP --minimal linux-2.6.22.10/include/linux/syscalls.h linux-2.6.22.10-vs2.2.0.5/include/linux/syscalls.h
11036 --- linux-2.6.22.10/include/linux/syscalls.h    2007-07-09 13:20:01 +0200
11037 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/syscalls.h  2007-07-07 03:52:54 +0200
11038 @@ -294,6 +294,8 @@ asmlinkage long sys_symlink(const char _
11039  asmlinkage long sys_unlink(const char __user *pathname);
11040  asmlinkage long sys_rename(const char __user *oldname,
11041                                 const char __user *newname);
11042 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
11043 +                               umode_t mode);
11044  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
11045  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
11046  
11047 diff -NurpP --minimal linux-2.6.22.10/include/linux/sysctl.h linux-2.6.22.10-vs2.2.0.5/include/linux/sysctl.h
11048 --- linux-2.6.22.10/include/linux/sysctl.h      2007-07-09 13:20:01 +0200
11049 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/sysctl.h    2007-06-15 02:37:04 +0200
11050 @@ -106,6 +106,7 @@ enum
11051         KERN_CAP_BSET=14,       /* int: capability bounding set */
11052         KERN_PANIC=15,          /* int: panic timeout */
11053         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11054 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11055  
11056         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11057         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11058 diff -NurpP --minimal linux-2.6.22.10/include/linux/sysfs.h linux-2.6.22.10-vs2.2.0.5/include/linux/sysfs.h
11059 --- linux-2.6.22.10/include/linux/sysfs.h       2007-07-09 13:20:01 +0200
11060 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/sysfs.h     2007-06-15 02:37:04 +0200
11061 @@ -15,6 +15,8 @@
11062  #include <linux/list.h>
11063  #include <asm/atomic.h>
11064  
11065 +#define SYSFS_SUPER_MAGIC      0x62656572
11066 +
11067  struct kobject;
11068  struct module;
11069  struct nameidata;
11070 diff -NurpP --minimal linux-2.6.22.10/include/linux/time.h linux-2.6.22.10-vs2.2.0.5/include/linux/time.h
11071 --- linux-2.6.22.10/include/linux/time.h        2007-07-09 13:20:01 +0200
11072 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/time.h      2007-06-15 02:37:04 +0200
11073 @@ -176,6 +176,9 @@ static inline void timespec_add_ns(struc
11074         }
11075         a->tv_nsec = ns;
11076  }
11077 +
11078 +#include <linux/vs_time.h>
11079 +
11080  #endif /* __KERNEL__ */
11081  
11082  #define NFDBITS                        __NFDBITS
11083 diff -NurpP --minimal linux-2.6.22.10/include/linux/types.h linux-2.6.22.10-vs2.2.0.5/include/linux/types.h
11084 --- linux-2.6.22.10/include/linux/types.h       2007-02-06 03:01:52 +0100
11085 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/types.h     2007-06-15 02:37:04 +0200
11086 @@ -39,6 +39,9 @@ typedef __kernel_uid32_t      uid_t;
11087  typedef __kernel_gid32_t       gid_t;
11088  typedef __kernel_uid16_t        uid16_t;
11089  typedef __kernel_gid16_t        gid16_t;
11090 +typedef unsigned int           xid_t;
11091 +typedef unsigned int           nid_t;
11092 +typedef unsigned int           tag_t;
11093  
11094  #ifdef CONFIG_UID16
11095  /* This is defined by include/asm-{arch}/posix_types.h */
11096 diff -NurpP --minimal linux-2.6.22.10/include/linux/vroot.h linux-2.6.22.10-vs2.2.0.5/include/linux/vroot.h
11097 --- linux-2.6.22.10/include/linux/vroot.h       1970-01-01 01:00:00 +0100
11098 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vroot.h     2007-06-15 02:37:04 +0200
11099 @@ -0,0 +1,51 @@
11100 +
11101 +/*
11102 + * include/linux/vroot.h
11103 + *
11104 + * written by Herbert Pötzl, 9/11/2002
11105 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
11106 + *
11107 + * Copyright (C) 2002-2007 by Herbert Pötzl.
11108 + * Redistribution of this file is permitted under the
11109 + * GNU General Public License.
11110 + */
11111 +
11112 +#ifndef _LINUX_VROOT_H
11113 +#define _LINUX_VROOT_H
11114 +
11115 +
11116 +#ifdef __KERNEL__
11117 +
11118 +/* Possible states of device */
11119 +enum {
11120 +       Vr_unbound,
11121 +       Vr_bound,
11122 +};
11123 +
11124 +struct vroot_device {
11125 +       int             vr_number;
11126 +       int             vr_refcnt;
11127 +
11128 +       struct semaphore        vr_ctl_mutex;
11129 +       struct block_device    *vr_device;
11130 +       int                     vr_state;
11131 +};
11132 +
11133 +
11134 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
11135 +
11136 +extern int register_vroot_grb(vroot_grb_func *);
11137 +extern int unregister_vroot_grb(vroot_grb_func *);
11138 +
11139 +#endif /* __KERNEL__ */
11140 +
11141 +#define MAX_VROOT_DEFAULT      8
11142 +
11143 +/*
11144 + * IOCTL commands --- we will commandeer 0x56 ('V')
11145 + */
11146 +
11147 +#define VROOT_SET_DEV          0x5600
11148 +#define VROOT_CLR_DEV          0x5601
11149 +
11150 +#endif /* _LINUX_VROOT_H */
11151 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_base.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_base.h
11152 --- linux-2.6.22.10/include/linux/vs_base.h     1970-01-01 01:00:00 +0100
11153 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_base.h   2007-06-15 02:37:04 +0200
11154 @@ -0,0 +1,9 @@
11155 +#ifndef _VS_BASE_H
11156 +#define _VS_BASE_H
11157 +
11158 +#include "vserver/base.h"
11159 +#include "vserver/debug.h"
11160 +
11161 +#else
11162 +#warning duplicate inclusion
11163 +#endif
11164 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_context.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_context.h
11165 --- linux-2.6.22.10/include/linux/vs_context.h  1970-01-01 01:00:00 +0100
11166 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_context.h        2007-06-15 02:37:04 +0200
11167 @@ -0,0 +1,224 @@
11168 +#ifndef _VS_CONTEXT_H
11169 +#define _VS_CONTEXT_H
11170 +
11171 +#include "vserver/base.h"
11172 +#include "vserver/context.h"
11173 +#include "vserver/history.h"
11174 +#include "vserver/debug.h"
11175 +
11176 +
11177 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
11178 +
11179 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
11180 +       const char *_file, int _line, void *_here)
11181 +{
11182 +       if (!vxi)
11183 +               return NULL;
11184 +
11185 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
11186 +               vxi, vxi ? vxi->vx_id : 0,
11187 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11188 +               _file, _line);
11189 +       __vxh_get_vx_info(vxi, _here);
11190 +
11191 +       atomic_inc(&vxi->vx_usecnt);
11192 +       return vxi;
11193 +}
11194 +
11195 +
11196 +extern void free_vx_info(struct vx_info *);
11197 +
11198 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
11199 +
11200 +static inline void __put_vx_info(struct vx_info *vxi,
11201 +       const char *_file, int _line, void *_here)
11202 +{
11203 +       if (!vxi)
11204 +               return;
11205 +
11206 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
11207 +               vxi, vxi ? vxi->vx_id : 0,
11208 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11209 +               _file, _line);
11210 +       __vxh_put_vx_info(vxi, _here);
11211 +
11212 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
11213 +               free_vx_info(vxi);
11214 +}
11215 +
11216 +
11217 +#define init_vx_info(p, i) \
11218 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11219 +
11220 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11221 +       const char *_file, int _line, void *_here)
11222 +{
11223 +       if (vxi) {
11224 +               vxlprintk(VXD_CBIT(xid, 3),
11225 +                       "init_vx_info(%p[#%d.%d])",
11226 +                       vxi, vxi ? vxi->vx_id : 0,
11227 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11228 +                       _file, _line);
11229 +               __vxh_init_vx_info(vxi, vxp, _here);
11230 +
11231 +               atomic_inc(&vxi->vx_usecnt);
11232 +       }
11233 +       *vxp = vxi;
11234 +}
11235 +
11236 +
11237 +#define set_vx_info(p, i) \
11238 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
11239 +
11240 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
11241 +       const char *_file, int _line, void *_here)
11242 +{
11243 +       struct vx_info *vxo;
11244 +
11245 +       if (!vxi)
11246 +               return;
11247 +
11248 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
11249 +               vxi, vxi ? vxi->vx_id : 0,
11250 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11251 +               _file, _line);
11252 +       __vxh_set_vx_info(vxi, vxp, _here);
11253 +
11254 +       atomic_inc(&vxi->vx_usecnt);
11255 +       vxo = xchg(vxp, vxi);
11256 +       BUG_ON(vxo);
11257 +}
11258 +
11259 +
11260 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
11261 +
11262 +static inline void __clr_vx_info(struct vx_info **vxp,
11263 +       const char *_file, int _line, void *_here)
11264 +{
11265 +       struct vx_info *vxo;
11266 +
11267 +       vxo = xchg(vxp, NULL);
11268 +       if (!vxo)
11269 +               return;
11270 +
11271 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
11272 +               vxo, vxo ? vxo->vx_id : 0,
11273 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
11274 +               _file, _line);
11275 +       __vxh_clr_vx_info(vxo, vxp, _here);
11276 +
11277 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
11278 +               free_vx_info(vxo);
11279 +}
11280 +
11281 +
11282 +#define claim_vx_info(v, p) \
11283 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
11284 +
11285 +static inline void __claim_vx_info(struct vx_info *vxi,
11286 +       struct task_struct *task,
11287 +       const char *_file, int _line, void *_here)
11288 +{
11289 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
11290 +               vxi, vxi ? vxi->vx_id : 0,
11291 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11292 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
11293 +               task, _file, _line);
11294 +       __vxh_claim_vx_info(vxi, task, _here);
11295 +
11296 +       atomic_inc(&vxi->vx_tasks);
11297 +}
11298 +
11299 +
11300 +extern void unhash_vx_info(struct vx_info *);
11301 +
11302 +#define release_vx_info(v, p) \
11303 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
11304 +
11305 +static inline void __release_vx_info(struct vx_info *vxi,
11306 +       struct task_struct *task,
11307 +       const char *_file, int _line, void *_here)
11308 +{
11309 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
11310 +               vxi, vxi ? vxi->vx_id : 0,
11311 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
11312 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
11313 +               task, _file, _line);
11314 +       __vxh_release_vx_info(vxi, task, _here);
11315 +
11316 +       might_sleep();
11317 +
11318 +       if (atomic_dec_and_test(&vxi->vx_tasks))
11319 +               unhash_vx_info(vxi);
11320 +}
11321 +
11322 +
11323 +#define task_get_vx_info(p) \
11324 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
11325 +
11326 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
11327 +       const char *_file, int _line, void *_here)
11328 +{
11329 +       struct vx_info *vxi;
11330 +
11331 +       task_lock(p);
11332 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
11333 +               p, _file, _line);
11334 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
11335 +       task_unlock(p);
11336 +       return vxi;
11337 +}
11338 +
11339 +
11340 +static inline void __wakeup_vx_info(struct vx_info *vxi)
11341 +{
11342 +       if (waitqueue_active(&vxi->vx_wait))
11343 +               wake_up_interruptible(&vxi->vx_wait);
11344 +}
11345 +
11346 +
11347 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
11348 +
11349 +static inline void __enter_vx_info(struct vx_info *vxi,
11350 +       struct vx_info_save *vxis, const char *_file, int _line)
11351 +{
11352 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
11353 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
11354 +               current->xid, current->vx_info, _file, _line);
11355 +       vxis->vxi = xchg(&current->vx_info, vxi);
11356 +       vxis->xid = current->xid;
11357 +       current->xid = vxi ? vxi->vx_id : 0;
11358 +}
11359 +
11360 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
11361 +
11362 +static inline void __leave_vx_info(struct vx_info_save *vxis,
11363 +       const char *_file, int _line)
11364 +{
11365 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
11366 +               vxis, vxis->xid, vxis->vxi, current,
11367 +               current->xid, current->vx_info, _file, _line);
11368 +       (void)xchg(&current->vx_info, vxis->vxi);
11369 +       current->xid = vxis->xid;
11370 +}
11371 +
11372 +
11373 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
11374 +{
11375 +       vxis->vxi = xchg(&current->vx_info, NULL);
11376 +       vxis->xid = xchg(&current->xid, (xid_t)0);
11377 +}
11378 +
11379 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
11380 +{
11381 +       (void)xchg(&current->xid, vxis->xid);
11382 +       (void)xchg(&current->vx_info, vxis->vxi);
11383 +}
11384 +
11385 +extern void exit_vx_info(struct task_struct *, int);
11386 +extern void exit_vx_info_early(struct task_struct *, int);
11387 +
11388 +
11389 +#else
11390 +#warning duplicate inclusion
11391 +#endif
11392 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_cowbl.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_cowbl.h
11393 --- linux-2.6.22.10/include/linux/vs_cowbl.h    1970-01-01 01:00:00 +0100
11394 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_cowbl.h  2007-06-15 02:37:04 +0200
11395 @@ -0,0 +1,44 @@
11396 +#ifndef _VS_COWBL_H
11397 +#define _VS_COWBL_H
11398 +
11399 +#include <linux/fs.h>
11400 +#include <linux/dcache.h>
11401 +#include <linux/namei.h>
11402 +
11403 +extern struct dentry *cow_break_link(const char *pathname);
11404 +
11405 +static inline int cow_check_and_break(struct nameidata *nd)
11406 +{
11407 +       struct inode *inode = nd->dentry->d_inode;
11408 +       int error = 0;
11409 +       if (IS_RDONLY(inode) || MNT_IS_RDONLY(nd->mnt))
11410 +               return -EROFS;
11411 +       if (IS_COW(inode)) {
11412 +               if (IS_COW_LINK(inode)) {
11413 +                       struct dentry *new_dentry, *old_dentry = nd->dentry;
11414 +                       char *path, *buf;
11415 +
11416 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
11417 +                       if (!buf) {
11418 +                               return -ENOMEM;
11419 +                       }
11420 +                       path = d_path(nd->dentry, nd->mnt, buf, PATH_MAX);
11421 +                       new_dentry = cow_break_link(path);
11422 +                       kfree(buf);
11423 +                       if (!IS_ERR(new_dentry)) {
11424 +                               nd->dentry = new_dentry;
11425 +                               dput(old_dentry);
11426 +                       } else
11427 +                               error = PTR_ERR(new_dentry);
11428 +               } else {
11429 +                       inode->i_flags &= ~(S_IUNLINK | S_IMMUTABLE);
11430 +                       inode->i_ctime = CURRENT_TIME;
11431 +                       mark_inode_dirty(inode);
11432 +               }
11433 +       }
11434 +       return error;
11435 +}
11436 +
11437 +#else
11438 +#warning duplicate inclusion
11439 +#endif
11440 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_cvirt.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_cvirt.h
11441 --- linux-2.6.22.10/include/linux/vs_cvirt.h    1970-01-01 01:00:00 +0100
11442 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_cvirt.h  2007-06-15 02:37:04 +0200
11443 @@ -0,0 +1,49 @@
11444 +#ifndef _VS_CVIRT_H
11445 +#define _VS_CVIRT_H
11446 +
11447 +#include "vserver/cvirt.h"
11448 +#include "vserver/context.h"
11449 +#include "vserver/base.h"
11450 +#include "vserver/debug.h"
11451 +
11452 +
11453 +static inline void vx_activate_task(struct task_struct *p)
11454 +{
11455 +       struct vx_info *vxi;
11456 +
11457 +       if ((vxi = p->vx_info)) {
11458 +               vx_update_load(vxi);
11459 +               atomic_inc(&vxi->cvirt.nr_running);
11460 +       }
11461 +}
11462 +
11463 +static inline void vx_deactivate_task(struct task_struct *p)
11464 +{
11465 +       struct vx_info *vxi;
11466 +
11467 +       if ((vxi = p->vx_info)) {
11468 +               vx_update_load(vxi);
11469 +               atomic_dec(&vxi->cvirt.nr_running);
11470 +       }
11471 +}
11472 +
11473 +static inline void vx_uninterruptible_inc(struct task_struct *p)
11474 +{
11475 +       struct vx_info *vxi;
11476 +
11477 +       if ((vxi = p->vx_info))
11478 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
11479 +}
11480 +
11481 +static inline void vx_uninterruptible_dec(struct task_struct *p)
11482 +{
11483 +       struct vx_info *vxi;
11484 +
11485 +       if ((vxi = p->vx_info))
11486 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
11487 +}
11488 +
11489 +
11490 +#else
11491 +#warning duplicate inclusion
11492 +#endif
11493 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_dlimit.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_dlimit.h
11494 --- linux-2.6.22.10/include/linux/vs_dlimit.h   1970-01-01 01:00:00 +0100
11495 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_dlimit.h 2007-06-15 02:37:04 +0200
11496 @@ -0,0 +1,209 @@
11497 +#ifndef _VS_DLIMIT_H
11498 +#define _VS_DLIMIT_H
11499 +
11500 +#include "vserver/dlimit.h"
11501 +#include "vserver/base.h"
11502 +#include "vserver/debug.h"
11503 +
11504 +
11505 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
11506 +
11507 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
11508 +       const char *_file, int _line)
11509 +{
11510 +       if (!dli)
11511 +               return NULL;
11512 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
11513 +               dli, dli ? dli->dl_tag : 0,
11514 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11515 +               _file, _line);
11516 +       atomic_inc(&dli->dl_usecnt);
11517 +       return dli;
11518 +}
11519 +
11520 +
11521 +#define free_dl_info(i) \
11522 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
11523 +
11524 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
11525 +
11526 +static inline void __put_dl_info(struct dl_info *dli,
11527 +       const char *_file, int _line)
11528 +{
11529 +       if (!dli)
11530 +               return;
11531 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
11532 +               dli, dli ? dli->dl_tag : 0,
11533 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
11534 +               _file, _line);
11535 +       if (atomic_dec_and_test(&dli->dl_usecnt))
11536 +               free_dl_info(dli);
11537 +}
11538 +
11539 +
11540 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
11541 +
11542 +static inline int __dl_alloc_space(struct super_block *sb,
11543 +       tag_t tag, dlsize_t nr, const char *file, int line)
11544 +{
11545 +       struct dl_info *dli = NULL;
11546 +       int ret = 0;
11547 +
11548 +       if (nr == 0)
11549 +               goto out;
11550 +       dli = locate_dl_info(sb, tag);
11551 +       if (!dli)
11552 +               goto out;
11553 +
11554 +       spin_lock(&dli->dl_lock);
11555 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
11556 +       if (!ret)
11557 +               dli->dl_space_used += nr;
11558 +       spin_unlock(&dli->dl_lock);
11559 +       put_dl_info(dli);
11560 +out:
11561 +       vxlprintk(VXD_CBIT(dlim, 1),
11562 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
11563 +               sb, tag, __dlimit_char(dli), (long long)nr,
11564 +               ret, file, line);
11565 +       return ret;
11566 +}
11567 +
11568 +static inline void __dl_free_space(struct super_block *sb,
11569 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
11570 +{
11571 +       struct dl_info *dli = NULL;
11572 +
11573 +       if (nr == 0)
11574 +               goto out;
11575 +       dli = locate_dl_info(sb, tag);
11576 +       if (!dli)
11577 +               goto out;
11578 +
11579 +       spin_lock(&dli->dl_lock);
11580 +       if (dli->dl_space_used > nr)
11581 +               dli->dl_space_used -= nr;
11582 +       else
11583 +               dli->dl_space_used = 0;
11584 +       spin_unlock(&dli->dl_lock);
11585 +       put_dl_info(dli);
11586 +out:
11587 +       vxlprintk(VXD_CBIT(dlim, 1),
11588 +               "FREE  (%p,#%d)%c %lld bytes",
11589 +               sb, tag, __dlimit_char(dli), (long long)nr,
11590 +               _file, _line);
11591 +}
11592 +
11593 +static inline int __dl_alloc_inode(struct super_block *sb,
11594 +       tag_t tag, const char *_file, int _line)
11595 +{
11596 +       struct dl_info *dli;
11597 +       int ret = 0;
11598 +
11599 +       dli = locate_dl_info(sb, tag);
11600 +       if (!dli)
11601 +               goto out;
11602 +
11603 +       spin_lock(&dli->dl_lock);
11604 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
11605 +       if (!ret)
11606 +               dli->dl_inodes_used++;
11607 +       spin_unlock(&dli->dl_lock);
11608 +       put_dl_info(dli);
11609 +out:
11610 +       vxlprintk(VXD_CBIT(dlim, 0),
11611 +               "ALLOC (%p,#%d)%c inode (%d)",
11612 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
11613 +       return ret;
11614 +}
11615 +
11616 +static inline void __dl_free_inode(struct super_block *sb,
11617 +       tag_t tag, const char *_file, int _line)
11618 +{
11619 +       struct dl_info *dli;
11620 +
11621 +       dli = locate_dl_info(sb, tag);
11622 +       if (!dli)
11623 +               goto out;
11624 +
11625 +       spin_lock(&dli->dl_lock);
11626 +       if (dli->dl_inodes_used > 1)
11627 +               dli->dl_inodes_used--;
11628 +       else
11629 +               dli->dl_inodes_used = 0;
11630 +       spin_unlock(&dli->dl_lock);
11631 +       put_dl_info(dli);
11632 +out:
11633 +       vxlprintk(VXD_CBIT(dlim, 0),
11634 +               "FREE  (%p,#%d)%c inode",
11635 +               sb, tag, __dlimit_char(dli), _file, _line);
11636 +}
11637 +
11638 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
11639 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
11640 +       const char *_file, int _line)
11641 +{
11642 +       struct dl_info *dli;
11643 +       uint64_t broot, bfree;
11644 +
11645 +       dli = locate_dl_info(sb, tag);
11646 +       if (!dli)
11647 +               return;
11648 +
11649 +       spin_lock(&dli->dl_lock);
11650 +       broot = (dli->dl_space_total -
11651 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
11652 +               >> sb->s_blocksize_bits;
11653 +       bfree = (dli->dl_space_total - dli->dl_space_used)
11654 +                       >> sb->s_blocksize_bits;
11655 +       spin_unlock(&dli->dl_lock);
11656 +
11657 +       vxlprintk(VXD_CBIT(dlim, 2),
11658 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
11659 +               (long long)bfree, (long long)broot,
11660 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
11661 +               _file, _line);
11662 +       if (free_blocks) {
11663 +               if (*free_blocks > bfree)
11664 +                       *free_blocks = bfree;
11665 +       }
11666 +       if (root_blocks) {
11667 +               if (*root_blocks > broot)
11668 +                       *root_blocks = broot;
11669 +       }
11670 +       put_dl_info(dli);
11671 +}
11672 +
11673 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
11674 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11675 +               __FILE__, __LINE__ )
11676 +
11677 +#define DLIMIT_FREE_SPACE(in, bytes) \
11678 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
11679 +               __FILE__, __LINE__ )
11680 +
11681 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
11682 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
11683 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
11684 +               __FILE__, __LINE__ )
11685 +
11686 +#define DLIMIT_FREE_BLOCK(in, nr) \
11687 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
11688 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
11689 +               __FILE__, __LINE__ )
11690 +
11691 +
11692 +#define DLIMIT_ALLOC_INODE(in) \
11693 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11694 +
11695 +#define DLIMIT_FREE_INODE(in) \
11696 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
11697 +
11698 +
11699 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
11700 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
11701 +
11702 +
11703 +#else
11704 +#warning duplicate inclusion
11705 +#endif
11706 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_limit.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_limit.h
11707 --- linux-2.6.22.10/include/linux/vs_limit.h    1970-01-01 01:00:00 +0100
11708 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_limit.h  2007-06-15 02:37:04 +0200
11709 @@ -0,0 +1,140 @@
11710 +#ifndef _VS_LIMIT_H
11711 +#define _VS_LIMIT_H
11712 +
11713 +#include "vserver/limit.h"
11714 +#include "vserver/base.h"
11715 +#include "vserver/context.h"
11716 +#include "vserver/debug.h"
11717 +#include "vserver/context.h"
11718 +#include "vserver/limit_int.h"
11719 +
11720 +
11721 +#define vx_acc_cres(v, d, p, r) \
11722 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
11723 +
11724 +#define vx_acc_cres_cond(x, d, p, r) \
11725 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
11726 +       r, d, p, __FILE__, __LINE__)
11727 +
11728 +
11729 +#define vx_add_cres(v, a, p, r) \
11730 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
11731 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
11732 +
11733 +#define vx_add_cres_cond(x, a, p, r) \
11734 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
11735 +       r, a, p, __FILE__, __LINE__)
11736 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
11737 +
11738 +
11739 +/* process and file limits */
11740 +
11741 +#define vx_nproc_inc(p) \
11742 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
11743 +
11744 +#define vx_nproc_dec(p) \
11745 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
11746 +
11747 +#define vx_files_inc(f) \
11748 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
11749 +
11750 +#define vx_files_dec(f) \
11751 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
11752 +
11753 +#define vx_locks_inc(l) \
11754 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
11755 +
11756 +#define vx_locks_dec(l) \
11757 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
11758 +
11759 +#define vx_openfd_inc(f) \
11760 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
11761 +
11762 +#define vx_openfd_dec(f) \
11763 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
11764 +
11765 +
11766 +#define vx_cres_avail(v, n, r) \
11767 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
11768 +
11769 +
11770 +#define vx_nproc_avail(n) \
11771 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
11772 +
11773 +#define vx_files_avail(n) \
11774 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
11775 +
11776 +#define vx_locks_avail(n) \
11777 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
11778 +
11779 +#define vx_openfd_avail(n) \
11780 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
11781 +
11782 +
11783 +/* dentry limits */
11784 +
11785 +#define vx_dentry_inc(d) do {                                          \
11786 +       if (atomic_read(&d->d_count) == 1)                              \
11787 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
11788 +       } while (0)
11789 +
11790 +#define vx_dentry_dec(d) do {                                          \
11791 +       if (atomic_read(&d->d_count) == 0)                              \
11792 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
11793 +       } while (0)
11794 +
11795 +#define vx_dentry_avail(n) \
11796 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
11797 +
11798 +
11799 +/* socket limits */
11800 +
11801 +#define vx_sock_inc(s) \
11802 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
11803 +
11804 +#define vx_sock_dec(s) \
11805 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
11806 +
11807 +#define vx_sock_avail(n) \
11808 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
11809 +
11810 +
11811 +/* ipc resource limits */
11812 +
11813 +#define vx_ipcmsg_add(v, u, a) \
11814 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
11815 +
11816 +#define vx_ipcmsg_sub(v, u, a) \
11817 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
11818 +
11819 +#define vx_ipcmsg_avail(v, a) \
11820 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
11821 +
11822 +
11823 +#define vx_ipcshm_add(v, k, a) \
11824 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
11825 +
11826 +#define vx_ipcshm_sub(v, k, a) \
11827 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
11828 +
11829 +#define vx_ipcshm_avail(v, a) \
11830 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
11831 +
11832 +
11833 +#define vx_semary_inc(a) \
11834 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
11835 +
11836 +#define vx_semary_dec(a) \
11837 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
11838 +
11839 +
11840 +#define vx_nsems_add(a,n) \
11841 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
11842 +
11843 +#define vx_nsems_sub(a,n) \
11844 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
11845 +
11846 +
11847 +#else
11848 +#warning duplicate inclusion
11849 +#endif
11850 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_memory.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_memory.h
11851 --- linux-2.6.22.10/include/linux/vs_memory.h   1970-01-01 01:00:00 +0100
11852 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_memory.h 2007-06-15 02:37:04 +0200
11853 @@ -0,0 +1,159 @@
11854 +#ifndef _VS_MEMORY_H
11855 +#define _VS_MEMORY_H
11856 +
11857 +#include "vserver/limit.h"
11858 +#include "vserver/base.h"
11859 +#include "vserver/context.h"
11860 +#include "vserver/debug.h"
11861 +#include "vserver/context.h"
11862 +#include "vserver/limit_int.h"
11863 +
11864 +
11865 +#define __acc_add_long(a, v)   (*(v) += (a))
11866 +#define __acc_inc_long(v)      (++*(v))
11867 +#define __acc_dec_long(v)      (--*(v))
11868 +
11869 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
11870 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
11871 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
11872 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
11873 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11874 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
11875 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
11876 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
11877 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
11878 +
11879 +
11880 +#define vx_acc_page(m, d, v, r) do {                                   \
11881 +       if ((d) > 0)                                                    \
11882 +               __acc_inc_long(&(m)->v);                                \
11883 +       else                                                            \
11884 +               __acc_dec_long(&(m)->v);                                \
11885 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
11886 +} while (0)
11887 +
11888 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
11889 +       if ((d) > 0)                                                    \
11890 +               __acc_inc_atomic(&(m)->v);                              \
11891 +       else                                                            \
11892 +               __acc_dec_atomic(&(m)->v);                              \
11893 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
11894 +} while (0)
11895 +
11896 +
11897 +#define vx_acc_pages(m, p, v, r) do {                                  \
11898 +       unsigned long __p = (p);                                        \
11899 +       __acc_add_long(__p, &(m)->v);                                   \
11900 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
11901 +} while (0)
11902 +
11903 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
11904 +       unsigned long __p = (p);                                        \
11905 +       __acc_add_atomic(__p, &(m)->v);                                 \
11906 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
11907 +} while (0)
11908 +
11909 +
11910 +
11911 +#define vx_acc_vmpage(m, d) \
11912 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
11913 +#define vx_acc_vmlpage(m, d) \
11914 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
11915 +#define vx_acc_file_rsspage(m, d) \
11916 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
11917 +#define vx_acc_anon_rsspage(m, d) \
11918 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
11919 +
11920 +#define vx_acc_vmpages(m, p) \
11921 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
11922 +#define vx_acc_vmlpages(m, p) \
11923 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
11924 +#define vx_acc_file_rsspages(m, p) \
11925 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
11926 +#define vx_acc_anon_rsspages(m, p) \
11927 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
11928 +
11929 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
11930 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
11931 +
11932 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
11933 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
11934 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
11935 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
11936 +
11937 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
11938 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
11939 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
11940 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
11941 +
11942 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
11943 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
11944 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
11945 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
11946 +
11947 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
11948 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
11949 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
11950 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
11951 +
11952 +
11953 +#define vx_pages_avail(m, p, r) \
11954 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
11955 +
11956 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
11957 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
11958 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
11959 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
11960 +
11961 +#define vx_rss_avail(m, p) \
11962 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
11963 +
11964 +
11965 +enum {
11966 +       VXPT_UNKNOWN = 0,
11967 +       VXPT_ANON,
11968 +       VXPT_NONE,
11969 +       VXPT_FILE,
11970 +       VXPT_SWAP,
11971 +       VXPT_WRITE
11972 +};
11973 +
11974 +#if 0
11975 +#define        vx_page_fault(mm, vma, type, ret)
11976 +#else
11977 +
11978 +static inline
11979 +void __vx_page_fault(struct mm_struct *mm,
11980 +       struct vm_area_struct *vma, int type, int ret)
11981 +{
11982 +       struct vx_info *vxi = mm->mm_vx_info;
11983 +       int what;
11984 +/*
11985 +       static char *page_type[6] =
11986 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
11987 +       static char *page_what[4] =
11988 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
11989 +*/
11990 +
11991 +       if (!vxi)
11992 +               return;
11993 +
11994 +       what = (ret & 0x3);
11995 +
11996 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
11997 +               type, what, ret, page_type[type], page_what[what]);
11998 +*/
11999 +       if (ret & VM_FAULT_WRITE)
12000 +               what |= 0x4;
12001 +       atomic_inc(&vxi->cacct.page[type][what]);
12002 +}
12003 +
12004 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
12005 +#endif
12006 +
12007 +
12008 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
12009 +
12010 +#else
12011 +#warning duplicate inclusion
12012 +#endif
12013 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_network.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_network.h
12014 --- linux-2.6.22.10/include/linux/vs_network.h  1970-01-01 01:00:00 +0100
12015 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_network.h        2007-06-15 02:37:04 +0200
12016 @@ -0,0 +1,185 @@
12017 +#ifndef _NX_VS_NETWORK_H
12018 +#define _NX_VS_NETWORK_H
12019 +
12020 +#include "vserver/context.h"
12021 +#include "vserver/network.h"
12022 +#include "vserver/base.h"
12023 +#include "vserver/debug.h"
12024 +
12025 +
12026 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
12027 +
12028 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
12029 +       const char *_file, int _line)
12030 +{
12031 +       if (!nxi)
12032 +               return NULL;
12033 +
12034 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
12035 +               nxi, nxi ? nxi->nx_id : 0,
12036 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12037 +               _file, _line);
12038 +
12039 +       atomic_inc(&nxi->nx_usecnt);
12040 +       return nxi;
12041 +}
12042 +
12043 +
12044 +extern void free_nx_info(struct nx_info *);
12045 +
12046 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
12047 +
12048 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
12049 +{
12050 +       if (!nxi)
12051 +               return;
12052 +
12053 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
12054 +               nxi, nxi ? nxi->nx_id : 0,
12055 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12056 +               _file, _line);
12057 +
12058 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
12059 +               free_nx_info(nxi);
12060 +}
12061 +
12062 +
12063 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
12064 +
12065 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
12066 +               const char *_file, int _line)
12067 +{
12068 +       if (nxi) {
12069 +               vxlprintk(VXD_CBIT(nid, 3),
12070 +                       "init_nx_info(%p[#%d.%d])",
12071 +                       nxi, nxi ? nxi->nx_id : 0,
12072 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12073 +                       _file, _line);
12074 +
12075 +               atomic_inc(&nxi->nx_usecnt);
12076 +       }
12077 +       *nxp = nxi;
12078 +}
12079 +
12080 +
12081 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
12082 +
12083 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
12084 +       const char *_file, int _line)
12085 +{
12086 +       struct nx_info *nxo;
12087 +
12088 +       if (!nxi)
12089 +               return;
12090 +
12091 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
12092 +               nxi, nxi ? nxi->nx_id : 0,
12093 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12094 +               _file, _line);
12095 +
12096 +       atomic_inc(&nxi->nx_usecnt);
12097 +       nxo = xchg(nxp, nxi);
12098 +       BUG_ON(nxo);
12099 +}
12100 +
12101 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
12102 +
12103 +static inline void __clr_nx_info(struct nx_info **nxp,
12104 +       const char *_file, int _line)
12105 +{
12106 +       struct nx_info *nxo;
12107 +
12108 +       nxo = xchg(nxp, NULL);
12109 +       if (!nxo)
12110 +               return;
12111 +
12112 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
12113 +               nxo, nxo ? nxo->nx_id : 0,
12114 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
12115 +               _file, _line);
12116 +
12117 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
12118 +               free_nx_info(nxo);
12119 +}
12120 +
12121 +
12122 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
12123 +
12124 +static inline void __claim_nx_info(struct nx_info *nxi,
12125 +       struct task_struct *task, const char *_file, int _line)
12126 +{
12127 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
12128 +               nxi, nxi ? nxi->nx_id : 0,
12129 +               nxi?atomic_read(&nxi->nx_usecnt):0,
12130 +               nxi?atomic_read(&nxi->nx_tasks):0,
12131 +               task, _file, _line);
12132 +
12133 +       atomic_inc(&nxi->nx_tasks);
12134 +}
12135 +
12136 +
12137 +extern void unhash_nx_info(struct nx_info *);
12138 +
12139 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
12140 +
12141 +static inline void __release_nx_info(struct nx_info *nxi,
12142 +       struct task_struct *task, const char *_file, int _line)
12143 +{
12144 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
12145 +               nxi, nxi ? nxi->nx_id : 0,
12146 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
12147 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
12148 +               task, _file, _line);
12149 +
12150 +       might_sleep();
12151 +
12152 +       if (atomic_dec_and_test(&nxi->nx_tasks))
12153 +               unhash_nx_info(nxi);
12154 +}
12155 +
12156 +
12157 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
12158 +
12159 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
12160 +       const char *_file, int _line)
12161 +{
12162 +       struct nx_info *nxi;
12163 +
12164 +       task_lock(p);
12165 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
12166 +               p, _file, _line);
12167 +       nxi = __get_nx_info(p->nx_info, _file, _line);
12168 +       task_unlock(p);
12169 +       return nxi;
12170 +}
12171 +
12172 +
12173 +
12174 +
12175 +static inline int addr_in_nx_info(struct nx_info *nxi, uint32_t addr)
12176 +{
12177 +       int n, i;
12178 +
12179 +       if (!nxi)
12180 +               return 1;
12181 +
12182 +       n = nxi->nbipv4;
12183 +       if (n && (nxi->ipv4[0] == 0))
12184 +               return 1;
12185 +       for (i = 0; i < n; i++) {
12186 +               if (nxi->ipv4[i] == addr)
12187 +                       return 1;
12188 +       }
12189 +       return 0;
12190 +}
12191 +
12192 +static inline void exit_nx_info(struct task_struct *p)
12193 +{
12194 +       if (p->nx_info)
12195 +               release_nx_info(p->nx_info, p);
12196 +}
12197 +
12198 +
12199 +#else
12200 +#warning duplicate inclusion
12201 +#endif
12202 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_pid.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_pid.h
12203 --- linux-2.6.22.10/include/linux/vs_pid.h      1970-01-01 01:00:00 +0100
12204 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_pid.h    2007-06-15 02:37:04 +0200
12205 @@ -0,0 +1,133 @@
12206 +#ifndef _VS_PID_H
12207 +#define _VS_PID_H
12208 +
12209 +#include "vserver/base.h"
12210 +#include "vserver/context.h"
12211 +#include "vserver/debug.h"
12212 +#include <linux/pid_namespace.h>
12213 +
12214 +
12215 +/* pid faking stuff */
12216 +
12217 +
12218 +#define vx_info_map_pid(v, p) \
12219 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
12220 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12221 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
12222 +#define vx_map_tgid(p) vx_map_pid(p)
12223 +
12224 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12225 +       const char *func, const char *file, int line)
12226 +{
12227 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12228 +               vxfprintk(VXD_CBIT(cvirt, 2),
12229 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12230 +                       vxi, (long long)vxi->vx_flags, pid,
12231 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12232 +                       func, file, line);
12233 +               if (pid == 0)
12234 +                       return 0;
12235 +               if (pid == vxi->vx_initpid)
12236 +                       return 1;
12237 +       }
12238 +       return pid;
12239 +}
12240 +
12241 +#define vx_info_rmap_pid(v, p) \
12242 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
12243 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
12244 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12245 +
12246 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12247 +       const char *func, const char *file, int line)
12248 +{
12249 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12250 +               vxfprintk(VXD_CBIT(cvirt, 2),
12251 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12252 +                       vxi, (long long)vxi->vx_flags, pid,
12253 +                       (pid == 1) ? vxi->vx_initpid : pid,
12254 +                       func, file, line);
12255 +               if ((pid == 1) && vxi->vx_initpid)
12256 +                       return vxi->vx_initpid;
12257 +               if (pid == vxi->vx_initpid)
12258 +                       return ~0U;
12259 +       }
12260 +       return pid;
12261 +}
12262 +
12263 +
12264 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
12265 +
12266 +static inline
12267 +int vx_proc_task_visible(struct task_struct *task)
12268 +{
12269 +       if ((task->pid == 1) &&
12270 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
12271 +               /* show a blend through init */
12272 +               goto visible;
12273 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
12274 +               goto visible;
12275 +       return 0;
12276 +visible:
12277 +       return 1;
12278 +}
12279 +
12280 +static inline
12281 +struct task_struct *vx_find_proc_task_by_pid(int pid)
12282 +{
12283 +       struct task_struct *task = find_task_by_real_pid(pid);
12284 +
12285 +       if (task && !vx_proc_task_visible(task)) {
12286 +               vxdprintk(VXD_CBIT(misc, 6),
12287 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
12288 +                       task, task->xid, task->pid,
12289 +                       current, current->xid, current->pid);
12290 +               task = NULL;
12291 +       }
12292 +       return task;
12293 +}
12294 +
12295 +static inline
12296 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
12297 +{
12298 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
12299 +
12300 +       if (task && !vx_proc_task_visible(task)) {
12301 +               vxdprintk(VXD_CBIT(misc, 6),
12302 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
12303 +                       task, task->xid, task->pid,
12304 +                       current, current->xid, current->pid);
12305 +               put_task_struct(task);
12306 +               task = NULL;
12307 +       }
12308 +       return task;
12309 +}
12310 +
12311 +
12312 +static inline
12313 +struct task_struct *vx_child_reaper(struct task_struct *p)
12314 +{
12315 +       struct vx_info *vxi = p->vx_info;
12316 +       struct task_struct *reaper = child_reaper(p);
12317 +
12318 +       if (!vxi)
12319 +               goto out;
12320 +
12321 +       BUG_ON(!p->vx_info->vx_reaper);
12322 +
12323 +       /* child reaper for the guest reaper */
12324 +       if (vxi->vx_reaper == p)
12325 +               goto out;
12326 +
12327 +       reaper = vxi->vx_reaper;
12328 +out:
12329 +       vxdprintk(VXD_CBIT(xid, 7),
12330 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
12331 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
12332 +       return reaper;
12333 +}
12334 +
12335 +
12336 +#else
12337 +#warning duplicate inclusion
12338 +#endif
12339 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_sched.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_sched.h
12340 --- linux-2.6.22.10/include/linux/vs_sched.h    1970-01-01 01:00:00 +0100
12341 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_sched.h  2007-06-15 02:37:04 +0200
12342 @@ -0,0 +1,110 @@
12343 +#ifndef _VS_SCHED_H
12344 +#define _VS_SCHED_H
12345 +
12346 +#include "vserver/base.h"
12347 +#include "vserver/context.h"
12348 +#include "vserver/sched.h"
12349 +
12350 +
12351 +#define VAVAVOOM_RATIO          50
12352 +
12353 +#define MAX_PRIO_BIAS           20
12354 +#define MIN_PRIO_BIAS          -20
12355 +
12356 +
12357 +#ifdef CONFIG_VSERVER_HARDCPU
12358 +
12359 +/*
12360 + * effective_prio - return the priority that is based on the static
12361 + * priority but is modified by bonuses/penalties.
12362 + *
12363 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
12364 + * into a -4 ... 0 ... +4 bonus/penalty range.
12365 + *
12366 + * Additionally, we scale another amount based on the number of
12367 + * CPU tokens currently held by the context, if the process is
12368 + * part of a context (and the appropriate SCHED flag is set).
12369 + * This ranges from -5 ... 0 ... +15, quadratically.
12370 + *
12371 + * So, the total bonus is -9 .. 0 .. +19
12372 + * We use ~50% of the full 0...39 priority range so that:
12373 + *
12374 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
12375 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
12376 + *    unless that context is far exceeding its CPU allocation.
12377 + *
12378 + * Both properties are important to certain workloads.
12379 + */
12380 +static inline
12381 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
12382 +{
12383 +       int vavavoom, max;
12384 +
12385 +       /* lots of tokens = lots of vavavoom
12386 +        *      no tokens = no vavavoom      */
12387 +       if ((vavavoom = sched_pc->tokens) >= 0) {
12388 +               max = sched_pc->tokens_max;
12389 +               vavavoom = max - vavavoom;
12390 +               max = max * max;
12391 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
12392 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
12393 +               return vavavoom;
12394 +       }
12395 +       return 0;
12396 +}
12397 +
12398 +
12399 +static inline
12400 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
12401 +{
12402 +       struct vx_info *vxi = p->vx_info;
12403 +       struct _vx_sched_pc *sched_pc;
12404 +
12405 +       if (!vxi)
12406 +               return prio;
12407 +
12408 +       sched_pc = &vx_cpu(vxi, sched_pc);
12409 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
12410 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
12411 +
12412 +               sched_pc->vavavoom = vavavoom;
12413 +               prio += vavavoom;
12414 +       }
12415 +       prio += sched_pc->prio_bias;
12416 +       return prio;
12417 +}
12418 +
12419 +#else /* !CONFIG_VSERVER_HARDCPU */
12420 +
12421 +static inline
12422 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
12423 +{
12424 +       struct vx_info *vxi = p->vx_info;
12425 +
12426 +       if (vxi)
12427 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
12428 +       return prio;
12429 +}
12430 +
12431 +#endif /* CONFIG_VSERVER_HARDCPU */
12432 +
12433 +
12434 +static inline void vx_account_user(struct vx_info *vxi,
12435 +       cputime_t cputime, int nice)
12436 +{
12437 +       if (!vxi)
12438 +               return;
12439 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
12440 +}
12441 +
12442 +static inline void vx_account_system(struct vx_info *vxi,
12443 +       cputime_t cputime, int idle)
12444 +{
12445 +       if (!vxi)
12446 +               return;
12447 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
12448 +}
12449 +
12450 +#else
12451 +#warning duplicate inclusion
12452 +#endif
12453 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_socket.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_socket.h
12454 --- linux-2.6.22.10/include/linux/vs_socket.h   1970-01-01 01:00:00 +0100
12455 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_socket.h 2007-06-15 02:37:04 +0200
12456 @@ -0,0 +1,67 @@
12457 +#ifndef _VS_SOCKET_H
12458 +#define _VS_SOCKET_H
12459 +
12460 +#include "vserver/debug.h"
12461 +#include "vserver/base.h"
12462 +#include "vserver/cacct.h"
12463 +#include "vserver/context.h"
12464 +
12465 +
12466 +/* socket accounting */
12467 +
12468 +#include <linux/socket.h>
12469 +
12470 +static inline int vx_sock_type(int family)
12471 +{
12472 +       switch (family) {
12473 +       case PF_UNSPEC:
12474 +               return VXA_SOCK_UNSPEC;
12475 +       case PF_UNIX:
12476 +               return VXA_SOCK_UNIX;
12477 +       case PF_INET:
12478 +               return VXA_SOCK_INET;
12479 +       case PF_INET6:
12480 +               return VXA_SOCK_INET6;
12481 +       case PF_PACKET:
12482 +               return VXA_SOCK_PACKET;
12483 +       default:
12484 +               return VXA_SOCK_OTHER;
12485 +       }
12486 +}
12487 +
12488 +#define vx_acc_sock(v, f, p, s) \
12489 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
12490 +
12491 +static inline void __vx_acc_sock(struct vx_info *vxi,
12492 +       int family, int pos, int size, char *file, int line)
12493 +{
12494 +       if (vxi) {
12495 +               int type = vx_sock_type(family);
12496 +
12497 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
12498 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
12499 +       }
12500 +}
12501 +
12502 +#define vx_sock_recv(sk, s) \
12503 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
12504 +#define vx_sock_send(sk, s) \
12505 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
12506 +#define vx_sock_fail(sk, s) \
12507 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
12508 +
12509 +
12510 +#define sock_vx_init(s) do {           \
12511 +       (s)->sk_xid = 0;                \
12512 +       (s)->sk_vx_info = NULL;         \
12513 +       } while (0)
12514 +
12515 +#define sock_nx_init(s) do {           \
12516 +       (s)->sk_nid = 0;                \
12517 +       (s)->sk_nx_info = NULL;         \
12518 +       } while (0)
12519 +
12520 +
12521 +#else
12522 +#warning duplicate inclusion
12523 +#endif
12524 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_tag.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_tag.h
12525 --- linux-2.6.22.10/include/linux/vs_tag.h      1970-01-01 01:00:00 +0100
12526 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_tag.h    2007-06-15 02:37:04 +0200
12527 @@ -0,0 +1,43 @@
12528 +#ifndef _VS_TAG_H
12529 +#define _VS_TAG_H
12530 +
12531 +#include <linux/vserver/tag.h>
12532 +
12533 +/* check conditions */
12534 +
12535 +#define DX_ADMIN       0x0001
12536 +#define DX_WATCH       0x0002
12537 +#define DX_HOSTID      0x0008
12538 +
12539 +#define DX_IDENT       0x0010
12540 +
12541 +#define DX_ARG_MASK    0x0010
12542 +
12543 +
12544 +#define dx_task_tag(t) ((t)->xid)
12545 +
12546 +#define dx_current_tag() dx_task_tag(current)
12547 +
12548 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
12549 +
12550 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
12551 +
12552 +
12553 +/*
12554 + * check current context for ADMIN/WATCH and
12555 + * optionally against supplied argument
12556 + */
12557 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
12558 +{
12559 +       if (mode & DX_ARG_MASK) {
12560 +               if ((mode & DX_IDENT) && (id == cid))
12561 +                       return 1;
12562 +       }
12563 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
12564 +               ((mode & DX_WATCH) && (cid == 1)) ||
12565 +               ((mode & DX_HOSTID) && (id == 0)));
12566 +}
12567 +
12568 +#else
12569 +#warning duplicate inclusion
12570 +#endif
12571 diff -NurpP --minimal linux-2.6.22.10/include/linux/vs_time.h linux-2.6.22.10-vs2.2.0.5/include/linux/vs_time.h
12572 --- linux-2.6.22.10/include/linux/vs_time.h     1970-01-01 01:00:00 +0100
12573 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vs_time.h   2007-06-15 02:37:04 +0200
12574 @@ -0,0 +1,19 @@
12575 +#ifndef _VS_TIME_H
12576 +#define _VS_TIME_H
12577 +
12578 +
12579 +/* time faking stuff */
12580 +
12581 +#ifdef CONFIG_VSERVER_VTIME
12582 +
12583 +extern void vx_gettimeofday(struct timeval *tv);
12584 +extern int vx_settimeofday(struct timespec *ts);
12585 +
12586 +#else
12587 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
12588 +#define        vx_settimeofday(t)      do_settimeofday(t)
12589 +#endif
12590 +
12591 +#else
12592 +#warning duplicate inclusion
12593 +#endif
12594 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/Kbuild linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/Kbuild
12595 --- linux-2.6.22.10/include/linux/vserver/Kbuild        1970-01-01 01:00:00 +0100
12596 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/Kbuild      2007-06-16 19:48:30 +0200
12597 @@ -0,0 +1,9 @@
12598 +
12599 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
12600 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12601 +       inode_cmd.h sched_cmd.h signal_cmd.h debug_cmd.h
12602 +
12603 +unifdef-y += switch.h network.h monitor.h inode.h
12604 +
12605 +unifdef-y += legacy.h
12606 +
12607 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/base.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/base.h
12608 --- linux-2.6.22.10/include/linux/vserver/base.h        1970-01-01 01:00:00 +0100
12609 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/base.h      2007-06-15 02:37:04 +0200
12610 @@ -0,0 +1,236 @@
12611 +#ifndef _VX_BASE_H
12612 +#define _VX_BASE_H
12613 +
12614 +
12615 +/* context state changes */
12616 +
12617 +enum {
12618 +       VSC_STARTUP = 1,
12619 +       VSC_SHUTDOWN,
12620 +
12621 +       VSC_NETUP,
12622 +       VSC_NETDOWN,
12623 +};
12624 +
12625 +
12626 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
12627 +
12628 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
12629 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
12630 +#else
12631 +#define MIN_D_CONTEXT  65536
12632 +#endif
12633 +
12634 +/* check conditions */
12635 +
12636 +#define VS_ADMIN       0x0001
12637 +#define VS_WATCH       0x0002
12638 +#define VS_HIDE                0x0004
12639 +#define VS_HOSTID      0x0008
12640 +
12641 +#define VS_IDENT       0x0010
12642 +#define VS_EQUIV       0x0020
12643 +#define VS_PARENT      0x0040
12644 +#define VS_CHILD       0x0080
12645 +
12646 +#define VS_ARG_MASK    0x00F0
12647 +
12648 +#define VS_DYNAMIC     0x0100
12649 +#define VS_STATIC      0x0200
12650 +
12651 +#define VS_ATR_MASK    0x0F00
12652 +
12653 +#ifdef CONFIG_VSERVER_PRIVACY
12654 +#define VS_ADMIN_P     (0)
12655 +#define VS_WATCH_P     (0)
12656 +#else
12657 +#define VS_ADMIN_P     VS_ADMIN
12658 +#define VS_WATCH_P     VS_WATCH
12659 +#endif
12660 +
12661 +#define VS_HARDIRQ     0x1000
12662 +#define VS_SOFTIRQ     0x2000
12663 +#define VS_IRQ         0x4000
12664 +
12665 +#define VS_IRQ_MASK    0xF000
12666 +
12667 +#include <linux/hardirq.h>
12668 +
12669 +/*
12670 + * check current context for ADMIN/WATCH and
12671 + * optionally against supplied argument
12672 + */
12673 +static inline int __vs_check(int cid, int id, unsigned int mode)
12674 +{
12675 +       if (mode & VS_ARG_MASK) {
12676 +               if ((mode & VS_IDENT) && (id == cid))
12677 +                       return 1;
12678 +       }
12679 +       if (mode & VS_ATR_MASK) {
12680 +               if ((mode & VS_DYNAMIC) &&
12681 +                       (id >= MIN_D_CONTEXT) &&
12682 +                       (id <= MAX_S_CONTEXT))
12683 +                       return 1;
12684 +               if ((mode & VS_STATIC) &&
12685 +                       (id > 1) && (id < MIN_D_CONTEXT))
12686 +                       return 1;
12687 +       }
12688 +       if (mode & VS_IRQ_MASK) {
12689 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
12690 +                       return 1;
12691 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
12692 +                       return 1;
12693 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
12694 +                       return 1;
12695 +       }
12696 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
12697 +               ((mode & VS_WATCH) && (cid == 1)) ||
12698 +               ((mode & VS_HOSTID) && (id == 0)));
12699 +}
12700 +
12701 +#define vx_task_xid(t) ((t)->xid)
12702 +
12703 +#define vx_current_xid() vx_task_xid(current)
12704 +
12705 +#define current_vx_info() (current->vx_info)
12706 +
12707 +
12708 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
12709 +
12710 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
12711 +
12712 +
12713 +#define nx_task_nid(t) ((t)->nid)
12714 +
12715 +#define nx_current_nid() nx_task_nid(current)
12716 +
12717 +#define current_nx_info() (current->nx_info)
12718 +
12719 +
12720 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
12721 +
12722 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
12723 +
12724 +
12725 +
12726 +/* generic flag merging */
12727 +
12728 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
12729 +
12730 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
12731 +
12732 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
12733 +
12734 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
12735 +
12736 +
12737 +/* context flags */
12738 +
12739 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
12740 +
12741 +#define vx_current_flags()     __vx_flags(current->vx_info)
12742 +
12743 +#define vx_info_flags(v, m, f) \
12744 +       vs_check_flags(__vx_flags(v), m, f)
12745 +
12746 +#define task_vx_flags(t, m, f) \
12747 +       ((t) && vx_info_flags((t)->vx_info, m, f))
12748 +
12749 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
12750 +
12751 +
12752 +/* context caps */
12753 +
12754 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
12755 +
12756 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
12757 +
12758 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
12759 +
12760 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
12761 +
12762 +
12763 +
12764 +/* network flags */
12765 +
12766 +#define __nx_flags(v)  ((v) ? (v)->nx_flags : 0)
12767 +
12768 +#define nx_current_flags()     __nx_flags(current->nx_info)
12769 +
12770 +#define nx_info_flags(v, m, f) \
12771 +       vs_check_flags(__nx_flags(v), m, f)
12772 +
12773 +#define task_nx_flags(t, m, f) \
12774 +       ((t) && nx_info_flags((t)->nx_info, m, f))
12775 +
12776 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
12777 +
12778 +
12779 +/* network caps */
12780 +
12781 +#define __nx_ncaps(v)  ((v) ? (v)->nx_ncaps : 0)
12782 +
12783 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
12784 +
12785 +#define nx_info_ncaps(v, c)    (__nx_ncaps(v) & (c))
12786 +
12787 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
12788 +
12789 +
12790 +/* context mask capabilities */
12791 +
12792 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
12793 +
12794 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
12795 +
12796 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
12797 +
12798 +
12799 +/* context bcap mask */
12800 +
12801 +#define __vx_bcaps(v)  ((v) ? (v)->vx_bcaps : ~0 )
12802 +
12803 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
12804 +
12805 +#define vx_info_bcaps(v, c)    (__vx_bcaps(v) & (c))
12806 +
12807 +#define vx_bcaps(c)    vx_info_bcaps(current->vx_info, c)
12808 +
12809 +
12810 +#define vx_info_cap_bset(v)    ((v) ? (v)->vx_cap_bset : cap_bset)
12811 +
12812 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
12813 +
12814 +
12815 +#define __vx_info_mbcap(v, b) \
12816 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
12817 +       vx_info_bcaps(v, b) : (b))
12818 +
12819 +#define vx_info_mbcap(v, b)    __vx_info_mbcap(v, cap_t(b))
12820 +
12821 +#define task_vx_mbcap(t, b) \
12822 +       vx_info_mbcap((t)->vx_info, (t)->b)
12823 +
12824 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
12825 +
12826 +#define vx_cap_raised(v, c, f) (vx_info_mbcap(v, c) & CAP_TO_MASK(f))
12827 +
12828 +#define vx_capable(b, c) (capable(b) || \
12829 +       (cap_raised(current->cap_effective, b) && vx_ccaps(c)))
12830 +
12831 +
12832 +#define vx_current_initpid(n) \
12833 +       (current->vx_info && \
12834 +       (current->vx_info->vx_initpid == (n)))
12835 +
12836 +
12837 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
12838 +
12839 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
12840 +
12841 +
12842 +#define __nx_state(v)  ((v) ? ((v)->nx_state) : 0)
12843 +
12844 +#define nx_info_state(v, m)    (__nx_state(v) & (m))
12845 +
12846 +#endif
12847 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cacct.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cacct.h
12848 --- linux-2.6.22.10/include/linux/vserver/cacct.h       1970-01-01 01:00:00 +0100
12849 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cacct.h     2007-06-15 02:37:04 +0200
12850 @@ -0,0 +1,15 @@
12851 +#ifndef _VX_CACCT_H
12852 +#define _VX_CACCT_H
12853 +
12854 +
12855 +enum sock_acc_field {
12856 +       VXA_SOCK_UNSPEC = 0,
12857 +       VXA_SOCK_UNIX,
12858 +       VXA_SOCK_INET,
12859 +       VXA_SOCK_INET6,
12860 +       VXA_SOCK_PACKET,
12861 +       VXA_SOCK_OTHER,
12862 +       VXA_SOCK_SIZE   /* array size */
12863 +};
12864 +
12865 +#endif /* _VX_CACCT_H */
12866 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cacct_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cacct_cmd.h
12867 --- linux-2.6.22.10/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00 +0100
12868 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cacct_cmd.h 2007-06-15 02:37:04 +0200
12869 @@ -0,0 +1,23 @@
12870 +#ifndef _VX_CACCT_CMD_H
12871 +#define _VX_CACCT_CMD_H
12872 +
12873 +
12874 +/* virtual host info name commands */
12875 +
12876 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12877 +
12878 +struct vcmd_sock_stat_v0 {
12879 +       uint32_t field;
12880 +       uint32_t count[3];
12881 +       uint64_t total[3];
12882 +};
12883 +
12884 +
12885 +#ifdef __KERNEL__
12886 +
12887 +#include <linux/compiler.h>
12888 +
12889 +extern int vc_sock_stat(struct vx_info *, void __user *);
12890 +
12891 +#endif /* __KERNEL__ */
12892 +#endif /* _VX_CACCT_CMD_H */
12893 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cacct_def.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cacct_def.h
12894 --- linux-2.6.22.10/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00 +0100
12895 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cacct_def.h 2007-06-15 02:37:04 +0200
12896 @@ -0,0 +1,43 @@
12897 +#ifndef _VX_CACCT_DEF_H
12898 +#define _VX_CACCT_DEF_H
12899 +
12900 +#include <asm/atomic.h>
12901 +#include <linux/vserver/cacct.h>
12902 +
12903 +
12904 +struct _vx_sock_acc {
12905 +       atomic_long_t count;
12906 +       atomic_long_t total;
12907 +};
12908 +
12909 +/* context sub struct */
12910 +
12911 +struct _vx_cacct {
12912 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
12913 +       atomic_t slab[8];
12914 +       atomic_t page[6][8];
12915 +};
12916 +
12917 +#ifdef CONFIG_VSERVER_DEBUG
12918 +
12919 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
12920 +{
12921 +       int i, j;
12922 +
12923 +       printk("\t_vx_cacct:");
12924 +       for (i = 0; i < 6; i++) {
12925 +               struct _vx_sock_acc *ptr = cacct->sock[i];
12926 +
12927 +               printk("\t [%d] =", i);
12928 +               for (j = 0; j < 3; j++) {
12929 +                       printk(" [%d] = %8lu, %8lu", j,
12930 +                               atomic_long_read(&ptr[j].count),
12931 +                               atomic_long_read(&ptr[j].total));
12932 +               }
12933 +               printk("\n");
12934 +       }
12935 +}
12936 +
12937 +#endif
12938 +
12939 +#endif /* _VX_CACCT_DEF_H */
12940 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cacct_int.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cacct_int.h
12941 --- linux-2.6.22.10/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00 +0100
12942 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cacct_int.h 2007-06-15 02:37:04 +0200
12943 @@ -0,0 +1,21 @@
12944 +#ifndef _VX_CACCT_INT_H
12945 +#define _VX_CACCT_INT_H
12946 +
12947 +
12948 +#ifdef __KERNEL__
12949 +
12950 +static inline
12951 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
12952 +{
12953 +       return atomic_long_read(&cacct->sock[type][pos].count);
12954 +}
12955 +
12956 +
12957 +static inline
12958 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
12959 +{
12960 +       return atomic_long_read(&cacct->sock[type][pos].total);
12961 +}
12962 +
12963 +#endif /* __KERNEL__ */
12964 +#endif /* _VX_CACCT_INT_H */
12965 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/context.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/context.h
12966 --- linux-2.6.22.10/include/linux/vserver/context.h     1970-01-01 01:00:00 +0100
12967 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/context.h   2007-06-15 02:37:04 +0200
12968 @@ -0,0 +1,172 @@
12969 +#ifndef _VX_CONTEXT_H
12970 +#define _VX_CONTEXT_H
12971 +
12972 +#include <linux/types.h>
12973 +#include <linux/capability.h>
12974 +
12975 +
12976 +#define VX_DYNAMIC_ID  ((uint32_t)-1)          /* id for dynamic context */
12977 +
12978 +/* context flags */
12979 +
12980 +#define VXF_INFO_SCHED         0x00000002
12981 +#define VXF_INFO_NPROC         0x00000004
12982 +#define VXF_INFO_PRIVATE       0x00000008
12983 +
12984 +#define VXF_INFO_INIT          0x00000010
12985 +#define VXF_INFO_HIDE          0x00000020
12986 +#define VXF_INFO_ULIMIT                0x00000040
12987 +#define VXF_INFO_NSPACE                0x00000080
12988 +
12989 +#define VXF_SCHED_HARD         0x00000100
12990 +#define VXF_SCHED_PRIO         0x00000200
12991 +#define VXF_SCHED_PAUSE                0x00000400
12992 +
12993 +#define VXF_VIRT_MEM           0x00010000
12994 +#define VXF_VIRT_UPTIME                0x00020000
12995 +#define VXF_VIRT_CPU           0x00040000
12996 +#define VXF_VIRT_LOAD          0x00080000
12997 +#define VXF_VIRT_TIME          0x00100000
12998 +
12999 +#define VXF_HIDE_MOUNT         0x01000000
13000 +#define VXF_HIDE_NETIF         0x02000000
13001 +#define VXF_HIDE_VINFO         0x04000000
13002 +
13003 +#define VXF_STATE_SETUP                (1ULL << 32)
13004 +#define VXF_STATE_INIT         (1ULL << 33)
13005 +#define VXF_STATE_ADMIN                (1ULL << 34)
13006 +
13007 +#define VXF_SC_HELPER          (1ULL << 36)
13008 +#define VXF_REBOOT_KILL                (1ULL << 37)
13009 +#define VXF_PERSISTENT         (1ULL << 38)
13010 +
13011 +#define VXF_FORK_RSS           (1ULL << 48)
13012 +#define VXF_PROLIFIC           (1ULL << 49)
13013 +
13014 +#define VXF_IGNEG_NICE         (1ULL << 52)
13015 +
13016 +#define VXF_ONE_TIME           (0x0007ULL << 32)
13017 +
13018 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
13019 +
13020 +
13021 +/* context migration */
13022 +
13023 +#define VXM_SET_INIT           0x00000001
13024 +#define VXM_SET_REAPER         0x00000002
13025 +
13026 +/* context caps */
13027 +
13028 +#define VXC_CAP_MASK           0x00000000
13029 +
13030 +#define VXC_SET_UTSNAME                0x00000001
13031 +#define VXC_SET_RLIMIT         0x00000002
13032 +
13033 +#define VXC_RAW_ICMP           0x00000100
13034 +#define VXC_SYSLOG             0x00001000
13035 +
13036 +#define VXC_SECURE_MOUNT       0x00010000
13037 +#define VXC_SECURE_REMOUNT     0x00020000
13038 +#define VXC_BINARY_MOUNT       0x00040000
13039 +
13040 +#define VXC_QUOTA_CTL          0x00100000
13041 +#define VXC_ADMIN_MAPPER       0x00200000
13042 +#define VXC_ADMIN_CLOOP                0x00400000
13043 +
13044 +
13045 +#ifdef __KERNEL__
13046 +
13047 +#include <linux/list.h>
13048 +#include <linux/spinlock.h>
13049 +#include <linux/rcupdate.h>
13050 +
13051 +#include "limit_def.h"
13052 +#include "sched_def.h"
13053 +#include "cvirt_def.h"
13054 +#include "cacct_def.h"
13055 +
13056 +struct _vx_info_pc {
13057 +       struct _vx_sched_pc sched_pc;
13058 +       struct _vx_cvirt_pc cvirt_pc;
13059 +};
13060 +
13061 +struct vx_info {
13062 +       struct hlist_node vx_hlist;             /* linked list of contexts */
13063 +       xid_t vx_id;                            /* context id */
13064 +       atomic_t vx_usecnt;                     /* usage count */
13065 +       atomic_t vx_tasks;                      /* tasks count */
13066 +       struct vx_info *vx_parent;              /* parent context */
13067 +       int vx_state;                           /* context state */
13068 +
13069 +       unsigned long vx_nsmask;                /* assignment mask */
13070 +       struct nsproxy *vx_nsproxy;             /* private namespace */
13071 +       struct fs_struct *vx_fs;                /* private namespace fs */
13072 +
13073 +       uint64_t vx_flags;                      /* context flags */
13074 +       uint64_t vx_bcaps;                      /* bounding caps (system) */
13075 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
13076 +       kernel_cap_t vx_cap_bset;               /* the guest's bset */
13077 +
13078 +       struct task_struct *vx_reaper;          /* guest reaper process */
13079 +       pid_t vx_initpid;                       /* PID of guest init */
13080 +
13081 +       struct _vx_limit limit;                 /* vserver limits */
13082 +       struct _vx_sched sched;                 /* vserver scheduler */
13083 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
13084 +       struct _vx_cacct cacct;                 /* context accounting */
13085 +
13086 +#ifndef CONFIG_SMP
13087 +       struct _vx_info_pc info_pc;             /* per cpu data */
13088 +#else
13089 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
13090 +#endif
13091 +
13092 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
13093 +       int reboot_cmd;                         /* last sys_reboot() cmd */
13094 +       int exit_code;                          /* last process exit code */
13095 +
13096 +       char vx_name[65];                       /* vserver name */
13097 +};
13098 +
13099 +#ifndef CONFIG_SMP
13100 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
13101 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
13102 +#else
13103 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
13104 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
13105 +#endif
13106 +
13107 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
13108 +
13109 +
13110 +struct vx_info_save {
13111 +       struct vx_info *vxi;
13112 +       xid_t xid;
13113 +};
13114 +
13115 +
13116 +/* status flags */
13117 +
13118 +#define VXS_HASHED     0x0001
13119 +#define VXS_PAUSED     0x0010
13120 +#define VXS_SHUTDOWN   0x0100
13121 +#define VXS_HELPER     0x1000
13122 +#define VXS_RELEASED   0x8000
13123 +
13124 +
13125 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
13126 +extern void release_vx_info(struct vx_info *, struct task_struct *);
13127 +
13128 +extern struct vx_info *lookup_vx_info(int);
13129 +extern struct vx_info *lookup_or_create_vx_info(int);
13130 +
13131 +extern int get_xid_list(int, unsigned int *, int);
13132 +extern int xid_is_hashed(xid_t);
13133 +
13134 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
13135 +
13136 +extern long vs_state_change(struct vx_info *, unsigned int);
13137 +
13138 +
13139 +#endif /* __KERNEL__ */
13140 +#endif /* _VX_CONTEXT_H */
13141 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/context_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/context_cmd.h
13142 --- linux-2.6.22.10/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00 +0100
13143 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/context_cmd.h       2007-06-15 02:37:04 +0200
13144 @@ -0,0 +1,123 @@
13145 +#ifndef _VX_CONTEXT_CMD_H
13146 +#define _VX_CONTEXT_CMD_H
13147 +
13148 +
13149 +/* vinfo commands */
13150 +
13151 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
13152 +
13153 +#ifdef __KERNEL__
13154 +extern int vc_task_xid(uint32_t, void __user *);
13155 +
13156 +#endif /* __KERNEL__ */
13157 +
13158 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
13159 +
13160 +struct vcmd_vx_info_v0 {
13161 +       uint32_t xid;
13162 +       uint32_t initpid;
13163 +       /* more to come */
13164 +};
13165 +
13166 +#ifdef __KERNEL__
13167 +extern int vc_vx_info(struct vx_info *, void __user *);
13168 +
13169 +#endif /* __KERNEL__ */
13170 +
13171 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
13172 +
13173 +struct vcmd_ctx_stat_v0 {
13174 +       uint32_t usecnt;
13175 +       uint32_t tasks;
13176 +       /* more to come */
13177 +};
13178 +
13179 +#ifdef __KERNEL__
13180 +extern int vc_ctx_stat(struct vx_info *, void __user *);
13181 +
13182 +#endif /* __KERNEL__ */
13183 +
13184 +/* context commands */
13185 +
13186 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
13187 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
13188 +
13189 +struct vcmd_ctx_create {
13190 +       uint64_t flagword;
13191 +};
13192 +
13193 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
13194 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
13195 +
13196 +struct vcmd_ctx_migrate {
13197 +       uint64_t flagword;
13198 +};
13199 +
13200 +#ifdef __KERNEL__
13201 +extern int vc_ctx_create(uint32_t, void __user *);
13202 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
13203 +
13204 +#endif /* __KERNEL__ */
13205 +
13206 +
13207 +/* flag commands */
13208 +
13209 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
13210 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
13211 +
13212 +struct vcmd_ctx_flags_v0 {
13213 +       uint64_t flagword;
13214 +       uint64_t mask;
13215 +};
13216 +
13217 +#ifdef __KERNEL__
13218 +extern int vc_get_cflags(struct vx_info *, void __user *);
13219 +extern int vc_set_cflags(struct vx_info *, void __user *);
13220 +
13221 +#endif /* __KERNEL__ */
13222 +
13223 +
13224 +/* context caps commands */
13225 +
13226 +#define VCMD_get_ccaps_v0      VC_CMD(FLAGS, 3, 0)
13227 +#define VCMD_set_ccaps_v0      VC_CMD(FLAGS, 4, 0)
13228 +
13229 +struct vcmd_ctx_caps_v0 {
13230 +       uint64_t bcaps;
13231 +       uint64_t ccaps;
13232 +       uint64_t cmask;
13233 +};
13234 +
13235 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
13236 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
13237 +
13238 +struct vcmd_ctx_caps_v1 {
13239 +       uint64_t ccaps;
13240 +       uint64_t cmask;
13241 +};
13242 +
13243 +#ifdef __KERNEL__
13244 +extern int vc_get_ccaps_v0(struct vx_info *, void __user *);
13245 +extern int vc_set_ccaps_v0(struct vx_info *, void __user *);
13246 +extern int vc_get_ccaps(struct vx_info *, void __user *);
13247 +extern int vc_set_ccaps(struct vx_info *, void __user *);
13248 +
13249 +#endif /* __KERNEL__ */
13250 +
13251 +
13252 +/* bcaps commands */
13253 +
13254 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
13255 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
13256 +
13257 +struct vcmd_bcaps {
13258 +       uint64_t bcaps;
13259 +       uint64_t bmask;
13260 +};
13261 +
13262 +#ifdef __KERNEL__
13263 +extern int vc_get_bcaps(struct vx_info *, void __user *);
13264 +extern int vc_set_bcaps(struct vx_info *, void __user *);
13265 +
13266 +#endif /* __KERNEL__ */
13267 +#endif /* _VX_CONTEXT_CMD_H */
13268 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cvirt.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cvirt.h
13269 --- linux-2.6.22.10/include/linux/vserver/cvirt.h       1970-01-01 01:00:00 +0100
13270 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cvirt.h     2007-06-15 02:37:04 +0200
13271 @@ -0,0 +1,20 @@
13272 +#ifndef _VX_CVIRT_H
13273 +#define _VX_CVIRT_H
13274 +
13275 +
13276 +#ifdef __KERNEL__
13277 +
13278 +struct timespec;
13279 +
13280 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13281 +
13282 +
13283 +struct vx_info;
13284 +
13285 +void vx_update_load(struct vx_info *);
13286 +
13287 +
13288 +int vx_do_syslog(int, char __user *, int);
13289 +
13290 +#endif /* __KERNEL__ */
13291 +#endif /* _VX_CVIRT_H */
13292 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cvirt_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cvirt_cmd.h
13293 --- linux-2.6.22.10/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00 +0100
13294 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cvirt_cmd.h 2007-06-15 02:37:04 +0200
13295 @@ -0,0 +1,53 @@
13296 +#ifndef _VX_CVIRT_CMD_H
13297 +#define _VX_CVIRT_CMD_H
13298 +
13299 +
13300 +/* virtual host info name commands */
13301 +
13302 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
13303 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
13304 +
13305 +struct vcmd_vhi_name_v0 {
13306 +       uint32_t field;
13307 +       char name[65];
13308 +};
13309 +
13310 +
13311 +enum vhi_name_field {
13312 +       VHIN_CONTEXT = 0,
13313 +       VHIN_SYSNAME,
13314 +       VHIN_NODENAME,
13315 +       VHIN_RELEASE,
13316 +       VHIN_VERSION,
13317 +       VHIN_MACHINE,
13318 +       VHIN_DOMAINNAME,
13319 +};
13320 +
13321 +
13322 +#ifdef __KERNEL__
13323 +
13324 +#include <linux/compiler.h>
13325 +
13326 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
13327 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
13328 +
13329 +#endif /* __KERNEL__ */
13330 +
13331 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
13332 +
13333 +struct vcmd_virt_stat_v0 {
13334 +       uint64_t offset;
13335 +       uint64_t uptime;
13336 +       uint32_t nr_threads;
13337 +       uint32_t nr_running;
13338 +       uint32_t nr_uninterruptible;
13339 +       uint32_t nr_onhold;
13340 +       uint32_t nr_forks;
13341 +       uint32_t load[3];
13342 +};
13343 +
13344 +#ifdef __KERNEL__
13345 +extern int vc_virt_stat(struct vx_info *, void __user *);
13346 +
13347 +#endif /* __KERNEL__ */
13348 +#endif /* _VX_CVIRT_CMD_H */
13349 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/cvirt_def.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cvirt_def.h
13350 --- linux-2.6.22.10/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00 +0100
13351 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/cvirt_def.h 2007-06-15 02:37:04 +0200
13352 @@ -0,0 +1,81 @@
13353 +#ifndef _VX_CVIRT_DEF_H
13354 +#define _VX_CVIRT_DEF_H
13355 +
13356 +#include <linux/jiffies.h>
13357 +#include <linux/spinlock.h>
13358 +#include <linux/wait.h>
13359 +#include <linux/time.h>
13360 +#include <linux/utsname.h>
13361 +#include <asm/atomic.h>
13362 +
13363 +
13364 +struct _vx_usage_stat {
13365 +       uint64_t user;
13366 +       uint64_t nice;
13367 +       uint64_t system;
13368 +       uint64_t softirq;
13369 +       uint64_t irq;
13370 +       uint64_t idle;
13371 +       uint64_t iowait;
13372 +};
13373 +
13374 +struct _vx_syslog {
13375 +       wait_queue_head_t log_wait;
13376 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
13377 +
13378 +       unsigned long log_start;        /* next char to be read by syslog() */
13379 +       unsigned long con_start;        /* next char to be sent to consoles */
13380 +       unsigned long log_end;  /* most-recently-written-char + 1 */
13381 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
13382 +
13383 +       char log_buf[1024];
13384 +};
13385 +
13386 +
13387 +/* context sub struct */
13388 +
13389 +struct _vx_cvirt {
13390 +       atomic_t nr_threads;            /* number of current threads */
13391 +       atomic_t nr_running;            /* number of running threads */
13392 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
13393 +
13394 +       atomic_t nr_onhold;             /* processes on hold */
13395 +       uint32_t onhold_last;           /* jiffies when put on hold */
13396 +
13397 +       struct timeval bias_tv;         /* time offset to the host */
13398 +       struct timespec bias_idle;
13399 +       struct timespec bias_uptime;    /* context creation point */
13400 +       uint64_t bias_clock;            /* offset in clock_t */
13401 +
13402 +       spinlock_t load_lock;           /* lock for the load averages */
13403 +       atomic_t load_updates;          /* nr of load updates done so far */
13404 +       uint32_t load_last;             /* last time load was calculated */
13405 +       uint32_t load[3];               /* load averages 1,5,15 */
13406 +
13407 +       atomic_t total_forks;           /* number of forks so far */
13408 +
13409 +       struct _vx_syslog syslog;
13410 +};
13411 +
13412 +struct _vx_cvirt_pc {
13413 +       struct _vx_usage_stat cpustat;
13414 +};
13415 +
13416 +
13417 +#ifdef CONFIG_VSERVER_DEBUG
13418 +
13419 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
13420 +{
13421 +       printk("\t_vx_cvirt:\n");
13422 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
13423 +               atomic_read(&cvirt->nr_threads),
13424 +               atomic_read(&cvirt->nr_running),
13425 +               atomic_read(&cvirt->nr_uninterruptible),
13426 +               atomic_read(&cvirt->nr_onhold));
13427 +       /* add rest here */
13428 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
13429 +}
13430 +
13431 +#endif
13432 +
13433 +#endif /* _VX_CVIRT_DEF_H */
13434 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/debug.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/debug.h
13435 --- linux-2.6.22.10/include/linux/vserver/debug.h       1970-01-01 01:00:00 +0100
13436 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/debug.h     2007-10-29 23:39:46 +0100
13437 @@ -0,0 +1,124 @@
13438 +#ifndef _VX_DEBUG_H
13439 +#define _VX_DEBUG_H
13440 +
13441 +
13442 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
13443 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
13444 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
13445 +
13446 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
13447 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
13448 +#define VXF_DEV                "%p[%lu,%d:%d]"
13449 +
13450 +
13451 +#define __FUNC__       __func__
13452 +
13453 +
13454 +#define vxd_path(d, m)                                         \
13455 +       ({ static char _buffer[PATH_MAX];                       \
13456 +          d_path(d, m, _buffer, sizeof(_buffer)); })
13457 +
13458 +#define vxd_cond_path(n)                                       \
13459 +       ((n) ? vxd_path((n)->dentry, (n)->mnt) : "<null>" )
13460 +
13461 +
13462 +#ifdef CONFIG_VSERVER_DEBUG
13463 +
13464 +extern unsigned int vx_debug_switch;
13465 +extern unsigned int vx_debug_xid;
13466 +extern unsigned int vx_debug_nid;
13467 +extern unsigned int vx_debug_tag;
13468 +extern unsigned int vx_debug_net;
13469 +extern unsigned int vx_debug_limit;
13470 +extern unsigned int vx_debug_cres;
13471 +extern unsigned int vx_debug_dlim;
13472 +extern unsigned int vx_debug_quota;
13473 +extern unsigned int vx_debug_cvirt;
13474 +extern unsigned int vx_debug_space;
13475 +extern unsigned int vx_debug_misc;
13476 +
13477 +
13478 +#define VX_LOGLEVEL    "vxD: "
13479 +
13480 +#define vxdprintk(c, f, x...)                                  \
13481 +       do {                                                    \
13482 +               if (c)                                          \
13483 +                       printk(VX_LOGLEVEL f "\n" , ##x);       \
13484 +       } while (0)
13485 +
13486 +#define vxlprintk(c, f, x...)                                  \
13487 +       do {                                                    \
13488 +               if (c)                                          \
13489 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
13490 +       } while (0)
13491 +
13492 +#define vxfprintk(c, f, x...)                                  \
13493 +       do {                                                    \
13494 +               if (c)                                          \
13495 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
13496 +       } while (0)
13497 +
13498 +
13499 +struct vx_info;
13500 +
13501 +void dump_vx_info(struct vx_info *, int);
13502 +void dump_vx_info_inactive(int);
13503 +
13504 +#else  /* CONFIG_VSERVER_DEBUG */
13505 +
13506 +#define vx_debug_switch 0
13507 +#define vx_debug_xid   0
13508 +#define vx_debug_nid   0
13509 +#define vx_debug_tag   0
13510 +#define vx_debug_net   0
13511 +#define vx_debug_limit 0
13512 +#define vx_debug_cres  0
13513 +#define vx_debug_dlim  0
13514 +#define vx_debug_cvirt 0
13515 +
13516 +#define vxdprintk(x...) do { } while (0)
13517 +#define vxlprintk(x...) do { } while (0)
13518 +#define vxfprintk(x...) do { } while (0)
13519 +
13520 +#endif /* CONFIG_VSERVER_DEBUG */
13521 +
13522 +
13523 +#ifdef CONFIG_VSERVER_WARN
13524 +
13525 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
13526 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u] "
13527 +#define VX_WARN_XID    "[xid #%u] "
13528 +#define VX_WARN_NID    "[nid #%u] "
13529 +
13530 +#define vxwprintk(c, f, x...)                                  \
13531 +       do {                                                    \
13532 +               if (c)                                          \
13533 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
13534 +       } while (0)
13535 +
13536 +#else  /* CONFIG_VSERVER_WARN */
13537 +
13538 +#define vxwprintk(x...) do { } while (0)
13539 +
13540 +#endif /* CONFIG_VSERVER_WARN */
13541 +
13542 +#define vxwprintk_task(c, f, x...)                             \
13543 +       vxwprintk(c, VX_WARN_TASK f,                            \
13544 +               current->comm, current->pid,                    \
13545 +               current->xid, current->nid, ##x)
13546 +#define vxwprintk_xid(c, f, x...)                              \
13547 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
13548 +#define vxwprintk_nid(c, f, x...)                              \
13549 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
13550 +
13551 +#ifdef CONFIG_VSERVER_DEBUG
13552 +#define vxd_assert_lock(l)     assert_spin_locked(l)
13553 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
13554 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
13555 +#else
13556 +#define vxd_assert_lock(l)     do { } while (0)
13557 +#define vxd_assert(c, f, x...) do { } while (0)
13558 +#endif
13559 +
13560 +
13561 +#endif /* _VX_DEBUG_H */
13562 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/debug_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/debug_cmd.h
13563 --- linux-2.6.22.10/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00 +0100
13564 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/debug_cmd.h 2007-06-15 02:37:04 +0200
13565 @@ -0,0 +1,58 @@
13566 +#ifndef _VX_DEBUG_CMD_H
13567 +#define _VX_DEBUG_CMD_H
13568 +
13569 +
13570 +/* debug commands */
13571 +
13572 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
13573 +
13574 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
13575 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
13576 +
13577 +struct  vcmd_read_history_v0 {
13578 +       uint32_t index;
13579 +       uint32_t count;
13580 +       char __user *data;
13581 +};
13582 +
13583 +struct  vcmd_read_monitor_v0 {
13584 +       uint32_t index;
13585 +       uint32_t count;
13586 +       char __user *data;
13587 +};
13588 +
13589 +
13590 +#ifdef __KERNEL__
13591 +
13592 +#ifdef CONFIG_COMPAT
13593 +
13594 +#include <asm/compat.h>
13595 +
13596 +struct vcmd_read_history_v0_x32 {
13597 +       uint32_t index;
13598 +       uint32_t count;
13599 +       compat_uptr_t data_ptr;
13600 +};
13601 +
13602 +struct vcmd_read_monitor_v0_x32 {
13603 +       uint32_t index;
13604 +       uint32_t count;
13605 +       compat_uptr_t data_ptr;
13606 +};
13607 +
13608 +#endif  /* CONFIG_COMPAT */
13609 +
13610 +extern int vc_dump_history(uint32_t);
13611 +
13612 +extern int vc_read_history(uint32_t, void __user *);
13613 +extern int vc_read_monitor(uint32_t, void __user *);
13614 +
13615 +#ifdef CONFIG_COMPAT
13616 +
13617 +extern int vc_read_history_x32(uint32_t, void __user *);
13618 +extern int vc_read_monitor_x32(uint32_t, void __user *);
13619 +
13620 +#endif  /* CONFIG_COMPAT */
13621 +
13622 +#endif /* __KERNEL__ */
13623 +#endif /* _VX_DEBUG_CMD_H */
13624 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/dlimit.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/dlimit.h
13625 --- linux-2.6.22.10/include/linux/vserver/dlimit.h      1970-01-01 01:00:00 +0100
13626 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/dlimit.h    2007-06-15 02:37:04 +0200
13627 @@ -0,0 +1,53 @@
13628 +#ifndef _VX_DLIMIT_H
13629 +#define _VX_DLIMIT_H
13630 +
13631 +#include "switch.h"
13632 +
13633 +
13634 +#ifdef __KERNEL__
13635 +
13636 +/*      keep in sync with CDLIM_INFINITY       */
13637 +
13638 +#define DLIM_INFINITY          (~0ULL)
13639 +
13640 +#include <linux/spinlock.h>
13641 +
13642 +struct super_block;
13643 +
13644 +struct dl_info {
13645 +       struct hlist_node dl_hlist;             /* linked list of contexts */
13646 +       struct rcu_head dl_rcu;                 /* the rcu head */
13647 +       tag_t dl_tag;                           /* context tag */
13648 +       atomic_t dl_usecnt;                     /* usage count */
13649 +       atomic_t dl_refcnt;                     /* reference count */
13650 +
13651 +       struct super_block *dl_sb;              /* associated superblock */
13652 +
13653 +       spinlock_t dl_lock;                     /* protect the values */
13654 +
13655 +       unsigned long long dl_space_used;       /* used space in bytes */
13656 +       unsigned long long dl_space_total;      /* maximum space in bytes */
13657 +       unsigned long dl_inodes_used;           /* used inodes */
13658 +       unsigned long dl_inodes_total;          /* maximum inodes */
13659 +
13660 +       unsigned int dl_nrlmult;                /* non root limit mult */
13661 +};
13662 +
13663 +struct rcu_head;
13664 +
13665 +extern void rcu_free_dl_info(struct rcu_head *);
13666 +extern void unhash_dl_info(struct dl_info *);
13667 +
13668 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
13669 +
13670 +
13671 +struct kstatfs;
13672 +
13673 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
13674 +
13675 +typedef uint64_t dlsize_t;
13676 +
13677 +#endif /* __KERNEL__ */
13678 +#else  /* _VX_DLIMIT_H */
13679 +#warning duplicate inclusion
13680 +#endif /* _VX_DLIMIT_H */
13681 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/dlimit_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/dlimit_cmd.h
13682 --- linux-2.6.22.10/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00 +0100
13683 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/dlimit_cmd.h        2007-06-15 02:37:04 +0200
13684 @@ -0,0 +1,74 @@
13685 +#ifndef _VX_DLIMIT_CMD_H
13686 +#define _VX_DLIMIT_CMD_H
13687 +
13688 +
13689 +/*  dlimit vserver commands */
13690 +
13691 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13692 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13693 +
13694 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13695 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13696 +
13697 +struct vcmd_ctx_dlimit_base_v0 {
13698 +       const char __user *name;
13699 +       uint32_t flags;
13700 +};
13701 +
13702 +struct vcmd_ctx_dlimit_v0 {
13703 +       const char __user *name;
13704 +       uint32_t space_used;                    /* used space in kbytes */
13705 +       uint32_t space_total;                   /* maximum space in kbytes */
13706 +       uint32_t inodes_used;                   /* used inodes */
13707 +       uint32_t inodes_total;                  /* maximum inodes */
13708 +       uint32_t reserved;                      /* reserved for root in % */
13709 +       uint32_t flags;
13710 +};
13711 +
13712 +#define CDLIM_UNSET            ((uint32_t)0UL)
13713 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13714 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13715 +
13716 +#ifdef __KERNEL__
13717 +
13718 +#ifdef CONFIG_COMPAT
13719 +
13720 +#include <asm/compat.h>
13721 +
13722 +struct vcmd_ctx_dlimit_base_v0_x32 {
13723 +       compat_uptr_t name_ptr;
13724 +       uint32_t flags;
13725 +};
13726 +
13727 +struct vcmd_ctx_dlimit_v0_x32 {
13728 +       compat_uptr_t name_ptr;
13729 +       uint32_t space_used;                    /* used space in kbytes */
13730 +       uint32_t space_total;                   /* maximum space in kbytes */
13731 +       uint32_t inodes_used;                   /* used inodes */
13732 +       uint32_t inodes_total;                  /* maximum inodes */
13733 +       uint32_t reserved;                      /* reserved for root in % */
13734 +       uint32_t flags;
13735 +};
13736 +
13737 +#endif /* CONFIG_COMPAT */
13738 +
13739 +#include <linux/compiler.h>
13740 +
13741 +extern int vc_add_dlimit(uint32_t, void __user *);
13742 +extern int vc_rem_dlimit(uint32_t, void __user *);
13743 +
13744 +extern int vc_set_dlimit(uint32_t, void __user *);
13745 +extern int vc_get_dlimit(uint32_t, void __user *);
13746 +
13747 +#ifdef CONFIG_COMPAT
13748 +
13749 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
13750 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
13751 +
13752 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
13753 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
13754 +
13755 +#endif /* CONFIG_COMPAT */
13756 +
13757 +#endif /* __KERNEL__ */
13758 +#endif /* _VX_DLIMIT_CMD_H */
13759 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/global.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/global.h
13760 --- linux-2.6.22.10/include/linux/vserver/global.h      1970-01-01 01:00:00 +0100
13761 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/global.h    2007-06-15 02:37:04 +0200
13762 @@ -0,0 +1,18 @@
13763 +#ifndef _VX_GLOBAL_H
13764 +#define _VX_GLOBAL_H
13765 +
13766 +
13767 +extern atomic_t vx_global_ctotal;
13768 +extern atomic_t vx_global_cactive;
13769 +
13770 +extern atomic_t nx_global_ctotal;
13771 +extern atomic_t nx_global_cactive;
13772 +
13773 +extern atomic_t vs_global_nsproxy;
13774 +extern atomic_t vs_global_fs;
13775 +extern atomic_t vs_global_mnt_ns;
13776 +extern atomic_t vs_global_uts_ns;
13777 +extern atomic_t vs_global_ipc_ns;
13778 +
13779 +
13780 +#endif /* _VX_GLOBAL_H */
13781 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/history.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/history.h
13782 --- linux-2.6.22.10/include/linux/vserver/history.h     1970-01-01 01:00:00 +0100
13783 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/history.h   2007-06-15 02:37:04 +0200
13784 @@ -0,0 +1,197 @@
13785 +#ifndef _VX_HISTORY_H
13786 +#define _VX_HISTORY_H
13787 +
13788 +
13789 +enum {
13790 +       VXH_UNUSED = 0,
13791 +       VXH_THROW_OOPS = 1,
13792 +
13793 +       VXH_GET_VX_INFO,
13794 +       VXH_PUT_VX_INFO,
13795 +       VXH_INIT_VX_INFO,
13796 +       VXH_SET_VX_INFO,
13797 +       VXH_CLR_VX_INFO,
13798 +       VXH_CLAIM_VX_INFO,
13799 +       VXH_RELEASE_VX_INFO,
13800 +       VXH_ALLOC_VX_INFO,
13801 +       VXH_DEALLOC_VX_INFO,
13802 +       VXH_HASH_VX_INFO,
13803 +       VXH_UNHASH_VX_INFO,
13804 +       VXH_LOC_VX_INFO,
13805 +       VXH_LOOKUP_VX_INFO,
13806 +       VXH_CREATE_VX_INFO,
13807 +};
13808 +
13809 +struct _vxhe_vxi {
13810 +       struct vx_info *ptr;
13811 +       unsigned xid;
13812 +       unsigned usecnt;
13813 +       unsigned tasks;
13814 +};
13815 +
13816 +struct _vxhe_set_clr {
13817 +       void *data;
13818 +};
13819 +
13820 +struct _vxhe_loc_lookup {
13821 +       unsigned arg;
13822 +};
13823 +
13824 +struct _vx_hist_entry {
13825 +       void *loc;
13826 +       unsigned short seq;
13827 +       unsigned short type;
13828 +       struct _vxhe_vxi vxi;
13829 +       union {
13830 +               struct _vxhe_set_clr sc;
13831 +               struct _vxhe_loc_lookup ll;
13832 +       };
13833 +};
13834 +
13835 +#ifdef CONFIG_VSERVER_HISTORY
13836 +
13837 +extern unsigned volatile int vxh_active;
13838 +
13839 +struct _vx_hist_entry *vxh_advance(void *loc);
13840 +
13841 +
13842 +static inline
13843 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
13844 +{
13845 +       entry->vxi.ptr = vxi;
13846 +       if (vxi) {
13847 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
13848 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
13849 +               entry->vxi.xid = vxi->vx_id;
13850 +       }
13851 +}
13852 +
13853 +
13854 +#define        __HERE__ current_text_addr()
13855 +
13856 +#define __VXH_BODY(__type, __data, __here)     \
13857 +       struct _vx_hist_entry *entry;           \
13858 +                                               \
13859 +       preempt_disable();                      \
13860 +       entry = vxh_advance(__here);            \
13861 +       __data;                                 \
13862 +       entry->type = __type;                   \
13863 +       preempt_enable();
13864 +
13865 +
13866 +       /* pass vxi only */
13867 +
13868 +#define __VXH_SMPL                             \
13869 +       __vxh_copy_vxi(entry, vxi)
13870 +
13871 +static inline
13872 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
13873 +{
13874 +       __VXH_BODY(__type, __VXH_SMPL, __here)
13875 +}
13876 +
13877 +       /* pass vxi and data (void *) */
13878 +
13879 +#define __VXH_DATA                             \
13880 +       __vxh_copy_vxi(entry, vxi);             \
13881 +       entry->sc.data = data
13882 +
13883 +static inline
13884 +void   __vxh_data(struct vx_info *vxi, void *data,
13885 +                       int __type, void *__here)
13886 +{
13887 +       __VXH_BODY(__type, __VXH_DATA, __here)
13888 +}
13889 +
13890 +       /* pass vxi and arg (long) */
13891 +
13892 +#define __VXH_LONG                             \
13893 +       __vxh_copy_vxi(entry, vxi);             \
13894 +       entry->ll.arg = arg
13895 +
13896 +static inline
13897 +void   __vxh_long(struct vx_info *vxi, long arg,
13898 +                       int __type, void *__here)
13899 +{
13900 +       __VXH_BODY(__type, __VXH_LONG, __here)
13901 +}
13902 +
13903 +
13904 +static inline
13905 +void   __vxh_throw_oops(void *__here)
13906 +{
13907 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
13908 +       /* prevent further acquisition */
13909 +       vxh_active = 0;
13910 +}
13911 +
13912 +
13913 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
13914 +
13915 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
13916 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
13917 +
13918 +#define __vxh_init_vx_info(v, d, h) \
13919 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
13920 +#define __vxh_set_vx_info(v, d, h) \
13921 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
13922 +#define __vxh_clr_vx_info(v, d, h) \
13923 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
13924 +
13925 +#define __vxh_claim_vx_info(v, d, h) \
13926 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
13927 +#define __vxh_release_vx_info(v, d, h) \
13928 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
13929 +
13930 +#define vxh_alloc_vx_info(v) \
13931 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
13932 +#define vxh_dealloc_vx_info(v) \
13933 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
13934 +
13935 +#define vxh_hash_vx_info(v) \
13936 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
13937 +#define vxh_unhash_vx_info(v) \
13938 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
13939 +
13940 +#define vxh_loc_vx_info(v, l) \
13941 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
13942 +#define vxh_lookup_vx_info(v, l) \
13943 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
13944 +#define vxh_create_vx_info(v, l) \
13945 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
13946 +
13947 +extern void vxh_dump_history(void);
13948 +
13949 +
13950 +#else  /* CONFIG_VSERVER_HISTORY */
13951 +
13952 +#define        __HERE__        0
13953 +
13954 +#define vxh_throw_oops()               do { } while (0)
13955 +
13956 +#define __vxh_get_vx_info(v, h)                do { } while (0)
13957 +#define __vxh_put_vx_info(v, h)                do { } while (0)
13958 +
13959 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
13960 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
13961 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
13962 +
13963 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
13964 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
13965 +
13966 +#define vxh_alloc_vx_info(v)           do { } while (0)
13967 +#define vxh_dealloc_vx_info(v)         do { } while (0)
13968 +
13969 +#define vxh_hash_vx_info(v)            do { } while (0)
13970 +#define vxh_unhash_vx_info(v)          do { } while (0)
13971 +
13972 +#define vxh_loc_vx_info(v, l)          do { } while (0)
13973 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
13974 +#define vxh_create_vx_info(v, l)       do { } while (0)
13975 +
13976 +#define vxh_dump_history()             do { } while (0)
13977 +
13978 +
13979 +#endif /* CONFIG_VSERVER_HISTORY */
13980 +
13981 +#endif /* _VX_HISTORY_H */
13982 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/inode.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/inode.h
13983 --- linux-2.6.22.10/include/linux/vserver/inode.h       1970-01-01 01:00:00 +0100
13984 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/inode.h     2007-06-15 02:37:04 +0200
13985 @@ -0,0 +1,38 @@
13986 +#ifndef _VX_INODE_H
13987 +#define _VX_INODE_H
13988 +
13989 +
13990 +#define IATTR_TAG      0x01000000
13991 +
13992 +#define IATTR_ADMIN    0x00000001
13993 +#define IATTR_WATCH    0x00000002
13994 +#define IATTR_HIDE     0x00000004
13995 +#define IATTR_FLAGS    0x00000007
13996 +
13997 +#define IATTR_BARRIER  0x00010000
13998 +#define IATTR_IUNLINK  0x00020000
13999 +#define IATTR_IMMUTABLE 0x00040000
14000 +
14001 +#ifdef __KERNEL__
14002 +
14003 +
14004 +#ifdef CONFIG_VSERVER_PROC_SECURE
14005 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
14006 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14007 +#else
14008 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
14009 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
14010 +#endif
14011 +
14012 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
14013 +
14014 +#endif /* __KERNEL__ */
14015 +
14016 +/* inode ioctls */
14017 +
14018 +#define FIOC_GETXFLG   _IOR('x', 5, long)
14019 +#define FIOC_SETXFLG   _IOW('x', 6, long)
14020 +
14021 +#else  /* _VX_INODE_H */
14022 +#warning duplicate inclusion
14023 +#endif /* _VX_INODE_H */
14024 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/inode_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/inode_cmd.h
14025 --- linux-2.6.22.10/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00 +0100
14026 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/inode_cmd.h 2007-07-16 06:38:22 +0200
14027 @@ -0,0 +1,59 @@
14028 +#ifndef _VX_INODE_CMD_H
14029 +#define _VX_INODE_CMD_H
14030 +
14031 +
14032 +/*  inode vserver commands */
14033 +
14034 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
14035 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
14036 +
14037 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
14038 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
14039 +
14040 +struct vcmd_ctx_iattr_v1 {
14041 +       const char __user *name;
14042 +       uint32_t xid;
14043 +       uint32_t flags;
14044 +       uint32_t mask;
14045 +};
14046 +
14047 +struct vcmd_ctx_fiattr_v0 {
14048 +       uint32_t xid;
14049 +       uint32_t flags;
14050 +       uint32_t mask;
14051 +};
14052 +
14053 +
14054 +#ifdef __KERNEL__
14055 +
14056 +
14057 +#ifdef CONFIG_COMPAT
14058 +
14059 +#include <asm/compat.h>
14060 +
14061 +struct vcmd_ctx_iattr_v1_x32 {
14062 +       compat_uptr_t name_ptr;
14063 +       uint32_t xid;
14064 +       uint32_t flags;
14065 +       uint32_t mask;
14066 +};
14067 +
14068 +#endif /* CONFIG_COMPAT */
14069 +
14070 +#include <linux/compiler.h>
14071 +
14072 +extern int vc_get_iattr(void __user *);
14073 +extern int vc_set_iattr(void __user *);
14074 +
14075 +extern int vc_fget_iattr(uint32_t, void __user *);
14076 +extern int vc_fset_iattr(uint32_t, void __user *);
14077 +
14078 +#ifdef CONFIG_COMPAT
14079 +
14080 +extern int vc_get_iattr_x32(void __user *);
14081 +extern int vc_set_iattr_x32(void __user *);
14082 +
14083 +#endif /* CONFIG_COMPAT */
14084 +
14085 +#endif /* __KERNEL__ */
14086 +#endif /* _VX_INODE_CMD_H */
14087 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/legacy.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/legacy.h
14088 --- linux-2.6.22.10/include/linux/vserver/legacy.h      1970-01-01 01:00:00 +0100
14089 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/legacy.h    2007-06-15 02:37:04 +0200
14090 @@ -0,0 +1,49 @@
14091 +#ifndef _VX_LEGACY_H
14092 +#define _VX_LEGACY_H
14093 +
14094 +#include "switch.h"
14095 +
14096 +
14097 +/*  compatibiliy vserver commands */
14098 +
14099 +#define VCMD_new_s_context     VC_CMD(COMPAT, 1, 1)
14100 +#define VCMD_set_ipv4root      VC_CMD(COMPAT, 2, 3)
14101 +
14102 +#define VCMD_create_context    VC_CMD(VSETUP, 1, 0)
14103 +
14104 +/*  compatibiliy vserver arguments */
14105 +
14106 +struct vcmd_new_s_context_v1 {
14107 +       uint32_t remove_cap;
14108 +       uint32_t flags;
14109 +};
14110 +
14111 +struct vcmd_set_ipv4root_v3 {
14112 +       /* number of pairs in id */
14113 +       uint32_t broadcast;
14114 +       struct {
14115 +               uint32_t ip;
14116 +               uint32_t mask;
14117 +       } nx_mask_pair[NB_IPV4ROOT];
14118 +};
14119 +
14120 +
14121 +#define VX_INFO_LOCK           1       /* Can't request a new vx_id */
14122 +#define VX_INFO_NPROC          4       /* Limit number of processes in a context */
14123 +#define VX_INFO_PRIVATE                8       /* Noone can join this security context */
14124 +#define VX_INFO_INIT           16      /* This process wants to become the */
14125 +                                       /* logical process 1 of the security */
14126 +                                       /* context */
14127 +#define VX_INFO_HIDEINFO       32      /* Hide some information in /proc */
14128 +#define VX_INFO_ULIMIT         64      /* Use ulimit of the current process */
14129 +                                       /* to become the global limits */
14130 +                                       /* of the context */
14131 +#define VX_INFO_NAMESPACE      128     /* save private namespace */
14132 +
14133 +
14134 +#ifdef __KERNEL__
14135 +extern int vc_new_s_context(uint32_t, void __user *);
14136 +extern int vc_set_ipv4root(uint32_t, void __user *);
14137 +
14138 +#endif /* __KERNEL__ */
14139 +#endif /* _VX_LEGACY_H */
14140 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/limit.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/limit.h
14141 --- linux-2.6.22.10/include/linux/vserver/limit.h       1970-01-01 01:00:00 +0100
14142 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/limit.h     2007-06-15 02:37:04 +0200
14143 @@ -0,0 +1,68 @@
14144 +#ifndef _VX_LIMIT_H
14145 +#define _VX_LIMIT_H
14146 +
14147 +
14148 +#define VLIMIT_NSOCK   16
14149 +#define VLIMIT_OPENFD  17
14150 +#define VLIMIT_ANON    18
14151 +#define VLIMIT_SHMEM   19
14152 +#define VLIMIT_SEMARY  20
14153 +#define VLIMIT_NSEMS   21
14154 +#define VLIMIT_DENTRY  22
14155 +#define VLIMIT_MAPPED  23
14156 +
14157 +
14158 +#ifdef __KERNEL__
14159 +
14160 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
14161 +
14162 +/*     keep in sync with CRLIM_INFINITY */
14163 +
14164 +#define        VLIM_INFINITY   (~0ULL)
14165 +
14166 +#ifndef RLIM_INFINITY
14167 +#warning RLIM_INFINITY is undefined
14168 +#endif
14169 +
14170 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
14171 +
14172 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
14173 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
14174 +
14175 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
14176 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
14177 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
14178 +
14179 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
14180 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
14181 +
14182 +typedef atomic_long_t rlim_atomic_t;
14183 +typedef unsigned long rlim_t;
14184 +
14185 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
14186 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
14187 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
14188 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
14189 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
14190 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
14191 +
14192 +
14193 +#if    (RLIM_INFINITY == VLIM_INFINITY)
14194 +#define        VX_VLIM(r) ((long long)(long)(r))
14195 +#define        VX_RLIM(v) ((rlim_t)(v))
14196 +#else
14197 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
14198 +               ? VLIM_INFINITY : (long long)(r))
14199 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
14200 +               ? RLIM_INFINITY : (rlim_t)(v))
14201 +#endif
14202 +
14203 +struct sysinfo;
14204 +
14205 +void vx_vsi_meminfo(struct sysinfo *);
14206 +void vx_vsi_swapinfo(struct sysinfo *);
14207 +
14208 +#define NUM_LIMITS     24
14209 +
14210 +#endif /* __KERNEL__ */
14211 +#endif /* _VX_LIMIT_H */
14212 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/limit_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/limit_cmd.h
14213 --- linux-2.6.22.10/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00 +0100
14214 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/limit_cmd.h 2007-06-15 02:37:04 +0200
14215 @@ -0,0 +1,69 @@
14216 +#ifndef _VX_LIMIT_CMD_H
14217 +#define _VX_LIMIT_CMD_H
14218 +
14219 +
14220 +/*  rlimit vserver commands */
14221 +
14222 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
14223 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
14224 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
14225 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
14226 +
14227 +struct vcmd_ctx_rlimit_v0 {
14228 +       uint32_t id;
14229 +       uint64_t minimum;
14230 +       uint64_t softlimit;
14231 +       uint64_t maximum;
14232 +};
14233 +
14234 +struct vcmd_ctx_rlimit_mask_v0 {
14235 +       uint32_t minimum;
14236 +       uint32_t softlimit;
14237 +       uint32_t maximum;
14238 +};
14239 +
14240 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
14241 +
14242 +struct vcmd_rlimit_stat_v0 {
14243 +       uint32_t id;
14244 +       uint32_t hits;
14245 +       uint64_t value;
14246 +       uint64_t minimum;
14247 +       uint64_t maximum;
14248 +};
14249 +
14250 +#define CRLIM_UNSET            (0ULL)
14251 +#define CRLIM_INFINITY         (~0ULL)
14252 +#define CRLIM_KEEP             (~1ULL)
14253 +
14254 +#ifdef __KERNEL__
14255 +
14256 +#ifdef CONFIG_IA32_EMULATION
14257 +
14258 +struct vcmd_ctx_rlimit_v0_x32 {
14259 +       uint32_t id;
14260 +       uint64_t minimum;
14261 +       uint64_t softlimit;
14262 +       uint64_t maximum;
14263 +} __attribute__ ((aligned (4)));
14264 +
14265 +#endif /* CONFIG_IA32_EMULATION */
14266 +
14267 +#include <linux/compiler.h>
14268 +
14269 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
14270 +extern int vc_get_rlimit(struct vx_info *, void __user *);
14271 +extern int vc_set_rlimit(struct vx_info *, void __user *);
14272 +extern int vc_reset_minmax(struct vx_info *, void __user *);
14273 +
14274 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
14275 +
14276 +#ifdef CONFIG_IA32_EMULATION
14277 +
14278 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
14279 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
14280 +
14281 +#endif /* CONFIG_IA32_EMULATION */
14282 +
14283 +#endif /* __KERNEL__ */
14284 +#endif /* _VX_LIMIT_CMD_H */
14285 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/limit_def.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/limit_def.h
14286 --- linux-2.6.22.10/include/linux/vserver/limit_def.h   1970-01-01 01:00:00 +0100
14287 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/limit_def.h 2007-06-15 02:37:04 +0200
14288 @@ -0,0 +1,47 @@
14289 +#ifndef _VX_LIMIT_DEF_H
14290 +#define _VX_LIMIT_DEF_H
14291 +
14292 +#include <asm/atomic.h>
14293 +#include <asm/resource.h>
14294 +
14295 +#include "limit.h"
14296 +
14297 +
14298 +struct _vx_res_limit {
14299 +       rlim_t soft;            /* Context soft limit */
14300 +       rlim_t hard;            /* Context hard limit */
14301 +
14302 +       rlim_atomic_t rcur;     /* Current value */
14303 +       rlim_t rmin;            /* Context minimum */
14304 +       rlim_t rmax;            /* Context maximum */
14305 +
14306 +       atomic_t lhit;          /* Limit hits */
14307 +};
14308 +
14309 +/* context sub struct */
14310 +
14311 +struct _vx_limit {
14312 +       struct _vx_res_limit res[NUM_LIMITS];
14313 +};
14314 +
14315 +#ifdef CONFIG_VSERVER_DEBUG
14316 +
14317 +static inline void __dump_vx_limit(struct _vx_limit *limit)
14318 +{
14319 +       int i;
14320 +
14321 +       printk("\t_vx_limit:");
14322 +       for (i = 0; i < NUM_LIMITS; i++) {
14323 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
14324 +                       i, (unsigned long)__rlim_get(limit, i),
14325 +                       (unsigned long)__rlim_rmin(limit, i),
14326 +                       (unsigned long)__rlim_rmax(limit, i),
14327 +                       (long)__rlim_soft(limit, i),
14328 +                       (long)__rlim_hard(limit, i),
14329 +                       atomic_read(&__rlim_lhit(limit, i)));
14330 +       }
14331 +}
14332 +
14333 +#endif
14334 +
14335 +#endif /* _VX_LIMIT_DEF_H */
14336 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/limit_int.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/limit_int.h
14337 --- linux-2.6.22.10/include/linux/vserver/limit_int.h   1970-01-01 01:00:00 +0100
14338 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/limit_int.h 2007-06-15 02:37:04 +0200
14339 @@ -0,0 +1,198 @@
14340 +#ifndef _VX_LIMIT_INT_H
14341 +#define _VX_LIMIT_INT_H
14342 +
14343 +#include "context.h"
14344 +
14345 +#ifdef __KERNEL__
14346 +
14347 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
14348 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
14349 +
14350 +extern const char *vlimit_name[NUM_LIMITS];
14351 +
14352 +static inline void __vx_acc_cres(struct vx_info *vxi,
14353 +       int res, int dir, void *_data, char *_file, int _line)
14354 +{
14355 +       if (VXD_RCRES_COND(res))
14356 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
14357 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14358 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14359 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
14360 +       if (!vxi)
14361 +               return;
14362 +
14363 +       if (dir > 0)
14364 +               __rlim_inc(&vxi->limit, res);
14365 +       else
14366 +               __rlim_dec(&vxi->limit, res);
14367 +}
14368 +
14369 +static inline void __vx_add_cres(struct vx_info *vxi,
14370 +       int res, int amount, void *_data, char *_file, int _line)
14371 +{
14372 +       if (VXD_RCRES_COND(res))
14373 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
14374 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14375 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14376 +                       amount, _data, _file, _line);
14377 +       if (amount == 0)
14378 +               return;
14379 +       if (!vxi)
14380 +               return;
14381 +       __rlim_add(&vxi->limit, res, amount);
14382 +}
14383 +
14384 +static inline
14385 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
14386 +{
14387 +       int cond = (value > __rlim_rmax(limit, res));
14388 +
14389 +       if (cond)
14390 +               __rlim_rmax(limit, res) = value;
14391 +       return cond;
14392 +}
14393 +
14394 +static inline
14395 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
14396 +{
14397 +       int cond = (value < __rlim_rmin(limit, res));
14398 +
14399 +       if (cond)
14400 +               __rlim_rmin(limit, res) = value;
14401 +       return cond;
14402 +}
14403 +
14404 +static inline
14405 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
14406 +{
14407 +       if (!__vx_cres_adjust_max(limit, res, value))
14408 +               __vx_cres_adjust_min(limit, res, value);
14409 +}
14410 +
14411 +
14412 +/*     return values:
14413 +        +1 ... no limit hit
14414 +        -1 ... over soft limit
14415 +         0 ... over hard limit         */
14416 +
14417 +static inline int __vx_cres_avail(struct vx_info *vxi,
14418 +       int res, int num, char *_file, int _line)
14419 +{
14420 +       struct _vx_limit *limit;
14421 +       rlim_t value;
14422 +
14423 +       if (VXD_RLIMIT_COND(res))
14424 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
14425 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
14426 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
14427 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
14428 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
14429 +                       num, _file, _line);
14430 +       if (!vxi)
14431 +               return 1;
14432 +
14433 +       limit = &vxi->limit;
14434 +       value = __rlim_get(limit, res);
14435 +
14436 +       if (!__vx_cres_adjust_max(limit, res, value))
14437 +               __vx_cres_adjust_min(limit, res, value);
14438 +
14439 +       if (num == 0)
14440 +               return 1;
14441 +
14442 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
14443 +               return -1;
14444 +       if (value + num <= __rlim_soft(limit, res))
14445 +               return -1;
14446 +
14447 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
14448 +               return 1;
14449 +       if (value + num <= __rlim_hard(limit, res))
14450 +               return 1;
14451 +
14452 +       __rlim_hit(limit, res);
14453 +       return 0;
14454 +}
14455 +
14456 +
14457 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
14458 +
14459 +static inline
14460 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
14461 +{
14462 +       rlim_t value, sum = 0;
14463 +       int res;
14464 +
14465 +       while ((res = *array++)) {
14466 +               value = __rlim_get(limit, res);
14467 +               __vx_cres_fixup(limit, res, value);
14468 +               sum += value;
14469 +       }
14470 +       return sum;
14471 +}
14472 +
14473 +static inline
14474 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
14475 +{
14476 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
14477 +       int res = *array;
14478 +
14479 +       if (value == __rlim_get(limit, res))
14480 +               return value;
14481 +
14482 +       __rlim_set(limit, res, value);
14483 +       /* now adjust min/max */
14484 +       if (!__vx_cres_adjust_max(limit, res, value))
14485 +               __vx_cres_adjust_min(limit, res, value);
14486 +
14487 +       return value;
14488 +}
14489 +
14490 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
14491 +       const int *array, int num, char *_file, int _line)
14492 +{
14493 +       struct _vx_limit *limit;
14494 +       rlim_t value = 0;
14495 +       int res;
14496 +
14497 +       if (num == 0)
14498 +               return 1;
14499 +       if (!vxi)
14500 +               return 1;
14501 +
14502 +       limit = &vxi->limit;
14503 +       res = *array;
14504 +       value = __vx_cres_array_sum(limit, array + 1);
14505 +
14506 +       __rlim_set(limit, res, value);
14507 +       __vx_cres_fixup(limit, res, value);
14508 +
14509 +       return __vx_cres_avail(vxi, res, num, _file, _line);
14510 +}
14511 +
14512 +
14513 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
14514 +{
14515 +       rlim_t value;
14516 +       int res;
14517 +
14518 +       /* complex resources first */
14519 +       if ((id < 0) || (id == RLIMIT_RSS))
14520 +               __vx_cres_array_fixup(limit, VLA_RSS);
14521 +
14522 +       for (res = 0; res < NUM_LIMITS; res++) {
14523 +               if ((id > 0) && (res != id))
14524 +                       continue;
14525 +
14526 +               value = __rlim_get(limit, res);
14527 +               __vx_cres_fixup(limit, res, value);
14528 +
14529 +               /* not supposed to happen, maybe warn? */
14530 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
14531 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
14532 +       }
14533 +}
14534 +
14535 +
14536 +#endif /* __KERNEL__ */
14537 +#endif /* _VX_LIMIT_INT_H */
14538 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/monitor.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/monitor.h
14539 --- linux-2.6.22.10/include/linux/vserver/monitor.h     1970-01-01 01:00:00 +0100
14540 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/monitor.h   2007-06-15 02:37:04 +0200
14541 @@ -0,0 +1,95 @@
14542 +#ifndef _VX_MONITOR_H
14543 +#define _VX_MONITOR_H
14544 +
14545 +
14546 +enum {
14547 +       VXM_UNUSED = 0,
14548 +
14549 +       VXM_SYNC = 0x10,
14550 +
14551 +       VXM_UPDATE = 0x20,
14552 +       VXM_UPDATE_1,
14553 +       VXM_UPDATE_2,
14554 +
14555 +       VXM_RQINFO_1 = 0x24,
14556 +       VXM_RQINFO_2,
14557 +
14558 +       VXM_ACTIVATE = 0x40,
14559 +       VXM_DEACTIVATE,
14560 +       VXM_IDLE,
14561 +
14562 +       VXM_HOLD = 0x44,
14563 +       VXM_UNHOLD,
14564 +
14565 +       VXM_MIGRATE = 0x48,
14566 +       VXM_RESCHED,
14567 +
14568 +       /* all other bits are flags */
14569 +       VXM_SCHED = 0x80,
14570 +};
14571 +
14572 +struct _vxm_update_1 {
14573 +       uint32_t tokens_max;
14574 +       uint32_t fill_rate;
14575 +       uint32_t interval;
14576 +};
14577 +
14578 +struct _vxm_update_2 {
14579 +       uint32_t tokens_min;
14580 +       uint32_t fill_rate;
14581 +       uint32_t interval;
14582 +};
14583 +
14584 +struct _vxm_rqinfo_1 {
14585 +       uint16_t running;
14586 +       uint16_t onhold;
14587 +       uint16_t iowait;
14588 +       uint16_t uintr;
14589 +       uint32_t idle_tokens;
14590 +};
14591 +
14592 +struct _vxm_rqinfo_2 {
14593 +       uint32_t norm_time;
14594 +       uint32_t idle_time;
14595 +       uint32_t idle_skip;
14596 +};
14597 +
14598 +struct _vxm_sched {
14599 +       uint32_t tokens;
14600 +       uint32_t norm_time;
14601 +       uint32_t idle_time;
14602 +};
14603 +
14604 +struct _vxm_task {
14605 +       uint16_t pid;
14606 +       uint16_t state;
14607 +};
14608 +
14609 +struct _vxm_event {
14610 +       uint32_t jif;
14611 +       union {
14612 +               uint32_t seq;
14613 +               uint32_t sec;
14614 +       };
14615 +       union {
14616 +               uint32_t tokens;
14617 +               uint32_t nsec;
14618 +               struct _vxm_task tsk;
14619 +       };
14620 +};
14621 +
14622 +struct _vx_mon_entry {
14623 +       uint16_t type;
14624 +       uint16_t xid;
14625 +       union {
14626 +               struct _vxm_event ev;
14627 +               struct _vxm_sched sd;
14628 +               struct _vxm_update_1 u1;
14629 +               struct _vxm_update_2 u2;
14630 +               struct _vxm_rqinfo_1 q1;
14631 +               struct _vxm_rqinfo_2 q2;
14632 +       };
14633 +};
14634 +
14635 +
14636 +#endif /* _VX_MONITOR_H */
14637 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/network.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/network.h
14638 --- linux-2.6.22.10/include/linux/vserver/network.h     1970-01-01 01:00:00 +0100
14639 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/network.h   2007-06-15 02:37:04 +0200
14640 @@ -0,0 +1,142 @@
14641 +#ifndef _VX_NETWORK_H
14642 +#define _VX_NETWORK_H
14643 +
14644 +#include <linux/types.h>
14645 +
14646 +
14647 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
14648 +
14649 +#define NX_DYNAMIC_ID  ((uint32_t)-1)          /* id for dynamic context */
14650 +
14651 +#define NB_IPV4ROOT    16
14652 +
14653 +
14654 +/* network flags */
14655 +
14656 +#define NXF_INFO_PRIVATE       0x00000008
14657 +
14658 +#define NXF_STATE_SETUP                (1ULL << 32)
14659 +#define NXF_STATE_ADMIN                (1ULL << 34)
14660 +
14661 +#define NXF_SC_HELPER          (1ULL << 36)
14662 +#define NXF_PERSISTENT         (1ULL << 38)
14663 +
14664 +#define NXF_ONE_TIME           (0x0005ULL << 32)
14665 +
14666 +#define NXF_INIT_SET           (NXF_STATE_ADMIN)
14667 +
14668 +
14669 +/* address types */
14670 +
14671 +#define NXA_TYPE_IPV4          1
14672 +#define NXA_TYPE_IPV6          2
14673 +
14674 +#define NXA_MOD_BCAST          (1 << 8)
14675 +
14676 +#define NXA_TYPE_ANY           ((uint16_t)-1)
14677 +
14678 +
14679 +#ifdef __KERNEL__
14680 +
14681 +#include <linux/list.h>
14682 +#include <linux/spinlock.h>
14683 +#include <linux/rcupdate.h>
14684 +#include <asm/atomic.h>
14685 +
14686 +
14687 +struct nx_info {
14688 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
14689 +       nid_t nx_id;                    /* vnet id */
14690 +       atomic_t nx_usecnt;             /* usage count */
14691 +       atomic_t nx_tasks;              /* tasks count */
14692 +       int nx_state;                   /* context state */
14693 +
14694 +       uint64_t nx_flags;              /* network flag word */
14695 +       uint64_t nx_ncaps;              /* network capabilities */
14696 +
14697 +       int nbipv4;
14698 +       __u32 ipv4[NB_IPV4ROOT];        /* Process can only bind to these IPs */
14699 +                                       /* The first one is used to connect */
14700 +                                       /* and for bind any service */
14701 +                                       /* The other must be used explicity */
14702 +       __u32 mask[NB_IPV4ROOT];        /* Netmask for each ipv4 */
14703 +                                       /* Used to select the proper source */
14704 +                                       /* address for sockets */
14705 +       __u32 v4_bcast;                 /* Broadcast address to receive UDP  */
14706 +
14707 +       char nx_name[65];               /* network context name */
14708 +};
14709 +
14710 +
14711 +/* status flags */
14712 +
14713 +#define NXS_HASHED      0x0001
14714 +#define NXS_SHUTDOWN    0x0100
14715 +#define NXS_RELEASED    0x8000
14716 +
14717 +/* check conditions */
14718 +
14719 +#define NX_ADMIN       0x0001
14720 +#define NX_WATCH       0x0002
14721 +#define NX_BLEND       0x0004
14722 +#define NX_HOSTID      0x0008
14723 +
14724 +#define NX_IDENT       0x0010
14725 +#define NX_EQUIV       0x0020
14726 +#define NX_PARENT      0x0040
14727 +#define NX_CHILD       0x0080
14728 +
14729 +#define NX_ARG_MASK    0x00F0
14730 +
14731 +#define NX_DYNAMIC     0x0100
14732 +#define NX_STATIC      0x0200
14733 +
14734 +#define NX_ATR_MASK    0x0F00
14735 +
14736 +
14737 +extern struct nx_info *lookup_nx_info(int);
14738 +
14739 +extern int get_nid_list(int, unsigned int *, int);
14740 +extern int nid_is_hashed(nid_t);
14741 +
14742 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
14743 +
14744 +extern long vs_net_change(struct nx_info *, unsigned int);
14745 +
14746 +struct in_ifaddr;
14747 +struct net_device;
14748 +
14749 +#ifdef CONFIG_INET
14750 +int ifa_in_nx_info(struct in_ifaddr *, struct nx_info *);
14751 +int dev_in_nx_info(struct net_device *, struct nx_info *);
14752 +
14753 +#else /* CONFIG_INET */
14754 +static inline
14755 +int ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
14756 +{
14757 +       return 1;
14758 +}
14759 +
14760 +static inline
14761 +int dev_in_nx_info(struct net_device *d, struct nx_info *n)
14762 +{
14763 +       return 1;
14764 +}
14765 +#endif /* CONFIG_INET */
14766 +
14767 +struct sock;
14768 +
14769 +#ifdef CONFIG_INET
14770 +int nx_addr_conflict(struct nx_info *, uint32_t, const struct sock *);
14771 +#else /* CONFIG_INET */
14772 +static inline
14773 +int nx_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
14774 +{
14775 +       return 1;
14776 +}
14777 +#endif /* CONFIG_INET */
14778 +
14779 +#endif /* __KERNEL__ */
14780 +#else  /* _VX_NETWORK_H */
14781 +#warning duplicate inclusion
14782 +#endif /* _VX_NETWORK_H */
14783 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/network_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/network_cmd.h
14784 --- linux-2.6.22.10/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00 +0100
14785 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/network_cmd.h       2007-06-15 02:37:04 +0200
14786 @@ -0,0 +1,89 @@
14787 +#ifndef _VX_NETWORK_CMD_H
14788 +#define _VX_NETWORK_CMD_H
14789 +
14790 +
14791 +/* vinfo commands */
14792 +
14793 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
14794 +
14795 +#ifdef __KERNEL__
14796 +extern int vc_task_nid(uint32_t, void __user *);
14797 +
14798 +#endif /* __KERNEL__ */
14799 +
14800 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
14801 +
14802 +struct vcmd_nx_info_v0 {
14803 +       uint32_t nid;
14804 +       /* more to come */
14805 +};
14806 +
14807 +#ifdef __KERNEL__
14808 +extern int vc_nx_info(struct nx_info *, void __user *);
14809 +
14810 +#endif /* __KERNEL__ */
14811 +
14812 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
14813 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
14814 +
14815 +struct  vcmd_net_create {
14816 +       uint64_t flagword;
14817 +};
14818 +
14819 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
14820 +
14821 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
14822 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
14823 +
14824 +struct vcmd_net_addr_v0 {
14825 +       uint16_t type;
14826 +       uint16_t count;
14827 +       uint32_t ip[4];
14828 +       uint32_t mask[4];
14829 +       /* more to come */
14830 +};
14831 +
14832 +
14833 +#ifdef __KERNEL__
14834 +extern int vc_net_create(uint32_t, void __user *);
14835 +extern int vc_net_migrate(struct nx_info *, void __user *);
14836 +
14837 +extern int vc_net_add(struct nx_info *, void __user *);
14838 +extern int vc_net_remove(struct nx_info *, void __user *);
14839 +
14840 +#endif /* __KERNEL__ */
14841 +
14842 +
14843 +/* flag commands */
14844 +
14845 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
14846 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
14847 +
14848 +struct vcmd_net_flags_v0 {
14849 +       uint64_t flagword;
14850 +       uint64_t mask;
14851 +};
14852 +
14853 +#ifdef __KERNEL__
14854 +extern int vc_get_nflags(struct nx_info *, void __user *);
14855 +extern int vc_set_nflags(struct nx_info *, void __user *);
14856 +
14857 +#endif /* __KERNEL__ */
14858 +
14859 +
14860 +/* network caps commands */
14861 +
14862 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
14863 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
14864 +
14865 +struct vcmd_net_caps_v0 {
14866 +       uint64_t ncaps;
14867 +       uint64_t cmask;
14868 +};
14869 +
14870 +#ifdef __KERNEL__
14871 +extern int vc_get_ncaps(struct nx_info *, void __user *);
14872 +extern int vc_set_ncaps(struct nx_info *, void __user *);
14873 +
14874 +#endif /* __KERNEL__ */
14875 +#endif /* _VX_CONTEXT_CMD_H */
14876 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/percpu.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/percpu.h
14877 --- linux-2.6.22.10/include/linux/vserver/percpu.h      1970-01-01 01:00:00 +0100
14878 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/percpu.h    2007-06-15 02:37:04 +0200
14879 @@ -0,0 +1,14 @@
14880 +#ifndef _VX_PERCPU_H
14881 +#define _VX_PERCPU_H
14882 +
14883 +#include "cvirt_def.h"
14884 +#include "sched_def.h"
14885 +
14886 +struct _vx_percpu {
14887 +       struct _vx_cvirt_pc cvirt;
14888 +       struct _vx_sched_pc sched;
14889 +};
14890 +
14891 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
14892 +
14893 +#endif /* _VX_PERCPU_H */
14894 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/sched.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/sched.h
14895 --- linux-2.6.22.10/include/linux/vserver/sched.h       1970-01-01 01:00:00 +0100
14896 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/sched.h     2007-06-15 02:37:04 +0200
14897 @@ -0,0 +1,26 @@
14898 +#ifndef _VX_SCHED_H
14899 +#define _VX_SCHED_H
14900 +
14901 +
14902 +#ifdef __KERNEL__
14903 +
14904 +struct timespec;
14905 +
14906 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14907 +
14908 +
14909 +struct vx_info;
14910 +
14911 +void vx_update_load(struct vx_info *);
14912 +
14913 +
14914 +int vx_tokens_recalc(struct _vx_sched_pc *,
14915 +       unsigned long *, unsigned long *, int [2]);
14916 +
14917 +void vx_update_sched_param(struct _vx_sched *sched,
14918 +       struct _vx_sched_pc *sched_pc);
14919 +
14920 +#endif /* __KERNEL__ */
14921 +#else  /* _VX_SCHED_H */
14922 +#warning duplicate inclusion
14923 +#endif /* _VX_SCHED_H */
14924 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/sched_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/sched_cmd.h
14925 --- linux-2.6.22.10/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00 +0100
14926 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/sched_cmd.h 2007-06-15 02:37:04 +0200
14927 @@ -0,0 +1,108 @@
14928 +#ifndef _VX_SCHED_CMD_H
14929 +#define _VX_SCHED_CMD_H
14930 +
14931 +
14932 +/*  sched vserver commands */
14933 +
14934 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
14935 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
14936 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
14937 +
14938 +struct vcmd_set_sched_v2 {
14939 +       int32_t fill_rate;
14940 +       int32_t interval;
14941 +       int32_t tokens;
14942 +       int32_t tokens_min;
14943 +       int32_t tokens_max;
14944 +       uint64_t cpu_mask;
14945 +};
14946 +
14947 +struct vcmd_set_sched_v3 {
14948 +       uint32_t set_mask;
14949 +       int32_t fill_rate;
14950 +       int32_t interval;
14951 +       int32_t tokens;
14952 +       int32_t tokens_min;
14953 +       int32_t tokens_max;
14954 +       int32_t priority_bias;
14955 +};
14956 +
14957 +struct vcmd_set_sched_v4 {
14958 +       uint32_t set_mask;
14959 +       int32_t fill_rate;
14960 +       int32_t interval;
14961 +       int32_t tokens;
14962 +       int32_t tokens_min;
14963 +       int32_t tokens_max;
14964 +       int32_t prio_bias;
14965 +       int32_t cpu_id;
14966 +       int32_t bucket_id;
14967 +};
14968 +
14969 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
14970 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
14971 +
14972 +struct vcmd_sched_v5 {
14973 +       uint32_t mask;
14974 +       int32_t cpu_id;
14975 +       int32_t bucket_id;
14976 +       int32_t fill_rate[2];
14977 +       int32_t interval[2];
14978 +       int32_t tokens;
14979 +       int32_t tokens_min;
14980 +       int32_t tokens_max;
14981 +       int32_t prio_bias;
14982 +};
14983 +
14984 +#define VXSM_FILL_RATE         0x0001
14985 +#define VXSM_INTERVAL          0x0002
14986 +#define VXSM_FILL_RATE2                0x0004
14987 +#define VXSM_INTERVAL2         0x0008
14988 +#define VXSM_TOKENS            0x0010
14989 +#define VXSM_TOKENS_MIN                0x0020
14990 +#define VXSM_TOKENS_MAX                0x0040
14991 +#define VXSM_PRIO_BIAS         0x0100
14992 +
14993 +#define VXSM_IDLE_TIME         0x0200
14994 +#define VXSM_FORCE             0x0400
14995 +
14996 +#define        VXSM_V3_MASK            0x0173
14997 +#define        VXSM_SET_MASK           0x01FF
14998 +
14999 +#define VXSM_CPU_ID            0x1000
15000 +#define VXSM_BUCKET_ID         0x2000
15001 +
15002 +#define VXSM_MSEC              0x4000
15003 +
15004 +#define SCHED_KEEP             (-2)    /* only for v2 */
15005 +
15006 +#ifdef __KERNEL__
15007 +
15008 +#include <linux/compiler.h>
15009 +
15010 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
15011 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
15012 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
15013 +extern int vc_set_sched(struct vx_info *, void __user *);
15014 +extern int vc_get_sched(struct vx_info *, void __user *);
15015 +
15016 +#endif /* __KERNEL__ */
15017 +
15018 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
15019 +
15020 +struct vcmd_sched_info {
15021 +       int32_t cpu_id;
15022 +       int32_t bucket_id;
15023 +       uint64_t user_msec;
15024 +       uint64_t sys_msec;
15025 +       uint64_t hold_msec;
15026 +       uint32_t token_usec;
15027 +       int32_t vavavoom;
15028 +};
15029 +
15030 +#ifdef __KERNEL__
15031 +
15032 +extern int vc_sched_info(struct vx_info *, void __user *);
15033 +
15034 +#endif /* __KERNEL__ */
15035 +#endif /* _VX_SCHED_CMD_H */
15036 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/sched_def.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/sched_def.h
15037 --- linux-2.6.22.10/include/linux/vserver/sched_def.h   1970-01-01 01:00:00 +0100
15038 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/sched_def.h 2007-06-15 02:37:04 +0200
15039 @@ -0,0 +1,68 @@
15040 +#ifndef _VX_SCHED_DEF_H
15041 +#define _VX_SCHED_DEF_H
15042 +
15043 +#include <linux/spinlock.h>
15044 +#include <linux/jiffies.h>
15045 +#include <linux/cpumask.h>
15046 +#include <asm/atomic.h>
15047 +#include <asm/param.h>
15048 +
15049 +
15050 +/* context sub struct */
15051 +
15052 +struct _vx_sched {
15053 +       spinlock_t tokens_lock;         /* lock for token bucket */
15054 +
15055 +       int tokens;                     /* number of CPU tokens */
15056 +       int fill_rate[2];               /* Fill rate: add X tokens... */
15057 +       int interval[2];                /* Divisor:   per Y jiffies   */
15058 +       int tokens_min;                 /* Limit:     minimum for unhold */
15059 +       int tokens_max;                 /* Limit:     no more than N tokens */
15060 +
15061 +       int prio_bias;                  /* bias offset for priority */
15062 +
15063 +       unsigned update_mask;           /* which features should be updated */
15064 +       cpumask_t update;               /* CPUs which should update */
15065 +};
15066 +
15067 +struct _vx_sched_pc {
15068 +       int tokens;                     /* number of CPU tokens */
15069 +       int flags;                      /* bucket flags */
15070 +
15071 +       int fill_rate[2];               /* Fill rate: add X tokens... */
15072 +       int interval[2];                /* Divisor:   per Y jiffies   */
15073 +       int tokens_min;                 /* Limit:     minimum for unhold */
15074 +       int tokens_max;                 /* Limit:     no more than N tokens */
15075 +
15076 +       int prio_bias;                  /* bias offset for priority */
15077 +       int vavavoom;                   /* last calculated vavavoom */
15078 +
15079 +       unsigned long norm_time;        /* last time accounted */
15080 +       unsigned long idle_time;        /* non linear time for fair sched */
15081 +       unsigned long token_time;       /* token time for accounting */
15082 +       unsigned long onhold;           /* jiffies when put on hold */
15083 +
15084 +       uint64_t user_ticks;            /* token tick events */
15085 +       uint64_t sys_ticks;             /* token tick events */
15086 +       uint64_t hold_ticks;            /* token ticks paused */
15087 +};
15088 +
15089 +
15090 +#define VXSF_ONHOLD    0x0001
15091 +#define VXSF_IDLE_TIME 0x0100
15092 +
15093 +#ifdef CONFIG_VSERVER_DEBUG
15094 +
15095 +static inline void __dump_vx_sched(struct _vx_sched *sched)
15096 +{
15097 +       printk("\t_vx_sched:\n");
15098 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
15099 +               sched->fill_rate[0], sched->interval[0],
15100 +               sched->fill_rate[1], sched->interval[1],
15101 +               sched->tokens_min, sched->tokens_max);
15102 +       printk("\t priority = %4d\n", sched->prio_bias);
15103 +}
15104 +
15105 +#endif
15106 +
15107 +#endif /* _VX_SCHED_DEF_H */
15108 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/signal.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/signal.h
15109 --- linux-2.6.22.10/include/linux/vserver/signal.h      1970-01-01 01:00:00 +0100
15110 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/signal.h    2007-06-15 02:37:04 +0200
15111 @@ -0,0 +1,14 @@
15112 +#ifndef _VX_SIGNAL_H
15113 +#define _VX_SIGNAL_H
15114 +
15115 +
15116 +#ifdef __KERNEL__
15117 +
15118 +struct vx_info;
15119 +
15120 +int vx_info_kill(struct vx_info *, int, int);
15121 +
15122 +#endif /* __KERNEL__ */
15123 +#else  /* _VX_SIGNAL_H */
15124 +#warning duplicate inclusion
15125 +#endif /* _VX_SIGNAL_H */
15126 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/signal_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/signal_cmd.h
15127 --- linux-2.6.22.10/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00 +0100
15128 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/signal_cmd.h        2007-06-15 02:37:04 +0200
15129 @@ -0,0 +1,43 @@
15130 +#ifndef _VX_SIGNAL_CMD_H
15131 +#define _VX_SIGNAL_CMD_H
15132 +
15133 +
15134 +/*  signalling vserver commands */
15135 +
15136 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
15137 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
15138 +
15139 +struct vcmd_ctx_kill_v0 {
15140 +       int32_t pid;
15141 +       int32_t sig;
15142 +};
15143 +
15144 +struct vcmd_wait_exit_v0 {
15145 +       int32_t reboot_cmd;
15146 +       int32_t exit_code;
15147 +};
15148 +
15149 +#ifdef __KERNEL__
15150 +
15151 +extern int vc_ctx_kill(struct vx_info *, void __user *);
15152 +extern int vc_wait_exit(struct vx_info *, void __user *);
15153 +
15154 +#endif /* __KERNEL__ */
15155 +
15156 +/*  process alteration commands */
15157 +
15158 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
15159 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
15160 +
15161 +struct vcmd_pflags_v0 {
15162 +       uint32_t flagword;
15163 +       uint32_t mask;
15164 +};
15165 +
15166 +#ifdef __KERNEL__
15167 +
15168 +extern int vc_get_pflags(uint32_t pid, void __user *);
15169 +extern int vc_set_pflags(uint32_t pid, void __user *);
15170 +
15171 +#endif /* __KERNEL__ */
15172 +#endif /* _VX_SIGNAL_CMD_H */
15173 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/space.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/space.h
15174 --- linux-2.6.22.10/include/linux/vserver/space.h       1970-01-01 01:00:00 +0100
15175 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/space.h     2007-06-15 02:37:04 +0200
15176 @@ -0,0 +1,13 @@
15177 +#ifndef _VX_SPACE_H
15178 +#define _VX_SPACE_H
15179 +
15180 +
15181 +#include <linux/types.h>
15182 +
15183 +struct vx_info;
15184 +
15185 +int vx_set_space(struct vx_info *vxi, unsigned long mask);
15186 +
15187 +#else  /* _VX_SPACE_H */
15188 +#warning duplicate inclusion
15189 +#endif /* _VX_SPACE_H */
15190 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/space_cmd.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/space_cmd.h
15191 --- linux-2.6.22.10/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00 +0100
15192 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/space_cmd.h 2007-06-15 02:37:04 +0200
15193 @@ -0,0 +1,26 @@
15194 +#ifndef _VX_SPACE_CMD_H
15195 +#define _VX_SPACE_CMD_H
15196 +
15197 +
15198 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
15199 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
15200 +
15201 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
15202 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
15203 +
15204 +#define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
15205 +
15206 +
15207 +struct vcmd_space_mask {
15208 +       uint64_t mask;
15209 +};
15210 +
15211 +
15212 +#ifdef __KERNEL__
15213 +
15214 +extern int vc_enter_space(struct vx_info *, void __user *);
15215 +extern int vc_set_space(struct vx_info *, void __user *);
15216 +extern int vc_get_space_mask(struct vx_info *, void __user *);
15217 +
15218 +#endif /* __KERNEL__ */
15219 +#endif /* _VX_SPACE_CMD_H */
15220 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/switch.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/switch.h
15221 --- linux-2.6.22.10/include/linux/vserver/switch.h      1970-01-01 01:00:00 +0100
15222 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/switch.h    2007-06-15 02:37:04 +0200
15223 @@ -0,0 +1,95 @@
15224 +#ifndef _VX_SWITCH_H
15225 +#define _VX_SWITCH_H
15226 +
15227 +#include <linux/types.h>
15228 +
15229 +
15230 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
15231 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
15232 +#define VC_VERSION(c)          ((c) & 0xFFF)
15233 +
15234 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
15235 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
15236 +
15237 +/*
15238 +
15239 +  Syscall Matrix V2.8
15240 +
15241 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
15242 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
15243 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
15244 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15245 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICES|       |
15246 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
15247 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15248 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
15249 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
15250 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15251 +  MEMORY |       |       |       |       |       |       | |SWAP   |       |
15252 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
15253 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15254 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
15255 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
15256 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15257 +  DISK   |       |       |       |       |DLIMIT |       | |INODE  |       |
15258 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
15259 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15260 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
15261 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
15262 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
15263 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
15264 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
15265 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15266 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
15267 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
15268 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
15269 +
15270 +*/
15271 +
15272 +#define VC_CAT_VERSION         0
15273 +
15274 +#define VC_CAT_VSETUP          1
15275 +#define VC_CAT_VHOST           2
15276 +
15277 +#define VC_CAT_VPROC           9
15278 +#define VC_CAT_PROCALT         10
15279 +#define VC_CAT_PROCMIG         11
15280 +#define VC_CAT_PROCTRL         12
15281 +
15282 +#define VC_CAT_SCHED           14
15283 +
15284 +#define VC_CAT_VNET            25
15285 +#define VC_CAT_NETALT          26
15286 +#define VC_CAT_NETMIG          27
15287 +#define VC_CAT_NETCTRL         28
15288 +
15289 +#define VC_CAT_DLIMIT          36
15290 +#define VC_CAT_INODE           38
15291 +
15292 +#define VC_CAT_VSTAT           40
15293 +#define VC_CAT_VINFO           46
15294 +#define VC_CAT_EVENT           48
15295 +
15296 +#define VC_CAT_FLAGS           52
15297 +#define VC_CAT_DEBUG           56
15298 +#define VC_CAT_RLIMIT          60
15299 +
15300 +#define VC_CAT_SYSTEST         61
15301 +#define VC_CAT_COMPAT          63
15302 +
15303 +/*  query version */
15304 +
15305 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
15306 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
15307 +
15308 +
15309 +#ifdef __KERNEL__
15310 +
15311 +#include <linux/errno.h>
15312 +
15313 +
15314 +#else  /* __KERNEL__ */
15315 +#define __user
15316 +#endif /* __KERNEL__ */
15317 +
15318 +#endif /* _VX_SWITCH_H */
15319 diff -NurpP --minimal linux-2.6.22.10/include/linux/vserver/tag.h linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/tag.h
15320 --- linux-2.6.22.10/include/linux/vserver/tag.h 1970-01-01 01:00:00 +0100
15321 +++ linux-2.6.22.10-vs2.2.0.5/include/linux/vserver/tag.h       2007-06-15 02:37:04 +0200
15322 @@ -0,0 +1,140 @@
15323 +#ifndef _DX_TAG_H
15324 +#define _DX_TAG_H
15325 +
15326 +
15327 +#define DX_TAG(in)     (IS_TAGGED(in))
15328 +
15329 +
15330 +#ifdef CONFIG_DX_TAG_NFSD
15331 +#define DX_TAG_NFSD    1
15332 +#else
15333 +#define DX_TAG_NFSD    0
15334 +#endif
15335 +
15336 +
15337 +#ifdef CONFIG_TAGGING_NONE
15338 +
15339 +#define MAX_UID                0xFFFFFFFF
15340 +#define MAX_GID                0xFFFFFFFF
15341 +
15342 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
15343 +
15344 +#define TAGINO_UID(cond, uid, tag)     (uid)
15345 +#define TAGINO_GID(cond, gid, tag)     (gid)
15346 +
15347 +#endif
15348 +
15349 +
15350 +#ifdef CONFIG_TAGGING_GID16
15351 +
15352 +#define MAX_UID                0xFFFFFFFF
15353 +#define MAX_GID                0x0000FFFF
15354 +
15355 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15356 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
15357 +
15358 +#define TAGINO_UID(cond, uid, tag)     (uid)
15359 +#define TAGINO_GID(cond, gid, tag)     \
15360 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
15361 +
15362 +#endif
15363 +
15364 +
15365 +#ifdef CONFIG_TAGGING_ID24
15366 +
15367 +#define MAX_UID                0x00FFFFFF
15368 +#define MAX_GID                0x00FFFFFF
15369 +
15370 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15371 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
15372 +
15373 +#define TAGINO_UID(cond, uid, tag)     \
15374 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
15375 +#define TAGINO_GID(cond, gid, tag)     \
15376 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
15377 +
15378 +#endif
15379 +
15380 +
15381 +#ifdef CONFIG_TAGGING_UID16
15382 +
15383 +#define MAX_UID                0x0000FFFF
15384 +#define MAX_GID                0xFFFFFFFF
15385 +
15386 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15387 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
15388 +
15389 +#define TAGINO_UID(cond, uid, tag)     \
15390 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
15391 +#define TAGINO_GID(cond, gid, tag)     (gid)
15392 +
15393 +#endif
15394 +
15395 +
15396 +#ifdef CONFIG_TAGGING_INTERN
15397 +
15398 +#define MAX_UID                0xFFFFFFFF
15399 +#define MAX_GID                0xFFFFFFFF
15400 +
15401 +#define INOTAG_TAG(cond, uid, gid, tag)        \
15402 +       ((cond) ? (tag) : 0)
15403 +
15404 +#define TAGINO_UID(cond, uid, tag)     (uid)
15405 +#define TAGINO_GID(cond, gid, tag)     (gid)
15406 +
15407 +#endif
15408 +
15409 +
15410 +#ifndef CONFIG_TAGGING_NONE
15411 +#define dx_current_fstag(sb)   \
15412 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
15413 +#else
15414 +#define dx_current_fstag(sb)   (0)
15415 +#endif
15416 +
15417 +#ifndef CONFIG_TAGGING_INTERN
15418 +#define TAGINO_TAG(cond, tag)  (0)
15419 +#else
15420 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
15421 +#endif
15422 +
15423 +#define INOTAG_UID(cond, uid, gid)     \
15424 +       ((cond) ? ((uid) & MAX_UID) : (uid))
15425 +#define INOTAG_GID(cond, uid, gid)     \
15426 +       ((cond) ? ((gid) & MAX_GID) : (gid))
15427 +
15428 +
15429 +static inline uid_t dx_map_uid(uid_t uid)
15430 +{
15431 +       if ((uid > MAX_UID) && (uid != -1))
15432 +               uid = -2;
15433 +       return (uid & MAX_UID);
15434 +}
15435 +
15436 +static inline gid_t dx_map_gid(gid_t gid)
15437 +{
15438 +       if ((gid > MAX_GID) && (gid != -1))
15439 +               gid = -2;
15440 +       return (gid & MAX_GID);
15441 +}
15442 +
15443 +
15444 +#ifdef CONFIG_VSERVER_LEGACY
15445 +#define FIOC_GETTAG    _IOR('x', 1, long)
15446 +#define FIOC_SETTAG    _IOW('x', 2, long)
15447 +#define FIOC_SETTAGJ   _IOW('x', 3, long)
15448 +#endif
15449 +
15450 +#ifdef CONFIG_PROPAGATE
15451 +
15452 +int dx_parse_tag(char *string, tag_t *tag, int remove);
15453 +
15454 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
15455 +
15456 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
15457 +
15458 +#else
15459 +#define dx_propagate_tag(n, i) do { } while (0)
15460 +#endif
15461 +
15462 +#endif /* _DX_TAG_H */
15463 diff -NurpP --minimal linux-2.6.22.10/include/net/af_unix.h linux-2.6.22.10-vs2.2.0.5/include/net/af_unix.h
15464 --- linux-2.6.22.10/include/net/af_unix.h       2007-07-09 13:20:01 +0200
15465 +++ linux-2.6.22.10-vs2.2.0.5/include/net/af_unix.h     2007-06-15 02:37:04 +0200
15466 @@ -4,6 +4,7 @@
15467  #include <linux/socket.h>
15468  #include <linux/un.h>
15469  #include <linux/mutex.h>
15470 +#include <linux/vs_base.h>
15471  #include <net/sock.h>
15472  
15473  extern void unix_inflight(struct file *fp);
15474 @@ -17,9 +18,9 @@ extern spinlock_t unix_table_lock;
15475  
15476  extern atomic_t unix_tot_inflight;
15477  
15478 -static inline struct sock *first_unix_socket(int *i)
15479 +static inline struct sock *next_unix_socket_table(int *i)
15480  {
15481 -       for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
15482 +       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
15483                 if (!hlist_empty(&unix_socket_table[*i]))
15484                         return __sk_head(&unix_socket_table[*i]);
15485         }
15486 @@ -28,16 +29,19 @@ static inline struct sock *first_unix_so
15487  
15488  static inline struct sock *next_unix_socket(int *i, struct sock *s)
15489  {
15490 -       struct sock *next = sk_next(s);
15491 -       /* More in this chain? */
15492 -       if (next)
15493 -               return next;
15494 -       /* Look for next non-empty chain. */
15495 -       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
15496 -               if (!hlist_empty(&unix_socket_table[*i]))
15497 -                       return __sk_head(&unix_socket_table[*i]);
15498 -       }
15499 -       return NULL;
15500 +       do {
15501 +               if (s)
15502 +                       s = sk_next(s);
15503 +               if (!s)
15504 +                       s = next_unix_socket_table(i);
15505 +       } while (s && !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT));
15506 +       return s;
15507 +}
15508 +
15509 +static inline struct sock *first_unix_socket(int *i)
15510 +{
15511 +       *i = 0;
15512 +       return next_unix_socket(i, NULL);
15513  }
15514  
15515  #define forall_unix_sockets(i, s) \
15516 diff -NurpP --minimal linux-2.6.22.10/include/net/inet_hashtables.h linux-2.6.22.10-vs2.2.0.5/include/net/inet_hashtables.h
15517 --- linux-2.6.22.10/include/net/inet_hashtables.h       2007-05-02 19:25:35 +0200
15518 +++ linux-2.6.22.10-vs2.2.0.5/include/net/inet_hashtables.h     2007-06-15 02:37:04 +0200
15519 @@ -271,6 +271,26 @@ static inline int inet_iif(const struct 
15520         return ((struct rtable *)skb->dst)->rt_iif;
15521  }
15522  
15523 +/*
15524 + *      Check if a given address matches for an inet socket
15525 + *
15526 + *      nxi:   the socket's nx_info if any
15527 + *      addr:  to be verified address
15528 + *      saddr: socket addresses
15529 + */
15530 +static inline int inet_addr_match (
15531 +       struct nx_info *nxi,
15532 +       uint32_t addr,
15533 +       uint32_t saddr)
15534 +{
15535 +       if (addr && (saddr == addr))
15536 +               return 1;
15537 +       if (!saddr)
15538 +               return addr_in_nx_info(nxi, addr);
15539 +       return 0;
15540 +}
15541 +
15542 +
15543  extern struct sock *__inet_lookup_listener(struct inet_hashinfo *hashinfo,
15544                                            const __be32 daddr,
15545                                            const unsigned short hnum,
15546 diff -NurpP --minimal linux-2.6.22.10/include/net/inet_sock.h linux-2.6.22.10-vs2.2.0.5/include/net/inet_sock.h
15547 --- linux-2.6.22.10/include/net/inet_sock.h     2007-07-09 13:20:01 +0200
15548 +++ linux-2.6.22.10-vs2.2.0.5/include/net/inet_sock.h   2007-06-15 02:37:04 +0200
15549 @@ -113,6 +113,7 @@ struct inet_sock {
15550         /* Socket demultiplex comparisons on incoming packets. */
15551         __be32                  daddr;
15552         __be32                  rcv_saddr;
15553 +       __be32                  rcv_saddr2;     /* Second bound ipv4 addr, for ipv4root */
15554         __be16                  dport;
15555         __u16                   num;
15556         __be32                  saddr;
15557 diff -NurpP --minimal linux-2.6.22.10/include/net/inet_timewait_sock.h linux-2.6.22.10-vs2.2.0.5/include/net/inet_timewait_sock.h
15558 --- linux-2.6.22.10/include/net/inet_timewait_sock.h    2007-05-02 19:25:35 +0200
15559 +++ linux-2.6.22.10-vs2.2.0.5/include/net/inet_timewait_sock.h  2007-06-15 02:37:04 +0200
15560 @@ -115,6 +115,10 @@ struct inet_timewait_sock {
15561  #define tw_refcnt              __tw_common.skc_refcnt
15562  #define tw_hash                        __tw_common.skc_hash
15563  #define tw_prot                        __tw_common.skc_prot
15564 +#define tw_xid         __tw_common.skc_xid
15565 +#define tw_vx_info             __tw_common.skc_vx_info
15566 +#define tw_nid         __tw_common.skc_nid
15567 +#define tw_nx_info             __tw_common.skc_nx_info
15568         volatile unsigned char  tw_substate;
15569         /* 3 bits hole, try to pack */
15570         unsigned char           tw_rcv_wscale;
15571 diff -NurpP --minimal linux-2.6.22.10/include/net/route.h linux-2.6.22.10-vs2.2.0.5/include/net/route.h
15572 --- linux-2.6.22.10/include/net/route.h 2007-05-02 19:25:35 +0200
15573 +++ linux-2.6.22.10-vs2.2.0.5/include/net/route.h       2007-06-15 02:37:04 +0200
15574 @@ -27,12 +27,16 @@
15575  #include <net/dst.h>
15576  #include <net/inetpeer.h>
15577  #include <net/flow.h>
15578 +#include <net/inet_sock.h>
15579  #include <linux/in_route.h>
15580  #include <linux/rtnetlink.h>
15581  #include <linux/route.h>
15582  #include <linux/ip.h>
15583  #include <linux/cache.h>
15584  #include <linux/security.h>
15585 +#include <linux/vs_base.h>
15586 +#include <linux/vs_network.h>
15587 +#include <linux/in.h>
15588  
15589  #ifndef __KERNEL__
15590  #warning This file is not supposed to be used outside of kernel.
15591 @@ -143,6 +147,59 @@ static inline char rt_tos2priority(u8 to
15592         return ip_tos2prio[IPTOS_TOS(tos)>>1];
15593  }
15594  
15595 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
15596 +
15597 +static inline int ip_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
15598 +{
15599 +       int err;
15600 +       int i, n = nxi->nbipv4;
15601 +       u32 ipv4root = nxi->ipv4[0];
15602 +
15603 +       if (ipv4root == 0)
15604 +               return 0;
15605 +
15606 +       if (fl->fl4_src == 0) {
15607 +               if (n > 1) {
15608 +                       u32 foundsrc;
15609 +
15610 +                       err = __ip_route_output_key(rp, fl);
15611 +                       if (err) {
15612 +                               fl->fl4_src = ipv4root;
15613 +                               err = __ip_route_output_key(rp, fl);
15614 +                       }
15615 +                       if (err)
15616 +                               return err;
15617 +
15618 +                       foundsrc = (*rp)->rt_src;
15619 +                       ip_rt_put(*rp);
15620 +
15621 +                       for (i=0; i<n; i++){
15622 +                               u32 mask = nxi->mask[i];
15623 +                               u32 ipv4 = nxi->ipv4[i];
15624 +                               u32 net4 = ipv4 & mask;
15625 +
15626 +                               if (foundsrc == ipv4) {
15627 +                                       fl->fl4_src = ipv4;
15628 +                                       break;
15629 +                               }
15630 +                               if (!fl->fl4_src && (foundsrc & mask) == net4)
15631 +                                       fl->fl4_src = ipv4;
15632 +                       }
15633 +               }
15634 +               if (fl->fl4_src == 0)
15635 +                       fl->fl4_src = (fl->fl4_dst == IPI_LOOPBACK)
15636 +                               ? IPI_LOOPBACK : ipv4root;
15637 +       } else {
15638 +               for (i=0; i<n; i++) {
15639 +                       if (nxi->ipv4[i] == fl->fl4_src)
15640 +                               break;
15641 +               }
15642 +               if (i == n)
15643 +                       return -EPERM;
15644 +       }
15645 +       return 0;
15646 +}
15647 +
15648  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
15649                                    __be32 src, u32 tos, int oif, u8 protocol,
15650                                    __be16 sport, __be16 dport, struct sock *sk,
15651 @@ -158,7 +215,27 @@ static inline int ip_route_connect(struc
15652                                          .dport = dport } } };
15653  
15654         int err;
15655 -       if (!dst || !src) {
15656 +       struct nx_info *nx_info = current->nx_info;
15657 +
15658 +       if (sk)
15659 +               nx_info = sk->sk_nx_info;
15660 +       vxdprintk(VXD_CBIT(net, 4),
15661 +               "ip_route_connect(%p) %p,%p;%lx",
15662 +               sk, nx_info, sk->sk_socket,
15663 +               (sk->sk_socket?sk->sk_socket->flags:0));
15664 +
15665 +       if (nx_info) {
15666 +               err = ip_find_src(nx_info, rp, &fl);
15667 +               if (err)
15668 +                       return err;
15669 +               if (fl.fl4_dst == IPI_LOOPBACK && !nx_check(0, VS_ADMIN))
15670 +                       fl.fl4_dst = nx_info->ipv4[0];
15671 +#ifdef CONFIG_VSERVER_REMAP_SADDR
15672 +               if (fl.fl4_src == IPI_LOOPBACK && !nx_check(0, VS_ADMIN))
15673 +                       fl.fl4_src = nx_info->ipv4[0];
15674 +#endif
15675 +       }
15676 +       if (!fl.fl4_dst || !fl.fl4_src) {
15677                 err = __ip_route_output_key(rp, &fl);
15678                 if (err)
15679                         return err;
15680 diff -NurpP --minimal linux-2.6.22.10/include/net/sock.h linux-2.6.22.10-vs2.2.0.5/include/net/sock.h
15681 --- linux-2.6.22.10/include/net/sock.h  2007-07-09 13:20:02 +0200
15682 +++ linux-2.6.22.10-vs2.2.0.5/include/net/sock.h        2007-06-15 02:37:04 +0200
15683 @@ -119,6 +119,10 @@ struct sock_common {
15684         atomic_t                skc_refcnt;
15685         unsigned int            skc_hash;
15686         struct proto            *skc_prot;
15687 +       xid_t                   skc_xid;
15688 +       struct vx_info          *skc_vx_info;
15689 +       nid_t                   skc_nid;
15690 +       struct nx_info          *skc_nx_info;
15691  };
15692  
15693  /**
15694 @@ -195,6 +199,10 @@ struct sock {
15695  #define sk_refcnt              __sk_common.skc_refcnt
15696  #define sk_hash                        __sk_common.skc_hash
15697  #define sk_prot                        __sk_common.skc_prot
15698 +#define sk_xid                 __sk_common.skc_xid
15699 +#define sk_vx_info             __sk_common.skc_vx_info
15700 +#define sk_nid                 __sk_common.skc_nid
15701 +#define sk_nx_info             __sk_common.skc_nx_info
15702         unsigned char           sk_shutdown : 2,
15703                                 sk_no_check : 2,
15704                                 sk_userlocks : 4;
15705 diff -NurpP --minimal linux-2.6.22.10/init/main.c linux-2.6.22.10-vs2.2.0.5/init/main.c
15706 --- linux-2.6.22.10/init/main.c 2007-07-09 13:20:03 +0200
15707 +++ linux-2.6.22.10-vs2.2.0.5/init/main.c       2007-06-15 04:03:00 +0200
15708 @@ -55,6 +55,7 @@
15709  #include <linux/pid_namespace.h>
15710  #include <linux/device.h>
15711  #include <linux/kthread.h>
15712 +#include <linux/vserver/percpu.h>
15713  
15714  #include <asm/io.h>
15715  #include <asm/bugs.h>
15716 @@ -364,12 +365,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
15717  
15718  static void __init setup_per_cpu_areas(void)
15719  {
15720 -       unsigned long size, i;
15721 +       unsigned long size, vspc, i;
15722         char *ptr;
15723         unsigned long nr_possible_cpus = num_possible_cpus();
15724  
15725 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
15726 +
15727         /* Copy section for each CPU (we discard the original) */
15728 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
15729 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
15730         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
15731  
15732         for_each_possible_cpu(i) {
15733 diff -NurpP --minimal linux-2.6.22.10/ipc/mqueue.c linux-2.6.22.10-vs2.2.0.5/ipc/mqueue.c
15734 --- linux-2.6.22.10/ipc/mqueue.c        2007-07-09 13:20:03 +0200
15735 +++ linux-2.6.22.10-vs2.2.0.5/ipc/mqueue.c      2007-06-15 02:37:04 +0200
15736 @@ -29,6 +29,8 @@
15737  #include <linux/audit.h>
15738  #include <linux/signal.h>
15739  #include <linux/mutex.h>
15740 +#include <linux/vs_context.h>
15741 +#include <linux/vs_limit.h>
15742  
15743  #include <net/sock.h>
15744  #include "util.h"
15745 @@ -151,17 +153,20 @@ static struct inode *mqueue_get_inode(st
15746                         spin_lock(&mq_lock);
15747                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
15748                             u->mq_bytes + mq_bytes >
15749 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
15750 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
15751 +                           !vx_ipcmsg_avail(p->vx_info, mq_bytes)) {
15752                                 spin_unlock(&mq_lock);
15753                                 goto out_inode;
15754                         }
15755                         u->mq_bytes += mq_bytes;
15756 +                       vx_ipcmsg_add(p->vx_info, u, mq_bytes);
15757                         spin_unlock(&mq_lock);
15758  
15759                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
15760                         if (!info->messages) {
15761                                 spin_lock(&mq_lock);
15762                                 u->mq_bytes -= mq_bytes;
15763 +                               vx_ipcmsg_sub(p->vx_info, u, mq_bytes);
15764                                 spin_unlock(&mq_lock);
15765                                 goto out_inode;
15766                         }
15767 @@ -257,10 +262,14 @@ static void mqueue_delete_inode(struct i
15768                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
15769         user = info->user;
15770         if (user) {
15771 +               struct vx_info *vxi = lookup_vx_info(user->xid);
15772 +
15773                 spin_lock(&mq_lock);
15774                 user->mq_bytes -= mq_bytes;
15775 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
15776                 queues_count--;
15777                 spin_unlock(&mq_lock);
15778 +               put_vx_info(vxi);
15779                 free_uid(user);
15780         }
15781  }
15782 @@ -748,7 +757,7 @@ asmlinkage long sys_mq_unlink(const char
15783         if (inode)
15784                 atomic_inc(&inode->i_count);
15785  
15786 -       err = vfs_unlink(dentry->d_parent->d_inode, dentry);
15787 +       err = vfs_unlink(dentry->d_parent->d_inode, dentry, NULL);
15788  out_err:
15789         dput(dentry);
15790  
15791 diff -NurpP --minimal linux-2.6.22.10/ipc/msg.c linux-2.6.22.10-vs2.2.0.5/ipc/msg.c
15792 --- linux-2.6.22.10/ipc/msg.c   2007-02-06 03:01:55 +0100
15793 +++ linux-2.6.22.10-vs2.2.0.5/ipc/msg.c 2007-06-15 02:37:04 +0200
15794 @@ -36,6 +36,7 @@
15795  #include <linux/seq_file.h>
15796  #include <linux/mutex.h>
15797  #include <linux/nsproxy.h>
15798 +#include <linux/vs_base.h>
15799  
15800  #include <asm/current.h>
15801  #include <asm/uaccess.h>
15802 @@ -149,6 +150,7 @@ static int newque (struct ipc_namespace 
15803  
15804         msq->q_perm.mode = msgflg & S_IRWXUGO;
15805         msq->q_perm.key = key;
15806 +       msq->q_perm.xid = vx_current_xid();
15807  
15808         msq->q_perm.security = NULL;
15809         retval = security_msg_queue_alloc(msq);
15810 diff -NurpP --minimal linux-2.6.22.10/ipc/sem.c linux-2.6.22.10-vs2.2.0.5/ipc/sem.c
15811 --- linux-2.6.22.10/ipc/sem.c   2007-07-09 13:20:03 +0200
15812 +++ linux-2.6.22.10-vs2.2.0.5/ipc/sem.c 2007-06-15 02:37:04 +0200
15813 @@ -82,6 +82,8 @@
15814  #include <linux/seq_file.h>
15815  #include <linux/mutex.h>
15816  #include <linux/nsproxy.h>
15817 +#include <linux/vs_base.h>
15818 +#include <linux/vs_limit.h>
15819  
15820  #include <asm/uaccess.h>
15821  #include "util.h"
15822 @@ -229,6 +231,7 @@ static int newary (struct ipc_namespace 
15823  
15824         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15825         sma->sem_perm.key = key;
15826 +       sma->sem_perm.xid = vx_current_xid();
15827  
15828         sma->sem_perm.security = NULL;
15829         retval = security_sem_alloc(sma);
15830 @@ -244,6 +247,9 @@ static int newary (struct ipc_namespace 
15831                 return -ENOSPC;
15832         }
15833         ns->used_sems += nsems;
15834 +       /* FIXME: obsoleted? */
15835 +       vx_semary_inc(sma);
15836 +       vx_nsems_add(sma, nsems);
15837  
15838         sma->sem_id = sem_buildid(ns, id, sma->sem_perm.seq);
15839         sma->sem_base = (struct sem *) &sma[1];
15840 @@ -525,6 +531,9 @@ static void freeary (struct ipc_namespac
15841         sem_unlock(sma);
15842  
15843         ns->used_sems -= sma->sem_nsems;
15844 +       /* FIXME: obsoleted? */
15845 +       vx_nsems_sub(sma, sma->sem_nsems);
15846 +       vx_semary_dec(sma);
15847         size = sizeof (*sma) + sma->sem_nsems * sizeof (struct sem);
15848         security_sem_free(sma);
15849         ipc_rcu_putref(sma);
15850 diff -NurpP --minimal linux-2.6.22.10/ipc/shm.c linux-2.6.22.10-vs2.2.0.5/ipc/shm.c
15851 --- linux-2.6.22.10/ipc/shm.c   2007-10-30 01:57:14 +0100
15852 +++ linux-2.6.22.10-vs2.2.0.5/ipc/shm.c 2007-08-12 12:21:52 +0200
15853 @@ -38,6 +38,8 @@
15854  #include <linux/mutex.h>
15855  #include <linux/nsproxy.h>
15856  #include <linux/mount.h>
15857 +#include <linux/vs_context.h>
15858 +#include <linux/vs_limit.h>
15859  
15860  #include <asm/uaccess.h>
15861  
15862 @@ -185,7 +187,12 @@ static void shm_open(struct vm_area_stru
15863   */
15864  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15865  {
15866 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15867 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15868 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15869 +
15870 +       vx_ipcshm_sub(vxi, shp, numpages);
15871 +       ns->shm_tot -= numpages;
15872 +
15873         shm_rmid(ns, shp->id);
15874         shm_unlock(shp);
15875         if (!is_file_hugepages(shp->shm_file))
15876 @@ -195,6 +202,7 @@ static void shm_destroy(struct ipc_names
15877                                                 shp->mlock_user);
15878         fput (shp->shm_file);
15879         security_shm_free(shp);
15880 +       put_vx_info(vxi);
15881         ipc_rcu_putref(shp);
15882  }
15883  
15884 @@ -351,11 +359,15 @@ static int newseg (struct ipc_namespace 
15885         if (ns->shm_tot + numpages > ns->shm_ctlall)
15886                 return -ENOSPC;
15887  
15888 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
15889 +               return -ENOSPC;
15890 +
15891         shp = ipc_rcu_alloc(sizeof(*shp));
15892         if (!shp)
15893                 return -ENOMEM;
15894  
15895         shp->shm_perm.key = key;
15896 +       shp->shm_perm.xid = vx_current_xid();
15897         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15898         shp->mlock_user = NULL;
15899  
15900 @@ -406,6 +418,7 @@ static int newseg (struct ipc_namespace 
15901         file->f_dentry->d_inode->i_ino = shp->id;
15902  
15903         ns->shm_tot += numpages;
15904 +       vx_ipcshm_add(current->vx_info, key, numpages);
15905         shm_unlock(shp);
15906         return shp->id;
15907  
15908 diff -NurpP --minimal linux-2.6.22.10/ipc/util.c linux-2.6.22.10-vs2.2.0.5/ipc/util.c
15909 --- linux-2.6.22.10/ipc/util.c  2007-07-09 13:20:03 +0200
15910 +++ linux-2.6.22.10-vs2.2.0.5/ipc/util.c        2007-06-15 02:37:04 +0200
15911 @@ -32,6 +32,8 @@
15912  #include <linux/proc_fs.h>
15913  #include <linux/audit.h>
15914  #include <linux/nsproxy.h>
15915 +#include <linux/vs_base.h>
15916 +#include <linux/vserver/global.h>
15917  
15918  #include <asm/unistd.h>
15919  
15920 @@ -72,6 +74,7 @@ static struct ipc_namespace *clone_ipc_n
15921                 goto err_shm;
15922  
15923         kref_init(&ns->kref);
15924 +       atomic_inc(&vs_global_ipc_ns);
15925         return ns;
15926  
15927  err_shm:
15928 @@ -108,6 +111,7 @@ void free_ipc_ns(struct kref *kref)
15929         sem_exit_ns(ns);
15930         msg_exit_ns(ns);
15931         shm_exit_ns(ns);
15932 +       atomic_dec(&vs_global_ipc_ns);
15933         kfree(ns);
15934  }
15935  #else
15936 diff -NurpP --minimal linux-2.6.22.10/kernel/Makefile linux-2.6.22.10-vs2.2.0.5/kernel/Makefile
15937 --- linux-2.6.22.10/kernel/Makefile     2007-07-09 13:20:03 +0200
15938 +++ linux-2.6.22.10-vs2.2.0.5/kernel/Makefile   2007-06-15 02:37:04 +0200
15939 @@ -10,6 +10,8 @@ obj-y     = sched.o fork.o exec_domain.o
15940             kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
15941             hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o
15942  
15943 +obj-y    += vserver/
15944 +
15945  obj-$(CONFIG_STACKTRACE) += stacktrace.o
15946  obj-y += time/
15947  obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
15948 diff -NurpP --minimal linux-2.6.22.10/kernel/capability.c linux-2.6.22.10-vs2.2.0.5/kernel/capability.c
15949 --- linux-2.6.22.10/kernel/capability.c 2007-05-02 19:25:37 +0200
15950 +++ linux-2.6.22.10-vs2.2.0.5/kernel/capability.c       2007-06-15 02:37:04 +0200
15951 @@ -12,6 +12,7 @@
15952  #include <linux/module.h>
15953  #include <linux/security.h>
15954  #include <linux/syscalls.h>
15955 +#include <linux/vs_context.h>
15956  #include <asm/uaccess.h>
15957  
15958  unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
15959 @@ -103,6 +104,8 @@ static inline int cap_set_pg(int pgrp_nr
15960  
15961         pgrp = find_pid(pgrp_nr);
15962         do_each_pid_task(pgrp, PIDTYPE_PGID, g) {
15963 +               if (!vx_check(g->xid, VS_ADMIN_P | VS_IDENT))
15964 +                       continue;
15965                 target = g;
15966                 while_each_thread(g, target) {
15967                         if (!security_capset_check(target, effective,
15968 @@ -246,8 +249,12 @@ int __capable(struct task_struct *t, int
15969  }
15970  EXPORT_SYMBOL(__capable);
15971  
15972 +#include <linux/vserver/base.h>
15973  int capable(int cap)
15974  {
15975 +       /* here for now so we don't require task locking */
15976 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15977 +               return 0;
15978         return __capable(current, cap);
15979  }
15980  EXPORT_SYMBOL(capable);
15981 diff -NurpP --minimal linux-2.6.22.10/kernel/compat.c linux-2.6.22.10-vs2.2.0.5/kernel/compat.c
15982 --- linux-2.6.22.10/kernel/compat.c     2007-07-09 13:20:03 +0200
15983 +++ linux-2.6.22.10-vs2.2.0.5/kernel/compat.c   2007-06-15 02:37:04 +0200
15984 @@ -846,7 +846,7 @@ asmlinkage long compat_sys_time(compat_t
15985         compat_time_t i;
15986         struct timeval tv;
15987  
15988 -       do_gettimeofday(&tv);
15989 +       vx_gettimeofday(&tv);
15990         i = tv.tv_sec;
15991  
15992         if (tloc) {
15993 @@ -870,7 +870,7 @@ asmlinkage long compat_sys_stime(compat_
15994         if (err)
15995                 return err;
15996  
15997 -       do_settimeofday(&tv);
15998 +       vx_settimeofday(&tv);
15999         return 0;
16000  }
16001  
16002 diff -NurpP --minimal linux-2.6.22.10/kernel/exit.c linux-2.6.22.10-vs2.2.0.5/kernel/exit.c
16003 --- linux-2.6.22.10/kernel/exit.c       2007-07-09 13:20:03 +0200
16004 +++ linux-2.6.22.10-vs2.2.0.5/kernel/exit.c     2007-07-17 03:02:15 +0200
16005 @@ -44,6 +44,11 @@
16006  #include <linux/resource.h>
16007  #include <linux/blkdev.h>
16008  #include <linux/task_io_accounting_ops.h>
16009 +#include <linux/vs_limit.h>
16010 +#include <linux/vs_context.h>
16011 +#include <linux/vs_network.h>
16012 +#include <linux/vs_pid.h>
16013 +#include <linux/vserver/global.h>
16014  
16015  #include <asm/uaccess.h>
16016  #include <asm/unistd.h>
16017 @@ -443,9 +448,11 @@ static void close_files(struct files_str
16018                                         filp_close(file, files);
16019                                         cond_resched();
16020                                 }
16021 +                               vx_openfd_dec(i);
16022                         }
16023                         i++;
16024                         set >>= 1;
16025 +                       cond_resched();
16026                 }
16027         }
16028  }
16029 @@ -525,6 +532,7 @@ static inline void __put_fs_struct(struc
16030                         dput(fs->altroot);
16031                         mntput(fs->altrootmnt);
16032                 }
16033 +               atomic_dec(&vs_global_fs);
16034                 kmem_cache_free(fs_cachep, fs);
16035         }
16036  }
16037 @@ -596,6 +604,14 @@ static void exit_mm(struct task_struct *
16038  static inline void
16039  choose_new_parent(struct task_struct *p, struct task_struct *reaper)
16040  {
16041 +       /* check for reaper context */
16042 +       vxwprintk((p->xid != reaper->xid) && (reaper != child_reaper(p)),
16043 +               "rogue reaper: %p[%d,#%u] <> %p[%d,#%u]",
16044 +               p, p->pid, p->xid, reaper, reaper->pid, reaper->xid);
16045 +
16046 +       if (p == reaper)
16047 +               reaper = vx_child_reaper(p);
16048 +
16049         /*
16050          * Make sure we're not reparenting to ourselves and that
16051          * the parent is not a zombie.
16052 @@ -687,7 +703,7 @@ forget_original_parent(struct task_struc
16053         do {
16054                 reaper = next_thread(reaper);
16055                 if (reaper == father) {
16056 -                       reaper = child_reaper(father);
16057 +                       reaper = vx_child_reaper(father);
16058                         break;
16059                 }
16060         } while (reaper->exit_state);
16061 @@ -964,6 +980,8 @@ fastcall NORET_TYPE void do_exit(long co
16062         tsk->exit_code = code;
16063         proc_exit_connector(tsk);
16064         exit_task_namespaces(tsk);
16065 +       /* needs to stay before exit_notify() */
16066 +       exit_vx_info_early(tsk, code);
16067         exit_notify(tsk);
16068  #ifdef CONFIG_NUMA
16069         mpol_free(tsk->mempolicy);
16070 @@ -994,6 +1012,10 @@ fastcall NORET_TYPE void do_exit(long co
16071         if (tsk->splice_pipe)
16072                 __free_pipe_info(tsk->splice_pipe);
16073  
16074 +       /* needs to stay after exit_notify() */
16075 +       exit_vx_info(tsk, code);
16076 +       exit_nx_info(tsk);
16077 +
16078         preempt_disable();
16079         /* causes final put_task_struct in finish_task_switch(). */
16080         tsk->state = TASK_DEAD;
16081 diff -NurpP --minimal linux-2.6.22.10/kernel/fork.c linux-2.6.22.10-vs2.2.0.5/kernel/fork.c
16082 --- linux-2.6.22.10/kernel/fork.c       2007-07-09 13:20:03 +0200
16083 +++ linux-2.6.22.10-vs2.2.0.5/kernel/fork.c     2007-10-29 23:35:00 +0100
16084 @@ -49,6 +49,11 @@
16085  #include <linux/delayacct.h>
16086  #include <linux/taskstats_kern.h>
16087  #include <linux/random.h>
16088 +#include <linux/vs_context.h>
16089 +#include <linux/vs_network.h>
16090 +#include <linux/vs_limit.h>
16091 +#include <linux/vs_memory.h>
16092 +#include <linux/vserver/global.h>
16093  
16094  #include <asm/pgtable.h>
16095  #include <asm/pgalloc.h>
16096 @@ -108,6 +113,8 @@ void free_task(struct task_struct *tsk)
16097  {
16098         free_thread_info(tsk->stack);
16099         rt_mutex_debug_task_free(tsk);
16100 +       clr_vx_info(&tsk->vx_info);
16101 +       clr_nx_info(&tsk->nx_info);
16102         free_task_struct(tsk);
16103  }
16104  EXPORT_SYMBOL(free_task);
16105 @@ -215,6 +222,8 @@ static inline int dup_mmap(struct mm_str
16106         mm->free_area_cache = oldmm->mmap_base;
16107         mm->cached_hole_size = ~0UL;
16108         mm->map_count = 0;
16109 +       __set_mm_counter(mm, file_rss, 0);
16110 +       __set_mm_counter(mm, anon_rss, 0);
16111         cpus_clear(mm->cpu_vm_mask);
16112         mm->mm_rb = RB_ROOT;
16113         rb_link = &mm->mm_rb.rb_node;
16114 @@ -226,7 +235,7 @@ static inline int dup_mmap(struct mm_str
16115  
16116                 if (mpnt->vm_flags & VM_DONTCOPY) {
16117                         long pages = vma_pages(mpnt);
16118 -                       mm->total_vm -= pages;
16119 +                       vx_vmpages_sub(mm, pages);
16120                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
16121                                                                 -pages);
16122                         continue;
16123 @@ -327,7 +336,7 @@ static inline void mm_free_pgd(struct mm
16124  
16125  #include <linux/init_task.h>
16126  
16127 -static struct mm_struct * mm_init(struct mm_struct * mm)
16128 +static struct mm_struct * mm_init(struct mm_struct * mm, struct vx_info *vxi)
16129  {
16130         atomic_set(&mm->mm_users, 1);
16131         atomic_set(&mm->mm_count, 1);
16132 @@ -335,8 +344,8 @@ static struct mm_struct * mm_init(struct
16133         INIT_LIST_HEAD(&mm->mmlist);
16134         mm->core_waiters = 0;
16135         mm->nr_ptes = 0;
16136 -       set_mm_counter(mm, file_rss, 0);
16137 -       set_mm_counter(mm, anon_rss, 0);
16138 +       __set_mm_counter(mm, file_rss, 0);
16139 +       __set_mm_counter(mm, anon_rss, 0);
16140         spin_lock_init(&mm->page_table_lock);
16141         rwlock_init(&mm->ioctx_list_lock);
16142         mm->ioctx_list = NULL;
16143 @@ -345,6 +354,7 @@ static struct mm_struct * mm_init(struct
16144  
16145         if (likely(!mm_alloc_pgd(mm))) {
16146                 mm->def_flags = 0;
16147 +               set_vx_info(&mm->mm_vx_info, vxi);
16148                 return mm;
16149         }
16150         free_mm(mm);
16151 @@ -361,7 +371,7 @@ struct mm_struct * mm_alloc(void)
16152         mm = allocate_mm();
16153         if (mm) {
16154                 memset(mm, 0, sizeof(*mm));
16155 -               mm = mm_init(mm);
16156 +               mm = mm_init(mm, current->vx_info);
16157         }
16158         return mm;
16159  }
16160 @@ -376,6 +386,7 @@ void fastcall __mmdrop(struct mm_struct 
16161         BUG_ON(mm == &init_mm);
16162         mm_free_pgd(mm);
16163         destroy_context(mm);
16164 +       clr_vx_info(&mm->mm_vx_info);
16165         free_mm(mm);
16166  }
16167  
16168 @@ -490,12 +501,13 @@ static struct mm_struct *dup_mm(struct t
16169                 goto fail_nomem;
16170  
16171         memcpy(mm, oldmm, sizeof(*mm));
16172 +       mm->mm_vx_info = NULL;
16173  
16174         /* Initializing for Swap token stuff */
16175         mm->token_priority = 0;
16176         mm->last_interval = 0;
16177  
16178 -       if (!mm_init(mm))
16179 +       if (!mm_init(mm, oldmm->mm_vx_info))
16180                 goto fail_nomem;
16181  
16182         if (init_new_context(tsk, mm))
16183 @@ -521,6 +533,7 @@ fail_nocontext:
16184          * If init_new_context() failed, we cannot use mmput() to free the mm
16185          * because it calls destroy_context()
16186          */
16187 +       clr_vx_info(&mm->mm_vx_info);
16188         mm_free_pgd(mm);
16189         free_mm(mm);
16190         return NULL;
16191 @@ -591,6 +604,7 @@ static inline struct fs_struct *__copy_f
16192                         fs->altroot = NULL;
16193                 }
16194                 read_unlock(&old->lock);
16195 +               atomic_inc(&vs_global_fs);
16196         }
16197         return fs;
16198  }
16199 @@ -709,6 +723,8 @@ static struct files_struct *dup_fd(struc
16200                 struct file *f = *old_fds++;
16201                 if (f) {
16202                         get_file(f);
16203 +                       /* TODO: sum it first for check and performance */
16204 +                       vx_openfd_inc(open_files - i);
16205                 } else {
16206                         /*
16207                          * The fd may be claimed in the fd bitmap but not yet
16208 @@ -961,6 +977,8 @@ static struct task_struct *copy_process(
16209  {
16210         int retval;
16211         struct task_struct *p = NULL;
16212 +       struct vx_info *vxi;
16213 +       struct nx_info *nxi;
16214  
16215         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
16216                 return ERR_PTR(-EINVAL);
16217 @@ -995,12 +1013,30 @@ static struct task_struct *copy_process(
16218         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
16219         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
16220  #endif
16221 +       init_vx_info(&p->vx_info, current->vx_info);
16222 +       init_nx_info(&p->nx_info, current->nx_info);
16223 +
16224 +       /* check vserver memory */
16225 +       if (p->mm && !(clone_flags & CLONE_VM)) {
16226 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
16227 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
16228 +               else
16229 +                       goto bad_fork_free;
16230 +       }
16231 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
16232 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
16233 +                       goto bad_fork_cleanup_vm;
16234 +       }
16235 +
16236         retval = -EAGAIN;
16237 +       if (!vx_nproc_avail(1))
16238 +               goto bad_fork_cleanup_vm;
16239 +
16240         if (atomic_read(&p->user->processes) >=
16241                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
16242                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
16243                                 p->user != &root_user)
16244 -                       goto bad_fork_free;
16245 +                       goto bad_fork_cleanup_vm;
16246         }
16247  
16248         atomic_inc(&p->user->__count);
16249 @@ -1265,6 +1301,18 @@ static struct task_struct *copy_process(
16250  
16251         total_forks++;
16252         spin_unlock(&current->sighand->siglock);
16253 +
16254 +       /* p is copy of current */
16255 +       vxi = p->vx_info;
16256 +       if (vxi) {
16257 +               claim_vx_info(vxi, p);
16258 +               atomic_inc(&vxi->cvirt.nr_threads);
16259 +               atomic_inc(&vxi->cvirt.total_forks);
16260 +               vx_nproc_inc(p);
16261 +       }
16262 +       nxi = p->nx_info;
16263 +       if (nxi)
16264 +               claim_nx_info(nxi, p);
16265         write_unlock_irq(&tasklist_lock);
16266         proc_fork_connector(p);
16267         return p;
16268 @@ -1306,6 +1354,9 @@ bad_fork_cleanup_count:
16269         put_group_info(p->group_info);
16270         atomic_dec(&p->user->processes);
16271         free_uid(p->user);
16272 +bad_fork_cleanup_vm:
16273 +       if (p->mm && !(clone_flags & CLONE_VM))
16274 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
16275  bad_fork_free:
16276         free_task(p);
16277  fork_out:
16278 @@ -1367,6 +1418,14 @@ long do_fork(unsigned long clone_flags,
16279  
16280         if (!pid)
16281                 return -EAGAIN;
16282 +
16283 +       /* kernel threads are host only */
16284 +       if ((clone_flags & CLONE_KTHREAD) && !vx_check(0, VS_ADMIN)) {
16285 +               vxwprintk_task(1, "tried to spawn a kernel thread.");
16286 +               free_pid(pid);
16287 +               return -EPERM;
16288 +       }
16289 +
16290         nr = pid->nr;
16291         if (unlikely(current->ptrace)) {
16292                 trace = fork_traceflag (clone_flags);
16293 diff -NurpP --minimal linux-2.6.22.10/kernel/kthread.c linux-2.6.22.10-vs2.2.0.5/kernel/kthread.c
16294 --- linux-2.6.22.10/kernel/kthread.c    2007-07-09 13:20:03 +0200
16295 +++ linux-2.6.22.10-vs2.2.0.5/kernel/kthread.c  2007-06-15 02:37:04 +0200
16296 @@ -96,7 +96,7 @@ static void create_kthread(struct kthrea
16297         } else {
16298                 wait_for_completion(&create->started);
16299                 read_lock(&tasklist_lock);
16300 -               create->result = find_task_by_pid(pid);
16301 +               create->result = find_task_by_real_pid(pid);
16302                 read_unlock(&tasklist_lock);
16303         }
16304         complete(&create->done);
16305 diff -NurpP --minimal linux-2.6.22.10/kernel/nsproxy.c linux-2.6.22.10-vs2.2.0.5/kernel/nsproxy.c
16306 --- linux-2.6.22.10/kernel/nsproxy.c    2007-07-09 13:20:03 +0200
16307 +++ linux-2.6.22.10-vs2.2.0.5/kernel/nsproxy.c  2007-07-07 04:12:31 +0200
16308 @@ -20,14 +20,11 @@
16309  #include <linux/mnt_namespace.h>
16310  #include <linux/utsname.h>
16311  #include <linux/pid_namespace.h>
16312 +#include <linux/vserver/global.h>
16313 +#include <linux/vserver/debug.h>
16314  
16315  struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
16316  
16317 -static inline void get_nsproxy(struct nsproxy *ns)
16318 -{
16319 -       atomic_inc(&ns->count);
16320 -}
16321 -
16322  void get_task_namespaces(struct task_struct *tsk)
16323  {
16324         struct nsproxy *ns = tsk->nsproxy;
16325 @@ -46,6 +43,9 @@ static inline struct nsproxy *clone_nspr
16326         ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
16327         if (ns)
16328                 atomic_set(&ns->count, 1);
16329 +       vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
16330 +               orig, atomic_read(&orig->count), ns);
16331 +       atomic_inc(&vs_global_nsproxy);
16332         return ns;
16333  }
16334  
16335 @@ -54,28 +54,32 @@ static inline struct nsproxy *clone_nspr
16336   * Return the newly created nsproxy.  Do not attach this to the task,
16337   * leave it to the caller to do proper locking and attach it to task.
16338   */
16339 -static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
16340 +static struct nsproxy *unshare_namespaces(int flags, struct nsproxy *orig,
16341                         struct fs_struct *new_fs)
16342  {
16343         struct nsproxy *new_nsp;
16344  
16345 -       new_nsp = clone_nsproxy(tsk->nsproxy);
16346 +       vxdprintk(VXD_CBIT(space, 4),
16347 +               "unshare_namespaces(0x%08x,%p,%p)",
16348 +               flags, orig, new_fs);
16349 +
16350 +       new_nsp = clone_nsproxy(orig);
16351         if (!new_nsp)
16352                 return ERR_PTR(-ENOMEM);
16353  
16354 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
16355 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
16356         if (IS_ERR(new_nsp->mnt_ns))
16357                 goto out_ns;
16358  
16359 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
16360 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
16361         if (IS_ERR(new_nsp->uts_ns))
16362                 goto out_uts;
16363  
16364 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
16365 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
16366         if (IS_ERR(new_nsp->ipc_ns))
16367                 goto out_ipc;
16368  
16369 -       new_nsp->pid_ns = copy_pid_ns(flags, tsk->nsproxy->pid_ns);
16370 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
16371         if (IS_ERR(new_nsp->pid_ns))
16372                 goto out_pid;
16373  
16374 @@ -95,6 +99,33 @@ out_ns:
16375         return ERR_PTR(-ENOMEM);
16376  }
16377  
16378 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
16379 +                       struct fs_struct *new_fs)
16380 +{
16381 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
16382 +}
16383 +
16384 +/*
16385 + * copies the nsproxy, setting refcount to 1, and grabbing a
16386 + * reference to all contained namespaces.
16387 + */
16388 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
16389 +{
16390 +       struct nsproxy *ns = clone_nsproxy(orig);
16391 +
16392 +       if (ns) {
16393 +               if (ns->mnt_ns)
16394 +                       get_mnt_ns(ns->mnt_ns);
16395 +               if (ns->uts_ns)
16396 +                       get_uts_ns(ns->uts_ns);
16397 +               if (ns->ipc_ns)
16398 +                       get_ipc_ns(ns->ipc_ns);
16399 +               if (ns->pid_ns)
16400 +                       get_pid_ns(ns->pid_ns);
16401 +       }
16402 +       return ns;
16403 +}
16404 +
16405  /*
16406   * called from clone.  This now handles copy for nsproxy and all
16407   * namespaces therein.
16408 @@ -102,9 +133,12 @@ out_ns:
16409  int copy_namespaces(int flags, struct task_struct *tsk)
16410  {
16411         struct nsproxy *old_ns = tsk->nsproxy;
16412 -       struct nsproxy *new_ns;
16413 +       struct nsproxy *new_ns = NULL;
16414         int err = 0;
16415  
16416 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08x,%p[%p])",
16417 +               flags, tsk, old_ns);
16418 +
16419         if (!old_ns)
16420                 return 0;
16421  
16422 @@ -127,6 +161,9 @@ int copy_namespaces(int flags, struct ta
16423         tsk->nsproxy = new_ns;
16424  out:
16425         put_nsproxy(old_ns);
16426 +       vxdprintk(VXD_CBIT(space, 3),
16427 +               "copy_namespaces(0x%08x,%p[%p]) = %d [%p]",
16428 +               flags, tsk, old_ns, err, new_ns);
16429         return err;
16430  }
16431  
16432 @@ -140,6 +177,7 @@ void free_nsproxy(struct nsproxy *ns)
16433                 put_ipc_ns(ns->ipc_ns);
16434         if (ns->pid_ns)
16435                 put_pid_ns(ns->pid_ns);
16436 +       atomic_dec(&vs_global_nsproxy);
16437         kfree(ns);
16438  }
16439  
16440 @@ -152,6 +190,10 @@ int unshare_nsproxy_namespaces(unsigned 
16441  {
16442         int err = 0;
16443  
16444 +       vxdprintk(VXD_CBIT(space, 4),
16445 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
16446 +               unshare_flags, current->nsproxy);
16447 +
16448         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC)))
16449                 return 0;
16450  
16451 diff -NurpP --minimal linux-2.6.22.10/kernel/pid.c linux-2.6.22.10-vs2.2.0.5/kernel/pid.c
16452 --- linux-2.6.22.10/kernel/pid.c        2007-07-09 13:20:03 +0200
16453 +++ linux-2.6.22.10-vs2.2.0.5/kernel/pid.c      2007-06-15 04:04:09 +0200
16454 @@ -28,6 +28,7 @@
16455  #include <linux/hash.h>
16456  #include <linux/pid_namespace.h>
16457  #include <linux/init_task.h>
16458 +#include <linux/vs_pid.h>
16459  
16460  #define pid_hashfn(nr) hash_long((unsigned long)nr, pidhash_shift)
16461  static struct hlist_head *pid_hash;
16462 @@ -295,6 +296,9 @@ void fastcall transfer_pid(struct task_s
16463  struct task_struct * fastcall pid_task(struct pid *pid, enum pid_type type)
16464  {
16465         struct task_struct *result = NULL;
16466 +
16467 +       if (type == PIDTYPE_REALPID)
16468 +               type = PIDTYPE_PID;
16469         if (pid) {
16470                 struct hlist_node *first;
16471                 first = rcu_dereference(pid->tasks[type].first);
16472 @@ -309,7 +313,17 @@ struct task_struct * fastcall pid_task(s
16473   */
16474  struct task_struct *find_task_by_pid_type(int type, int nr)
16475  {
16476 -       return pid_task(find_pid(nr), type);
16477 +       struct task_struct *task;
16478 +
16479 +       if (type == PIDTYPE_PID)
16480 +               nr = vx_rmap_pid(nr);
16481 +
16482 +       task = pid_task(find_pid(nr), type);
16483 +       if (task && (type != PIDTYPE_REALPID) &&
16484 +               /* maybe VS_WATCH_P in the future? */
16485 +               !vx_check(task->xid, VS_WATCH|VS_IDENT))
16486 +               return NULL;
16487 +       return task;
16488  }
16489  
16490  EXPORT_SYMBOL(find_task_by_pid_type);
16491 diff -NurpP --minimal linux-2.6.22.10/kernel/posix-timers.c linux-2.6.22.10-vs2.2.0.5/kernel/posix-timers.c
16492 --- linux-2.6.22.10/kernel/posix-timers.c       2007-07-09 13:20:03 +0200
16493 +++ linux-2.6.22.10-vs2.2.0.5/kernel/posix-timers.c     2007-10-11 14:14:00 +0200
16494 @@ -47,6 +47,7 @@
16495  #include <linux/wait.h>
16496  #include <linux/workqueue.h>
16497  #include <linux/module.h>
16498 +#include <linux/vs_context.h>
16499  
16500  /*
16501   * Management arrays for POSIX timers.  Timers are kept in slab memory
16502 @@ -297,6 +298,12 @@ void do_schedule_next_timer(struct sigin
16503  
16504  int posix_timer_event(struct k_itimer *timr,int si_private)
16505  {
16506 +       struct vx_info_save vxis;
16507 +       struct vx_info *vxi;
16508 +       int ret;
16509 +
16510 +       vxi = task_get_vx_info(timr->it_process);
16511 +       enter_vx_info(vxi, &vxis);
16512         memset(&timr->sigq->info, 0, sizeof(siginfo_t));
16513         timr->sigq->info.si_sys_private = si_private;
16514         /* Send signal to the process that owns this timer.*/
16515 @@ -309,11 +316,11 @@ int posix_timer_event(struct k_itimer *t
16516  
16517         if (timr->it_sigev_notify & SIGEV_THREAD_ID) {
16518                 struct task_struct *leader;
16519 -               int ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
16520 -                                       timr->it_process);
16521  
16522 +               ret = send_sigqueue(timr->it_sigev_signo, timr->sigq,
16523 +                                   timr->it_process);
16524                 if (likely(ret >= 0))
16525 -                       return ret;
16526 +                       goto out;
16527  
16528                 timr->it_sigev_notify = SIGEV_SIGNAL;
16529                 leader = timr->it_process->group_leader;
16530 @@ -321,8 +328,12 @@ int posix_timer_event(struct k_itimer *t
16531                 timr->it_process = leader;
16532         }
16533  
16534 -       return send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
16535 +       ret = send_group_sigqueue(timr->it_sigev_signo, timr->sigq,
16536                                    timr->it_process);
16537 +out:
16538 +       leave_vx_info(&vxis);
16539 +       put_vx_info(vxi);
16540 +       return ret;
16541  }
16542  EXPORT_SYMBOL_GPL(posix_timer_event);
16543  
16544 @@ -402,7 +413,7 @@ static struct task_struct * good_sigeven
16545         struct task_struct *rtn = current->group_leader;
16546  
16547         if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
16548 -               (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
16549 +               (!(rtn = find_task_by_real_pid(event->sigev_notify_thread_id)) ||
16550                  rtn->tgid != current->tgid ||
16551                  (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
16552                 return NULL;
16553 diff -NurpP --minimal linux-2.6.22.10/kernel/printk.c linux-2.6.22.10-vs2.2.0.5/kernel/printk.c
16554 --- linux-2.6.22.10/kernel/printk.c     2007-07-09 13:20:03 +0200
16555 +++ linux-2.6.22.10-vs2.2.0.5/kernel/printk.c   2007-06-15 02:37:04 +0200
16556 @@ -31,6 +31,7 @@
16557  #include <linux/bootmem.h>
16558  #include <linux/syscalls.h>
16559  #include <linux/jiffies.h>
16560 +#include <linux/vs_cvirt.h>
16561  
16562  #include <asm/uaccess.h>
16563  
16564 @@ -182,18 +183,13 @@ int do_syslog(int type, char __user *buf
16565         unsigned long i, j, limit, count;
16566         int do_clear = 0;
16567         char c;
16568 -       int error = 0;
16569 +       int error;
16570  
16571         error = security_syslog(type);
16572         if (error)
16573                 return error;
16574  
16575 -       switch (type) {
16576 -       case 0:         /* Close log */
16577 -               break;
16578 -       case 1:         /* Open log */
16579 -               break;
16580 -       case 2:         /* Read from log */
16581 +       if ((type >= 2) && (type <= 4)) {
16582                 error = -EINVAL;
16583                 if (!buf || len < 0)
16584                         goto out;
16585 @@ -204,6 +200,16 @@ int do_syslog(int type, char __user *buf
16586                         error = -EFAULT;
16587                         goto out;
16588                 }
16589 +       }
16590 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16591 +               return vx_do_syslog(type, buf, len);
16592 +
16593 +       switch (type) {
16594 +       case 0:         /* Close log */
16595 +               break;
16596 +       case 1:         /* Open log */
16597 +               break;
16598 +       case 2:         /* Read from log */
16599                 error = wait_event_interruptible(log_wait,
16600                                                         (log_start - log_end));
16601                 if (error)
16602 @@ -228,16 +234,6 @@ int do_syslog(int type, char __user *buf
16603                 do_clear = 1;
16604                 /* FALL THRU */
16605         case 3:         /* Read last kernel messages */
16606 -               error = -EINVAL;
16607 -               if (!buf || len < 0)
16608 -                       goto out;
16609 -               error = 0;
16610 -               if (!len)
16611 -                       goto out;
16612 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
16613 -                       error = -EFAULT;
16614 -                       goto out;
16615 -               }
16616                 count = len;
16617                 if (count > log_buf_len)
16618                         count = log_buf_len;
16619 diff -NurpP --minimal linux-2.6.22.10/kernel/ptrace.c linux-2.6.22.10-vs2.2.0.5/kernel/ptrace.c
16620 --- linux-2.6.22.10/kernel/ptrace.c     2007-07-09 13:20:03 +0200
16621 +++ linux-2.6.22.10-vs2.2.0.5/kernel/ptrace.c   2007-06-15 04:28:02 +0200
16622 @@ -19,6 +19,7 @@
16623  #include <linux/security.h>
16624  #include <linux/signal.h>
16625  #include <linux/audit.h>
16626 +#include <linux/vs_context.h>
16627  
16628  #include <asm/pgtable.h>
16629  #include <asm/uaccess.h>
16630 @@ -145,6 +146,11 @@ static int may_attach(struct task_struct
16631                 dumpable = task->mm->dumpable;
16632         if (!dumpable && !capable(CAP_SYS_PTRACE))
16633                 return -EPERM;
16634 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
16635 +               return -EPERM;
16636 +       if (!vx_check(task->xid, VS_IDENT) &&
16637 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
16638 +               return -EACCES;
16639  
16640         return security_ptrace(current, task);
16641  }
16642 @@ -471,6 +477,10 @@ asmlinkage long sys_ptrace(long request,
16643                 goto out;
16644         }
16645  
16646 +       ret = -EPERM;
16647 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
16648 +               goto out_put_task_struct;
16649 +
16650         if (request == PTRACE_ATTACH) {
16651                 ret = ptrace_attach(child);
16652                 goto out_put_task_struct;
16653 diff -NurpP --minimal linux-2.6.22.10/kernel/sched.c linux-2.6.22.10-vs2.2.0.5/kernel/sched.c
16654 --- linux-2.6.22.10/kernel/sched.c      2007-07-09 13:20:03 +0200
16655 +++ linux-2.6.22.10-vs2.2.0.5/kernel/sched.c    2007-07-07 03:52:54 +0200
16656 @@ -56,6 +56,8 @@
16657  
16658  #include <asm/tlb.h>
16659  #include <asm/unistd.h>
16660 +#include <linux/vs_sched.h>
16661 +#include <linux/vs_cvirt.h>
16662  
16663  /*
16664   * Scheduler clock - returns current time in nanosec units.
16665 @@ -281,6 +283,16 @@ struct rq {
16666         struct task_struct *migration_thread;
16667         struct list_head migration_queue;
16668  #endif
16669 +       unsigned long norm_time;
16670 +       unsigned long idle_time;
16671 +#ifdef CONFIG_VSERVER_IDLETIME
16672 +       int idle_skip;
16673 +#endif
16674 +#ifdef CONFIG_VSERVER_HARDCPU
16675 +       struct list_head hold_queue;
16676 +       unsigned long nr_onhold;
16677 +       int idle_tokens;
16678 +#endif
16679  
16680  #ifdef CONFIG_SCHEDSTATS
16681         /* latency stats */
16682 @@ -714,6 +726,7 @@ sched_info_switch(struct task_struct *pr
16683   */
16684  static void dequeue_task(struct task_struct *p, struct prio_array *array)
16685  {
16686 +       BUG_ON(p->state & TASK_ONHOLD);
16687         array->nr_active--;
16688         list_del(&p->run_list);
16689         if (list_empty(array->queue + p->prio))
16690 @@ -722,6 +735,7 @@ static void dequeue_task(struct task_str
16691  
16692  static void enqueue_task(struct task_struct *p, struct prio_array *array)
16693  {
16694 +       BUG_ON(p->state & TASK_ONHOLD);
16695         sched_info_queued(p);
16696         list_add_tail(&p->run_list, array->queue + p->prio);
16697         __set_bit(p->prio, array->bitmap);
16698 @@ -735,12 +749,14 @@ static void enqueue_task(struct task_str
16699   */
16700  static void requeue_task(struct task_struct *p, struct prio_array *array)
16701  {
16702 +       BUG_ON(p->state & TASK_ONHOLD);
16703         list_move_tail(&p->run_list, array->queue + p->prio);
16704  }
16705  
16706  static inline void
16707  enqueue_task_head(struct task_struct *p, struct prio_array *array)
16708  {
16709 +       BUG_ON(p->state & TASK_ONHOLD);
16710         list_add(&p->run_list, array->queue + p->prio);
16711         __set_bit(p->prio, array->bitmap);
16712         array->nr_active++;
16713 @@ -769,6 +785,10 @@ static inline int __normal_prio(struct t
16714         bonus = CURRENT_BONUS(p) - MAX_BONUS / 2;
16715  
16716         prio = p->static_prio - bonus;
16717 +
16718 +       /* adjust effective priority */
16719 +       prio = vx_adjust_prio(p, prio, MAX_USER_PRIO);
16720 +
16721         if (prio < MAX_RT_PRIO)
16722                 prio = MAX_RT_PRIO;
16723         if (prio > MAX_PRIO-1)
16724 @@ -878,6 +898,9 @@ static int effective_prio(struct task_st
16725         return p->prio;
16726  }
16727  
16728 +#include "sched_mon.h"
16729 +
16730 +
16731  /*
16732   * __activate_task - move a task to the runqueue.
16733   */
16734 @@ -887,6 +910,7 @@ static void __activate_task(struct task_
16735  
16736         if (batch_task(p))
16737                 target = rq->expired;
16738 +       vxm_activate_task(p, rq);
16739         enqueue_task(p, target);
16740         inc_nr_running(p, rq);
16741  }
16742 @@ -896,6 +920,7 @@ static void __activate_task(struct task_
16743   */
16744  static inline void __activate_idle_task(struct task_struct *p, struct rq *rq)
16745  {
16746 +       vxm_activate_idle(p, rq);
16747         enqueue_task_head(p, rq->active);
16748         inc_nr_running(p, rq);
16749  }
16750 @@ -1030,19 +1055,30 @@ static void activate_task(struct task_st
16751         }
16752         p->timestamp = now;
16753  out:
16754 +       vx_activate_task(p);
16755         __activate_task(p, rq);
16756  }
16757  
16758  /*
16759 - * deactivate_task - remove a task from the runqueue.
16760 + * __deactivate_task - remove a task from the runqueue.
16761   */
16762 -static void deactivate_task(struct task_struct *p, struct rq *rq)
16763 +static void __deactivate_task(struct task_struct *p, struct rq *rq)
16764  {
16765         dec_nr_running(p, rq);
16766         dequeue_task(p, p->array);
16767 +       vxm_deactivate_task(p, rq);
16768         p->array = NULL;
16769  }
16770  
16771 +static inline
16772 +void deactivate_task(struct task_struct *p, struct rq *rq)
16773 +{
16774 +       vx_deactivate_task(p);
16775 +       __deactivate_task(p, rq);
16776 +}
16777 +
16778 +#include "sched_hard.h"
16779 +
16780  /*
16781   * resched_task - mark a task 'to be rescheduled now'.
16782   *
16783 @@ -1129,6 +1165,7 @@ migrate_task(struct task_struct *p, int 
16784  {
16785         struct rq *rq = task_rq(p);
16786  
16787 +       vxm_migrate_task(p, rq, dest_cpu);
16788         /*
16789          * If the task is not on a runqueue (and not running), then
16790          * it is sufficient to simply update the task's cpu field.
16791 @@ -1518,6 +1555,12 @@ static int try_to_wake_up(struct task_st
16792  
16793         rq = task_rq_lock(p, &flags);
16794         old_state = p->state;
16795 +
16796 +       /* we need to unhold suspended tasks */
16797 +       if (old_state & TASK_ONHOLD) {
16798 +               vx_unhold_task(p, rq);
16799 +               old_state = p->state;
16800 +       }
16801         if (!(old_state & state))
16802                 goto out;
16803  
16804 @@ -1625,6 +1668,7 @@ out_activate:
16805  #endif /* CONFIG_SMP */
16806         if (old_state == TASK_UNINTERRUPTIBLE) {
16807                 rq->nr_uninterruptible--;
16808 +               vx_uninterruptible_dec(p);
16809                 /*
16810                  * Tasks on involuntary sleep don't earn
16811                  * sleep_avg beyond just interactive state.
16812 @@ -1676,7 +1720,7 @@ int fastcall wake_up_state(struct task_s
16813         return try_to_wake_up(p, state, 0);
16814  }
16815  
16816 -static void task_running_tick(struct rq *rq, struct task_struct *p);
16817 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu);
16818  /*
16819   * Perform scheduler related setup for a newly forked process p.
16820   * p is forked by current.
16821 @@ -1737,7 +1781,7 @@ void fastcall sched_fork(struct task_str
16822                  * runqueue lock is not a problem.
16823                  */
16824                 current->time_slice = 1;
16825 -               task_running_tick(cpu_rq(cpu), current);
16826 +               task_running_tick(cpu_rq(cpu), current, cpu);
16827         }
16828         local_irq_enable();
16829         put_cpu();
16830 @@ -1772,6 +1816,7 @@ void fastcall wake_up_new_task(struct ta
16831  
16832         p->prio = effective_prio(p);
16833  
16834 +       vx_activate_task(p);
16835         if (likely(cpu == this_cpu)) {
16836                 if (!(clone_flags & CLONE_VM)) {
16837                         /*
16838 @@ -1783,6 +1828,7 @@ void fastcall wake_up_new_task(struct ta
16839                                 __activate_task(p, rq);
16840                         else {
16841                                 p->prio = current->prio;
16842 +                               BUG_ON(p->state & TASK_ONHOLD);
16843                                 p->normal_prio = current->normal_prio;
16844                                 list_add_tail(&p->run_list, &current->run_list);
16845                                 p->array = current->array;
16846 @@ -3351,13 +3397,16 @@ static inline int expired_starving(struc
16847  void account_user_time(struct task_struct *p, cputime_t cputime)
16848  {
16849         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16850 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16851         cputime64_t tmp;
16852 +       int nice = (TASK_NICE(p) > 0);
16853  
16854         p->utime = cputime_add(p->utime, cputime);
16855 +       vx_account_user(vxi, cputime, nice);
16856  
16857         /* Add user time to cpustat. */
16858         tmp = cputime_to_cputime64(cputime);
16859 -       if (TASK_NICE(p) > 0)
16860 +       if (nice)
16861                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16862         else
16863                 cpustat->user = cputime64_add(cpustat->user, tmp);
16864 @@ -3373,10 +3422,12 @@ void account_system_time(struct task_str
16865                          cputime_t cputime)
16866  {
16867         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16868 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16869         struct rq *rq = this_rq();
16870         cputime64_t tmp;
16871  
16872         p->stime = cputime_add(p->stime, cputime);
16873 +       vx_account_system(vxi, cputime, (p == rq->idle));
16874  
16875         /* Add system time to cpustat. */
16876         tmp = cputime_to_cputime64(cputime);
16877 @@ -3415,7 +3466,7 @@ void account_steal_time(struct task_stru
16878                 cpustat->steal = cputime64_add(cpustat->steal, tmp);
16879  }
16880  
16881 -static void task_running_tick(struct rq *rq, struct task_struct *p)
16882 +static void task_running_tick(struct rq *rq, struct task_struct *p, int cpu)
16883  {
16884         if (p->array != rq->active) {
16885                 /* Task has expired but was not scheduled yet */
16886 @@ -3445,7 +3496,7 @@ static void task_running_tick(struct rq 
16887                 }
16888                 goto out_unlock;
16889         }
16890 -       if (!--p->time_slice) {
16891 +       if (vx_need_resched(p, --p->time_slice, cpu)) {
16892                 dequeue_task(p, rq->active);
16893                 set_tsk_need_resched(p);
16894                 p->prio = effective_prio(p);
16895 @@ -3506,9 +3557,12 @@ void scheduler_tick(void)
16896         struct rq *rq = cpu_rq(cpu);
16897  
16898         update_cpu_clock(p, rq, now);
16899 -
16900 -       if (!idle_at_tick)
16901 -               task_running_tick(rq, p);
16902 +       vxm_sync(now, cpu);
16903 +
16904 +       if (idle_at_tick)
16905 +               vx_idle_resched(rq);
16906 +       else
16907 +               task_running_tick(rq, p, cpu);
16908  #ifdef CONFIG_SMP
16909         update_load(rq);
16910         rq->idle_at_tick = idle_at_tick;
16911 @@ -3630,14 +3684,25 @@ need_resched_nonpreemptible:
16912                                 unlikely(signal_pending(prev))))
16913                         prev->state = TASK_RUNNING;
16914                 else {
16915 -                       if (prev->state == TASK_UNINTERRUPTIBLE)
16916 +                       if (prev->state == TASK_UNINTERRUPTIBLE) {
16917                                 rq->nr_uninterruptible++;
16918 +                               vx_uninterruptible_inc(prev);
16919 +                       }
16920                         deactivate_task(prev, rq);
16921                 }
16922         }
16923  
16924         cpu = smp_processor_id();
16925 +       vx_set_rq_time(rq, jiffies);
16926 +try_unhold:
16927 +       vx_try_unhold(rq, cpu);
16928 +pick_next:
16929 +
16930         if (unlikely(!rq->nr_running)) {
16931 +               /* can we skip idle time? */
16932 +               if (vx_try_skip(rq, cpu))
16933 +                       goto try_unhold;
16934 +
16935                 idle_balance(cpu, rq);
16936                 if (!rq->nr_running) {
16937                         next = rq->idle;
16938 @@ -3663,6 +3728,10 @@ need_resched_nonpreemptible:
16939         queue = array->queue + idx;
16940         next = list_entry(queue->next, struct task_struct, run_list);
16941  
16942 +       /* check before we schedule this context */
16943 +       if (!vx_schedule(next, rq, cpu))
16944 +               goto pick_next;
16945 +
16946         if (!rt_task(next) && interactive_sleep(next->sleep_type)) {
16947                 unsigned long long delta = now - next->timestamp;
16948                 if (unlikely((long long)(now - next->timestamp) < 0))
16949 @@ -4263,7 +4332,7 @@ asmlinkage long sys_nice(int increment)
16950                 nice = 19;
16951  
16952         if (increment < 0 && !can_nice(current, nice))
16953 -               return -EPERM;
16954 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16955  
16956         retval = security_task_setnice(current, nice);
16957         if (retval)
16958 @@ -4435,6 +4504,7 @@ recheck:
16959         oldprio = p->prio;
16960         __setscheduler(p, policy, param->sched_priority);
16961         if (array) {
16962 +               vx_activate_task(p);
16963                 __activate_task(p, rq);
16964                 /*
16965                  * Reschedule if we are currently running on this runqueue and
16966 @@ -5188,6 +5258,7 @@ static int __migrate_task(struct task_st
16967                 p->timestamp = p->timestamp - rq_src->most_recent_timestamp
16968                                 + rq_dest->most_recent_timestamp;
16969                 deactivate_task(p, rq_src);
16970 +               vx_activate_task(p);
16971                 __activate_task(p, rq_dest);
16972                 if (TASK_PREEMPTS_CURR(p, rq_dest))
16973                         resched_task(rq_dest->curr);
16974 @@ -7058,7 +7129,10 @@ void __init sched_init(void)
16975                 INIT_LIST_HEAD(&rq->migration_queue);
16976  #endif
16977                 atomic_set(&rq->nr_iowait, 0);
16978 -
16979 +#ifdef CONFIG_VSERVER_HARDCPU
16980 +               INIT_LIST_HEAD(&rq->hold_queue);
16981 +               rq->nr_onhold = 0;
16982 +#endif
16983                 for (j = 0; j < 2; j++) {
16984                         array = rq->arrays + j;
16985                         for (k = 0; k < MAX_PRIO; k++) {
16986 @@ -7144,6 +7218,7 @@ void normalize_rt_tasks(void)
16987                         deactivate_task(p, task_rq(p));
16988                 __setscheduler(p, SCHED_NORMAL, 0);
16989                 if (array) {
16990 +                       vx_activate_task(p);
16991                         __activate_task(p, task_rq(p));
16992                         resched_task(rq->curr);
16993                 }
16994 diff -NurpP --minimal linux-2.6.22.10/kernel/sched_hard.h linux-2.6.22.10-vs2.2.0.5/kernel/sched_hard.h
16995 --- linux-2.6.22.10/kernel/sched_hard.h 1970-01-01 01:00:00 +0100
16996 +++ linux-2.6.22.10-vs2.2.0.5/kernel/sched_hard.h       2007-06-15 19:20:10 +0200
16997 @@ -0,0 +1,324 @@
16998 +
16999 +#ifdef CONFIG_VSERVER_IDLELIMIT
17000 +
17001 +/*
17002 + * vx_idle_resched - reschedule after maxidle
17003 + */
17004 +static inline
17005 +void vx_idle_resched(struct rq *rq)
17006 +{
17007 +       /* maybe have a better criterion for paused */
17008 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
17009 +               set_need_resched();
17010 +}
17011 +
17012 +#else /* !CONFIG_VSERVER_IDLELIMIT */
17013 +
17014 +#define vx_idle_resched(rq)
17015 +
17016 +#endif /* CONFIG_VSERVER_IDLELIMIT */
17017 +
17018 +
17019 +
17020 +#ifdef CONFIG_VSERVER_IDLETIME
17021 +
17022 +#define vx_set_rq_min_skip(rq, min)            \
17023 +       (rq)->idle_skip = (min)
17024 +
17025 +#define vx_save_min_skip(ret, min, val)                \
17026 +       __vx_save_min_skip(ret, min, val)
17027 +
17028 +static inline
17029 +void __vx_save_min_skip(int ret, int *min, int val)
17030 +{
17031 +       if (ret > -2)
17032 +               return;
17033 +       if ((*min > val) || !*min)
17034 +               *min = val;
17035 +}
17036 +
17037 +static inline
17038 +int vx_try_skip(struct rq *rq, int cpu)
17039 +{
17040 +       /* artificially advance time */
17041 +       if (rq->idle_skip > 0) {
17042 +               vxdprintk(list_empty(&rq->hold_queue),
17043 +                       "hold queue empty on cpu %d", cpu);
17044 +               rq->idle_time += rq->idle_skip;
17045 +               vxm_idle_skip(rq, cpu);
17046 +               return 1;
17047 +       }
17048 +       return 0;
17049 +}
17050 +
17051 +#else /* !CONFIG_VSERVER_IDLETIME */
17052 +
17053 +#define vx_set_rq_min_skip(rq, min)            \
17054 +       ({ int dummy = (min); dummy; })
17055 +
17056 +#define vx_save_min_skip(ret, min, val)
17057 +
17058 +static inline
17059 +int vx_try_skip(struct rq *rq, int cpu)
17060 +{
17061 +       return 0;
17062 +}
17063 +
17064 +#endif /* CONFIG_VSERVER_IDLETIME */
17065 +
17066 +
17067 +
17068 +#ifdef CONFIG_VSERVER_HARDCPU
17069 +
17070 +#define vx_set_rq_max_idle(rq, max)            \
17071 +       (rq)->idle_tokens = (max)
17072 +
17073 +#define vx_save_max_idle(ret, min, val)                \
17074 +       __vx_save_max_idle(ret, min, val)
17075 +
17076 +static inline
17077 +void __vx_save_max_idle(int ret, int *min, int val)
17078 +{
17079 +       if (*min > val)
17080 +               *min = val;
17081 +}
17082 +
17083 +
17084 +/*
17085 + * vx_hold_task - put a task on the hold queue
17086 + */
17087 +static inline
17088 +void vx_hold_task(struct task_struct *p, struct rq *rq)
17089 +{
17090 +       __deactivate_task(p, rq);
17091 +       p->state |= TASK_ONHOLD;
17092 +       /* a new one on hold */
17093 +       rq->nr_onhold++;
17094 +       vxm_hold_task(p, rq);
17095 +       list_add_tail(&p->run_list, &rq->hold_queue);
17096 +}
17097 +
17098 +/*
17099 + * vx_unhold_task - put a task back to the runqueue
17100 + */
17101 +static inline
17102 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
17103 +{
17104 +       list_del(&p->run_list);
17105 +       /* one less waiting */
17106 +       rq->nr_onhold--;
17107 +       p->state &= ~TASK_ONHOLD;
17108 +       enqueue_task(p, rq->expired);
17109 +       inc_nr_running(p, rq);
17110 +       vxm_unhold_task(p, rq);
17111 +
17112 +       if (p->static_prio < rq->best_expired_prio)
17113 +               rq->best_expired_prio = p->static_prio;
17114 +}
17115 +
17116 +unsigned long nr_onhold(void)
17117 +{
17118 +       unsigned long i, sum = 0;
17119 +
17120 +       for_each_online_cpu(i)
17121 +               sum += cpu_rq(i)->nr_onhold;
17122 +
17123 +       return sum;
17124 +}
17125 +
17126 +
17127 +
17128 +static inline
17129 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
17130 +{
17131 +       return sched_pc->tokens;
17132 +}
17133 +
17134 +static inline
17135 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
17136 +{
17137 +       sched_pc->tokens--;
17138 +}
17139 +
17140 +static inline
17141 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
17142 +{
17143 +       struct vx_info *vxi = p->vx_info;
17144 +
17145 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
17146 +               struct _vx_sched_pc *sched_pc =
17147 +                       &vx_per_cpu(vxi, sched_pc, cpu);
17148 +               int tokens;
17149 +
17150 +               /* maybe we can simplify that to decrement
17151 +                  the token counter unconditional? */
17152 +
17153 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
17154 +                       __vx_consume_token(sched_pc);
17155 +
17156 +               /* for tokens > 0, one token was consumed */
17157 +               if (tokens < 2)
17158 +                       slice = 0;
17159 +       }
17160 +       vxm_need_resched(p, slice, cpu);
17161 +       return (slice == 0);
17162 +}
17163 +
17164 +
17165 +#define vx_set_rq_time(rq, time) do {  \
17166 +       rq->norm_time = time;           \
17167 +} while (0)
17168 +
17169 +
17170 +static inline
17171 +void vx_try_unhold(struct rq *rq, int cpu)
17172 +{
17173 +       struct vx_info *vxi = NULL;
17174 +       struct list_head *l, *n;
17175 +       int maxidle = HZ;
17176 +       int minskip = 0;
17177 +
17178 +       /* nothing to do? what about pause? */
17179 +       if (list_empty(&rq->hold_queue))
17180 +               return;
17181 +
17182 +       list_for_each_safe(l, n, &rq->hold_queue) {
17183 +               int ret, delta_min[2];
17184 +               struct _vx_sched_pc *sched_pc;
17185 +               struct task_struct *p;
17186 +
17187 +               p = list_entry(l, struct task_struct, run_list);
17188 +               /* don't bother with same context */
17189 +               if (vxi == p->vx_info)
17190 +                       continue;
17191 +
17192 +               vxi = p->vx_info;
17193 +               /* ignore paused contexts */
17194 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
17195 +                       continue;
17196 +
17197 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
17198 +
17199 +               /* recalc tokens */
17200 +               vxm_sched_info(sched_pc, vxi, cpu);
17201 +               ret = vx_tokens_recalc(sched_pc,
17202 +                       &rq->norm_time, &rq->idle_time, delta_min);
17203 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
17204 +
17205 +               if (ret > 0) {
17206 +                       /* we found a runable context */
17207 +                       vx_unhold_task(p, rq);
17208 +                       break;
17209 +               }
17210 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
17211 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
17212 +       }
17213 +       vx_set_rq_max_idle(rq, maxidle);
17214 +       vx_set_rq_min_skip(rq, minskip);
17215 +       vxm_rq_max_min(rq, cpu);
17216 +}
17217 +
17218 +
17219 +static inline
17220 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
17221 +{
17222 +       struct vx_info *vxi = next->vx_info;
17223 +       struct _vx_sched_pc *sched_pc;
17224 +       int delta_min[2];
17225 +       int flags, ret;
17226 +
17227 +       if (!vxi)
17228 +               return 1;
17229 +
17230 +       flags = vxi->vx_flags;
17231 +
17232 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
17233 +               goto put_on_hold;
17234 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
17235 +               return 1;
17236 +
17237 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
17238 +#ifdef CONFIG_SMP
17239 +       /* update scheduler params */
17240 +       if (cpu_isset(cpu, vxi->sched.update)) {
17241 +               vx_update_sched_param(&vxi->sched, sched_pc);
17242 +               vxm_update_sched(sched_pc, vxi, cpu);
17243 +               cpu_clear(cpu, vxi->sched.update);
17244 +       }
17245 +#endif
17246 +       vxm_sched_info(sched_pc, vxi, cpu);
17247 +       ret  = vx_tokens_recalc(sched_pc,
17248 +               &rq->norm_time, &rq->idle_time, delta_min);
17249 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
17250 +
17251 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
17252 +               return 1;
17253 +
17254 +       if (unlikely(ret < 0)) {
17255 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
17256 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
17257 +               vxm_rq_max_min(rq, cpu);
17258 +       put_on_hold:
17259 +               vx_hold_task(next, rq);
17260 +               return 0;
17261 +       }
17262 +       return 1;
17263 +}
17264 +
17265 +
17266 +#else /* CONFIG_VSERVER_HARDCPU */
17267 +
17268 +static inline
17269 +void vx_hold_task(struct task_struct *p, struct rq *rq)
17270 +{
17271 +       return;
17272 +}
17273 +
17274 +static inline
17275 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
17276 +{
17277 +       return;
17278 +}
17279 +
17280 +unsigned long nr_onhold(void)
17281 +{
17282 +       return 0;
17283 +}
17284 +
17285 +
17286 +static inline
17287 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
17288 +{
17289 +       return (slice == 0);
17290 +}
17291 +
17292 +
17293 +#define vx_set_rq_time(rq, time)
17294 +
17295 +static inline
17296 +void vx_try_unhold(struct rq *rq, int cpu)
17297 +{
17298 +       return;
17299 +}
17300 +
17301 +static inline
17302 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
17303 +{
17304 +       struct vx_info *vxi = next->vx_info;
17305 +       struct _vx_sched_pc *sched_pc;
17306 +       int delta_min[2];
17307 +       int ret;
17308 +
17309 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
17310 +               return 1;
17311 +
17312 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
17313 +       vxm_sched_info(sched_pc, vxi, cpu);
17314 +       ret  = vx_tokens_recalc(sched_pc,
17315 +               &rq->norm_time, &rq->idle_time, delta_min);
17316 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
17317 +       return 1;
17318 +}
17319 +
17320 +#endif /* CONFIG_VSERVER_HARDCPU */
17321 +
17322 diff -NurpP --minimal linux-2.6.22.10/kernel/sched_mon.h linux-2.6.22.10-vs2.2.0.5/kernel/sched_mon.h
17323 --- linux-2.6.22.10/kernel/sched_mon.h  1970-01-01 01:00:00 +0100
17324 +++ linux-2.6.22.10-vs2.2.0.5/kernel/sched_mon.h        2007-06-15 02:37:04 +0200
17325 @@ -0,0 +1,200 @@
17326 +
17327 +#include <linux/vserver/monitor.h>
17328 +
17329 +#ifdef  CONFIG_VSERVER_MONITOR
17330 +
17331 +#ifdef CONFIG_VSERVER_HARDCPU
17332 +#define HARDCPU(x) (x)
17333 +#else
17334 +#define HARDCPU(x) (0)
17335 +#endif
17336 +
17337 +#ifdef CONFIG_VSERVER_IDLETIME
17338 +#define IDLETIME(x) (x)
17339 +#else
17340 +#define IDLETIME(x) (0)
17341 +#endif
17342 +
17343 +struct _vx_mon_entry *vxm_advance(int cpu);
17344 +
17345 +
17346 +static inline
17347 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
17348 +{
17349 +       entry->type = type;
17350 +       entry->xid = xid;
17351 +}
17352 +
17353 +static inline
17354 +void   __vxm_sync(int cpu)
17355 +{
17356 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17357 +
17358 +       __vxm_basic(entry, 0, VXM_SYNC);
17359 +       entry->ev.sec = xtime.tv_sec;
17360 +       entry->ev.nsec = xtime.tv_nsec;
17361 +}
17362 +
17363 +static inline
17364 +void   __vxm_task(struct task_struct *p, int type)
17365 +{
17366 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
17367 +
17368 +       __vxm_basic(entry, p->xid, type);
17369 +       entry->ev.tsk.pid = p->pid;
17370 +       entry->ev.tsk.state = p->state;
17371 +}
17372 +
17373 +static inline
17374 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17375 +{
17376 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17377 +
17378 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
17379 +       entry->sd.tokens = s->tokens;
17380 +       entry->sd.norm_time = s->norm_time;
17381 +       entry->sd.idle_time = s->idle_time;
17382 +}
17383 +
17384 +static inline
17385 +void   __vxm_rqinfo1(struct rq *q, int cpu)
17386 +{
17387 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17388 +
17389 +       entry->type = VXM_RQINFO_1;
17390 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
17391 +       entry->q1.running = q->nr_running;
17392 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
17393 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
17394 +       entry->q1.uintr = q->nr_uninterruptible;
17395 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
17396 +}
17397 +
17398 +static inline
17399 +void   __vxm_rqinfo2(struct rq *q, int cpu)
17400 +{
17401 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17402 +
17403 +       entry->type = VXM_RQINFO_2;
17404 +       entry->xid = (unsigned long)q & 0xffff;
17405 +       entry->q2.norm_time = q->norm_time;
17406 +       entry->q2.idle_time = q->idle_time;
17407 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
17408 +}
17409 +
17410 +static inline
17411 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17412 +{
17413 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17414 +
17415 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
17416 +       entry->ev.tokens = s->tokens;
17417 +}
17418 +
17419 +static inline
17420 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17421 +{
17422 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17423 +
17424 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
17425 +       entry->u1.tokens_max = s->tokens_max;
17426 +       entry->u1.fill_rate = s->fill_rate[0];
17427 +       entry->u1.interval = s->interval[0];
17428 +}
17429 +
17430 +static inline
17431 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17432 +{
17433 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
17434 +
17435 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
17436 +       entry->u2.tokens_min = s->tokens_min;
17437 +       entry->u2.fill_rate = s->fill_rate[1];
17438 +       entry->u2.interval = s->interval[1];
17439 +}
17440 +
17441 +
17442 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
17443 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
17444 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
17445 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
17446 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
17447 +
17448 +static inline
17449 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
17450 +{
17451 +       __vxm_task(p, VXM_MIGRATE);
17452 +       __vxm_rqinfo1(rq, task_cpu(p));
17453 +       __vxm_rqinfo2(rq, task_cpu(p));
17454 +}
17455 +
17456 +static inline
17457 +void   vxm_idle_skip(struct rq *rq, int cpu)
17458 +{
17459 +       __vxm_rqinfo1(rq, cpu);
17460 +       __vxm_rqinfo2(rq, cpu);
17461 +}
17462 +
17463 +static inline
17464 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
17465 +{
17466 +       if (slice)
17467 +               return;
17468 +
17469 +       __vxm_task(p, VXM_RESCHED);
17470 +}
17471 +
17472 +static inline
17473 +void   vxm_sync(unsigned long now, int cpu)
17474 +{
17475 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
17476 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
17477 +               return;
17478 +
17479 +       __vxm_sync(cpu);
17480 +}
17481 +
17482 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
17483 +
17484 +static inline
17485 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
17486 +       struct vx_info *vxi, int cpu)
17487 +{
17488 +       __vxm_sched(s, vxi, cpu);
17489 +       __vxm_rqinfo2(rq, cpu);
17490 +}
17491 +
17492 +static inline
17493 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
17494 +{
17495 +       __vxm_sched(s, vxi, cpu);
17496 +       __vxm_update(s, vxi, cpu);
17497 +       __vxm_update1(s, vxi, cpu);
17498 +       __vxm_update2(s, vxi, cpu);
17499 +}
17500 +
17501 +static inline
17502 +void   vxm_rq_max_min(struct rq *rq, int cpu)
17503 +{
17504 +       __vxm_rqinfo1(rq, cpu);
17505 +       __vxm_rqinfo2(rq, cpu);
17506 +}
17507 +
17508 +#else  /* CONFIG_VSERVER_MONITOR */
17509 +
17510 +#define        vxm_activate_task(t,q)          do { } while (0)
17511 +#define        vxm_activate_idle(t,q)          do { } while (0)
17512 +#define        vxm_deactivate_task(t,q)        do { } while (0)
17513 +#define        vxm_hold_task(t,q)              do { } while (0)
17514 +#define        vxm_unhold_task(t,q)            do { } while (0)
17515 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
17516 +#define        vxm_idle_skip(q,c)              do { } while (0)
17517 +#define        vxm_need_resched(t,s,c)         do { } while (0)
17518 +#define        vxm_sync(s,c)                   do { } while (0)
17519 +#define        vxm_sched_info(s,v,c)           do { } while (0)
17520 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
17521 +#define        vxm_update_sched(s,v,c)         do { } while (0)
17522 +#define        vxm_rq_max_min(q,c)             do { } while (0)
17523 +
17524 +#endif /* CONFIG_VSERVER_MONITOR */
17525 +
17526 diff -NurpP --minimal linux-2.6.22.10/kernel/signal.c linux-2.6.22.10-vs2.2.0.5/kernel/signal.c
17527 --- linux-2.6.22.10/kernel/signal.c     2007-10-30 01:57:15 +0100
17528 +++ linux-2.6.22.10-vs2.2.0.5/kernel/signal.c   2007-10-01 15:25:35 +0200
17529 @@ -26,6 +26,8 @@
17530  #include <linux/freezer.h>
17531  #include <linux/pid_namespace.h>
17532  #include <linux/nsproxy.h>
17533 +#include <linux/vs_context.h>
17534 +#include <linux/vs_pid.h>
17535  
17536  #include <asm/param.h>
17537  #include <asm/uaccess.h>
17538 @@ -523,19 +525,34 @@ static int check_kill_permission(int sig
17539         if (!valid_signal(sig))
17540                 return error;
17541  
17542 +       if ((info != SEND_SIG_NOINFO) &&
17543 +               (is_si_special(info) || !SI_FROMUSER(info)))
17544 +               goto skip;
17545 +
17546 +       vxdprintk(VXD_CBIT(misc, 7),
17547 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17548 +               sig, info, t, vx_task_xid(t), t->pid);
17549 +
17550         error = audit_signal_info(sig, t); /* Let audit system see the signal */
17551         if (error)
17552                 return error;
17553  
17554         error = -EPERM;
17555 -       if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
17556 -           && ((sig != SIGCONT) ||
17557 +       if (((sig != SIGCONT) ||
17558                 (process_session(current) != process_session(t)))
17559             && (current->euid ^ t->suid) && (current->euid ^ t->uid)
17560             && (current->uid ^ t->suid) && (current->uid ^ t->uid)
17561             && !capable(CAP_KILL))
17562                 return error;
17563  
17564 +       error = -ESRCH;
17565 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17566 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17567 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17568 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17569 +               return error;
17570 +       }
17571 +skip:
17572         return security_task_kill(t, info, sig, 0);
17573  }
17574  
17575 @@ -1043,7 +1060,7 @@ int kill_pid_info(int sig, struct siginf
17576  
17577         p = pid_task(pid, PIDTYPE_PID);
17578         error = -ESRCH;
17579 -       if (p)
17580 +       if (p && vx_check(vx_task_xid(p), VS_IDENT))
17581                 error = group_send_sig_info(sig, info, p);
17582  
17583         if (unlikely(sig_needs_tasklist(sig)))
17584 @@ -1057,7 +1074,7 @@ kill_proc_info(int sig, struct siginfo *
17585  {
17586         int error;
17587         rcu_read_lock();
17588 -       error = kill_pid_info(sig, info, find_pid(pid));
17589 +       error = kill_pid_info(sig, info, find_pid(vx_rmap_pid(pid)));
17590         rcu_read_unlock();
17591         return error;
17592  }
17593 @@ -1118,7 +1135,8 @@ static int kill_something_info(int sig, 
17594  
17595                 read_lock(&tasklist_lock);
17596                 for_each_process(p) {
17597 -                       if (p->pid > 1 && p->tgid != current->tgid) {
17598 +                       if (vx_check(vx_task_xid(p), VS_ADMIN_P|VS_IDENT) &&
17599 +                               p->pid > 1 && p->tgid != current->tgid) {
17600                                 int err = group_send_sig_info(sig, info, p);
17601                                 ++count;
17602                                 if (err != -EPERM)
17603 @@ -1814,6 +1832,11 @@ relock:
17604                 if (current == child_reaper(current))
17605                         continue;
17606  
17607 +               /* virtual init is protected against user signals */
17608 +               if ((info->si_code == SI_USER) &&
17609 +                       vx_current_initpid(current->pid))
17610 +                       continue;
17611 +
17612                 if (sig_kernel_stop(signr)) {
17613                         /*
17614                          * The default action is to stop all threads in
17615 diff -NurpP --minimal linux-2.6.22.10/kernel/softirq.c linux-2.6.22.10-vs2.2.0.5/kernel/softirq.c
17616 --- linux-2.6.22.10/kernel/softirq.c    2007-07-09 13:20:03 +0200
17617 +++ linux-2.6.22.10-vs2.2.0.5/kernel/softirq.c  2007-06-15 02:37:04 +0200
17618 @@ -18,6 +18,7 @@
17619  #include <linux/rcupdate.h>
17620  #include <linux/smp.h>
17621  #include <linux/tick.h>
17622 +#include <linux/vs_context.h>
17623  
17624  #include <asm/irq.h>
17625  /*
17626 diff -NurpP --minimal linux-2.6.22.10/kernel/sys.c linux-2.6.22.10-vs2.2.0.5/kernel/sys.c
17627 --- linux-2.6.22.10/kernel/sys.c        2007-10-30 01:57:15 +0100
17628 +++ linux-2.6.22.10-vs2.2.0.5/kernel/sys.c      2007-10-30 01:24:36 +0100
17629 @@ -36,6 +36,7 @@
17630  #include <linux/compat.h>
17631  #include <linux/syscalls.h>
17632  #include <linux/kprobes.h>
17633 +#include <linux/vs_pid.h>
17634  
17635  #include <asm/uaccess.h>
17636  #include <asm/io.h>
17637 @@ -639,7 +640,10 @@ static int set_one_prio(struct task_stru
17638                 goto out;
17639         }
17640         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17641 -               error = -EACCES;
17642 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17643 +                       error = 0;
17644 +               else
17645 +                       error = -EACCES;
17646                 goto out;
17647         }
17648         no_nice = security_task_setnice(p, niceval);
17649 @@ -687,6 +691,8 @@ asmlinkage long sys_setpriority(int whic
17650                         else
17651                                 pgrp = task_pgrp(current);
17652                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
17653 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17654 +                                       continue;
17655                                 error = set_one_prio(p, niceval, error);
17656                         } while_each_pid_task(pgrp, PIDTYPE_PGID, p);
17657                         break;
17658 @@ -695,7 +701,8 @@ asmlinkage long sys_setpriority(int whic
17659                         if (!who)
17660                                 who = current->uid;
17661                         else
17662 -                               if ((who != current->uid) && !(user = find_user(who)))
17663 +                               if ((who != current->uid) &&
17664 +                                       !(user = find_user(vx_current_xid(), who)))
17665                                         goto out_unlock;        /* No processes for this user */
17666  
17667                         do_each_thread(g, p)
17668 @@ -747,6 +754,8 @@ asmlinkage long sys_getpriority(int whic
17669                         else
17670                                 pgrp = task_pgrp(current);
17671                         do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
17672 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17673 +                                       continue;
17674                                 niceval = 20 - task_nice(p);
17675                                 if (niceval > retval)
17676                                         retval = niceval;
17677 @@ -757,7 +766,8 @@ asmlinkage long sys_getpriority(int whic
17678                         if (!who)
17679                                 who = current->uid;
17680                         else
17681 -                               if ((who != current->uid) && !(user = find_user(who)))
17682 +                               if ((who != current->uid) &&
17683 +                                       !(user = find_user(vx_current_xid(), who)))
17684                                         goto out_unlock;        /* No processes for this user */
17685  
17686                         do_each_thread(g, p)
17687 @@ -871,6 +881,9 @@ void kernel_power_off(void)
17688         machine_power_off();
17689  }
17690  EXPORT_SYMBOL_GPL(kernel_power_off);
17691 +
17692 +long vs_reboot(unsigned int, void __user *);
17693 +
17694  /*
17695   * Reboot system call: for obvious reasons only root may call it,
17696   * and even root needs to set up some magic numbers in the registers
17697 @@ -901,6 +914,9 @@ asmlinkage long sys_reboot(int magic1, i
17698         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17699                 cmd = LINUX_REBOOT_CMD_HALT;
17700  
17701 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17702 +               return vs_reboot(cmd, arg);
17703 +
17704         lock_kernel();
17705         switch (cmd) {
17706         case LINUX_REBOOT_CMD_RESTART:
17707 @@ -1080,7 +1096,7 @@ static int set_user(uid_t new_ruid, int 
17708  {
17709         struct user_struct *new_user;
17710  
17711 -       new_user = alloc_uid(new_ruid);
17712 +       new_user = alloc_uid(vx_current_xid(), new_ruid);
17713         if (!new_user)
17714                 return -EAGAIN;
17715  
17716 @@ -1434,15 +1450,18 @@ asmlinkage long sys_setpgid(pid_t pid, p
17717  {
17718         struct task_struct *p;
17719         struct task_struct *group_leader = current->group_leader;
17720 +       pid_t rpgid;
17721         int err = -EINVAL;
17722  
17723         if (!pid)
17724 -               pid = group_leader->pid;
17725 +               pid = vx_map_pid(group_leader->pid);
17726         if (!pgid)
17727                 pgid = pid;
17728         if (pgid < 0)
17729                 return -EINVAL;
17730  
17731 +       rpgid = vx_rmap_pid(pgid);
17732 +
17733         /* From this point forward we keep holding onto the tasklist lock
17734          * so that our parent does not change from under us. -DaveM
17735          */
17736 @@ -1476,20 +1495,20 @@ asmlinkage long sys_setpgid(pid_t pid, p
17737  
17738         if (pgid != pid) {
17739                 struct task_struct *g =
17740 -                       find_task_by_pid_type(PIDTYPE_PGID, pgid);
17741 +                       find_task_by_pid_type(PIDTYPE_PGID, rpgid);
17742  
17743                 if (!g || task_session(g) != task_session(group_leader))
17744                         goto out;
17745         }
17746  
17747 -       err = security_task_setpgid(p, pgid);
17748 +       err = security_task_setpgid(p, rpgid);
17749         if (err)
17750                 goto out;
17751  
17752 -       if (process_group(p) != pgid) {
17753 +       if (process_group(p) != rpgid) {
17754                 detach_pid(p, PIDTYPE_PGID);
17755 -               p->signal->pgrp = pgid;
17756 -               attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
17757 +               p->signal->pgrp = rpgid;
17758 +               attach_pid(p, PIDTYPE_PGID, find_pid(rpgid));
17759         }
17760  
17761         err = 0;
17762 @@ -1502,7 +1521,7 @@ out:
17763  asmlinkage long sys_getpgid(pid_t pid)
17764  {
17765         if (!pid)
17766 -               return process_group(current);
17767 +               return vx_rmap_pid(process_group(current));
17768         else {
17769                 int retval;
17770                 struct task_struct *p;
17771 @@ -1514,7 +1533,7 @@ asmlinkage long sys_getpgid(pid_t pid)
17772                 if (p) {
17773                         retval = security_task_getpgid(p);
17774                         if (!retval)
17775 -                               retval = process_group(p);
17776 +                               retval = vx_rmap_pid(process_group(p));
17777                 }
17778                 read_unlock(&tasklist_lock);
17779                 return retval;
17780 @@ -1865,7 +1884,7 @@ asmlinkage long sys_sethostname(char __u
17781         int errno;
17782         char tmp[__NEW_UTS_LEN];
17783  
17784 -       if (!capable(CAP_SYS_ADMIN))
17785 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17786                 return -EPERM;
17787         if (len < 0 || len > __NEW_UTS_LEN)
17788                 return -EINVAL;
17789 @@ -1910,7 +1929,7 @@ asmlinkage long sys_setdomainname(char _
17790         int errno;
17791         char tmp[__NEW_UTS_LEN];
17792  
17793 -       if (!capable(CAP_SYS_ADMIN))
17794 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17795                 return -EPERM;
17796         if (len < 0 || len > __NEW_UTS_LEN)
17797                 return -EINVAL;
17798 @@ -1977,7 +1996,7 @@ asmlinkage long sys_setrlimit(unsigned i
17799                 return -EINVAL;
17800         old_rlim = current->signal->rlim + resource;
17801         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17802 -           !capable(CAP_SYS_RESOURCE))
17803 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17804                 return -EPERM;
17805         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
17806                 return -EPERM;
17807 diff -NurpP --minimal linux-2.6.22.10/kernel/sysctl.c linux-2.6.22.10-vs2.2.0.5/kernel/sysctl.c
17808 --- linux-2.6.22.10/kernel/sysctl.c     2007-07-09 13:20:03 +0200
17809 +++ linux-2.6.22.10-vs2.2.0.5/kernel/sysctl.c   2007-06-15 02:37:04 +0200
17810 @@ -89,6 +89,7 @@ static int ngroups_max = NGROUPS_MAX;
17811  #ifdef CONFIG_KMOD
17812  extern char modprobe_path[];
17813  #endif
17814 +extern char vshelper_path[];
17815  #ifdef CONFIG_CHR_DEV_SG
17816  extern int sg_big_buff;
17817  #endif
17818 @@ -343,6 +344,15 @@ static ctl_table kern_table[] = {
17819                 .strategy       = &sysctl_string,
17820         },
17821  #endif
17822 +       {
17823 +               .ctl_name       = KERN_VSHELPER,
17824 +               .procname       = "vshelper",
17825 +               .data           = &vshelper_path,
17826 +               .maxlen         = 256,
17827 +               .mode           = 0644,
17828 +               .proc_handler   = &proc_dostring,
17829 +               .strategy       = &sysctl_string,
17830 +       },
17831  #ifdef CONFIG_CHR_DEV_SG
17832         {
17833                 .ctl_name       = KERN_SG_BIG_BUFF,
17834 diff -NurpP --minimal linux-2.6.22.10/kernel/time.c linux-2.6.22.10-vs2.2.0.5/kernel/time.c
17835 --- linux-2.6.22.10/kernel/time.c       2007-07-09 13:20:03 +0200
17836 +++ linux-2.6.22.10-vs2.2.0.5/kernel/time.c     2007-06-15 02:37:04 +0200
17837 @@ -60,7 +60,7 @@ asmlinkage long sys_time(time_t __user *
17838         time_t i;
17839         struct timeval tv;
17840  
17841 -       do_gettimeofday(&tv);
17842 +       vx_gettimeofday(&tv);
17843         i = tv.tv_sec;
17844  
17845         if (tloc) {
17846 @@ -91,7 +91,7 @@ asmlinkage long sys_stime(time_t __user 
17847         if (err)
17848                 return err;
17849  
17850 -       do_settimeofday(&tv);
17851 +       vx_settimeofday(&tv);
17852         return 0;
17853  }
17854  
17855 @@ -101,7 +101,7 @@ asmlinkage long sys_gettimeofday(struct 
17856  {
17857         if (likely(tv != NULL)) {
17858                 struct timeval ktv;
17859 -               do_gettimeofday(&ktv);
17860 +               vx_gettimeofday(&ktv);
17861                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17862                         return -EFAULT;
17863         }
17864 @@ -175,7 +175,7 @@ int do_sys_settimeofday(struct timespec 
17865                 /* SMP safe, again the code in arch/foo/time.c should
17866                  * globally block out interrupts when it runs.
17867                  */
17868 -               return do_settimeofday(tv);
17869 +               return vx_settimeofday(tv);
17870         }
17871         return 0;
17872  }
17873 @@ -388,7 +388,7 @@ void getnstimeofday(struct timespec *tv)
17874  {
17875         struct timeval x;
17876  
17877 -       do_gettimeofday(&x);
17878 +       vx_gettimeofday(&x);
17879         tv->tv_sec = x.tv_sec;
17880         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17881  }
17882 diff -NurpP --minimal linux-2.6.22.10/kernel/timer.c linux-2.6.22.10-vs2.2.0.5/kernel/timer.c
17883 --- linux-2.6.22.10/kernel/timer.c      2007-07-09 13:20:04 +0200
17884 +++ linux-2.6.22.10-vs2.2.0.5/kernel/timer.c    2007-06-15 02:37:04 +0200
17885 @@ -36,6 +36,10 @@
17886  #include <linux/delay.h>
17887  #include <linux/tick.h>
17888  #include <linux/kallsyms.h>
17889 +#include <linux/vs_base.h>
17890 +#include <linux/vs_cvirt.h>
17891 +#include <linux/vs_pid.h>
17892 +#include <linux/vserver/sched.h>
17893  
17894  #include <asm/uaccess.h>
17895  #include <asm/unistd.h>
17896 @@ -921,12 +925,6 @@ asmlinkage unsigned long sys_alarm(unsig
17897  
17898  #endif
17899  
17900 -#ifndef __alpha__
17901 -
17902 -/*
17903 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17904 - * should be moved into arch/i386 instead?
17905 - */
17906  
17907  /**
17908   * sys_getpid - return the thread group id of the current process
17909 @@ -939,7 +937,7 @@ asmlinkage unsigned long sys_alarm(unsig
17910   */
17911  asmlinkage long sys_getpid(void)
17912  {
17913 -       return current->tgid;
17914 +       return vx_map_tgid(current->tgid);
17915  }
17916  
17917  /*
17918 @@ -955,10 +953,23 @@ asmlinkage long sys_getppid(void)
17919         rcu_read_lock();
17920         pid = rcu_dereference(current->real_parent)->tgid;
17921         rcu_read_unlock();
17922 +       return vx_map_pid(pid);
17923 +}
17924  
17925 -       return pid;
17926 +#ifdef __alpha__
17927 +
17928 +/*
17929 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17930 + */
17931 +
17932 +asmlinkage long do_getxpid(long *ppid)
17933 +{
17934 +       *ppid = sys_getppid();
17935 +       return sys_getpid();
17936  }
17937  
17938 +#else /* _alpha_ */
17939 +
17940  asmlinkage long sys_getuid(void)
17941  {
17942         /* Only we change this so SMP safe */
17943 @@ -1118,6 +1129,8 @@ int do_sysinfo(struct sysinfo *info)
17944                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
17945                         tp.tv_sec++;
17946                 }
17947 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
17948 +                       vx_vsi_uptime(&tp, NULL);
17949                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
17950  
17951                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
17952 diff -NurpP --minimal linux-2.6.22.10/kernel/user.c linux-2.6.22.10-vs2.2.0.5/kernel/user.c
17953 --- linux-2.6.22.10/kernel/user.c       2007-02-06 03:01:56 +0100
17954 +++ linux-2.6.22.10-vs2.2.0.5/kernel/user.c     2007-06-15 02:37:04 +0200
17955 @@ -23,8 +23,8 @@
17956  #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
17957  #define UIDHASH_SZ             (1 << UIDHASH_BITS)
17958  #define UIDHASH_MASK           (UIDHASH_SZ - 1)
17959 -#define __uidhashfn(uid)       (((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
17960 -#define uidhashentry(uid)      (uidhash_table + __uidhashfn((uid)))
17961 +#define __uidhashfn(xid,uid)   ((((uid) >> UIDHASH_BITS) + ((uid)^(xid))) & UIDHASH_MASK)
17962 +#define uidhashentry(xid,uid)  (uidhash_table + __uidhashfn((xid),(uid)))
17963  
17964  static struct kmem_cache *uid_cachep;
17965  static struct list_head uidhash_table[UIDHASH_SZ];
17966 @@ -66,7 +66,7 @@ static inline void uid_hash_remove(struc
17967         list_del(&up->uidhash_list);
17968  }
17969  
17970 -static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *hashent)
17971 +static inline struct user_struct *uid_hash_find(xid_t xid, uid_t uid, struct list_head *hashent)
17972  {
17973         struct list_head *up;
17974  
17975 @@ -75,7 +75,7 @@ static inline struct user_struct *uid_ha
17976  
17977                 user = list_entry(up, struct user_struct, uidhash_list);
17978  
17979 -               if(user->uid == uid) {
17980 +               if(user->uid == uid && user->xid == xid) {
17981                         atomic_inc(&user->__count);
17982                         return user;
17983                 }
17984 @@ -90,13 +90,13 @@ static inline struct user_struct *uid_ha
17985   *
17986   * If the user_struct could not be found, return NULL.
17987   */
17988 -struct user_struct *find_user(uid_t uid)
17989 +struct user_struct *find_user(xid_t xid, uid_t uid)
17990  {
17991         struct user_struct *ret;
17992         unsigned long flags;
17993  
17994         spin_lock_irqsave(&uidhash_lock, flags);
17995 -       ret = uid_hash_find(uid, uidhashentry(uid));
17996 +       ret = uid_hash_find(xid, uid, uidhashentry(xid, uid));
17997         spin_unlock_irqrestore(&uidhash_lock, flags);
17998         return ret;
17999  }
18000 @@ -120,13 +120,13 @@ void free_uid(struct user_struct *up)
18001         }
18002  }
18003  
18004 -struct user_struct * alloc_uid(uid_t uid)
18005 +struct user_struct * alloc_uid(xid_t xid, uid_t uid)
18006  {
18007 -       struct list_head *hashent = uidhashentry(uid);
18008 +       struct list_head *hashent = uidhashentry(xid, uid);
18009         struct user_struct *up;
18010  
18011         spin_lock_irq(&uidhash_lock);
18012 -       up = uid_hash_find(uid, hashent);
18013 +       up = uid_hash_find(xid, uid, hashent);
18014         spin_unlock_irq(&uidhash_lock);
18015  
18016         if (!up) {
18017 @@ -136,6 +136,7 @@ struct user_struct * alloc_uid(uid_t uid
18018                 if (!new)
18019                         return NULL;
18020                 new->uid = uid;
18021 +               new->xid = xid;
18022                 atomic_set(&new->__count, 1);
18023                 atomic_set(&new->processes, 0);
18024                 atomic_set(&new->files, 0);
18025 @@ -158,7 +159,7 @@ struct user_struct * alloc_uid(uid_t uid
18026                  * on adding the same user already..
18027                  */
18028                 spin_lock_irq(&uidhash_lock);
18029 -               up = uid_hash_find(uid, hashent);
18030 +               up = uid_hash_find(xid, uid, hashent);
18031                 if (up) {
18032                         key_put(new->uid_keyring);
18033                         key_put(new->session_keyring);
18034 @@ -215,7 +216,7 @@ static int __init uid_cache_init(void)
18035  
18036         /* Insert the root user immediately (init already runs as root) */
18037         spin_lock_irq(&uidhash_lock);
18038 -       uid_hash_insert(&root_user, uidhashentry(0));
18039 +       uid_hash_insert(&root_user, uidhashentry(0,0));
18040         spin_unlock_irq(&uidhash_lock);
18041  
18042         return 0;
18043 diff -NurpP --minimal linux-2.6.22.10/kernel/utsname.c linux-2.6.22.10-vs2.2.0.5/kernel/utsname.c
18044 --- linux-2.6.22.10/kernel/utsname.c    2007-07-09 13:20:04 +0200
18045 +++ linux-2.6.22.10-vs2.2.0.5/kernel/utsname.c  2007-06-15 02:37:04 +0200
18046 @@ -13,6 +13,7 @@
18047  #include <linux/uts.h>
18048  #include <linux/utsname.h>
18049  #include <linux/version.h>
18050 +#include <linux/vserver/global.h>
18051  
18052  /*
18053   * Clone a new ns copying an original utsname, setting refcount to 1
18054 @@ -27,6 +28,7 @@ static struct uts_namespace *clone_uts_n
18055         if (ns) {
18056                 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
18057                 kref_init(&ns->kref);
18058 +               atomic_inc(&vs_global_uts_ns);
18059         }
18060         return ns;
18061  }
18062 @@ -58,5 +60,6 @@ void free_uts_ns(struct kref *kref)
18063         struct uts_namespace *ns;
18064  
18065         ns = container_of(kref, struct uts_namespace, kref);
18066 +       atomic_dec(&vs_global_uts_ns);
18067         kfree(ns);
18068  }
18069 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/Kconfig linux-2.6.22.10-vs2.2.0.5/kernel/vserver/Kconfig
18070 --- linux-2.6.22.10/kernel/vserver/Kconfig      1970-01-01 01:00:00 +0100
18071 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/Kconfig    2007-06-15 02:37:04 +0200
18072 @@ -0,0 +1,284 @@
18073 +#
18074 +# Linux VServer configuration
18075 +#
18076 +
18077 +menu "Linux VServer"
18078 +
18079 +config VSERVER_LEGACY
18080 +       bool    "Enable Legacy Kernel API"
18081 +       depends on EXPERIMENTAL
18082 +       default n
18083 +       help
18084 +         This enables the legacy API used in vs1.xx, maintaining
18085 +         compatibility with older vserver tools, and guest images
18086 +         that are configured using the legacy method.
18087 +
18088 +config VSERVER_LEGACY_VERSION
18089 +       bool    "Show a Legacy Version ID"
18090 +       depends on VSERVER_LEGACY
18091 +       default n
18092 +       help
18093 +         This shows a special legacy version to very old tools
18094 +         which do not handle the current version correctly.
18095 +
18096 +         Warning: recent tools are not able to utilize the
18097 +         newer APIs when this is enabled, so some features will
18098 +         not be available. Better avoid it, unless you really,
18099 +         really need it for backwards compatibility.
18100 +
18101 +config VSERVER_DYNAMIC_IDS
18102 +       bool    "Enable dynamic context IDs"
18103 +       depends on EXPERIMENTAL && VSERVER_LEGACY
18104 +       default n
18105 +       help
18106 +         This enables support of in kernel dynamic context IDs,
18107 +         which is deprecated and will probably be removed in the
18108 +         next release.
18109 +
18110 +config VSERVER_LEGACYNET
18111 +       bool    "Enable Legacy Networking Kernel API"
18112 +       depends on EXPERIMENTAL
18113 +       default n
18114 +       help
18115 +         This enables the legacy networking API which is used
18116 +         by older tools (pre 0.30.210) to set up the network
18117 +         context (chbind).
18118 +
18119 +config VSERVER_REMAP_SADDR
18120 +       bool    "Remap Source IP Address"
18121 +       depends on EXPERIMENTAL
18122 +       default n
18123 +       help
18124 +         This allows to remap the source IP address of 'local'
18125 +         connections from 127.0.0.1 to the first assigned
18126 +         guest IP.
18127 +
18128 +config VSERVER_COWBL
18129 +       bool    "Enable COW Immutable Link Breaking"
18130 +       default y
18131 +       help
18132 +         This enables the COW (Copy-On-Write) link break code.
18133 +         It allows you to treat unified files like normal files
18134 +         when writing to them (which will implicitely break the
18135 +         link and create a copy of the unified file)
18136 +
18137 +config VSERVER_VTIME
18138 +       bool    "Enable Virtualized Guest Time"
18139 +       depends on EXPERIMENTAL
18140 +       default n
18141 +       help
18142 +         This enables per guest time offsets to allow for
18143 +         adjusting the system clock individually per guest.
18144 +         this adds some overhead to the time functions and
18145 +         therefore should not be enabled without good reason.
18146 +
18147 +config VSERVER_PROC_SECURE
18148 +       bool    "Enable Proc Security"
18149 +       depends on PROC_FS
18150 +       default y
18151 +       help
18152 +         This configures ProcFS security to initially hide
18153 +         non-process entries for all contexts except the main and
18154 +         spectator context (i.e. for all guests), which is a secure
18155 +         default.
18156 +
18157 +         (note: on 1.2x the entries were visible by default)
18158 +
18159 +config VSERVER_HARDCPU
18160 +       bool    "Enable Hard CPU Limits"
18161 +       default y
18162 +       help
18163 +         Activate the Hard CPU Limits
18164 +
18165 +         This will compile in code that allows the Token Bucket
18166 +         Scheduler to put processes on hold when a context's
18167 +         tokens are depleted (provided that its per-context
18168 +         sched_hard flag is set).
18169 +
18170 +         Processes belonging to that context will not be able
18171 +         to consume CPU resources again until a per-context
18172 +         configured minimum of tokens has been reached.
18173 +
18174 +config VSERVER_IDLETIME
18175 +       bool    "Avoid idle CPUs by skipping Time"
18176 +       depends on VSERVER_HARDCPU
18177 +       default y
18178 +       help
18179 +         This option allows the scheduler to artificially
18180 +         advance time (per cpu) when otherwise the idle
18181 +         task would be scheduled, thus keeping the cpu
18182 +         busy and sharing the available resources among
18183 +         certain contexts.
18184 +
18185 +config VSERVER_IDLELIMIT
18186 +       bool    "Limit the IDLE task"
18187 +       depends on VSERVER_HARDCPU
18188 +       default n
18189 +       help
18190 +         Limit the idle slices, so the the next context
18191 +         will be scheduled as soon as possible.
18192 +
18193 +         This might improve interactivity and latency, but
18194 +         will also marginally increase scheduling overhead.
18195 +
18196 +choice
18197 +       prompt  "Persistent Inode Tagging"
18198 +       default TAGGING_ID24
18199 +       help
18200 +         This adds persistent context information to filesystems
18201 +         mounted with the tagxid option. Tagging is a requirement
18202 +         for per-context disk limits and per-context quota.
18203 +
18204 +
18205 +config TAGGING_NONE
18206 +       bool    "Disabled"
18207 +       help
18208 +         do not store per-context information in inodes.
18209 +
18210 +config TAGGING_UID16
18211 +       bool    "UID16/GID32"
18212 +       help
18213 +         reduces UID to 16 bit, but leaves GID at 32 bit.
18214 +
18215 +config TAGGING_GID16
18216 +       bool    "UID32/GID16"
18217 +       help
18218 +         reduces GID to 16 bit, but leaves UID at 32 bit.
18219 +
18220 +config TAGGING_ID24
18221 +       bool    "UID24/GID24"
18222 +       help
18223 +         uses the upper 8bit from UID and GID for XID tagging
18224 +         which leaves 24bit for UID/GID each, which should be
18225 +         more than sufficient for normal use.
18226 +
18227 +config TAGGING_INTERN
18228 +       bool    "UID32/GID32"
18229 +       help
18230 +         this uses otherwise reserved inode fields in the on
18231 +         disk representation, which limits the use to a few
18232 +         filesystems (currently ext2 and ext3)
18233 +
18234 +endchoice
18235 +
18236 +config TAG_NFSD
18237 +       bool    "Tag NFSD User Auth and Files"
18238 +       default n
18239 +       help
18240 +         Enable this if you do want the in-kernel NFS
18241 +         Server to use the tagging specified above.
18242 +         (will require patched clients too)
18243 +
18244 +config PROPAGATE
18245 +       bool    "Enable Inode Tag Propagation"
18246 +       default n
18247 +       depends on EXPERIMENTAL
18248 +       help
18249 +         This allows for the tagid= mount option to specify
18250 +         a tagid which is to be used for the entire mount
18251 +         tree.
18252 +
18253 +config VSERVER_PRIVACY
18254 +       bool    "Honor Privacy Aspects of Guests"
18255 +       default y
18256 +       help
18257 +         When enabled, most context checks will disallow
18258 +         access to structures assigned to a specific context,
18259 +         like ptys or loop devices.
18260 +
18261 +config VSERVER_CONTEXTS
18262 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
18263 +       range 1 65533
18264 +       default "768"   if 64BIT
18265 +       default "256"
18266 +       help
18267 +         This setting will optimize certain data structures
18268 +         and memory allocations according to the expected
18269 +         maximum.
18270 +
18271 +         note: this is not a strict upper limit.
18272 +
18273 +config VSERVER_WARN
18274 +       bool    "VServer Warnings"
18275 +       default y
18276 +       help
18277 +         This enables various runtime warnings, which will
18278 +         notify about potential manipulation attempts or
18279 +         resource shortage. It is generally considered to
18280 +         be a good idea to have that enabled.
18281 +
18282 +config VSERVER_DEBUG
18283 +       bool    "VServer Debugging Code"
18284 +       default n
18285 +       help
18286 +         Set this to yes if you want to be able to activate
18287 +         debugging output at runtime. It adds a very small
18288 +         overhead to all vserver related functions and
18289 +         increases the kernel size by about 20k.
18290 +
18291 +config VSERVER_HISTORY
18292 +       bool    "VServer History Tracing"
18293 +       depends on VSERVER_DEBUG
18294 +       default n
18295 +       help
18296 +         Set this to yes if you want to record the history of
18297 +         linux-vserver activities, so they can be replayed in
18298 +         the event of a kernel panic or oops.
18299 +
18300 +config VSERVER_HISTORY_SIZE
18301 +       int     "Per-CPU History Size (32-65536)"
18302 +       depends on VSERVER_HISTORY
18303 +       range 32 65536
18304 +       default 64
18305 +       help
18306 +         This allows you to specify the number of entries in
18307 +         the per-CPU history buffer.
18308 +
18309 +config VSERVER_MONITOR
18310 +       bool    "VServer Scheduling Monitor"
18311 +       depends on VSERVER_DEBUG
18312 +       default n
18313 +       help
18314 +         Set this to yes if you want to record the scheduling
18315 +         decisions, so that they can be relayed to userspace
18316 +         for detailed analysis.
18317 +
18318 +config VSERVER_MONITOR_SIZE
18319 +       int     "Per-CPU Monitor Queue Size (32-65536)"
18320 +       depends on VSERVER_MONITOR
18321 +       range 32 65536
18322 +       default 1024
18323 +       help
18324 +         This allows you to specify the number of entries in
18325 +         the per-CPU scheduling monitor buffer.
18326 +
18327 +config VSERVER_MONITOR_SYNC
18328 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
18329 +       depends on VSERVER_MONITOR
18330 +       range 0 65536
18331 +       default 256
18332 +       help
18333 +         This allows you to specify the interval in ticks
18334 +         when a time sync entry is inserted.
18335 +
18336 +endmenu
18337 +
18338 +
18339 +config VSERVER
18340 +       bool
18341 +       default y
18342 +       select UTS_NS
18343 +       select SYSVIPC
18344 +       select IPC_NS
18345 +
18346 +config VSERVER_SECURITY
18347 +       bool
18348 +       depends on SECURITY
18349 +       default y
18350 +       select SECURITY_CAPABILITIES
18351 +
18352 +config VSERVER_NGNET
18353 +       bool
18354 +       depends on EXPERIMENTAL && !VSERVER_LEGACYNET
18355 +       default y
18356 +
18357 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/Makefile linux-2.6.22.10-vs2.2.0.5/kernel/vserver/Makefile
18358 --- linux-2.6.22.10/kernel/vserver/Makefile     1970-01-01 01:00:00 +0100
18359 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/Makefile   2007-06-15 02:37:04 +0200
18360 @@ -0,0 +1,17 @@
18361 +#
18362 +# Makefile for the Linux vserver routines.
18363 +#
18364 +
18365 +
18366 +obj-y          += vserver.o
18367 +
18368 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
18369 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o dlimit.o
18370 +
18371 +vserver-$(CONFIG_PROC_FS) += proc.o
18372 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
18373 +vserver-$(CONFIG_VSERVER_LEGACY) += legacy.o
18374 +vserver-$(CONFIG_VSERVER_LEGACYNET) += legacynet.o
18375 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
18376 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
18377 +
18378 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cacct.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cacct.c
18379 --- linux-2.6.22.10/kernel/vserver/cacct.c      1970-01-01 01:00:00 +0100
18380 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cacct.c    2007-06-15 02:37:04 +0200
18381 @@ -0,0 +1,44 @@
18382 +/*
18383 + *  linux/kernel/vserver/cacct.c
18384 + *
18385 + *  Virtual Server: Context Accounting
18386 + *
18387 + *  Copyright (C) 2006-2007 Herbert Pötzl
18388 + *
18389 + *  V0.01  added accounting stats
18390 + *
18391 + */
18392 +
18393 +#include <linux/types.h>
18394 +#include <linux/sched.h>
18395 +#include <linux/vs_context.h>
18396 +#include <linux/vserver/switch.h>
18397 +#include <linux/vserver/cacct_cmd.h>
18398 +#include <linux/vserver/cacct_int.h>
18399 +
18400 +#include <asm/errno.h>
18401 +#include <asm/uaccess.h>
18402 +
18403 +
18404 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
18405 +{
18406 +       struct vcmd_sock_stat_v0 vc_data;
18407 +       int j, field;
18408 +
18409 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18410 +               return -EFAULT;
18411 +
18412 +       field = vc_data.field;
18413 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
18414 +               return -EINVAL;
18415 +
18416 +       for (j = 0; j < 3; j++) {
18417 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
18418 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
18419 +       }
18420 +
18421 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18422 +               return -EFAULT;
18423 +       return 0;
18424 +}
18425 +
18426 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cacct_init.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cacct_init.h
18427 --- linux-2.6.22.10/kernel/vserver/cacct_init.h 1970-01-01 01:00:00 +0100
18428 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cacct_init.h       2007-06-15 02:37:04 +0200
18429 @@ -0,0 +1,25 @@
18430 +
18431 +
18432 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
18433 +{
18434 +       int i, j;
18435 +
18436 +
18437 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
18438 +               for (j = 0; j < 3; j++) {
18439 +                       atomic_set(&cacct->sock[i][j].count, 0);
18440 +                       atomic_set(&cacct->sock[i][j].total, 0);
18441 +               }
18442 +       }
18443 +       for (i = 0; i < 8; i++)
18444 +               atomic_set(&cacct->slab[i], 0);
18445 +       for (i = 0; i < 5; i++)
18446 +               for (j = 0; j < 4; j++)
18447 +                       atomic_set(&cacct->page[i][j], 0);
18448 +}
18449 +
18450 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
18451 +{
18452 +       return;
18453 +}
18454 +
18455 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cacct_proc.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cacct_proc.h
18456 --- linux-2.6.22.10/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00 +0100
18457 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cacct_proc.h       2007-06-15 02:37:04 +0200
18458 @@ -0,0 +1,53 @@
18459 +#ifndef _VX_CACCT_PROC_H
18460 +#define _VX_CACCT_PROC_H
18461 +
18462 +#include <linux/vserver/cacct_int.h>
18463 +
18464 +
18465 +#define VX_SOCKA_TOP   \
18466 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
18467 +
18468 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
18469 +{
18470 +       int i, j, length = 0;
18471 +       static char *type[VXA_SOCK_SIZE] = {
18472 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
18473 +       };
18474 +
18475 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
18476 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
18477 +               length += sprintf(buffer + length, "%s:", type[i]);
18478 +               for (j = 0; j < 3; j++) {
18479 +                       length += sprintf(buffer + length,
18480 +                               "\t%10lu/%-10lu",
18481 +                               vx_sock_count(cacct, i, j),
18482 +                               vx_sock_total(cacct, i, j));
18483 +               }
18484 +               buffer[length++] = '\n';
18485 +       }
18486 +
18487 +       length += sprintf(buffer + length, "\n");
18488 +       length += sprintf(buffer + length,
18489 +               "slab:\t %8u %8u %8u %8u\n",
18490 +               atomic_read(&cacct->slab[1]),
18491 +               atomic_read(&cacct->slab[4]),
18492 +               atomic_read(&cacct->slab[0]),
18493 +               atomic_read(&cacct->slab[2]));
18494 +
18495 +       length += sprintf(buffer + length, "\n");
18496 +       for (i = 0; i < 5; i++) {
18497 +               length += sprintf(buffer + length,
18498 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
18499 +                       atomic_read(&cacct->page[i][0]),
18500 +                       atomic_read(&cacct->page[i][1]),
18501 +                       atomic_read(&cacct->page[i][2]),
18502 +                       atomic_read(&cacct->page[i][3]),
18503 +                       atomic_read(&cacct->page[i][4]),
18504 +                       atomic_read(&cacct->page[i][5]),
18505 +                       atomic_read(&cacct->page[i][6]),
18506 +                       atomic_read(&cacct->page[i][7]));
18507 +       }
18508 +       return length;
18509 +}
18510 +
18511 +#endif /* _VX_CACCT_PROC_H */
18512 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/context.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/context.c
18513 --- linux-2.6.22.10/kernel/vserver/context.c    1970-01-01 01:00:00 +0100
18514 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/context.c  2007-10-01 15:47:53 +0200
18515 @@ -0,0 +1,1106 @@
18516 +/*
18517 + *  linux/kernel/vserver/context.c
18518 + *
18519 + *  Virtual Server: Context Support
18520 + *
18521 + *  Copyright (C) 2003-2007  Herbert Pötzl
18522 + *
18523 + *  V0.01  context helper
18524 + *  V0.02  vx_ctx_kill syscall command
18525 + *  V0.03  replaced context_info calls
18526 + *  V0.04  redesign of struct (de)alloc
18527 + *  V0.05  rlimit basic implementation
18528 + *  V0.06  task_xid and info commands
18529 + *  V0.07  context flags and caps
18530 + *  V0.08  switch to RCU based hash
18531 + *  V0.09  revert to non RCU for now
18532 + *  V0.10  and back to working RCU hash
18533 + *  V0.11  and back to locking again
18534 + *  V0.12  referenced context store
18535 + *  V0.13  separate per cpu data
18536 + *  V0.14  changed vcmds to vxi arg
18537 + *  V0.15  added context stat
18538 + *  V0.16  have __create claim() the vxi
18539 + *
18540 + */
18541 +
18542 +#include <linux/slab.h>
18543 +#include <linux/types.h>
18544 +#include <linux/mnt_namespace.h>
18545 +#include <linux/pid_namespace.h>
18546 +
18547 +#include <linux/sched.h>
18548 +#include <linux/vserver/context.h>
18549 +#include <linux/vserver/network.h>
18550 +#include <linux/vserver/legacy.h>
18551 +#include <linux/vserver/debug.h>
18552 +#include <linux/vserver/limit.h>
18553 +#include <linux/vserver/limit_int.h>
18554 +#include <linux/vserver/space.h>
18555 +
18556 +#include <linux/vs_context.h>
18557 +#include <linux/vs_limit.h>
18558 +#include <linux/vserver/context_cmd.h>
18559 +
18560 +#include <linux/err.h>
18561 +#include <asm/errno.h>
18562 +
18563 +#include "cvirt_init.h"
18564 +#include "cacct_init.h"
18565 +#include "limit_init.h"
18566 +#include "sched_init.h"
18567 +
18568 +
18569 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
18570 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
18571 +
18572 +
18573 +/*     now inactive context structures */
18574 +
18575 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
18576 +
18577 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
18578 +
18579 +
18580 +/*     __alloc_vx_info()
18581 +
18582 +       * allocate an initialized vx_info struct
18583 +       * doesn't make it visible (hash)                        */
18584 +
18585 +static struct vx_info *__alloc_vx_info(xid_t xid)
18586 +{
18587 +       struct vx_info *new = NULL;
18588 +       int cpu;
18589 +
18590 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
18591 +
18592 +       /* would this benefit from a slab cache? */
18593 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
18594 +       if (!new)
18595 +               return 0;
18596 +
18597 +       memset(new, 0, sizeof(struct vx_info));
18598 +#ifdef CONFIG_SMP
18599 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
18600 +       if (!new->ptr_pc)
18601 +               goto error;
18602 +#endif
18603 +       new->vx_id = xid;
18604 +       INIT_HLIST_NODE(&new->vx_hlist);
18605 +       atomic_set(&new->vx_usecnt, 0);
18606 +       atomic_set(&new->vx_tasks, 0);
18607 +       new->vx_parent = NULL;
18608 +       new->vx_state = 0;
18609 +       init_waitqueue_head(&new->vx_wait);
18610 +
18611 +       /* prepare reaper */
18612 +       get_task_struct(init_pid_ns.child_reaper);
18613 +       new->vx_reaper = init_pid_ns.child_reaper;
18614 +
18615 +       /* rest of init goes here */
18616 +       vx_info_init_limit(&new->limit);
18617 +       vx_info_init_sched(&new->sched);
18618 +       vx_info_init_cvirt(&new->cvirt);
18619 +       vx_info_init_cacct(&new->cacct);
18620 +
18621 +       /* per cpu data structures */
18622 +       for_each_possible_cpu(cpu) {
18623 +               vx_info_init_sched_pc(
18624 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
18625 +               vx_info_init_cvirt_pc(
18626 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
18627 +       }
18628 +
18629 +       new->vx_flags = VXF_INIT_SET;
18630 +       new->vx_bcaps = CAP_INIT_EFF_SET;
18631 +       new->vx_ccaps = 0;
18632 +       new->vx_cap_bset = cap_bset;
18633 +
18634 +       new->reboot_cmd = 0;
18635 +       new->exit_code = 0;
18636 +
18637 +       vxdprintk(VXD_CBIT(xid, 0),
18638 +               "alloc_vx_info(%d) = %p", xid, new);
18639 +       vxh_alloc_vx_info(new);
18640 +       atomic_inc(&vx_global_ctotal);
18641 +       return new;
18642 +#ifdef CONFIG_SMP
18643 +error:
18644 +       kfree(new);
18645 +       return 0;
18646 +#endif
18647 +}
18648 +
18649 +/*     __dealloc_vx_info()
18650 +
18651 +       * final disposal of vx_info                             */
18652 +
18653 +static void __dealloc_vx_info(struct vx_info *vxi)
18654 +{
18655 +       int cpu;
18656 +
18657 +       vxdprintk(VXD_CBIT(xid, 0),
18658 +               "dealloc_vx_info(%p)", vxi);
18659 +       vxh_dealloc_vx_info(vxi);
18660 +
18661 +       vxi->vx_id = -1;
18662 +
18663 +       vx_info_exit_limit(&vxi->limit);
18664 +       vx_info_exit_sched(&vxi->sched);
18665 +       vx_info_exit_cvirt(&vxi->cvirt);
18666 +       vx_info_exit_cacct(&vxi->cacct);
18667 +
18668 +       for_each_possible_cpu(cpu) {
18669 +               vx_info_exit_sched_pc(
18670 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
18671 +               vx_info_exit_cvirt_pc(
18672 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
18673 +       }
18674 +
18675 +       vxi->vx_state |= VXS_RELEASED;
18676 +
18677 +#ifdef CONFIG_SMP
18678 +       free_percpu(vxi->ptr_pc);
18679 +#endif
18680 +       kfree(vxi);
18681 +       atomic_dec(&vx_global_ctotal);
18682 +}
18683 +
18684 +static void __shutdown_vx_info(struct vx_info *vxi)
18685 +{
18686 +       struct nsproxy *nsproxy;
18687 +       struct fs_struct *fs;
18688 +
18689 +       might_sleep();
18690 +
18691 +       vxi->vx_state |= VXS_SHUTDOWN;
18692 +       vs_state_change(vxi, VSC_SHUTDOWN);
18693 +
18694 +       nsproxy = xchg(&vxi->vx_nsproxy, NULL);
18695 +       fs = xchg(&vxi->vx_fs, NULL);
18696 +
18697 +       if (nsproxy)
18698 +               put_nsproxy(nsproxy);
18699 +       if (fs)
18700 +               put_fs_struct(fs);
18701 +}
18702 +
18703 +/* exported stuff */
18704 +
18705 +void free_vx_info(struct vx_info *vxi)
18706 +{
18707 +       unsigned long flags;
18708 +
18709 +       /* check for reference counts first */
18710 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
18711 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18712 +
18713 +       /* context must not be hashed */
18714 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18715 +
18716 +       /* context shutdown is mandatory */
18717 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
18718 +
18719 +       BUG_ON(vxi->vx_nsproxy);
18720 +       BUG_ON(vxi->vx_fs);
18721 +
18722 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18723 +       hlist_del(&vxi->vx_hlist);
18724 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18725 +
18726 +       __dealloc_vx_info(vxi);
18727 +}
18728 +
18729 +
18730 +/*     hash table for vx_info hash */
18731 +
18732 +#define VX_HASH_SIZE   13
18733 +
18734 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
18735 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
18736 +
18737 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
18738 +
18739 +
18740 +static inline unsigned int __hashval(xid_t xid)
18741 +{
18742 +       return (xid % VX_HASH_SIZE);
18743 +}
18744 +
18745 +
18746 +
18747 +/*     __hash_vx_info()
18748 +
18749 +       * add the vxi to the global hash table
18750 +       * requires the hash_lock to be held                     */
18751 +
18752 +static inline void __hash_vx_info(struct vx_info *vxi)
18753 +{
18754 +       struct hlist_head *head;
18755 +
18756 +       vxd_assert_lock(&vx_info_hash_lock);
18757 +       vxdprintk(VXD_CBIT(xid, 4),
18758 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
18759 +       vxh_hash_vx_info(vxi);
18760 +
18761 +       /* context must not be hashed */
18762 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18763 +
18764 +       vxi->vx_state |= VXS_HASHED;
18765 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
18766 +       hlist_add_head(&vxi->vx_hlist, head);
18767 +       atomic_inc(&vx_global_cactive);
18768 +}
18769 +
18770 +/*     __unhash_vx_info()
18771 +
18772 +       * remove the vxi from the global hash table
18773 +       * requires the hash_lock to be held                     */
18774 +
18775 +static inline void __unhash_vx_info(struct vx_info *vxi)
18776 +{
18777 +       unsigned long flags;
18778 +
18779 +       vxd_assert_lock(&vx_info_hash_lock);
18780 +       vxdprintk(VXD_CBIT(xid, 4),
18781 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
18782 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
18783 +       vxh_unhash_vx_info(vxi);
18784 +
18785 +       /* context must be hashed */
18786 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
18787 +       /* but without tasks */
18788 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18789 +
18790 +       vxi->vx_state &= ~VXS_HASHED;
18791 +       hlist_del_init(&vxi->vx_hlist);
18792 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18793 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
18794 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18795 +       atomic_dec(&vx_global_cactive);
18796 +}
18797 +
18798 +
18799 +/*     __lookup_vx_info()
18800 +
18801 +       * requires the hash_lock to be held
18802 +       * doesn't increment the vx_refcnt                       */
18803 +
18804 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
18805 +{
18806 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
18807 +       struct hlist_node *pos;
18808 +       struct vx_info *vxi;
18809 +
18810 +       vxd_assert_lock(&vx_info_hash_lock);
18811 +       hlist_for_each(pos, head) {
18812 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18813 +
18814 +               if (vxi->vx_id == xid)
18815 +                       goto found;
18816 +       }
18817 +       vxi = NULL;
18818 +found:
18819 +       vxdprintk(VXD_CBIT(xid, 0),
18820 +               "__lookup_vx_info(#%u): %p[#%u]",
18821 +               xid, vxi, vxi ? vxi->vx_id : 0);
18822 +       vxh_lookup_vx_info(vxi, xid);
18823 +       return vxi;
18824 +}
18825 +
18826 +
18827 +/*     __vx_dynamic_id()
18828 +
18829 +       * find unused dynamic xid
18830 +       * requires the hash_lock to be held                     */
18831 +
18832 +static inline xid_t __vx_dynamic_id(void)
18833 +{
18834 +       static xid_t seq = MAX_S_CONTEXT;
18835 +       xid_t barrier = seq;
18836 +
18837 +       vxd_assert_lock(&vx_info_hash_lock);
18838 +       do {
18839 +               if (++seq > MAX_S_CONTEXT)
18840 +                       seq = MIN_D_CONTEXT;
18841 +               if (!__lookup_vx_info(seq)) {
18842 +                       vxdprintk(VXD_CBIT(xid, 4),
18843 +                               "__vx_dynamic_id: [#%d]", seq);
18844 +                       return seq;
18845 +               }
18846 +       } while (barrier != seq);
18847 +       return 0;
18848 +}
18849 +
18850 +#ifdef CONFIG_VSERVER_LEGACY
18851 +
18852 +/*     __loc_vx_info()
18853 +
18854 +       * locate or create the requested context
18855 +       * get() it and if new hash it                           */
18856 +
18857 +static struct vx_info *__loc_vx_info(int id, int *err)
18858 +{
18859 +       struct vx_info *new, *vxi = NULL;
18860 +
18861 +       vxdprintk(VXD_CBIT(xid, 1), "loc_vx_info(%d)*", id);
18862 +
18863 +       if (!(new = __alloc_vx_info(id))) {
18864 +               *err = -ENOMEM;
18865 +               return NULL;
18866 +       }
18867 +
18868 +       /* required to make dynamic xids unique */
18869 +       spin_lock(&vx_info_hash_lock);
18870 +
18871 +       /* dynamic context requested */
18872 +       if (id == VX_DYNAMIC_ID) {
18873 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
18874 +               id = __vx_dynamic_id();
18875 +               if (!id) {
18876 +                       printk(KERN_ERR "no dynamic context available.\n");
18877 +                       goto out_unlock;
18878 +               }
18879 +               new->vx_id = id;
18880 +#else
18881 +               printk(KERN_ERR "dynamic contexts disabled.\n");
18882 +               goto out_unlock;
18883 +#endif
18884 +       }
18885 +       /* existing context requested */
18886 +       else if ((vxi = __lookup_vx_info(id))) {
18887 +               /* context in setup is not available */
18888 +               if (vxi->vx_flags & VXF_STATE_SETUP) {
18889 +                       vxdprintk(VXD_CBIT(xid, 0),
18890 +                               "loc_vx_info(%d) = %p (not available)", id, vxi);
18891 +                       vxi = NULL;
18892 +                       *err = -EBUSY;
18893 +               } else {
18894 +                       vxdprintk(VXD_CBIT(xid, 0),
18895 +                               "loc_vx_info(%d) = %p (found)", id, vxi);
18896 +                       get_vx_info(vxi);
18897 +                       *err = 0;
18898 +               }
18899 +               goto out_unlock;
18900 +       }
18901 +
18902 +       /* new context requested */
18903 +       vxdprintk(VXD_CBIT(xid, 0),
18904 +               "loc_vx_info(%d) = %p (new)", id, new);
18905 +       __hash_vx_info(get_vx_info(new));
18906 +       vxi = new, new = NULL;
18907 +       *err = 1;
18908 +
18909 +out_unlock:
18910 +       spin_unlock(&vx_info_hash_lock);
18911 +       vxh_loc_vx_info(vxi, id);
18912 +       if (new)
18913 +               __dealloc_vx_info(new);
18914 +       return vxi;
18915 +}
18916 +
18917 +#endif
18918 +
18919 +/*     __create_vx_info()
18920 +
18921 +       * create the requested context
18922 +       * get(), claim() and hash it                            */
18923 +
18924 +static struct vx_info *__create_vx_info(int id)
18925 +{
18926 +       struct vx_info *new, *vxi = NULL;
18927 +
18928 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18929 +
18930 +       if (!(new = __alloc_vx_info(id)))
18931 +               return ERR_PTR(-ENOMEM);
18932 +
18933 +       /* required to make dynamic xids unique */
18934 +       spin_lock(&vx_info_hash_lock);
18935 +
18936 +       /* dynamic context requested */
18937 +       if (id == VX_DYNAMIC_ID) {
18938 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
18939 +               id = __vx_dynamic_id();
18940 +               if (!id) {
18941 +                       printk(KERN_ERR "no dynamic context available.\n");
18942 +                       vxi = ERR_PTR(-EAGAIN);
18943 +                       goto out_unlock;
18944 +               }
18945 +               new->vx_id = id;
18946 +#else
18947 +               printk(KERN_ERR "dynamic contexts disabled.\n");
18948 +               vxi = ERR_PTR(-EINVAL);
18949 +               goto out_unlock;
18950 +#endif
18951 +       }
18952 +       /* static context requested */
18953 +       else if ((vxi = __lookup_vx_info(id))) {
18954 +               vxdprintk(VXD_CBIT(xid, 0),
18955 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18956 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18957 +                       vxi = ERR_PTR(-EBUSY);
18958 +               else
18959 +                       vxi = ERR_PTR(-EEXIST);
18960 +               goto out_unlock;
18961 +       }
18962 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
18963 +       /* dynamic xid creation blocker */
18964 +       else if (id >= MIN_D_CONTEXT) {
18965 +               vxdprintk(VXD_CBIT(xid, 0),
18966 +                       "create_vx_info(%d) (dynamic rejected)", id);
18967 +               vxi = ERR_PTR(-EINVAL);
18968 +               goto out_unlock;
18969 +       }
18970 +#endif
18971 +
18972 +       /* new context */
18973 +       vxdprintk(VXD_CBIT(xid, 0),
18974 +               "create_vx_info(%d) = %p (new)", id, new);
18975 +       claim_vx_info(new, NULL);
18976 +       __hash_vx_info(get_vx_info(new));
18977 +       vxi = new, new = NULL;
18978 +
18979 +out_unlock:
18980 +       spin_unlock(&vx_info_hash_lock);
18981 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18982 +       if (new)
18983 +               __dealloc_vx_info(new);
18984 +       return vxi;
18985 +}
18986 +
18987 +
18988 +/*     exported stuff                                          */
18989 +
18990 +
18991 +void unhash_vx_info(struct vx_info *vxi)
18992 +{
18993 +       __shutdown_vx_info(vxi);
18994 +       spin_lock(&vx_info_hash_lock);
18995 +       __unhash_vx_info(vxi);
18996 +       spin_unlock(&vx_info_hash_lock);
18997 +       __wakeup_vx_info(vxi);
18998 +}
18999 +
19000 +
19001 +/*     lookup_vx_info()
19002 +
19003 +       * search for a vx_info and get() it
19004 +       * negative id means current                             */
19005 +
19006 +struct vx_info *lookup_vx_info(int id)
19007 +{
19008 +       struct vx_info *vxi = NULL;
19009 +
19010 +       if (id < 0) {
19011 +               vxi = get_vx_info(current->vx_info);
19012 +       } else if (id > 1) {
19013 +               spin_lock(&vx_info_hash_lock);
19014 +               vxi = get_vx_info(__lookup_vx_info(id));
19015 +               spin_unlock(&vx_info_hash_lock);
19016 +       }
19017 +       return vxi;
19018 +}
19019 +
19020 +/*     xid_is_hashed()
19021 +
19022 +       * verify that xid is still hashed                       */
19023 +
19024 +int xid_is_hashed(xid_t xid)
19025 +{
19026 +       int hashed;
19027 +
19028 +       spin_lock(&vx_info_hash_lock);
19029 +       hashed = (__lookup_vx_info(xid) != NULL);
19030 +       spin_unlock(&vx_info_hash_lock);
19031 +       return hashed;
19032 +}
19033 +
19034 +#ifdef CONFIG_VSERVER_LEGACY
19035 +
19036 +struct vx_info *lookup_or_create_vx_info(int id)
19037 +{
19038 +       int err;
19039 +
19040 +       return __loc_vx_info(id, &err);
19041 +}
19042 +
19043 +#endif
19044 +
19045 +#ifdef CONFIG_PROC_FS
19046 +
19047 +/*     get_xid_list()
19048 +
19049 +       * get a subset of hashed xids for proc
19050 +       * assumes size is at least one                          */
19051 +
19052 +int get_xid_list(int index, unsigned int *xids, int size)
19053 +{
19054 +       int hindex, nr_xids = 0;
19055 +
19056 +       /* only show current and children */
19057 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
19058 +               if (index > 0)
19059 +                       return 0;
19060 +               xids[nr_xids] = vx_current_xid();
19061 +               return 1;
19062 +       }
19063 +
19064 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
19065 +               struct hlist_head *head = &vx_info_hash[hindex];
19066 +               struct hlist_node *pos;
19067 +
19068 +               spin_lock(&vx_info_hash_lock);
19069 +               hlist_for_each(pos, head) {
19070 +                       struct vx_info *vxi;
19071 +
19072 +                       if (--index > 0)
19073 +                               continue;
19074 +
19075 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
19076 +                       xids[nr_xids] = vxi->vx_id;
19077 +                       if (++nr_xids >= size) {
19078 +                               spin_unlock(&vx_info_hash_lock);
19079 +                               goto out;
19080 +                       }
19081 +               }
19082 +               /* keep the lock time short */
19083 +               spin_unlock(&vx_info_hash_lock);
19084 +       }
19085 +out:
19086 +       return nr_xids;
19087 +}
19088 +#endif
19089 +
19090 +#ifdef CONFIG_VSERVER_DEBUG
19091 +
19092 +void   dump_vx_info_inactive(int level)
19093 +{
19094 +       struct hlist_node *entry, *next;
19095 +
19096 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
19097 +               struct vx_info *vxi =
19098 +                       list_entry(entry, struct vx_info, vx_hlist);
19099 +
19100 +               dump_vx_info(vxi, level);
19101 +       }
19102 +}
19103 +
19104 +#endif
19105 +
19106 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
19107 +{
19108 +       struct user_struct *new_user, *old_user;
19109 +
19110 +       if (!p || !vxi)
19111 +               BUG();
19112 +
19113 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
19114 +               return -EACCES;
19115 +
19116 +       new_user = alloc_uid(vxi->vx_id, p->uid);
19117 +       if (!new_user)
19118 +               return -ENOMEM;
19119 +
19120 +       old_user = p->user;
19121 +       if (new_user != old_user) {
19122 +               atomic_inc(&new_user->processes);
19123 +               atomic_dec(&old_user->processes);
19124 +               p->user = new_user;
19125 +       }
19126 +       free_uid(old_user);
19127 +       return 0;
19128 +}
19129 +
19130 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
19131 +{
19132 +       p->cap_effective &= vxi->vx_cap_bset;
19133 +       p->cap_inheritable &= vxi->vx_cap_bset;
19134 +       p->cap_permitted &= vxi->vx_cap_bset;
19135 +}
19136 +
19137 +
19138 +#include <linux/file.h>
19139 +
19140 +static int vx_openfd_task(struct task_struct *tsk)
19141 +{
19142 +       struct files_struct *files = tsk->files;
19143 +       struct fdtable *fdt;
19144 +       const unsigned long *bptr;
19145 +       int count, total;
19146 +
19147 +       /* no rcu_read_lock() because of spin_lock() */
19148 +       spin_lock(&files->file_lock);
19149 +       fdt = files_fdtable(files);
19150 +       bptr = fdt->open_fds->fds_bits;
19151 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
19152 +       for (total = 0; count > 0; count--) {
19153 +               if (*bptr)
19154 +                       total += hweight_long(*bptr);
19155 +               bptr++;
19156 +       }
19157 +       spin_unlock(&files->file_lock);
19158 +       return total;
19159 +}
19160 +
19161 +
19162 +/*     for *space compatibility */
19163 +
19164 +asmlinkage long sys_unshare(unsigned long);
19165 +
19166 +/*
19167 + *     migrate task to new context
19168 + *     gets vxi, puts old_vxi on change
19169 + *     optionally unshares namespaces (hack)
19170 + */
19171 +
19172 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
19173 +{
19174 +       struct vx_info *old_vxi;
19175 +       int ret = 0;
19176 +
19177 +       if (!p || !vxi)
19178 +               BUG();
19179 +
19180 +       vxdprintk(VXD_CBIT(xid, 5),
19181 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
19182 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
19183 +
19184 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
19185 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
19186 +               return -EACCES;
19187 +
19188 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
19189 +               return -EFAULT;
19190 +
19191 +       old_vxi = task_get_vx_info(p);
19192 +       if (old_vxi == vxi)
19193 +               goto out;
19194 +
19195 +       if (!(ret = vx_migrate_user(p, vxi))) {
19196 +               int openfd;
19197 +
19198 +               task_lock(p);
19199 +               openfd = vx_openfd_task(p);
19200 +
19201 +               if (old_vxi) {
19202 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
19203 +                       atomic_dec(&old_vxi->cvirt.nr_running);
19204 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
19205 +                       /* FIXME: what about the struct files here? */
19206 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
19207 +                       /* account for the executable */
19208 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
19209 +               }
19210 +               atomic_inc(&vxi->cvirt.nr_threads);
19211 +               atomic_inc(&vxi->cvirt.nr_running);
19212 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
19213 +               /* FIXME: what about the struct files here? */
19214 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
19215 +               /* account for the executable */
19216 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
19217 +
19218 +               if (old_vxi) {
19219 +                       release_vx_info(old_vxi, p);
19220 +                       clr_vx_info(&p->vx_info);
19221 +               }
19222 +               claim_vx_info(vxi, p);
19223 +               set_vx_info(&p->vx_info, vxi);
19224 +               p->xid = vxi->vx_id;
19225 +
19226 +               vxdprintk(VXD_CBIT(xid, 5),
19227 +                       "moved task %p into vxi:%p[#%d]",
19228 +                       p, vxi, vxi->vx_id);
19229 +
19230 +               vx_mask_cap_bset(vxi, p);
19231 +               task_unlock(p);
19232 +
19233 +               /* hack for *spaces to provide compatibility */
19234 +               if (unshare) {
19235 +                       struct nsproxy *old_nsp, *new_nsp;
19236 +
19237 +                       ret = unshare_nsproxy_namespaces(
19238 +                               CLONE_NEWUTS | CLONE_NEWIPC,
19239 +                               &new_nsp, NULL);
19240 +                       if (ret)
19241 +                               goto out;
19242 +
19243 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
19244 +                       vx_set_space(vxi, CLONE_NEWUTS | CLONE_NEWIPC);
19245 +                       put_nsproxy(old_nsp);
19246 +               }
19247 +       }
19248 +out:
19249 +       put_vx_info(old_vxi);
19250 +       return ret;
19251 +}
19252 +
19253 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
19254 +{
19255 +       struct task_struct *old_reaper;
19256 +
19257 +       if (!vxi)
19258 +               return -EINVAL;
19259 +
19260 +       vxdprintk(VXD_CBIT(xid, 6),
19261 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
19262 +               vxi, vxi->vx_id, p, p->xid, p->pid);
19263 +
19264 +       old_reaper = vxi->vx_reaper;
19265 +       if (old_reaper == p)
19266 +               return 0;
19267 +
19268 +       /* set new child reaper */
19269 +       get_task_struct(p);
19270 +       vxi->vx_reaper = p;
19271 +       put_task_struct(old_reaper);
19272 +       return 0;
19273 +}
19274 +
19275 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
19276 +{
19277 +       if (!vxi)
19278 +               return -EINVAL;
19279 +
19280 +       vxdprintk(VXD_CBIT(xid, 6),
19281 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
19282 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
19283 +
19284 +       vxi->vx_flags &= ~VXF_STATE_INIT;
19285 +       vxi->vx_initpid = p->tgid;
19286 +       return 0;
19287 +}
19288 +
19289 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
19290 +{
19291 +       vxdprintk(VXD_CBIT(xid, 6),
19292 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
19293 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
19294 +
19295 +       vxi->exit_code = code;
19296 +       vxi->vx_initpid = 0;
19297 +}
19298 +
19299 +
19300 +void vx_set_persistent(struct vx_info *vxi)
19301 +{
19302 +       vxdprintk(VXD_CBIT(xid, 6),
19303 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
19304 +
19305 +       get_vx_info(vxi);
19306 +       claim_vx_info(vxi, NULL);
19307 +}
19308 +
19309 +void vx_clear_persistent(struct vx_info *vxi)
19310 +{
19311 +       vxdprintk(VXD_CBIT(xid, 6),
19312 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
19313 +
19314 +       release_vx_info(vxi, NULL);
19315 +       put_vx_info(vxi);
19316 +}
19317 +
19318 +void vx_update_persistent(struct vx_info *vxi)
19319 +{
19320 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
19321 +               vx_set_persistent(vxi);
19322 +       else
19323 +               vx_clear_persistent(vxi);
19324 +}
19325 +
19326 +
19327 +/*     task must be current or locked          */
19328 +
19329 +void   exit_vx_info(struct task_struct *p, int code)
19330 +{
19331 +       struct vx_info *vxi = p->vx_info;
19332 +
19333 +       if (vxi) {
19334 +               atomic_dec(&vxi->cvirt.nr_threads);
19335 +               vx_nproc_dec(p);
19336 +
19337 +               vxi->exit_code = code;
19338 +               release_vx_info(vxi, p);
19339 +       }
19340 +}
19341 +
19342 +void   exit_vx_info_early(struct task_struct *p, int code)
19343 +{
19344 +       struct vx_info *vxi = p->vx_info;
19345 +
19346 +       if (vxi) {
19347 +               if (vxi->vx_initpid == p->tgid)
19348 +                       vx_exit_init(vxi, p, code);
19349 +               if (vxi->vx_reaper == p)
19350 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
19351 +       }
19352 +}
19353 +
19354 +
19355 +/* vserver syscall commands below here */
19356 +
19357 +/* taks xid and vx_info functions */
19358 +
19359 +#include <asm/uaccess.h>
19360 +
19361 +
19362 +int vc_task_xid(uint32_t id, void __user *data)
19363 +{
19364 +       xid_t xid;
19365 +
19366 +       if (id) {
19367 +               struct task_struct *tsk;
19368 +
19369 +               if (!vx_check(0, VS_ADMIN | VS_WATCH))
19370 +                       return -EPERM;
19371 +
19372 +               read_lock(&tasklist_lock);
19373 +               tsk = find_task_by_real_pid(id);
19374 +               xid = (tsk) ? tsk->xid : -ESRCH;
19375 +               read_unlock(&tasklist_lock);
19376 +       } else
19377 +               xid = vx_current_xid();
19378 +       return xid;
19379 +}
19380 +
19381 +
19382 +int vc_vx_info(struct vx_info *vxi, void __user *data)
19383 +{
19384 +       struct vcmd_vx_info_v0 vc_data;
19385 +
19386 +       vc_data.xid = vxi->vx_id;
19387 +       vc_data.initpid = vxi->vx_initpid;
19388 +
19389 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19390 +               return -EFAULT;
19391 +       return 0;
19392 +}
19393 +
19394 +
19395 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
19396 +{
19397 +       struct vcmd_ctx_stat_v0 vc_data;
19398 +
19399 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
19400 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
19401 +
19402 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19403 +               return -EFAULT;
19404 +       return 0;
19405 +}
19406 +
19407 +
19408 +/* context functions */
19409 +
19410 +int vc_ctx_create(uint32_t xid, void __user *data)
19411 +{
19412 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
19413 +       struct vx_info *new_vxi;
19414 +       int ret;
19415 +
19416 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19417 +               return -EFAULT;
19418 +
19419 +       if ((xid > MAX_S_CONTEXT) && (xid != VX_DYNAMIC_ID))
19420 +               return -EINVAL;
19421 +       if (xid < 2)
19422 +               return -EINVAL;
19423 +
19424 +       new_vxi = __create_vx_info(xid);
19425 +       if (IS_ERR(new_vxi))
19426 +               return PTR_ERR(new_vxi);
19427 +
19428 +       /* initial flags */
19429 +       new_vxi->vx_flags = vc_data.flagword;
19430 +
19431 +       ret = -ENOEXEC;
19432 +       if (vs_state_change(new_vxi, VSC_STARTUP))
19433 +               goto out;
19434 +
19435 +       ret = vx_migrate_task(current, new_vxi, (!data));
19436 +       if (ret)
19437 +               goto out;
19438 +
19439 +       /* return context id on success */
19440 +       ret = new_vxi->vx_id;
19441 +
19442 +       /* get a reference for persistent contexts */
19443 +       if ((vc_data.flagword & VXF_PERSISTENT))
19444 +               vx_set_persistent(new_vxi);
19445 +out:
19446 +       release_vx_info(new_vxi, NULL);
19447 +       put_vx_info(new_vxi);
19448 +       return ret;
19449 +}
19450 +
19451 +
19452 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
19453 +{
19454 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
19455 +       int ret;
19456 +
19457 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19458 +               return -EFAULT;
19459 +
19460 +       ret = vx_migrate_task(current, vxi, 0);
19461 +       if (ret)
19462 +               return ret;
19463 +       if (vc_data.flagword & VXM_SET_INIT)
19464 +               ret = vx_set_init(vxi, current);
19465 +       if (ret)
19466 +               return ret;
19467 +       if (vc_data.flagword & VXM_SET_REAPER)
19468 +               ret = vx_set_reaper(vxi, current);
19469 +       return ret;
19470 +}
19471 +
19472 +
19473 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
19474 +{
19475 +       struct vcmd_ctx_flags_v0 vc_data;
19476 +
19477 +       vc_data.flagword = vxi->vx_flags;
19478 +
19479 +       /* special STATE flag handling */
19480 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
19481 +
19482 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19483 +               return -EFAULT;
19484 +       return 0;
19485 +}
19486 +
19487 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
19488 +{
19489 +       struct vcmd_ctx_flags_v0 vc_data;
19490 +       uint64_t mask, trigger;
19491 +
19492 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19493 +               return -EFAULT;
19494 +
19495 +       /* special STATE flag handling */
19496 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
19497 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
19498 +
19499 +       if (vxi == current->vx_info) {
19500 +               if (trigger & VXF_STATE_SETUP)
19501 +                       vx_mask_cap_bset(vxi, current);
19502 +               if (trigger & VXF_STATE_INIT) {
19503 +                       int ret;
19504 +
19505 +                       ret = vx_set_init(vxi, current);
19506 +                       if (ret)
19507 +                               return ret;
19508 +                       ret = vx_set_reaper(vxi, current);
19509 +                       if (ret)
19510 +                               return ret;
19511 +               }
19512 +       }
19513 +
19514 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
19515 +               vc_data.flagword, mask);
19516 +       if (trigger & VXF_PERSISTENT)
19517 +               vx_update_persistent(vxi);
19518 +
19519 +       return 0;
19520 +}
19521 +
19522 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
19523 +{
19524 +       if (bcaps)
19525 +               *bcaps = vxi->vx_bcaps;
19526 +       if (ccaps)
19527 +               *ccaps = vxi->vx_ccaps;
19528 +
19529 +       return 0;
19530 +}
19531 +
19532 +int vc_get_ccaps_v0(struct vx_info *vxi, void __user *data)
19533 +{
19534 +       struct vcmd_ctx_caps_v0 vc_data;
19535 +       int ret;
19536 +
19537 +       ret = do_get_caps(vxi, &vc_data.bcaps, &vc_data.ccaps);
19538 +       if (ret)
19539 +               return ret;
19540 +       vc_data.cmask = ~0ULL;
19541 +
19542 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19543 +               return -EFAULT;
19544 +       return 0;
19545 +}
19546 +
19547 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
19548 +{
19549 +       struct vcmd_ctx_caps_v1 vc_data;
19550 +       int ret;
19551 +
19552 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
19553 +       if (ret)
19554 +               return ret;
19555 +       vc_data.cmask = ~0ULL;
19556 +
19557 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19558 +               return -EFAULT;
19559 +       return 0;
19560 +}
19561 +
19562 +static int do_set_caps(struct vx_info *vxi,
19563 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
19564 +{
19565 +       vxi->vx_bcaps = vs_mask_flags(vxi->vx_bcaps, bcaps, bmask);
19566 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
19567 +
19568 +       return 0;
19569 +}
19570 +
19571 +int vc_set_ccaps_v0(struct vx_info *vxi, void __user *data)
19572 +{
19573 +       struct vcmd_ctx_caps_v0 vc_data;
19574 +
19575 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19576 +               return -EFAULT;
19577 +
19578 +       /* simulate old &= behaviour for bcaps */
19579 +       return do_set_caps(vxi, 0, ~vc_data.bcaps,
19580 +               vc_data.ccaps, vc_data.cmask);
19581 +}
19582 +
19583 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
19584 +{
19585 +       struct vcmd_ctx_caps_v1 vc_data;
19586 +
19587 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19588 +               return -EFAULT;
19589 +
19590 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
19591 +}
19592 +
19593 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
19594 +{
19595 +       struct vcmd_bcaps vc_data;
19596 +       int ret;
19597 +
19598 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
19599 +       if (ret)
19600 +               return ret;
19601 +       vc_data.bmask = ~0ULL;
19602 +
19603 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19604 +               return -EFAULT;
19605 +       return 0;
19606 +}
19607 +
19608 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
19609 +{
19610 +       struct vcmd_bcaps vc_data;
19611 +
19612 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19613 +               return -EFAULT;
19614 +
19615 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
19616 +}
19617 +
19618 +#include <linux/module.h>
19619 +
19620 +EXPORT_SYMBOL_GPL(free_vx_info);
19621 +
19622 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cvirt.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cvirt.c
19623 --- linux-2.6.22.10/kernel/vserver/cvirt.c      1970-01-01 01:00:00 +0100
19624 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cvirt.c    2007-06-15 02:37:04 +0200
19625 @@ -0,0 +1,304 @@
19626 +/*
19627 + *  linux/kernel/vserver/cvirt.c
19628 + *
19629 + *  Virtual Server: Context Virtualization
19630 + *
19631 + *  Copyright (C) 2004-2007  Herbert Pötzl
19632 + *
19633 + *  V0.01  broken out from limit.c
19634 + *  V0.02  added utsname stuff
19635 + *  V0.03  changed vcmds to vxi arg
19636 + *
19637 + */
19638 +
19639 +#include <linux/sched.h>
19640 +#include <linux/sysctl.h>
19641 +#include <linux/types.h>
19642 +#include <linux/vs_context.h>
19643 +#include <linux/vs_cvirt.h>
19644 +#include <linux/vserver/switch.h>
19645 +#include <linux/vserver/cvirt_cmd.h>
19646 +
19647 +#include <asm/errno.h>
19648 +#include <asm/uaccess.h>
19649 +
19650 +
19651 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
19652 +{
19653 +       struct vx_info *vxi = current->vx_info;
19654 +
19655 +       set_normalized_timespec(uptime,
19656 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
19657 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
19658 +       if (!idle)
19659 +               return;
19660 +       set_normalized_timespec(idle,
19661 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
19662 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
19663 +       return;
19664 +}
19665 +
19666 +uint64_t vx_idle_jiffies(void)
19667 +{
19668 +       return init_task.utime + init_task.stime;
19669 +}
19670 +
19671 +
19672 +
19673 +static inline uint32_t __update_loadavg(uint32_t load,
19674 +       int wsize, int delta, int n)
19675 +{
19676 +       unsigned long long calc, prev;
19677 +
19678 +       /* just set it to n */
19679 +       if (unlikely(delta >= wsize))
19680 +               return (n << FSHIFT);
19681 +
19682 +       calc = delta * n;
19683 +       calc <<= FSHIFT;
19684 +       prev = (wsize - delta);
19685 +       prev *= load;
19686 +       calc += prev;
19687 +       do_div(calc, wsize);
19688 +       return calc;
19689 +}
19690 +
19691 +
19692 +void vx_update_load(struct vx_info *vxi)
19693 +{
19694 +       uint32_t now, last, delta;
19695 +       unsigned int nr_running, nr_uninterruptible;
19696 +       unsigned int total;
19697 +       unsigned long flags;
19698 +
19699 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
19700 +
19701 +       now = jiffies;
19702 +       last = vxi->cvirt.load_last;
19703 +       delta = now - last;
19704 +
19705 +       if (delta < 5*HZ)
19706 +               goto out;
19707 +
19708 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
19709 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
19710 +       total = nr_running + nr_uninterruptible;
19711 +
19712 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
19713 +               60*HZ, delta, total);
19714 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
19715 +               5*60*HZ, delta, total);
19716 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
19717 +               15*60*HZ, delta, total);
19718 +
19719 +       vxi->cvirt.load_last = now;
19720 +out:
19721 +       atomic_inc(&vxi->cvirt.load_updates);
19722 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
19723 +}
19724 +
19725 +
19726 +/*
19727 + * Commands to do_syslog:
19728 + *
19729 + *      0 -- Close the log.  Currently a NOP.
19730 + *      1 -- Open the log. Currently a NOP.
19731 + *      2 -- Read from the log.
19732 + *      3 -- Read all messages remaining in the ring buffer.
19733 + *      4 -- Read and clear all messages remaining in the ring buffer
19734 + *      5 -- Clear ring buffer.
19735 + *      6 -- Disable printk's to console
19736 + *      7 -- Enable printk's to console
19737 + *      8 -- Set level of messages printed to console
19738 + *      9 -- Return number of unread characters in the log buffer
19739 + *     10 -- Return size of the log buffer
19740 + */
19741 +int vx_do_syslog(int type, char __user *buf, int len)
19742 +{
19743 +       int error = 0;
19744 +       int do_clear = 0;
19745 +       struct vx_info *vxi = current->vx_info;
19746 +       struct _vx_syslog *log;
19747 +
19748 +       if (!vxi)
19749 +               return -EINVAL;
19750 +       log = &vxi->cvirt.syslog;
19751 +
19752 +       switch (type) {
19753 +       case 0:         /* Close log */
19754 +       case 1:         /* Open log */
19755 +               break;
19756 +       case 2:         /* Read from log */
19757 +               error = wait_event_interruptible(log->log_wait,
19758 +                       (log->log_start - log->log_end));
19759 +               if (error)
19760 +                       break;
19761 +               spin_lock_irq(&log->logbuf_lock);
19762 +               spin_unlock_irq(&log->logbuf_lock);
19763 +               break;
19764 +       case 4:         /* Read/clear last kernel messages */
19765 +               do_clear = 1;
19766 +               /* fall through */
19767 +       case 3:         /* Read last kernel messages */
19768 +               return 0;
19769 +
19770 +       case 5:         /* Clear ring buffer */
19771 +               return 0;
19772 +
19773 +       case 6:         /* Disable logging to console */
19774 +       case 7:         /* Enable logging to console */
19775 +       case 8:         /* Set level of messages printed to console */
19776 +               break;
19777 +
19778 +       case 9:         /* Number of chars in the log buffer */
19779 +               return 0;
19780 +       case 10:        /* Size of the log buffer */
19781 +               return 0;
19782 +       default:
19783 +               error = -EINVAL;
19784 +               break;
19785 +       }
19786 +       return error;
19787 +}
19788 +
19789 +
19790 +/* virtual host info names */
19791 +
19792 +static char *vx_vhi_name(struct vx_info *vxi, int id)
19793 +{
19794 +       struct nsproxy *nsproxy;
19795 +       struct uts_namespace *uts;
19796 +
19797 +
19798 +       if (id == VHIN_CONTEXT)
19799 +               return vxi->vx_name;
19800 +
19801 +       nsproxy = vxi->vx_nsproxy;
19802 +       if (!nsproxy)
19803 +               return NULL;
19804 +
19805 +       uts = nsproxy->uts_ns;
19806 +       if (!uts)
19807 +               return NULL;
19808 +
19809 +       switch (id) {
19810 +       case VHIN_SYSNAME:
19811 +               return uts->name.sysname;
19812 +       case VHIN_NODENAME:
19813 +               return uts->name.nodename;
19814 +       case VHIN_RELEASE:
19815 +               return uts->name.release;
19816 +       case VHIN_VERSION:
19817 +               return uts->name.version;
19818 +       case VHIN_MACHINE:
19819 +               return uts->name.machine;
19820 +       case VHIN_DOMAINNAME:
19821 +               return uts->name.domainname;
19822 +       default:
19823 +               return NULL;
19824 +       }
19825 +       return NULL;
19826 +}
19827 +
19828 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
19829 +{
19830 +       struct vcmd_vhi_name_v0 vc_data;
19831 +       char *name;
19832 +
19833 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19834 +               return -EFAULT;
19835 +
19836 +       name = vx_vhi_name(vxi, vc_data.field);
19837 +       if (!name)
19838 +               return -EINVAL;
19839 +
19840 +       memcpy(name, vc_data.name, 65);
19841 +       return 0;
19842 +}
19843 +
19844 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
19845 +{
19846 +       struct vcmd_vhi_name_v0 vc_data;
19847 +       char *name;
19848 +
19849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19850 +               return -EFAULT;
19851 +
19852 +       name = vx_vhi_name(vxi, vc_data.field);
19853 +       if (!name)
19854 +               return -EINVAL;
19855 +
19856 +       memcpy(vc_data.name, name, 65);
19857 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19858 +               return -EFAULT;
19859 +       return 0;
19860 +}
19861 +
19862 +
19863 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
19864 +{
19865 +       struct vcmd_virt_stat_v0 vc_data;
19866 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
19867 +       struct timespec uptime;
19868 +
19869 +       do_posix_clock_monotonic_gettime(&uptime);
19870 +       set_normalized_timespec(&uptime,
19871 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
19872 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
19873 +
19874 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
19875 +       vc_data.uptime = timespec_to_ns(&uptime);
19876 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
19877 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
19878 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
19879 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
19880 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
19881 +       vc_data.load[0] = cvirt->load[0];
19882 +       vc_data.load[1] = cvirt->load[1];
19883 +       vc_data.load[2] = cvirt->load[2];
19884 +
19885 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19886 +               return -EFAULT;
19887 +       return 0;
19888 +}
19889 +
19890 +
19891 +#ifdef CONFIG_VSERVER_VTIME
19892 +
19893 +/* virtualized time base */
19894 +
19895 +void vx_gettimeofday(struct timeval *tv)
19896 +{
19897 +       do_gettimeofday(tv);
19898 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19899 +               return;
19900 +
19901 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
19902 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
19903 +
19904 +       if (tv->tv_usec >= USEC_PER_SEC) {
19905 +               tv->tv_sec++;
19906 +               tv->tv_usec -= USEC_PER_SEC;
19907 +       } else if (tv->tv_usec < 0) {
19908 +               tv->tv_sec--;
19909 +               tv->tv_usec += USEC_PER_SEC;
19910 +       }
19911 +}
19912 +
19913 +int vx_settimeofday(struct timespec *ts)
19914 +{
19915 +       struct timeval tv;
19916 +
19917 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19918 +               return do_settimeofday(ts);
19919 +
19920 +       do_gettimeofday(&tv);
19921 +       current->vx_info->cvirt.bias_tv.tv_sec =
19922 +               ts->tv_sec - tv.tv_sec;
19923 +       current->vx_info->cvirt.bias_tv.tv_usec =
19924 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
19925 +       return 0;
19926 +}
19927 +
19928 +#endif
19929 +
19930 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cvirt_init.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cvirt_init.h
19931 --- linux-2.6.22.10/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00 +0100
19932 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cvirt_init.h       2007-10-29 23:34:24 +0100
19933 @@ -0,0 +1,69 @@
19934 +
19935 +
19936 +extern uint64_t vx_idle_jiffies(void);
19937 +
19938 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19939 +{
19940 +       uint64_t idle_jiffies = vx_idle_jiffies();
19941 +       uint64_t nsuptime;
19942 +
19943 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19944 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19945 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19946 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19947 +       cvirt->bias_tv.tv_sec = 0;
19948 +       cvirt->bias_tv.tv_usec = 0;
19949 +
19950 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19951 +       atomic_set(&cvirt->nr_threads, 0);
19952 +       atomic_set(&cvirt->nr_running, 0);
19953 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19954 +       atomic_set(&cvirt->nr_onhold, 0);
19955 +
19956 +       spin_lock_init(&cvirt->load_lock);
19957 +       cvirt->load_last = jiffies;
19958 +       atomic_set(&cvirt->load_updates, 0);
19959 +       cvirt->load[0] = 0;
19960 +       cvirt->load[1] = 0;
19961 +       cvirt->load[2] = 0;
19962 +       atomic_set(&cvirt->total_forks, 0);
19963 +
19964 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19965 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19966 +       cvirt->syslog.log_start = 0;
19967 +       cvirt->syslog.log_end = 0;
19968 +       cvirt->syslog.con_start = 0;
19969 +       cvirt->syslog.logged_chars = 0;
19970 +}
19971 +
19972 +static inline
19973 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19974 +{
19975 +       // cvirt_pc->cpustat = { 0 };
19976 +}
19977 +
19978 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19979 +{
19980 +       int value;
19981 +
19982 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19983 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19984 +               cvirt, value);
19985 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19986 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19987 +               cvirt, value);
19988 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19989 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19990 +               cvirt, value);
19991 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19992 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19993 +               cvirt, value);
19994 +       return;
19995 +}
19996 +
19997 +static inline
19998 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19999 +{
20000 +       return;
20001 +}
20002 +
20003 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/cvirt_proc.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cvirt_proc.h
20004 --- linux-2.6.22.10/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00 +0100
20005 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/cvirt_proc.h       2007-06-15 02:37:04 +0200
20006 @@ -0,0 +1,133 @@
20007 +#ifndef _VX_CVIRT_PROC_H
20008 +#define _VX_CVIRT_PROC_H
20009 +
20010 +#include <linux/nsproxy.h>
20011 +#include <linux/mnt_namespace.h>
20012 +#include <linux/utsname.h>
20013 +#include <linux/ipc.h>
20014 +
20015 +
20016 +static inline
20017 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
20018 +{
20019 +       struct mnt_namespace *ns;
20020 +       struct uts_namespace *uts;
20021 +       struct ipc_namespace *ipc;
20022 +       struct vfsmount *mnt;
20023 +       char *path, *root;
20024 +       int length = 0;
20025 +
20026 +       if (!nsproxy)
20027 +               goto out;
20028 +
20029 +       length += sprintf(buffer + length,
20030 +               "NSProxy:\t%p [%p,%p,%p]\n",
20031 +               nsproxy, nsproxy->mnt_ns,
20032 +               nsproxy->uts_ns, nsproxy->ipc_ns);
20033 +
20034 +       ns = nsproxy->mnt_ns;
20035 +       if (!ns)
20036 +               goto skip_ns;
20037 +
20038 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
20039 +       if (!path)
20040 +               goto skip_ns;
20041 +
20042 +       mnt = ns->root;
20043 +       root = d_path(mnt->mnt_root, mnt->mnt_parent, path, PATH_MAX - 2);
20044 +       length += sprintf(buffer + length,
20045 +               "Namespace:\t%p [#%u]\n"
20046 +               "RootPath:\t%s\n",
20047 +               ns, atomic_read(&ns->count),
20048 +               root);
20049 +       kfree(path);
20050 +skip_ns:
20051 +
20052 +       uts = nsproxy->uts_ns;
20053 +       if (!uts)
20054 +               goto skip_uts;
20055 +
20056 +       length += sprintf(buffer + length,
20057 +               "SysName:\t%.*s\n"
20058 +               "NodeName:\t%.*s\n"
20059 +               "Release:\t%.*s\n"
20060 +               "Version:\t%.*s\n"
20061 +               "Machine:\t%.*s\n"
20062 +               "DomainName:\t%.*s\n",
20063 +               __NEW_UTS_LEN, uts->name.sysname,
20064 +               __NEW_UTS_LEN, uts->name.nodename,
20065 +               __NEW_UTS_LEN, uts->name.release,
20066 +               __NEW_UTS_LEN, uts->name.version,
20067 +               __NEW_UTS_LEN, uts->name.machine,
20068 +               __NEW_UTS_LEN, uts->name.domainname);
20069 +skip_uts:
20070 +
20071 +       ipc = nsproxy->ipc_ns;
20072 +       if (!ipc)
20073 +               goto skip_ipc;
20074 +
20075 +       length += sprintf(buffer + length,
20076 +               "SEMS:\t\t%d %d %d %d  %d\n"
20077 +               "MSG:\t\t%d %d %d\n"
20078 +               "SHM:\t\t%lu %lu  %d %d\n",
20079 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
20080 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
20081 +               ipc->used_sems,
20082 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
20083 +               (unsigned long)ipc->shm_ctlmax,
20084 +               (unsigned long)ipc->shm_ctlall,
20085 +               ipc->shm_ctlmni, ipc->shm_tot);
20086 +skip_ipc:
20087 +out:
20088 +       return length;
20089 +}
20090 +
20091 +
20092 +#include <linux/sched.h>
20093 +
20094 +#define LOAD_INT(x) ((x) >> FSHIFT)
20095 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
20096 +
20097 +static inline
20098 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
20099 +{
20100 +       int length = 0;
20101 +       int a, b, c;
20102 +
20103 +       length += sprintf(buffer + length,
20104 +               "BiasUptime:\t%lu.%02lu\n",
20105 +               (unsigned long)cvirt->bias_uptime.tv_sec,
20106 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
20107 +
20108 +       a = cvirt->load[0] + (FIXED_1 / 200);
20109 +       b = cvirt->load[1] + (FIXED_1 / 200);
20110 +       c = cvirt->load[2] + (FIXED_1 / 200);
20111 +       length += sprintf(buffer + length,
20112 +               "nr_threads:\t%d\n"
20113 +               "nr_running:\t%d\n"
20114 +               "nr_unintr:\t%d\n"
20115 +               "nr_onhold:\t%d\n"
20116 +               "load_updates:\t%d\n"
20117 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
20118 +               "total_forks:\t%d\n",
20119 +               atomic_read(&cvirt->nr_threads),
20120 +               atomic_read(&cvirt->nr_running),
20121 +               atomic_read(&cvirt->nr_uninterruptible),
20122 +               atomic_read(&cvirt->nr_onhold),
20123 +               atomic_read(&cvirt->load_updates),
20124 +               LOAD_INT(a), LOAD_FRAC(a),
20125 +               LOAD_INT(b), LOAD_FRAC(b),
20126 +               LOAD_INT(c), LOAD_FRAC(c),
20127 +               atomic_read(&cvirt->total_forks));
20128 +       return length;
20129 +}
20130 +
20131 +static inline
20132 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
20133 +       char *buffer, int cpu)
20134 +{
20135 +       int length = 0;
20136 +       return length;
20137 +}
20138 +
20139 +#endif /* _VX_CVIRT_PROC_H */
20140 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/debug.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/debug.c
20141 --- linux-2.6.22.10/kernel/vserver/debug.c      1970-01-01 01:00:00 +0100
20142 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/debug.c    2007-06-15 02:37:04 +0200
20143 @@ -0,0 +1,35 @@
20144 +/*
20145 + *  kernel/vserver/debug.c
20146 + *
20147 + *  Copyright (C) 2005-2007 Herbert Pötzl
20148 + *
20149 + *  V0.01  vx_info dump support
20150 + *
20151 + */
20152 +
20153 +#include <linux/errno.h>
20154 +#include <linux/kernel.h>
20155 +#include <linux/module.h>
20156 +#include <linux/vs_base.h>
20157 +
20158 +#include <linux/vserver/context.h>
20159 +
20160 +
20161 +void   dump_vx_info(struct vx_info *vxi, int level)
20162 +{
20163 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
20164 +               atomic_read(&vxi->vx_usecnt),
20165 +               atomic_read(&vxi->vx_tasks),
20166 +               vxi->vx_state);
20167 +       if (level > 0) {
20168 +               __dump_vx_limit(&vxi->limit);
20169 +               __dump_vx_sched(&vxi->sched);
20170 +               __dump_vx_cvirt(&vxi->cvirt);
20171 +               __dump_vx_cacct(&vxi->cacct);
20172 +       }
20173 +       printk("---\n");
20174 +}
20175 +
20176 +
20177 +EXPORT_SYMBOL_GPL(dump_vx_info);
20178 +
20179 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/dlimit.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/dlimit.c
20180 --- linux-2.6.22.10/kernel/vserver/dlimit.c     1970-01-01 01:00:00 +0100
20181 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/dlimit.c   2007-07-17 03:02:15 +0200
20182 @@ -0,0 +1,526 @@
20183 +/*
20184 + *  linux/kernel/vserver/dlimit.c
20185 + *
20186 + *  Virtual Server: Context Disk Limits
20187 + *
20188 + *  Copyright (C) 2004-2007  Herbert Pötzl
20189 + *
20190 + *  V0.01  initial version
20191 + *  V0.02  compat32 splitup
20192 + *
20193 + */
20194 +
20195 +#include <linux/fs.h>
20196 +#include <linux/namei.h>
20197 +#include <linux/statfs.h>
20198 +#include <linux/compat.h>
20199 +#include <linux/vserver/switch.h>
20200 +#include <linux/vs_context.h>
20201 +#include <linux/vs_tag.h>
20202 +#include <linux/vs_dlimit.h>
20203 +#include <linux/vserver/dlimit_cmd.h>
20204 +
20205 +#include <asm/errno.h>
20206 +#include <asm/uaccess.h>
20207 +
20208 +/*     __alloc_dl_info()
20209 +
20210 +       * allocate an initialized dl_info struct
20211 +       * doesn't make it visible (hash)                        */
20212 +
20213 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
20214 +{
20215 +       struct dl_info *new = NULL;
20216 +
20217 +       vxdprintk(VXD_CBIT(dlim, 5),
20218 +               "alloc_dl_info(%p,%d)*", sb, tag);
20219 +
20220 +       /* would this benefit from a slab cache? */
20221 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
20222 +       if (!new)
20223 +               return 0;
20224 +
20225 +       memset(new, 0, sizeof(struct dl_info));
20226 +       new->dl_tag = tag;
20227 +       new->dl_sb = sb;
20228 +       INIT_RCU_HEAD(&new->dl_rcu);
20229 +       INIT_HLIST_NODE(&new->dl_hlist);
20230 +       spin_lock_init(&new->dl_lock);
20231 +       atomic_set(&new->dl_refcnt, 0);
20232 +       atomic_set(&new->dl_usecnt, 0);
20233 +
20234 +       /* rest of init goes here */
20235 +
20236 +       vxdprintk(VXD_CBIT(dlim, 4),
20237 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
20238 +       return new;
20239 +}
20240 +
20241 +/*     __dealloc_dl_info()
20242 +
20243 +       * final disposal of dl_info                             */
20244 +
20245 +static void __dealloc_dl_info(struct dl_info *dli)
20246 +{
20247 +       vxdprintk(VXD_CBIT(dlim, 4),
20248 +               "dealloc_dl_info(%p)", dli);
20249 +
20250 +       dli->dl_hlist.next = LIST_POISON1;
20251 +       dli->dl_tag = -1;
20252 +       dli->dl_sb = 0;
20253 +
20254 +       BUG_ON(atomic_read(&dli->dl_usecnt));
20255 +       BUG_ON(atomic_read(&dli->dl_refcnt));
20256 +
20257 +       kfree(dli);
20258 +}
20259 +
20260 +
20261 +/*     hash table for dl_info hash */
20262 +
20263 +#define DL_HASH_SIZE   13
20264 +
20265 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
20266 +
20267 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
20268 +
20269 +
20270 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
20271 +{
20272 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
20273 +}
20274 +
20275 +
20276 +
20277 +/*     __hash_dl_info()
20278 +
20279 +       * add the dli to the global hash table
20280 +       * requires the hash_lock to be held                     */
20281 +
20282 +static inline void __hash_dl_info(struct dl_info *dli)
20283 +{
20284 +       struct hlist_head *head;
20285 +
20286 +       vxdprintk(VXD_CBIT(dlim, 6),
20287 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
20288 +       get_dl_info(dli);
20289 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
20290 +       hlist_add_head_rcu(&dli->dl_hlist, head);
20291 +}
20292 +
20293 +/*     __unhash_dl_info()
20294 +
20295 +       * remove the dli from the global hash table
20296 +       * requires the hash_lock to be held                     */
20297 +
20298 +static inline void __unhash_dl_info(struct dl_info *dli)
20299 +{
20300 +       vxdprintk(VXD_CBIT(dlim, 6),
20301 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
20302 +       hlist_del_rcu(&dli->dl_hlist);
20303 +       put_dl_info(dli);
20304 +}
20305 +
20306 +
20307 +/*     __lookup_dl_info()
20308 +
20309 +       * requires the rcu_read_lock()
20310 +       * doesn't increment the dl_refcnt                       */
20311 +
20312 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
20313 +{
20314 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
20315 +       struct hlist_node *pos;
20316 +       struct dl_info *dli;
20317 +
20318 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
20319 +
20320 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
20321 +                       return dli;
20322 +               }
20323 +       }
20324 +       return NULL;
20325 +}
20326 +
20327 +
20328 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
20329 +{
20330 +       struct dl_info *dli;
20331 +
20332 +       rcu_read_lock();
20333 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
20334 +       vxdprintk(VXD_CBIT(dlim, 7),
20335 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
20336 +       rcu_read_unlock();
20337 +       return dli;
20338 +}
20339 +
20340 +void rcu_free_dl_info(struct rcu_head *head)
20341 +{
20342 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
20343 +       int usecnt, refcnt;
20344 +
20345 +       BUG_ON(!dli || !head);
20346 +
20347 +       usecnt = atomic_read(&dli->dl_usecnt);
20348 +       BUG_ON(usecnt < 0);
20349 +
20350 +       refcnt = atomic_read(&dli->dl_refcnt);
20351 +       BUG_ON(refcnt < 0);
20352 +
20353 +       vxdprintk(VXD_CBIT(dlim, 3),
20354 +               "rcu_free_dl_info(%p)", dli);
20355 +       if (!usecnt)
20356 +               __dealloc_dl_info(dli);
20357 +       else
20358 +               printk("!!! rcu didn't free\n");
20359 +}
20360 +
20361 +
20362 +
20363 +
20364 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
20365 +       uint32_t flags, int add)
20366 +{
20367 +       struct nameidata nd;
20368 +       int ret;
20369 +
20370 +       ret = user_path_walk_link(name, &nd);
20371 +       if (!ret) {
20372 +               struct super_block *sb;
20373 +               struct dl_info *dli;
20374 +
20375 +               ret = -EINVAL;
20376 +               if (!nd.dentry->d_inode)
20377 +                       goto out_release;
20378 +               if (!(sb = nd.dentry->d_inode->i_sb))
20379 +                       goto out_release;
20380 +
20381 +               if (add) {
20382 +                       dli = __alloc_dl_info(sb, id);
20383 +                       spin_lock(&dl_info_hash_lock);
20384 +
20385 +                       ret = -EEXIST;
20386 +                       if (__lookup_dl_info(sb, id))
20387 +                               goto out_unlock;
20388 +                       __hash_dl_info(dli);
20389 +                       dli = NULL;
20390 +               } else {
20391 +                       spin_lock(&dl_info_hash_lock);
20392 +                       dli = __lookup_dl_info(sb, id);
20393 +
20394 +                       ret = -ESRCH;
20395 +                       if (!dli)
20396 +                               goto out_unlock;
20397 +                       __unhash_dl_info(dli);
20398 +               }
20399 +               ret = 0;
20400 +       out_unlock:
20401 +               spin_unlock(&dl_info_hash_lock);
20402 +               if (add && dli)
20403 +                       __dealloc_dl_info(dli);
20404 +       out_release:
20405 +               path_release(&nd);
20406 +       }
20407 +       return ret;
20408 +}
20409 +
20410 +int vc_add_dlimit(uint32_t id, void __user *data)
20411 +{
20412 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20413 +
20414 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20415 +               return -EFAULT;
20416 +
20417 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
20418 +}
20419 +
20420 +int vc_rem_dlimit(uint32_t id, void __user *data)
20421 +{
20422 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20423 +
20424 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20425 +               return -EFAULT;
20426 +
20427 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
20428 +}
20429 +
20430 +#ifdef CONFIG_COMPAT
20431 +
20432 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
20433 +{
20434 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20435 +
20436 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20437 +               return -EFAULT;
20438 +
20439 +       return do_addrem_dlimit(id,
20440 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
20441 +}
20442 +
20443 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
20444 +{
20445 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20446 +
20447 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20448 +               return -EFAULT;
20449 +
20450 +       return do_addrem_dlimit(id,
20451 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
20452 +}
20453 +
20454 +#endif /* CONFIG_COMPAT */
20455 +
20456 +
20457 +static inline
20458 +int do_set_dlimit(uint32_t id, const char __user *name,
20459 +       uint32_t space_used, uint32_t space_total,
20460 +       uint32_t inodes_used, uint32_t inodes_total,
20461 +       uint32_t reserved, uint32_t flags)
20462 +{
20463 +       struct nameidata nd;
20464 +       int ret;
20465 +
20466 +       ret = user_path_walk_link(name, &nd);
20467 +       if (!ret) {
20468 +               struct super_block *sb;
20469 +               struct dl_info *dli;
20470 +
20471 +               ret = -EINVAL;
20472 +               if (!nd.dentry->d_inode)
20473 +                       goto out_release;
20474 +               if (!(sb = nd.dentry->d_inode->i_sb))
20475 +                       goto out_release;
20476 +               if ((reserved != CDLIM_KEEP &&
20477 +                       reserved > 100) ||
20478 +                       (inodes_used != CDLIM_KEEP &&
20479 +                       inodes_used > inodes_total) ||
20480 +                       (space_used != CDLIM_KEEP &&
20481 +                       space_used > space_total))
20482 +                       goto out_release;
20483 +
20484 +               ret = -ESRCH;
20485 +               dli = locate_dl_info(sb, id);
20486 +               if (!dli)
20487 +                       goto out_release;
20488 +
20489 +               spin_lock(&dli->dl_lock);
20490 +
20491 +               if (inodes_used != CDLIM_KEEP)
20492 +                       dli->dl_inodes_used = inodes_used;
20493 +               if (inodes_total != CDLIM_KEEP)
20494 +                       dli->dl_inodes_total = inodes_total;
20495 +               if (space_used != CDLIM_KEEP) {
20496 +                       dli->dl_space_used = space_used;
20497 +                       dli->dl_space_used <<= 10;
20498 +               }
20499 +               if (space_total == CDLIM_INFINITY)
20500 +                       dli->dl_space_total = DLIM_INFINITY;
20501 +               else if (space_total != CDLIM_KEEP) {
20502 +                       dli->dl_space_total = space_total;
20503 +                       dli->dl_space_total <<= 10;
20504 +               }
20505 +               if (reserved != CDLIM_KEEP)
20506 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20507 +
20508 +               spin_unlock(&dli->dl_lock);
20509 +
20510 +               put_dl_info(dli);
20511 +               ret = 0;
20512 +
20513 +       out_release:
20514 +               path_release(&nd);
20515 +       }
20516 +       return ret;
20517 +}
20518 +
20519 +int vc_set_dlimit(uint32_t id, void __user *data)
20520 +{
20521 +       struct vcmd_ctx_dlimit_v0 vc_data;
20522 +
20523 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20524 +               return -EFAULT;
20525 +
20526 +       return do_set_dlimit(id, vc_data.name,
20527 +               vc_data.space_used, vc_data.space_total,
20528 +               vc_data.inodes_used, vc_data.inodes_total,
20529 +               vc_data.reserved, vc_data.flags);
20530 +}
20531 +
20532 +#ifdef CONFIG_COMPAT
20533 +
20534 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20535 +{
20536 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20537 +
20538 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20539 +               return -EFAULT;
20540 +
20541 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20542 +               vc_data.space_used, vc_data.space_total,
20543 +               vc_data.inodes_used, vc_data.inodes_total,
20544 +               vc_data.reserved, vc_data.flags);
20545 +}
20546 +
20547 +#endif /* CONFIG_COMPAT */
20548 +
20549 +
20550 +static inline
20551 +int do_get_dlimit(uint32_t id, const char __user *name,
20552 +       uint32_t *space_used, uint32_t *space_total,
20553 +       uint32_t *inodes_used, uint32_t *inodes_total,
20554 +       uint32_t *reserved, uint32_t *flags)
20555 +{
20556 +       struct nameidata nd;
20557 +       int ret;
20558 +
20559 +       ret = user_path_walk_link(name, &nd);
20560 +       if (!ret) {
20561 +               struct super_block *sb;
20562 +               struct dl_info *dli;
20563 +
20564 +               ret = -EINVAL;
20565 +               if (!nd.dentry->d_inode)
20566 +                       goto out_release;
20567 +               if (!(sb = nd.dentry->d_inode->i_sb))
20568 +                       goto out_release;
20569 +
20570 +               ret = -ESRCH;
20571 +               dli = locate_dl_info(sb, id);
20572 +               if (!dli)
20573 +                       goto out_release;
20574 +
20575 +               spin_lock(&dli->dl_lock);
20576 +               *inodes_used = dli->dl_inodes_used;
20577 +               *inodes_total = dli->dl_inodes_total;
20578 +               *space_used = dli->dl_space_used >> 10;
20579 +               if (dli->dl_space_total == DLIM_INFINITY)
20580 +                       *space_total = CDLIM_INFINITY;
20581 +               else
20582 +                       *space_total = dli->dl_space_total >> 10;
20583 +
20584 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20585 +               spin_unlock(&dli->dl_lock);
20586 +
20587 +               put_dl_info(dli);
20588 +               ret = -EFAULT;
20589 +
20590 +               ret = 0;
20591 +       out_release:
20592 +               path_release(&nd);
20593 +       }
20594 +       return ret;
20595 +}
20596 +
20597 +
20598 +int vc_get_dlimit(uint32_t id, void __user *data)
20599 +{
20600 +       struct vcmd_ctx_dlimit_v0 vc_data;
20601 +       int ret;
20602 +
20603 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20604 +               return -EFAULT;
20605 +
20606 +       ret = do_get_dlimit(id, vc_data.name,
20607 +               &vc_data.space_used, &vc_data.space_total,
20608 +               &vc_data.inodes_used, &vc_data.inodes_total,
20609 +               &vc_data.reserved, &vc_data.flags);
20610 +       if (ret)
20611 +               return ret;
20612 +
20613 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20614 +               return -EFAULT;
20615 +       return 0;
20616 +}
20617 +
20618 +#ifdef CONFIG_COMPAT
20619 +
20620 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20621 +{
20622 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20623 +       int ret;
20624 +
20625 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20626 +               return -EFAULT;
20627 +
20628 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20629 +               &vc_data.space_used, &vc_data.space_total,
20630 +               &vc_data.inodes_used, &vc_data.inodes_total,
20631 +               &vc_data.reserved, &vc_data.flags);
20632 +       if (ret)
20633 +               return ret;
20634 +
20635 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20636 +               return -EFAULT;
20637 +       return 0;
20638 +}
20639 +
20640 +#endif /* CONFIG_COMPAT */
20641 +
20642 +
20643 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20644 +{
20645 +       struct dl_info *dli;
20646 +       __u64 blimit, bfree, bavail;
20647 +       __u32 ifree;
20648 +
20649 +       dli = locate_dl_info(sb, dx_current_tag());
20650 +       if (!dli)
20651 +               return;
20652 +
20653 +       spin_lock(&dli->dl_lock);
20654 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20655 +               goto no_ilim;
20656 +
20657 +       /* reduce max inodes available to limit */
20658 +       if (buf->f_files > dli->dl_inodes_total)
20659 +               buf->f_files = dli->dl_inodes_total;
20660 +
20661 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20662 +       /* reduce free inodes to min */
20663 +       if (ifree < buf->f_ffree)
20664 +               buf->f_ffree = ifree;
20665 +
20666 +no_ilim:
20667 +       if (dli->dl_space_total == DLIM_INFINITY)
20668 +               goto no_blim;
20669 +
20670 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20671 +
20672 +       if (dli->dl_space_total < dli->dl_space_used)
20673 +               bfree = 0;
20674 +       else
20675 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20676 +                       >> sb->s_blocksize_bits;
20677 +
20678 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20679 +       if (bavail < dli->dl_space_used)
20680 +               bavail = 0;
20681 +       else
20682 +               bavail = (bavail - dli->dl_space_used)
20683 +                       >> sb->s_blocksize_bits;
20684 +
20685 +       /* reduce max space available to limit */
20686 +       if (buf->f_blocks > blimit)
20687 +               buf->f_blocks = blimit;
20688 +
20689 +       /* reduce free space to min */
20690 +       if (bfree < buf->f_bfree)
20691 +               buf->f_bfree = bfree;
20692 +
20693 +       /* reduce avail space to min */
20694 +       if (bavail < buf->f_bavail)
20695 +               buf->f_bavail = bavail;
20696 +
20697 +no_blim:
20698 +       spin_unlock(&dli->dl_lock);
20699 +       put_dl_info(dli);
20700 +
20701 +       return;
20702 +}
20703 +
20704 +#include <linux/module.h>
20705 +
20706 +EXPORT_SYMBOL_GPL(locate_dl_info);
20707 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20708 +
20709 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/helper.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/helper.c
20710 --- linux-2.6.22.10/kernel/vserver/helper.c     1970-01-01 01:00:00 +0100
20711 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/helper.c   2007-06-15 02:37:04 +0200
20712 @@ -0,0 +1,208 @@
20713 +/*
20714 + *  linux/kernel/vserver/helper.c
20715 + *
20716 + *  Virtual Context Support
20717 + *
20718 + *  Copyright (C) 2004-2007  Herbert Pötzl
20719 + *
20720 + *  V0.01  basic helper
20721 + *
20722 + */
20723 +
20724 +#include <linux/errno.h>
20725 +#include <linux/kmod.h>
20726 +#include <linux/sched.h>
20727 +#include <linux/reboot.h>
20728 +#include <linux/vs_context.h>
20729 +#include <linux/vs_network.h>
20730 +#include <linux/vserver/signal.h>
20731 +
20732 +#include <asm/uaccess.h>
20733 +#include <asm/unistd.h>
20734 +
20735 +
20736 +char vshelper_path[255] = "/sbin/vshelper";
20737 +
20738 +
20739 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20740 +{
20741 +       int ret;
20742 +
20743 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20744 +               printk( KERN_WARNING
20745 +                       "%s: (%s %s) returned %s with %d\n",
20746 +                       name, argv[1], argv[2],
20747 +                       sync ? "sync" : "async", ret);
20748 +       }
20749 +       vxdprintk(VXD_CBIT(switch, 4),
20750 +               "%s: (%s %s) returned %s with %d",
20751 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20752 +       return ret;
20753 +}
20754 +
20755 +/*
20756 + *      vshelper path is set via /proc/sys
20757 + *      invoked by vserver sys_reboot(), with
20758 + *      the following arguments
20759 + *
20760 + *      argv [0] = vshelper_path;
20761 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20762 + *      argv [2] = context identifier
20763 + *
20764 + *      envp [*] = type-specific parameters
20765 + */
20766 +
20767 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20768 +{
20769 +       char id_buf[8], cmd_buf[16];
20770 +       char uid_buf[16], pid_buf[16];
20771 +       int ret;
20772 +
20773 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20774 +       char *envp[] = {"HOME=/", "TERM=linux",
20775 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20776 +                       uid_buf, pid_buf, cmd_buf, 0};
20777 +
20778 +       if (vx_info_state(vxi, VXS_HELPER))
20779 +               return -EAGAIN;
20780 +       vxi->vx_state |= VXS_HELPER;
20781 +
20782 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20783 +
20784 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20785 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
20786 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20787 +
20788 +       switch (cmd) {
20789 +       case LINUX_REBOOT_CMD_RESTART:
20790 +               argv[1] = "restart";
20791 +               break;
20792 +
20793 +       case LINUX_REBOOT_CMD_HALT:
20794 +               argv[1] = "halt";
20795 +               break;
20796 +
20797 +       case LINUX_REBOOT_CMD_POWER_OFF:
20798 +               argv[1] = "poweroff";
20799 +               break;
20800 +
20801 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20802 +               argv[1] = "swsusp";
20803 +               break;
20804 +
20805 +       default:
20806 +               vxi->vx_state &= ~VXS_HELPER;
20807 +               return 0;
20808 +       }
20809 +
20810 +#ifndef CONFIG_VSERVER_LEGACY
20811 +       ret = do_vshelper(vshelper_path, argv, envp, 1);
20812 +#else
20813 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20814 +#endif
20815 +       vxi->vx_state &= ~VXS_HELPER;
20816 +       __wakeup_vx_info(vxi);
20817 +       return (ret) ? -EPERM : 0;
20818 +}
20819 +
20820 +
20821 +long vs_reboot(unsigned int cmd, void __user *arg)
20822 +{
20823 +       struct vx_info *vxi = current->vx_info;
20824 +       long ret = 0;
20825 +
20826 +       vxdprintk(VXD_CBIT(misc, 5),
20827 +               "vs_reboot(%p[#%d],%d)",
20828 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20829 +
20830 +       ret = vs_reboot_helper(vxi, cmd, arg);
20831 +       if (ret)
20832 +               return ret;
20833 +
20834 +       vxi->reboot_cmd = cmd;
20835 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20836 +               switch (cmd) {
20837 +               case LINUX_REBOOT_CMD_RESTART:
20838 +               case LINUX_REBOOT_CMD_HALT:
20839 +               case LINUX_REBOOT_CMD_POWER_OFF:
20840 +                       vx_info_kill(vxi, 0, SIGKILL);
20841 +                       vx_info_kill(vxi, 1, SIGKILL);
20842 +               default:
20843 +                       break;
20844 +               }
20845 +       }
20846 +       return 0;
20847 +}
20848 +
20849 +
20850 +/*
20851 + *      argv [0] = vshelper_path;
20852 + *      argv [1] = action: "startup", "shutdown"
20853 + *      argv [2] = context identifier
20854 + *
20855 + *      envp [*] = type-specific parameters
20856 + */
20857 +
20858 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20859 +{
20860 +       char id_buf[8], cmd_buf[16];
20861 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20862 +       char *envp[] = {"HOME=/", "TERM=linux",
20863 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20864 +
20865 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20866 +               return 0;
20867 +
20868 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20869 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20870 +
20871 +       switch (cmd) {
20872 +       case VSC_STARTUP:
20873 +               argv[1] = "startup";
20874 +               break;
20875 +       case VSC_SHUTDOWN:
20876 +               argv[1] = "shutdown";
20877 +               break;
20878 +       default:
20879 +               return 0;
20880 +       }
20881 +
20882 +       return do_vshelper(vshelper_path, argv, envp, 1);
20883 +}
20884 +
20885 +
20886 +/*
20887 + *      argv [0] = vshelper_path;
20888 + *      argv [1] = action: "netup", "netdown"
20889 + *      argv [2] = context identifier
20890 + *
20891 + *      envp [*] = type-specific parameters
20892 + */
20893 +
20894 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20895 +{
20896 +       char id_buf[8], cmd_buf[16];
20897 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20898 +       char *envp[] = {"HOME=/", "TERM=linux",
20899 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20900 +
20901 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20902 +               return 0;
20903 +
20904 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20905 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20906 +
20907 +       switch (cmd) {
20908 +       case VSC_NETUP:
20909 +               argv[1] = "netup";
20910 +               break;
20911 +       case VSC_NETDOWN:
20912 +               argv[1] = "netdown";
20913 +               break;
20914 +       default:
20915 +               return 0;
20916 +       }
20917 +
20918 +       return do_vshelper(vshelper_path, argv, envp, 1);
20919 +}
20920 +
20921 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/history.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/history.c
20922 --- linux-2.6.22.10/kernel/vserver/history.c    1970-01-01 01:00:00 +0100
20923 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/history.c  2007-06-15 02:37:04 +0200
20924 @@ -0,0 +1,264 @@
20925 +/*
20926 + *  kernel/vserver/history.c
20927 + *
20928 + *  Virtual Context History Backtrace
20929 + *
20930 + *  Copyright (C) 2004-2007  Herbert Pötzl
20931 + *
20932 + *  V0.01  basic structure
20933 + *  V0.02  hash/unhash and trace
20934 + *  V0.03  preemption fixes
20935 + *
20936 + */
20937 +
20938 +#include <linux/errno.h>
20939 +#include <linux/module.h>
20940 +#include <linux/types.h>
20941 +#include <linux/ctype.h>
20942 +
20943 +#include <asm/uaccess.h>
20944 +#include <asm/atomic.h>
20945 +#include <asm/unistd.h>
20946 +
20947 +#include <linux/vserver/context.h>
20948 +#include <linux/vserver/debug.h>
20949 +#include <linux/vserver/debug_cmd.h>
20950 +#include <linux/vserver/history.h>
20951 +
20952 +
20953 +#ifdef CONFIG_VSERVER_HISTORY
20954 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20955 +#else
20956 +#define VXH_SIZE       64
20957 +#endif
20958 +
20959 +struct _vx_history {
20960 +       unsigned int counter;
20961 +
20962 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20963 +};
20964 +
20965 +
20966 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20967 +
20968 +unsigned volatile int vxh_active = 1;
20969 +
20970 +static atomic_t sequence = ATOMIC_INIT(0);
20971 +
20972 +
20973 +/*     vxh_advance()
20974 +
20975 +       * requires disabled preemption                          */
20976 +
20977 +struct _vx_hist_entry *vxh_advance(void *loc)
20978 +{
20979 +       unsigned int cpu = smp_processor_id();
20980 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20981 +       struct _vx_hist_entry *entry;
20982 +       unsigned int index;
20983 +
20984 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20985 +       entry = &hist->entry[index];
20986 +
20987 +       entry->seq = atomic_inc_return(&sequence);
20988 +       entry->loc = loc;
20989 +       return entry;
20990 +}
20991 +
20992 +EXPORT_SYMBOL_GPL(vxh_advance);
20993 +
20994 +
20995 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20996 +
20997 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20998 +
20999 +
21000 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
21001 +
21002 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
21003 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
21004 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
21005 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
21006 +
21007 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
21008 +{
21009 +       switch (e->type) {
21010 +       case VXH_THROW_OOPS:
21011 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
21012 +               break;
21013 +
21014 +       case VXH_GET_VX_INFO:
21015 +       case VXH_PUT_VX_INFO:
21016 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
21017 +                       VXH_LOC_ARGS(e),
21018 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
21019 +                       VXH_VXI_ARGS(e));
21020 +               break;
21021 +
21022 +       case VXH_INIT_VX_INFO:
21023 +       case VXH_SET_VX_INFO:
21024 +       case VXH_CLR_VX_INFO:
21025 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
21026 +                       VXH_LOC_ARGS(e),
21027 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
21028 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
21029 +                       VXH_VXI_ARGS(e), e->sc.data);
21030 +               break;
21031 +
21032 +       case VXH_CLAIM_VX_INFO:
21033 +       case VXH_RELEASE_VX_INFO:
21034 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
21035 +                       VXH_LOC_ARGS(e),
21036 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
21037 +                       VXH_VXI_ARGS(e), e->sc.data);
21038 +               break;
21039 +
21040 +       case VXH_ALLOC_VX_INFO:
21041 +       case VXH_DEALLOC_VX_INFO:
21042 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
21043 +                       VXH_LOC_ARGS(e),
21044 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
21045 +                       VXH_VXI_ARGS(e));
21046 +               break;
21047 +
21048 +       case VXH_HASH_VX_INFO:
21049 +       case VXH_UNHASH_VX_INFO:
21050 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
21051 +                       VXH_LOC_ARGS(e),
21052 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
21053 +                       VXH_VXI_ARGS(e));
21054 +               break;
21055 +
21056 +       case VXH_LOC_VX_INFO:
21057 +       case VXH_LOOKUP_VX_INFO:
21058 +       case VXH_CREATE_VX_INFO:
21059 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
21060 +                       VXH_LOC_ARGS(e),
21061 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
21062 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
21063 +                       e->ll.arg, VXH_VXI_ARGS(e));
21064 +               break;
21065 +       }
21066 +}
21067 +
21068 +static void __vxh_dump_history(void)
21069 +{
21070 +       unsigned int i, cpu;
21071 +
21072 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
21073 +               atomic_read(&sequence), NR_CPUS);
21074 +
21075 +       for (i = 0; i < VXH_SIZE; i++) {
21076 +               for_each_online_cpu(cpu) {
21077 +                       struct _vx_history *hist =
21078 +                               &per_cpu(vx_history_buffer, cpu);
21079 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
21080 +                       struct _vx_hist_entry *entry = &hist->entry[index];
21081 +
21082 +                       vxh_dump_entry(entry, cpu);
21083 +               }
21084 +       }
21085 +}
21086 +
21087 +void   vxh_dump_history(void)
21088 +{
21089 +       vxh_active = 0;
21090 +#ifdef CONFIG_SMP
21091 +       local_irq_enable();
21092 +       smp_send_stop();
21093 +       local_irq_disable();
21094 +#endif
21095 +       __vxh_dump_history();
21096 +}
21097 +
21098 +
21099 +/* vserver syscall commands below here */
21100 +
21101 +
21102 +int vc_dump_history(uint32_t id)
21103 +{
21104 +       vxh_active = 0;
21105 +       __vxh_dump_history();
21106 +       vxh_active = 1;
21107 +
21108 +       return 0;
21109 +}
21110 +
21111 +
21112 +int do_read_history(struct __user _vx_hist_entry *data,
21113 +       int cpu, uint32_t *index, uint32_t *count)
21114 +{
21115 +       int pos, ret = 0;
21116 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
21117 +       int end = hist->counter;
21118 +       int start = end - VXH_SIZE + 2;
21119 +       int idx = *index;
21120 +
21121 +       /* special case: get current pos */
21122 +       if (!*count) {
21123 +               *index = end;
21124 +               return 0;
21125 +       }
21126 +
21127 +       /* have we lost some data? */
21128 +       if (idx < start)
21129 +               idx = start;
21130 +
21131 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21132 +               struct _vx_hist_entry *entry =
21133 +                       &hist->entry[idx % VXH_SIZE];
21134 +
21135 +               /* send entry to userspace */
21136 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21137 +               if (ret)
21138 +                       break;
21139 +       }
21140 +       /* save new index and count */
21141 +       *index = idx;
21142 +       *count = pos;
21143 +       return ret ? ret : (*index < end);
21144 +}
21145 +
21146 +int vc_read_history(uint32_t id, void __user *data)
21147 +{
21148 +       struct vcmd_read_history_v0 vc_data;
21149 +       int ret;
21150 +
21151 +       if (id >= NR_CPUS)
21152 +               return -EINVAL;
21153 +
21154 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21155 +               return -EFAULT;
21156 +
21157 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
21158 +               id, &vc_data.index, &vc_data.count);
21159 +
21160 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21161 +               return -EFAULT;
21162 +       return ret;
21163 +}
21164 +
21165 +#ifdef CONFIG_COMPAT
21166 +
21167 +int vc_read_history_x32(uint32_t id, void __user *data)
21168 +{
21169 +       struct vcmd_read_history_v0_x32 vc_data;
21170 +       int ret;
21171 +
21172 +       if (id >= NR_CPUS)
21173 +               return -EINVAL;
21174 +
21175 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21176 +               return -EFAULT;
21177 +
21178 +       ret = do_read_history((struct __user _vx_hist_entry *)
21179 +               compat_ptr(vc_data.data_ptr),
21180 +               id, &vc_data.index, &vc_data.count);
21181 +
21182 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21183 +               return -EFAULT;
21184 +       return ret;
21185 +}
21186 +
21187 +#endif /* CONFIG_COMPAT */
21188 +
21189 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/init.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/init.c
21190 --- linux-2.6.22.10/kernel/vserver/init.c       1970-01-01 01:00:00 +0100
21191 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/init.c     2007-06-15 02:37:04 +0200
21192 @@ -0,0 +1,47 @@
21193 +/*
21194 + *  linux/kernel/init.c
21195 + *
21196 + *  Virtual Server Init
21197 + *
21198 + *  Copyright (C) 2004-2007  Herbert Pötzl
21199 + *
21200 + *  V0.01  basic structure
21201 + *
21202 + */
21203 +
21204 +#include <linux/errno.h>
21205 +#include <linux/init.h>
21206 +#include <linux/module.h>
21207 +
21208 +int    vserver_register_sysctl(void);
21209 +void   vserver_unregister_sysctl(void);
21210 +
21211 +
21212 +static int __init init_vserver(void)
21213 +{
21214 +       int ret = 0;
21215 +
21216 +#ifdef CONFIG_VSERVER_DEBUG
21217 +       vserver_register_sysctl();
21218 +#endif
21219 +       return ret;
21220 +}
21221 +
21222 +
21223 +static void __exit exit_vserver(void)
21224 +{
21225 +
21226 +#ifdef CONFIG_VSERVER_DEBUG
21227 +       vserver_unregister_sysctl();
21228 +#endif
21229 +       return;
21230 +}
21231 +
21232 +/* FIXME: GFP_ZONETYPES gone
21233 +long vx_slab[GFP_ZONETYPES]; */
21234 +long vx_area;
21235 +
21236 +
21237 +module_init(init_vserver);
21238 +module_exit(exit_vserver);
21239 +
21240 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/inode.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/inode.c
21241 --- linux-2.6.22.10/kernel/vserver/inode.c      1970-01-01 01:00:00 +0100
21242 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/inode.c    2007-07-16 06:39:15 +0200
21243 @@ -0,0 +1,417 @@
21244 +/*
21245 + *  linux/kernel/vserver/inode.c
21246 + *
21247 + *  Virtual Server: File System Support
21248 + *
21249 + *  Copyright (C) 2004-2007  Herbert Pötzl
21250 + *
21251 + *  V0.01  separated from vcontext V0.05
21252 + *
21253 + */
21254 +
21255 +#include <linux/sched.h>
21256 +#include <linux/proc_fs.h>
21257 +#include <linux/devpts_fs.h>
21258 +#include <linux/namei.h>
21259 +#include <linux/mount.h>
21260 +#include <linux/parser.h>
21261 +#include <linux/file.h>
21262 +#include <linux/compat.h>
21263 +#include <linux/vserver/inode.h>
21264 +#include <linux/vserver/inode_cmd.h>
21265 +#include <linux/vs_base.h>
21266 +#include <linux/vs_tag.h>
21267 +
21268 +#include <asm/errno.h>
21269 +#include <asm/uaccess.h>
21270 +
21271 +
21272 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21273 +{
21274 +       struct proc_dir_entry *entry;
21275 +
21276 +       if (!in || !in->i_sb)
21277 +               return -ESRCH;
21278 +
21279 +       *flags = IATTR_TAG
21280 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21281 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
21282 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
21283 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
21284 +
21285 +       if (S_ISDIR(in->i_mode))
21286 +               *mask |= IATTR_BARRIER;
21287 +
21288 +       if (IS_TAGGED(in)) {
21289 +               *tag = in->i_tag;
21290 +               *mask |= IATTR_TAG;
21291 +       }
21292 +
21293 +       switch (in->i_sb->s_magic) {
21294 +       case PROC_SUPER_MAGIC:
21295 +               entry = PROC_I(in)->pde;
21296 +
21297 +               /* check for specific inodes? */
21298 +               if (entry)
21299 +                       *mask |= IATTR_FLAGS;
21300 +               if (entry)
21301 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21302 +               else
21303 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21304 +               break;
21305 +
21306 +       case DEVPTS_SUPER_MAGIC:
21307 +               *tag = in->i_tag;
21308 +               *mask |= IATTR_TAG;
21309 +               break;
21310 +
21311 +       default:
21312 +               break;
21313 +       }
21314 +       return 0;
21315 +}
21316 +
21317 +int vc_get_iattr(void __user *data)
21318 +{
21319 +       struct nameidata nd;
21320 +       struct vcmd_ctx_iattr_v1 vc_data = { .xid = -1 };
21321 +       int ret;
21322 +
21323 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21324 +               return -EFAULT;
21325 +
21326 +       ret = user_path_walk_link(vc_data.name, &nd);
21327 +       if (!ret) {
21328 +               ret = __vc_get_iattr(nd.dentry->d_inode,
21329 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
21330 +               path_release(&nd);
21331 +       }
21332 +       if (ret)
21333 +               return ret;
21334 +
21335 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21336 +               ret = -EFAULT;
21337 +       return ret;
21338 +}
21339 +
21340 +#ifdef CONFIG_COMPAT
21341 +
21342 +int vc_get_iattr_x32(void __user *data)
21343 +{
21344 +       struct nameidata nd;
21345 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .xid = -1 };
21346 +       int ret;
21347 +
21348 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21349 +               return -EFAULT;
21350 +
21351 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
21352 +       if (!ret) {
21353 +               ret = __vc_get_iattr(nd.dentry->d_inode,
21354 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
21355 +               path_release(&nd);
21356 +       }
21357 +       if (ret)
21358 +               return ret;
21359 +
21360 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21361 +               ret = -EFAULT;
21362 +       return ret;
21363 +}
21364 +
21365 +#endif /* CONFIG_COMPAT */
21366 +
21367 +
21368 +int vc_fget_iattr(uint32_t fd, void __user *data)
21369 +{
21370 +       struct file *filp;
21371 +       struct vcmd_ctx_fiattr_v0 vc_data = { .xid = -1 };
21372 +       int ret;
21373 +
21374 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21375 +               return -EFAULT;
21376 +
21377 +       filp = fget(fd);
21378 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21379 +               return -EBADF;
21380 +
21381 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21382 +               &vc_data.xid, &vc_data.flags, &vc_data.mask);
21383 +
21384 +       fput(filp);
21385 +
21386 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21387 +               ret = -EFAULT;
21388 +       return ret;
21389 +}
21390 +
21391 +
21392 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21393 +{
21394 +       struct inode *in = de->d_inode;
21395 +       int error = 0, is_proc = 0, has_tag = 0;
21396 +       struct iattr attr = { 0 };
21397 +
21398 +       if (!in || !in->i_sb)
21399 +               return -ESRCH;
21400 +
21401 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21402 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21403 +               return -EINVAL;
21404 +
21405 +       has_tag = IS_TAGGED(in) ||
21406 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21407 +       if ((*mask & IATTR_TAG) && !has_tag)
21408 +               return -EINVAL;
21409 +
21410 +       mutex_lock(&in->i_mutex);
21411 +       if (*mask & IATTR_TAG) {
21412 +               attr.ia_tag = *tag;
21413 +               attr.ia_valid |= ATTR_TAG;
21414 +       }
21415 +
21416 +       if (*mask & IATTR_FLAGS) {
21417 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21418 +               unsigned int iflags = PROC_I(in)->vx_flags;
21419 +
21420 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21421 +                       | (*flags & IATTR_FLAGS);
21422 +               PROC_I(in)->vx_flags = iflags;
21423 +               if (entry)
21424 +                       entry->vx_flags = iflags;
21425 +       }
21426 +
21427 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
21428 +               if (*mask & IATTR_IMMUTABLE) {
21429 +                       if (*flags & IATTR_IMMUTABLE)
21430 +                               in->i_flags |= S_IMMUTABLE;
21431 +                       else
21432 +                               in->i_flags &= ~S_IMMUTABLE;
21433 +               }
21434 +               if (*mask & IATTR_IUNLINK) {
21435 +                       if (*flags & IATTR_IUNLINK)
21436 +                               in->i_flags |= S_IUNLINK;
21437 +                       else
21438 +                               in->i_flags &= ~S_IUNLINK;
21439 +               }
21440 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21441 +                       if (*flags & IATTR_BARRIER)
21442 +                               in->i_flags |= S_BARRIER;
21443 +                       else
21444 +                               in->i_flags &= ~S_BARRIER;
21445 +               }
21446 +               if (in->i_op && in->i_op->sync_flags) {
21447 +                       error = in->i_op->sync_flags(in);
21448 +                       if (error)
21449 +                               goto out;
21450 +               }
21451 +       }
21452 +
21453 +       if (attr.ia_valid) {
21454 +               if (in->i_op && in->i_op->setattr)
21455 +                       error = in->i_op->setattr(de, &attr);
21456 +               else {
21457 +                       error = inode_change_ok(in, &attr);
21458 +                       if (!error)
21459 +                               error = inode_setattr(in, &attr);
21460 +               }
21461 +       }
21462 +
21463 +out:
21464 +       mutex_unlock(&in->i_mutex);
21465 +       return error;
21466 +}
21467 +
21468 +int vc_set_iattr(void __user *data)
21469 +{
21470 +       struct nameidata nd;
21471 +       struct vcmd_ctx_iattr_v1 vc_data;
21472 +       int ret;
21473 +
21474 +       if (!capable(CAP_LINUX_IMMUTABLE))
21475 +               return -EPERM;
21476 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21477 +               return -EFAULT;
21478 +
21479 +       ret = user_path_walk_link(vc_data.name, &nd);
21480 +       if (!ret) {
21481 +               ret = __vc_set_iattr(nd.dentry,
21482 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
21483 +               path_release(&nd);
21484 +       }
21485 +
21486 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21487 +               ret = -EFAULT;
21488 +       return ret;
21489 +}
21490 +
21491 +#ifdef CONFIG_COMPAT
21492 +
21493 +int vc_set_iattr_x32(void __user *data)
21494 +{
21495 +       struct nameidata nd;
21496 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21497 +       int ret;
21498 +
21499 +       if (!capable(CAP_LINUX_IMMUTABLE))
21500 +               return -EPERM;
21501 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21502 +               return -EFAULT;
21503 +
21504 +       ret = user_path_walk_link(compat_ptr(vc_data.name_ptr), &nd);
21505 +       if (!ret) {
21506 +               ret = __vc_set_iattr(nd.dentry,
21507 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
21508 +               path_release(&nd);
21509 +       }
21510 +
21511 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21512 +               ret = -EFAULT;
21513 +       return ret;
21514 +}
21515 +
21516 +#endif /* CONFIG_COMPAT */
21517 +
21518 +int vc_fset_iattr(uint32_t fd, void __user *data)
21519 +{
21520 +       struct file *filp;
21521 +       struct vcmd_ctx_fiattr_v0 vc_data;
21522 +       int ret;
21523 +
21524 +       if (!capable(CAP_LINUX_IMMUTABLE))
21525 +               return -EPERM;
21526 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21527 +               return -EFAULT;
21528 +
21529 +       filp = fget(fd);
21530 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21531 +               return -EBADF;
21532 +
21533 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.xid,
21534 +               &vc_data.flags, &vc_data.mask);
21535 +
21536 +       fput(filp);
21537 +
21538 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21539 +               return -EFAULT;
21540 +       return ret;
21541 +}
21542 +
21543 +#ifdef CONFIG_VSERVER_LEGACY
21544 +
21545 +#define PROC_DYNAMIC_FIRST 0xF0000000UL
21546 +
21547 +int vx_proc_ioctl(struct inode *inode, struct file *filp,
21548 +       unsigned int cmd, unsigned long arg)
21549 +{
21550 +       struct proc_dir_entry *entry;
21551 +       int error = 0;
21552 +       int flags;
21553 +
21554 +       if (inode->i_ino < PROC_DYNAMIC_FIRST)
21555 +               return -ENOTTY;
21556 +
21557 +       entry = PROC_I(inode)->pde;
21558 +       if (!entry)
21559 +               return -ENOTTY;
21560 +
21561 +       switch(cmd) {
21562 +       case FIOC_GETXFLG: {
21563 +               /* fixme: if stealth, return -ENOTTY */
21564 +               error = -EPERM;
21565 +               flags = entry->vx_flags;
21566 +               if (capable(CAP_CONTEXT))
21567 +                       error = put_user(flags, (int __user *) arg);
21568 +               break;
21569 +       }
21570 +       case FIOC_SETXFLG: {
21571 +               /* fixme: if stealth, return -ENOTTY */
21572 +               error = -EPERM;
21573 +               if (!capable(CAP_CONTEXT))
21574 +                       break;
21575 +               error = -EROFS;
21576 +               if (IS_RDONLY(inode))
21577 +                       break;
21578 +               error = -EFAULT;
21579 +               if (get_user(flags, (int __user *) arg))
21580 +                       break;
21581 +               error = 0;
21582 +               entry->vx_flags = flags;
21583 +               break;
21584 +       }
21585 +       default:
21586 +               return -ENOTTY;
21587 +       }
21588 +       return error;
21589 +}
21590 +#endif /* CONFIG_VSERVER_LEGACY */
21591 +
21592 +#ifdef CONFIG_PROPAGATE
21593 +
21594 +int dx_parse_tag(char *string, tag_t *tag, int remove)
21595 +{
21596 +       static match_table_t tokens = {
21597 +               {1, "tagid=%u"},
21598 +               {0, NULL}
21599 +       };
21600 +       substring_t args[MAX_OPT_ARGS];
21601 +       int token, option = 0;
21602 +
21603 +       if (!string)
21604 +               return 0;
21605 +
21606 +       token = match_token(string, tokens, args);
21607 +       if (token && tag && !match_int(args, &option))
21608 +               *tag = option;
21609 +
21610 +       vxdprintk(VXD_CBIT(tag, 7),
21611 +               "dx_parse_tag(»%s«): %d:#%d",
21612 +               string, token, option);
21613 +
21614 +       if ((token == 1) && remove) {
21615 +               char *p = strstr(string, "tagid=");
21616 +               char *q = p;
21617 +
21618 +               if (p) {
21619 +                       while (*q != '\0' && *q != ',')
21620 +                               q++;
21621 +                       while (*q)
21622 +                               *p++ = *q++;
21623 +                       while (*p)
21624 +                               *p++ = '\0';
21625 +               }
21626 +       }
21627 +       return token;
21628 +}
21629 +
21630 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21631 +{
21632 +       tag_t new_tag = 0;
21633 +       struct vfsmount *mnt;
21634 +       int propagate;
21635 +
21636 +       if (!nd)
21637 +               return;
21638 +       mnt = nd->mnt;
21639 +       if (!mnt)
21640 +               return;
21641 +
21642 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21643 +       if (propagate)
21644 +               new_tag = mnt->mnt_tag;
21645 +
21646 +       vxdprintk(VXD_CBIT(tag, 7),
21647 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21648 +               inode, inode->i_ino, inode->i_tag,
21649 +               new_tag, (propagate) ? 1 : 0);
21650 +
21651 +       if (propagate)
21652 +               inode->i_tag = new_tag;
21653 +}
21654 +
21655 +#include <linux/module.h>
21656 +
21657 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21658 +
21659 +#endif /* CONFIG_PROPAGATE */
21660 +
21661 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/legacy.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/legacy.c
21662 --- linux-2.6.22.10/kernel/vserver/legacy.c     1970-01-01 01:00:00 +0100
21663 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/legacy.c   2007-06-15 02:37:04 +0200
21664 @@ -0,0 +1,114 @@
21665 +/*
21666 + *  linux/kernel/vserver/legacy.c
21667 + *
21668 + *  Virtual Server: Legacy Funtions
21669 + *
21670 + *  Copyright (C) 2001-2003  Jacques Gelinas
21671 + *  Copyright (C) 2003-2007  Herbert Pötzl
21672 + *
21673 + *  V0.01  broken out from vcontext.c V0.05
21674 + *  V0.02  updated to spaces *sigh*
21675 + *
21676 + */
21677 +
21678 +#include <linux/sched.h>
21679 +#include <linux/vs_context.h>
21680 +#include <linux/vs_network.h>
21681 +#include <linux/vserver/legacy.h>
21682 +#include <linux/vserver/space.h>
21683 +// #include <linux/mnt_namespace.h>
21684 +
21685 +#include <asm/errno.h>
21686 +#include <asm/uaccess.h>
21687 +
21688 +
21689 +extern int vx_set_init(struct vx_info *, struct task_struct *);
21690 +
21691 +static int vx_set_initpid(struct vx_info *vxi, int pid)
21692 +{
21693 +       struct task_struct *init;
21694 +
21695 +       init = find_task_by_real_pid(pid);
21696 +       if (!init)
21697 +               return -ESRCH;
21698 +       return vx_set_init(vxi, init);
21699 +}
21700 +
21701 +int vc_new_s_context(uint32_t ctx, void __user *data)
21702 +{
21703 +       int ret = -ENOMEM;
21704 +       struct vcmd_new_s_context_v1 vc_data;
21705 +       struct vx_info *new_vxi;
21706 +
21707 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21708 +               return -EFAULT;
21709 +
21710 +       /* legacy hack, will be removed soon */
21711 +       if (ctx == -2) {
21712 +               /* assign flags and initpid */
21713 +               if (!current->vx_info)
21714 +                       return -EINVAL;
21715 +               ret = 0;
21716 +               if (vc_data.flags & VX_INFO_INIT)
21717 +                       ret = vx_set_initpid(current->vx_info, current->tgid);
21718 +               if (ret == 0) {
21719 +                       /* We keep the same vx_id, but lower the capabilities */
21720 +                       current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
21721 +                       ret = vx_current_xid();
21722 +                       current->vx_info->vx_flags |= vc_data.flags;
21723 +               }
21724 +               return ret;
21725 +       }
21726 +
21727 +       if (!vx_check(0, VS_ADMIN) || !capable(CAP_SYS_ADMIN)
21728 +               /* might make sense in the future, or not ... */
21729 +               || vx_flags(VX_INFO_PRIVATE, 0))
21730 +               return -EPERM;
21731 +
21732 +       /* ugly hack for Spectator */
21733 +       if (ctx == 1) {
21734 +               current->xid = 1;
21735 +               return 0;
21736 +       }
21737 +
21738 +       if (((ctx > MAX_S_CONTEXT) && (ctx != VX_DYNAMIC_ID)) ||
21739 +               (ctx == 0))
21740 +               return -EINVAL;
21741 +
21742 +       if ((ctx == VX_DYNAMIC_ID) || (ctx < MIN_D_CONTEXT))
21743 +               new_vxi = lookup_or_create_vx_info(ctx);
21744 +       else
21745 +               new_vxi = lookup_vx_info(ctx);
21746 +
21747 +       if (!new_vxi)
21748 +               return -EINVAL;
21749 +
21750 +       ret = -EPERM;
21751 +       if (!vx_info_flags(new_vxi, VXF_STATE_SETUP, 0) &&
21752 +               vx_info_flags(new_vxi, VX_INFO_PRIVATE, 0))
21753 +               goto out_put;
21754 +
21755 +       ret = vx_migrate_task(current, new_vxi,
21756 +               vx_info_flags(new_vxi, VXF_STATE_SETUP, 0));
21757 +       new_vxi->vx_flags &= ~VXF_STATE_SETUP;
21758 +
21759 +       if (ret == 0) {
21760 +               current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
21761 +               new_vxi->vx_flags |= vc_data.flags;
21762 +               if (vc_data.flags & VX_INFO_INIT)
21763 +                       vx_set_initpid(new_vxi, current->tgid);
21764 +               if (vc_data.flags & VX_INFO_NAMESPACE)
21765 +                       vx_set_space(new_vxi, CLONE_NEWNS | CLONE_FS);
21766 +               if (vc_data.flags & VX_INFO_NPROC)
21767 +                       __rlim_set(&new_vxi->limit, RLIMIT_NPROC,
21768 +                               current->signal->rlim[RLIMIT_NPROC].rlim_max);
21769 +
21770 +               /* tweak some defaults for legacy */
21771 +               new_vxi->vx_flags |= (VXF_HIDE_NETIF | VXF_INFO_INIT);
21772 +               ret = new_vxi->vx_id;
21773 +       }
21774 +out_put:
21775 +       put_vx_info(new_vxi);
21776 +       return ret;
21777 +}
21778 +
21779 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/legacynet.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/legacynet.c
21780 --- linux-2.6.22.10/kernel/vserver/legacynet.c  1970-01-01 01:00:00 +0100
21781 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/legacynet.c        2007-06-15 02:37:04 +0200
21782 @@ -0,0 +1,85 @@
21783 +
21784 +/*
21785 + *  linux/kernel/vserver/legacynet.c
21786 + *
21787 + *  Virtual Server: Legacy Network Funtions
21788 + *
21789 + *  Copyright (C) 2001-2003  Jacques Gelinas
21790 + *  Copyright (C) 2003-2007  Herbert Pötzl
21791 + *
21792 + *  V0.01  broken out from legacy.c
21793 + *
21794 + */
21795 +
21796 +#include <linux/sched.h>
21797 +#include <linux/vs_context.h>
21798 +#include <linux/vs_network.h>
21799 +#include <linux/vserver/legacy.h>
21800 +// #include <linux/mnt_namespace.h>
21801 +#include <linux/err.h>
21802 +
21803 +#include <asm/errno.h>
21804 +#include <asm/uaccess.h>
21805 +
21806 +
21807 +extern struct nx_info *create_nx_info(void);
21808 +
21809 +/*  set ipv4 root (syscall) */
21810 +
21811 +int vc_set_ipv4root(uint32_t nbip, void __user *data)
21812 +{
21813 +       int i, err = -EPERM;
21814 +       struct vcmd_set_ipv4root_v3 vc_data;
21815 +       struct nx_info *new_nxi, *nxi = current->nx_info;
21816 +
21817 +       if (nbip < 0 || nbip > NB_IPV4ROOT)
21818 +               return -EINVAL;
21819 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21820 +               return -EFAULT;
21821 +
21822 +       if (!nxi || nxi->ipv4[0] == 0 || capable(CAP_NET_ADMIN))
21823 +               /* We are allowed to change everything */
21824 +               err = 0;
21825 +       else if (nxi) {
21826 +               int found = 0;
21827 +
21828 +               /* We are allowed to select a subset of the currently
21829 +                  installed IP numbers. No new one are allowed
21830 +                  We can't change the broadcast address though */
21831 +               for (i = 0; i < nbip; i++) {
21832 +                       int j;
21833 +                       __u32 nxip = vc_data.nx_mask_pair[i].ip;
21834 +                       for (j = 0; j < nxi->nbipv4; j++) {
21835 +                               if (nxip == nxi->ipv4[j]) {
21836 +                                       found++;
21837 +                                       break;
21838 +                               }
21839 +                       }
21840 +               }
21841 +               if ((found == nbip) &&
21842 +                       (vc_data.broadcast == nxi->v4_bcast))
21843 +                       err = 0;
21844 +       }
21845 +       if (err)
21846 +               return err;
21847 +
21848 +       new_nxi = create_nx_info();
21849 +       if (IS_ERR(new_nxi))
21850 +               return -EINVAL;
21851 +
21852 +       new_nxi->nbipv4 = nbip;
21853 +       for (i = 0; i < nbip; i++) {
21854 +               new_nxi->ipv4[i] = vc_data.nx_mask_pair[i].ip;
21855 +               new_nxi->mask[i] = vc_data.nx_mask_pair[i].mask;
21856 +       }
21857 +       new_nxi->v4_bcast = vc_data.broadcast;
21858 +       if (nxi)
21859 +               printk("!!! switching nx_info %p->%p\n", nxi, new_nxi);
21860 +
21861 +       nx_migrate_task(current, new_nxi);
21862 +       release_nx_info(new_nxi, NULL);
21863 +       put_nx_info(new_nxi);
21864 +       return 0;
21865 +}
21866 +
21867 +
21868 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/limit.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/limit.c
21869 --- linux-2.6.22.10/kernel/vserver/limit.c      1970-01-01 01:00:00 +0100
21870 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/limit.c    2007-06-15 02:37:04 +0200
21871 @@ -0,0 +1,319 @@
21872 +/*
21873 + *  linux/kernel/vserver/limit.c
21874 + *
21875 + *  Virtual Server: Context Limits
21876 + *
21877 + *  Copyright (C) 2004-2007  Herbert Pötzl
21878 + *
21879 + *  V0.01  broken out from vcontext V0.05
21880 + *  V0.02  changed vcmds to vxi arg
21881 + *
21882 + */
21883 +
21884 +#include <linux/module.h>
21885 +#include <linux/vs_context.h>
21886 +#include <linux/vs_limit.h>
21887 +#include <linux/vserver/limit.h>
21888 +#include <linux/vserver/switch.h>
21889 +#include <linux/vserver/limit_cmd.h>
21890 +
21891 +#include <asm/errno.h>
21892 +#include <asm/uaccess.h>
21893 +
21894 +
21895 +const char *vlimit_name[NUM_LIMITS] = {
21896 +       [RLIMIT_CPU]            = "CPU",
21897 +       [RLIMIT_RSS]            = "RSS",
21898 +       [RLIMIT_NPROC]          = "NPROC",
21899 +       [RLIMIT_NOFILE]         = "NOFILE",
21900 +       [RLIMIT_MEMLOCK]        = "VML",
21901 +       [RLIMIT_AS]             = "VM",
21902 +       [RLIMIT_LOCKS]          = "LOCKS",
21903 +       [RLIMIT_SIGPENDING]     = "SIGP",
21904 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21905 +
21906 +       [VLIMIT_NSOCK]          = "NSOCK",
21907 +       [VLIMIT_OPENFD]         = "OPENFD",
21908 +       [VLIMIT_ANON]           = "ANON",
21909 +       [VLIMIT_SHMEM]          = "SHMEM",
21910 +       [VLIMIT_DENTRY]         = "DENTRY",
21911 +};
21912 +
21913 +EXPORT_SYMBOL_GPL(vlimit_name);
21914 +
21915 +#define MASK_ENTRY(x)  (1 << (x))
21916 +
21917 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21918 +               /* minimum */
21919 +       0
21920 +       ,       /* softlimit */
21921 +       MASK_ENTRY( RLIMIT_RSS          ) |
21922 +       MASK_ENTRY( VLIMIT_ANON         ) |
21923 +       0
21924 +       ,       /* maximum */
21925 +       MASK_ENTRY( RLIMIT_RSS          ) |
21926 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21927 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21928 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21929 +       MASK_ENTRY( RLIMIT_AS           ) |
21930 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21931 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21932 +
21933 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21934 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21935 +       MASK_ENTRY( VLIMIT_ANON         ) |
21936 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21937 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21938 +       0
21939 +};
21940 +               /* accounting only */
21941 +uint32_t account_mask =
21942 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21943 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21944 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21945 +       0;
21946 +
21947 +
21948 +static int is_valid_vlimit(int id)
21949 +{
21950 +       uint32_t mask = vlimit_mask.minimum |
21951 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21952 +       return mask & (1 << id);
21953 +}
21954 +
21955 +static int is_accounted_vlimit(int id)
21956 +{
21957 +       if (is_valid_vlimit(id))
21958 +               return 1;
21959 +       return account_mask & (1 << id);
21960 +}
21961 +
21962 +
21963 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21964 +{
21965 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21966 +       return VX_VLIM(limit);
21967 +}
21968 +
21969 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21970 +{
21971 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21972 +       return VX_VLIM(limit);
21973 +}
21974 +
21975 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21976 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21977 +{
21978 +       if (!is_valid_vlimit(id))
21979 +               return -EINVAL;
21980 +
21981 +       if (minimum)
21982 +               *minimum = CRLIM_UNSET;
21983 +       if (softlimit)
21984 +               *softlimit = vc_get_soft(vxi, id);
21985 +       if (maximum)
21986 +               *maximum = vc_get_hard(vxi, id);
21987 +       return 0;
21988 +}
21989 +
21990 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21991 +{
21992 +       struct vcmd_ctx_rlimit_v0 vc_data;
21993 +       int ret;
21994 +
21995 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21996 +               return -EFAULT;
21997 +
21998 +       ret = do_get_rlimit(vxi, vc_data.id,
21999 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
22000 +       if (ret)
22001 +               return ret;
22002 +
22003 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22004 +               return -EFAULT;
22005 +       return 0;
22006 +}
22007 +
22008 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
22009 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
22010 +{
22011 +       if (!is_valid_vlimit(id))
22012 +               return -EINVAL;
22013 +
22014 +       if (maximum != CRLIM_KEEP)
22015 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
22016 +       if (softlimit != CRLIM_KEEP)
22017 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
22018 +
22019 +       /* clamp soft limit */
22020 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
22021 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
22022 +
22023 +       return 0;
22024 +}
22025 +
22026 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
22027 +{
22028 +       struct vcmd_ctx_rlimit_v0 vc_data;
22029 +
22030 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22031 +               return -EFAULT;
22032 +
22033 +       return do_set_rlimit(vxi, vc_data.id,
22034 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
22035 +}
22036 +
22037 +#ifdef CONFIG_IA32_EMULATION
22038 +
22039 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
22040 +{
22041 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
22042 +
22043 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22044 +               return -EFAULT;
22045 +
22046 +       return do_set_rlimit(vxi, vc_data.id,
22047 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
22048 +}
22049 +
22050 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
22051 +{
22052 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
22053 +       int ret;
22054 +
22055 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22056 +               return -EFAULT;
22057 +
22058 +       ret = do_get_rlimit(vxi, vc_data.id,
22059 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
22060 +       if (ret)
22061 +               return ret;
22062 +
22063 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22064 +               return -EFAULT;
22065 +       return 0;
22066 +}
22067 +
22068 +#endif /* CONFIG_IA32_EMULATION */
22069 +
22070 +
22071 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
22072 +{
22073 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
22074 +               return -EFAULT;
22075 +       return 0;
22076 +}
22077 +
22078 +
22079 +static inline void vx_reset_minmax(struct _vx_limit *limit)
22080 +{
22081 +       rlim_t value;
22082 +       int lim;
22083 +
22084 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22085 +               value = __rlim_get(limit, lim);
22086 +               __rlim_rmax(limit, lim) = value;
22087 +               __rlim_rmin(limit, lim) = value;
22088 +       }
22089 +}
22090 +
22091 +
22092 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
22093 +{
22094 +       vx_reset_minmax(&vxi->limit);
22095 +       return 0;
22096 +}
22097 +
22098 +
22099 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
22100 +{
22101 +       struct vcmd_rlimit_stat_v0 vc_data;
22102 +       struct _vx_limit *limit = &vxi->limit;
22103 +       int id;
22104 +
22105 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22106 +               return -EFAULT;
22107 +
22108 +       id = vc_data.id;
22109 +       if (!is_accounted_vlimit(id))
22110 +               return -EINVAL;
22111 +
22112 +       vx_limit_fixup(limit, id);
22113 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
22114 +       vc_data.value = __rlim_get(limit, id);
22115 +       vc_data.minimum = __rlim_rmin(limit, id);
22116 +       vc_data.maximum = __rlim_rmax(limit, id);
22117 +
22118 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22119 +               return -EFAULT;
22120 +       return 0;
22121 +}
22122 +
22123 +
22124 +void vx_vsi_meminfo(struct sysinfo *val)
22125 +{
22126 +       struct vx_info *vxi = current->vx_info;
22127 +       unsigned long totalram, freeram;
22128 +       rlim_t v;
22129 +
22130 +       /* we blindly accept the max */
22131 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22132 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
22133 +
22134 +       /* total minus used equals free */
22135 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22136 +       freeram = (v < totalram) ? totalram - v : 0;
22137 +
22138 +       val->totalram = totalram;
22139 +       val->freeram = freeram;
22140 +       val->bufferram = 0;
22141 +       val->totalhigh = 0;
22142 +       val->freehigh = 0;
22143 +       return;
22144 +}
22145 +
22146 +void vx_vsi_swapinfo(struct sysinfo *val)
22147 +{
22148 +       struct vx_info *vxi = current->vx_info;
22149 +       unsigned long totalswap, freeswap;
22150 +       rlim_t v, w;
22151 +
22152 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22153 +       if (v == RLIM_INFINITY) {
22154 +               val->freeswap = val->totalswap;
22155 +               return;
22156 +       }
22157 +
22158 +       /* we blindly accept the max */
22159 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
22160 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
22161 +
22162 +       /* currently 'used' swap */
22163 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22164 +       w -= (w > v) ? v : w;
22165 +
22166 +       /* total minus used equals free */
22167 +       freeswap = (w < totalswap) ? totalswap - w : 0;
22168 +
22169 +       val->totalswap = totalswap;
22170 +       val->freeswap = freeswap;
22171 +       return;
22172 +}
22173 +
22174 +
22175 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
22176 +{
22177 +       struct vx_info *vxi = mm->mm_vx_info;
22178 +       unsigned long points;
22179 +       rlim_t v, w;
22180 +
22181 +       if (!vxi)
22182 +               return 0;
22183 +
22184 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22185 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22186 +       points = (v > w) ? (v - w) : 0;
22187 +
22188 +       return points;
22189 +}
22190 +
22191 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/limit_init.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/limit_init.h
22192 --- linux-2.6.22.10/kernel/vserver/limit_init.h 1970-01-01 01:00:00 +0100
22193 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/limit_init.h       2007-10-29 23:34:24 +0100
22194 @@ -0,0 +1,33 @@
22195 +
22196 +
22197 +static inline void vx_info_init_limit(struct _vx_limit *limit)
22198 +{
22199 +       int lim;
22200 +
22201 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22202 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
22203 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
22204 +               __rlim_set(limit, lim, 0);
22205 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22206 +               __rlim_rmin(limit, lim) = 0;
22207 +               __rlim_rmax(limit, lim) = 0;
22208 +       }
22209 +}
22210 +
22211 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
22212 +{
22213 +#ifdef CONFIG_VSERVER_WARN
22214 +       rlim_t value;
22215 +       int lim;
22216 +
22217 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22218 +               if ((1 << lim) & VLIM_NOCHECK)
22219 +                       continue;
22220 +               value = __rlim_get(limit, lim);
22221 +               vxwprintk_xid(value,
22222 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
22223 +                       limit, vlimit_name[lim], lim, (long)value);
22224 +       }
22225 +#endif
22226 +}
22227 +
22228 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/limit_proc.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/limit_proc.h
22229 --- linux-2.6.22.10/kernel/vserver/limit_proc.h 1970-01-01 01:00:00 +0100
22230 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/limit_proc.h       2007-06-15 02:37:04 +0200
22231 @@ -0,0 +1,57 @@
22232 +#ifndef _VX_LIMIT_PROC_H
22233 +#define _VX_LIMIT_PROC_H
22234 +
22235 +#include <linux/vserver/limit_int.h>
22236 +
22237 +
22238 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22239 +#define VX_LIMIT_TOP   \
22240 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22241 +
22242 +#define VX_LIMIT_ARG(r)                                \
22243 +       (unsigned long)__rlim_get(limit, r),    \
22244 +       (unsigned long)__rlim_rmin(limit, r),   \
22245 +       (unsigned long)__rlim_rmax(limit, r),   \
22246 +       VX_VLIM(__rlim_soft(limit, r)),         \
22247 +       VX_VLIM(__rlim_hard(limit, r)),         \
22248 +       atomic_read(&__rlim_lhit(limit, r))
22249 +
22250 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22251 +{
22252 +       vx_limit_fixup(limit, -1);
22253 +       return sprintf(buffer, VX_LIMIT_TOP
22254 +               "PROC"  VX_LIMIT_FMT
22255 +               "VM"    VX_LIMIT_FMT
22256 +               "VML"   VX_LIMIT_FMT
22257 +               "RSS"   VX_LIMIT_FMT
22258 +               "ANON"  VX_LIMIT_FMT
22259 +               "RMAP"  VX_LIMIT_FMT
22260 +               "FILES" VX_LIMIT_FMT
22261 +               "OFD"   VX_LIMIT_FMT
22262 +               "LOCKS" VX_LIMIT_FMT
22263 +               "SOCK"  VX_LIMIT_FMT
22264 +               "MSGQ"  VX_LIMIT_FMT
22265 +               "SHM"   VX_LIMIT_FMT
22266 +               "SEMA"  VX_LIMIT_FMT
22267 +               "SEMS"  VX_LIMIT_FMT
22268 +               "DENT"  VX_LIMIT_FMT,
22269 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22270 +               VX_LIMIT_ARG(RLIMIT_AS),
22271 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22272 +               VX_LIMIT_ARG(RLIMIT_RSS),
22273 +               VX_LIMIT_ARG(VLIMIT_ANON),
22274 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22275 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22276 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22277 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22278 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22279 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22280 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22281 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22282 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22283 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22284 +}
22285 +
22286 +#endif /* _VX_LIMIT_PROC_H */
22287 +
22288 +
22289 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/monitor.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/monitor.c
22290 --- linux-2.6.22.10/kernel/vserver/monitor.c    1970-01-01 01:00:00 +0100
22291 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/monitor.c  2007-06-15 05:59:57 +0200
22292 @@ -0,0 +1,143 @@
22293 +/*
22294 + *  kernel/vserver/monitor.c
22295 + *
22296 + *  Virtual Context Scheduler Monitor
22297 + *
22298 + *  Copyright (C) 2006-2007 Herbert Pötzl
22299 + *
22300 + *  V0.01  basic design
22301 + *
22302 + */
22303 +
22304 +#include <linux/errno.h>
22305 +#include <linux/module.h>
22306 +#include <linux/types.h>
22307 +#include <linux/ctype.h>
22308 +#include <linux/jiffies.h>
22309 +
22310 +#include <asm/uaccess.h>
22311 +#include <asm/atomic.h>
22312 +#include <asm/unistd.h>
22313 +
22314 +#include <linux/vserver/monitor.h>
22315 +#include <linux/vserver/debug_cmd.h>
22316 +
22317 +
22318 +#ifdef CONFIG_VSERVER_MONITOR
22319 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
22320 +#else
22321 +#define VXM_SIZE       64
22322 +#endif
22323 +
22324 +struct _vx_monitor {
22325 +       unsigned int counter;
22326 +
22327 +       struct _vx_mon_entry entry[VXM_SIZE+1];
22328 +};
22329 +
22330 +
22331 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
22332 +
22333 +unsigned volatile int vxm_active = 1;
22334 +
22335 +static atomic_t sequence = ATOMIC_INIT(0);
22336 +
22337 +
22338 +/*     vxm_advance()
22339 +
22340 +       * requires disabled preemption                          */
22341 +
22342 +struct _vx_mon_entry *vxm_advance(int cpu)
22343 +{
22344 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22345 +       struct _vx_mon_entry *entry;
22346 +       unsigned int index;
22347 +
22348 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
22349 +       entry = &mon->entry[index];
22350 +
22351 +       entry->ev.seq = atomic_inc_return(&sequence);
22352 +       entry->ev.jif = jiffies;
22353 +       return entry;
22354 +}
22355 +
22356 +EXPORT_SYMBOL_GPL(vxm_advance);
22357 +
22358 +
22359 +int do_read_monitor(struct __user _vx_mon_entry *data,
22360 +       int cpu, uint32_t *index, uint32_t *count)
22361 +{
22362 +       int pos, ret = 0;
22363 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22364 +       int end = mon->counter;
22365 +       int start = end - VXM_SIZE + 2;
22366 +       int idx = *index;
22367 +
22368 +       /* special case: get current pos */
22369 +       if (!*count) {
22370 +               *index = end;
22371 +               return 0;
22372 +       }
22373 +
22374 +       /* have we lost some data? */
22375 +       if (idx < start)
22376 +               idx = start;
22377 +
22378 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22379 +               struct _vx_mon_entry *entry =
22380 +                       &mon->entry[idx % VXM_SIZE];
22381 +
22382 +               /* send entry to userspace */
22383 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22384 +               if (ret)
22385 +                       break;
22386 +       }
22387 +       /* save new index and count */
22388 +       *index = idx;
22389 +       *count = pos;
22390 +       return ret ? ret : (*index < end);
22391 +}
22392 +
22393 +int vc_read_monitor(uint32_t id, void __user *data)
22394 +{
22395 +       struct vcmd_read_monitor_v0 vc_data;
22396 +       int ret;
22397 +
22398 +       if (id >= NR_CPUS)
22399 +               return -EINVAL;
22400 +
22401 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22402 +               return -EFAULT;
22403 +
22404 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22405 +               id, &vc_data.index, &vc_data.count);
22406 +
22407 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22408 +               return -EFAULT;
22409 +       return ret;
22410 +}
22411 +
22412 +#ifdef CONFIG_COMPAT
22413 +
22414 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22415 +{
22416 +       struct vcmd_read_monitor_v0_x32 vc_data;
22417 +       int ret;
22418 +
22419 +       if (id >= NR_CPUS)
22420 +               return -EINVAL;
22421 +
22422 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22423 +               return -EFAULT;
22424 +
22425 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22426 +               compat_ptr(vc_data.data_ptr),
22427 +               id, &vc_data.index, &vc_data.count);
22428 +
22429 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22430 +               return -EFAULT;
22431 +       return ret;
22432 +}
22433 +
22434 +#endif /* CONFIG_COMPAT */
22435 +
22436 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/network.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/network.c
22437 --- linux-2.6.22.10/kernel/vserver/network.c    1970-01-01 01:00:00 +0100
22438 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/network.c  2007-07-19 07:08:54 +0200
22439 @@ -0,0 +1,771 @@
22440 +/*
22441 + *  linux/kernel/vserver/network.c
22442 + *
22443 + *  Virtual Server: Network Support
22444 + *
22445 + *  Copyright (C) 2003-2007  Herbert Pötzl
22446 + *
22447 + *  V0.01  broken out from vcontext V0.05
22448 + *  V0.02  cleaned up implementation
22449 + *  V0.03  added equiv nx commands
22450 + *  V0.04  switch to RCU based hash
22451 + *  V0.05  and back to locking again
22452 + *  V0.06  changed vcmds to nxi arg
22453 + *  V0.07  have __create claim() the nxi
22454 + *
22455 + */
22456 +
22457 +#include <linux/slab.h>
22458 +#include <linux/rcupdate.h>
22459 +#include <net/tcp.h>
22460 +
22461 +#include <asm/errno.h>
22462 +#include <linux/vserver/base.h>
22463 +#include <linux/vserver/network_cmd.h>
22464 +
22465 +
22466 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22467 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22468 +
22469 +
22470 +/*     __alloc_nx_info()
22471 +
22472 +       * allocate an initialized nx_info struct
22473 +       * doesn't make it visible (hash)                        */
22474 +
22475 +static struct nx_info *__alloc_nx_info(nid_t nid)
22476 +{
22477 +       struct nx_info *new = NULL;
22478 +
22479 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22480 +
22481 +       /* would this benefit from a slab cache? */
22482 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22483 +       if (!new)
22484 +               return 0;
22485 +
22486 +       memset(new, 0, sizeof(struct nx_info));
22487 +       new->nx_id = nid;
22488 +       INIT_HLIST_NODE(&new->nx_hlist);
22489 +       atomic_set(&new->nx_usecnt, 0);
22490 +       atomic_set(&new->nx_tasks, 0);
22491 +       new->nx_state = 0;
22492 +
22493 +       new->nx_flags = NXF_INIT_SET;
22494 +
22495 +       /* rest of init goes here */
22496 +
22497 +       vxdprintk(VXD_CBIT(nid, 0),
22498 +               "alloc_nx_info(%d) = %p", nid, new);
22499 +       atomic_inc(&nx_global_ctotal);
22500 +       return new;
22501 +}
22502 +
22503 +/*     __dealloc_nx_info()
22504 +
22505 +       * final disposal of nx_info                             */
22506 +
22507 +static void __dealloc_nx_info(struct nx_info *nxi)
22508 +{
22509 +       vxdprintk(VXD_CBIT(nid, 0),
22510 +               "dealloc_nx_info(%p)", nxi);
22511 +
22512 +       nxi->nx_hlist.next = LIST_POISON1;
22513 +       nxi->nx_id = -1;
22514 +
22515 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22516 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22517 +
22518 +       nxi->nx_state |= NXS_RELEASED;
22519 +       kfree(nxi);
22520 +       atomic_dec(&nx_global_ctotal);
22521 +}
22522 +
22523 +static void __shutdown_nx_info(struct nx_info *nxi)
22524 +{
22525 +       nxi->nx_state |= NXS_SHUTDOWN;
22526 +       vs_net_change(nxi, VSC_NETDOWN);
22527 +}
22528 +
22529 +/*     exported stuff                                          */
22530 +
22531 +void free_nx_info(struct nx_info *nxi)
22532 +{
22533 +       /* context shutdown is mandatory */
22534 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22535 +
22536 +       /* context must not be hashed */
22537 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22538 +
22539 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22540 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22541 +
22542 +       __dealloc_nx_info(nxi);
22543 +}
22544 +
22545 +
22546 +/*     hash table for nx_info hash */
22547 +
22548 +#define NX_HASH_SIZE   13
22549 +
22550 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22551 +
22552 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22553 +
22554 +
22555 +static inline unsigned int __hashval(nid_t nid)
22556 +{
22557 +       return (nid % NX_HASH_SIZE);
22558 +}
22559 +
22560 +
22561 +
22562 +/*     __hash_nx_info()
22563 +
22564 +       * add the nxi to the global hash table
22565 +       * requires the hash_lock to be held                     */
22566 +
22567 +static inline void __hash_nx_info(struct nx_info *nxi)
22568 +{
22569 +       struct hlist_head *head;
22570 +
22571 +       vxd_assert_lock(&nx_info_hash_lock);
22572 +       vxdprintk(VXD_CBIT(nid, 4),
22573 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22574 +
22575 +       /* context must not be hashed */
22576 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22577 +
22578 +       nxi->nx_state |= NXS_HASHED;
22579 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22580 +       hlist_add_head(&nxi->nx_hlist, head);
22581 +       atomic_inc(&nx_global_cactive);
22582 +}
22583 +
22584 +/*     __unhash_nx_info()
22585 +
22586 +       * remove the nxi from the global hash table
22587 +       * requires the hash_lock to be held                     */
22588 +
22589 +static inline void __unhash_nx_info(struct nx_info *nxi)
22590 +{
22591 +       vxd_assert_lock(&nx_info_hash_lock);
22592 +       vxdprintk(VXD_CBIT(nid, 4),
22593 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22594 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22595 +
22596 +       /* context must be hashed */
22597 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22598 +       /* but without tasks */
22599 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22600 +
22601 +       nxi->nx_state &= ~NXS_HASHED;
22602 +       hlist_del(&nxi->nx_hlist);
22603 +       atomic_dec(&nx_global_cactive);
22604 +}
22605 +
22606 +
22607 +/*     __lookup_nx_info()
22608 +
22609 +       * requires the hash_lock to be held
22610 +       * doesn't increment the nx_refcnt                       */
22611 +
22612 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22613 +{
22614 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22615 +       struct hlist_node *pos;
22616 +       struct nx_info *nxi;
22617 +
22618 +       vxd_assert_lock(&nx_info_hash_lock);
22619 +       hlist_for_each(pos, head) {
22620 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22621 +
22622 +               if (nxi->nx_id == nid)
22623 +                       goto found;
22624 +       }
22625 +       nxi = NULL;
22626 +found:
22627 +       vxdprintk(VXD_CBIT(nid, 0),
22628 +               "__lookup_nx_info(#%u): %p[#%u]",
22629 +               nid, nxi, nxi ? nxi->nx_id : 0);
22630 +       return nxi;
22631 +}
22632 +
22633 +
22634 +/*     __nx_dynamic_id()
22635 +
22636 +       * find unused dynamic nid
22637 +       * requires the hash_lock to be held                     */
22638 +
22639 +static inline nid_t __nx_dynamic_id(void)
22640 +{
22641 +       static nid_t seq = MAX_N_CONTEXT;
22642 +       nid_t barrier = seq;
22643 +
22644 +       vxd_assert_lock(&nx_info_hash_lock);
22645 +       do {
22646 +               if (++seq > MAX_N_CONTEXT)
22647 +                       seq = MIN_D_CONTEXT;
22648 +               if (!__lookup_nx_info(seq)) {
22649 +                       vxdprintk(VXD_CBIT(nid, 4),
22650 +                               "__nx_dynamic_id: [#%d]", seq);
22651 +                       return seq;
22652 +               }
22653 +       } while (barrier != seq);
22654 +       return 0;
22655 +}
22656 +
22657 +/*     __create_nx_info()
22658 +
22659 +       * create the requested context
22660 +       * get(), claim() and hash it                            */
22661 +
22662 +static struct nx_info *__create_nx_info(int id)
22663 +{
22664 +       struct nx_info *new, *nxi = NULL;
22665 +
22666 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22667 +
22668 +       if (!(new = __alloc_nx_info(id)))
22669 +               return ERR_PTR(-ENOMEM);
22670 +
22671 +       /* required to make dynamic xids unique */
22672 +       spin_lock(&nx_info_hash_lock);
22673 +
22674 +       /* dynamic context requested */
22675 +       if (id == NX_DYNAMIC_ID) {
22676 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
22677 +               id = __nx_dynamic_id();
22678 +               if (!id) {
22679 +                       printk(KERN_ERR "no dynamic context available.\n");
22680 +                       nxi = ERR_PTR(-EAGAIN);
22681 +                       goto out_unlock;
22682 +               }
22683 +               new->nx_id = id;
22684 +#else
22685 +               printk(KERN_ERR "dynamic contexts disabled.\n");
22686 +               nxi = ERR_PTR(-EINVAL);
22687 +               goto out_unlock;
22688 +#endif
22689 +       }
22690 +       /* static context requested */
22691 +       else if ((nxi = __lookup_nx_info(id))) {
22692 +               vxdprintk(VXD_CBIT(nid, 0),
22693 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22694 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22695 +                       nxi = ERR_PTR(-EBUSY);
22696 +               else
22697 +                       nxi = ERR_PTR(-EEXIST);
22698 +               goto out_unlock;
22699 +       }
22700 +       /* dynamic nid creation blocker */
22701 +       else if (id >= MIN_D_CONTEXT) {
22702 +               vxdprintk(VXD_CBIT(nid, 0),
22703 +                       "create_nx_info(%d) (dynamic rejected)", id);
22704 +               nxi = ERR_PTR(-EINVAL);
22705 +               goto out_unlock;
22706 +       }
22707 +
22708 +       /* new context */
22709 +       vxdprintk(VXD_CBIT(nid, 0),
22710 +               "create_nx_info(%d) = %p (new)", id, new);
22711 +       claim_nx_info(new, NULL);
22712 +       __hash_nx_info(get_nx_info(new));
22713 +       nxi = new, new = NULL;
22714 +
22715 +out_unlock:
22716 +       spin_unlock(&nx_info_hash_lock);
22717 +       if (new)
22718 +               __dealloc_nx_info(new);
22719 +       return nxi;
22720 +}
22721 +
22722 +
22723 +
22724 +/*     exported stuff                                          */
22725 +
22726 +
22727 +void unhash_nx_info(struct nx_info *nxi)
22728 +{
22729 +       __shutdown_nx_info(nxi);
22730 +       spin_lock(&nx_info_hash_lock);
22731 +       __unhash_nx_info(nxi);
22732 +       spin_unlock(&nx_info_hash_lock);
22733 +}
22734 +
22735 +#ifdef  CONFIG_VSERVER_LEGACYNET
22736 +
22737 +struct nx_info *create_nx_info(void)
22738 +{
22739 +       return __create_nx_info(NX_DYNAMIC_ID);
22740 +}
22741 +
22742 +#endif
22743 +
22744 +/*     lookup_nx_info()
22745 +
22746 +       * search for a nx_info and get() it
22747 +       * negative id means current                             */
22748 +
22749 +struct nx_info *lookup_nx_info(int id)
22750 +{
22751 +       struct nx_info *nxi = NULL;
22752 +
22753 +       if (id < 0) {
22754 +               nxi = get_nx_info(current->nx_info);
22755 +       } else if (id > 1) {
22756 +               spin_lock(&nx_info_hash_lock);
22757 +               nxi = get_nx_info(__lookup_nx_info(id));
22758 +               spin_unlock(&nx_info_hash_lock);
22759 +       }
22760 +       return nxi;
22761 +}
22762 +
22763 +/*     nid_is_hashed()
22764 +
22765 +       * verify that nid is still hashed                       */
22766 +
22767 +int nid_is_hashed(nid_t nid)
22768 +{
22769 +       int hashed;
22770 +
22771 +       spin_lock(&nx_info_hash_lock);
22772 +       hashed = (__lookup_nx_info(nid) != NULL);
22773 +       spin_unlock(&nx_info_hash_lock);
22774 +       return hashed;
22775 +}
22776 +
22777 +
22778 +#ifdef CONFIG_PROC_FS
22779 +
22780 +/*     get_nid_list()
22781 +
22782 +       * get a subset of hashed nids for proc
22783 +       * assumes size is at least one                          */
22784 +
22785 +int get_nid_list(int index, unsigned int *nids, int size)
22786 +{
22787 +       int hindex, nr_nids = 0;
22788 +
22789 +       /* only show current and children */
22790 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22791 +               if (index > 0)
22792 +                       return 0;
22793 +               nids[nr_nids] = nx_current_nid();
22794 +               return 1;
22795 +       }
22796 +
22797 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22798 +               struct hlist_head *head = &nx_info_hash[hindex];
22799 +               struct hlist_node *pos;
22800 +
22801 +               spin_lock(&nx_info_hash_lock);
22802 +               hlist_for_each(pos, head) {
22803 +                       struct nx_info *nxi;
22804 +
22805 +                       if (--index > 0)
22806 +                               continue;
22807 +
22808 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22809 +                       nids[nr_nids] = nxi->nx_id;
22810 +                       if (++nr_nids >= size) {
22811 +                               spin_unlock(&nx_info_hash_lock);
22812 +                               goto out;
22813 +                       }
22814 +               }
22815 +               /* keep the lock time short */
22816 +               spin_unlock(&nx_info_hash_lock);
22817 +       }
22818 +out:
22819 +       return nr_nids;
22820 +}
22821 +#endif
22822 +
22823 +
22824 +/*
22825 + *     migrate task to new network
22826 + *     gets nxi, puts old_nxi on change
22827 + */
22828 +
22829 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22830 +{
22831 +       struct nx_info *old_nxi;
22832 +       int ret = 0;
22833 +
22834 +       if (!p || !nxi)
22835 +               BUG();
22836 +
22837 +       vxdprintk(VXD_CBIT(nid, 5),
22838 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22839 +               p, nxi, nxi->nx_id,
22840 +               atomic_read(&nxi->nx_usecnt),
22841 +               atomic_read(&nxi->nx_tasks));
22842 +
22843 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22844 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22845 +               return -EACCES;
22846 +
22847 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22848 +               return -EFAULT;
22849 +
22850 +       /* maybe disallow this completely? */
22851 +       old_nxi = task_get_nx_info(p);
22852 +       if (old_nxi == nxi)
22853 +               goto out;
22854 +
22855 +       task_lock(p);
22856 +       if (old_nxi)
22857 +               clr_nx_info(&p->nx_info);
22858 +       claim_nx_info(nxi, p);
22859 +       set_nx_info(&p->nx_info, nxi);
22860 +       p->nid = nxi->nx_id;
22861 +       task_unlock(p);
22862 +
22863 +       vxdprintk(VXD_CBIT(nid, 5),
22864 +               "moved task %p into nxi:%p[#%d]",
22865 +               p, nxi, nxi->nx_id);
22866 +
22867 +       if (old_nxi)
22868 +               release_nx_info(old_nxi, p);
22869 +       ret = 0;
22870 +out:
22871 +       put_nx_info(old_nxi);
22872 +       return ret;
22873 +}
22874 +
22875 +
22876 +#ifdef CONFIG_INET
22877 +
22878 +#include <linux/netdevice.h>
22879 +#include <linux/inetdevice.h>
22880 +
22881 +int ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
22882 +{
22883 +       if (!nxi)
22884 +               return 1;
22885 +       if (!ifa)
22886 +               return 0;
22887 +       return addr_in_nx_info(nxi, ifa->ifa_local);
22888 +}
22889 +
22890 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
22891 +{
22892 +       struct in_device *in_dev;
22893 +       struct in_ifaddr **ifap;
22894 +       struct in_ifaddr *ifa;
22895 +       int ret = 0;
22896 +
22897 +       if (!nxi)
22898 +               return 1;
22899 +
22900 +       if (!dev)
22901 +               goto out;
22902 +       in_dev = in_dev_get(dev);
22903 +       if (!in_dev)
22904 +               goto out;
22905 +
22906 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
22907 +               ifap = &ifa->ifa_next) {
22908 +               if (addr_in_nx_info(nxi, ifa->ifa_local)) {
22909 +                       ret = 1;
22910 +                       break;
22911 +               }
22912 +       }
22913 +       in_dev_put(in_dev);
22914 +out:
22915 +       return ret;
22916 +}
22917 +
22918 +/*
22919 + *     check if address is covered by socket
22920 + *
22921 + *     sk:     the socket to check against
22922 + *     addr:   the address in question (must be != 0)
22923 + */
22924 +static inline int __addr_in_socket(const struct sock *sk, uint32_t addr)
22925 +{
22926 +       struct nx_info *nxi = sk->sk_nx_info;
22927 +       uint32_t saddr = inet_rcv_saddr(sk);
22928 +
22929 +       vxdprintk(VXD_CBIT(net, 5),
22930 +               "__addr_in_socket(%p," NIPQUAD_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
22931 +               sk, NIPQUAD(addr), nxi, NIPQUAD(saddr), sk->sk_socket,
22932 +               (sk->sk_socket ? sk->sk_socket->flags : 0));
22933 +
22934 +       if (saddr) {
22935 +               /* direct address match */
22936 +               return (saddr == addr);
22937 +       } else if (nxi) {
22938 +               /* match against nx_info */
22939 +               return addr_in_nx_info(nxi, addr);
22940 +       } else {
22941 +               /* unrestricted any socket */
22942 +               return 1;
22943 +       }
22944 +}
22945 +
22946 +
22947 +int nx_addr_conflict(struct nx_info *nxi, uint32_t addr, const struct sock *sk)
22948 +{
22949 +       vxdprintk(VXD_CBIT(net, 2),
22950 +               "nx_addr_conflict(%p,%p) " NIPQUAD_FMT,
22951 +               nxi, sk, NIPQUAD(addr));
22952 +
22953 +       if (addr) {
22954 +               /* check real address */
22955 +               return __addr_in_socket(sk, addr);
22956 +       } else if (nxi) {
22957 +               /* check against nx_info */
22958 +               int i, n = nxi->nbipv4;
22959 +
22960 +               for (i = 0; i < n; i++)
22961 +                       if (__addr_in_socket(sk, nxi->ipv4[i]))
22962 +                               return 1;
22963 +               return 0;
22964 +       } else {
22965 +               /* check against any */
22966 +               return 1;
22967 +       }
22968 +}
22969 +
22970 +#endif /* CONFIG_INET */
22971 +
22972 +void nx_set_persistent(struct nx_info *nxi)
22973 +{
22974 +       vxdprintk(VXD_CBIT(nid, 6),
22975 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22976 +
22977 +       get_nx_info(nxi);
22978 +       claim_nx_info(nxi, NULL);
22979 +}
22980 +
22981 +void nx_clear_persistent(struct nx_info *nxi)
22982 +{
22983 +       vxdprintk(VXD_CBIT(nid, 6),
22984 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22985 +
22986 +       release_nx_info(nxi, NULL);
22987 +       put_nx_info(nxi);
22988 +}
22989 +
22990 +void nx_update_persistent(struct nx_info *nxi)
22991 +{
22992 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22993 +               nx_set_persistent(nxi);
22994 +       else
22995 +               nx_clear_persistent(nxi);
22996 +}
22997 +
22998 +/* vserver syscall commands below here */
22999 +
23000 +/* taks nid and nx_info functions */
23001 +
23002 +#include <asm/uaccess.h>
23003 +
23004 +
23005 +int vc_task_nid(uint32_t id, void __user *data)
23006 +{
23007 +       nid_t nid;
23008 +
23009 +       if (id) {
23010 +               struct task_struct *tsk;
23011 +
23012 +               if (!nx_check(0, VS_ADMIN | VS_WATCH))
23013 +                       return -EPERM;
23014 +
23015 +               read_lock(&tasklist_lock);
23016 +               tsk = find_task_by_real_pid(id);
23017 +               nid = (tsk) ? tsk->nid : -ESRCH;
23018 +               read_unlock(&tasklist_lock);
23019 +       } else
23020 +               nid = nx_current_nid();
23021 +       return nid;
23022 +}
23023 +
23024 +
23025 +int vc_nx_info(struct nx_info *nxi, void __user *data)
23026 +{
23027 +       struct vcmd_nx_info_v0 vc_data;
23028 +
23029 +       vc_data.nid = nxi->nx_id;
23030 +
23031 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23032 +               return -EFAULT;
23033 +       return 0;
23034 +}
23035 +
23036 +
23037 +/* network functions */
23038 +
23039 +int vc_net_create(uint32_t nid, void __user *data)
23040 +{
23041 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
23042 +       struct nx_info *new_nxi;
23043 +       int ret;
23044 +
23045 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23046 +               return -EFAULT;
23047 +
23048 +       if ((nid > MAX_S_CONTEXT) && (nid != NX_DYNAMIC_ID))
23049 +               return -EINVAL;
23050 +       if (nid < 2)
23051 +               return -EINVAL;
23052 +
23053 +       new_nxi = __create_nx_info(nid);
23054 +       if (IS_ERR(new_nxi))
23055 +               return PTR_ERR(new_nxi);
23056 +
23057 +       /* initial flags */
23058 +       new_nxi->nx_flags = vc_data.flagword;
23059 +
23060 +       ret = -ENOEXEC;
23061 +       if (vs_net_change(new_nxi, VSC_NETUP))
23062 +               goto out;
23063 +
23064 +       ret = nx_migrate_task(current, new_nxi);
23065 +       if (ret)
23066 +               goto out;
23067 +
23068 +       /* return context id on success */
23069 +       ret = new_nxi->nx_id;
23070 +
23071 +       /* get a reference for persistent contexts */
23072 +       if ((vc_data.flagword & NXF_PERSISTENT))
23073 +               nx_set_persistent(new_nxi);
23074 +out:
23075 +       release_nx_info(new_nxi, NULL);
23076 +       put_nx_info(new_nxi);
23077 +       return ret;
23078 +}
23079 +
23080 +
23081 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
23082 +{
23083 +       return nx_migrate_task(current, nxi);
23084 +}
23085 +
23086 +int vc_net_add(struct nx_info *nxi, void __user *data)
23087 +{
23088 +       struct vcmd_net_addr_v0 vc_data;
23089 +       int index, pos, ret = 0;
23090 +
23091 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23092 +               return -EFAULT;
23093 +
23094 +       switch (vc_data.type) {
23095 +       case NXA_TYPE_IPV4:
23096 +               if ((vc_data.count < 1) || (vc_data.count > 4))
23097 +                       return -EINVAL;
23098 +               break;
23099 +
23100 +       default:
23101 +               break;
23102 +       }
23103 +
23104 +       switch (vc_data.type) {
23105 +       case NXA_TYPE_IPV4:
23106 +               index = 0;
23107 +               while ((index < vc_data.count) &&
23108 +                       ((pos = nxi->nbipv4) < NB_IPV4ROOT)) {
23109 +                       nxi->ipv4[pos] = vc_data.ip[index];
23110 +                       nxi->mask[pos] = vc_data.mask[index];
23111 +                       index++;
23112 +                       nxi->nbipv4++;
23113 +               }
23114 +               ret = index;
23115 +               break;
23116 +
23117 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
23118 +               nxi->v4_bcast = vc_data.ip[0];
23119 +               ret = 1;
23120 +               break;
23121 +
23122 +       default:
23123 +               ret = -EINVAL;
23124 +               break;
23125 +       }
23126 +       return ret;
23127 +}
23128 +
23129 +int vc_net_remove(struct nx_info *nxi, void __user *data)
23130 +{
23131 +       struct vcmd_net_addr_v0 vc_data;
23132 +
23133 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23134 +               return -EFAULT;
23135 +
23136 +       switch (vc_data.type) {
23137 +       case NXA_TYPE_ANY:
23138 +               nxi->nbipv4 = 0;
23139 +               break;
23140 +
23141 +       default:
23142 +               return -EINVAL;
23143 +       }
23144 +       return 0;
23145 +}
23146 +
23147 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23148 +{
23149 +       struct vcmd_net_flags_v0 vc_data;
23150 +
23151 +       vc_data.flagword = nxi->nx_flags;
23152 +
23153 +       /* special STATE flag handling */
23154 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23155 +
23156 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23157 +               return -EFAULT;
23158 +       return 0;
23159 +}
23160 +
23161 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23162 +{
23163 +       struct vcmd_net_flags_v0 vc_data;
23164 +       uint64_t mask, trigger;
23165 +
23166 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23167 +               return -EFAULT;
23168 +
23169 +       /* special STATE flag handling */
23170 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23171 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23172 +
23173 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23174 +               vc_data.flagword, mask);
23175 +       if (trigger & NXF_PERSISTENT)
23176 +               nx_update_persistent(nxi);
23177 +
23178 +       return 0;
23179 +}
23180 +
23181 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23182 +{
23183 +       struct vcmd_net_caps_v0 vc_data;
23184 +
23185 +       vc_data.ncaps = nxi->nx_ncaps;
23186 +       vc_data.cmask = ~0ULL;
23187 +
23188 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23189 +               return -EFAULT;
23190 +       return 0;
23191 +}
23192 +
23193 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23194 +{
23195 +       struct vcmd_net_caps_v0 vc_data;
23196 +
23197 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23198 +               return -EFAULT;
23199 +
23200 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23201 +               vc_data.ncaps, vc_data.cmask);
23202 +       return 0;
23203 +}
23204 +
23205 +
23206 +#include <linux/module.h>
23207 +
23208 +EXPORT_SYMBOL_GPL(free_nx_info);
23209 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23210 +
23211 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/proc.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/proc.c
23212 --- linux-2.6.22.10/kernel/vserver/proc.c       1970-01-01 01:00:00 +0100
23213 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/proc.c     2007-06-15 19:20:10 +0200
23214 @@ -0,0 +1,1033 @@
23215 +/*
23216 + *  linux/kernel/vserver/proc.c
23217 + *
23218 + *  Virtual Context Support
23219 + *
23220 + *  Copyright (C) 2003-2007  Herbert Pötzl
23221 + *
23222 + *  V0.01  basic structure
23223 + *  V0.02  adaptation vs1.3.0
23224 + *  V0.03  proc permissions
23225 + *  V0.04  locking/generic
23226 + *  V0.05  next generation procfs
23227 + *  V0.06  inode validation
23228 + *  V0.07  generic rewrite vid
23229 + *  V0.08  remove inode type
23230 + *
23231 + */
23232 +
23233 +#include <linux/errno.h>
23234 +#include <linux/proc_fs.h>
23235 +#include <linux/sched.h>
23236 +#include <linux/vs_context.h>
23237 +#include <linux/vs_network.h>
23238 +#include <linux/vs_cvirt.h>
23239 +
23240 +#include <linux/vserver/switch.h>
23241 +#include <linux/vserver/global.h>
23242 +
23243 +#include <asm/uaccess.h>
23244 +#include <asm/unistd.h>
23245 +
23246 +#include "cvirt_proc.h"
23247 +#include "cacct_proc.h"
23248 +#include "limit_proc.h"
23249 +#include "sched_proc.h"
23250 +#include "vci_config.h"
23251 +
23252 +static struct proc_dir_entry *proc_virtual;
23253 +
23254 +static struct proc_dir_entry *proc_virtnet;
23255 +
23256 +
23257 +/* first the actual feeds */
23258 +
23259 +
23260 +static int proc_vci(char *buffer)
23261 +{
23262 +       return sprintf(buffer,
23263 +               "VCIVersion:\t%04x:%04x\n"
23264 +               "VCISyscall:\t%d\n"
23265 +               "VCIKernel:\t%08x\n",
23266 +               VCI_VERSION >> 16,
23267 +               VCI_VERSION & 0xFFFF,
23268 +               __NR_vserver,
23269 +               vci_kernel_config());
23270 +}
23271 +
23272 +static int proc_virtual_info(char *buffer)
23273 +{
23274 +       return proc_vci(buffer);
23275 +}
23276 +
23277 +static int proc_virtual_status(char *buffer)
23278 +{
23279 +       return sprintf(buffer,
23280 +               "#CTotal:\t%d\n"
23281 +               "#CActive:\t%d\n"
23282 +               "#NSProxy:\t%d\t%d %d %d %d\n",
23283 +               atomic_read(&vx_global_ctotal),
23284 +               atomic_read(&vx_global_cactive),
23285 +               atomic_read(&vs_global_nsproxy),
23286 +               atomic_read(&vs_global_fs),
23287 +               atomic_read(&vs_global_mnt_ns),
23288 +               atomic_read(&vs_global_uts_ns),
23289 +               atomic_read(&vs_global_ipc_ns));
23290 +}
23291 +
23292 +
23293 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23294 +{
23295 +       int length;
23296 +
23297 +       length = sprintf(buffer,
23298 +               "ID:\t%d\n"
23299 +               "Info:\t%p\n"
23300 +               "Init:\t%d\n",
23301 +               vxi->vx_id,
23302 +               vxi,
23303 +               vxi->vx_initpid);
23304 +       return length;
23305 +}
23306 +
23307 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23308 +{
23309 +       int length;
23310 +
23311 +       length = sprintf(buffer,
23312 +               "UseCnt:\t%d\n"
23313 +               "Tasks:\t%d\n"
23314 +               "Flags:\t%016llx\n"
23315 +               "BCaps:\t%016llx\n"
23316 +               "CCaps:\t%016llx\n"
23317 +               "Spaces:\t%08lx\n",
23318 +               atomic_read(&vxi->vx_usecnt),
23319 +               atomic_read(&vxi->vx_tasks),
23320 +               (unsigned long long)vxi->vx_flags,
23321 +               (unsigned long long)vxi->vx_bcaps,
23322 +               (unsigned long long)vxi->vx_ccaps,
23323 +               vxi->vx_nsmask);
23324 +       return length;
23325 +}
23326 +
23327 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23328 +{
23329 +       return vx_info_proc_limit(&vxi->limit, buffer);
23330 +}
23331 +
23332 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23333 +{
23334 +       int cpu, length;
23335 +
23336 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23337 +       for_each_online_cpu(cpu) {
23338 +               length += vx_info_proc_sched_pc(
23339 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23340 +                       buffer + length, cpu);
23341 +       }
23342 +       return length;
23343 +}
23344 +
23345 +int proc_vxi_nsproxy(struct vx_info *vxi, char *buffer)
23346 +{
23347 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy, buffer);
23348 +}
23349 +
23350 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23351 +{
23352 +       int cpu, length;
23353 +
23354 +       vx_update_load(vxi);
23355 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23356 +       for_each_online_cpu(cpu) {
23357 +               length += vx_info_proc_cvirt_pc(
23358 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23359 +                       buffer + length, cpu);
23360 +       }
23361 +       return length;
23362 +}
23363 +
23364 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23365 +{
23366 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23367 +}
23368 +
23369 +
23370 +static int proc_virtnet_info(char *buffer)
23371 +{
23372 +       return proc_vci(buffer);
23373 +}
23374 +
23375 +static int proc_virtnet_status(char *buffer)
23376 +{
23377 +       return sprintf(buffer,
23378 +               "#CTotal:\t%d\n"
23379 +               "#CActive:\t%d\n",
23380 +               atomic_read(&nx_global_ctotal),
23381 +               atomic_read(&nx_global_cactive));
23382 +}
23383 +
23384 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23385 +{
23386 +       int length, i;
23387 +
23388 +       length = sprintf(buffer,
23389 +               "ID:\t%d\n"
23390 +               "Info:\t%p\n",
23391 +               nxi->nx_id,
23392 +               nxi);
23393 +       for (i = 0; i < nxi->nbipv4; i++) {
23394 +               length += sprintf(buffer + length,
23395 +                       "%d:\t" NIPQUAD_FMT "/" NIPQUAD_FMT "\n", i,
23396 +                       NIPQUAD(nxi->ipv4[i]), NIPQUAD(nxi->mask[i]));
23397 +       }
23398 +       return length;
23399 +}
23400 +
23401 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23402 +{
23403 +       int length;
23404 +
23405 +       length = sprintf(buffer,
23406 +               "UseCnt:\t%d\n"
23407 +               "Tasks:\t%d\n"
23408 +               "Flags:\t%016llx\n"
23409 +               "NCaps:\t%016llx\n",
23410 +               atomic_read(&nxi->nx_usecnt),
23411 +               atomic_read(&nxi->nx_tasks),
23412 +               (unsigned long long)nxi->nx_flags,
23413 +               (unsigned long long)nxi->nx_ncaps);
23414 +       return length;
23415 +}
23416 +
23417 +
23418 +
23419 +/* here the inode helpers */
23420 +
23421 +struct vs_entry {
23422 +       int len;
23423 +       char *name;
23424 +       mode_t mode;
23425 +       struct inode_operations *iop;
23426 +       struct file_operations *fop;
23427 +       union proc_op op;
23428 +};
23429 +
23430 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23431 +{
23432 +       struct inode *inode = new_inode(sb);
23433 +
23434 +       if (!inode)
23435 +               goto out;
23436 +
23437 +       inode->i_mode = p->mode;
23438 +       if (p->iop)
23439 +               inode->i_op = p->iop;
23440 +       if (p->fop)
23441 +               inode->i_fop = p->fop;
23442 +
23443 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23444 +       inode->i_flags |= S_IMMUTABLE;
23445 +
23446 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23447 +
23448 +       inode->i_uid = 0;
23449 +       inode->i_gid = 0;
23450 +       inode->i_tag = 0;
23451 +out:
23452 +       return inode;
23453 +}
23454 +
23455 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23456 +       struct dentry *dentry, int id, void *ptr)
23457 +{
23458 +       struct vs_entry *p = ptr;
23459 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23460 +       struct dentry *error = ERR_PTR(-EINVAL);
23461 +
23462 +       if (!inode)
23463 +               goto out;
23464 +
23465 +       PROC_I(inode)->op = p->op;
23466 +       PROC_I(inode)->fd = id;
23467 +       d_add(dentry, inode);
23468 +       error = NULL;
23469 +out:
23470 +       return error;
23471 +}
23472 +
23473 +/* Lookups */
23474 +
23475 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23476 +
23477 +/*
23478 + * Fill a directory entry.
23479 + *
23480 + * If possible create the dcache entry and derive our inode number and
23481 + * file type from dcache entry.
23482 + *
23483 + * Since all of the proc inode numbers are dynamically generated, the inode
23484 + * numbers do not exist until the inode is cache.  This means creating the
23485 + * the dcache entry in readdir is necessary to keep the inode numbers
23486 + * reported by readdir in sync with the inode numbers reported
23487 + * by stat.
23488 + */
23489 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23490 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23491 +{
23492 +       struct dentry *child, *dir = filp->f_dentry;
23493 +       struct inode *inode;
23494 +       struct qstr qname;
23495 +       ino_t ino = 0;
23496 +       unsigned type = DT_UNKNOWN;
23497 +
23498 +       qname.name = name;
23499 +       qname.len  = len;
23500 +       qname.hash = full_name_hash(name, len);
23501 +
23502 +       child = d_lookup(dir, &qname);
23503 +       if (!child) {
23504 +               struct dentry *new;
23505 +               new = d_alloc(dir, &qname);
23506 +               if (new) {
23507 +                       child = instantiate(dir->d_inode, new, id, ptr);
23508 +                       if (child)
23509 +                               dput(new);
23510 +                       else
23511 +                               child = new;
23512 +               }
23513 +       }
23514 +       if (!child || IS_ERR(child) || !child->d_inode)
23515 +               goto end_instantiate;
23516 +       inode = child->d_inode;
23517 +       if (inode) {
23518 +               ino = inode->i_ino;
23519 +               type = inode->i_mode >> 12;
23520 +       }
23521 +       dput(child);
23522 +end_instantiate:
23523 +       if (!ino)
23524 +               ino = find_inode_number(dir, &qname);
23525 +       if (!ino)
23526 +               ino = 1;
23527 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23528 +}
23529 +
23530 +
23531 +
23532 +/* get and revalidate vx_info/xid */
23533 +
23534 +static inline
23535 +struct vx_info *get_proc_vx_info(struct inode *inode)
23536 +{
23537 +       return lookup_vx_info(PROC_I(inode)->fd);
23538 +}
23539 +
23540 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23541 +{
23542 +       struct inode *inode = dentry->d_inode;
23543 +       xid_t xid = PROC_I(inode)->fd;
23544 +
23545 +       if (!xid || xid_is_hashed(xid))
23546 +               return 1;
23547 +       d_drop(dentry);
23548 +       return 0;
23549 +}
23550 +
23551 +
23552 +/* get and revalidate nx_info/nid */
23553 +
23554 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23555 +{
23556 +       struct inode *inode = dentry->d_inode;
23557 +       nid_t nid = PROC_I(inode)->fd;
23558 +
23559 +       if (!nid || nid_is_hashed(nid))
23560 +               return 1;
23561 +       d_drop(dentry);
23562 +       return 0;
23563 +}
23564 +
23565 +
23566 +
23567 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23568 +
23569 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23570 +                         size_t count, loff_t *ppos)
23571 +{
23572 +       struct inode *inode = file->f_dentry->d_inode;
23573 +       unsigned long page;
23574 +       ssize_t length = 0;
23575 +
23576 +       if (count > PROC_BLOCK_SIZE)
23577 +               count = PROC_BLOCK_SIZE;
23578 +
23579 +       /* fade that out as soon as stable */
23580 +       WARN_ON(PROC_I(inode)->fd);
23581 +
23582 +       if (!(page = __get_free_page(GFP_KERNEL)))
23583 +               return -ENOMEM;
23584 +
23585 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23586 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23587 +
23588 +       if (length >= 0)
23589 +               length = simple_read_from_buffer(buf, count, ppos,
23590 +                       (char *)page, length);
23591 +
23592 +       free_page(page);
23593 +       return length;
23594 +}
23595 +
23596 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23597 +                         size_t count, loff_t *ppos)
23598 +{
23599 +       struct inode *inode = file->f_dentry->d_inode;
23600 +       struct vx_info *vxi = NULL;
23601 +       xid_t xid = PROC_I(inode)->fd;
23602 +       unsigned long page;
23603 +       ssize_t length = 0;
23604 +
23605 +       if (count > PROC_BLOCK_SIZE)
23606 +               count = PROC_BLOCK_SIZE;
23607 +
23608 +       /* fade that out as soon as stable */
23609 +       WARN_ON(!xid);
23610 +       vxi = lookup_vx_info(xid);
23611 +       if (!vxi)
23612 +               goto out;
23613 +
23614 +       length = -ENOMEM;
23615 +       if (!(page = __get_free_page(GFP_KERNEL)))
23616 +               goto out_put;
23617 +
23618 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23619 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23620 +
23621 +       if (length >= 0)
23622 +               length = simple_read_from_buffer(buf, count, ppos,
23623 +                       (char *)page, length);
23624 +
23625 +       free_page(page);
23626 +out_put:
23627 +       put_vx_info(vxi);
23628 +out:
23629 +       return length;
23630 +}
23631 +
23632 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23633 +                         size_t count, loff_t *ppos)
23634 +{
23635 +       struct inode *inode = file->f_dentry->d_inode;
23636 +       struct nx_info *nxi = NULL;
23637 +       nid_t nid = PROC_I(inode)->fd;
23638 +       unsigned long page;
23639 +       ssize_t length = 0;
23640 +
23641 +       if (count > PROC_BLOCK_SIZE)
23642 +               count = PROC_BLOCK_SIZE;
23643 +
23644 +       /* fade that out as soon as stable */
23645 +       WARN_ON(!nid);
23646 +       nxi = lookup_nx_info(nid);
23647 +       if (!nxi)
23648 +               goto out;
23649 +
23650 +       length = -ENOMEM;
23651 +       if (!(page = __get_free_page(GFP_KERNEL)))
23652 +               goto out_put;
23653 +
23654 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23655 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23656 +
23657 +       if (length >= 0)
23658 +               length = simple_read_from_buffer(buf, count, ppos,
23659 +                       (char *)page, length);
23660 +
23661 +       free_page(page);
23662 +out_put:
23663 +       put_nx_info(nxi);
23664 +out:
23665 +       return length;
23666 +}
23667 +
23668 +
23669 +
23670 +/* here comes the lower level */
23671 +
23672 +
23673 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23674 +       .len  = sizeof(NAME) - 1,       \
23675 +       .name = (NAME),                 \
23676 +       .mode = MODE,                   \
23677 +       .iop  = IOP,                    \
23678 +       .fop  = FOP,                    \
23679 +       .op   = OP,                     \
23680 +}
23681 +
23682 +
23683 +#define DIR(NAME, MODE, OTYPE)                         \
23684 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23685 +               &proc_ ## OTYPE ## _inode_operations,   \
23686 +               &proc_ ## OTYPE ## _file_operations, { } )
23687 +
23688 +#define INF(NAME, MODE, OTYPE)                         \
23689 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23690 +               &proc_vs_info_file_operations,          \
23691 +               { .proc_vs_read = &proc_##OTYPE } )
23692 +
23693 +#define VINF(NAME, MODE, OTYPE)                                \
23694 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23695 +               &proc_vx_info_file_operations,          \
23696 +               { .proc_vxi_read = &proc_##OTYPE } )
23697 +
23698 +#define NINF(NAME, MODE, OTYPE)                                \
23699 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23700 +               &proc_nx_info_file_operations,          \
23701 +               { .proc_nxi_read = &proc_##OTYPE } )
23702 +
23703 +
23704 +static struct file_operations proc_vs_info_file_operations = {
23705 +       .read =         proc_vs_info_read,
23706 +};
23707 +
23708 +static struct file_operations proc_vx_info_file_operations = {
23709 +       .read =         proc_vx_info_read,
23710 +};
23711 +
23712 +static struct dentry_operations proc_xid_dentry_operations = {
23713 +       .d_revalidate = proc_xid_revalidate,
23714 +};
23715 +
23716 +static struct vs_entry vx_base_stuff[] = {
23717 +       VINF("info",    S_IRUGO, vxi_info),
23718 +       VINF("status",  S_IRUGO, vxi_status),
23719 +       VINF("limit",   S_IRUGO, vxi_limit),
23720 +       VINF("sched",   S_IRUGO, vxi_sched),
23721 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy),
23722 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23723 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23724 +       {}
23725 +};
23726 +
23727 +
23728 +
23729 +
23730 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23731 +       struct dentry *dentry, int id, void *ptr)
23732 +{
23733 +       dentry->d_op = &proc_xid_dentry_operations;
23734 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23735 +}
23736 +
23737 +static struct dentry *proc_xid_lookup(struct inode *dir,
23738 +       struct dentry *dentry, struct nameidata *nd)
23739 +{
23740 +       struct vs_entry *p = vx_base_stuff;
23741 +       struct dentry *error = ERR_PTR(-ENOENT);
23742 +
23743 +       for (; p->name; p++) {
23744 +               if (p->len != dentry->d_name.len)
23745 +                       continue;
23746 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23747 +                       break;
23748 +       }
23749 +       if (!p->name)
23750 +               goto out;
23751 +
23752 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23753 +out:
23754 +       return error;
23755 +}
23756 +
23757 +static int proc_xid_readdir(struct file *filp,
23758 +       void *dirent, filldir_t filldir)
23759 +{
23760 +       struct dentry *dentry = filp->f_dentry;
23761 +       struct inode *inode = dentry->d_inode;
23762 +       struct vs_entry *p = vx_base_stuff;
23763 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23764 +       int pos, index;
23765 +       u64 ino;
23766 +
23767 +       pos = filp->f_pos;
23768 +       switch (pos) {
23769 +       case 0:
23770 +               ino = inode->i_ino;
23771 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23772 +                       goto out;
23773 +               pos++;
23774 +               /* fall through */
23775 +       case 1:
23776 +               ino = parent_ino(dentry);
23777 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23778 +                       goto out;
23779 +               pos++;
23780 +               /* fall through */
23781 +       default:
23782 +               index = pos - 2;
23783 +               if (index >= size)
23784 +                       goto out;
23785 +               for (p += index; p->name; p++) {
23786 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23787 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23788 +                               goto out;
23789 +                       pos++;
23790 +               }
23791 +       }
23792 +out:
23793 +       filp->f_pos = pos;
23794 +       return 1;
23795 +}
23796 +
23797 +
23798 +
23799 +static struct file_operations proc_nx_info_file_operations = {
23800 +       .read =         proc_nx_info_read,
23801 +};
23802 +
23803 +static struct dentry_operations proc_nid_dentry_operations = {
23804 +       .d_revalidate = proc_nid_revalidate,
23805 +};
23806 +
23807 +static struct vs_entry nx_base_stuff[] = {
23808 +       NINF("info",    S_IRUGO, nxi_info),
23809 +       NINF("status",  S_IRUGO, nxi_status),
23810 +       {}
23811 +};
23812 +
23813 +
23814 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23815 +       struct dentry *dentry, int id, void *ptr)
23816 +{
23817 +       dentry->d_op = &proc_nid_dentry_operations;
23818 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23819 +}
23820 +
23821 +static struct dentry *proc_nid_lookup(struct inode *dir,
23822 +       struct dentry *dentry, struct nameidata *nd)
23823 +{
23824 +       struct vs_entry *p = nx_base_stuff;
23825 +       struct dentry *error = ERR_PTR(-ENOENT);
23826 +
23827 +       for (; p->name; p++) {
23828 +               if (p->len != dentry->d_name.len)
23829 +                       continue;
23830 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23831 +                       break;
23832 +       }
23833 +       if (!p->name)
23834 +               goto out;
23835 +
23836 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23837 +out:
23838 +       return error;
23839 +}
23840 +
23841 +static int proc_nid_readdir(struct file *filp,
23842 +       void *dirent, filldir_t filldir)
23843 +{
23844 +       struct dentry *dentry = filp->f_dentry;
23845 +       struct inode *inode = dentry->d_inode;
23846 +       struct vs_entry *p = nx_base_stuff;
23847 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23848 +       int pos, index;
23849 +       u64 ino;
23850 +
23851 +       pos = filp->f_pos;
23852 +       switch (pos) {
23853 +       case 0:
23854 +               ino = inode->i_ino;
23855 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23856 +                       goto out;
23857 +               pos++;
23858 +               /* fall through */
23859 +       case 1:
23860 +               ino = parent_ino(dentry);
23861 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23862 +                       goto out;
23863 +               pos++;
23864 +               /* fall through */
23865 +       default:
23866 +               index = pos - 2;
23867 +               if (index >= size)
23868 +                       goto out;
23869 +               for (p += index; p->name; p++) {
23870 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23871 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23872 +                               goto out;
23873 +                       pos++;
23874 +               }
23875 +       }
23876 +out:
23877 +       filp->f_pos = pos;
23878 +       return 1;
23879 +}
23880 +
23881 +
23882 +#define MAX_MULBY10    ((~0U - 9) / 10)
23883 +
23884 +static inline int atovid(const char *str, int len)
23885 +{
23886 +       int vid, c;
23887 +
23888 +       vid = 0;
23889 +       while (len-- > 0) {
23890 +               c = *str - '0';
23891 +               str++;
23892 +               if (c > 9)
23893 +                       return -1;
23894 +               if (vid >= MAX_MULBY10)
23895 +                       return -1;
23896 +               vid *= 10;
23897 +               vid += c;
23898 +               if (!vid)
23899 +                       return -1;
23900 +       }
23901 +       return vid;
23902 +}
23903 +
23904 +/* now the upper level (virtual) */
23905 +
23906 +
23907 +static struct file_operations proc_xid_file_operations = {
23908 +       .read =         generic_read_dir,
23909 +       .readdir =      proc_xid_readdir,
23910 +};
23911 +
23912 +static struct inode_operations proc_xid_inode_operations = {
23913 +       .lookup =       proc_xid_lookup,
23914 +};
23915 +
23916 +static struct vs_entry vx_virtual_stuff[] = {
23917 +       INF("info",     S_IRUGO, virtual_info),
23918 +       INF("status",   S_IRUGO, virtual_status),
23919 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23920 +};
23921 +
23922 +
23923 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23924 +       struct dentry *dentry, struct nameidata *nd)
23925 +{
23926 +       struct vs_entry *p = vx_virtual_stuff;
23927 +       struct dentry *error = ERR_PTR(-ENOENT);
23928 +       int id = 0;
23929 +
23930 +       for (; p->name; p++) {
23931 +               if (p->len != dentry->d_name.len)
23932 +                       continue;
23933 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23934 +                       break;
23935 +       }
23936 +       if (p->name)
23937 +               goto instantiate;
23938 +
23939 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23940 +       if ((id < 0) || !xid_is_hashed(id))
23941 +               goto out;
23942 +
23943 +instantiate:
23944 +       error = proc_xid_instantiate(dir, dentry, id, p);
23945 +out:
23946 +       return error;
23947 +}
23948 +
23949 +static struct file_operations proc_nid_file_operations = {
23950 +       .read =         generic_read_dir,
23951 +       .readdir =      proc_nid_readdir,
23952 +};
23953 +
23954 +static struct inode_operations proc_nid_inode_operations = {
23955 +       .lookup =       proc_nid_lookup,
23956 +};
23957 +
23958 +static struct vs_entry nx_virtnet_stuff[] = {
23959 +       INF("info",     S_IRUGO, virtnet_info),
23960 +       INF("status",   S_IRUGO, virtnet_status),
23961 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23962 +};
23963 +
23964 +
23965 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23966 +       struct dentry *dentry, struct nameidata *nd)
23967 +{
23968 +       struct vs_entry *p = nx_virtnet_stuff;
23969 +       struct dentry *error = ERR_PTR(-ENOENT);
23970 +       int id = 0;
23971 +
23972 +       for (; p->name; p++) {
23973 +               if (p->len != dentry->d_name.len)
23974 +                       continue;
23975 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23976 +                       break;
23977 +       }
23978 +       if (p->name)
23979 +               goto instantiate;
23980 +
23981 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23982 +       if ((id < 0) || !nid_is_hashed(id))
23983 +               goto out;
23984 +
23985 +instantiate:
23986 +       error = proc_nid_instantiate(dir, dentry, id, p);
23987 +out:
23988 +       return error;
23989 +}
23990 +
23991 +
23992 +
23993 +#define PROC_NUMBUF 10
23994 +#define PROC_MAXVIDS 32
23995 +
23996 +int proc_virtual_readdir(struct file *filp,
23997 +       void *dirent, filldir_t filldir)
23998 +{
23999 +       struct dentry *dentry = filp->f_dentry;
24000 +       struct inode *inode = dentry->d_inode;
24001 +       struct vs_entry *p = vx_virtual_stuff;
24002 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
24003 +       int pos, index;
24004 +       unsigned int xid_array[PROC_MAXVIDS];
24005 +       char buf[PROC_NUMBUF];
24006 +       unsigned int nr_xids, i;
24007 +       u64 ino;
24008 +
24009 +       pos = filp->f_pos;
24010 +       switch (pos) {
24011 +       case 0:
24012 +               ino = inode->i_ino;
24013 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24014 +                       goto out;
24015 +               pos++;
24016 +               /* fall through */
24017 +       case 1:
24018 +               ino = parent_ino(dentry);
24019 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24020 +                       goto out;
24021 +               pos++;
24022 +               /* fall through */
24023 +       default:
24024 +               index = pos - 2;
24025 +               if (index >= size)
24026 +                       goto entries;
24027 +               for (p += index; p->name; p++) {
24028 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24029 +                               vs_proc_instantiate, 0, p))
24030 +                               goto out;
24031 +                       pos++;
24032 +               }
24033 +       entries:
24034 +               index = pos - size;
24035 +               p = &vx_virtual_stuff[size - 1];
24036 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
24037 +               for (i = 0; i < nr_xids; i++) {
24038 +                       int n, xid = xid_array[i];
24039 +                       unsigned int j = PROC_NUMBUF;
24040 +
24041 +                       n = xid;
24042 +                       do
24043 +                               buf[--j] = '0' + (n % 10);
24044 +                       while (n /= 10);
24045 +
24046 +                       if (proc_fill_cache(filp, dirent, filldir,
24047 +                               buf + j, PROC_NUMBUF - j,
24048 +                               vs_proc_instantiate, xid, p))
24049 +                               goto out;
24050 +                       pos++;
24051 +               }
24052 +       }
24053 +out:
24054 +       filp->f_pos = pos;
24055 +       return 0;
24056 +}
24057 +
24058 +static int proc_virtual_getattr(struct vfsmount *mnt,
24059 +       struct dentry *dentry, struct kstat *stat)
24060 +{
24061 +       struct inode *inode = dentry->d_inode;
24062 +
24063 +       generic_fillattr(inode, stat);
24064 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
24065 +       return 0;
24066 +}
24067 +
24068 +static struct file_operations proc_virtual_dir_operations = {
24069 +       .read =         generic_read_dir,
24070 +       .readdir =      proc_virtual_readdir,
24071 +};
24072 +
24073 +static struct inode_operations proc_virtual_dir_inode_operations = {
24074 +       .getattr =      proc_virtual_getattr,
24075 +       .lookup =       proc_virtual_lookup,
24076 +};
24077 +
24078 +
24079 +
24080 +
24081 +
24082 +int proc_virtnet_readdir(struct file *filp,
24083 +       void *dirent, filldir_t filldir)
24084 +{
24085 +       struct dentry *dentry = filp->f_dentry;
24086 +       struct inode *inode = dentry->d_inode;
24087 +       struct vs_entry *p = nx_virtnet_stuff;
24088 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24089 +       int pos, index;
24090 +       unsigned int nid_array[PROC_MAXVIDS];
24091 +       char buf[PROC_NUMBUF];
24092 +       unsigned int nr_nids, i;
24093 +       u64 ino;
24094 +
24095 +       pos = filp->f_pos;
24096 +       switch (pos) {
24097 +       case 0:
24098 +               ino = inode->i_ino;
24099 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24100 +                       goto out;
24101 +               pos++;
24102 +               /* fall through */
24103 +       case 1:
24104 +               ino = parent_ino(dentry);
24105 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24106 +                       goto out;
24107 +               pos++;
24108 +               /* fall through */
24109 +       default:
24110 +               index = pos - 2;
24111 +               if (index >= size)
24112 +                       goto entries;
24113 +               for (p += index; p->name; p++) {
24114 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24115 +                               vs_proc_instantiate, 0, p))
24116 +                               goto out;
24117 +                       pos++;
24118 +               }
24119 +       entries:
24120 +               index = pos - size;
24121 +               p = &nx_virtnet_stuff[size - 1];
24122 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24123 +               for (i = 0; i < nr_nids; i++) {
24124 +                       int n, nid = nid_array[i];
24125 +                       unsigned int j = PROC_NUMBUF;
24126 +
24127 +                       n = nid;
24128 +                       do
24129 +                               buf[--j] = '0' + (n % 10);
24130 +                       while (n /= 10);
24131 +
24132 +                       if (proc_fill_cache(filp, dirent, filldir,
24133 +                               buf + j, PROC_NUMBUF - j,
24134 +                               vs_proc_instantiate, nid, p))
24135 +                               goto out;
24136 +                       pos++;
24137 +               }
24138 +       }
24139 +out:
24140 +       filp->f_pos = pos;
24141 +       return 0;
24142 +}
24143 +
24144 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24145 +       struct dentry *dentry, struct kstat *stat)
24146 +{
24147 +       struct inode *inode = dentry->d_inode;
24148 +
24149 +       generic_fillattr(inode, stat);
24150 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24151 +       return 0;
24152 +}
24153 +
24154 +static struct file_operations proc_virtnet_dir_operations = {
24155 +       .read =         generic_read_dir,
24156 +       .readdir =      proc_virtnet_readdir,
24157 +};
24158 +
24159 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24160 +       .getattr =      proc_virtnet_getattr,
24161 +       .lookup =       proc_virtnet_lookup,
24162 +};
24163 +
24164 +
24165 +
24166 +void proc_vx_init(void)
24167 +{
24168 +       struct proc_dir_entry *ent;
24169 +
24170 +       ent = proc_mkdir("virtual", 0);
24171 +       if (ent) {
24172 +               ent->proc_fops = &proc_virtual_dir_operations;
24173 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24174 +       }
24175 +       proc_virtual = ent;
24176 +
24177 +       ent = proc_mkdir("virtnet", 0);
24178 +       if (ent) {
24179 +               ent->proc_fops = &proc_virtnet_dir_operations;
24180 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24181 +       }
24182 +       proc_virtnet = ent;
24183 +}
24184 +
24185 +
24186 +
24187 +
24188 +/* per pid info */
24189 +
24190 +
24191 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24192 +{
24193 +       struct vx_info *vxi;
24194 +       char *orig = buffer;
24195 +
24196 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24197 +
24198 +       vxi = task_get_vx_info(p);
24199 +       if (!vxi)
24200 +               goto out;
24201 +
24202 +       buffer += sprintf(buffer, "BCaps:\t%016llx\n",
24203 +               (unsigned long long)vxi->vx_bcaps);
24204 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24205 +               (unsigned long long)vxi->vx_ccaps);
24206 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24207 +               (unsigned long long)vxi->vx_flags);
24208 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24209 +
24210 +       put_vx_info(vxi);
24211 +out:
24212 +       return buffer - orig;
24213 +}
24214 +
24215 +
24216 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24217 +{
24218 +       struct nx_info *nxi;
24219 +       char *orig = buffer;
24220 +       int i;
24221 +
24222 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24223 +
24224 +       nxi = task_get_nx_info(p);
24225 +       if (!nxi)
24226 +               goto out;
24227 +
24228 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24229 +               (unsigned long long)nxi->nx_ncaps);
24230 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24231 +               (unsigned long long)nxi->nx_flags);
24232 +
24233 +       for (i = 0; i < nxi->nbipv4; i++){
24234 +               buffer += sprintf(buffer,
24235 +                       "V4Root[%d]:\t" NIPQUAD_FMT "/" NIPQUAD_FMT "\n", i,
24236 +                       NIPQUAD(nxi->ipv4[i]),
24237 +                       NIPQUAD(nxi->mask[i]));
24238 +       }
24239 +       buffer += sprintf(buffer,
24240 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24241 +               NIPQUAD(nxi->v4_bcast));
24242 +
24243 +       put_nx_info(nxi);
24244 +out:
24245 +       return buffer - orig;
24246 +}
24247 +
24248 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/sched.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/sched.c
24249 --- linux-2.6.22.10/kernel/vserver/sched.c      1970-01-01 01:00:00 +0100
24250 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/sched.c    2007-06-15 02:37:04 +0200
24251 @@ -0,0 +1,447 @@
24252 +/*
24253 + *  linux/kernel/vserver/sched.c
24254 + *
24255 + *  Virtual Server: Scheduler Support
24256 + *
24257 + *  Copyright (C) 2004-2007  Herbert Pötzl
24258 + *
24259 + *  V0.01  adapted Sam Vilains version to 2.6.3
24260 + *  V0.02  removed legacy interface
24261 + *  V0.03  changed vcmds to vxi arg
24262 + *
24263 + */
24264 +
24265 +#include <linux/sched.h>
24266 +#include <linux/vs_context.h>
24267 +#include <linux/vs_sched.h>
24268 +#include <linux/vserver/sched_cmd.h>
24269 +
24270 +#include <asm/errno.h>
24271 +#include <asm/uaccess.h>
24272 +
24273 +#define vxd_check_range(val, min, max) do {            \
24274 +       vxlprintk((val < min) || (val > max),           \
24275 +               "check_range(%ld,%ld,%ld)",             \
24276 +               (long)val, (long)min, (long)max,        \
24277 +               __FILE__, __LINE__);                    \
24278 +       } while (0)
24279 +
24280 +
24281 +void vx_update_sched_param(struct _vx_sched *sched,
24282 +       struct _vx_sched_pc *sched_pc)
24283 +{
24284 +       unsigned int set_mask = sched->update_mask;
24285 +
24286 +       if (set_mask & VXSM_FILL_RATE)
24287 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24288 +       if (set_mask & VXSM_INTERVAL)
24289 +               sched_pc->interval[0] = sched->interval[0];
24290 +       if (set_mask & VXSM_FILL_RATE2)
24291 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24292 +       if (set_mask & VXSM_INTERVAL2)
24293 +               sched_pc->interval[1] = sched->interval[1];
24294 +       if (set_mask & VXSM_TOKENS)
24295 +               sched_pc->tokens = sched->tokens;
24296 +       if (set_mask & VXSM_TOKENS_MIN)
24297 +               sched_pc->tokens_min = sched->tokens_min;
24298 +       if (set_mask & VXSM_TOKENS_MAX)
24299 +               sched_pc->tokens_max = sched->tokens_max;
24300 +       if (set_mask & VXSM_PRIO_BIAS)
24301 +               sched_pc->prio_bias = sched->prio_bias;
24302 +
24303 +       if (set_mask & VXSM_IDLE_TIME)
24304 +               sched_pc->flags |= VXSF_IDLE_TIME;
24305 +       else
24306 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24307 +
24308 +       /* reset time */
24309 +       sched_pc->norm_time = jiffies;
24310 +}
24311 +
24312 +
24313 +/*
24314 + * recalculate the context's scheduling tokens
24315 + *
24316 + * ret > 0 : number of tokens available
24317 + * ret < 0 : on hold, check delta_min[]
24318 + *          -1 only jiffies
24319 + *          -2 also idle time
24320 + *
24321 + */
24322 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24323 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24324 +{
24325 +       long delta;
24326 +       long tokens = 0;
24327 +       int flags = sched_pc->flags;
24328 +
24329 +       /* how much time did pass? */
24330 +       delta = *norm_time - sched_pc->norm_time;
24331 +       vxd_check_range(delta, 0, INT_MAX);
24332 +
24333 +       if (delta >= sched_pc->interval[0]) {
24334 +               long tokens, integral;
24335 +
24336 +               /* calc integral token part */
24337 +               tokens = delta / sched_pc->interval[0];
24338 +               integral = tokens * sched_pc->interval[0];
24339 +               tokens *= sched_pc->fill_rate[0];
24340 +#ifdef CONFIG_VSERVER_HARDCPU
24341 +               delta_min[0] = delta - integral;
24342 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24343 +#endif
24344 +               /* advance time */
24345 +               sched_pc->norm_time += delta;
24346 +
24347 +               /* add tokens */
24348 +               sched_pc->tokens += tokens;
24349 +               sched_pc->token_time += tokens;
24350 +       } else
24351 +               delta_min[0] = delta;
24352 +
24353 +#ifdef CONFIG_VSERVER_IDLETIME
24354 +       if (!(flags & VXSF_IDLE_TIME))
24355 +               goto skip_idle;
24356 +
24357 +       /* how much was the idle skip? */
24358 +       delta = *idle_time - sched_pc->idle_time;
24359 +       vxd_check_range(delta, 0, INT_MAX);
24360 +
24361 +       if (delta >= sched_pc->interval[1]) {
24362 +               long tokens, integral;
24363 +
24364 +               /* calc fair share token part */
24365 +               tokens = delta / sched_pc->interval[1];
24366 +               integral = tokens * sched_pc->interval[1];
24367 +               tokens *= sched_pc->fill_rate[1];
24368 +               delta_min[1] = delta - integral;
24369 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24370 +
24371 +               /* advance idle time */
24372 +               sched_pc->idle_time += integral;
24373 +
24374 +               /* add tokens */
24375 +               sched_pc->tokens += tokens;
24376 +               sched_pc->token_time += tokens;
24377 +       } else
24378 +               delta_min[1] = delta;
24379 +skip_idle:
24380 +#endif
24381 +
24382 +       /* clip at maximum */
24383 +       if (sched_pc->tokens > sched_pc->tokens_max)
24384 +               sched_pc->tokens = sched_pc->tokens_max;
24385 +       tokens = sched_pc->tokens;
24386 +
24387 +       if ((flags & VXSF_ONHOLD)) {
24388 +               /* can we unhold? */
24389 +               if (tokens >= sched_pc->tokens_min) {
24390 +                       flags &= ~VXSF_ONHOLD;
24391 +                       sched_pc->hold_ticks +=
24392 +                               *norm_time - sched_pc->onhold;
24393 +               } else
24394 +                       goto on_hold;
24395 +       } else {
24396 +               /* put on hold? */
24397 +               if (tokens <= 0) {
24398 +                       flags |= VXSF_ONHOLD;
24399 +                       sched_pc->onhold = *norm_time;
24400 +                       goto on_hold;
24401 +               }
24402 +       }
24403 +       sched_pc->flags = flags;
24404 +       return tokens;
24405 +
24406 +on_hold:
24407 +       tokens = sched_pc->tokens_min - tokens;
24408 +       sched_pc->flags = flags;
24409 +       BUG_ON(tokens < 0);
24410 +
24411 +#ifdef CONFIG_VSERVER_HARDCPU
24412 +       /* next interval? */
24413 +       if (!sched_pc->fill_rate[0])
24414 +               delta_min[0] = HZ;
24415 +       else if (tokens > sched_pc->fill_rate[0])
24416 +               delta_min[0] += sched_pc->interval[0] *
24417 +                       tokens / sched_pc->fill_rate[0];
24418 +       else
24419 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24420 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24421 +
24422 +#ifdef CONFIG_VSERVER_IDLETIME
24423 +       if (!(flags & VXSF_IDLE_TIME))
24424 +               return -1;
24425 +
24426 +       /* next interval? */
24427 +       if (!sched_pc->fill_rate[1])
24428 +               delta_min[1] = HZ;
24429 +       else if (tokens > sched_pc->fill_rate[1])
24430 +               delta_min[1] += sched_pc->interval[1] *
24431 +                       tokens / sched_pc->fill_rate[1];
24432 +       else
24433 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24434 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24435 +
24436 +       return -2;
24437 +#else
24438 +       return -1;
24439 +#endif /* CONFIG_VSERVER_IDLETIME */
24440 +#else
24441 +       return 0;
24442 +#endif /* CONFIG_VSERVER_HARDCPU */
24443 +}
24444 +
24445 +static inline unsigned long msec_to_ticks(unsigned long msec)
24446 +{
24447 +       return msecs_to_jiffies(msec);
24448 +}
24449 +
24450 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24451 +{
24452 +       return jiffies_to_msecs(ticks);
24453 +}
24454 +
24455 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24456 +{
24457 +       return jiffies_to_usecs(ticks);
24458 +}
24459 +
24460 +
24461 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24462 +{
24463 +       unsigned int set_mask = data->mask;
24464 +       unsigned int update_mask;
24465 +       int i, cpu;
24466 +
24467 +       /* Sanity check data values */
24468 +       if (data->tokens_max <= 0)
24469 +               data->tokens_max = HZ;
24470 +       if (data->tokens_min < 0)
24471 +               data->tokens_min = HZ / 3;
24472 +       if (data->tokens_min >= data->tokens_max)
24473 +               data->tokens_min = data->tokens_max;
24474 +
24475 +       if (data->prio_bias > MAX_PRIO_BIAS)
24476 +               data->prio_bias = MAX_PRIO_BIAS;
24477 +       if (data->prio_bias < MIN_PRIO_BIAS)
24478 +               data->prio_bias = MIN_PRIO_BIAS;
24479 +
24480 +       spin_lock(&vxi->sched.tokens_lock);
24481 +
24482 +       /* sync up on delayed updates */
24483 +       for_each_cpu_mask(cpu, vxi->sched.update)
24484 +               vx_update_sched_param(&vxi->sched,
24485 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24486 +
24487 +       if (set_mask & VXSM_FILL_RATE)
24488 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24489 +       if (set_mask & VXSM_FILL_RATE2)
24490 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24491 +       if (set_mask & VXSM_INTERVAL)
24492 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24493 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24494 +       if (set_mask & VXSM_INTERVAL2)
24495 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24496 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24497 +       if (set_mask & VXSM_TOKENS)
24498 +               vxi->sched.tokens = data->tokens;
24499 +       if (set_mask & VXSM_TOKENS_MIN)
24500 +               vxi->sched.tokens_min = data->tokens_min;
24501 +       if (set_mask & VXSM_TOKENS_MAX)
24502 +               vxi->sched.tokens_max = data->tokens_max;
24503 +       if (set_mask & VXSM_PRIO_BIAS)
24504 +               vxi->sched.prio_bias = data->prio_bias;
24505 +
24506 +       /* Sanity check rate/interval */
24507 +       for (i = 0; i < 2; i++) {
24508 +               if (data->fill_rate[i] < 0)
24509 +                       data->fill_rate[i] = 0;
24510 +               if (data->interval[i] <= 0)
24511 +                       data->interval[i] = HZ;
24512 +       }
24513 +
24514 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24515 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24516 +       vxi->sched.update_mask = update_mask;
24517 +#ifdef CONFIG_SMP
24518 +       rmb();
24519 +       if (set_mask & VXSM_CPU_ID) {
24520 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24521 +               cpus_and(vxi->sched.update, cpu_online_map,
24522 +                       vxi->sched.update);
24523 +       } else
24524 +               vxi->sched.update = cpu_online_map;
24525 +
24526 +       /* forced reload? */
24527 +       if (set_mask & VXSM_FORCE) {
24528 +               for_each_cpu_mask(cpu, vxi->sched.update)
24529 +                       vx_update_sched_param(&vxi->sched,
24530 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24531 +               vxi->sched.update = CPU_MASK_NONE;
24532 +       }
24533 +#else
24534 +       /* on UP we update immediately */
24535 +       vx_update_sched_param(&vxi->sched,
24536 +               &vx_per_cpu(vxi, sched_pc, 0));
24537 +#endif
24538 +
24539 +       spin_unlock(&vxi->sched.tokens_lock);
24540 +       return 0;
24541 +}
24542 +
24543 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24544 +#define COPY_PRI(C) C(prio_bias)
24545 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24546 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24547 +                   C(fill_rate[1]); C(interval[1]);
24548 +
24549 +#define COPY_VALUE(name) vc_data.name = data->name
24550 +
24551 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24552 +{
24553 +       struct vcmd_sched_v5 vc_data;
24554 +
24555 +       vc_data.mask = data->set_mask;
24556 +       COPY_IDS(COPY_VALUE);
24557 +       COPY_PRI(COPY_VALUE);
24558 +       COPY_TOK(COPY_VALUE);
24559 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24560 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24561 +       return do_set_sched(vxi, &vc_data);
24562 +}
24563 +
24564 +#ifdef CONFIG_VSERVER_LEGACY
24565 +
24566 +#define COPY_MASK_V2(name, mask)                       \
24567 +       if (vc_data.name != SCHED_KEEP) {               \
24568 +               vc_data_v4.name = vc_data.name;         \
24569 +               vc_data_v4.set_mask |= mask;            \
24570 +       }
24571 +
24572 +int vc_set_sched_v2(struct vx_info *vxi, void __user *data)
24573 +{
24574 +       struct vcmd_set_sched_v2 vc_data;
24575 +       struct vcmd_set_sched_v4 vc_data_v4 = { .set_mask = 0 };
24576 +
24577 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24578 +               return -EFAULT;
24579 +
24580 +       COPY_MASK_V2(fill_rate,  VXSM_FILL_RATE);
24581 +       COPY_MASK_V2(interval,   VXSM_INTERVAL);
24582 +       COPY_MASK_V2(tokens,     VXSM_TOKENS);
24583 +       COPY_MASK_V2(tokens_min, VXSM_TOKENS_MIN);
24584 +       COPY_MASK_V2(tokens_max, VXSM_TOKENS_MAX);
24585 +       vc_data_v4.bucket_id = 0;
24586 +
24587 +       do_set_sched_v4(vxi, &vc_data_v4);
24588 +       return 0;
24589 +}
24590 +#endif
24591 +
24592 +int vc_set_sched_v3(struct vx_info *vxi, void __user *data)
24593 +{
24594 +       struct vcmd_set_sched_v3 vc_data;
24595 +       struct vcmd_set_sched_v4 vc_data_v4;
24596 +
24597 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24598 +               return -EFAULT;
24599 +
24600 +       /* structures are binary compatible */
24601 +       memcpy(&vc_data_v4, &vc_data, sizeof(vc_data));
24602 +       vc_data_v4.set_mask &= VXSM_V3_MASK;
24603 +       vc_data_v4.bucket_id = 0;
24604 +
24605 +       return do_set_sched_v4(vxi, &vc_data_v4);
24606 +}
24607 +
24608 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24609 +{
24610 +       struct vcmd_set_sched_v4 vc_data;
24611 +
24612 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24613 +               return -EFAULT;
24614 +
24615 +       return do_set_sched_v4(vxi, &vc_data);
24616 +}
24617 +
24618 +       /* latest interface is v5 */
24619 +
24620 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24621 +{
24622 +       struct vcmd_sched_v5 vc_data;
24623 +
24624 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24625 +               return -EFAULT;
24626 +
24627 +       return do_set_sched(vxi, &vc_data);
24628 +}
24629 +
24630 +
24631 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24632 +{
24633 +       struct vcmd_sched_v5 vc_data;
24634 +
24635 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24636 +               return -EFAULT;
24637 +
24638 +       if (vc_data.mask & VXSM_CPU_ID) {
24639 +               int cpu = vc_data.cpu_id;
24640 +               struct _vx_sched_pc *data;
24641 +
24642 +               if (!cpu_possible(cpu))
24643 +                       return -EINVAL;
24644 +
24645 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24646 +               COPY_TOK(COPY_VALUE);
24647 +               COPY_PRI(COPY_VALUE);
24648 +               COPY_FRI(COPY_VALUE);
24649 +
24650 +               if (data->flags & VXSF_IDLE_TIME)
24651 +                       vc_data.mask |= VXSM_IDLE_TIME;
24652 +       } else {
24653 +               struct _vx_sched *data = &vxi->sched;
24654 +
24655 +               COPY_TOK(COPY_VALUE);
24656 +               COPY_PRI(COPY_VALUE);
24657 +               COPY_FRI(COPY_VALUE);
24658 +       }
24659 +
24660 +       if (vc_data.mask & VXSM_MSEC) {
24661 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24662 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24663 +       }
24664 +
24665 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24666 +               return -EFAULT;
24667 +       return 0;
24668 +}
24669 +
24670 +
24671 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24672 +{
24673 +       struct vcmd_sched_info vc_data;
24674 +       int cpu;
24675 +
24676 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24677 +               return -EFAULT;
24678 +
24679 +       cpu = vc_data.cpu_id;
24680 +       if (!cpu_possible(cpu))
24681 +               return -EINVAL;
24682 +
24683 +       if (vxi) {
24684 +               struct _vx_sched_pc *sched_pc =
24685 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24686 +
24687 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24688 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24689 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24690 +               vc_data.vavavoom = sched_pc->vavavoom;
24691 +       }
24692 +       vc_data.token_usec = ticks_to_usec(1);
24693 +
24694 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24695 +               return -EFAULT;
24696 +       return 0;
24697 +}
24698 +
24699 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/sched_init.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/sched_init.h
24700 --- linux-2.6.22.10/kernel/vserver/sched_init.h 1970-01-01 01:00:00 +0100
24701 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/sched_init.h       2007-06-15 02:37:04 +0200
24702 @@ -0,0 +1,50 @@
24703 +
24704 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24705 +{
24706 +       static struct lock_class_key tokens_lock_key;
24707 +
24708 +       /* scheduling; hard code starting values as constants */
24709 +       sched->fill_rate[0]     = 1;
24710 +       sched->interval[0]      = 4;
24711 +       sched->fill_rate[1]     = 1;
24712 +       sched->interval[1]      = 8;
24713 +       sched->tokens           = HZ >> 2;
24714 +       sched->tokens_min       = HZ >> 4;
24715 +       sched->tokens_max       = HZ >> 1;
24716 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24717 +       sched->prio_bias        = 0;
24718 +
24719 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24720 +}
24721 +
24722 +static inline
24723 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24724 +{
24725 +       sched_pc->fill_rate[0]  = 1;
24726 +       sched_pc->interval[0]   = 4;
24727 +       sched_pc->fill_rate[1]  = 1;
24728 +       sched_pc->interval[1]   = 8;
24729 +       sched_pc->tokens        = HZ >> 2;
24730 +       sched_pc->tokens_min    = HZ >> 4;
24731 +       sched_pc->tokens_max    = HZ >> 1;
24732 +       sched_pc->prio_bias     = 0;
24733 +       sched_pc->vavavoom      = 0;
24734 +       sched_pc->token_time    = 0;
24735 +       sched_pc->idle_time     = 0;
24736 +       sched_pc->norm_time     = jiffies;
24737 +
24738 +       sched_pc->user_ticks = 0;
24739 +       sched_pc->sys_ticks = 0;
24740 +       sched_pc->hold_ticks = 0;
24741 +}
24742 +
24743 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24744 +{
24745 +       return;
24746 +}
24747 +
24748 +static inline
24749 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24750 +{
24751 +       return;
24752 +}
24753 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/sched_proc.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/sched_proc.h
24754 --- linux-2.6.22.10/kernel/vserver/sched_proc.h 1970-01-01 01:00:00 +0100
24755 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/sched_proc.h       2007-06-15 02:37:04 +0200
24756 @@ -0,0 +1,57 @@
24757 +#ifndef _VX_SCHED_PROC_H
24758 +#define _VX_SCHED_PROC_H
24759 +
24760 +
24761 +static inline
24762 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24763 +{
24764 +       int length = 0;
24765 +
24766 +       length += sprintf(buffer,
24767 +               "FillRate:\t%8d,%d\n"
24768 +               "Interval:\t%8d,%d\n"
24769 +               "TokensMin:\t%8d\n"
24770 +               "TokensMax:\t%8d\n"
24771 +               "PrioBias:\t%8d\n",
24772 +               sched->fill_rate[0],
24773 +               sched->fill_rate[1],
24774 +               sched->interval[0],
24775 +               sched->interval[1],
24776 +               sched->tokens_min,
24777 +               sched->tokens_max,
24778 +               sched->prio_bias);
24779 +       return length;
24780 +}
24781 +
24782 +static inline
24783 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24784 +       char *buffer, int cpu)
24785 +{
24786 +       int length = 0;
24787 +
24788 +       length += sprintf(buffer + length,
24789 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24790 +               (unsigned long long)sched_pc->user_ticks,
24791 +               (unsigned long long)sched_pc->sys_ticks,
24792 +               (unsigned long long)sched_pc->hold_ticks,
24793 +               sched_pc->token_time,
24794 +               sched_pc->idle_time);
24795 +       length += sprintf(buffer + length,
24796 +               " %c%c %d %d %d %d/%d %d/%d",
24797 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24798 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24799 +               sched_pc->tokens,
24800 +               sched_pc->tokens_min,
24801 +               sched_pc->tokens_max,
24802 +               sched_pc->fill_rate[0],
24803 +               sched_pc->interval[0],
24804 +               sched_pc->fill_rate[1],
24805 +               sched_pc->interval[1]);
24806 +       length += sprintf(buffer + length,
24807 +               " %d %d\n",
24808 +               sched_pc->prio_bias,
24809 +               sched_pc->vavavoom);
24810 +       return length;
24811 +}
24812 +
24813 +#endif /* _VX_SCHED_PROC_H */
24814 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/signal.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/signal.c
24815 --- linux-2.6.22.10/kernel/vserver/signal.c     1970-01-01 01:00:00 +0100
24816 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/signal.c   2007-06-15 02:37:04 +0200
24817 @@ -0,0 +1,134 @@
24818 +/*
24819 + *  linux/kernel/vserver/signal.c
24820 + *
24821 + *  Virtual Server: Signal Support
24822 + *
24823 + *  Copyright (C) 2003-2007  Herbert Pötzl
24824 + *
24825 + *  V0.01  broken out from vcontext V0.05
24826 + *  V0.02  changed vcmds to vxi arg
24827 + *  V0.03  adjusted siginfo for kill
24828 + *
24829 + */
24830 +
24831 +#include <linux/sched.h>
24832 +
24833 +#include <asm/errno.h>
24834 +#include <asm/uaccess.h>
24835 +
24836 +#include <linux/vs_context.h>
24837 +#include <linux/vserver/signal_cmd.h>
24838 +
24839 +
24840 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24841 +{
24842 +       int retval, count = 0;
24843 +       struct task_struct *p;
24844 +       struct siginfo *sip = SEND_SIG_PRIV;
24845 +
24846 +       retval = -ESRCH;
24847 +       vxdprintk(VXD_CBIT(misc, 4),
24848 +               "vx_info_kill(%p[#%d],%d,%d)*",
24849 +               vxi, vxi->vx_id, pid, sig);
24850 +       read_lock(&tasklist_lock);
24851 +       switch (pid) {
24852 +       case  0:
24853 +       case -1:
24854 +               for_each_process(p) {
24855 +                       int err = 0;
24856 +
24857 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24858 +                               (pid && vxi->vx_initpid == p->pid))
24859 +                               continue;
24860 +
24861 +                       err = group_send_sig_info(sig, sip, p);
24862 +                       ++count;
24863 +                       if (err != -EPERM)
24864 +                               retval = err;
24865 +               }
24866 +               break;
24867 +
24868 +       case 1:
24869 +               if (vxi->vx_initpid) {
24870 +                       pid = vxi->vx_initpid;
24871 +                       /* for now, only SIGINT to private init ... */
24872 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24873 +                               /* ... as long as there are tasks left */
24874 +                               (atomic_read(&vxi->vx_tasks) > 1))
24875 +                               sig = SIGINT;
24876 +               }
24877 +               /* fallthrough */
24878 +       default:
24879 +               p = find_task_by_real_pid(pid);
24880 +               if (p) {
24881 +                       if (vx_task_xid(p) == vxi->vx_id)
24882 +                               retval = group_send_sig_info(sig, sip, p);
24883 +               }
24884 +               break;
24885 +       }
24886 +       read_unlock(&tasklist_lock);
24887 +       vxdprintk(VXD_CBIT(misc, 4),
24888 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24889 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24890 +       return retval;
24891 +}
24892 +
24893 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24894 +{
24895 +       struct vcmd_ctx_kill_v0 vc_data;
24896 +
24897 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24898 +               return -EFAULT;
24899 +
24900 +       /* special check to allow guest shutdown */
24901 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24902 +               /* forbid killall pid=0 when init is present */
24903 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24904 +               (vc_data.pid > 1)))
24905 +               return -EACCES;
24906 +
24907 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24908 +}
24909 +
24910 +
24911 +static int __wait_exit(struct vx_info *vxi)
24912 +{
24913 +       DECLARE_WAITQUEUE(wait, current);
24914 +       int ret = 0;
24915 +
24916 +       add_wait_queue(&vxi->vx_wait, &wait);
24917 +       set_current_state(TASK_INTERRUPTIBLE);
24918 +
24919 +wait:
24920 +       if (vx_info_state(vxi,
24921 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24922 +               goto out;
24923 +       if (signal_pending(current)) {
24924 +               ret = -ERESTARTSYS;
24925 +               goto out;
24926 +       }
24927 +       schedule();
24928 +       goto wait;
24929 +
24930 +out:
24931 +       set_current_state(TASK_RUNNING);
24932 +       remove_wait_queue(&vxi->vx_wait, &wait);
24933 +       return ret;
24934 +}
24935 +
24936 +
24937 +
24938 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24939 +{
24940 +       struct vcmd_wait_exit_v0 vc_data;
24941 +       int ret;
24942 +
24943 +       ret = __wait_exit(vxi);
24944 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24945 +       vc_data.exit_code = vxi->exit_code;
24946 +
24947 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24948 +               ret = -EFAULT;
24949 +       return ret;
24950 +}
24951 +
24952 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/space.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/space.c
24953 --- linux-2.6.22.10/kernel/vserver/space.c      1970-01-01 01:00:00 +0100
24954 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/space.c    2007-06-16 19:12:02 +0200
24955 @@ -0,0 +1,281 @@
24956 +/*
24957 + *  linux/kernel/vserver/space.c
24958 + *
24959 + *  Virtual Server: Context Space Support
24960 + *
24961 + *  Copyright (C) 2003-2007  Herbert Pötzl
24962 + *
24963 + *  V0.01  broken out from context.c 0.07
24964 + *  V0.02  added task locking for namespace
24965 + *  V0.03  broken out vx_enter_namespace
24966 + *  V0.04  added *space support and commands
24967 + *
24968 + */
24969 +
24970 +#include <linux/utsname.h>
24971 +#include <linux/sched.h>
24972 +#include <linux/vs_context.h>
24973 +#include <linux/vserver/space.h>
24974 +#include <linux/vserver/space_cmd.h>
24975 +#include <linux/dcache.h>
24976 +#include <linux/mount.h>
24977 +#include <linux/nsproxy.h>
24978 +#include <linux/fs.h>
24979 +
24980 +#include <asm/errno.h>
24981 +#include <asm/uaccess.h>
24982 +
24983 +
24984 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24985 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24986 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24987 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24988 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24989 +
24990 +
24991 +/* namespace functions */
24992 +
24993 +#include <linux/mnt_namespace.h>
24994 +
24995 +const struct vcmd_space_mask space_mask = {
24996 +       .mask = CLONE_NEWNS |
24997 +               CLONE_NEWUTS |
24998 +               CLONE_NEWIPC |
24999 +               CLONE_FS
25000 +};
25001 +
25002 +
25003 +/*
25004 + *     build a new nsproxy mix
25005 + *      assumes that both proxies are 'const'
25006 + *     does not touch nsproxy refcounts
25007 + *     will hold a reference on the result.
25008 + */
25009 +
25010 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
25011 +       struct nsproxy *new_nsproxy, unsigned long mask)
25012 +{
25013 +       struct mnt_namespace *old_ns;
25014 +       struct uts_namespace *old_uts;
25015 +       struct ipc_namespace *old_ipc;
25016 +       struct nsproxy *nsproxy;
25017 +
25018 +       nsproxy = copy_nsproxy(old_nsproxy);
25019 +       if (!nsproxy)
25020 +               goto out;
25021 +
25022 +       if (mask & CLONE_NEWNS) {
25023 +               old_ns = nsproxy->mnt_ns;
25024 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
25025 +               if (nsproxy->mnt_ns)
25026 +                       get_mnt_ns(nsproxy->mnt_ns);
25027 +       } else
25028 +               old_ns = NULL;
25029 +
25030 +       if (mask & CLONE_NEWUTS) {
25031 +               old_uts = nsproxy->uts_ns;
25032 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
25033 +               if (nsproxy->uts_ns)
25034 +                       get_uts_ns(nsproxy->uts_ns);
25035 +       } else
25036 +               old_uts = NULL;
25037 +
25038 +       if (mask & CLONE_NEWIPC) {
25039 +               old_ipc = nsproxy->ipc_ns;
25040 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
25041 +               if (nsproxy->ipc_ns)
25042 +                       get_ipc_ns(nsproxy->ipc_ns);
25043 +       } else
25044 +               old_ipc = NULL;
25045 +
25046 +       if (old_ns)
25047 +               put_mnt_ns(old_ns);
25048 +       if (old_uts)
25049 +               put_uts_ns(old_uts);
25050 +       if (old_ipc)
25051 +               put_ipc_ns(old_ipc);
25052 +out:
25053 +       return nsproxy;
25054 +}
25055 +
25056 +
25057 +/*
25058 + *     merge two nsproxy structs into a new one.
25059 + *     will hold a reference on the result.
25060 + */
25061 +
25062 +static inline
25063 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
25064 +       struct nsproxy *proxy, unsigned long mask)
25065 +{
25066 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
25067 +
25068 +       if (!proxy)
25069 +               return NULL;
25070 +
25071 +       if (mask) {
25072 +               /* vs_mix_nsproxy returns with reference */
25073 +               return vs_mix_nsproxy(old ? old : &null_proxy,
25074 +                       proxy, mask);
25075 +       }
25076 +       get_nsproxy(proxy);
25077 +       return proxy;
25078 +}
25079 +
25080 +/*
25081 + *     merge two fs structs into a new one.
25082 + *     will take a reference on the result.
25083 + */
25084 +
25085 +static inline
25086 +struct fs_struct *__vs_merge_fs(struct fs_struct *old,
25087 +       struct fs_struct *fs, unsigned long mask)
25088 +{
25089 +       if (!(mask & CLONE_FS)) {
25090 +               if (old)
25091 +                       atomic_inc(&old->count);
25092 +               return old;
25093 +       }
25094 +
25095 +       if (!fs)
25096 +               return NULL;
25097 +
25098 +       return copy_fs_struct(fs);
25099 +}
25100 +
25101 +
25102 +int vx_enter_space(struct vx_info *vxi, unsigned long mask)
25103 +{
25104 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
25105 +       struct fs_struct *fs, *fs_cur, *fs_new;
25106 +       int ret;
25107 +
25108 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
25109 +               return -EACCES;
25110 +
25111 +       if (!mask)
25112 +               mask = vxi->vx_nsmask;
25113 +
25114 +       if ((mask & vxi->vx_nsmask) != mask)
25115 +               return -EINVAL;
25116 +
25117 +       proxy = vxi->vx_nsproxy;
25118 +       fs = vxi->vx_fs;
25119 +
25120 +       task_lock(current);
25121 +       fs_cur = current->fs;
25122 +       atomic_inc(&fs_cur->count);
25123 +       proxy_cur = current->nsproxy;
25124 +       get_nsproxy(proxy_cur);
25125 +       task_unlock(current);
25126 +
25127 +       fs_new = __vs_merge_fs(fs_cur, fs, mask);
25128 +       if (IS_ERR(fs_new)) {
25129 +               ret = PTR_ERR(fs_new);
25130 +               goto out_put;
25131 +       }
25132 +
25133 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
25134 +       if (IS_ERR(proxy_new)) {
25135 +               ret = PTR_ERR(proxy_new);
25136 +               goto out_put_fs;
25137 +       }
25138 +
25139 +       fs_new = xchg(&current->fs, fs_new);
25140 +       proxy_new = xchg(&current->nsproxy, proxy_new);
25141 +       ret = 0;
25142 +
25143 +       if (proxy_new)
25144 +               put_nsproxy(proxy_new);
25145 +out_put_fs:
25146 +       if (fs_new)
25147 +               put_fs_struct(fs_new);
25148 +out_put:
25149 +       if (proxy_cur)
25150 +               put_nsproxy(proxy_cur);
25151 +       if (fs_cur)
25152 +               put_fs_struct(fs_cur);
25153 +       return ret;
25154 +}
25155 +
25156 +
25157 +int vx_set_space(struct vx_info *vxi, unsigned long mask)
25158 +{
25159 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
25160 +       struct fs_struct *fs_vxi, *fs_cur, *fs_new;
25161 +       int ret;
25162 +
25163 +       if (!mask)
25164 +               mask = space_mask.mask;
25165 +
25166 +       if ((mask & space_mask.mask) != mask)
25167 +               return -EINVAL;
25168 +
25169 +       proxy_vxi = vxi->vx_nsproxy;
25170 +       fs_vxi = vxi->vx_fs;
25171 +
25172 +       task_lock(current);
25173 +       fs_cur = current->fs;
25174 +       atomic_inc(&fs_cur->count);
25175 +       proxy_cur = current->nsproxy;
25176 +       get_nsproxy(proxy_cur);
25177 +       task_unlock(current);
25178 +
25179 +       fs_new = __vs_merge_fs(fs_vxi, fs_cur, mask);
25180 +       if (IS_ERR(fs_new)) {
25181 +               ret = PTR_ERR(fs_new);
25182 +               goto out_put;
25183 +       }
25184 +
25185 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
25186 +       if (IS_ERR(proxy_new)) {
25187 +               ret = PTR_ERR(proxy_new);
25188 +               goto out_put_fs;
25189 +       }
25190 +
25191 +       fs_new = xchg(&vxi->vx_fs, fs_new);
25192 +       proxy_new = xchg(&vxi->vx_nsproxy, proxy_new);
25193 +       vxi->vx_nsmask |= mask;
25194 +       ret = 0;
25195 +
25196 +       if (proxy_new)
25197 +               put_nsproxy(proxy_new);
25198 +out_put_fs:
25199 +       if (fs_new)
25200 +               put_fs_struct(fs_new);
25201 +out_put:
25202 +       if (proxy_cur)
25203 +               put_nsproxy(proxy_cur);
25204 +       if (fs_cur)
25205 +               put_fs_struct(fs_cur);
25206 +       return ret;
25207 +}
25208 +
25209 +
25210 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25211 +{
25212 +       struct vcmd_space_mask vc_data = { .mask = 0 };
25213 +
25214 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25215 +               return -EFAULT;
25216 +
25217 +       return vx_enter_space(vxi, vc_data.mask);
25218 +}
25219 +
25220 +int vc_set_space(struct vx_info *vxi, void __user *data)
25221 +{
25222 +       struct vcmd_space_mask vc_data = { .mask = 0 };
25223 +
25224 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25225 +               return -EFAULT;
25226 +
25227 +       return vx_set_space(vxi, vc_data.mask);
25228 +}
25229 +
25230 +int vc_get_space_mask(struct vx_info *vxi, void __user *data)
25231 +{
25232 +       if (copy_to_user(data, &space_mask, sizeof(space_mask)))
25233 +               return -EFAULT;
25234 +       return 0;
25235 +}
25236 +
25237 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/switch.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/switch.c
25238 --- linux-2.6.22.10/kernel/vserver/switch.c     1970-01-01 01:00:00 +0100
25239 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/switch.c   2007-10-29 23:34:24 +0100
25240 @@ -0,0 +1,538 @@
25241 +/*
25242 + *  linux/kernel/vserver/switch.c
25243 + *
25244 + *  Virtual Server: Syscall Switch
25245 + *
25246 + *  Copyright (C) 2003-2007  Herbert Pötzl
25247 + *
25248 + *  V0.01  syscall switch
25249 + *  V0.02  added signal to context
25250 + *  V0.03  added rlimit functions
25251 + *  V0.04  added iattr, task/xid functions
25252 + *  V0.05  added debug/history stuff
25253 + *  V0.06  added compat32 layer
25254 + *  V0.07  vcmd args and perms
25255 + *  V0.08  added status commands
25256 + *
25257 + */
25258 +
25259 +#include <linux/linkage.h>
25260 +#include <linux/sched.h>
25261 +#include <linux/compat.h>
25262 +#include <asm/errno.h>
25263 +
25264 +#include <linux/vs_context.h>
25265 +#include <linux/vs_network.h>
25266 +#include <linux/vserver/switch.h>
25267 +
25268 +#include "vci_config.h"
25269 +
25270 +static inline
25271 +int vc_get_version(uint32_t id)
25272 +{
25273 +#ifdef CONFIG_VSERVER_LEGACY_VERSION
25274 +       if (id == 63)
25275 +               return VCI_LEGACY_VERSION;
25276 +#endif
25277 +       return VCI_VERSION;
25278 +}
25279 +
25280 +static inline
25281 +int vc_get_vci(uint32_t id)
25282 +{
25283 +       return vci_kernel_config();
25284 +}
25285 +
25286 +#include <linux/vserver/context_cmd.h>
25287 +#include <linux/vserver/cvirt_cmd.h>
25288 +#include <linux/vserver/cacct_cmd.h>
25289 +#include <linux/vserver/limit_cmd.h>
25290 +#include <linux/vserver/network_cmd.h>
25291 +#include <linux/vserver/sched_cmd.h>
25292 +#include <linux/vserver/debug_cmd.h>
25293 +#include <linux/vserver/inode_cmd.h>
25294 +#include <linux/vserver/dlimit_cmd.h>
25295 +#include <linux/vserver/signal_cmd.h>
25296 +#include <linux/vserver/space_cmd.h>
25297 +
25298 +#include <linux/vserver/legacy.h>
25299 +#include <linux/vserver/inode.h>
25300 +#include <linux/vserver/dlimit.h>
25301 +
25302 +
25303 +#ifdef CONFIG_COMPAT
25304 +#define __COMPAT(name, id, data, compat)       \
25305 +       (compat) ? name ## _x32(id, data) : name(id, data)
25306 +#define __COMPAT_NO_ID(name, data, compat)     \
25307 +       (compat) ? name ## _x32(data) : name(data)
25308 +#else
25309 +#define __COMPAT(name, id, data, compat)       \
25310 +       name(id, data)
25311 +#define __COMPAT_NO_ID(name, data, compat)     \
25312 +       name(data)
25313 +#endif
25314 +
25315 +
25316 +static inline
25317 +long do_vcmd(uint32_t cmd, uint32_t id,
25318 +       struct vx_info *vxi, struct nx_info *nxi,
25319 +       void __user *data, int compat)
25320 +{
25321 +       switch (cmd) {
25322 +
25323 +       case VCMD_get_version:
25324 +               return vc_get_version(id);
25325 +       case VCMD_get_vci:
25326 +               return vc_get_vci(id);
25327 +
25328 +       case VCMD_task_xid:
25329 +               return vc_task_xid(id, data);
25330 +       case VCMD_vx_info:
25331 +               return vc_vx_info(vxi, data);
25332 +
25333 +       case VCMD_task_nid:
25334 +               return vc_task_nid(id, data);
25335 +       case VCMD_nx_info:
25336 +               return vc_nx_info(nxi, data);
25337 +
25338 +       case VCMD_set_space_v0:
25339 +       /* this is version 1 */
25340 +       case VCMD_set_space:
25341 +               return vc_set_space(vxi, data);
25342 +
25343 +       case VCMD_get_space_mask:
25344 +               return vc_get_space_mask(vxi, data);
25345 +
25346 +#ifdef CONFIG_IA32_EMULATION
25347 +       case VCMD_get_rlimit:
25348 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25349 +       case VCMD_set_rlimit:
25350 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25351 +#else
25352 +       case VCMD_get_rlimit:
25353 +               return vc_get_rlimit(vxi, data);
25354 +       case VCMD_set_rlimit:
25355 +               return vc_set_rlimit(vxi, data);
25356 +#endif
25357 +       case VCMD_get_rlimit_mask:
25358 +               return vc_get_rlimit_mask(id, data);
25359 +       case VCMD_reset_minmax:
25360 +               return vc_reset_minmax(vxi, data);
25361 +
25362 +       case VCMD_get_vhi_name:
25363 +               return vc_get_vhi_name(vxi, data);
25364 +       case VCMD_set_vhi_name:
25365 +               return vc_set_vhi_name(vxi, data);
25366 +
25367 +       case VCMD_ctx_stat:
25368 +               return vc_ctx_stat(vxi, data);
25369 +       case VCMD_virt_stat:
25370 +               return vc_virt_stat(vxi, data);
25371 +       case VCMD_sock_stat:
25372 +               return vc_sock_stat(vxi, data);
25373 +       case VCMD_rlimit_stat:
25374 +               return vc_rlimit_stat(vxi, data);
25375 +
25376 +       case VCMD_set_cflags:
25377 +               return vc_set_cflags(vxi, data);
25378 +       case VCMD_get_cflags:
25379 +               return vc_get_cflags(vxi, data);
25380 +
25381 +       case VCMD_set_ccaps_v0:
25382 +               return vc_set_ccaps_v0(vxi, data);
25383 +       /* this is version 1 */
25384 +       case VCMD_set_ccaps:
25385 +               return vc_set_ccaps(vxi, data);
25386 +       case VCMD_get_ccaps_v0:
25387 +               return vc_get_ccaps_v0(vxi, data);
25388 +       /* this is version 1 */
25389 +       case VCMD_get_ccaps:
25390 +               return vc_get_ccaps(vxi, data);
25391 +       case VCMD_set_bcaps:
25392 +               return vc_set_bcaps(vxi, data);
25393 +       case VCMD_get_bcaps:
25394 +               return vc_get_bcaps(vxi, data);
25395 +
25396 +       case VCMD_set_nflags:
25397 +               return vc_set_nflags(nxi, data);
25398 +       case VCMD_get_nflags:
25399 +               return vc_get_nflags(nxi, data);
25400 +
25401 +       case VCMD_set_ncaps:
25402 +               return vc_set_ncaps(nxi, data);
25403 +       case VCMD_get_ncaps:
25404 +               return vc_get_ncaps(nxi, data);
25405 +
25406 +#ifdef CONFIG_VSERVER_LEGACY
25407 +       case VCMD_set_sched_v2:
25408 +               return vc_set_sched_v2(vxi, data);
25409 +#endif
25410 +       case VCMD_set_sched_v3:
25411 +               return vc_set_sched_v3(vxi, data);
25412 +       case VCMD_set_sched_v4:
25413 +               return vc_set_sched_v4(vxi, data);
25414 +       /* this is version 5 */
25415 +       case VCMD_set_sched:
25416 +               return vc_set_sched(vxi, data);
25417 +       case VCMD_get_sched:
25418 +               return vc_get_sched(vxi, data);
25419 +       case VCMD_sched_info:
25420 +               return vc_sched_info(vxi, data);
25421 +
25422 +       case VCMD_add_dlimit:
25423 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25424 +       case VCMD_rem_dlimit:
25425 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25426 +       case VCMD_set_dlimit:
25427 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25428 +       case VCMD_get_dlimit:
25429 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25430 +
25431 +       case VCMD_ctx_kill:
25432 +               return vc_ctx_kill(vxi, data);
25433 +
25434 +       case VCMD_wait_exit:
25435 +               return vc_wait_exit(vxi, data);
25436 +
25437 +#ifdef CONFIG_VSERVER_LEGACY
25438 +       case VCMD_create_context:
25439 +               return vc_ctx_create(id, NULL);
25440 +#endif
25441 +
25442 +       case VCMD_get_iattr:
25443 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25444 +       case VCMD_set_iattr:
25445 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25446 +
25447 +       case VCMD_fget_iattr:
25448 +               return vc_fget_iattr(id, data);
25449 +       case VCMD_fset_iattr:
25450 +               return vc_fset_iattr(id, data);
25451 +
25452 +       case VCMD_enter_space_v0:
25453 +               return vc_enter_space(vxi, NULL);
25454 +       /* this is version 1 */
25455 +       case VCMD_enter_space:
25456 +               return vc_enter_space(vxi, data);
25457 +
25458 +       case VCMD_ctx_create_v0:
25459 +               return vc_ctx_create(id, NULL);
25460 +       case VCMD_ctx_create:
25461 +               return vc_ctx_create(id, data);
25462 +       case VCMD_ctx_migrate_v0:
25463 +               return vc_ctx_migrate(vxi, NULL);
25464 +       case VCMD_ctx_migrate:
25465 +               return vc_ctx_migrate(vxi, data);
25466 +
25467 +       case VCMD_net_create_v0:
25468 +               return vc_net_create(id, NULL);
25469 +       case VCMD_net_create:
25470 +               return vc_net_create(id, data);
25471 +       case VCMD_net_migrate:
25472 +               return vc_net_migrate(nxi, data);
25473 +       case VCMD_net_add:
25474 +               return vc_net_add(nxi, data);
25475 +       case VCMD_net_remove:
25476 +               return vc_net_remove(nxi, data);
25477 +
25478 +#ifdef CONFIG_VSERVER_HISTORY
25479 +       case VCMD_dump_history:
25480 +               return vc_dump_history(id);
25481 +       case VCMD_read_history:
25482 +               return __COMPAT(vc_read_history, id, data, compat);
25483 +#endif
25484 +#ifdef CONFIG_VSERVER_MONITOR
25485 +       case VCMD_read_monitor:
25486 +               return __COMPAT(vc_read_monitor, id, data, compat);
25487 +#endif
25488 +#ifdef CONFIG_VSERVER_LEGACY
25489 +       case VCMD_new_s_context:
25490 +               return vc_new_s_context(id, data);
25491 +#endif
25492 +#ifdef CONFIG_VSERVER_LEGACYNET
25493 +       case VCMD_set_ipv4root:
25494 +               return vc_set_ipv4root(id, data);
25495 +#endif
25496 +       default:
25497 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25498 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25499 +       }
25500 +       return -ENOSYS;
25501 +}
25502 +
25503 +
25504 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25505 +       case VCMD_ ## vcmd: perm = _perm;               \
25506 +               args = _args; flags = _flags; break
25507 +
25508 +
25509 +#define VCA_NONE       0x00
25510 +#define VCA_VXI                0x01
25511 +#define VCA_NXI                0x02
25512 +
25513 +#define VCF_NONE       0x00
25514 +#define VCF_INFO       0x01
25515 +#define VCF_ADMIN      0x02
25516 +#define VCF_ARES       0x06    /* includes admin */
25517 +#define VCF_SETUP      0x08
25518 +
25519 +#define VCF_ZIDOK      0x10    /* zero id okay */
25520 +
25521 +
25522 +static inline
25523 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25524 +{
25525 +       long ret;
25526 +       int permit = -1, state = 0;
25527 +       int perm = -1, args = 0, flags = 0;
25528 +       struct vx_info *vxi = NULL;
25529 +       struct nx_info *nxi = NULL;
25530 +
25531 +       switch (cmd) {
25532 +       /* unpriviledged commands */
25533 +       __VCMD(get_version,      0, VCA_NONE,   0);
25534 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25535 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25536 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25537 +
25538 +       /* info commands */
25539 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25540 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25541 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25542 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25543 +       __VCMD(get_ccaps_v0,     3, VCA_VXI,    VCF_INFO);
25544 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25545 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25546 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25547 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25548 +
25549 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25550 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25551 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25552 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25553 +
25554 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25555 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25556 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25557 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25558 +
25559 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25560 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25561 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25562 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25563 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25564 +
25565 +       /* lower admin commands */
25566 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25567 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25568 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25569 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25570 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25571 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25572 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25573 +
25574 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25575 +       __VCMD(net_create,       5, VCA_NONE,   0);
25576 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25577 +
25578 +       /* higher admin commands */
25579 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25580 +       __VCMD(set_space_v0,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25581 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25582 +
25583 +       __VCMD(set_ccaps_v0,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25584 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25585 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25586 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25587 +
25588 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25589 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25590 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25591 +       __VCMD(set_sched_v2,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25592 +       __VCMD(set_sched_v3,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25593 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25594 +
25595 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25596 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25597 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25598 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25599 +
25600 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25601 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25602 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25603 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25604 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25605 +
25606 +       /* debug level admin commands */
25607 +#ifdef CONFIG_VSERVER_HISTORY
25608 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25609 +       __VCMD(read_history,     9, VCA_NONE,   0);
25610 +#endif
25611 +#ifdef CONFIG_VSERVER_MONITOR
25612 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25613 +#endif
25614 +
25615 +       /* legacy commands */
25616 +#ifdef CONFIG_VSERVER_LEGACY
25617 +       __VCMD(new_s_context,    1, VCA_NONE,   0);
25618 +       __VCMD(create_context,   5, VCA_NONE,   0);
25619 +#endif
25620 +#ifdef CONFIG_VSERVER_LEGACYNET
25621 +       __VCMD(set_ipv4root,     5, VCA_NONE,   0);
25622 +#endif
25623 +       default:
25624 +               perm = -1;
25625 +       }
25626 +
25627 +       vxdprintk(VXD_CBIT(switch, 0),
25628 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25629 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25630 +               VC_VERSION(cmd), id, data, compat,
25631 +               perm, args, flags);
25632 +
25633 +       ret = -ENOSYS;
25634 +       if (perm < 0)
25635 +               goto out;
25636 +
25637 +       state = 1;
25638 +#ifdef CONFIG_VSERVER_LEGACY
25639 +       if (!capable(CAP_CONTEXT) &&
25640 +               /* dirty hack for capremove */
25641 +               !(cmd == VCMD_new_s_context && id == -2))
25642 +               goto out;
25643 +#else
25644 +       if (!capable(CAP_CONTEXT))
25645 +               goto out;
25646 +#endif
25647 +
25648 +       state = 2;
25649 +       /* moved here from the individual commands */
25650 +       ret = -EPERM;
25651 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25652 +               goto out;
25653 +
25654 +       state = 3;
25655 +       /* vcmd involves resource management  */
25656 +       ret = -EPERM;
25657 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25658 +               goto out;
25659 +
25660 +       state = 4;
25661 +       /* various legacy exceptions */
25662 +       switch (cmd) {
25663 +#ifdef CONFIG_VSERVER_LEGACY
25664 +       case VCMD_set_cflags:
25665 +       case VCMD_set_ccaps_v0:
25666 +               ret = 0;
25667 +               if (vx_check(0, VS_WATCH))
25668 +                       goto out;
25669 +               break;
25670 +
25671 +       case VCMD_ctx_create_v0:
25672 +#endif
25673 +       /* will go away when spectator is a cap */
25674 +       case VCMD_ctx_migrate_v0:
25675 +       case VCMD_ctx_migrate:
25676 +               if (id == 1) {
25677 +                       current->xid = 1;
25678 +                       ret = 1;
25679 +                       goto out;
25680 +               }
25681 +               break;
25682 +
25683 +       /* will go away when spectator is a cap */
25684 +       case VCMD_net_migrate:
25685 +               if (id == 1) {
25686 +                       current->nid = 1;
25687 +                       ret = 1;
25688 +                       goto out;
25689 +               }
25690 +               break;
25691 +
25692 +       /* legacy special casing */
25693 +       case VCMD_set_space_v0:
25694 +               id = -1;
25695 +               break;
25696 +       }
25697 +
25698 +       /* vcmds are fine by default */
25699 +       permit = 1;
25700 +
25701 +       /* admin type vcmds require admin ... */
25702 +       if (flags & VCF_ADMIN)
25703 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25704 +
25705 +       /* ... but setup type vcmds override that */
25706 +       if (!permit && (flags & VCF_SETUP))
25707 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25708 +
25709 +       state = 5;
25710 +       ret = -EPERM;
25711 +       if (!permit)
25712 +               goto out;
25713 +
25714 +       state = 6;
25715 +       if (!id && (flags & VCF_ZIDOK))
25716 +               goto skip_id;
25717 +
25718 +       ret = -ESRCH;
25719 +       if (args & VCA_VXI) {
25720 +               vxi = lookup_vx_info(id);
25721 +               if (!vxi)
25722 +                       goto out;
25723 +
25724 +               if ((flags & VCF_ADMIN) &&
25725 +                       /* special case kill for shutdown */
25726 +                       (cmd != VCMD_ctx_kill) &&
25727 +                       /* can context be administrated? */
25728 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25729 +                       ret = -EACCES;
25730 +                       goto out_vxi;
25731 +               }
25732 +       }
25733 +       state = 7;
25734 +       if (args & VCA_NXI) {
25735 +               nxi = lookup_nx_info(id);
25736 +               if (!nxi)
25737 +                       goto out_vxi;
25738 +
25739 +               if ((flags & VCF_ADMIN) &&
25740 +                       /* can context be administrated? */
25741 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25742 +                       ret = -EACCES;
25743 +                       goto out_nxi;
25744 +               }
25745 +       }
25746 +skip_id:
25747 +       state = 8;
25748 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25749 +
25750 +out_nxi:
25751 +       if ((args & VCA_NXI) && nxi)
25752 +               put_nx_info(nxi);
25753 +out_vxi:
25754 +       if ((args & VCA_VXI) && vxi)
25755 +               put_vx_info(vxi);
25756 +out:
25757 +       vxdprintk(VXD_CBIT(switch, 1),
25758 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25759 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25760 +               VC_VERSION(cmd), ret, ret, state, permit);
25761 +       return ret;
25762 +}
25763 +
25764 +asmlinkage long
25765 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25766 +{
25767 +       return do_vserver(cmd, id, data, 0);
25768 +}
25769 +
25770 +#ifdef CONFIG_COMPAT
25771 +
25772 +asmlinkage long
25773 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25774 +{
25775 +       return do_vserver(cmd, id, data, 1);
25776 +}
25777 +
25778 +#endif /* CONFIG_COMPAT */
25779 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/sysctl.c linux-2.6.22.10-vs2.2.0.5/kernel/vserver/sysctl.c
25780 --- linux-2.6.22.10/kernel/vserver/sysctl.c     1970-01-01 01:00:00 +0100
25781 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/sysctl.c   2007-06-16 05:31:20 +0200
25782 @@ -0,0 +1,248 @@
25783 +/*
25784 + *  kernel/vserver/sysctl.c
25785 + *
25786 + *  Virtual Context Support
25787 + *
25788 + *  Copyright (C) 2004-2007  Herbert Pötzl
25789 + *
25790 + *  V0.01  basic structure
25791 + *
25792 + */
25793 +
25794 +#include <linux/errno.h>
25795 +#include <linux/module.h>
25796 +#include <linux/types.h>
25797 +#include <linux/ctype.h>
25798 +#include <linux/sysctl.h>
25799 +#include <linux/parser.h>
25800 +#include <linux/fs.h>
25801 +
25802 +#include <asm/uaccess.h>
25803 +#include <asm/unistd.h>
25804 +
25805 +
25806 +#define CTL_VSERVER    4242    /* unused? */
25807 +
25808 +enum {
25809 +       CTL_DEBUG_ERROR         = 0,
25810 +       CTL_DEBUG_SWITCH        = 1,
25811 +       CTL_DEBUG_XID,
25812 +       CTL_DEBUG_NID,
25813 +       CTL_DEBUG_TAG,
25814 +       CTL_DEBUG_NET,
25815 +       CTL_DEBUG_LIMIT,
25816 +       CTL_DEBUG_CRES,
25817 +       CTL_DEBUG_DLIM,
25818 +       CTL_DEBUG_QUOTA,
25819 +       CTL_DEBUG_CVIRT,
25820 +       CTL_DEBUG_SPACE,
25821 +       CTL_DEBUG_MISC,
25822 +};
25823 +
25824 +
25825 +unsigned int vx_debug_switch   = 0;
25826 +unsigned int vx_debug_xid      = 0;
25827 +unsigned int vx_debug_nid      = 0;
25828 +unsigned int vx_debug_tag      = 0;
25829 +unsigned int vx_debug_net      = 0;
25830 +unsigned int vx_debug_limit    = 0;
25831 +unsigned int vx_debug_cres     = 0;
25832 +unsigned int vx_debug_dlim     = 0;
25833 +unsigned int vx_debug_quota    = 0;
25834 +unsigned int vx_debug_cvirt    = 0;
25835 +unsigned int vx_debug_space    = 0;
25836 +unsigned int vx_debug_misc     = 0;
25837 +
25838 +
25839 +static struct ctl_table_header *vserver_table_header;
25840 +static ctl_table vserver_table[];
25841 +
25842 +
25843 +void vserver_register_sysctl(void)
25844 +{
25845 +       if (!vserver_table_header) {
25846 +               vserver_table_header = register_sysctl_table(vserver_table);
25847 +       }
25848 +
25849 +}
25850 +
25851 +void vserver_unregister_sysctl(void)
25852 +{
25853 +       if (vserver_table_header) {
25854 +               unregister_sysctl_table(vserver_table_header);
25855 +               vserver_table_header = NULL;
25856 +       }
25857 +}
25858 +
25859 +
25860 +static int proc_dodebug(ctl_table *table, int write,
25861 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25862 +{
25863 +       char            tmpbuf[20], *p, c;
25864 +       unsigned int    value;
25865 +       size_t          left, len;
25866 +
25867 +       if ((*ppos && !write) || !*lenp) {
25868 +               *lenp = 0;
25869 +               return 0;
25870 +       }
25871 +
25872 +       left = *lenp;
25873 +
25874 +       if (write) {
25875 +               if (!access_ok(VERIFY_READ, buffer, left))
25876 +                       return -EFAULT;
25877 +               p = (char *)buffer;
25878 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25879 +                       left--, p++;
25880 +               if (!left)
25881 +                       goto done;
25882 +
25883 +               if (left > sizeof(tmpbuf) - 1)
25884 +                       return -EINVAL;
25885 +               if (copy_from_user(tmpbuf, p, left))
25886 +                       return -EFAULT;
25887 +               tmpbuf[left] = '\0';
25888 +
25889 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25890 +                       value = 10 * value + (*p - '0');
25891 +               if (*p && !isspace(*p))
25892 +                       return -EINVAL;
25893 +               while (left && isspace(*p))
25894 +                       left--, p++;
25895 +               *(unsigned int *)table->data = value;
25896 +       } else {
25897 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25898 +                       return -EFAULT;
25899 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25900 +               if (len > left)
25901 +                       len = left;
25902 +               if (__copy_to_user(buffer, tmpbuf, len))
25903 +                       return -EFAULT;
25904 +               if ((left -= len) > 0) {
25905 +                       if (put_user('\n', (char *)buffer + len))
25906 +                               return -EFAULT;
25907 +                       left--;
25908 +               }
25909 +       }
25910 +
25911 +done:
25912 +       *lenp -= left;
25913 +       *ppos += *lenp;
25914 +       return 0;
25915 +}
25916 +
25917 +
25918 +#define        CTL_ENTRY(ctl, name)                            \
25919 +       {                                               \
25920 +               .ctl_name       = ctl,                  \
25921 +               .procname       = #name,                \
25922 +               .data           = &vx_ ## name,         \
25923 +               .maxlen         = sizeof(int),          \
25924 +               .mode           = 0644,                 \
25925 +               .proc_handler   = &proc_dodebug         \
25926 +       }
25927 +
25928 +static ctl_table debug_table[] = {
25929 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25930 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25931 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25932 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25933 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25934 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25935 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25936 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25937 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25938 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25939 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25940 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25941 +       { .ctl_name = 0 }
25942 +};
25943 +
25944 +static ctl_table vserver_table[] = {
25945 +       {
25946 +               .ctl_name       = CTL_VSERVER,
25947 +               .procname       = "vserver",
25948 +               .mode           = 0555,
25949 +               .child          = debug_table
25950 +       },
25951 +       { .ctl_name = 0 }
25952 +};
25953 +
25954 +
25955 +static match_table_t tokens = {
25956 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25957 +       { CTL_DEBUG_XID,        "xid=%x"        },
25958 +       { CTL_DEBUG_NID,        "nid=%x"        },
25959 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25960 +       { CTL_DEBUG_NET,        "net=%x"        },
25961 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25962 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25963 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25964 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25965 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25966 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25967 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25968 +       { CTL_DEBUG_ERROR,      NULL            }
25969 +};
25970 +
25971 +#define        HANDLE_CASE(id, name, val)                              \
25972 +       case CTL_DEBUG_ ## id:                                  \
25973 +               vx_debug_ ## name = val;                        \
25974 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25975 +               break
25976 +
25977 +
25978 +static int __init vs_debug_setup(char *str)
25979 +{
25980 +       char *p;
25981 +       int token;
25982 +
25983 +       printk("vs_debug_setup(%s)\n", str);
25984 +       while ((p = strsep(&str, ",")) != NULL) {
25985 +               substring_t args[MAX_OPT_ARGS];
25986 +               unsigned int value;
25987 +
25988 +               if (!*p)
25989 +                       continue;
25990 +
25991 +               token = match_token(p, tokens, args);
25992 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25993 +
25994 +               switch (token) {
25995 +               HANDLE_CASE(SWITCH, switch, value);
25996 +               HANDLE_CASE(XID,    xid,    value);
25997 +               HANDLE_CASE(NID,    nid,    value);
25998 +               HANDLE_CASE(TAG,    tag,    value);
25999 +               HANDLE_CASE(NET,    net,    value);
26000 +               HANDLE_CASE(LIMIT,  limit,  value);
26001 +               HANDLE_CASE(CRES,   cres,   value);
26002 +               HANDLE_CASE(DLIM,   dlim,   value);
26003 +               HANDLE_CASE(QUOTA,  quota,  value);
26004 +               HANDLE_CASE(CVIRT,  cvirt,  value);
26005 +               HANDLE_CASE(SPACE,  space,  value);
26006 +               HANDLE_CASE(MISC,   misc,   value);
26007 +               default:
26008 +                       return -EINVAL;
26009 +                       break;
26010 +               }
26011 +       }
26012 +       return 1;
26013 +}
26014 +
26015 +__setup("vsdebug=", vs_debug_setup);
26016 +
26017 +
26018 +
26019 +EXPORT_SYMBOL_GPL(vx_debug_switch);
26020 +EXPORT_SYMBOL_GPL(vx_debug_xid);
26021 +EXPORT_SYMBOL_GPL(vx_debug_nid);
26022 +EXPORT_SYMBOL_GPL(vx_debug_net);
26023 +EXPORT_SYMBOL_GPL(vx_debug_limit);
26024 +EXPORT_SYMBOL_GPL(vx_debug_cres);
26025 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
26026 +EXPORT_SYMBOL_GPL(vx_debug_quota);
26027 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
26028 +EXPORT_SYMBOL_GPL(vx_debug_space);
26029 +EXPORT_SYMBOL_GPL(vx_debug_misc);
26030 +
26031 diff -NurpP --minimal linux-2.6.22.10/kernel/vserver/vci_config.h linux-2.6.22.10-vs2.2.0.5/kernel/vserver/vci_config.h
26032 --- linux-2.6.22.10/kernel/vserver/vci_config.h 1970-01-01 01:00:00 +0100
26033 +++ linux-2.6.22.10-vs2.2.0.5/kernel/vserver/vci_config.h       2007-06-15 02:37:04 +0200
26034 @@ -0,0 +1,92 @@
26035 +
26036 +/*  interface version */
26037 +
26038 +#define VCI_VERSION            0x00020200
26039 +#define VCI_LEGACY_VERSION     0x000100FF
26040 +
26041 +
26042 +enum {
26043 +       VCI_KCBIT_NO_DYNAMIC = 0,
26044 +       VCI_KCBIT_LEGACY = 1,
26045 +       VCI_KCBIT_LEGACYNET = 2,
26046 +       VCI_KCBIT_NGNET = 3,
26047 +
26048 +       VCI_KCBIT_PROC_SECURE = 4,
26049 +       VCI_KCBIT_HARDCPU = 5,
26050 +       VCI_KCBIT_IDLELIMIT = 6,
26051 +       VCI_KCBIT_IDLETIME = 7,
26052 +
26053 +       VCI_KCBIT_COWBL = 8,
26054 +       VCI_KCBIT_FULLCOWBL = 9,
26055 +       VCI_KCBIT_SPACES = 10,
26056 +
26057 +       VCI_KCBIT_LEGACY_VERSION = 15,
26058 +       VCI_KCBIT_DEBUG = 16,
26059 +       VCI_KCBIT_HISTORY = 20,
26060 +       VCI_KCBIT_TAGGED = 24,
26061 +};
26062 +
26063 +
26064 +static inline uint32_t vci_kernel_config(void)
26065 +{
26066 +       return
26067 +       /* various legacy options */
26068 +#ifndef CONFIG_VSERVER_DYNAMIC_IDS
26069 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
26070 +#endif
26071 +#ifdef CONFIG_VSERVER_LEGACY
26072 +       (1 << VCI_KCBIT_LEGACY) |
26073 +#endif
26074 +#ifdef CONFIG_VSERVER_LEGACYNET
26075 +       (1 << VCI_KCBIT_LEGACYNET) |
26076 +#endif
26077 +#ifdef CONFIG_VSERVER_LEGACY_VERSION
26078 +       (1 << VCI_KCBIT_LEGACY_VERSION) |
26079 +#endif
26080 +
26081 +       /* configured features */
26082 +#ifdef CONFIG_VSERVER_PROC_SECURE
26083 +       (1 << VCI_KCBIT_PROC_SECURE) |
26084 +#endif
26085 +#ifdef CONFIG_VSERVER_HARDCPU
26086 +       (1 << VCI_KCBIT_HARDCPU) |
26087 +#endif
26088 +#ifdef CONFIG_VSERVER_IDLELIMIT
26089 +       (1 << VCI_KCBIT_IDLELIMIT) |
26090 +#endif
26091 +#ifdef CONFIG_VSERVER_IDLETIME
26092 +       (1 << VCI_KCBIT_IDLETIME) |
26093 +#endif
26094 +#ifdef CONFIG_VSERVER_COWBL
26095 +       (1 << VCI_KCBIT_COWBL) |
26096 +       (1 << VCI_KCBIT_FULLCOWBL) |
26097 +#endif
26098 +       (1 << VCI_KCBIT_SPACES) |
26099 +
26100 +       /* debug options */
26101 +#ifdef CONFIG_VSERVER_DEBUG
26102 +       (1 << VCI_KCBIT_DEBUG) |
26103 +#endif
26104 +#ifdef CONFIG_VSERVER_HISTORY
26105 +       (1 << VCI_KCBIT_HISTORY) |
26106 +#endif
26107 +
26108 +       /* inode context tagging */
26109 +#if    defined(CONFIG_TAGGING_NONE)
26110 +       (0 << VCI_KCBIT_TAGGED) |
26111 +#elif  defined(CONFIG_TAGGING_UID16)
26112 +       (1 << VCI_KCBIT_TAGGED) |
26113 +#elif  defined(CONFIG_TAGGING_GID16)
26114 +       (2 << VCI_KCBIT_TAGGED) |
26115 +#elif  defined(CONFIG_TAGGING_ID24)
26116 +       (3 << VCI_KCBIT_TAGGED) |
26117 +#elif  defined(CONFIG_TAGGING_INTERN)
26118 +       (4 << VCI_KCBIT_TAGGED) |
26119 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26120 +       (5 << VCI_KCBIT_TAGGED) |
26121 +#else
26122 +       (7 << VCI_KCBIT_TAGGED) |
26123 +#endif
26124 +       0;
26125 +}
26126 +
26127 diff -NurpP --minimal linux-2.6.22.10/mm/filemap_xip.c linux-2.6.22.10-vs2.2.0.5/mm/filemap_xip.c
26128 --- linux-2.6.22.10/mm/filemap_xip.c    2007-07-09 13:20:04 +0200
26129 +++ linux-2.6.22.10-vs2.2.0.5/mm/filemap_xip.c  2007-06-15 05:30:21 +0200
26130 @@ -14,6 +14,7 @@
26131  #include <linux/uio.h>
26132  #include <linux/rmap.h>
26133  #include <linux/sched.h>
26134 +#include <linux/vs_memory.h>
26135  #include <asm/tlbflush.h>
26136  #include "filemap.h"
26137  
26138 diff -NurpP --minimal linux-2.6.22.10/mm/fremap.c linux-2.6.22.10-vs2.2.0.5/mm/fremap.c
26139 --- linux-2.6.22.10/mm/fremap.c 2007-02-06 03:01:56 +0100
26140 +++ linux-2.6.22.10-vs2.2.0.5/mm/fremap.c       2007-06-15 02:37:04 +0200
26141 @@ -15,6 +15,7 @@
26142  #include <linux/rmap.h>
26143  #include <linux/module.h>
26144  #include <linux/syscalls.h>
26145 +#include <linux/vs_memory.h>
26146  
26147  #include <asm/mmu_context.h>
26148  #include <asm/cacheflush.h>
26149 @@ -74,6 +75,8 @@ int install_page(struct mm_struct *mm, s
26150         err = -ENOMEM;
26151         if (page_mapcount(page) > INT_MAX/2)
26152                 goto unlock;
26153 +       if (!vx_rss_avail(mm, 1))
26154 +               goto unlock;
26155  
26156         if (pte_none(*pte) || !zap_pte(mm, vma, addr, pte))
26157                 inc_mm_counter(mm, file_rss);
26158 diff -NurpP --minimal linux-2.6.22.10/mm/hugetlb.c linux-2.6.22.10-vs2.2.0.5/mm/hugetlb.c
26159 --- linux-2.6.22.10/mm/hugetlb.c        2007-10-30 01:57:15 +0100
26160 +++ linux-2.6.22.10-vs2.2.0.5/mm/hugetlb.c      2007-08-12 12:21:52 +0200
26161 @@ -19,6 +19,7 @@
26162  #include <asm/pgtable.h>
26163  
26164  #include <linux/hugetlb.h>
26165 +#include <linux/vs_memory.h>
26166  #include "internal.h"
26167  
26168  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26169 diff -NurpP --minimal linux-2.6.22.10/mm/memory.c linux-2.6.22.10-vs2.2.0.5/mm/memory.c
26170 --- linux-2.6.22.10/mm/memory.c 2007-07-09 13:20:04 +0200
26171 +++ linux-2.6.22.10-vs2.2.0.5/mm/memory.c       2007-06-17 05:55:53 +0200
26172 @@ -498,6 +498,9 @@ static int copy_pte_range(struct mm_stru
26173         int progress = 0;
26174         int rss[2];
26175  
26176 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26177 +               return -ENOMEM;
26178 +
26179  again:
26180         rss[1] = rss[0] = 0;
26181         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26182 @@ -2157,6 +2160,11 @@ static int do_swap_page(struct mm_struct
26183                 count_vm_event(PGMAJFAULT);
26184         }
26185  
26186 +       if (!vx_rss_avail(mm, 1)) {
26187 +               ret = VM_FAULT_OOM;
26188 +               goto out;
26189 +       }
26190 +
26191         delayacct_clear_flag(DELAYACCT_PF_SWAPIN);
26192         mark_page_accessed(page);
26193         lock_page(page);
26194 @@ -2229,6 +2237,8 @@ static int do_anonymous_page(struct mm_s
26195                 /* Allocate our own private page. */
26196                 pte_unmap(page_table);
26197  
26198 +               if (!vx_rss_avail(mm, 1))
26199 +                       goto oom;
26200                 if (unlikely(anon_vma_prepare(vma)))
26201                         goto oom;
26202                 page = alloc_zeroed_user_highpage(vma, address);
26203 @@ -2302,6 +2312,9 @@ static int do_no_page(struct mm_struct *
26204         pte_unmap(page_table);
26205         BUG_ON(vma->vm_flags & VM_PFNMAP);
26206  
26207 +       if (!vx_rss_avail(mm, 1))
26208 +               return VM_FAULT_OOM;
26209 +
26210         if (vma->vm_file) {
26211                 mapping = vma->vm_file->f_mapping;
26212                 sequence = mapping->truncate_count;
26213 @@ -2527,6 +2540,7 @@ static inline int handle_pte_fault(struc
26214  {
26215         pte_t entry;
26216         spinlock_t *ptl;
26217 +       int ret, type = VXPT_UNKNOWN;
26218  
26219         entry = *pte;
26220         if (!pte_present(entry)) {
26221 @@ -2555,9 +2569,12 @@ static inline int handle_pte_fault(struc
26222         if (unlikely(!pte_same(*pte, entry)))
26223                 goto unlock;
26224         if (write_access) {
26225 -               if (!pte_write(entry))
26226 -                       return do_wp_page(mm, vma, address,
26227 +               if (!pte_write(entry)) {
26228 +                       ret = do_wp_page(mm, vma, address,
26229                                         pte, pmd, ptl, entry);
26230 +                       type = VXPT_WRITE;
26231 +                       goto out;
26232 +               }
26233                 entry = pte_mkdirty(entry);
26234         }
26235         entry = pte_mkyoung(entry);
26236 @@ -2576,7 +2593,10 @@ static inline int handle_pte_fault(struc
26237         }
26238  unlock:
26239         pte_unmap_unlock(pte, ptl);
26240 -       return VM_FAULT_MINOR;
26241 +       ret = VM_FAULT_MINOR;
26242 +out:
26243 +       vx_page_fault(mm, vma, type, ret);
26244 +       return ret;
26245  }
26246  
26247  /*
26248 diff -NurpP --minimal linux-2.6.22.10/mm/mlock.c linux-2.6.22.10-vs2.2.0.5/mm/mlock.c
26249 --- linux-2.6.22.10/mm/mlock.c  2007-10-30 01:57:15 +0100
26250 +++ linux-2.6.22.10-vs2.2.0.5/mm/mlock.c        2007-08-12 12:21:52 +0200
26251 @@ -12,6 +12,7 @@
26252  #include <linux/syscalls.h>
26253  #include <linux/sched.h>
26254  #include <linux/module.h>
26255 +#include <linux/vs_memory.h>
26256  
26257  int can_do_mlock(void)
26258  {
26259 @@ -76,7 +77,7 @@ success:
26260                         ret = make_pages_present(start, end);
26261         }
26262  
26263 -       mm->locked_vm -= pages;
26264 +       vx_vmlocked_sub(mm, pages);
26265  out:
26266         if (ret == -ENOMEM)
26267                 ret = -EAGAIN;
26268 @@ -134,7 +135,7 @@ static int do_mlock(unsigned long start,
26269  
26270  asmlinkage long sys_mlock(unsigned long start, size_t len)
26271  {
26272 -       unsigned long locked;
26273 +       unsigned long locked, grow;
26274         unsigned long lock_limit;
26275         int error = -ENOMEM;
26276  
26277 @@ -145,8 +146,10 @@ asmlinkage long sys_mlock(unsigned long 
26278         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26279         start &= PAGE_MASK;
26280  
26281 -       locked = len >> PAGE_SHIFT;
26282 -       locked += current->mm->locked_vm;
26283 +       grow = len >> PAGE_SHIFT;
26284 +       if (!vx_vmlocked_avail(current->mm, grow))
26285 +               goto out;
26286 +       locked = current->mm->locked_vm + grow;
26287  
26288         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26289         lock_limit >>= PAGE_SHIFT;
26290 @@ -154,6 +157,7 @@ asmlinkage long sys_mlock(unsigned long 
26291         /* check against resource limits */
26292         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26293                 error = do_mlock(start, len, 1);
26294 +out:
26295         up_write(&current->mm->mmap_sem);
26296         return error;
26297  }
26298 @@ -213,6 +217,8 @@ asmlinkage long sys_mlockall(int flags)
26299         lock_limit >>= PAGE_SHIFT;
26300  
26301         ret = -ENOMEM;
26302 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26303 +               goto out;
26304         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26305             capable(CAP_IPC_LOCK))
26306                 ret = do_mlockall(flags);
26307 diff -NurpP --minimal linux-2.6.22.10/mm/mmap.c linux-2.6.22.10-vs2.2.0.5/mm/mmap.c
26308 --- linux-2.6.22.10/mm/mmap.c   2007-07-09 13:20:04 +0200
26309 +++ linux-2.6.22.10-vs2.2.0.5/mm/mmap.c 2007-07-17 03:02:15 +0200
26310 @@ -1144,10 +1144,10 @@ munmap_back:
26311                 kmem_cache_free(vm_area_cachep, vma);
26312         }
26313  out:   
26314 -       mm->total_vm += len >> PAGE_SHIFT;
26315 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26316         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26317         if (vm_flags & VM_LOCKED) {
26318 -               mm->locked_vm += len >> PAGE_SHIFT;
26319 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26320                 make_pages_present(addr, addr + len);
26321         }
26322         if (flags & MAP_POPULATE) {
26323 @@ -1502,9 +1502,9 @@ static int acct_stack_growth(struct vm_a
26324                 return -ENOMEM;
26325  
26326         /* Ok, everything looks good - let it rip */
26327 -       mm->total_vm += grow;
26328 +       vx_vmpages_add(mm, grow);
26329         if (vma->vm_flags & VM_LOCKED)
26330 -               mm->locked_vm += grow;
26331 +               vx_vmlocked_add(mm, grow);
26332         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26333         return 0;
26334  }
26335 @@ -1662,9 +1662,9 @@ static void remove_vma_list(struct mm_st
26336         do {
26337                 long nrpages = vma_pages(vma);
26338  
26339 -               mm->total_vm -= nrpages;
26340 +               vx_vmpages_sub(mm, nrpages);
26341                 if (vma->vm_flags & VM_LOCKED)
26342 -                       mm->locked_vm -= nrpages;
26343 +                       vx_vmlocked_sub(mm, nrpages);
26344                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26345                 vma = remove_vma(vma);
26346         } while (vma);
26347 @@ -1903,6 +1903,8 @@ unsigned long do_brk(unsigned long addr,
26348                 lock_limit >>= PAGE_SHIFT;
26349                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26350                         return -EAGAIN;
26351 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26352 +                       return -ENOMEM;
26353         }
26354  
26355         /*
26356 @@ -1929,7 +1931,8 @@ unsigned long do_brk(unsigned long addr,
26357         if (mm->map_count > sysctl_max_map_count)
26358                 return -ENOMEM;
26359  
26360 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26361 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26362 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26363                 return -ENOMEM;
26364  
26365         /* Can we just expand an old private anonymous mapping? */
26366 @@ -1955,9 +1958,9 @@ unsigned long do_brk(unsigned long addr,
26367                                 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)];
26368         vma_link(mm, vma, prev, rb_link, rb_parent);
26369  out:
26370 -       mm->total_vm += len >> PAGE_SHIFT;
26371 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26372         if (flags & VM_LOCKED) {
26373 -               mm->locked_vm += len >> PAGE_SHIFT;
26374 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26375                 make_pages_present(addr, addr + len);
26376         }
26377         return addr;
26378 @@ -1986,6 +1989,11 @@ void exit_mmap(struct mm_struct *mm)
26379         free_pgtables(&tlb, vma, FIRST_USER_ADDRESS, 0);
26380         tlb_finish_mmu(tlb, 0, end);
26381  
26382 +       set_mm_counter(mm, file_rss, 0);
26383 +       set_mm_counter(mm, anon_rss, 0);
26384 +       vx_vmpages_sub(mm, mm->total_vm);
26385 +       vx_vmlocked_sub(mm, mm->locked_vm);
26386 +
26387         /*
26388          * Walk the list again, actually closing and freeing it,
26389          * with preemption enabled, without holding any MM locks.
26390 @@ -2025,7 +2033,8 @@ int insert_vm_struct(struct mm_struct * 
26391         if (__vma && __vma->vm_start < vma->vm_end)
26392                 return -ENOMEM;
26393         if ((vma->vm_flags & VM_ACCOUNT) &&
26394 -            security_vm_enough_memory(vma_pages(vma)))
26395 +               (security_vm_enough_memory(vma_pages(vma)) ||
26396 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26397                 return -ENOMEM;
26398         vma_link(mm, vma, prev, rb_link, rb_parent);
26399         return 0;
26400 @@ -2098,6 +2107,8 @@ int may_expand_vm(struct mm_struct *mm, 
26401  
26402         if (cur + npages > lim)
26403                 return 0;
26404 +       if (!vx_vmpages_avail(mm, npages))
26405 +               return 0;
26406         return 1;
26407  }
26408  
26409 @@ -2168,7 +2179,6 @@ int install_special_mapping(struct mm_st
26410                 return -ENOMEM;
26411         }
26412  
26413 -       mm->total_vm += len >> PAGE_SHIFT;
26414 -
26415 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26416         return 0;
26417  }
26418 diff -NurpP --minimal linux-2.6.22.10/mm/mremap.c linux-2.6.22.10-vs2.2.0.5/mm/mremap.c
26419 --- linux-2.6.22.10/mm/mremap.c 2007-02-06 03:01:56 +0100
26420 +++ linux-2.6.22.10-vs2.2.0.5/mm/mremap.c       2007-06-15 02:37:04 +0200
26421 @@ -18,6 +18,7 @@
26422  #include <linux/highmem.h>
26423  #include <linux/security.h>
26424  #include <linux/syscalls.h>
26425 +#include <linux/vs_memory.h>
26426  
26427  #include <asm/uaccess.h>
26428  #include <asm/cacheflush.h>
26429 @@ -212,7 +213,7 @@ static unsigned long move_vma(struct vm_
26430          * If this were a serious issue, we'd add a flag to do_munmap().
26431          */
26432         hiwater_vm = mm->hiwater_vm;
26433 -       mm->total_vm += new_len >> PAGE_SHIFT;
26434 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26435         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26436  
26437         if (do_munmap(mm, old_addr, old_len) < 0) {
26438 @@ -230,7 +231,7 @@ static unsigned long move_vma(struct vm_
26439         }
26440  
26441         if (vm_flags & VM_LOCKED) {
26442 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26443 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26444                 if (new_len > old_len)
26445                         make_pages_present(new_addr + old_len,
26446                                            new_addr + new_len);
26447 @@ -337,6 +338,9 @@ unsigned long do_mremap(unsigned long ad
26448                 ret = -EAGAIN;
26449                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26450                         goto out;
26451 +               if (!vx_vmlocked_avail(current->mm,
26452 +                       (new_len - old_len) >> PAGE_SHIFT))
26453 +                       goto out;
26454         }
26455         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26456                 ret = -ENOMEM;
26457 @@ -365,10 +369,10 @@ unsigned long do_mremap(unsigned long ad
26458                         vma_adjust(vma, vma->vm_start,
26459                                 addr + new_len, vma->vm_pgoff, NULL);
26460  
26461 -                       mm->total_vm += pages;
26462 +                       vx_vmpages_add(mm, pages);
26463                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26464                         if (vma->vm_flags & VM_LOCKED) {
26465 -                               mm->locked_vm += pages;
26466 +                               vx_vmlocked_add(mm, pages);
26467                                 make_pages_present(addr + old_len,
26468                                                    addr + new_len);
26469                         }
26470 diff -NurpP --minimal linux-2.6.22.10/mm/nommu.c linux-2.6.22.10-vs2.2.0.5/mm/nommu.c
26471 --- linux-2.6.22.10/mm/nommu.c  2007-07-09 13:20:04 +0200
26472 +++ linux-2.6.22.10-vs2.2.0.5/mm/nommu.c        2007-06-15 02:37:04 +0200
26473 @@ -936,7 +936,7 @@ unsigned long do_mmap_pgoff(struct file 
26474         realalloc += kobjsize(vma);
26475         askedalloc += sizeof(*vma);
26476  
26477 -       current->mm->total_vm += len >> PAGE_SHIFT;
26478 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26479  
26480         add_nommu_vma(vma);
26481  
26482 @@ -1061,7 +1061,7 @@ int do_munmap(struct mm_struct *mm, unsi
26483         kfree(vml);
26484  
26485         update_hiwater_vm(mm);
26486 -       mm->total_vm -= len >> PAGE_SHIFT;
26487 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
26488  
26489  #ifdef DEBUG
26490         show_process_blocks();
26491 @@ -1093,7 +1093,7 @@ void exit_mmap(struct mm_struct * mm)
26492                 printk("Exit_mmap:\n");
26493  #endif
26494  
26495 -               mm->total_vm = 0;
26496 +               vx_vmpages_sub(mm, mm->total_vm);
26497  
26498                 while ((tmp = mm->context.vmlist)) {
26499                         mm->context.vmlist = tmp->next;
26500 diff -NurpP --minimal linux-2.6.22.10/mm/oom_kill.c linux-2.6.22.10-vs2.2.0.5/mm/oom_kill.c
26501 --- linux-2.6.22.10/mm/oom_kill.c       2007-07-09 13:20:04 +0200
26502 +++ linux-2.6.22.10-vs2.2.0.5/mm/oom_kill.c     2007-06-15 02:37:04 +0200
26503 @@ -24,6 +24,7 @@
26504  #include <linux/cpuset.h>
26505  #include <linux/module.h>
26506  #include <linux/notifier.h>
26507 +#include <linux/vs_memory.h>
26508  
26509  int sysctl_panic_on_oom;
26510  /* #define DEBUG */
26511 @@ -66,6 +67,12 @@ unsigned long badness(struct task_struct
26512         points = mm->total_vm;
26513  
26514         /*
26515 +        * add points for context badness
26516 +        */
26517 +
26518 +       points += vx_badness(p, mm);
26519 +
26520 +       /*
26521          * After this unlock we can no longer dereference local variable `mm'
26522          */
26523         task_unlock(p);
26524 @@ -156,8 +163,8 @@ unsigned long badness(struct task_struct
26525         }
26526  
26527  #ifdef DEBUG
26528 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
26529 -       p->pid, p->comm, points);
26530 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26531 +               p->pid, p->xid, p->comm, points);
26532  #endif
26533         return points;
26534  }
26535 @@ -288,7 +295,8 @@ static void __oom_kill_task(struct task_
26536         }
26537  
26538         if (verbose)
26539 -               printk(KERN_ERR "Killed process %d (%s)\n", p->pid, p->comm);
26540 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26541 +                               p->pid, p->xid, p->comm);
26542  
26543         /*
26544          * We give our sacrificial lamb high priority and access to
26545 @@ -358,8 +366,8 @@ static int oom_kill_process(struct task_
26546                 return 0;
26547         }
26548  
26549 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26550 -                                       message, p->pid, p->comm, points);
26551 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26552 +                               message, p->pid, p->xid, p->comm, points);
26553  
26554         /* Try to kill a child first */
26555         list_for_each(tsk, &p->children) {
26556 diff -NurpP --minimal linux-2.6.22.10/mm/page_alloc.c linux-2.6.22.10-vs2.2.0.5/mm/page_alloc.c
26557 --- linux-2.6.22.10/mm/page_alloc.c     2007-07-09 13:20:04 +0200
26558 +++ linux-2.6.22.10-vs2.2.0.5/mm/page_alloc.c   2007-06-17 05:54:20 +0200
26559 @@ -41,6 +41,8 @@
26560  #include <linux/pfn.h>
26561  #include <linux/backing-dev.h>
26562  #include <linux/fault-inject.h>
26563 +#include <linux/vs_base.h>
26564 +#include <linux/vs_limit.h>
26565  
26566  #include <asm/tlbflush.h>
26567  #include <asm/div64.h>
26568 @@ -1488,6 +1490,9 @@ void si_meminfo(struct sysinfo *val)
26569         val->totalhigh = totalhigh_pages;
26570         val->freehigh = nr_free_highpages();
26571         val->mem_unit = PAGE_SIZE;
26572 +
26573 +       if (vx_flags(VXF_VIRT_MEM, 0))
26574 +               vx_vsi_meminfo(val);
26575  }
26576  
26577  EXPORT_SYMBOL(si_meminfo);
26578 @@ -1508,6 +1513,9 @@ void si_meminfo_node(struct sysinfo *val
26579         val->freehigh = 0;
26580  #endif
26581         val->mem_unit = PAGE_SIZE;
26582 +
26583 +       if (vx_flags(VXF_VIRT_MEM, 0))
26584 +               vx_vsi_meminfo(val);
26585  }
26586  #endif
26587  
26588 diff -NurpP --minimal linux-2.6.22.10/mm/rmap.c linux-2.6.22.10-vs2.2.0.5/mm/rmap.c
26589 --- linux-2.6.22.10/mm/rmap.c   2007-07-09 13:20:04 +0200
26590 +++ linux-2.6.22.10-vs2.2.0.5/mm/rmap.c 2007-07-07 03:52:54 +0200
26591 @@ -48,6 +48,7 @@
26592  #include <linux/rcupdate.h>
26593  #include <linux/module.h>
26594  #include <linux/kallsyms.h>
26595 +#include <linux/vs_memory.h>
26596  
26597  #include <asm/tlbflush.h>
26598  
26599 diff -NurpP --minimal linux-2.6.22.10/mm/shmem.c linux-2.6.22.10-vs2.2.0.5/mm/shmem.c
26600 --- linux-2.6.22.10/mm/shmem.c  2007-07-09 13:20:04 +0200
26601 +++ linux-2.6.22.10-vs2.2.0.5/mm/shmem.c        2007-06-17 05:54:20 +0200
26602 @@ -55,7 +55,6 @@
26603  #include <asm/pgtable.h>
26604  
26605  /* This magic number is used in glibc for posix shared memory */
26606 -#define TMPFS_MAGIC    0x01021994
26607  
26608  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
26609  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
26610 @@ -1734,7 +1733,7 @@ static int shmem_statfs(struct dentry *d
26611  {
26612         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26613  
26614 -       buf->f_type = TMPFS_MAGIC;
26615 +       buf->f_type = TMPFS_SUPER_MAGIC;
26616         buf->f_bsize = PAGE_CACHE_SIZE;
26617         buf->f_namelen = NAME_MAX;
26618         spin_lock(&sbinfo->stat_lock);
26619 @@ -2308,7 +2307,7 @@ static int shmem_fill_super(struct super
26620         sb->s_maxbytes = SHMEM_MAX_BYTES;
26621         sb->s_blocksize = PAGE_CACHE_SIZE;
26622         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26623 -       sb->s_magic = TMPFS_MAGIC;
26624 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26625         sb->s_op = &shmem_ops;
26626         sb->s_time_gran = 1;
26627  #ifdef CONFIG_TMPFS_POSIX_ACL
26628 diff -NurpP --minimal linux-2.6.22.10/mm/slab.c linux-2.6.22.10-vs2.2.0.5/mm/slab.c
26629 --- linux-2.6.22.10/mm/slab.c   2007-07-09 13:20:04 +0200
26630 +++ linux-2.6.22.10-vs2.2.0.5/mm/slab.c 2007-07-09 13:11:54 +0200
26631 @@ -510,6 +510,8 @@ struct kmem_cache {
26632  #define STATS_INC_FREEMISS(x)  do { } while (0)
26633  #endif
26634  
26635 +#include "slab_vs.h"
26636 +
26637  #if DEBUG
26638  
26639  /*
26640 @@ -3314,6 +3316,7 @@ retry:
26641  
26642         obj = slab_get_obj(cachep, slabp, nodeid);
26643         check_slabp(cachep, slabp);
26644 +       vx_slab_alloc(cachep, flags);
26645         l3->free_objects--;
26646         /* move slabp to correct slabp list: */
26647         list_del(&slabp->list);
26648 @@ -3386,6 +3389,7 @@ __cache_alloc_node(struct kmem_cache *ca
26649         /* ___cache_alloc_node can fall back to other nodes */
26650         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26651    out:
26652 +       vx_slab_alloc(cachep, flags);
26653         local_irq_restore(save_flags);
26654         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26655  
26656 @@ -3551,6 +3555,7 @@ static inline void __cache_free(struct k
26657  
26658         check_irq_off();
26659         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26660 +       vx_slab_free(cachep);
26661  
26662         if (cache_free_alien(cachep, objp))
26663                 return;
26664 diff -NurpP --minimal linux-2.6.22.10/mm/slab_vs.h linux-2.6.22.10-vs2.2.0.5/mm/slab_vs.h
26665 --- linux-2.6.22.10/mm/slab_vs.h        1970-01-01 01:00:00 +0100
26666 +++ linux-2.6.22.10-vs2.2.0.5/mm/slab_vs.h      2007-06-15 02:37:04 +0200
26667 @@ -0,0 +1,27 @@
26668 +
26669 +#include <linux/vserver/context.h>
26670 +
26671 +#include <linux/vs_context.h>
26672 +
26673 +static inline
26674 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26675 +{
26676 +       int what = gfp_zone(cachep->gfpflags);
26677 +
26678 +       if (!current->vx_info)
26679 +               return;
26680 +
26681 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26682 +}
26683 +
26684 +static inline
26685 +void vx_slab_free(struct kmem_cache *cachep)
26686 +{
26687 +       int what = gfp_zone(cachep->gfpflags);
26688 +
26689 +       if (!current->vx_info)
26690 +               return;
26691 +
26692 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26693 +}
26694 +
26695 diff -NurpP --minimal linux-2.6.22.10/mm/swapfile.c linux-2.6.22.10-vs2.2.0.5/mm/swapfile.c
26696 --- linux-2.6.22.10/mm/swapfile.c       2007-07-09 13:20:04 +0200
26697 +++ linux-2.6.22.10-vs2.2.0.5/mm/swapfile.c     2007-06-15 02:37:04 +0200
26698 @@ -31,6 +31,8 @@
26699  #include <asm/pgtable.h>
26700  #include <asm/tlbflush.h>
26701  #include <linux/swapops.h>
26702 +#include <linux/vs_base.h>
26703 +#include <linux/vs_memory.h>
26704  
26705  DEFINE_SPINLOCK(swap_lock);
26706  unsigned int nr_swapfiles;
26707 @@ -1712,6 +1714,8 @@ void si_swapinfo(struct sysinfo *val)
26708         val->freeswap = nr_swap_pages + nr_to_be_unused;
26709         val->totalswap = total_swap_pages + nr_to_be_unused;
26710         spin_unlock(&swap_lock);
26711 +       if (vx_flags(VXF_VIRT_MEM, 0))
26712 +               vx_vsi_swapinfo(val);
26713  }
26714  
26715  /*
26716 diff -NurpP --minimal linux-2.6.22.10/net/core/dev.c linux-2.6.22.10-vs2.2.0.5/net/core/dev.c
26717 --- linux-2.6.22.10/net/core/dev.c      2007-10-30 01:57:15 +0100
26718 +++ linux-2.6.22.10-vs2.2.0.5/net/core/dev.c    2007-09-05 03:05:53 +0200
26719 @@ -117,6 +117,8 @@
26720  #include <linux/err.h>
26721  #include <linux/ctype.h>
26722  #include <linux/if_arp.h>
26723 +#include <linux/vs_context.h> /* remove with NXF_HIDE_NETIF */
26724 +#include <linux/vs_network.h>
26725  
26726  /*
26727   *     The list of packet types we will receive (as opposed to discard)
26728 @@ -2120,6 +2122,9 @@ static int dev_ifconf(char __user *arg)
26729  
26730         total = 0;
26731         for_each_netdev(dev) {
26732 +               if (vx_flags(VXF_HIDE_NETIF, 0) &&
26733 +                       !dev_in_nx_info(dev, current->nx_info))
26734 +                       continue;
26735                 for (i = 0; i < NPROTO; i++) {
26736                         if (gifconf_list[i]) {
26737                                 int done;
26738 @@ -2183,6 +2188,10 @@ void dev_seq_stop(struct seq_file *seq, 
26739  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
26740  {
26741         struct net_device_stats *stats = dev->get_stats(dev);
26742 +       struct nx_info *nxi = current->nx_info;
26743 +
26744 +       if (vx_flags(VXF_HIDE_NETIF, 0) && !dev_in_nx_info(dev, nxi))
26745 +               return;
26746  
26747         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26748                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26749 diff -NurpP --minimal linux-2.6.22.10/net/core/rtnetlink.c linux-2.6.22.10-vs2.2.0.5/net/core/rtnetlink.c
26750 --- linux-2.6.22.10/net/core/rtnetlink.c        2007-07-09 13:20:05 +0200
26751 +++ linux-2.6.22.10-vs2.2.0.5/net/core/rtnetlink.c      2007-06-17 05:54:20 +0200
26752 @@ -35,6 +35,7 @@
26753  #include <linux/security.h>
26754  #include <linux/mutex.h>
26755  #include <linux/if_addr.h>
26756 +#include <linux/vs_context.h> /* remove with NXF_HIDE_NETIF */
26757  
26758  #include <asm/uaccess.h>
26759  #include <asm/system.h>
26760 @@ -537,6 +538,9 @@ static int rtnl_dump_ifinfo(struct sk_bu
26761  
26762         idx = 0;
26763         for_each_netdev(dev) {
26764 +               if (vx_info_flags(skb->sk->sk_vx_info, VXF_HIDE_NETIF, 0) &&
26765 +                       !dev_in_nx_info(dev, skb->sk->sk_nx_info))
26766 +                       continue;
26767                 if (idx < s_idx)
26768                         goto cont;
26769                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26770 diff -NurpP --minimal linux-2.6.22.10/net/core/sock.c linux-2.6.22.10-vs2.2.0.5/net/core/sock.c
26771 --- linux-2.6.22.10/net/core/sock.c     2007-07-09 13:20:05 +0200
26772 +++ linux-2.6.22.10-vs2.2.0.5/net/core/sock.c   2007-06-15 02:37:04 +0200
26773 @@ -125,6 +125,9 @@
26774  #include <linux/ipsec.h>
26775  
26776  #include <linux/filter.h>
26777 +#include <linux/vs_socket.h>
26778 +#include <linux/vs_limit.h>
26779 +#include <linux/vs_context.h>
26780  
26781  #ifdef CONFIG_INET
26782  #include <net/tcp.h>
26783 @@ -869,6 +872,8 @@ struct sock *sk_alloc(int family, gfp_t 
26784                         sk->sk_prot = sk->sk_prot_creator = prot;
26785                         sock_lock_init(sk);
26786                 }
26787 +               sock_vx_init(sk);
26788 +               sock_nx_init(sk);
26789  
26790                 if (security_sk_alloc(sk, family, priority))
26791                         goto out_free;
26792 @@ -907,6 +912,11 @@ void sk_free(struct sock *sk)
26793                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
26794  
26795         security_sk_free(sk);
26796 +       vx_sock_dec(sk);
26797 +       clr_vx_info(&sk->sk_vx_info);
26798 +       sk->sk_xid = -1;
26799 +       clr_nx_info(&sk->sk_nx_info);
26800 +       sk->sk_nid = -1;
26801         if (sk->sk_prot_creator->slab != NULL)
26802                 kmem_cache_free(sk->sk_prot_creator->slab, sk);
26803         else
26804 @@ -924,6 +934,8 @@ struct sock *sk_clone(const struct sock 
26805                 sock_copy(newsk, sk);
26806  
26807                 /* SANITY */
26808 +               sock_vx_init(newsk);
26809 +               sock_nx_init(newsk);
26810                 sk_node_init(&newsk->sk_node);
26811                 sock_lock_init(newsk);
26812                 bh_lock_sock(newsk);
26813 @@ -969,6 +981,12 @@ struct sock *sk_clone(const struct sock 
26814                 newsk->sk_priority = 0;
26815                 atomic_set(&newsk->sk_refcnt, 2);
26816  
26817 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26818 +               newsk->sk_xid = sk->sk_xid;
26819 +               vx_sock_inc(newsk);
26820 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26821 +               newsk->sk_nid = sk->sk_nid;
26822 +
26823                 /*
26824                  * Increment the counter in the same struct proto as the master
26825                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26826 @@ -1551,6 +1569,11 @@ void sock_init_data(struct socket *sock,
26827  
26828         sk->sk_stamp = ktime_set(-1L, -1L);
26829  
26830 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26831 +       sk->sk_xid = vx_current_xid();
26832 +       vx_sock_inc(sk);
26833 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26834 +       sk->sk_nid = nx_current_nid();
26835         atomic_set(&sk->sk_refcnt, 1);
26836  }
26837  
26838 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/af_inet.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/af_inet.c
26839 --- linux-2.6.22.10/net/ipv4/af_inet.c  2007-10-30 01:57:15 +0100
26840 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/af_inet.c        2007-09-05 03:05:54 +0200
26841 @@ -115,6 +115,7 @@
26842  #ifdef CONFIG_IP_MROUTE
26843  #include <linux/mroute.h>
26844  #endif
26845 +#include <linux/vs_limit.h>
26846  
26847  DEFINE_SNMP_STAT(struct linux_mib, net_statistics) __read_mostly;
26848  
26849 @@ -308,9 +309,11 @@ lookup_protocol:
26850         }
26851  
26852         err = -EPERM;
26853 +       if ((protocol == IPPROTO_ICMP) && vx_ccaps(VXC_RAW_ICMP))
26854 +               goto override;
26855         if (answer->capability > 0 && !capable(answer->capability))
26856                 goto out_rcu_unlock;
26857 -
26858 +override:
26859         sock->ops = answer->ops;
26860         answer_prot = answer->prot;
26861         answer_no_check = answer->no_check;
26862 @@ -427,6 +430,10 @@ int inet_bind(struct socket *sock, struc
26863         unsigned short snum;
26864         int chk_addr_ret;
26865         int err;
26866 +       __u32 s_addr;   /* Address used for validation */
26867 +       __u32 s_addr1;  /* Address used for socket */
26868 +       __u32 s_addr2;  /* Broadcast address for the socket */
26869 +       struct nx_info *nxi = sk->sk_nx_info;
26870  
26871         /* If the socket has its own bind function then use it. (RAW) */
26872         if (sk->sk_prot->bind) {
26873 @@ -437,7 +444,40 @@ int inet_bind(struct socket *sock, struc
26874         if (addr_len < sizeof(struct sockaddr_in))
26875                 goto out;
26876  
26877 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
26878 +       s_addr = addr->sin_addr.s_addr;
26879 +       s_addr1 = s_addr;
26880 +       s_addr2 = 0xffffffffl;
26881 +
26882 +       vxdprintk(VXD_CBIT(net, 3),
26883 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
26884 +               sk, sk->sk_nx_info, sk->sk_socket,
26885 +               (sk->sk_socket?sk->sk_socket->flags:0),
26886 +               NIPQUAD(s_addr));
26887 +       if (nxi) {
26888 +               __u32 v4_bcast = nxi->v4_bcast;
26889 +               __u32 ipv4root = nxi->ipv4[0];
26890 +               int nbipv4 = nxi->nbipv4;
26891 +
26892 +               if (s_addr == 0) {
26893 +                       /* bind to any for 1-n */
26894 +                       s_addr = ipv4root;
26895 +                       s_addr1 = (nbipv4 > 1) ? 0 : s_addr;
26896 +                       s_addr2 = v4_bcast;
26897 +               } else if (s_addr == IPI_LOOPBACK) {
26898 +                       /* rewrite localhost to ipv4root */
26899 +                       s_addr = ipv4root;
26900 +                       s_addr1 = ipv4root;
26901 +               } else if (s_addr != v4_bcast) {
26902 +                       /* normal address bind */
26903 +                       if (!addr_in_nx_info(nxi, s_addr))
26904 +                               return -EADDRNOTAVAIL;
26905 +               }
26906 +       }
26907 +       chk_addr_ret = inet_addr_type(s_addr);
26908 +
26909 +       vxdprintk(VXD_CBIT(net, 3),
26910 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT ", " NIPQUAD_FMT,
26911 +               sk, NIPQUAD(s_addr), NIPQUAD(s_addr1), NIPQUAD(s_addr2));
26912  
26913         /* Not specified by any standard per-se, however it breaks too
26914          * many applications when removed.  It is unfortunate since
26915 @@ -449,7 +489,7 @@ int inet_bind(struct socket *sock, struc
26916         err = -EADDRNOTAVAIL;
26917         if (!sysctl_ip_nonlocal_bind &&
26918             !inet->freebind &&
26919 -           addr->sin_addr.s_addr != INADDR_ANY &&
26920 +           s_addr != INADDR_ANY &&
26921             chk_addr_ret != RTN_LOCAL &&
26922             chk_addr_ret != RTN_MULTICAST &&
26923             chk_addr_ret != RTN_BROADCAST)
26924 @@ -474,7 +514,8 @@ int inet_bind(struct socket *sock, struc
26925         if (sk->sk_state != TCP_CLOSE || inet->num)
26926                 goto out_release_sock;
26927  
26928 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26929 +       inet->rcv_saddr = inet->saddr = s_addr1;
26930 +       inet->rcv_saddr2 = s_addr2;
26931         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26932                 inet->saddr = 0;  /* Use device */
26933  
26934 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/devinet.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/devinet.c
26935 --- linux-2.6.22.10/net/ipv4/devinet.c  2007-10-30 01:57:15 +0100
26936 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/devinet.c        2007-10-01 15:25:35 +0200
26937 @@ -56,6 +56,7 @@
26938  #include <linux/sysctl.h>
26939  #endif
26940  #include <linux/kmod.h>
26941 +#include <linux/vs_context.h>
26942  
26943  #include <net/arp.h>
26944  #include <net/ip.h>
26945 @@ -676,6 +677,9 @@ int devinet_ioctl(unsigned int cmd, void
26946                 *colon = ':';
26947  
26948         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26949 +               struct nx_info *nxi = current->nx_info;
26950 +               int hide_netif = vx_flags(VXF_HIDE_NETIF, 0);
26951 +
26952                 if (tryaddrmatch) {
26953                         /* Matthias Andree */
26954                         /* compare label and address (4.4BSD style) */
26955 @@ -684,6 +688,8 @@ int devinet_ioctl(unsigned int cmd, void
26956                            This is checked above. */
26957                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26958                              ifap = &ifa->ifa_next) {
26959 +                               if (hide_netif && !ifa_in_nx_info(ifa, nxi))
26960 +                                       continue;
26961                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26962                                     sin_orig.sin_addr.s_addr ==
26963                                                         ifa->ifa_address) {
26964 @@ -696,9 +702,12 @@ int devinet_ioctl(unsigned int cmd, void
26965                    comparing just the label */
26966                 if (!ifa) {
26967                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26968 -                            ifap = &ifa->ifa_next)
26969 +                            ifap = &ifa->ifa_next) {
26970 +                               if (hide_netif && !ifa_in_nx_info(ifa, nxi))
26971 +                                       continue;
26972                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26973                                         break;
26974 +                       }
26975                 }
26976         }
26977  
26978 @@ -849,6 +858,9 @@ static int inet_gifconf(struct net_devic
26979                 goto out;
26980  
26981         for (; ifa; ifa = ifa->ifa_next) {
26982 +               if (vx_flags(VXF_HIDE_NETIF, 0) &&
26983 +                       !ifa_in_nx_info(ifa, current->nx_info))
26984 +                       continue;
26985                 if (!buf) {
26986                         done += sizeof(ifr);
26987                         continue;
26988 @@ -1179,6 +1191,7 @@ static int inet_dump_ifaddr(struct sk_bu
26989         struct net_device *dev;
26990         struct in_device *in_dev;
26991         struct in_ifaddr *ifa;
26992 +       struct sock *sk = skb->sk;
26993         int s_ip_idx, s_idx = cb->args[0];
26994  
26995         s_ip_idx = ip_idx = cb->args[1];
26996 @@ -1193,6 +1206,9 @@ static int inet_dump_ifaddr(struct sk_bu
26997  
26998                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26999                      ifa = ifa->ifa_next, ip_idx++) {
27000 +                       if (sk && vx_info_flags(sk->sk_vx_info, VXF_HIDE_NETIF, 0) &&
27001 +                               !ifa_in_nx_info(ifa, sk->sk_nx_info))
27002 +                               continue;
27003                         if (ip_idx < s_ip_idx)
27004                                 continue;
27005                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
27006 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/fib_hash.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/fib_hash.c
27007 --- linux-2.6.22.10/net/ipv4/fib_hash.c 2007-07-09 13:20:05 +0200
27008 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/fib_hash.c       2007-06-15 02:37:04 +0200
27009 @@ -34,6 +34,7 @@
27010  #include <linux/skbuff.h>
27011  #include <linux/netlink.h>
27012  #include <linux/init.h>
27013 +#include <linux/vs_context.h>
27014  
27015  #include <net/ip.h>
27016  #include <net/protocol.h>
27017 @@ -982,6 +983,8 @@ static unsigned fib_flag_trans(int type,
27018         return flags;
27019  }
27020  
27021 +extern int dev_in_nx_info(struct net_device *, struct nx_info *);
27022 +
27023  /*
27024   *     This outputs /proc/net/route.
27025   *
27026 @@ -1012,7 +1015,8 @@ static int fib_seq_show(struct seq_file 
27027         prefix  = f->fn_key;
27028         mask    = FZ_MASK(iter->zone);
27029         flags   = fib_flag_trans(fa->fa_type, mask, fi);
27030 -       if (fi)
27031 +       if (fi && (!vx_flags(VXF_HIDE_NETIF, 0) ||
27032 +               dev_in_nx_info(fi->fib_dev, current->nx_info)))
27033                 snprintf(bf, sizeof(bf),
27034                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
27035                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
27036 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/inet_connection_sock.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/inet_connection_sock.c
27037 --- linux-2.6.22.10/net/ipv4/inet_connection_sock.c     2007-07-09 13:20:05 +0200
27038 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/inet_connection_sock.c   2007-06-15 02:37:04 +0200
27039 @@ -37,7 +37,6 @@ int sysctl_local_port_range[2] = { 32768
27040  int inet_csk_bind_conflict(const struct sock *sk,
27041                            const struct inet_bind_bucket *tb)
27042  {
27043 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
27044         struct sock *sk2;
27045         struct hlist_node *node;
27046         int reuse = sk->sk_reuse;
27047 @@ -50,9 +49,8 @@ int inet_csk_bind_conflict(const struct 
27048                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
27049                         if (!reuse || !sk2->sk_reuse ||
27050                             sk2->sk_state == TCP_LISTEN) {
27051 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27052 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
27053 -                                   sk2_rcv_saddr == sk_rcv_saddr)
27054 +                               if (nx_addr_conflict(sk->sk_nx_info,
27055 +                                       inet_rcv_saddr(sk), sk2))
27056                                         break;
27057                         }
27058                 }
27059 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/inet_diag.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/inet_diag.c
27060 --- linux-2.6.22.10/net/ipv4/inet_diag.c        2007-10-30 01:57:15 +0100
27061 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/inet_diag.c      2007-10-01 15:25:35 +0200
27062 @@ -697,6 +697,8 @@ static int inet_diag_dump(struct sk_buff
27063                         sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
27064                                 struct inet_sock *inet = inet_sk(sk);
27065  
27066 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27067 +                                       continue;
27068                                 if (num < s_num) {
27069                                         num++;
27070                                         continue;
27071 @@ -757,6 +759,8 @@ skip_listen_ht:
27072                 sk_for_each(sk, node, &head->chain) {
27073                         struct inet_sock *inet = inet_sk(sk);
27074  
27075 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27076 +                               continue;
27077                         if (num < s_num)
27078                                 goto next_normal;
27079                         if (!(r->idiag_states & (1 << sk->sk_state)))
27080 @@ -781,6 +785,8 @@ next_normal:
27081                         inet_twsk_for_each(tw, node,
27082                                     &head->twchain) {
27083  
27084 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27085 +                                       continue;
27086                                 if (num < s_num)
27087                                         goto next_dying;
27088                                 if (r->id.idiag_sport != tw->tw_sport &&
27089 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/inet_hashtables.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/inet_hashtables.c
27090 --- linux-2.6.22.10/net/ipv4/inet_hashtables.c  2007-05-02 19:25:40 +0200
27091 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/inet_hashtables.c        2007-06-15 02:37:04 +0200
27092 @@ -140,11 +140,10 @@ static struct sock *inet_lookup_listener
27093                         const __be32 rcv_saddr = inet->rcv_saddr;
27094                         int score = sk->sk_family == PF_INET ? 1 : 0;
27095  
27096 -                       if (rcv_saddr) {
27097 -                               if (rcv_saddr != daddr)
27098 -                                       continue;
27099 +                       if (inet_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
27100                                 score += 2;
27101 -                       }
27102 +                       else
27103 +                               continue;
27104                         if (sk->sk_bound_dev_if) {
27105                                 if (sk->sk_bound_dev_if != dif)
27106                                         continue;
27107 @@ -175,7 +174,7 @@ struct sock *__inet_lookup_listener(stru
27108                 const struct inet_sock *inet = inet_sk((sk = __sk_head(head)));
27109  
27110                 if (inet->num == hnum && !sk->sk_node.next &&
27111 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
27112 +                   inet_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
27113                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
27114                     !sk->sk_bound_dev_if)
27115                         goto sherry_cache;
27116 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/raw.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/raw.c
27117 --- linux-2.6.22.10/net/ipv4/raw.c      2007-07-09 13:20:06 +0200
27118 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/raw.c    2007-06-15 02:37:04 +0200
27119 @@ -101,6 +101,27 @@ static void raw_v4_unhash(struct sock *s
27120         write_unlock_bh(&raw_v4_lock);
27121  }
27122  
27123 +
27124 +/*
27125 + *     Check if a given address matches for a socket
27126 + *
27127 + *     nxi:            the socket's nx_info if any
27128 + *     addr:           to be verified address
27129 + *     saddr/baddr:    socket addresses
27130 + */
27131 +static inline int raw_addr_match (
27132 +       struct nx_info *nxi,
27133 +       uint32_t addr,
27134 +       uint32_t saddr,
27135 +       uint32_t baddr)
27136 +{
27137 +       if (addr && (saddr == addr || baddr == addr))
27138 +               return 1;
27139 +       if (!saddr)
27140 +               return addr_in_nx_info(nxi, addr);
27141 +       return 0;
27142 +}
27143 +
27144  struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
27145                              __be32 raddr, __be32 laddr,
27146                              int dif)
27147 @@ -112,7 +133,8 @@ struct sock *__raw_v4_lookup(struct sock
27148  
27149                 if (inet->num == num                                    &&
27150                     !(inet->daddr && inet->daddr != raddr)              &&
27151 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27152 +                   raw_addr_match(sk->sk_nx_info, laddr,
27153 +                       inet->rcv_saddr, inet->rcv_saddr2)              &&
27154                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27155                         goto found; /* gotcha */
27156         }
27157 @@ -314,6 +336,11 @@ static int raw_send_hdrinc(struct sock *
27158                 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
27159         }
27160  
27161 +       err = -EPERM;
27162 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW)
27163 +               && (!addr_in_nx_info(sk->sk_nx_info, iph->saddr)))
27164 +               goto error_free;
27165 +
27166         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27167                       dst_output);
27168         if (err > 0)
27169 @@ -325,6 +352,7 @@ out:
27170  
27171  error_fault:
27172         err = -EFAULT;
27173 +error_free:
27174         kfree_skb(skb);
27175  error:
27176         IP_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
27177 @@ -491,6 +519,12 @@ static int raw_sendmsg(struct kiocb *ioc
27178                 }
27179  
27180                 security_sk_classify_flow(sk, &fl);
27181 +               if (sk->sk_nx_info) {
27182 +                       err = ip_find_src(sk->sk_nx_info, &rt, &fl);
27183 +
27184 +                       if (err)
27185 +                               goto done;
27186 +               }
27187                 err = ip_route_output_flow(&rt, &fl, sk, 1);
27188         }
27189         if (err)
27190 @@ -795,7 +829,8 @@ static struct sock *raw_get_first(struct
27191                 struct hlist_node *node;
27192  
27193                 sk_for_each(sk, node, &raw_v4_htable[state->bucket])
27194 -                       if (sk->sk_family == PF_INET)
27195 +                       if (sk->sk_family == PF_INET &&
27196 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27197                                 goto found;
27198         }
27199         sk = NULL;
27200 @@ -811,7 +846,8 @@ static struct sock *raw_get_next(struct 
27201                 sk = sk_next(sk);
27202  try_again:
27203                 ;
27204 -       } while (sk && sk->sk_family != PF_INET);
27205 +       } while (sk && (sk->sk_family != PF_INET ||
27206 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27207  
27208         if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
27209                 sk = sk_head(&raw_v4_htable[state->bucket]);
27210 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/tcp.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/tcp.c
27211 --- linux-2.6.22.10/net/ipv4/tcp.c      2007-10-30 01:57:15 +0100
27212 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/tcp.c    2007-09-05 03:05:54 +0200
27213 @@ -258,6 +258,7 @@
27214  #include <linux/cache.h>
27215  #include <linux/err.h>
27216  #include <linux/crypto.h>
27217 +#include <linux/in.h>
27218  
27219  #include <net/icmp.h>
27220  #include <net/tcp.h>
27221 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/tcp_ipv4.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/tcp_ipv4.c
27222 --- linux-2.6.22.10/net/ipv4/tcp_ipv4.c 2007-10-30 01:57:15 +0100
27223 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/tcp_ipv4.c       2007-09-05 03:05:54 +0200
27224 @@ -1975,6 +1975,12 @@ static void *listening_get_next(struct s
27225                 req = req->dl_next;
27226                 while (1) {
27227                         while (req) {
27228 +                               vxdprintk(VXD_CBIT(net, 6),
27229 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27230 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27231 +                               if (req->sk &&
27232 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27233 +                                       continue;
27234                                 if (req->rsk_ops->family == st->family) {
27235                                         cur = req;
27236                                         goto out;
27237 @@ -1999,6 +2005,10 @@ get_req:
27238         }
27239  get_sk:
27240         sk_for_each_from(sk, node) {
27241 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27242 +                       sk, sk->sk_nid, nx_current_nid());
27243 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27244 +                       continue;
27245                 if (sk->sk_family == st->family) {
27246                         cur = sk;
27247                         goto out;
27248 @@ -2050,18 +2060,26 @@ static void *established_get_first(struc
27249  
27250                 read_lock(&tcp_hashinfo.ehash[st->bucket].lock);
27251                 sk_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27252 -                       if (sk->sk_family != st->family) {
27253 +                       vxdprintk(VXD_CBIT(net, 6),
27254 +                               "sk,egf: %p [#%d] (from %d)",
27255 +                               sk, sk->sk_nid, nx_current_nid());
27256 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27257 +                               continue;
27258 +                       if (sk->sk_family != st->family)
27259                                 continue;
27260 -                       }
27261                         rc = sk;
27262                         goto out;
27263                 }
27264                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27265                 inet_twsk_for_each(tw, node,
27266                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27267 -                       if (tw->tw_family != st->family) {
27268 +                       vxdprintk(VXD_CBIT(net, 6),
27269 +                               "tw: %p [#%d] (from %d)",
27270 +                               tw, tw->tw_nid, nx_current_nid());
27271 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27272 +                               continue;
27273 +                       if (tw->tw_family != st->family)
27274                                 continue;
27275 -                       }
27276                         rc = tw;
27277                         goto out;
27278                 }
27279 @@ -2085,7 +2103,8 @@ static void *established_get_next(struct
27280                 tw = cur;
27281                 tw = tw_next(tw);
27282  get_tw:
27283 -               while (tw && tw->tw_family != st->family) {
27284 +               while (tw && (tw->tw_family != st->family ||
27285 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27286                         tw = tw_next(tw);
27287                 }
27288                 if (tw) {
27289 @@ -2109,6 +2128,11 @@ get_tw:
27290                 sk = sk_next(sk);
27291  
27292         sk_for_each_from(sk, node) {
27293 +               vxdprintk(VXD_CBIT(net, 6),
27294 +                       "sk,egn: %p [#%d] (from %d)",
27295 +                       sk, sk->sk_nid, nx_current_nid());
27296 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27297 +                       continue;
27298                 if (sk->sk_family == st->family)
27299                         goto found;
27300         }
27301 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/tcp_minisocks.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/tcp_minisocks.c
27302 --- linux-2.6.22.10/net/ipv4/tcp_minisocks.c    2007-07-09 13:20:06 +0200
27303 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/tcp_minisocks.c  2007-06-15 02:37:04 +0200
27304 @@ -28,6 +28,10 @@
27305  #include <net/inet_common.h>
27306  #include <net/xfrm.h>
27307  
27308 +#include <linux/vs_limit.h>
27309 +#include <linux/vs_socket.h>
27310 +#include <linux/vs_context.h>
27311 +
27312  #ifdef CONFIG_SYSCTL
27313  #define SYNC_INIT 0 /* let the user enable it */
27314  #else
27315 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
27316                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27317                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27318  
27319 +               tw->tw_xid              = sk->sk_xid;
27320 +               tw->tw_vx_info          = NULL;
27321 +               tw->tw_nid              = sk->sk_nid;
27322 +               tw->tw_nx_info          = NULL;
27323 +
27324  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27325                 if (tw->tw_family == PF_INET6) {
27326                         struct ipv6_pinfo *np = inet6_sk(sk);
27327 diff -NurpP --minimal linux-2.6.22.10/net/ipv4/udp.c linux-2.6.22.10-vs2.2.0.5/net/ipv4/udp.c
27328 --- linux-2.6.22.10/net/ipv4/udp.c      2007-07-09 13:20:06 +0200
27329 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv4/udp.c    2007-06-17 06:02:02 +0200
27330 @@ -221,11 +221,8 @@ int udp_get_port(struct sock *sk, unsign
27331  
27332  int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27333  {
27334 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27335 -
27336         return  ( !ipv6_only_sock(sk2)  &&
27337 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27338 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
27339 +                  nx_addr_conflict(sk1->sk_nx_info, inet_rcv_saddr(sk1), sk2));
27340  }
27341  
27342  static inline int udp_v4_get_port(struct sock *sk, unsigned short snum)
27343 @@ -246,15 +243,22 @@ static struct sock *__udp4_lib_lookup(__
27344         int badness = -1;
27345  
27346         read_lock(&udp_hash_lock);
27347 +
27348         sk_for_each(sk, node, &udptable[hnum & (UDP_HTABLE_SIZE - 1)]) {
27349                 struct inet_sock *inet = inet_sk(sk);
27350  
27351                 if (sk->sk_hash == hnum && !ipv6_only_sock(sk)) {
27352                         int score = (sk->sk_family == PF_INET ? 1 : 0);
27353 +
27354                         if (inet->rcv_saddr) {
27355                                 if (inet->rcv_saddr != daddr)
27356                                         continue;
27357                                 score+=2;
27358 +                       } else if (sk->sk_nx_info) {
27359 +                               if (addr_in_nx_info(sk->sk_nx_info, daddr))
27360 +                                       score+=2;
27361 +                               else
27362 +                                       continue;
27363                         }
27364                         if (inet->daddr) {
27365                                 if (inet->daddr != saddr)
27366 @@ -280,6 +284,7 @@ static struct sock *__udp4_lib_lookup(__
27367                         }
27368                 }
27369         }
27370 +
27371         if (result)
27372                 sock_hold(result);
27373         read_unlock(&udp_hash_lock);
27374 @@ -301,7 +306,8 @@ static inline struct sock *udp_v4_mcast_
27375                 if (s->sk_hash != hnum                                  ||
27376                     (inet->daddr && inet->daddr != rmt_addr)            ||
27377                     (inet->dport != rmt_port && inet->dport)            ||
27378 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27379 +                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr &&
27380 +                    inet->rcv_saddr2 && inet->rcv_saddr2 != loc_addr)  ||
27381                     ipv6_only_sock(s)                                   ||
27382                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27383                         continue;
27384 @@ -631,7 +637,20 @@ int udp_sendmsg(struct kiocb *iocb, stru
27385                                     .uli_u = { .ports =
27386                                                { .sport = inet->sport,
27387                                                  .dport = dport } } };
27388 +               struct nx_info *nxi = sk->sk_nx_info;
27389 +
27390                 security_sk_classify_flow(sk, &fl);
27391 +               if (nxi) {
27392 +                       err = ip_find_src(nxi, &rt, &fl);
27393 +                       if (err)
27394 +                               goto out;
27395 +                       if (daddr == IPI_LOOPBACK && !nx_check(0, VS_ADMIN))
27396 +                               daddr = fl.fl4_dst = nxi->ipv4[0];
27397 +#ifdef CONFIG_VSERVER_REMAP_SADDR
27398 +                       if (saddr == IPI_LOOPBACK && !nx_check(0, VS_ADMIN))
27399 +                               saddr = fl.fl4_src = nxi->ipv4[0];
27400 +#endif
27401 +               }
27402                 err = ip_route_output_flow(&rt, &fl, sk, 1);
27403                 if (err) {
27404                         if (err == -ENETUNREACH)
27405 @@ -1551,7 +1570,8 @@ static struct sock *udp_get_first(struct
27406         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
27407                 struct hlist_node *node;
27408                 sk_for_each(sk, node, state->hashtable + state->bucket) {
27409 -                       if (sk->sk_family == state->family)
27410 +                       if (sk->sk_family == state->family &&
27411 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27412                                 goto found;
27413                 }
27414         }
27415 @@ -1568,7 +1588,8 @@ static struct sock *udp_get_next(struct 
27416                 sk = sk_next(sk);
27417  try_again:
27418                 ;
27419 -       } while (sk && sk->sk_family != state->family);
27420 +       } while (sk && (sk->sk_family != state->family ||
27421 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27422  
27423         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
27424                 sk = sk_head(state->hashtable + state->bucket);
27425 diff -NurpP --minimal linux-2.6.22.10/net/ipv6/addrconf.c linux-2.6.22.10-vs2.2.0.5/net/ipv6/addrconf.c
27426 --- linux-2.6.22.10/net/ipv6/addrconf.c 2007-10-30 01:57:15 +0100
27427 +++ linux-2.6.22.10-vs2.2.0.5/net/ipv6/addrconf.c       2007-10-01 15:25:35 +0200
27428 @@ -2772,7 +2772,10 @@ static void if6_seq_stop(struct seq_file
27429  static int if6_seq_show(struct seq_file *seq, void *v)
27430  {
27431         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27432 -       seq_printf(seq,
27433 +
27434 +       /* no ipv6 inside a vserver for now */
27435 +       if (nx_check(0, VS_ADMIN|VS_WATCH))
27436 +               seq_printf(seq,
27437                    NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
27438                    NIP6(ifp->addr),
27439                    ifp->idev->dev->ifindex,
27440 @@ -3255,6 +3258,10 @@ static int inet6_dump_addr(struct sk_buf
27441         struct ifmcaddr6 *ifmca;
27442         struct ifacaddr6 *ifaca;
27443  
27444 +       /* no ipv6 inside a vserver for now */
27445 +       if (skb->sk && skb->sk->sk_vx_info)
27446 +               return skb->len;
27447 +
27448         s_idx = cb->args[0];
27449         s_ip_idx = ip_idx = cb->args[1];
27450  
27451 @@ -3578,6 +3585,10 @@ static int inet6_dump_ifinfo(struct sk_b
27452         struct net_device *dev;
27453         struct inet6_dev *idev;
27454  
27455 +       /* no ipv6 inside a vserver for now */
27456 +       if (skb->sk && skb->sk->sk_vx_info)
27457 +               return skb->len;
27458 +
27459         read_lock(&dev_base_lock);
27460         idx = 0;
27461         for_each_netdev(dev) {
27462 diff -NurpP --minimal linux-2.6.22.10/net/netlink/af_netlink.c linux-2.6.22.10-vs2.2.0.5/net/netlink/af_netlink.c
27463 --- linux-2.6.22.10/net/netlink/af_netlink.c    2007-07-09 13:20:07 +0200
27464 +++ linux-2.6.22.10-vs2.2.0.5/net/netlink/af_netlink.c  2007-06-15 05:43:32 +0200
27465 @@ -56,6 +56,9 @@
27466  #include <linux/audit.h>
27467  #include <linux/selinux.h>
27468  #include <linux/mutex.h>
27469 +#include <linux/vs_context.h>
27470 +#include <linux/vs_network.h>
27471 +#include <linux/vs_limit.h>
27472  
27473  #include <net/sock.h>
27474  #include <net/scm.h>
27475 diff -NurpP --minimal linux-2.6.22.10/net/socket.c linux-2.6.22.10-vs2.2.0.5/net/socket.c
27476 --- linux-2.6.22.10/net/socket.c        2007-10-30 01:57:15 +0100
27477 +++ linux-2.6.22.10-vs2.2.0.5/net/socket.c      2007-09-05 03:05:54 +0200
27478 @@ -92,6 +92,8 @@
27479  
27480  #include <net/sock.h>
27481  #include <linux/netfilter.h>
27482 +#include <linux/vs_base.h>
27483 +#include <linux/vs_socket.h>
27484  
27485  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27486  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27487 @@ -543,7 +545,7 @@ static inline int __sock_sendmsg(struct 
27488                                  struct msghdr *msg, size_t size)
27489  {
27490         struct sock_iocb *si = kiocb_to_siocb(iocb);
27491 -       int err;
27492 +       int err, len;
27493  
27494         si->sock = sock;
27495         si->scm = NULL;
27496 @@ -554,7 +556,22 @@ static inline int __sock_sendmsg(struct 
27497         if (err)
27498                 return err;
27499  
27500 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27501 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27502 +       if (sock->sk) {
27503 +               if (len == size)
27504 +                       vx_sock_send(sock->sk, size);
27505 +               else
27506 +                       vx_sock_fail(sock->sk, size);
27507 +       }
27508 +       vxdprintk(VXD_CBIT(net, 7),
27509 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27510 +               sock, sock->sk,
27511 +               (sock->sk)?sock->sk->sk_nx_info:0,
27512 +               (sock->sk)?sock->sk->sk_vx_info:0,
27513 +               (sock->sk)?sock->sk->sk_xid:0,
27514 +               (sock->sk)?sock->sk->sk_nid:0,
27515 +               (unsigned int)size, len);
27516 +       return len;
27517  }
27518  
27519  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27520 @@ -623,7 +640,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27521  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27522                                  struct msghdr *msg, size_t size, int flags)
27523  {
27524 -       int err;
27525 +       int err, len;
27526         struct sock_iocb *si = kiocb_to_siocb(iocb);
27527  
27528         si->sock = sock;
27529 @@ -636,7 +653,18 @@ static inline int __sock_recvmsg(struct 
27530         if (err)
27531                 return err;
27532  
27533 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27534 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27535 +       if ((len >= 0) && sock->sk)
27536 +               vx_sock_recv(sock->sk, len);
27537 +       vxdprintk(VXD_CBIT(net, 7),
27538 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27539 +               sock, sock->sk,
27540 +               (sock->sk)?sock->sk->sk_nx_info:0,
27541 +               (sock->sk)?sock->sk->sk_vx_info:0,
27542 +               (sock->sk)?sock->sk->sk_xid:0,
27543 +               (sock->sk)?sock->sk->sk_nid:0,
27544 +               (unsigned int)size, len);
27545 +       return len;
27546  }
27547  
27548  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27549 @@ -1090,6 +1118,10 @@ static int __sock_create(int family, int
27550         if (type < 0 || type >= SOCK_MAX)
27551                 return -EINVAL;
27552  
27553 +       /* disable IPv6 inside vservers for now */
27554 +       if (family == PF_INET6 && !nx_check(0, VS_ADMIN))
27555 +               return -EAFNOSUPPORT;
27556 +
27557         /* Compatibility.
27558  
27559            This uglymoron is moved from INET layer to here to avoid
27560 @@ -1207,6 +1239,7 @@ asmlinkage long sys_socket(int family, i
27561         if (retval < 0)
27562                 goto out;
27563  
27564 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27565         retval = sock_map_fd(sock);
27566         if (retval < 0)
27567                 goto out_release;
27568 @@ -1239,10 +1272,12 @@ asmlinkage long sys_socketpair(int famil
27569         err = sock_create(family, type, protocol, &sock1);
27570         if (err < 0)
27571                 goto out;
27572 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27573  
27574         err = sock_create(family, type, protocol, &sock2);
27575         if (err < 0)
27576                 goto out_release_1;
27577 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27578  
27579         err = sock1->ops->socketpair(sock1, sock2);
27580         if (err < 0)
27581 diff -NurpP --minimal linux-2.6.22.10/net/sunrpc/auth.c linux-2.6.22.10-vs2.2.0.5/net/sunrpc/auth.c
27582 --- linux-2.6.22.10/net/sunrpc/auth.c   2007-05-02 19:25:48 +0200
27583 +++ linux-2.6.22.10-vs2.2.0.5/net/sunrpc/auth.c 2007-06-15 02:37:04 +0200
27584 @@ -13,6 +13,7 @@
27585  #include <linux/errno.h>
27586  #include <linux/sunrpc/clnt.h>
27587  #include <linux/spinlock.h>
27588 +#include <linux/vs_tag.h>
27589  
27590  #ifdef RPC_DEBUG
27591  # define RPCDBG_FACILITY       RPCDBG_AUTH
27592 @@ -263,6 +264,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27593         struct auth_cred acred = {
27594                 .uid = current->fsuid,
27595                 .gid = current->fsgid,
27596 +               .tag = dx_current_tag(),
27597                 .group_info = current->group_info,
27598         };
27599         struct rpc_cred *ret;
27600 @@ -282,6 +284,7 @@ rpcauth_bindcred(struct rpc_task *task)
27601         struct auth_cred acred = {
27602                 .uid = current->fsuid,
27603                 .gid = current->fsgid,
27604 +               .tag = dx_current_tag(),
27605                 .group_info = current->group_info,
27606         };
27607         struct rpc_cred *ret;
27608 diff -NurpP --minimal linux-2.6.22.10/net/sunrpc/auth_unix.c linux-2.6.22.10-vs2.2.0.5/net/sunrpc/auth_unix.c
27609 --- linux-2.6.22.10/net/sunrpc/auth_unix.c      2007-05-02 19:25:48 +0200
27610 +++ linux-2.6.22.10-vs2.2.0.5/net/sunrpc/auth_unix.c    2007-06-15 02:37:04 +0200
27611 @@ -11,12 +11,14 @@
27612  #include <linux/module.h>
27613  #include <linux/sunrpc/clnt.h>
27614  #include <linux/sunrpc/auth.h>
27615 +#include <linux/vs_tag.h>
27616  
27617  #define NFS_NGROUPS    16
27618  
27619  struct unx_cred {
27620         struct rpc_cred         uc_base;
27621         gid_t                   uc_gid;
27622 +       tag_t                   uc_tag;
27623         gid_t                   uc_gids[NFS_NGROUPS];
27624  };
27625  #define uc_uid                 uc_base.cr_uid
27626 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
27627         if (flags & RPCAUTH_LOOKUP_ROOTCREDS) {
27628                 cred->uc_uid = 0;
27629                 cred->uc_gid = 0;
27630 +               cred->uc_tag = dx_current_tag();
27631                 cred->uc_gids[0] = NOGROUP;
27632         } else {
27633                 int groups = acred->group_info->ngroups;
27634 @@ -87,6 +90,7 @@ unx_create_cred(struct rpc_auth *auth, s
27635  
27636                 cred->uc_uid = acred->uid;
27637                 cred->uc_gid = acred->gid;
27638 +               cred->uc_tag = acred->tag;
27639                 for (i = 0; i < groups; i++)
27640                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27641                 if (i < NFS_NGROUPS)
27642 @@ -118,7 +122,8 @@ unx_match(struct auth_cred *acred, struc
27643                 int groups;
27644  
27645                 if (cred->uc_uid != acred->uid
27646 -                || cred->uc_gid != acred->gid)
27647 +                || cred->uc_gid != acred->gid
27648 +                || cred->uc_tag != acred->tag)
27649                         return 0;
27650  
27651                 groups = acred->group_info->ngroups;
27652 @@ -144,7 +149,7 @@ unx_marshal(struct rpc_task *task, __be3
27653         struct rpc_clnt *clnt = task->tk_client;
27654         struct unx_cred *cred = (struct unx_cred *) task->tk_msg.rpc_cred;
27655         __be32          *base, *hold;
27656 -       int             i;
27657 +       int             i, tag;
27658  
27659         *p++ = htonl(RPC_AUTH_UNIX);
27660         base = p++;
27661 @@ -154,9 +159,12 @@ unx_marshal(struct rpc_task *task, __be3
27662          * Copy the UTS nodename captured when the client was created.
27663          */
27664         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27665 +       tag = task->tk_client->cl_tag;
27666  
27667 -       *p++ = htonl((u32) cred->uc_uid);
27668 -       *p++ = htonl((u32) cred->uc_gid);
27669 +       *p++ = htonl((u32) TAGINO_UID(tag,
27670 +               cred->uc_uid, cred->uc_tag));
27671 +       *p++ = htonl((u32) TAGINO_GID(tag,
27672 +               cred->uc_gid, cred->uc_tag));
27673         hold = p++;
27674         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27675                 *p++ = htonl((u32) cred->uc_gids[i]);
27676 diff -NurpP --minimal linux-2.6.22.10/net/sunrpc/clnt.c linux-2.6.22.10-vs2.2.0.5/net/sunrpc/clnt.c
27677 --- linux-2.6.22.10/net/sunrpc/clnt.c   2007-07-09 13:20:13 +0200
27678 +++ linux-2.6.22.10-vs2.2.0.5/net/sunrpc/clnt.c 2007-06-15 02:37:04 +0200
27679 @@ -30,6 +30,7 @@
27680  #include <linux/smp_lock.h>
27681  #include <linux/utsname.h>
27682  #include <linux/workqueue.h>
27683 +#include <linux/vs_cvirt.h>
27684  
27685  #include <linux/sunrpc/clnt.h>
27686  #include <linux/sunrpc/rpc_pipe_fs.h>
27687 @@ -249,7 +250,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27688                 clnt->cl_oneshot = 1;
27689         if (args->flags & RPC_CLNT_CREATE_DISCRTRY)
27690                 clnt->cl_discrtry = 1;
27691 -
27692 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27693 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27694 +               clnt->cl_tag = 1; */
27695         return clnt;
27696  }
27697  EXPORT_SYMBOL_GPL(rpc_create);
27698 diff -NurpP --minimal linux-2.6.22.10/net/unix/af_unix.c linux-2.6.22.10-vs2.2.0.5/net/unix/af_unix.c
27699 --- linux-2.6.22.10/net/unix/af_unix.c  2007-07-09 13:20:13 +0200
27700 +++ linux-2.6.22.10-vs2.2.0.5/net/unix/af_unix.c        2007-06-17 05:54:20 +0200
27701 @@ -115,6 +115,8 @@
27702  #include <linux/mount.h>
27703  #include <net/checksum.h>
27704  #include <linux/security.h>
27705 +#include <linux/vs_context.h>
27706 +#include <linux/vs_limit.h>
27707  
27708  int sysctl_unix_max_dgram_qlen __read_mostly = 10;
27709  
27710 @@ -252,6 +254,8 @@ static struct sock *__unix_find_socket_b
27711         sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
27712                 struct unix_sock *u = unix_sk(s);
27713  
27714 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27715 +                       continue;
27716                 if (u->addr->len == len &&
27717                     !memcmp(u->addr->name, sunname, len))
27718                         goto found;
27719 @@ -807,7 +811,7 @@ static int unix_bind(struct socket *sock
27720                  */
27721                 mode = S_IFSOCK |
27722                        (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
27723 -               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
27724 +               err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0, NULL);
27725                 if (err)
27726                         goto out_mknod_dput;
27727                 mutex_unlock(&nd.dentry->d_inode->i_mutex);
27728 diff -NurpP --minimal linux-2.6.22.10/net/x25/af_x25.c linux-2.6.22.10-vs2.2.0.5/net/x25/af_x25.c
27729 --- linux-2.6.22.10/net/x25/af_x25.c    2007-07-09 13:20:13 +0200
27730 +++ linux-2.6.22.10-vs2.2.0.5/net/x25/af_x25.c  2007-06-15 02:37:04 +0200
27731 @@ -500,7 +500,10 @@ static int x25_create(struct socket *soc
27732  
27733         x25 = x25_sk(sk);
27734  
27735 -       sock_init_data(sock, sk);
27736 +       sk->sk_socket = sock;
27737 +       sk->sk_type = sock->type;
27738 +       sk->sk_sleep = &sock->wait;
27739 +       sock->sk = sk;
27740  
27741         x25_init_timers(sk);
27742  
27743 diff -NurpP --minimal linux-2.6.22.10/security/Kconfig linux-2.6.22.10-vs2.2.0.5/security/Kconfig
27744 --- linux-2.6.22.10/security/Kconfig    2006-11-30 21:19:47 +0100
27745 +++ linux-2.6.22.10-vs2.2.0.5/security/Kconfig  2007-06-15 02:37:04 +0200
27746 @@ -6,6 +6,7 @@ menu "Security options"
27747  
27748  config KEYS
27749         bool "Enable access key retention support"
27750 +       depends on !VSERVER_SECURITY
27751         help
27752           This option provides support for retaining authentication tokens and
27753           access keys in the kernel.
27754 diff -NurpP --minimal linux-2.6.22.10/security/commoncap.c linux-2.6.22.10-vs2.2.0.5/security/commoncap.c
27755 --- linux-2.6.22.10/security/commoncap.c        2007-07-09 13:20:14 +0200
27756 +++ linux-2.6.22.10-vs2.2.0.5/security/commoncap.c      2007-06-15 02:37:04 +0200
27757 @@ -22,10 +22,11 @@
27758  #include <linux/ptrace.h>
27759  #include <linux/xattr.h>
27760  #include <linux/hugetlb.h>
27761 +#include <linux/vs_context.h>
27762  
27763  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
27764  {
27765 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
27766 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
27767         return 0;
27768  }
27769  
27770 @@ -43,7 +44,7 @@ EXPORT_SYMBOL(cap_netlink_recv);
27771  int cap_capable (struct task_struct *tsk, int cap)
27772  {
27773         /* Derived from include/linux/sched.h:capable. */
27774 -       if (cap_raised(tsk->cap_effective, cap))
27775 +       if (vx_cap_raised(tsk->vx_info, tsk->cap_effective, cap))
27776                 return 0;
27777         return -EPERM;
27778  }
27779 @@ -141,7 +142,8 @@ void cap_bprm_apply_creds (struct linux_
27780         /* Derived from fs/exec.c:compute_creds. */
27781         kernel_cap_t new_permitted, working;
27782  
27783 -       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
27784 +       new_permitted = cap_intersect (bprm->cap_permitted,
27785 +                                       vx_current_cap_bset());
27786         working = cap_intersect (bprm->cap_inheritable,
27787                                  current->cap_inheritable);
27788         new_permitted = cap_combine (new_permitted, working);
27789 @@ -310,7 +312,8 @@ void cap_task_reparent_to_init (struct t
27790  
27791  int cap_syslog (int type)
27792  {
27793 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
27794 +       if ((type != 3 && type != 10) &&
27795 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
27796                 return -EPERM;
27797         return 0;
27798  }
27799 diff -NurpP --minimal linux-2.6.22.10/security/dummy.c linux-2.6.22.10-vs2.2.0.5/security/dummy.c
27800 --- linux-2.6.22.10/security/dummy.c    2007-05-02 19:25:51 +0200
27801 +++ linux-2.6.22.10-vs2.2.0.5/security/dummy.c  2007-06-15 02:37:04 +0200
27802 @@ -28,6 +28,7 @@
27803  #include <linux/hugetlb.h>
27804  #include <linux/ptrace.h>
27805  #include <linux/file.h>
27806 +#include <linux/vs_context.h>
27807  
27808  static int dummy_ptrace (struct task_struct *parent, struct task_struct *child)
27809  {
27810 @@ -678,7 +679,7 @@ static int dummy_sem_semop (struct sem_a
27811  
27812  static int dummy_netlink_send (struct sock *sk, struct sk_buff *skb)
27813  {
27814 -       NETLINK_CB(skb).eff_cap = current->cap_effective;
27815 +       cap_t(NETLINK_CB(skb).eff_cap) = vx_mbcap(cap_effective);
27816         return 0;
27817  }
27818  
27819 diff -NurpP --minimal linux-2.6.22.10/security/selinux/hooks.c linux-2.6.22.10-vs2.2.0.5/security/selinux/hooks.c
27820 --- linux-2.6.22.10/security/selinux/hooks.c    2007-10-30 01:57:15 +0100
27821 +++ linux-2.6.22.10-vs2.2.0.5/security/selinux/hooks.c  2007-10-30 01:24:36 +0100
27822 @@ -60,7 +60,6 @@
27823  #include <linux/dccp.h>
27824  #include <linux/quota.h>
27825  #include <linux/un.h>          /* for Unix socket types */
27826 -#include <net/af_unix.h>       /* for Unix socket types */
27827  #include <linux/parser.h>
27828  #include <linux/nfs_mount.h>
27829  #include <net/ipv6.h>
This page took 2.112225 seconds and 3 git commands to generate.