]> git.pld-linux.org Git - packages/kernel.git/blob - linux-2.6-vs.patch
- obsolete
[packages/kernel.git] / linux-2.6-vs.patch
1 diff -NurpP --minimal linux-2.6.10/Documentation/vserver/debug.txt linux-2.6.10-vs1.9.3.17/Documentation/vserver/debug.txt
2 --- linux-2.6.10/Documentation/vserver/debug.txt        1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.10-vs1.9.3.17/Documentation/vserver/debug.txt     2004-12-26 19:40:35.000000000 +0100
4 @@ -0,0 +1,171 @@
5 +
6 +debug_switch:
7 +
8 + 0   1
9 +
10 + 1   2
11 +
12 + 2   4
13 +
14 + 3   8
15 +
16 + 4  16
17 +
18 + 5  32
19 +
20 + 6  64
21 +
22 + 7 128
23 +
24 +
25 +debug_xid:
26 +
27 + 0   1 "alloc_vx_info(%d) = %p\n"
28 +       "dealloc_vx_info(%p)"
29 +       "loc_vx_info(%d) = %p (not available)"
30 +       "loc_vx_info(%d) = %p (found)"
31 +       "loc_vx_info(%d) = %p (new)"
32 +
33 + 1   2 "alloc_vx_info(%d)*"
34 +       "loc_vx_info(%d)*"
35 +       "locate_vx_info(%d)"
36 +
37 + 2   4 "get_vx_info(%p[#%d.%d])"
38 +       "put_vx_info(%p[#%d.%d])"
39 +
40 + 3   8 "set_vx_info(%p[#%d.%d.%d])"
41 +       "clr_vx_info(%p[#%d.%d.%d])"
42 +       "rcu_free_vx_info(%p): uc=%d"
43 +
44 + 4  16 "__hash_vx_info: %p[#%d]"
45 +       "__unhash_vx_info: %p[#%d]"
46 +       "__vx_dynamic_id: [#%d]"
47 +
48 + 5  32 "vx_migrate_task(%p,%p[#%d.%d])"
49 +       "task_get_vx_info(%p)"
50 +
51 + 6  64 "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
52 +
53 + 7 128 "vx_propagate_xid(%p[#%d.%d]): %d"
54 +
55 +
56 +debug_nid:
57 +
58 + 0   1 "alloc_nx_info() = %p"
59 +       "dealloc_nx_info(%p)"
60 +       "loc_nx_info(%d) = %p (not available)"
61 +       "loc_nx_info(%d) = %p (found)"
62 +       "loc_nx_info(%d) = %p (new)"
63 +
64 + 1   2 "alloc_nx_info(%d)*"
65 +       "loc_nx_info(%d)*"
66 +
67 + 2   4 "get_nx_info(%p[#%d.%d])"
68 +       "put_nx_info(%p[#%d.%d])"
69 +
70 + 3   8 "set_nx_info(%p[#%d.%d.%d])"
71 +       "clr_nx_info(%p[#%d.%d.%d])"
72 +       "rcu_free_nx_info(%p): uc=%d"
73 +
74 + 4  16 "__hash_nx_info: %p[#%d]"
75 +       "__unhash_nx_info: %p[#%d]"
76 +       "__nx_dynamic_id: [#%d]"
77 +
78 + 5  32 "nx_migrate_task(%p,%p[#%d.%d])"
79 +       "task_get_nx_info(%p)"
80 +       "create_nx_info()"
81 +
82 + 6  64
83 +
84 + 7 128
85 +
86 +
87 +debug_dlim:
88 +
89 + 0   1 "alloc_dl_info(%p,%d) = %p"
90 +       "dealloc_dl_info(%p)"
91 +       "locate_dl_info(%p,#%d) = %p"
92 +
93 + 1   2 "alloc_dl_info(%p,%d)*"
94 +
95 + 2   4 "get_dl_info(%p[#%d.%d])"
96 +       "put_dl_info(%p[#%d.%d])"
97 +
98 + 3   8 "rcu_free_dl_info(%p)"
99 +       "__hash_dl_info: %p[#%d]"
100 +       "__unhash_dl_info: %p[#%d]"
101 +
102 +
103 + 4  16 "ALLOC (%p,#%d)%c inode (%d)"
104 +       "FREE  (%p,#%d)%c inode"
105 +
106 + 5  32 "ALLOC (%p,#%d)%c %lld bytes (%d)"
107 +       "FREE  (%p,#%d)%c %lld bytes"
108 +
109 + 6  64 "ADJUST: %lld,%lld on %d,%d [mult=%d]"
110 +
111 + 7 128 "ext3_has_free_blocks(%p): free=%u, root=%u"
112 +       "ext3_has_free_blocks(%p): %u<%u+1, %c, %u!=%u r=%d"
113 +
114 +
115 +
116 +debug_cvirt:
117 +
118 +
119 + 0   1
120 +
121 + 1   2
122 +
123 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
124 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
125 +
126 + 3   8
127 +
128 + 4  16
129 +
130 + 5  32
131 +
132 + 6  64
133 +
134 + 7 128
135 +
136 +
137 +
138 +debug_net:
139 +
140 +
141 + 0   1
142 +
143 + 1   2
144 +
145 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
146 +
147 + 3   8 "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
148 +       "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
149 +
150 + 4  16 "ip_route_connect(%p) %p,%p;%lx"
151 +
152 + 5  32 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
153 +
154 + 6  64 "sk: %p [#%d] (from %d)"
155 +       "sk,req: %p [#%d] (from %d)"
156 +       "sk,egf: %p [#%d] (from %d)"
157 +       "sk,egn: %p [#%d] (from %d)"
158 +       "tw: %p [#%d] (from %d)"
159 +
160 + 7 128 "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
161 +       "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
162 +
163 +
164 +
165 +
166 +debug_limit:
167 +
168 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
169 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
170 +
171 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
172 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
173 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
174 +
175 +
176 diff -NurpP --minimal linux-2.6.10/Makefile linux-2.6.10-vs1.9.3.17/Makefile
177 --- linux-2.6.10/Makefile       2004-12-25 01:54:42.000000000 +0100
178 +++ linux-2.6.10-vs1.9.3.17/Makefile    2005-01-06 07:53:34.000000000 +0100
179 @@ -1,7 +1,7 @@
180  VERSION = 2
181  PATCHLEVEL = 6
182  SUBLEVEL = 10
183 -EXTRAVERSION =
184 +EXTRAVERSION = -vs1.9.3.17
185  NAME=Woozy Numbat
186  
187  # *DOCUMENTATION*
188 diff -NurpP --minimal linux-2.6.10/arch/alpha/Kconfig linux-2.6.10-vs1.9.3.17/arch/alpha/Kconfig
189 --- linux-2.6.10/arch/alpha/Kconfig     2004-10-23 05:05:56.000000000 +0200
190 +++ linux-2.6.10-vs1.9.3.17/arch/alpha/Kconfig  2004-12-26 19:40:21.000000000 +0100
191 @@ -594,6 +594,8 @@ source "arch/alpha/oprofile/Kconfig"
192  
193  source "arch/alpha/Kconfig.debug"
194  
195 +source "kernel/vserver/Kconfig"
196 +
197  source "security/Kconfig"
198  
199  source "crypto/Kconfig"
200 diff -NurpP --minimal linux-2.6.10/arch/alpha/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/alpha/kernel/ptrace.c
201 --- linux-2.6.10/arch/alpha/kernel/ptrace.c     2004-12-25 01:54:42.000000000 +0100
202 +++ linux-2.6.10-vs1.9.3.17/arch/alpha/kernel/ptrace.c  2004-12-26 19:40:28.000000000 +0100
203 @@ -288,6 +288,8 @@ do_sys_ptrace(long request, long pid, lo
204         read_unlock(&tasklist_lock);
205         if (!child)
206                 goto out_notsk;
207 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
208 +               goto out;
209  
210         if (request == PTRACE_ATTACH) {
211                 ret = ptrace_attach(child);
212 diff -NurpP --minimal linux-2.6.10/arch/alpha/kernel/systbls.S linux-2.6.10-vs1.9.3.17/arch/alpha/kernel/systbls.S
213 --- linux-2.6.10/arch/alpha/kernel/systbls.S    2004-10-23 05:05:56.000000000 +0200
214 +++ linux-2.6.10-vs1.9.3.17/arch/alpha/kernel/systbls.S 2004-12-26 19:40:23.000000000 +0100
215 @@ -291,7 +291,7 @@ sys_call_table:
216         .quad alpha_ni_syscall                  /* 270 */
217         .quad alpha_ni_syscall
218         .quad alpha_ni_syscall
219 -       .quad alpha_ni_syscall
220 +       .quad sys_vserver                       /* 273 sys_vserver */
221         .quad alpha_ni_syscall
222         .quad alpha_ni_syscall                  /* 275 */
223         .quad alpha_ni_syscall
224 diff -NurpP --minimal linux-2.6.10/arch/arm/Kconfig linux-2.6.10-vs1.9.3.17/arch/arm/Kconfig
225 --- linux-2.6.10/arch/arm/Kconfig       2004-12-25 01:54:42.000000000 +0100
226 +++ linux-2.6.10-vs1.9.3.17/arch/arm/Kconfig    2004-12-26 19:40:21.000000000 +0100
227 @@ -709,6 +709,8 @@ source "drivers/mmc/Kconfig"
228  
229  source "arch/arm/Kconfig.debug"
230  
231 +source "kernel/vserver/Kconfig"
232 +
233  source "security/Kconfig"
234  
235  source "crypto/Kconfig"
236 diff -NurpP --minimal linux-2.6.10/arch/arm/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/arm/kernel/ptrace.c
237 --- linux-2.6.10/arch/arm/kernel/ptrace.c       2004-12-25 01:54:42.000000000 +0100
238 +++ linux-2.6.10-vs1.9.3.17/arch/arm/kernel/ptrace.c    2004-12-26 19:40:28.000000000 +0100
239 @@ -754,6 +754,8 @@ asmlinkage int sys_ptrace(long request, 
240         read_unlock(&tasklist_lock);
241         if (!child)
242                 goto out;
243 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
244 +               goto out_tsk;
245  
246         ret = -EPERM;
247         if (pid == 1)           /* you may not mess with init */
248 diff -NurpP --minimal linux-2.6.10/arch/arm26/Kconfig linux-2.6.10-vs1.9.3.17/arch/arm26/Kconfig
249 --- linux-2.6.10/arch/arm26/Kconfig     2004-10-23 05:05:57.000000000 +0200
250 +++ linux-2.6.10-vs1.9.3.17/arch/arm26/Kconfig  2004-12-26 19:40:21.000000000 +0100
251 @@ -216,6 +216,8 @@ source "drivers/usb/Kconfig"
252  
253  source "arch/arm26/Kconfig.debug"
254  
255 +source "kernel/vserver/Kconfig"
256 +
257  source "security/Kconfig"
258  
259  source "crypto/Kconfig"
260 diff -NurpP --minimal linux-2.6.10/arch/arm26/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/arm26/kernel/ptrace.c
261 --- linux-2.6.10/arch/arm26/kernel/ptrace.c     2004-12-25 01:54:43.000000000 +0100
262 +++ linux-2.6.10-vs1.9.3.17/arch/arm26/kernel/ptrace.c  2004-12-26 19:40:28.000000000 +0100
263 @@ -691,6 +691,8 @@ asmlinkage int sys_ptrace(long request, 
264         read_unlock(&tasklist_lock);
265         if (!child)
266                 goto out;
267 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
268 +               goto out_tsk;
269  
270         ret = -EPERM;
271         if (pid == 1)           /* you may not mess with init */
272 diff -NurpP --minimal linux-2.6.10/arch/cris/Kconfig linux-2.6.10-vs1.9.3.17/arch/cris/Kconfig
273 --- linux-2.6.10/arch/cris/Kconfig      2004-10-23 05:05:57.000000000 +0200
274 +++ linux-2.6.10-vs1.9.3.17/arch/cris/Kconfig   2004-12-26 19:40:21.000000000 +0100
275 @@ -169,6 +169,8 @@ source "drivers/usb/Kconfig"
276  
277  source "arch/cris/Kconfig.debug"
278  
279 +source "kernel/vserver/Kconfig"
280 +
281  source "security/Kconfig"
282  
283  source "crypto/Kconfig"
284 diff -NurpP --minimal linux-2.6.10/arch/h8300/Kconfig linux-2.6.10-vs1.9.3.17/arch/h8300/Kconfig
285 --- linux-2.6.10/arch/h8300/Kconfig     2004-10-23 05:05:57.000000000 +0200
286 +++ linux-2.6.10-vs1.9.3.17/arch/h8300/Kconfig  2004-12-26 19:40:21.000000000 +0100
287 @@ -183,6 +183,8 @@ source "fs/Kconfig"
288  
289  source "arch/h8300/Kconfig.debug"
290  
291 +source "kernel/vserver/Kconfig"
292 +
293  source "security/Kconfig"
294  
295  source "crypto/Kconfig"
296 diff -NurpP --minimal linux-2.6.10/arch/h8300/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/h8300/kernel/ptrace.c
297 --- linux-2.6.10/arch/h8300/kernel/ptrace.c     2004-12-25 01:54:43.000000000 +0100
298 +++ linux-2.6.10-vs1.9.3.17/arch/h8300/kernel/ptrace.c  2004-12-26 19:40:28.000000000 +0100
299 @@ -80,6 +80,8 @@ asmlinkage int sys_ptrace(long request, 
300         read_unlock(&tasklist_lock);
301         if (!child)
302                 goto out;
303 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
304 +               goto out_tsk;
305  
306         ret = -EPERM;
307         if (pid == 1)           /* you may not mess with init */
308 diff -NurpP --minimal linux-2.6.10/arch/i386/Kconfig linux-2.6.10-vs1.9.3.17/arch/i386/Kconfig
309 --- linux-2.6.10/arch/i386/Kconfig      2004-12-25 01:54:43.000000000 +0100
310 +++ linux-2.6.10-vs1.9.3.17/arch/i386/Kconfig   2004-12-26 19:40:36.000000000 +0100
311 @@ -553,6 +553,14 @@ config X86_IO_APIC
312         depends on !SMP && X86_UP_IOAPIC
313         default y
314  
315 +config KERNEL_HZ
316 +       int "Timer Frequency (100-20000)"
317 +       range 100 20000
318 +       default "1000"
319 +       help
320 +         This allows you to specify the frequency at which the
321 +         kernel timer interrupt will occur.
322 +
323  config X86_TSC
324         bool
325         depends on (MWINCHIP3D || MWINCHIP2 || MCRUSOE || MEFFICEON || MCYRIXIII || MK7 || MK6 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || MK8 || MVIAC3_2) && !X86_NUMAQ
326 @@ -720,6 +728,46 @@ config HIGHMEM64G
327  
328  endchoice
329  
330 +choice
331 +       prompt "Memory Split User Space"
332 +       default SPLIT_3GB
333 +       help
334 +         A different Userspace/Kernel split allows you to
335 +         utilize up to alsmost 3GB of RAM without the requirement
336 +         for HIGHMEM. It also increases the available lowmem.
337 +
338 +config SPLIT_3GB
339 +       bool "3.0GB/1.0GB Kernel (Default)"
340 +       help
341 +         This is the default split of 3GB userspace to 1GB kernel
342 +         space, which will result in about 860MB of lowmem.
343 +
344 +config SPLIT_25GB
345 +       bool "2.5GB/1.5GB Kernel"
346 +       help
347 +         This split provides 2.5GB userspace and 1.5GB kernel
348 +         space, which will result in about 1370MB of lowmem.
349 +
350 +config SPLIT_2GB
351 +       bool "2.0GB/2.0GB Kernel"
352 +       help
353 +         This split provides 2GB userspace and 2GB kernel
354 +         space, which will result in about 1880MB of lowmem.
355 +
356 +config SPLIT_15GB
357 +       bool "1.5GB/2.5GB Kernel"
358 +       help
359 +         This split provides 1.5GB userspace and 2.5GB kernel
360 +         space, which will result in about 2390MB of lowmem.
361 +
362 +config SPLIT_1GB
363 +       bool "1.0GB/3.0GB Kernel"
364 +       help
365 +         This split provides 1GB userspace and 3GB kernel
366 +         space, which will result in about 2900MB of lowmem.
367 +
368 +endchoice
369 +
370  config HIGHMEM
371         bool
372         depends on HIGHMEM64G || HIGHMEM4G
373 @@ -1194,6 +1242,8 @@ source "arch/i386/oprofile/Kconfig"
374  
375  source "arch/i386/Kconfig.debug"
376  
377 +source "kernel/vserver/Kconfig"
378 +
379  source "security/Kconfig"
380  
381  source "crypto/Kconfig"
382 diff -NurpP --minimal linux-2.6.10/arch/i386/kernel/apic.c linux-2.6.10-vs1.9.3.17/arch/i386/kernel/apic.c
383 --- linux-2.6.10/arch/i386/kernel/apic.c        2004-12-25 01:54:43.000000000 +0100
384 +++ linux-2.6.10-vs1.9.3.17/arch/i386/kernel/apic.c     2005-01-02 10:57:33.000000000 +0100
385 @@ -877,23 +877,18 @@ static unsigned int __init get_8254_time
386  /* next tick in 8254 can be caught by catching timer wraparound */
387  static void __init wait_8254_wraparound(void)
388  {
389 -       unsigned int curr_count, prev_count=~0;
390 -       int delta;
391 +       unsigned int curr_count, prev_count;
392  
393         curr_count = get_8254_timer_count();
394 -
395         do {
396                 prev_count = curr_count;
397                 curr_count = get_8254_timer_count();
398 -               delta = curr_count-prev_count;
399  
400 -       /*
401 -        * This limit for delta seems arbitrary, but it isn't, it's
402 -        * slightly above the level of error a buggy Mercury/Neptune
403 -        * chipset timer can cause.
404 -        */
405 +               /* workaround for broken Mercury/Neptune */
406 +               if (prev_count >= curr_count + 0x100)
407 +                       curr_count = get_8254_timer_count();
408  
409 -       } while (delta < 300);
410 +       } while (prev_count >= curr_count);
411  }
412  
413  /*
414 diff -NurpP --minimal linux-2.6.10/arch/i386/kernel/cpu/proc.c linux-2.6.10-vs1.9.3.17/arch/i386/kernel/cpu/proc.c
415 --- linux-2.6.10/arch/i386/kernel/cpu/proc.c    2004-12-25 01:54:44.000000000 +0100
416 +++ linux-2.6.10-vs1.9.3.17/arch/i386/kernel/cpu/proc.c 2004-12-26 19:40:36.000000000 +0100
417 @@ -121,8 +121,8 @@ static int show_cpuinfo(struct seq_file 
418                         seq_printf(m, " %s", x86_cap_flags[i]);
419  
420         seq_printf(m, "\nbogomips\t: %lu.%02lu\n\n",
421 -                    c->loops_per_jiffy/(500000/HZ),
422 -                    (c->loops_per_jiffy/(5000/HZ)) % 100);
423 +                    HZ*(c->loops_per_jiffy >> 3)/62500,
424 +                    (HZ*(c->loops_per_jiffy >> 3)/625) % 100);
425         return 0;
426  }
427  
428 diff -NurpP --minimal linux-2.6.10/arch/i386/kernel/entry.S linux-2.6.10-vs1.9.3.17/arch/i386/kernel/entry.S
429 --- linux-2.6.10/arch/i386/kernel/entry.S       2004-12-25 01:54:44.000000000 +0100
430 +++ linux-2.6.10-vs1.9.3.17/arch/i386/kernel/entry.S    2004-12-26 19:40:23.000000000 +0100
431 @@ -849,7 +849,7 @@ ENTRY(sys_call_table)
432         .long sys_tgkill        /* 270 */
433         .long sys_utimes
434         .long sys_fadvise64_64
435 -       .long sys_ni_syscall    /* sys_vserver */
436 +       .long sys_vserver
437         .long sys_mbind
438         .long sys_get_mempolicy
439         .long sys_set_mempolicy
440 diff -NurpP --minimal linux-2.6.10/arch/i386/kernel/io_apic.c linux-2.6.10-vs1.9.3.17/arch/i386/kernel/io_apic.c
441 --- linux-2.6.10/arch/i386/kernel/io_apic.c     2004-12-25 01:54:44.000000000 +0100
442 +++ linux-2.6.10-vs1.9.3.17/arch/i386/kernel/io_apic.c  2005-01-02 10:43:41.000000000 +0100
443 @@ -1764,7 +1764,7 @@ static int __init timer_irq_works(void)
444  
445         local_irq_enable();
446         /* Let ten ticks pass... */
447 -       mdelay((10 * 1000) / HZ);
448 +       mdelay((10 * 1000) / HZ + 1);
449  
450         /*
451          * Expect a few ticks at least, to be sure some possible
452 diff -NurpP --minimal linux-2.6.10/arch/i386/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/i386/kernel/ptrace.c
453 --- linux-2.6.10/arch/i386/kernel/ptrace.c      2004-12-25 01:54:44.000000000 +0100
454 +++ linux-2.6.10-vs1.9.3.17/arch/i386/kernel/ptrace.c   2004-12-26 19:40:28.000000000 +0100
455 @@ -278,6 +278,8 @@ asmlinkage int sys_ptrace(long request, 
456         read_unlock(&tasklist_lock);
457         if (!child)
458                 goto out;
459 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
460 +               goto out_tsk;
461  
462         ret = -EPERM;
463         if (pid == 1)           /* you may not mess with init */
464 diff -NurpP --minimal linux-2.6.10/arch/i386/kernel/smpboot.c linux-2.6.10-vs1.9.3.17/arch/i386/kernel/smpboot.c
465 --- linux-2.6.10/arch/i386/kernel/smpboot.c     2004-10-23 05:05:58.000000000 +0200
466 +++ linux-2.6.10-vs1.9.3.17/arch/i386/kernel/smpboot.c  2004-12-26 19:40:36.000000000 +0100
467 @@ -1024,8 +1024,8 @@ static void __init smp_boot_cpus(unsigne
468         printk(KERN_INFO
469                 "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
470                 cpucount+1,
471 -               bogosum/(500000/HZ),
472 -               (bogosum/(5000/HZ))%100);
473 +               HZ*(bogosum >> 3)/62500,
474 +               (HZ*(bogosum >> 3)/625) % 100);
475         
476         Dprintk("Before bogocount - setting activated=1.\n");
477  
478 diff -NurpP --minimal linux-2.6.10/arch/i386/kernel/sys_i386.c linux-2.6.10-vs1.9.3.17/arch/i386/kernel/sys_i386.c
479 --- linux-2.6.10/arch/i386/kernel/sys_i386.c    2004-08-14 12:56:23.000000000 +0200
480 +++ linux-2.6.10-vs1.9.3.17/arch/i386/kernel/sys_i386.c 2004-12-26 19:40:30.000000000 +0100
481 @@ -19,6 +19,7 @@
482  #include <linux/mman.h>
483  #include <linux/file.h>
484  #include <linux/utsname.h>
485 +#include <linux/vs_cvirt.h>
486  
487  #include <asm/uaccess.h>
488  #include <asm/ipc.h>
489 @@ -217,7 +218,7 @@ asmlinkage int sys_uname(struct old_utsn
490         if (!name)
491                 return -EFAULT;
492         down_read(&uts_sem);
493 -       err=copy_to_user(name, &system_utsname, sizeof (*name));
494 +       err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
495         up_read(&uts_sem);
496         return err?-EFAULT:0;
497  }
498 @@ -225,6 +226,7 @@ asmlinkage int sys_uname(struct old_utsn
499  asmlinkage int sys_olduname(struct oldold_utsname __user * name)
500  {
501         int error;
502 +       struct new_utsname *ptr;
503  
504         if (!name)
505                 return -EFAULT;
506 @@ -233,15 +235,16 @@ asmlinkage int sys_olduname(struct oldol
507    
508         down_read(&uts_sem);
509         
510 -       error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
511 +       ptr = vx_new_utsname();
512 +       error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
513         error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
514 -       error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
515 +       error |= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
516         error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
517 -       error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
518 +       error |= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
519         error |= __put_user(0,name->release+__OLD_UTS_LEN);
520 -       error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
521 +       error |= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
522         error |= __put_user(0,name->version+__OLD_UTS_LEN);
523 -       error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
524 +       error |= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
525         error |= __put_user(0,name->machine+__OLD_UTS_LEN);
526         
527         up_read(&uts_sem);
528 diff -NurpP --minimal linux-2.6.10/arch/i386/kernel/traps.c linux-2.6.10-vs1.9.3.17/arch/i386/kernel/traps.c
529 --- linux-2.6.10/arch/i386/kernel/traps.c       2004-12-25 01:54:44.000000000 +0100
530 +++ linux-2.6.10-vs1.9.3.17/arch/i386/kernel/traps.c    2005-01-02 10:28:58.000000000 +0100
531 @@ -53,6 +53,7 @@
532  
533  #include <linux/irq.h>
534  #include <linux/module.h>
535 +#include <linux/vserver/debug.h>
536  
537  #include "mach_traps.h"
538  
539 @@ -306,6 +307,7 @@ void die(const char * str, struct pt_reg
540         };
541         static int die_counter;
542  
543 +       vxh_throw_oops();
544         if (die.lock_owner != smp_processor_id()) {
545                 console_verbose();
546                 spin_lock_irq(&die.lock);
547 @@ -340,6 +342,7 @@ void die(const char * str, struct pt_reg
548         bust_spinlocks(0);
549         die.lock_owner = -1;
550         spin_unlock_irq(&die.lock);
551 +       vxh_dump_history();
552         if (in_interrupt())
553                 panic("Fatal exception in interrupt");
554  
555 diff -NurpP --minimal linux-2.6.10/arch/i386/mm/hugetlbpage.c linux-2.6.10-vs1.9.3.17/arch/i386/mm/hugetlbpage.c
556 --- linux-2.6.10/arch/i386/mm/hugetlbpage.c     2004-12-25 01:54:44.000000000 +0100
557 +++ linux-2.6.10-vs1.9.3.17/arch/i386/mm/hugetlbpage.c  2004-12-26 19:40:35.000000000 +0100
558 @@ -42,7 +42,8 @@ static void set_huge_pte(struct mm_struc
559  {
560         pte_t entry;
561  
562 -       mm->rss += (HPAGE_SIZE / PAGE_SIZE);
563 +       // mm->rss += (HPAGE_SIZE / PAGE_SIZE);
564 +       vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
565         if (write_access) {
566                 entry =
567                     pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
568 @@ -82,7 +83,8 @@ int copy_hugetlb_page_range(struct mm_st
569                 ptepage = pte_page(entry);
570                 get_page(ptepage);
571                 set_pte(dst_pte, entry);
572 -               dst->rss += (HPAGE_SIZE / PAGE_SIZE);
573 +               // dst->rss += (HPAGE_SIZE / PAGE_SIZE);
574 +               vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
575                 addr += HPAGE_SIZE;
576         }
577         return 0;
578 @@ -218,7 +220,8 @@ void unmap_hugepage_range(struct vm_area
579                 page = pte_page(pte);
580                 put_page(page);
581         }
582 -       mm->rss -= (end - start) >> PAGE_SHIFT;
583 +       // mm->rss -= (end - start) >> PAGE_SHIFT;
584 +       vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
585         flush_tlb_range(vma, start, end);
586  }
587  
588 diff -NurpP --minimal linux-2.6.10/arch/ia64/Kconfig linux-2.6.10-vs1.9.3.17/arch/ia64/Kconfig
589 --- linux-2.6.10/arch/ia64/Kconfig      2004-10-23 05:05:58.000000000 +0200
590 +++ linux-2.6.10-vs1.9.3.17/arch/ia64/Kconfig   2004-12-26 19:40:21.000000000 +0100
591 @@ -387,6 +387,8 @@ source "arch/ia64/oprofile/Kconfig"
592  
593  source "arch/ia64/Kconfig.debug"
594  
595 +source "kernel/vserver/Kconfig"
596 +
597  source "security/Kconfig"
598  
599  source "crypto/Kconfig"
600 diff -NurpP --minimal linux-2.6.10/arch/ia64/ia32/binfmt_elf32.c linux-2.6.10-vs1.9.3.17/arch/ia64/ia32/binfmt_elf32.c
601 --- linux-2.6.10/arch/ia64/ia32/binfmt_elf32.c  2004-12-25 01:54:44.000000000 +0100
602 +++ linux-2.6.10-vs1.9.3.17/arch/ia64/ia32/binfmt_elf32.c       2004-12-26 19:40:35.000000000 +0100
603 @@ -199,7 +199,7 @@ ia64_elf32_init (struct pt_regs *regs)
604  int
605  ia32_setup_arg_pages (struct linux_binprm *bprm, int executable_stack)
606  {
607 -       unsigned long stack_base;
608 +       unsigned long stack_base, grow;
609         struct vm_area_struct *mpnt;
610         struct mm_struct *mm = current->mm;
611         int i, ret;
612 @@ -216,8 +216,10 @@ ia32_setup_arg_pages (struct linux_binpr
613         if (!mpnt)
614                 return -ENOMEM;
615  
616 -       if (security_vm_enough_memory((IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
617 -                                     >> PAGE_SHIFT)) {
618 +       grow = (IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
619 +               >> PAGE_SHIFT;
620 +       if (security_vm_enough_memory(grow) ||
621 +               !vx_vmpages_avail(mm, grow)) {
622                 kmem_cache_free(vm_area_cachep, mpnt);
623                 return -ENOMEM;
624         }
625 @@ -242,7 +244,9 @@ ia32_setup_arg_pages (struct linux_binpr
626                         kmem_cache_free(vm_area_cachep, mpnt);
627                         return ret;
628                 }
629 -               current->mm->stack_vm = current->mm->total_vm = vma_pages(mpnt);
630 +               // current->mm->stack_vm = current->mm->total_vm = vma_pages(mpnt);
631 +               vx_vmpages_sub(current->mm, current->mm->total_vm - vma_pages(mpnt));
632 +               current->mm->stack_vm = current->mm->total_vm;
633         }
634  
635         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
636 diff -NurpP --minimal linux-2.6.10/arch/ia64/kernel/entry.S linux-2.6.10-vs1.9.3.17/arch/ia64/kernel/entry.S
637 --- linux-2.6.10/arch/ia64/kernel/entry.S       2004-12-25 01:54:44.000000000 +0100
638 +++ linux-2.6.10-vs1.9.3.17/arch/ia64/kernel/entry.S    2004-12-26 19:40:23.000000000 +0100
639 @@ -1526,7 +1526,7 @@ sys_call_table:
640         data8 sys_mq_notify
641         data8 sys_mq_getsetattr
642         data8 sys_ni_syscall                    // reserved for kexec_load
643 -       data8 sys_ni_syscall                    // reserved for vserver
644 +       data8 sys_vserver
645         data8 sys_waitid                        // 1270
646         data8 sys_add_key
647         data8 sys_request_key
648 diff -NurpP --minimal linux-2.6.10/arch/ia64/kernel/perfmon.c linux-2.6.10-vs1.9.3.17/arch/ia64/kernel/perfmon.c
649 --- linux-2.6.10/arch/ia64/kernel/perfmon.c     2004-12-25 01:54:44.000000000 +0100
650 +++ linux-2.6.10-vs1.9.3.17/arch/ia64/kernel/perfmon.c  2004-12-26 19:40:35.000000000 +0100
651 @@ -39,6 +39,8 @@
652  #include <linux/mount.h>
653  #include <linux/version.h>
654  #include <linux/bitops.h>
655 +#include <linux/vs_memory.h>
656 +#include <linux/vs_cvirt.h>
657  
658  #include <asm/errno.h>
659  #include <asm/intrinsics.h>
660 @@ -2341,7 +2343,8 @@ pfm_smpl_buffer_alloc(struct task_struct
661          */
662         insert_vm_struct(mm, vma);
663  
664 -       mm->total_vm  += size >> PAGE_SHIFT;
665 +       // mm->total_vm  += size >> PAGE_SHIFT;
666 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
667         vm_stat_account(vma);
668         up_write(&task->mm->mmap_sem);
669  
670 diff -NurpP --minimal linux-2.6.10/arch/ia64/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/ia64/kernel/ptrace.c
671 --- linux-2.6.10/arch/ia64/kernel/ptrace.c      2004-12-25 01:54:44.000000000 +0100
672 +++ linux-2.6.10-vs1.9.3.17/arch/ia64/kernel/ptrace.c   2004-12-26 19:40:28.000000000 +0100
673 @@ -1326,6 +1326,9 @@ sys_ptrace (long request, pid_t pid, uns
674         read_unlock(&tasklist_lock);
675         if (!child)
676                 goto out;
677 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
678 +               goto out_tsk;
679 +
680         ret = -EPERM;
681         if (pid == 1)           /* no messing around with init! */
682                 goto out_tsk;
683 diff -NurpP --minimal linux-2.6.10/arch/ia64/mm/fault.c linux-2.6.10-vs1.9.3.17/arch/ia64/mm/fault.c
684 --- linux-2.6.10/arch/ia64/mm/fault.c   2004-12-25 01:54:44.000000000 +0100
685 +++ linux-2.6.10-vs1.9.3.17/arch/ia64/mm/fault.c        2004-12-26 19:40:35.000000000 +0100
686 @@ -9,6 +9,7 @@
687  #include <linux/mm.h>
688  #include <linux/smp_lock.h>
689  #include <linux/interrupt.h>
690 +#include <linux/vs_memory.h>
691  
692  #include <asm/pgtable.h>
693  #include <asm/processor.h>
694 @@ -33,12 +34,19 @@ expand_backing_store (struct vm_area_str
695  
696         grow = PAGE_SIZE >> PAGE_SHIFT;
697         if (address - vma->vm_start > current->signal->rlim[RLIMIT_STACK].rlim_cur
698 -           || (((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) > current->signal->rlim[RLIMIT_AS].rlim_cur))
699 +           || (((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) >
700 +               current->signal->rlim[RLIMIT_AS].rlim_cur))
701 +               return -ENOMEM;
702 +       if (!vx_vmpages_avail(vma->vm_mm, grow) ||
703 +               ((vma->vm_flags & VM_LOCKED) &&
704 +               !vx_vmlocked_avail(vma->vm_mm, grow)))
705                 return -ENOMEM;
706         vma->vm_end += PAGE_SIZE;
707 -       vma->vm_mm->total_vm += grow;
708 +       // vma->vm_mm->total_vm += grow;
709 +       vx_vmpages_add(vma->vm_mm, grow);
710         if (vma->vm_flags & VM_LOCKED)
711 -               vma->vm_mm->locked_vm += grow;
712 +               // vma->vm_mm->locked_vm += grow;
713 +               vx_vmlocked_add(vma->vm_mm, grow);
714         __vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, grow);
715         return 0;
716  }
717 diff -NurpP --minimal linux-2.6.10/arch/ia64/mm/hugetlbpage.c linux-2.6.10-vs1.9.3.17/arch/ia64/mm/hugetlbpage.c
718 --- linux-2.6.10/arch/ia64/mm/hugetlbpage.c     2004-08-14 12:55:32.000000000 +0200
719 +++ linux-2.6.10-vs1.9.3.17/arch/ia64/mm/hugetlbpage.c  2004-12-26 19:40:35.000000000 +0100
720 @@ -65,7 +65,8 @@ set_huge_pte (struct mm_struct *mm, stru
721  {
722         pte_t entry;
723  
724 -       mm->rss += (HPAGE_SIZE / PAGE_SIZE);
725 +       // mm->rss += (HPAGE_SIZE / PAGE_SIZE);
726 +       vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
727         if (write_access) {
728                 entry =
729                     pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
730 @@ -108,7 +109,8 @@ int copy_hugetlb_page_range(struct mm_st
731                 ptepage = pte_page(entry);
732                 get_page(ptepage);
733                 set_pte(dst_pte, entry);
734 -               dst->rss += (HPAGE_SIZE / PAGE_SIZE);
735 +               // dst->rss += (HPAGE_SIZE / PAGE_SIZE);
736 +               vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
737                 addr += HPAGE_SIZE;
738         }
739         return 0;
740 @@ -249,7 +251,8 @@ void unmap_hugepage_range(struct vm_area
741                 put_page(page);
742                 pte_clear(pte);
743         }
744 -       mm->rss -= (end - start) >> PAGE_SHIFT;
745 +       // mm->rss -= (end - start) >> PAGE_SHIFT;
746 +       vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
747         flush_tlb_range(vma, start, end);
748  }
749  
750 diff -NurpP --minimal linux-2.6.10/arch/m68k/Kconfig linux-2.6.10-vs1.9.3.17/arch/m68k/Kconfig
751 --- linux-2.6.10/arch/m68k/Kconfig      2004-12-25 01:54:45.000000000 +0100
752 +++ linux-2.6.10-vs1.9.3.17/arch/m68k/Kconfig   2004-12-26 19:40:22.000000000 +0100
753 @@ -659,6 +659,8 @@ source "fs/Kconfig"
754  
755  source "arch/m68k/Kconfig.debug"
756  
757 +source "kernel/vserver/Kconfig"
758 +
759  source "security/Kconfig"
760  
761  source "crypto/Kconfig"
762 diff -NurpP --minimal linux-2.6.10/arch/m68k/atari/stram.c linux-2.6.10-vs1.9.3.17/arch/m68k/atari/stram.c
763 --- linux-2.6.10/arch/m68k/atari/stram.c        2004-08-14 12:55:48.000000000 +0200
764 +++ linux-2.6.10-vs1.9.3.17/arch/m68k/atari/stram.c     2004-12-26 19:40:35.000000000 +0100
765 @@ -635,7 +635,8 @@ static inline void unswap_pte(struct vm_
766         set_pte(dir, pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
767         swap_free(entry);
768         get_page(page);
769 -       ++vma->vm_mm->rss;
770 +       // ++vma->vm_mm->rss;
771 +       vx_rsspages_inc(vma->vm_mm);
772  }
773  
774  static inline void unswap_pmd(struct vm_area_struct * vma, pmd_t *dir,
775 diff -NurpP --minimal linux-2.6.10/arch/m68k/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/m68k/kernel/ptrace.c
776 --- linux-2.6.10/arch/m68k/kernel/ptrace.c      2004-12-25 01:54:45.000000000 +0100
777 +++ linux-2.6.10-vs1.9.3.17/arch/m68k/kernel/ptrace.c   2004-12-26 19:40:28.000000000 +0100
778 @@ -140,6 +140,8 @@ asmlinkage int sys_ptrace(long request, 
779         read_unlock(&tasklist_lock);
780         if (!child)
781                 goto out;
782 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
783 +               goto out_tsk;
784  
785         ret = -EPERM;
786         if (pid == 1)           /* you may not mess with init */
787 diff -NurpP --minimal linux-2.6.10/arch/m68knommu/Kconfig linux-2.6.10-vs1.9.3.17/arch/m68knommu/Kconfig
788 --- linux-2.6.10/arch/m68knommu/Kconfig 2004-12-25 01:54:45.000000000 +0100
789 +++ linux-2.6.10-vs1.9.3.17/arch/m68knommu/Kconfig      2004-12-26 19:40:23.000000000 +0100
790 @@ -581,6 +581,8 @@ source "fs/Kconfig"
791  
792  source "arch/m68knommu/Kconfig.debug"
793  
794 +source "kernel/vserver/Kconfig"
795 +
796  source "security/Kconfig"
797  
798  source "crypto/Kconfig"
799 diff -NurpP --minimal linux-2.6.10/arch/m68knommu/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/m68knommu/kernel/ptrace.c
800 --- linux-2.6.10/arch/m68knommu/kernel/ptrace.c 2004-12-25 01:54:45.000000000 +0100
801 +++ linux-2.6.10-vs1.9.3.17/arch/m68knommu/kernel/ptrace.c      2004-12-26 19:40:28.000000000 +0100
802 @@ -124,6 +124,8 @@ asmlinkage int sys_ptrace(long request, 
803         read_unlock(&tasklist_lock);
804         if (!child)
805                 goto out;
806 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
807 +               goto out_tsk;
808  
809         ret = -EPERM;
810         if (pid == 1)           /* you may not mess with init */
811 diff -NurpP --minimal linux-2.6.10/arch/mips/Kconfig linux-2.6.10-vs1.9.3.17/arch/mips/Kconfig
812 --- linux-2.6.10/arch/mips/Kconfig      2004-12-25 01:54:45.000000000 +0100
813 +++ linux-2.6.10-vs1.9.3.17/arch/mips/Kconfig   2004-12-26 19:40:23.000000000 +0100
814 @@ -1581,6 +1581,8 @@ source "fs/Kconfig"
815  
816  source "arch/mips/Kconfig.debug"
817  
818 +source "kernel/vserver/Kconfig"
819 +
820  source "security/Kconfig"
821  
822  source "crypto/Kconfig"
823 diff -NurpP --minimal linux-2.6.10/arch/mips/kernel/irixelf.c linux-2.6.10-vs1.9.3.17/arch/mips/kernel/irixelf.c
824 --- linux-2.6.10/arch/mips/kernel/irixelf.c     2004-12-25 01:54:46.000000000 +0100
825 +++ linux-2.6.10-vs1.9.3.17/arch/mips/kernel/irixelf.c  2004-12-26 19:40:35.000000000 +0100
826 @@ -684,7 +684,8 @@ static int load_irix_binary(struct linux
827         /* Do this so that we can load the interpreter, if need be.  We will
828          * change some of these later.
829          */
830 -       current->mm->rss = 0;
831 +       // current->mm->rss = 0;
832 +       vx_rsspages_sub(current->mm, current->mm->rss);
833         setup_arg_pages(bprm, EXSTACK_DEFAULT);
834         current->mm->start_stack = bprm->p;
835  
836 diff -NurpP --minimal linux-2.6.10/arch/mips/kernel/linux32.c linux-2.6.10-vs1.9.3.17/arch/mips/kernel/linux32.c
837 --- linux-2.6.10/arch/mips/kernel/linux32.c     2004-08-14 12:55:35.000000000 +0200
838 +++ linux-2.6.10-vs1.9.3.17/arch/mips/kernel/linux32.c  2004-12-26 19:40:30.000000000 +0100
839 @@ -1208,7 +1208,7 @@ asmlinkage long sys32_newuname(struct ne
840         int ret = 0;
841  
842         down_read(&uts_sem);
843 -       if (copy_to_user(name,&system_utsname,sizeof *name))
844 +       if (copy_to_user(name, vx_new_utsname(), sizeof *name))
845                 ret = -EFAULT;
846         up_read(&uts_sem);
847  
848 diff -NurpP --minimal linux-2.6.10/arch/mips/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/mips/kernel/ptrace.c
849 --- linux-2.6.10/arch/mips/kernel/ptrace.c      2004-12-25 01:54:46.000000000 +0100
850 +++ linux-2.6.10-vs1.9.3.17/arch/mips/kernel/ptrace.c   2004-12-26 19:40:28.000000000 +0100
851 @@ -76,6 +76,8 @@ asmlinkage int sys_ptrace(long request, 
852         read_unlock(&tasklist_lock);
853         if (!child)
854                 goto out;
855 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
856 +               goto out_tsk;
857  
858         ret = -EPERM;
859         if (pid == 1)           /* you may not mess with init */
860 diff -NurpP --minimal linux-2.6.10/arch/mips/kernel/syscall.c linux-2.6.10-vs1.9.3.17/arch/mips/kernel/syscall.c
861 --- linux-2.6.10/arch/mips/kernel/syscall.c     2004-12-25 01:54:46.000000000 +0100
862 +++ linux-2.6.10-vs1.9.3.17/arch/mips/kernel/syscall.c  2004-12-26 19:40:30.000000000 +0100
863 @@ -25,6 +25,7 @@
864  #include <linux/msg.h>
865  #include <linux/shm.h>
866  #include <linux/compiler.h>
867 +#include <linux/vs_cvirt.h>
868  
869  #include <asm/branch.h>
870  #include <asm/cachectl.h>
871 @@ -212,7 +213,7 @@ out:
872   */
873  asmlinkage int sys_uname(struct old_utsname * name)
874  {
875 -       if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
876 +       if (name && !copy_to_user(name, vx_new_utsname(), sizeof (*name)))
877                 return 0;
878         return -EFAULT;
879  }
880 @@ -223,21 +224,23 @@ asmlinkage int sys_uname(struct old_utsn
881  asmlinkage int sys_olduname(struct oldold_utsname * name)
882  {
883         int error;
884 +       struct new_utsname *ptr;
885  
886         if (!name)
887                 return -EFAULT;
888         if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
889                 return -EFAULT;
890  
891 -       error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
892 +       ptr = vx_new_utsname();
893 +       error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
894         error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
895 -       error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
896 +       error -= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
897         error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
898 -       error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
899 +       error -= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
900         error -= __put_user(0,name->release+__OLD_UTS_LEN);
901 -       error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
902 +       error -= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
903         error -= __put_user(0,name->version+__OLD_UTS_LEN);
904 -       error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
905 +       error -= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
906         error = __put_user(0,name->machine+__OLD_UTS_LEN);
907         error = error ? -EFAULT : 0;
908  
909 @@ -263,10 +266,10 @@ asmlinkage int _sys_sysmips(int cmd, lon
910                         return -EFAULT;
911  
912                 down_write(&uts_sem);
913 -               strncpy(system_utsname.nodename, nodename, len);
914 +               strncpy(vx_new_uts(nodename), nodename, len);
915                 nodename[__NEW_UTS_LEN] = '\0';
916 -               strlcpy(system_utsname.nodename, nodename,
917 -                       sizeof(system_utsname.nodename));
918 +               strlcpy(vx_new_uts(nodename), nodename,
919 +                       sizeof(vx_new_uts(nodename)));
920                 up_write(&uts_sem);
921                 return 0;
922         }
923 diff -NurpP --minimal linux-2.6.10/arch/mips/kernel/sysirix.c linux-2.6.10-vs1.9.3.17/arch/mips/kernel/sysirix.c
924 --- linux-2.6.10/arch/mips/kernel/sysirix.c     2004-12-25 01:54:46.000000000 +0100
925 +++ linux-2.6.10-vs1.9.3.17/arch/mips/kernel/sysirix.c  2004-12-26 19:40:35.000000000 +0100
926 @@ -30,6 +30,7 @@
927  #include <linux/socket.h>
928  #include <linux/security.h>
929  #include <linux/syscalls.h>
930 +#include <linux/vs_cvirt.h>
931  
932  #include <asm/ptrace.h>
933  #include <asm/page.h>
934 @@ -582,7 +583,8 @@ asmlinkage int irix_brk(unsigned long br
935         /*
936          * Check if we have enough memory..
937          */
938 -       if (security_vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT)) {
939 +       if (security_vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT) ||
940 +               !vx_vmpages_avail(mm, (newbrk-oldbrk) >> PAGE_SHIFT)) {
941                 ret = -ENOMEM;
942                 goto out;
943         }
944 diff -NurpP --minimal linux-2.6.10/arch/parisc/Kconfig linux-2.6.10-vs1.9.3.17/arch/parisc/Kconfig
945 --- linux-2.6.10/arch/parisc/Kconfig    2004-10-23 05:05:59.000000000 +0200
946 +++ linux-2.6.10-vs1.9.3.17/arch/parisc/Kconfig 2004-12-26 19:40:23.000000000 +0100
947 @@ -190,6 +190,8 @@ source "arch/parisc/oprofile/Kconfig"
948  
949  source "arch/parisc/Kconfig.debug"
950  
951 +source "kernel/vserver/Kconfig"
952 +
953  source "security/Kconfig"
954  
955  source "crypto/Kconfig"
956 diff -NurpP --minimal linux-2.6.10/arch/parisc/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/parisc/kernel/ptrace.c
957 --- linux-2.6.10/arch/parisc/kernel/ptrace.c    2004-12-25 01:54:47.000000000 +0100
958 +++ linux-2.6.10-vs1.9.3.17/arch/parisc/kernel/ptrace.c 2004-12-26 19:40:28.000000000 +0100
959 @@ -110,6 +110,9 @@ long sys_ptrace(long request, pid_t pid,
960         read_unlock(&tasklist_lock);
961         if (!child)
962                 goto out;
963 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
964 +               goto out_tsk;
965 +
966         ret = -EPERM;
967         if (pid == 1)           /* no messing around with init! */
968                 goto out_tsk;
969 diff -NurpP --minimal linux-2.6.10/arch/parisc/kernel/sys_parisc32.c linux-2.6.10-vs1.9.3.17/arch/parisc/kernel/sys_parisc32.c
970 --- linux-2.6.10/arch/parisc/kernel/sys_parisc32.c      2004-12-25 01:54:47.000000000 +0100
971 +++ linux-2.6.10-vs1.9.3.17/arch/parisc/kernel/sys_parisc32.c   2004-12-26 19:40:30.000000000 +0100
972 @@ -680,6 +680,7 @@ asmlinkage int sys32_sysinfo(struct sysi
973  
974         do {
975                 seq = read_seqbegin(&xtime_lock);
976 +               /* requires vx virtualization */
977                 val.uptime = jiffies / HZ;
978  
979                 val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
980 diff -NurpP --minimal linux-2.6.10/arch/ppc/Kconfig linux-2.6.10-vs1.9.3.17/arch/ppc/Kconfig
981 --- linux-2.6.10/arch/ppc/Kconfig       2004-12-25 01:54:48.000000000 +0100
982 +++ linux-2.6.10-vs1.9.3.17/arch/ppc/Kconfig    2004-12-26 19:40:23.000000000 +0100
983 @@ -1211,6 +1211,8 @@ source "arch/ppc/oprofile/Kconfig"
984  
985  source "arch/ppc/Kconfig.debug"
986  
987 +source "kernel/vserver/Kconfig"
988 +
989  source "security/Kconfig"
990  
991  source "crypto/Kconfig"
992 diff -NurpP --minimal linux-2.6.10/arch/ppc/kernel/misc.S linux-2.6.10-vs1.9.3.17/arch/ppc/kernel/misc.S
993 --- linux-2.6.10/arch/ppc/kernel/misc.S 2004-12-25 01:54:48.000000000 +0100
994 +++ linux-2.6.10-vs1.9.3.17/arch/ppc/kernel/misc.S      2004-12-26 19:40:23.000000000 +0100
995 @@ -1435,7 +1435,7 @@ _GLOBAL(sys_call_table)
996         .long ppc_fadvise64_64
997         .long sys_ni_syscall            /* 255 - rtas (used on ppc64) */
998         .long sys_ni_syscall            /* 256 reserved for sys_debug_setcontext */
999 -       .long sys_ni_syscall            /* 257 reserved for vserver */
1000 +       .long sys_vserver
1001         .long sys_ni_syscall            /* 258 reserved for new sys_remap_file_pages */
1002         .long sys_ni_syscall            /* 259 reserved for new sys_mbind */
1003         .long sys_ni_syscall            /* 260 reserved for new sys_get_mempolicy */
1004 diff -NurpP --minimal linux-2.6.10/arch/ppc/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/ppc/kernel/ptrace.c
1005 --- linux-2.6.10/arch/ppc/kernel/ptrace.c       2004-12-25 01:54:48.000000000 +0100
1006 +++ linux-2.6.10-vs1.9.3.17/arch/ppc/kernel/ptrace.c    2004-12-26 19:40:28.000000000 +0100
1007 @@ -262,6 +262,8 @@ int sys_ptrace(long request, long pid, l
1008         read_unlock(&tasklist_lock);
1009         if (!child)
1010                 goto out;
1011 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
1012 +               goto out_tsk;
1013  
1014         ret = -EPERM;
1015         if (pid == 1)           /* you may not mess with init */
1016 diff -NurpP --minimal linux-2.6.10/arch/ppc/kernel/syscalls.c linux-2.6.10-vs1.9.3.17/arch/ppc/kernel/syscalls.c
1017 --- linux-2.6.10/arch/ppc/kernel/syscalls.c     2004-08-14 12:56:22.000000000 +0200
1018 +++ linux-2.6.10-vs1.9.3.17/arch/ppc/kernel/syscalls.c  2004-12-26 19:40:30.000000000 +0100
1019 @@ -36,6 +36,7 @@
1020  #include <linux/utsname.h>
1021  #include <linux/file.h>
1022  #include <linux/unistd.h>
1023 +#include <linux/vs_cvirt.h>
1024  
1025  #include <asm/uaccess.h>
1026  #include <asm/ipc.h>
1027 @@ -229,7 +230,7 @@ int sys_uname(struct old_utsname __user 
1028         int err = -EFAULT;
1029  
1030         down_read(&uts_sem);
1031 -       if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
1032 +       if (name && !copy_to_user(name, vx_new_utsname(), sizeof (*name)))
1033                 err = 0;
1034         up_read(&uts_sem);
1035         return err;
1036 @@ -238,6 +239,7 @@ int sys_uname(struct old_utsname __user 
1037  int sys_olduname(struct oldold_utsname __user * name)
1038  {
1039         int error;
1040 +       struct new_utsname *ptr;
1041  
1042         if (!name)
1043                 return -EFAULT;
1044 @@ -245,15 +247,16 @@ int sys_olduname(struct oldold_utsname _
1045                 return -EFAULT;
1046  
1047         down_read(&uts_sem);
1048 -       error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
1049 +       ptr = vx_new_utsname();
1050 +       error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
1051         error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
1052 -       error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
1053 +       error -= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
1054         error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
1055 -       error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
1056 +       error -= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
1057         error -= __put_user(0,name->release+__OLD_UTS_LEN);
1058 -       error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
1059 +       error -= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
1060         error -= __put_user(0,name->version+__OLD_UTS_LEN);
1061 -       error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
1062 +       error -= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
1063         error = __put_user(0,name->machine+__OLD_UTS_LEN);
1064         up_read(&uts_sem);
1065  
1066 diff -NurpP --minimal linux-2.6.10/arch/ppc64/Kconfig linux-2.6.10-vs1.9.3.17/arch/ppc64/Kconfig
1067 --- linux-2.6.10/arch/ppc64/Kconfig     2004-12-25 01:54:48.000000000 +0100
1068 +++ linux-2.6.10-vs1.9.3.17/arch/ppc64/Kconfig  2004-12-26 19:40:23.000000000 +0100
1069 @@ -374,6 +374,8 @@ source "arch/ppc64/oprofile/Kconfig"
1070  
1071  source "arch/ppc64/Kconfig.debug"
1072  
1073 +source "kernel/vserver/Kconfig"
1074 +
1075  source "security/Kconfig"
1076  
1077  config KEYS_COMPAT
1078 diff -NurpP --minimal linux-2.6.10/arch/ppc64/kernel/misc.S linux-2.6.10-vs1.9.3.17/arch/ppc64/kernel/misc.S
1079 --- linux-2.6.10/arch/ppc64/kernel/misc.S       2004-12-25 01:54:49.000000000 +0100
1080 +++ linux-2.6.10-vs1.9.3.17/arch/ppc64/kernel/misc.S    2004-12-26 19:40:23.000000000 +0100
1081 @@ -951,7 +951,7 @@ _GLOBAL(sys_call_table32)
1082         .llong .ppc32_fadvise64_64      /* 32bit only fadvise64_64 */
1083         .llong .ppc_rtas                /* 255 */
1084         .llong .sys_ni_syscall          /* 256 reserved for sys_debug_setcontext */
1085 -       .llong .sys_ni_syscall          /* 257 reserved for vserver */
1086 +       .llong .sys_vserver
1087         .llong .sys_ni_syscall          /* 258 reserved for new sys_remap_file_pages */
1088         .llong .compat_sys_mbind
1089         .llong .compat_sys_get_mempolicy        /* 260 */
1090 diff -NurpP --minimal linux-2.6.10/arch/ppc64/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/ppc64/kernel/ptrace.c
1091 --- linux-2.6.10/arch/ppc64/kernel/ptrace.c     2004-12-25 01:54:49.000000000 +0100
1092 +++ linux-2.6.10-vs1.9.3.17/arch/ppc64/kernel/ptrace.c  2004-12-26 19:40:28.000000000 +0100
1093 @@ -76,6 +76,8 @@ int sys_ptrace(long request, long pid, l
1094         read_unlock(&tasklist_lock);
1095         if (!child)
1096                 goto out;
1097 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
1098 +               goto out_tsk;
1099  
1100         ret = -EPERM;
1101         if (pid == 1)           /* you may not mess with init */
1102 diff -NurpP --minimal linux-2.6.10/arch/ppc64/kernel/sys_ppc32.c linux-2.6.10-vs1.9.3.17/arch/ppc64/kernel/sys_ppc32.c
1103 --- linux-2.6.10/arch/ppc64/kernel/sys_ppc32.c  2004-12-25 01:54:49.000000000 +0100
1104 +++ linux-2.6.10-vs1.9.3.17/arch/ppc64/kernel/sys_ppc32.c       2004-12-26 19:40:30.000000000 +0100
1105 @@ -60,6 +60,7 @@
1106  #include <linux/ptrace.h>
1107  #include <linux/aio_abi.h>
1108  #include <linux/elf.h>
1109 +#include <linux/vs_cvirt.h>
1110  
1111  #include <net/scm.h>
1112  #include <net/sock.h>
1113 @@ -1173,6 +1174,7 @@ asmlinkage long sys32_time(compat_time_t
1114  asmlinkage int sys32_olduname(struct oldold_utsname __user * name)
1115  {
1116         int error;
1117 +       struct new_utsname *ptr;
1118         
1119         if (!name)
1120                 return -EFAULT;
1121 @@ -1180,15 +1182,16 @@ asmlinkage int sys32_olduname(struct old
1122                 return -EFAULT;
1123    
1124         down_read(&uts_sem);
1125 -       error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
1126 +       ptr = vx_new_utsname();
1127 +       error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
1128         error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
1129 -       error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
1130 +       error -= __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
1131         error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
1132 -       error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
1133 +       error -= __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
1134         error -= __put_user(0,name->release+__OLD_UTS_LEN);
1135 -       error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
1136 +       error -= __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
1137         error -= __put_user(0,name->version+__OLD_UTS_LEN);
1138 -       error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
1139 +       error -= __copy_to_user(&name->machine,ptr->machine,__OLD_UTS_LEN);
1140         error = __put_user(0,name->machine+__OLD_UTS_LEN);
1141         up_read(&uts_sem);
1142  
1143 diff -NurpP --minimal linux-2.6.10/arch/ppc64/mm/hugetlbpage.c linux-2.6.10-vs1.9.3.17/arch/ppc64/mm/hugetlbpage.c
1144 --- linux-2.6.10/arch/ppc64/mm/hugetlbpage.c    2004-12-25 01:54:49.000000000 +0100
1145 +++ linux-2.6.10-vs1.9.3.17/arch/ppc64/mm/hugetlbpage.c 2004-12-26 19:40:35.000000000 +0100
1146 @@ -153,7 +153,8 @@ static void set_huge_pte(struct mm_struc
1147  {
1148         pte_t entry;
1149  
1150 -       mm->rss += (HPAGE_SIZE / PAGE_SIZE);
1151 +       // mm->rss += (HPAGE_SIZE / PAGE_SIZE);
1152 +       vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
1153         if (write_access) {
1154                 entry =
1155                     pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
1156 @@ -311,7 +312,8 @@ int copy_hugetlb_page_range(struct mm_st
1157                 
1158                 ptepage = pte_page(entry);
1159                 get_page(ptepage);
1160 -               dst->rss += (HPAGE_SIZE / PAGE_SIZE);
1161 +               // dst->rss += (HPAGE_SIZE / PAGE_SIZE);
1162 +               vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
1163                 set_pte(dst_pte, entry);
1164  
1165                 addr += HPAGE_SIZE;
1166 @@ -421,7 +423,8 @@ void unmap_hugepage_range(struct vm_area
1167  
1168                 put_page(page);
1169         }
1170 -       mm->rss -= (end - start) >> PAGE_SHIFT;
1171 +       // mm->rss -= (end - start) >> PAGE_SHIFT;
1172 +       vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
1173         flush_tlb_pending();
1174  }
1175  
1176 diff -NurpP --minimal linux-2.6.10/arch/s390/Kconfig linux-2.6.10-vs1.9.3.17/arch/s390/Kconfig
1177 --- linux-2.6.10/arch/s390/Kconfig      2004-10-23 05:06:01.000000000 +0200
1178 +++ linux-2.6.10-vs1.9.3.17/arch/s390/Kconfig   2004-12-26 19:40:23.000000000 +0100
1179 @@ -461,6 +461,8 @@ source "arch/s390/oprofile/Kconfig"
1180  
1181  source "arch/s390/Kconfig.debug"
1182  
1183 +source "kernel/vserver/Kconfig"
1184 +
1185  source "security/Kconfig"
1186  
1187  source "crypto/Kconfig"
1188 diff -NurpP --minimal linux-2.6.10/arch/s390/kernel/compat_exec.c linux-2.6.10-vs1.9.3.17/arch/s390/kernel/compat_exec.c
1189 --- linux-2.6.10/arch/s390/kernel/compat_exec.c 2004-12-25 01:54:49.000000000 +0100
1190 +++ linux-2.6.10-vs1.9.3.17/arch/s390/kernel/compat_exec.c      2004-12-26 19:40:35.000000000 +0100
1191 @@ -36,7 +36,7 @@
1192  
1193  int setup_arg_pages32(struct linux_binprm *bprm, int executable_stack)
1194  {
1195 -       unsigned long stack_base;
1196 +       unsigned long stack_base, grow;
1197         struct vm_area_struct *mpnt;
1198         struct mm_struct *mm = current->mm;
1199         int i, ret;
1200 @@ -53,7 +53,10 @@ int setup_arg_pages32(struct linux_binpr
1201         if (!mpnt) 
1202                 return -ENOMEM; 
1203         
1204 -       if (security_vm_enough_memory((STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))>>PAGE_SHIFT)) {
1205 +       grow = (STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
1206 +               >> PAGE_SHIFT;
1207 +       if (security_vm_enough_memory(grow) ||
1208 +               !vx_vmpages_avail(mm, grow)) {
1209                 kmem_cache_free(vm_area_cachep, mpnt);
1210                 return -ENOMEM;
1211         }
1212 @@ -73,7 +76,9 @@ int setup_arg_pages32(struct linux_binpr
1213                         kmem_cache_free(vm_area_cachep, mpnt);
1214                         return ret;
1215                 }
1216 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
1217 +               // mm->stack_vm = mm->total_vm = vma_pages(mpnt);
1218 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
1219 +               mm->stack_vm = mm->total_vm;
1220         } 
1221  
1222         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
1223 diff -NurpP --minimal linux-2.6.10/arch/s390/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/s390/kernel/ptrace.c
1224 --- linux-2.6.10/arch/s390/kernel/ptrace.c      2004-12-25 01:54:49.000000000 +0100
1225 +++ linux-2.6.10-vs1.9.3.17/arch/s390/kernel/ptrace.c   2004-12-26 19:40:28.000000000 +0100
1226 @@ -698,9 +698,11 @@ sys_ptrace(long request, long pid, long 
1227         read_unlock(&tasklist_lock);
1228         if (!child)
1229                 goto out;
1230 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
1231 +               goto out_tsk;
1232  
1233         ret = do_ptrace(child, request, addr, data);
1234 -
1235 +out_tsk:
1236         put_task_struct(child);
1237  out:
1238         unlock_kernel();
1239 diff -NurpP --minimal linux-2.6.10/arch/s390/kernel/syscalls.S linux-2.6.10-vs1.9.3.17/arch/s390/kernel/syscalls.S
1240 --- linux-2.6.10/arch/s390/kernel/syscalls.S    2004-12-25 01:54:49.000000000 +0100
1241 +++ linux-2.6.10-vs1.9.3.17/arch/s390/kernel/syscalls.S 2004-12-26 19:40:23.000000000 +0100
1242 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
1243  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
1244  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
1245  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
1246 -NI_SYSCALL                                                     /* reserved for vserver */
1247 +SYSCALL(sys_vserver,sys_vserver,sys_vserver)
1248  SYSCALL(s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
1249  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
1250  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
1251 diff -NurpP --minimal linux-2.6.10/arch/sh/Kconfig linux-2.6.10-vs1.9.3.17/arch/sh/Kconfig
1252 --- linux-2.6.10/arch/sh/Kconfig        2004-12-25 01:54:49.000000000 +0100
1253 +++ linux-2.6.10-vs1.9.3.17/arch/sh/Kconfig     2004-12-26 19:40:23.000000000 +0100
1254 @@ -784,6 +784,8 @@ source "arch/sh/oprofile/Kconfig"
1255  
1256  source "arch/sh/Kconfig.debug"
1257  
1258 +source "kernel/vserver/Kconfig"
1259 +
1260  source "security/Kconfig"
1261  
1262  source "crypto/Kconfig"
1263 diff -NurpP --minimal linux-2.6.10/arch/sh/kernel/kgdb_stub.c linux-2.6.10-vs1.9.3.17/arch/sh/kernel/kgdb_stub.c
1264 --- linux-2.6.10/arch/sh/kernel/kgdb_stub.c     2004-08-14 12:54:51.000000000 +0200
1265 +++ linux-2.6.10-vs1.9.3.17/arch/sh/kernel/kgdb_stub.c  2004-12-26 19:40:30.000000000 +0100
1266 @@ -412,7 +412,7 @@ static struct task_struct *get_thread(in
1267         if (pid == PID_MAX) pid = 0;
1268  
1269         /* First check via PID */
1270 -       thread = find_task_by_pid(pid);
1271 +       thread = find_task_by_real_pid(pid);
1272  
1273         if (thread)
1274                 return thread;
1275 diff -NurpP --minimal linux-2.6.10/arch/sh/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/sh/kernel/ptrace.c
1276 --- linux-2.6.10/arch/sh/kernel/ptrace.c        2004-12-25 01:54:49.000000000 +0100
1277 +++ linux-2.6.10-vs1.9.3.17/arch/sh/kernel/ptrace.c     2004-12-26 19:40:28.000000000 +0100
1278 @@ -108,6 +108,8 @@ asmlinkage int sys_ptrace(long request, 
1279         read_unlock(&tasklist_lock);
1280         if (!child)
1281                 goto out;
1282 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
1283 +               goto out_tsk;
1284  
1285         ret = -EPERM;
1286         if (pid == 1)           /* you may not mess with init */
1287 diff -NurpP --minimal linux-2.6.10/arch/sh/mm/hugetlbpage.c linux-2.6.10-vs1.9.3.17/arch/sh/mm/hugetlbpage.c
1288 --- linux-2.6.10/arch/sh/mm/hugetlbpage.c       2004-08-14 12:55:33.000000000 +0200
1289 +++ linux-2.6.10-vs1.9.3.17/arch/sh/mm/hugetlbpage.c    2004-12-26 19:40:35.000000000 +0100
1290 @@ -62,7 +62,8 @@ static void set_huge_pte(struct mm_struc
1291         unsigned long i;
1292         pte_t entry;
1293  
1294 -       mm->rss += (HPAGE_SIZE / PAGE_SIZE);
1295 +       // mm->rss += (HPAGE_SIZE / PAGE_SIZE);
1296 +       vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
1297  
1298         if (write_access)
1299                 entry = pte_mkwrite(pte_mkdirty(mk_pte(page,
1300 @@ -115,7 +116,8 @@ int copy_hugetlb_page_range(struct mm_st
1301                         pte_val(entry) += PAGE_SIZE;
1302                         dst_pte++;
1303                 }
1304 -               dst->rss += (HPAGE_SIZE / PAGE_SIZE);
1305 +               // dst->rss += (HPAGE_SIZE / PAGE_SIZE);
1306 +               vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
1307                 addr += HPAGE_SIZE;
1308         }
1309         return 0;
1310 @@ -206,7 +208,8 @@ void unmap_hugepage_range(struct vm_area
1311                         pte++;
1312                 }
1313         }
1314 -       mm->rss -= (end - start) >> PAGE_SHIFT;
1315 +       // mm->rss -= (end - start) >> PAGE_SHIFT;
1316 +       vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
1317         flush_tlb_range(vma, start, end);
1318  }
1319  
1320 diff -NurpP --minimal linux-2.6.10/arch/sh64/mm/hugetlbpage.c linux-2.6.10-vs1.9.3.17/arch/sh64/mm/hugetlbpage.c
1321 --- linux-2.6.10/arch/sh64/mm/hugetlbpage.c     2004-08-14 12:55:10.000000000 +0200
1322 +++ linux-2.6.10-vs1.9.3.17/arch/sh64/mm/hugetlbpage.c  2004-12-26 19:40:35.000000000 +0100
1323 @@ -62,8 +62,8 @@ static void set_huge_pte(struct mm_struc
1324         unsigned long i;
1325         pte_t entry;
1326  
1327 -       mm->rss += (HPAGE_SIZE / PAGE_SIZE);
1328 -
1329 +       // mm->rss += (HPAGE_SIZE / PAGE_SIZE);
1330 +       vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
1331         if (write_access)
1332                 entry = pte_mkwrite(pte_mkdirty(mk_pte(page,
1333                                                        vma->vm_page_prot)));
1334 @@ -115,7 +115,8 @@ int copy_hugetlb_page_range(struct mm_st
1335                         pte_val(entry) += PAGE_SIZE;
1336                         dst_pte++;
1337                 }
1338 -               dst->rss += (HPAGE_SIZE / PAGE_SIZE);
1339 +               // dst->rss += (HPAGE_SIZE / PAGE_SIZE);
1340 +               vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
1341                 addr += HPAGE_SIZE;
1342         }
1343         return 0;
1344 @@ -206,7 +207,8 @@ void unmap_hugepage_range(struct vm_area
1345                         pte++;
1346                 }
1347         }
1348 -       mm->rss -= (end - start) >> PAGE_SHIFT;
1349 +       // mm->rss -= (end - start) >> PAGE_SHIFT;
1350 +       vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
1351         flush_tlb_range(vma, start, end);
1352  }
1353  
1354 diff -NurpP --minimal linux-2.6.10/arch/sparc/Kconfig linux-2.6.10-vs1.9.3.17/arch/sparc/Kconfig
1355 --- linux-2.6.10/arch/sparc/Kconfig     2004-12-25 01:54:50.000000000 +0100
1356 +++ linux-2.6.10-vs1.9.3.17/arch/sparc/Kconfig  2004-12-26 19:40:23.000000000 +0100
1357 @@ -380,6 +380,8 @@ source "drivers/char/watchdog/Kconfig"
1358  
1359  source "arch/sparc/Kconfig.debug"
1360  
1361 +source "kernel/vserver/Kconfig"
1362 +
1363  source "security/Kconfig"
1364  
1365  source "crypto/Kconfig"
1366 diff -NurpP --minimal linux-2.6.10/arch/sparc/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/sparc/kernel/ptrace.c
1367 --- linux-2.6.10/arch/sparc/kernel/ptrace.c     2004-12-25 01:54:50.000000000 +0100
1368 +++ linux-2.6.10-vs1.9.3.17/arch/sparc/kernel/ptrace.c  2004-12-26 19:40:28.000000000 +0100
1369 @@ -321,6 +321,10 @@ asmlinkage void do_ptrace(struct pt_regs
1370                 pt_error_return(regs, ESRCH);
1371                 goto out;
1372         }
1373 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT)) {
1374 +               pt_error_return(regs, ESRCH);
1375 +               goto out_tsk;
1376 +       }
1377  
1378         if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
1379             || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
1380 diff -NurpP --minimal linux-2.6.10/arch/sparc/kernel/sys_sparc.c linux-2.6.10-vs1.9.3.17/arch/sparc/kernel/sys_sparc.c
1381 --- linux-2.6.10/arch/sparc/kernel/sys_sparc.c  2004-08-14 12:55:10.000000000 +0200
1382 +++ linux-2.6.10-vs1.9.3.17/arch/sparc/kernel/sys_sparc.c       2004-12-26 19:40:30.000000000 +0100
1383 @@ -21,6 +21,7 @@
1384  #include <linux/utsname.h>
1385  #include <linux/smp.h>
1386  #include <linux/smp_lock.h>
1387 +#include <linux/vs_cvirt.h>
1388  
1389  #include <asm/uaccess.h>
1390  #include <asm/ipc.h>
1391 @@ -471,13 +472,13 @@ asmlinkage int sys_getdomainname(char __
1392         
1393         down_read(&uts_sem);
1394         
1395 -       nlen = strlen(system_utsname.domainname) + 1;
1396 +       nlen = strlen(vx_new_uts(domainname)) + 1;
1397  
1398         if (nlen < len)
1399                 len = nlen;
1400         if (len > __NEW_UTS_LEN)
1401                 goto done;
1402 -       if (copy_to_user(name, system_utsname.domainname, len))
1403 +       if (copy_to_user(name, vx_new_uts(domainname), len))
1404                 goto done;
1405         err = 0;
1406  done:
1407 diff -NurpP --minimal linux-2.6.10/arch/sparc/kernel/systbls.S linux-2.6.10-vs1.9.3.17/arch/sparc/kernel/systbls.S
1408 --- linux-2.6.10/arch/sparc/kernel/systbls.S    2004-12-25 01:54:50.000000000 +0100
1409 +++ linux-2.6.10-vs1.9.3.17/arch/sparc/kernel/systbls.S 2004-12-26 19:40:23.000000000 +0100
1410 @@ -72,7 +72,7 @@ sys_call_table:
1411  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1412  /*255*/        .long sys_nis_syscall, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1413  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1414 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
1415 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1416  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1417  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1418  /*280*/        .long sys_ni_syscall, sys_add_key, sys_request_key, sys_keyctl
1419 diff -NurpP --minimal linux-2.6.10/arch/sparc64/Kconfig linux-2.6.10-vs1.9.3.17/arch/sparc64/Kconfig
1420 --- linux-2.6.10/arch/sparc64/Kconfig   2004-12-25 01:54:50.000000000 +0100
1421 +++ linux-2.6.10-vs1.9.3.17/arch/sparc64/Kconfig        2004-12-26 19:40:23.000000000 +0100
1422 @@ -597,6 +597,8 @@ source "arch/sparc64/oprofile/Kconfig"
1423  
1424  source "arch/sparc64/Kconfig.debug"
1425  
1426 +source "kernel/vserver/Kconfig"
1427 +
1428  source "security/Kconfig"
1429  
1430  source "crypto/Kconfig"
1431 diff -NurpP --minimal linux-2.6.10/arch/sparc64/kernel/binfmt_aout32.c linux-2.6.10-vs1.9.3.17/arch/sparc64/kernel/binfmt_aout32.c
1432 --- linux-2.6.10/arch/sparc64/kernel/binfmt_aout32.c    2004-12-25 01:54:50.000000000 +0100
1433 +++ linux-2.6.10-vs1.9.3.17/arch/sparc64/kernel/binfmt_aout32.c 2004-12-26 19:40:35.000000000 +0100
1434 @@ -27,6 +27,7 @@
1435  #include <linux/binfmts.h>
1436  #include <linux/personality.h>
1437  #include <linux/init.h>
1438 +#include <linux/vs_memory.h>
1439  
1440  #include <asm/system.h>
1441  #include <asm/uaccess.h>
1442 @@ -239,7 +240,8 @@ static int load_aout32_binary(struct lin
1443         current->mm->brk = ex.a_bss +
1444                 (current->mm->start_brk = N_BSSADDR(ex));
1445  
1446 -       current->mm->rss = 0;
1447 +       // current->mm->rss = 0;
1448 +       vx_rsspages_sub(current->mm, current->mm->rss);
1449         current->mm->mmap = NULL;
1450         compute_creds(bprm);
1451         current->flags &= ~PF_FORKNOEXEC;
1452 diff -NurpP --minimal linux-2.6.10/arch/sparc64/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/sparc64/kernel/ptrace.c
1453 --- linux-2.6.10/arch/sparc64/kernel/ptrace.c   2004-12-25 01:54:50.000000000 +0100
1454 +++ linux-2.6.10-vs1.9.3.17/arch/sparc64/kernel/ptrace.c        2004-12-26 19:40:28.000000000 +0100
1455 @@ -172,6 +172,10 @@ asmlinkage void do_ptrace(struct pt_regs
1456                 pt_error_return(regs, ESRCH);
1457                 goto out;
1458         }
1459 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT)) {
1460 +               pt_error_return(regs, ESRCH);
1461 +               goto out_tsk;
1462 +       }
1463  
1464         if ((current->personality == PER_SUNOS && request == PTRACE_SUNATTACH)
1465             || (current->personality != PER_SUNOS && request == PTRACE_ATTACH)) {
1466 diff -NurpP --minimal linux-2.6.10/arch/sparc64/kernel/sys_sparc.c linux-2.6.10-vs1.9.3.17/arch/sparc64/kernel/sys_sparc.c
1467 --- linux-2.6.10/arch/sparc64/kernel/sys_sparc.c        2004-08-14 12:55:33.000000000 +0200
1468 +++ linux-2.6.10-vs1.9.3.17/arch/sparc64/kernel/sys_sparc.c     2004-12-26 19:40:30.000000000 +0100
1469 @@ -25,6 +25,7 @@
1470  #include <linux/syscalls.h>
1471  #include <linux/ipc.h>
1472  #include <linux/personality.h>
1473 +#include <linux/vs_cvirt.h>
1474  
1475  #include <asm/uaccess.h>
1476  #include <asm/ipc.h>
1477 @@ -465,13 +466,13 @@ asmlinkage long sys_getdomainname(char _
1478  
1479         down_read(&uts_sem);
1480         
1481 -       nlen = strlen(system_utsname.domainname) + 1;
1482 +       nlen = strlen(vx_new_uts(domainname)) + 1;
1483  
1484          if (nlen < len)
1485                  len = nlen;
1486         if (len > __NEW_UTS_LEN)
1487                 goto done;
1488 -       if (copy_to_user(name, system_utsname.domainname, len))
1489 +       if (copy_to_user(name, vx_new_uts(domainname), len))
1490                 goto done;
1491         err = 0;
1492  done:
1493 diff -NurpP --minimal linux-2.6.10/arch/sparc64/kernel/systbls.S linux-2.6.10-vs1.9.3.17/arch/sparc64/kernel/systbls.S
1494 --- linux-2.6.10/arch/sparc64/kernel/systbls.S  2004-12-25 01:54:50.000000000 +0100
1495 +++ linux-2.6.10-vs1.9.3.17/arch/sparc64/kernel/systbls.S       2004-12-26 19:40:23.000000000 +0100
1496 @@ -73,7 +73,7 @@ sys_call_table32:
1497  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
1498         .word sys_ni_syscall, sys32_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
1499  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
1500 -       .word sys_timer_delete, sys32_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
1501 +       .word sys_timer_delete, sys32_timer_create, sys_vserver, compat_sys_io_setup, sys_io_destroy
1502  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
1503         .word sys_mq_timedsend, sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
1504  /*280*/        .word sys_ni_syscall, sys_add_key, sys_request_key, sys_keyctl
1505 @@ -139,7 +139,7 @@ sys_call_table:
1506  /*250*/        .word sys64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1507         .word sys_ni_syscall, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1508  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1509 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
1510 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1511  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1512         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1513  /*280*/        .word sys_nis_syscall, sys_add_key, sys_request_key, sys_keyctl
1514 diff -NurpP --minimal linux-2.6.10/arch/sparc64/mm/hugetlbpage.c linux-2.6.10-vs1.9.3.17/arch/sparc64/mm/hugetlbpage.c
1515 --- linux-2.6.10/arch/sparc64/mm/hugetlbpage.c  2004-08-14 12:55:47.000000000 +0200
1516 +++ linux-2.6.10-vs1.9.3.17/arch/sparc64/mm/hugetlbpage.c       2004-12-26 19:40:35.000000000 +0100
1517 @@ -59,7 +59,8 @@ static void set_huge_pte(struct mm_struc
1518         unsigned long i;
1519         pte_t entry;
1520  
1521 -       mm->rss += (HPAGE_SIZE / PAGE_SIZE);
1522 +       // mm->rss += (HPAGE_SIZE / PAGE_SIZE);
1523 +       vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
1524  
1525         if (write_access)
1526                 entry = pte_mkwrite(pte_mkdirty(mk_pte(page,
1527 @@ -112,7 +113,8 @@ int copy_hugetlb_page_range(struct mm_st
1528                         pte_val(entry) += PAGE_SIZE;
1529                         dst_pte++;
1530                 }
1531 -               dst->rss += (HPAGE_SIZE / PAGE_SIZE);
1532 +               // dst->rss += (HPAGE_SIZE / PAGE_SIZE);
1533 +               vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
1534                 addr += HPAGE_SIZE;
1535         }
1536         return 0;
1537 @@ -203,7 +205,8 @@ void unmap_hugepage_range(struct vm_area
1538                         pte++;
1539                 }
1540         }
1541 -       mm->rss -= (end - start) >> PAGE_SHIFT;
1542 +       // mm->rss -= (end - start) >> PAGE_SHIFT;
1543 +       vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
1544         flush_tlb_range(vma, start, end);
1545  }
1546  
1547 diff -NurpP --minimal linux-2.6.10/arch/um/Kconfig linux-2.6.10-vs1.9.3.17/arch/um/Kconfig
1548 --- linux-2.6.10/arch/um/Kconfig        2004-12-25 01:54:50.000000000 +0100
1549 +++ linux-2.6.10-vs1.9.3.17/arch/um/Kconfig     2004-12-26 19:40:23.000000000 +0100
1550 @@ -250,6 +250,8 @@ source "net/Kconfig"
1551  
1552  source "fs/Kconfig"
1553  
1554 +source "kernel/vserver/Kconfig"
1555 +
1556  source "security/Kconfig"
1557  
1558  source "crypto/Kconfig"
1559 diff -NurpP --minimal linux-2.6.10/arch/um/kernel/process_kern.c linux-2.6.10-vs1.9.3.17/arch/um/kernel/process_kern.c
1560 --- linux-2.6.10/arch/um/kernel/process_kern.c  2004-12-25 01:54:50.000000000 +0100
1561 +++ linux-2.6.10-vs1.9.3.17/arch/um/kernel/process_kern.c       2004-12-26 19:40:14.000000000 +0100
1562 @@ -21,6 +21,8 @@
1563  #include "linux/spinlock.h"
1564  #include "linux/proc_fs.h"
1565  #include "linux/ptrace.h"
1566 +#include "linux/vs_cvirt.h"
1567 +
1568  #include "asm/unistd.h"
1569  #include "asm/mman.h"
1570  #include "asm/segment.h"
1571 diff -NurpP --minimal linux-2.6.10/arch/um/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/um/kernel/ptrace.c
1572 --- linux-2.6.10/arch/um/kernel/ptrace.c        2004-12-25 01:54:50.000000000 +0100
1573 +++ linux-2.6.10-vs1.9.3.17/arch/um/kernel/ptrace.c     2004-12-26 19:40:28.000000000 +0100
1574 @@ -55,6 +55,8 @@ long sys_ptrace(long request, long pid, 
1575         read_unlock(&tasklist_lock);
1576         if (!child)
1577                 goto out;
1578 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
1579 +               goto out_tsk;
1580  
1581         ret = -EPERM;
1582         if (pid == 1)           /* you may not mess with init */
1583 diff -NurpP --minimal linux-2.6.10/arch/um/kernel/sys_call_table.c linux-2.6.10-vs1.9.3.17/arch/um/kernel/sys_call_table.c
1584 --- linux-2.6.10/arch/um/kernel/sys_call_table.c        2004-10-23 05:06:02.000000000 +0200
1585 +++ linux-2.6.10-vs1.9.3.17/arch/um/kernel/sys_call_table.c     2004-12-26 19:40:24.000000000 +0100
1586 @@ -51,6 +51,7 @@ extern syscall_handler_t old_mmap_i386;
1587  extern syscall_handler_t old_select;
1588  extern syscall_handler_t sys_modify_ldt;
1589  extern syscall_handler_t sys_rt_sigsuspend;
1590 +extern syscall_handler_t sys_vserver;
1591  
1592  syscall_handler_t *sys_call_table[] = {
1593         [ __NR_restart_syscall ] = (syscall_handler_t *) sys_restart_syscall,
1594 @@ -305,7 +306,7 @@ syscall_handler_t *sys_call_table[] = {
1595         [ __NR_tgkill ] (syscall_handler_t *) sys_tgkill,
1596         [ __NR_utimes ] (syscall_handler_t *) sys_utimes,
1597         [ __NR_fadvise64_64 ] (syscall_handler_t *) sys_fadvise64_64,
1598 -       [ __NR_vserver ] (syscall_handler_t *) sys_ni_syscall,
1599 +       [ __NR_vserver ] (syscall_handler_t *) sys_vserver,
1600  
1601         ARCH_SYSCALLS
1602         [ LAST_SYSCALL + 1 ... NR_syscalls ] = 
1603 diff -NurpP --minimal linux-2.6.10/arch/um/kernel/syscall_kern.c linux-2.6.10-vs1.9.3.17/arch/um/kernel/syscall_kern.c
1604 --- linux-2.6.10/arch/um/kernel/syscall_kern.c  2004-12-25 01:54:50.000000000 +0100
1605 +++ linux-2.6.10-vs1.9.3.17/arch/um/kernel/syscall_kern.c       2004-12-26 19:40:30.000000000 +0100
1606 @@ -15,6 +15,8 @@
1607  #include "linux/unistd.h"
1608  #include "linux/slab.h"
1609  #include "linux/utime.h"
1610 +#include <linux/vs_cvirt.h>
1611 +
1612  #include "asm/mman.h"
1613  #include "asm/uaccess.h"
1614  #include "asm/ipc.h"
1615 @@ -224,7 +226,7 @@ long sys_uname(struct old_utsname * name
1616         if (!name)
1617                 return -EFAULT;
1618         down_read(&uts_sem);
1619 -       err=copy_to_user(name, &system_utsname, sizeof (*name));
1620 +       err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
1621         up_read(&uts_sem);
1622         return err?-EFAULT:0;
1623  }
1624 @@ -232,6 +234,7 @@ long sys_uname(struct old_utsname * name
1625  long sys_olduname(struct oldold_utsname * name)
1626  {
1627         long error;
1628 +       struct new_utsname *ptr;
1629  
1630         if (!name)
1631                 return -EFAULT;
1632 @@ -240,19 +243,20 @@ long sys_olduname(struct oldold_utsname 
1633    
1634         down_read(&uts_sem);
1635         
1636 -       error = __copy_to_user(&name->sysname,&system_utsname.sysname,
1637 +       ptr = vx_new_utsname();
1638 +       error = __copy_to_user(&name->sysname,ptr->sysname,
1639                                __OLD_UTS_LEN);
1640         error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
1641 -       error |= __copy_to_user(&name->nodename,&system_utsname.nodename,
1642 +       error |= __copy_to_user(&name->nodename,ptr->nodename,
1643                                 __OLD_UTS_LEN);
1644         error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
1645 -       error |= __copy_to_user(&name->release,&system_utsname.release,
1646 +       error |= __copy_to_user(&name->release,ptr->release,
1647                                 __OLD_UTS_LEN);
1648         error |= __put_user(0,name->release+__OLD_UTS_LEN);
1649 -       error |= __copy_to_user(&name->version,&system_utsname.version,
1650 +       error |= __copy_to_user(&name->version,ptr->version,
1651                                 __OLD_UTS_LEN);
1652         error |= __put_user(0,name->version+__OLD_UTS_LEN);
1653 -       error |= __copy_to_user(&name->machine,&system_utsname.machine,
1654 +       error |= __copy_to_user(&name->machine,ptr->machine,
1655                                 __OLD_UTS_LEN);
1656         error |= __put_user(0,name->machine+__OLD_UTS_LEN);
1657         
1658 diff -NurpP --minimal linux-2.6.10/arch/v850/Kconfig linux-2.6.10-vs1.9.3.17/arch/v850/Kconfig
1659 --- linux-2.6.10/arch/v850/Kconfig      2004-10-23 05:06:02.000000000 +0200
1660 +++ linux-2.6.10-vs1.9.3.17/arch/v850/Kconfig   2004-12-26 19:40:23.000000000 +0100
1661 @@ -304,6 +304,8 @@ source "drivers/usb/Kconfig"
1662  
1663  source "arch/v850/Kconfig.debug"
1664  
1665 +source "kernel/vserver/Kconfig"
1666 +
1667  source "security/Kconfig"
1668  
1669  source "crypto/Kconfig"
1670 diff -NurpP --minimal linux-2.6.10/arch/v850/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/v850/kernel/ptrace.c
1671 --- linux-2.6.10/arch/v850/kernel/ptrace.c      2004-12-25 01:54:50.000000000 +0100
1672 +++ linux-2.6.10-vs1.9.3.17/arch/v850/kernel/ptrace.c   2004-12-26 19:40:28.000000000 +0100
1673 @@ -138,6 +138,8 @@ int sys_ptrace(long request, long pid, l
1674         read_unlock(&tasklist_lock);
1675         if (!child)
1676                 goto out;
1677 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
1678 +               goto out_tsk;
1679  
1680         rval = -EPERM;
1681         if (pid == 1)           /* you may not mess with init */
1682 diff -NurpP --minimal linux-2.6.10/arch/x86_64/Kconfig linux-2.6.10-vs1.9.3.17/arch/x86_64/Kconfig
1683 --- linux-2.6.10/arch/x86_64/Kconfig    2004-12-25 01:54:50.000000000 +0100
1684 +++ linux-2.6.10-vs1.9.3.17/arch/x86_64/Kconfig 2004-12-26 19:40:23.000000000 +0100
1685 @@ -440,6 +440,8 @@ source "arch/x86_64/oprofile/Kconfig"
1686  
1687  source "arch/x86_64/Kconfig.debug"
1688  
1689 +source "kernel/vserver/Kconfig"
1690 +
1691  source "security/Kconfig"
1692  
1693  source "crypto/Kconfig"
1694 diff -NurpP --minimal linux-2.6.10/arch/x86_64/ia32/ia32_aout.c linux-2.6.10-vs1.9.3.17/arch/x86_64/ia32/ia32_aout.c
1695 --- linux-2.6.10/arch/x86_64/ia32/ia32_aout.c   2004-12-25 01:54:50.000000000 +0100
1696 +++ linux-2.6.10-vs1.9.3.17/arch/x86_64/ia32/ia32_aout.c        2004-12-26 19:40:35.000000000 +0100
1697 @@ -25,6 +25,7 @@
1698  #include <linux/binfmts.h>
1699  #include <linux/personality.h>
1700  #include <linux/init.h>
1701 +#include <linux/vs_memory.h>
1702  
1703  #include <asm/system.h>
1704  #include <asm/uaccess.h>
1705 @@ -310,7 +311,8 @@ static int load_aout_binary(struct linux
1706                 (current->mm->start_brk = N_BSSADDR(ex));
1707         current->mm->free_area_cache = TASK_UNMAPPED_BASE;
1708  
1709 -       current->mm->rss = 0;
1710 +       // current->mm->rss = 0;
1711 +       vx_rsspages_sub(current->mm, current->mm->rss);
1712         current->mm->mmap = NULL;
1713         compute_creds(bprm);
1714         current->flags &= ~PF_FORKNOEXEC;
1715 diff -NurpP --minimal linux-2.6.10/arch/x86_64/ia32/ia32_binfmt.c linux-2.6.10-vs1.9.3.17/arch/x86_64/ia32/ia32_binfmt.c
1716 --- linux-2.6.10/arch/x86_64/ia32/ia32_binfmt.c 2004-12-25 01:54:50.000000000 +0100
1717 +++ linux-2.6.10-vs1.9.3.17/arch/x86_64/ia32/ia32_binfmt.c      2004-12-26 19:40:35.000000000 +0100
1718 @@ -331,7 +331,7 @@ static void elf32_init(struct pt_regs *r
1719  
1720  int setup_arg_pages(struct linux_binprm *bprm, int executable_stack)
1721  {
1722 -       unsigned long stack_base;
1723 +       unsigned long stack_base, grow;
1724         struct vm_area_struct *mpnt;
1725         struct mm_struct *mm = current->mm;
1726         int i, ret;
1727 @@ -348,7 +348,10 @@ int setup_arg_pages(struct linux_binprm 
1728         if (!mpnt) 
1729                 return -ENOMEM; 
1730         
1731 -       if (security_vm_enough_memory((IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))>>PAGE_SHIFT)) {
1732 +       grow = (IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
1733 +               >> PAGE_SHIFT;
1734 +       if (security_vm_enough_memory(grow) ||
1735 +               !vx_vmpages_avail(mm, grow)) {
1736                 kmem_cache_free(vm_area_cachep, mpnt);
1737                 return -ENOMEM;
1738         }
1739 @@ -373,7 +376,9 @@ int setup_arg_pages(struct linux_binprm 
1740                         kmem_cache_free(vm_area_cachep, mpnt);
1741                         return ret;
1742                 }
1743 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
1744 +               // mm->stack_vm = mm->total_vm = vma_pages(mpnt);
1745 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
1746 +               mm->stack_vm = mm->total_vm;
1747         } 
1748  
1749         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
1750 diff -NurpP --minimal linux-2.6.10/arch/x86_64/ia32/ia32entry.S linux-2.6.10-vs1.9.3.17/arch/x86_64/ia32/ia32entry.S
1751 --- linux-2.6.10/arch/x86_64/ia32/ia32entry.S   2004-12-25 01:54:50.000000000 +0100
1752 +++ linux-2.6.10-vs1.9.3.17/arch/x86_64/ia32/ia32entry.S        2004-12-26 19:40:24.000000000 +0100
1753 @@ -575,7 +575,7 @@ ia32_sys_call_table:
1754         .quad sys_tgkill                /* 270 */
1755         .quad compat_sys_utimes
1756         .quad sys32_fadvise64_64
1757 -       .quad quiet_ni_syscall  /* sys_vserver */
1758 +       .quad sys_vserver
1759         .quad sys_mbind
1760         .quad compat_sys_get_mempolicy  /* 275 */
1761         .quad sys_set_mempolicy
1762 diff -NurpP --minimal linux-2.6.10/arch/x86_64/ia32/sys_ia32.c linux-2.6.10-vs1.9.3.17/arch/x86_64/ia32/sys_ia32.c
1763 --- linux-2.6.10/arch/x86_64/ia32/sys_ia32.c    2004-12-25 01:54:50.000000000 +0100
1764 +++ linux-2.6.10-vs1.9.3.17/arch/x86_64/ia32/sys_ia32.c 2004-12-26 19:40:30.000000000 +0100
1765 @@ -924,6 +924,7 @@ asmlinkage long sys32_mmap2(unsigned lon
1766  asmlinkage long sys32_olduname(struct oldold_utsname __user * name)
1767  {
1768         int error;
1769 +       struct new_utsname *ptr;
1770  
1771         if (!name)
1772                 return -EFAULT;
1773 @@ -932,13 +933,14 @@ asmlinkage long sys32_olduname(struct ol
1774    
1775         down_read(&uts_sem);
1776         
1777 -       error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
1778 +       ptr = vx_new_utsname();
1779 +       error = __copy_to_user(&name->sysname,ptr->sysname,__OLD_UTS_LEN);
1780          __put_user(0,name->sysname+__OLD_UTS_LEN);
1781 -        __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
1782 +        __copy_to_user(&name->nodename,ptr->nodename,__OLD_UTS_LEN);
1783          __put_user(0,name->nodename+__OLD_UTS_LEN);
1784 -        __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
1785 +        __copy_to_user(&name->release,ptr->release,__OLD_UTS_LEN);
1786          __put_user(0,name->release+__OLD_UTS_LEN);
1787 -        __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
1788 +        __copy_to_user(&name->version,ptr->version,__OLD_UTS_LEN);
1789          __put_user(0,name->version+__OLD_UTS_LEN);
1790          { 
1791                  char *arch = "x86_64";
1792 @@ -961,7 +963,7 @@ long sys32_uname(struct old_utsname __us
1793         if (!name)
1794                 return -EFAULT;
1795         down_read(&uts_sem);
1796 -       err=copy_to_user(name, &system_utsname, sizeof (*name));
1797 +       err=copy_to_user(name, vx_new_utsname(), sizeof (*name));
1798         up_read(&uts_sem);
1799         if (personality(current->personality) == PER_LINUX32) 
1800                 err |= copy_to_user(&name->machine, "i686", 5);
1801 diff -NurpP --minimal linux-2.6.10/arch/x86_64/kernel/ptrace.c linux-2.6.10-vs1.9.3.17/arch/x86_64/kernel/ptrace.c
1802 --- linux-2.6.10/arch/x86_64/kernel/ptrace.c    2004-12-25 01:54:50.000000000 +0100
1803 +++ linux-2.6.10-vs1.9.3.17/arch/x86_64/kernel/ptrace.c 2004-12-26 19:40:28.000000000 +0100
1804 @@ -209,6 +209,8 @@ asmlinkage long sys_ptrace(long request,
1805         read_unlock(&tasklist_lock);
1806         if (!child)
1807                 goto out;
1808 +       if (!vx_check(vx_task_xid(child), VX_WATCH|VX_IDENT))
1809 +               goto out_tsk;
1810  
1811         ret = -EPERM;
1812         if (pid == 1)           /* you may not mess with init */
1813 diff -NurpP --minimal linux-2.6.10/arch/x86_64/kernel/sys_x86_64.c linux-2.6.10-vs1.9.3.17/arch/x86_64/kernel/sys_x86_64.c
1814 --- linux-2.6.10/arch/x86_64/kernel/sys_x86_64.c        2004-08-14 12:55:35.000000000 +0200
1815 +++ linux-2.6.10-vs1.9.3.17/arch/x86_64/kernel/sys_x86_64.c     2004-12-26 19:40:30.000000000 +0100
1816 @@ -16,6 +16,7 @@
1817  #include <linux/file.h>
1818  #include <linux/utsname.h>
1819  #include <linux/personality.h>
1820 +#include <linux/vs_cvirt.h>
1821  
1822  #include <asm/uaccess.h>
1823  #include <asm/ipc.h>
1824 @@ -146,7 +147,7 @@ asmlinkage long sys_uname(struct new_uts
1825  {
1826         int err;
1827         down_read(&uts_sem);
1828 -       err = copy_to_user(name, &system_utsname, sizeof (*name));
1829 +       err = copy_to_user(name, vx_new_utsname(), sizeof (*name));
1830         up_read(&uts_sem);
1831         if (personality(current->personality) == PER_LINUX32) 
1832                 err |= copy_to_user(&name->machine, "i686", 5);                 
1833 diff -NurpP --minimal linux-2.6.10/drivers/acpi/osl.c linux-2.6.10-vs1.9.3.17/drivers/acpi/osl.c
1834 --- linux-2.6.10/drivers/acpi/osl.c     2004-12-25 01:54:51.000000000 +0100
1835 +++ linux-2.6.10-vs1.9.3.17/drivers/acpi/osl.c  2004-12-26 19:40:36.000000000 +0100
1836 @@ -937,7 +937,7 @@ acpi_os_wait_semaphore(
1837                 // TODO: A better timeout algorithm?
1838                 {
1839                         int i = 0;
1840 -                       static const int quantum_ms = 1000/HZ;
1841 +                       static const int quantum_ms = (HZ>1000)?1:(1000/HZ);
1842  
1843                         ret = down_trylock(sem);
1844                         for (i = timeout; (i > 0 && ret < 0); i -= quantum_ms) {
1845 diff -NurpP --minimal linux-2.6.10/drivers/block/floppy.c linux-2.6.10-vs1.9.3.17/drivers/block/floppy.c
1846 --- linux-2.6.10/drivers/block/floppy.c 2004-12-25 01:54:52.000000000 +0100
1847 +++ linux-2.6.10-vs1.9.3.17/drivers/block/floppy.c      2004-12-26 19:40:36.000000000 +0100
1848 @@ -359,7 +359,11 @@ static int inr;                    /* size of reply buffe
1849  #define R_SECTOR (reply_buffer[5])
1850  #define R_SIZECODE (reply_buffer[6])
1851  
1852 +#if HZ < 12800
1853  #define SEL_DLY (2*HZ/100)
1854 +#else
1855 +#define SEL_DLY (255)
1856 +#endif
1857  
1858  /*
1859   * this struct defines the different floppy drive types.
1860 @@ -4090,7 +4094,7 @@ static void __init daring(int *ints, int
1861                             FD_SILENT_DCL_CLEAR;
1862                 } else {
1863                         default_drive_params[i].params.select_delay =
1864 -                           2 * HZ / 100;
1865 +                           SEL_DLY;
1866                         default_drive_params[i].params.flags &=
1867                             ~FD_SILENT_DCL_CLEAR;
1868                 }
1869 diff -NurpP --minimal linux-2.6.10/drivers/char/dtlk.c linux-2.6.10-vs1.9.3.17/drivers/char/dtlk.c
1870 --- linux-2.6.10/drivers/char/dtlk.c    2004-12-25 01:54:52.000000000 +0100
1871 +++ linux-2.6.10-vs1.9.3.17/drivers/char/dtlk.c 2004-12-26 19:40:36.000000000 +0100
1872 @@ -198,7 +198,7 @@ static ssize_t dtlk_write(struct file *f
1873                                    up to 250 usec for the RDY bit to
1874                                    go nonzero. */
1875                                 for (retries = 0;
1876 -                                    retries < loops_per_jiffy / (4000/HZ);
1877 +                                    retries < HZ*(loops_per_jiffy >> 3)/500;
1878                                      retries++)
1879                                         if (inb_p(dtlk_port_tts) &
1880                                             TTS_WRITABLE)
1881 @@ -445,7 +445,7 @@ for (i = 0; i < 10; i++)                    \
1882                                 LOOK
1883                                 dtlk_write_bytes("\0012I\r", 4);
1884                                 buffer[b++] = 0;
1885 -                               __delay(50 * loops_per_jiffy / (1000/HZ));
1886 +                               __delay(50 * (loops_per_jiffy >> 3) * HZ / 125);
1887                                 outb_p(0xff, dtlk_port_lpc);
1888                                 buffer[b++] = 0;
1889                                 LOOK
1890 diff -NurpP --minimal linux-2.6.10/drivers/char/pcmcia/synclink_cs.c linux-2.6.10-vs1.9.3.17/drivers/char/pcmcia/synclink_cs.c
1891 --- linux-2.6.10/drivers/char/pcmcia/synclink_cs.c      2004-12-25 01:54:53.000000000 +0100
1892 +++ linux-2.6.10-vs1.9.3.17/drivers/char/pcmcia/synclink_cs.c   2004-12-26 19:40:36.000000000 +0100
1893 @@ -571,7 +571,11 @@ static dev_link_t *mgslpc_attach(void)
1894      INIT_WORK(&info->task, bh_handler, info);
1895      info->max_frame_size = 4096;
1896      info->close_delay = 5*HZ/10;
1897 +    #if HZ < 2185
1898      info->closing_wait = 30*HZ;
1899 +    #else
1900 +    info->closing_wait = 65534;
1901 +    #endif
1902      init_waitqueue_head(&info->open_wait);
1903      init_waitqueue_head(&info->close_wait);
1904      init_waitqueue_head(&info->status_event_wait_q);
1905 diff -NurpP --minimal linux-2.6.10/drivers/char/synclink.c linux-2.6.10-vs1.9.3.17/drivers/char/synclink.c
1906 --- linux-2.6.10/drivers/char/synclink.c        2004-12-25 01:54:54.000000000 +0100
1907 +++ linux-2.6.10-vs1.9.3.17/drivers/char/synclink.c     2004-12-26 19:40:36.000000000 +0100
1908 @@ -4378,7 +4378,11 @@ struct mgsl_struct* mgsl_allocate_device
1909                 INIT_WORK(&info->task, mgsl_bh_handler, info);
1910                 info->max_frame_size = 4096;
1911                 info->close_delay = 5*HZ/10;
1912 +               #if HZ < 2185
1913                 info->closing_wait = 30*HZ;
1914 +               #else
1915 +               info->closing_wait = 65534;
1916 +               #endif
1917                 init_waitqueue_head(&info->open_wait);
1918                 init_waitqueue_head(&info->close_wait);
1919                 init_waitqueue_head(&info->status_event_wait_q);
1920 diff -NurpP --minimal linux-2.6.10/drivers/char/synclinkmp.c linux-2.6.10-vs1.9.3.17/drivers/char/synclinkmp.c
1921 --- linux-2.6.10/drivers/char/synclinkmp.c      2004-12-25 01:54:54.000000000 +0100
1922 +++ linux-2.6.10-vs1.9.3.17/drivers/char/synclinkmp.c   2004-12-26 19:40:36.000000000 +0100
1923 @@ -3831,7 +3831,11 @@ SLMP_INFO *alloc_dev(int adapter_num, in
1924                 INIT_WORK(&info->task, bh_handler, info);
1925                 info->max_frame_size = 4096;
1926                 info->close_delay = 5*HZ/10;
1927 +               #if HZ < 2185
1928                 info->closing_wait = 30*HZ;
1929 +               #else
1930 +               info->closing_wait = 65534;
1931 +               #endif
1932                 init_waitqueue_head(&info->open_wait);
1933                 init_waitqueue_head(&info->close_wait);
1934                 init_waitqueue_head(&info->status_event_wait_q);
1935 diff -NurpP --minimal linux-2.6.10/drivers/char/tty_io.c linux-2.6.10-vs1.9.3.17/drivers/char/tty_io.c
1936 --- linux-2.6.10/drivers/char/tty_io.c  2004-12-25 01:54:54.000000000 +0100
1937 +++ linux-2.6.10-vs1.9.3.17/drivers/char/tty_io.c       2004-12-26 19:40:30.000000000 +0100
1938 @@ -102,6 +102,7 @@
1939  #include <linux/vt_kern.h>
1940  #include <linux/selection.h>
1941  #include <linux/devfs_fs_kernel.h>
1942 +#include <linux/vs_cvirt.h>
1943  
1944  #include <linux/kmod.h>
1945  
1946 @@ -2092,13 +2093,16 @@ static int tiocsctty(struct tty_struct *
1947  
1948  static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
1949  {
1950 +       pid_t pgrp;
1951         /*
1952          * (tty == real_tty) is a cheap way of
1953          * testing if the tty is NOT a master pty.
1954          */
1955         if (tty == real_tty && current->signal->tty != real_tty)
1956                 return -ENOTTY;
1957 -       return put_user(real_tty->pgrp, p);
1958 +
1959 +       pgrp = vx_map_pid(real_tty->pgrp);
1960 +       return put_user(pgrp, p);
1961  }
1962  
1963  static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
1964 @@ -2116,6 +2120,8 @@ static int tiocspgrp(struct tty_struct *
1965                 return -ENOTTY;
1966         if (get_user(pgrp, p))
1967                 return -EFAULT;
1968 +
1969 +       pgrp = vx_rmap_pid(pgrp);
1970         if (pgrp < 0)
1971                 return -EINVAL;
1972         if (session_of_pgrp(pgrp) != current->signal->session)
1973 diff -NurpP --minimal linux-2.6.10/drivers/usb/serial/io_edgeport.c linux-2.6.10-vs1.9.3.17/drivers/usb/serial/io_edgeport.c
1974 --- linux-2.6.10/drivers/usb/serial/io_edgeport.c       2004-12-25 01:55:15.000000000 +0100
1975 +++ linux-2.6.10-vs1.9.3.17/drivers/usb/serial/io_edgeport.c    2004-12-26 19:40:36.000000000 +0100
1976 @@ -1817,8 +1817,13 @@ static int get_serial_info(struct edgepo
1977         tmp.flags               = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
1978         tmp.xmit_fifo_size      = edge_port->maxTxCredits;
1979         tmp.baud_base           = 9600;
1980 +       #if HZ < 2185
1981         tmp.close_delay         = 5*HZ;
1982         tmp.closing_wait        = 30*HZ;
1983 +       #else
1984 +       tmp.close_delay         = 2*HZ;
1985 +       tmp.closing_wait        = 65534;
1986 +       #endif
1987  //     tmp.custom_divisor      = state->custom_divisor;
1988  //     tmp.hub6                = state->hub6;
1989  //     tmp.io_type             = state->io_type;
1990 diff -NurpP --minimal linux-2.6.10/fs/attr.c linux-2.6.10-vs1.9.3.17/fs/attr.c
1991 --- linux-2.6.10/fs/attr.c      2004-08-14 12:54:50.000000000 +0200
1992 +++ linux-2.6.10-vs1.9.3.17/fs/attr.c   2004-12-26 19:40:34.000000000 +0100
1993 @@ -14,6 +14,9 @@
1994  #include <linux/fcntl.h>
1995  #include <linux/quotaops.h>
1996  #include <linux/security.h>
1997 +#include <linux/proc_fs.h>
1998 +#include <linux/devpts_fs.h>
1999 +#include <linux/vserver/debug.h>
2000  
2001  /* Taken over from the old code... */
2002  
2003 @@ -55,6 +58,28 @@ int inode_change_ok(struct inode *inode,
2004                 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
2005                         goto error;
2006         }
2007 +
2008 +       /* Check for evil vserver activity */
2009 +       if (vx_check(0, VX_ADMIN))
2010 +               goto fine;
2011 +
2012 +       if (IS_BARRIER(inode)) {
2013 +               vxwprintk(1, "xid=%d messing with the barrier.",
2014 +                       vx_current_xid());
2015 +               goto error;
2016 +       }
2017 +       switch (inode->i_sb->s_magic) {
2018 +               case PROC_SUPER_MAGIC:
2019 +                       vxwprintk(1, "xid=%d messing with the procfs.",
2020 +                               vx_current_xid());
2021 +                       goto error;
2022 +               case DEVPTS_SUPER_MAGIC:
2023 +                       if (vx_check(inode->i_xid, VX_IDENT))
2024 +                               goto fine;
2025 +                       vxwprintk(1, "xid=%d messing with the devpts.",
2026 +                               vx_current_xid());
2027 +                       goto error;
2028 +       }
2029  fine:
2030         retval = 0;
2031  error:
2032 @@ -63,6 +88,24 @@ error:
2033  
2034  EXPORT_SYMBOL(inode_change_ok);
2035  
2036 +int inode_setattr_flags(struct inode *inode, unsigned int flags)
2037 +{
2038 +       unsigned int oldflags, newflags;
2039 +
2040 +       oldflags = inode->i_flags;
2041 +       newflags = oldflags & ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER);
2042 +       if (flags & ATTR_FLAG_IMMUTABLE)
2043 +               newflags |= S_IMMUTABLE;
2044 +       if (flags & ATTR_FLAG_IUNLINK)
2045 +               newflags |= S_IUNLINK;
2046 +       if (flags & ATTR_FLAG_BARRIER)
2047 +               newflags |= S_BARRIER;
2048 +
2049 +       if (oldflags ^ newflags)
2050 +               inode->i_flags = newflags;
2051 +       return 0;
2052 +}
2053 +
2054  int inode_setattr(struct inode * inode, struct iattr * attr)
2055  {
2056         unsigned int ia_valid = attr->ia_valid;
2057 @@ -86,6 +129,8 @@ int inode_setattr(struct inode * inode, 
2058                 inode->i_uid = attr->ia_uid;
2059         if (ia_valid & ATTR_GID)
2060                 inode->i_gid = attr->ia_gid;
2061 +       if (ia_valid & ATTR_XID)
2062 +               inode->i_xid = attr->ia_xid;
2063         if (ia_valid & ATTR_ATIME)
2064                 inode->i_atime = attr->ia_atime;
2065         if (ia_valid & ATTR_MTIME)
2066 @@ -99,6 +144,8 @@ int inode_setattr(struct inode * inode, 
2067                         mode &= ~S_ISGID;
2068                 inode->i_mode = mode;
2069         }
2070 +       if (ia_valid & ATTR_ATTR_FLAG)
2071 +               inode_setattr_flags(inode, attr->ia_attr_flags);
2072         mark_inode_dirty(inode);
2073  out:
2074         return error;
2075 @@ -114,6 +161,8 @@ int setattr_mask(unsigned int ia_valid)
2076                 dn_mask |= DN_ATTRIB;
2077         if (ia_valid & ATTR_GID)
2078                 dn_mask |= DN_ATTRIB;
2079 +       if (ia_valid & ATTR_XID)
2080 +               dn_mask |= DN_ATTRIB;
2081         if (ia_valid & ATTR_SIZE)
2082                 dn_mask |= DN_MODIFY;
2083         /* both times implies a utime(s) call */
2084 @@ -177,7 +226,8 @@ int notify_change(struct dentry * dentry
2085                         error = security_inode_setattr(dentry, attr);
2086                 if (!error) {
2087                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2088 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2089 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2090 +                           (ia_valid & ATTR_XID && attr->ia_xid != inode->i_xid))
2091                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
2092                         if (!error)
2093                                 error = inode_setattr(inode, attr);
2094 diff -NurpP --minimal linux-2.6.10/fs/binfmt_aout.c linux-2.6.10-vs1.9.3.17/fs/binfmt_aout.c
2095 --- linux-2.6.10/fs/binfmt_aout.c       2004-12-25 01:55:19.000000000 +0100
2096 +++ linux-2.6.10-vs1.9.3.17/fs/binfmt_aout.c    2004-12-26 19:40:35.000000000 +0100
2097 @@ -24,6 +24,7 @@
2098  #include <linux/binfmts.h>
2099  #include <linux/personality.h>
2100  #include <linux/init.h>
2101 +#include <linux/vs_memory.h>
2102  
2103  #include <asm/system.h>
2104  #include <asm/uaccess.h>
2105 @@ -314,7 +315,8 @@ static int load_aout_binary(struct linux
2106                 (current->mm->start_brk = N_BSSADDR(ex));
2107         current->mm->free_area_cache = current->mm->mmap_base;
2108  
2109 -       current->mm->rss = 0;
2110 +       // current->mm->rss = 0;
2111 +       vx_rsspages_sub(current->mm, current->mm->rss);
2112         current->mm->mmap = NULL;
2113         compute_creds(bprm);
2114         current->flags &= ~PF_FORKNOEXEC;
2115 diff -NurpP --minimal linux-2.6.10/fs/binfmt_elf.c linux-2.6.10-vs1.9.3.17/fs/binfmt_elf.c
2116 --- linux-2.6.10/fs/binfmt_elf.c        2004-12-25 01:55:19.000000000 +0100
2117 +++ linux-2.6.10-vs1.9.3.17/fs/binfmt_elf.c     2004-12-26 19:40:35.000000000 +0100
2118 @@ -37,6 +37,7 @@
2119  #include <linux/pagemap.h>
2120  #include <linux/security.h>
2121  #include <linux/syscalls.h>
2122 +#include <linux/vs_memory.h>
2123  
2124  #include <asm/uaccess.h>
2125  #include <asm/param.h>
2126 @@ -734,7 +735,8 @@ static int load_elf_binary(struct linux_
2127  
2128         /* Do this so that we can load the interpreter, if need be.  We will
2129            change some of these later */
2130 -       current->mm->rss = 0;
2131 +       // current->mm->rss = 0;
2132 +       vx_rsspages_sub(current->mm, current->mm->rss);
2133         current->mm->free_area_cache = current->mm->mmap_base;
2134         retval = setup_arg_pages(bprm, executable_stack);
2135         if (retval < 0) {
2136 diff -NurpP --minimal linux-2.6.10/fs/binfmt_flat.c linux-2.6.10-vs1.9.3.17/fs/binfmt_flat.c
2137 --- linux-2.6.10/fs/binfmt_flat.c       2004-12-25 01:55:19.000000000 +0100
2138 +++ linux-2.6.10-vs1.9.3.17/fs/binfmt_flat.c    2004-12-26 19:40:35.000000000 +0100
2139 @@ -36,6 +36,7 @@
2140  #include <linux/personality.h>
2141  #include <linux/init.h>
2142  #include <linux/flat.h>
2143 +#include <linux/vs_memory.h>
2144  
2145  #include <asm/byteorder.h>
2146  #include <asm/system.h>
2147 @@ -650,7 +651,8 @@ static int load_flat_file(struct linux_b
2148                 current->mm->start_brk = datapos + data_len + bss_len;
2149                 current->mm->brk = (current->mm->start_brk + 3) & ~3;
2150                 current->mm->context.end_brk = memp + ksize((void *) memp) - stack_len;
2151 -               current->mm->rss = 0;
2152 +               // current->mm->rss = 0;
2153 +               vx_rsspages_sub(current->mm, current->mm->rss);
2154         }
2155  
2156         if (flags & FLAT_FLAG_KTRACE)
2157 diff -NurpP --minimal linux-2.6.10/fs/binfmt_som.c linux-2.6.10-vs1.9.3.17/fs/binfmt_som.c
2158 --- linux-2.6.10/fs/binfmt_som.c        2004-08-14 12:55:19.000000000 +0200
2159 +++ linux-2.6.10-vs1.9.3.17/fs/binfmt_som.c     2004-12-26 19:40:35.000000000 +0100
2160 @@ -28,6 +28,7 @@
2161  #include <linux/shm.h>
2162  #include <linux/personality.h>
2163  #include <linux/init.h>
2164 +#include <linux/vs_memory.h>
2165  
2166  #include <asm/uaccess.h>
2167  #include <asm/pgtable.h>
2168 @@ -259,7 +260,8 @@ load_som_binary(struct linux_binprm * bp
2169         create_som_tables(bprm);
2170  
2171         current->mm->start_stack = bprm->p;
2172 -       current->mm->rss = 0;
2173 +       // current->mm->rss = 0;
2174 +       vx_rsspages_sub(current->mm, current->mm->rss);
2175  
2176  #if 0
2177         printk("(start_brk) %08lx\n" , (unsigned long) current->mm->start_brk);
2178 diff -NurpP --minimal linux-2.6.10/fs/devpts/inode.c linux-2.6.10-vs1.9.3.17/fs/devpts/inode.c
2179 --- linux-2.6.10/fs/devpts/inode.c      2004-12-25 01:55:20.000000000 +0100
2180 +++ linux-2.6.10-vs1.9.3.17/fs/devpts/inode.c   2004-12-26 19:40:30.000000000 +0100
2181 @@ -31,6 +31,15 @@ static struct xattr_handler *devpts_xatt
2182         NULL
2183  };
2184  
2185 +static int devpts_permission(struct inode *inode, int mask, struct nameidata *nd)
2186 +{
2187 +       int ret = -EACCES;
2188 +
2189 +       if (vx_check(inode->i_xid, VX_IDENT))
2190 +               ret = generic_permission(inode, mask, NULL);
2191 +       return ret;
2192 +}
2193 +
2194  struct inode_operations devpts_file_inode_operations = {
2195  #ifdef CONFIG_DEVPTS_FS_XATTR
2196         .setxattr       = generic_setxattr,
2197 @@ -38,6 +47,7 @@ struct inode_operations devpts_file_inod
2198         .listxattr      = generic_listxattr,
2199         .removexattr    = generic_removexattr,
2200  #endif
2201 +       .permission     = devpts_permission,
2202  };
2203  
2204  static struct vfsmount *devpts_mnt;
2205 @@ -88,6 +98,68 @@ static int devpts_remount(struct super_b
2206         return 0;
2207  }
2208  
2209 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2210 +{
2211 +       struct dentry *dentry = filp->f_dentry;
2212 +       struct dentry *cursor = filp->private_data;
2213 +       struct list_head *p, *q = &cursor->d_child;
2214 +       ino_t ino;
2215 +       int i = filp->f_pos;
2216 +
2217 +       switch (i) {
2218 +               case 0:
2219 +                       ino = dentry->d_inode->i_ino;
2220 +                       if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
2221 +                               break;
2222 +                       filp->f_pos++;
2223 +                       i++;
2224 +                       /* fallthrough */
2225 +               case 1:
2226 +                       ino = parent_ino(dentry);
2227 +                       if (filldir(dirent, "..", 2, i, ino, DT_DIR) < 0)
2228 +                               break;
2229 +                       filp->f_pos++;
2230 +                       i++;
2231 +                       /* fallthrough */
2232 +               default:
2233 +                       spin_lock(&dcache_lock);
2234 +                       if (filp->f_pos == 2) {
2235 +                               list_del(q);
2236 +                               list_add(q, &dentry->d_subdirs);
2237 +                       }
2238 +                       for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
2239 +                               struct dentry *next;
2240 +                               next = list_entry(p, struct dentry, d_child);
2241 +                               if (d_unhashed(next) || !next->d_inode)
2242 +                                       continue;
2243 +                               if (!vx_check(next->d_inode->i_xid, VX_IDENT))
2244 +                                       continue;
2245 +
2246 +                               spin_unlock(&dcache_lock);
2247 +                               if (filldir(dirent, next->d_name.name,
2248 +                                       next->d_name.len, filp->f_pos,
2249 +                                       next->d_inode->i_ino, DT_CHR) < 0)
2250 +                                       return 0;
2251 +                               spin_lock(&dcache_lock);
2252 +                               /* next is still alive */
2253 +                               list_del(q);
2254 +                               list_add(q, p);
2255 +                               p = q;
2256 +                               filp->f_pos++;
2257 +                       }
2258 +                       spin_unlock(&dcache_lock);
2259 +       }
2260 +       return 0;
2261 +}
2262 +
2263 +static struct file_operations devpts_dir_operations = {
2264 +       .open           = dcache_dir_open,
2265 +       .release        = dcache_dir_close,
2266 +       .llseek         = dcache_dir_lseek,
2267 +       .read           = generic_read_dir,
2268 +       .readdir        = devpts_readdir,
2269 +};
2270 +
2271  static struct super_operations devpts_sops = {
2272         .statfs         = simple_statfs,
2273         .remount_fs     = devpts_remount,
2274 @@ -114,8 +186,9 @@ devpts_fill_super(struct super_block *s,
2275         inode->i_uid = inode->i_gid = 0;
2276         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2277         inode->i_op = &simple_dir_inode_operations;
2278 -       inode->i_fop = &simple_dir_operations;
2279 +       inode->i_fop = &devpts_dir_operations;
2280         inode->i_nlink = 2;
2281 +       inode->i_xid = vx_current_xid();
2282  
2283         devpts_root = s->s_root = d_alloc_root(inode);
2284         if (s->s_root)
2285 @@ -174,6 +247,7 @@ int devpts_pty_new(struct tty_struct *tt
2286         inode->i_gid = config.setgid ? config.gid : current->fsgid;
2287         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2288         init_special_inode(inode, S_IFCHR|config.mode, device);
2289 +       inode->i_xid = vx_current_xid();
2290         inode->i_op = &devpts_file_inode_operations;
2291         inode->u.generic_ip = tty;
2292  
2293 diff -NurpP --minimal linux-2.6.10/fs/exec.c linux-2.6.10-vs1.9.3.17/fs/exec.c
2294 --- linux-2.6.10/fs/exec.c      2004-12-25 01:55:20.000000000 +0100
2295 +++ linux-2.6.10-vs1.9.3.17/fs/exec.c   2004-12-26 19:40:35.000000000 +0100
2296 @@ -47,6 +47,7 @@
2297  #include <linux/security.h>
2298  #include <linux/syscalls.h>
2299  #include <linux/rmap.h>
2300 +#include <linux/vs_memory.h>
2301  
2302  #include <asm/uaccess.h>
2303  #include <asm/mmu_context.h>
2304 @@ -320,7 +321,8 @@ void install_arg_page(struct vm_area_str
2305                 pte_unmap(pte);
2306                 goto out;
2307         }
2308 -       mm->rss++;
2309 +       // mm->rss++;
2310 +       vx_rsspages_inc(mm);
2311         lru_cache_add_active(page);
2312         set_pte(pte, pte_mkdirty(pte_mkwrite(mk_pte(
2313                                         page, vma->vm_page_prot))));
2314 @@ -404,7 +406,8 @@ int setup_arg_pages(struct linux_binprm 
2315         if (!mpnt)
2316                 return -ENOMEM;
2317  
2318 -       if (security_vm_enough_memory(arg_size >> PAGE_SHIFT)) {
2319 +       if (security_vm_enough_memory(arg_size >> PAGE_SHIFT) ||
2320 +               !vx_vmpages_avail(mm, arg_size >> PAGE_SHIFT)) {
2321                 kmem_cache_free(vm_area_cachep, mpnt);
2322                 return -ENOMEM;
2323         }
2324 @@ -438,7 +441,9 @@ int setup_arg_pages(struct linux_binprm 
2325                         kmem_cache_free(vm_area_cachep, mpnt);
2326                         return ret;
2327                 }
2328 -               mm->stack_vm = mm->total_vm = vma_pages(mpnt);
2329 +               // mm->stack_vm = mm->total_vm = vma_pages(mpnt);
2330 +               vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
2331 +               mm->stack_vm = mm->total_vm;
2332         }
2333  
2334         for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
2335 diff -NurpP --minimal linux-2.6.10/fs/ext2/balloc.c linux-2.6.10-vs1.9.3.17/fs/ext2/balloc.c
2336 --- linux-2.6.10/fs/ext2/balloc.c       2004-10-23 05:06:16.000000000 +0200
2337 +++ linux-2.6.10-vs1.9.3.17/fs/ext2/balloc.c    2004-12-26 19:40:35.000000000 +0100
2338 @@ -16,6 +16,7 @@
2339  #include <linux/quotaops.h>
2340  #include <linux/sched.h>
2341  #include <linux/buffer_head.h>
2342 +#include <linux/vs_dlimit.h>
2343  
2344  /*
2345   * balloc.c contains the blocks allocation and deallocation routines
2346 @@ -108,6 +109,8 @@ static int reserve_blocks(struct super_b
2347         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2348         root_blocks = le32_to_cpu(es->s_r_blocks_count);
2349  
2350 +       DLIMIT_ADJUST_BLOCK(sb, vx_current_xid(), &free_blocks, &root_blocks);
2351 +
2352         if (free_blocks < count)
2353                 count = free_blocks;
2354  
2355 @@ -258,6 +261,7 @@ do_more:
2356         }
2357  error_return:
2358         brelse(bitmap_bh);
2359 +       DLIMIT_FREE_BLOCK(sb, inode->i_xid, freed);
2360         release_blocks(sb, freed);
2361         DQUOT_FREE_BLOCK(inode, freed);
2362  }
2363 @@ -361,6 +365,10 @@ int ext2_new_block(struct inode *inode, 
2364                 *err = -ENOSPC;
2365                 goto out_dquot;
2366         }
2367 +       if (DLIMIT_ALLOC_BLOCK(sb, inode->i_xid, es_alloc)) {
2368 +               *err = -ENOSPC;
2369 +               goto out_dlimit;
2370 +       }
2371  
2372         ext2_debug ("goal=%lu.\n", goal);
2373  
2374 @@ -508,6 +516,8 @@ got_block:
2375         *err = 0;
2376  out_release:
2377         group_release_blocks(sb, group_no, desc, gdp_bh, group_alloc);
2378 +       DLIMIT_FREE_BLOCK(sb, inode->i_xid, es_alloc);
2379 +out_dlimit:
2380         release_blocks(sb, es_alloc);
2381  out_dquot:
2382         DQUOT_FREE_BLOCK(inode, dq_alloc);
2383 diff -NurpP --minimal linux-2.6.10/fs/ext2/ialloc.c linux-2.6.10-vs1.9.3.17/fs/ext2/ialloc.c
2384 --- linux-2.6.10/fs/ext2/ialloc.c       2004-10-23 05:06:16.000000000 +0200
2385 +++ linux-2.6.10-vs1.9.3.17/fs/ext2/ialloc.c    2004-12-26 19:40:35.000000000 +0100
2386 @@ -18,6 +18,8 @@
2387  #include <linux/backing-dev.h>
2388  #include <linux/buffer_head.h>
2389  #include <linux/random.h>
2390 +#include <linux/vs_dlimit.h>
2391 +
2392  #include "ext2.h"
2393  #include "xattr.h"
2394  #include "acl.h"
2395 @@ -124,6 +126,7 @@ void ext2_free_inode (struct inode * ino
2396         if (!is_bad_inode(inode)) {
2397                 /* Quota is already initialized in iput() */
2398                 ext2_xattr_delete_inode(inode);
2399 +               DLIMIT_FREE_INODE(sb, inode->i_xid);
2400                 DQUOT_FREE_INODE(inode);
2401                 DQUOT_DROP(inode);
2402         }
2403 @@ -465,6 +468,15 @@ struct inode *ext2_new_inode(struct inod
2404         if (!inode)
2405                 return ERR_PTR(-ENOMEM);
2406  
2407 +       if (sb->s_flags & MS_TAGXID)
2408 +               inode->i_xid = vx_current_xid();
2409 +       else
2410 +               inode->i_xid = 0;
2411 +
2412 +       if (DLIMIT_ALLOC_INODE(sb, inode->i_xid)) {
2413 +               err = -ENOSPC;
2414 +               goto fail_dlim;
2415 +       }
2416         ei = EXT2_I(inode);
2417         sbi = EXT2_SB(sb);
2418         es = sbi->s_es;
2419 @@ -579,7 +591,8 @@ got:
2420         inode->i_blocks = 0;
2421         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2422         memset(ei->i_data, 0, sizeof(ei->i_data));
2423 -       ei->i_flags = EXT2_I(dir)->i_flags & ~EXT2_BTREE_FL;
2424 +       ei->i_flags = EXT2_I(dir)->i_flags &
2425 +               ~(EXT2_BTREE_FL|EXT2_IUNLINK_FL|EXT2_BARRIER_FL);
2426         if (S_ISLNK(mode))
2427                 ei->i_flags &= ~(EXT2_IMMUTABLE_FL|EXT2_APPEND_FL);
2428         /* dirsync is only applied to directories */
2429 @@ -620,12 +633,15 @@ got:
2430         return inode;
2431  
2432  fail2:
2433 +       DLIMIT_FREE_INODE(sb, inode->i_xid);
2434         inode->i_flags |= S_NOQUOTA;
2435         inode->i_nlink = 0;
2436         iput(inode);
2437         return ERR_PTR(err);
2438  
2439  fail:
2440 +       DLIMIT_FREE_INODE(sb, inode->i_xid);
2441 +fail_dlim:
2442         make_bad_inode(inode);
2443         iput(inode);
2444         return ERR_PTR(err);
2445 diff -NurpP --minimal linux-2.6.10/fs/ext2/inode.c linux-2.6.10-vs1.9.3.17/fs/ext2/inode.c
2446 --- linux-2.6.10/fs/ext2/inode.c        2004-12-25 01:55:20.000000000 +0100
2447 +++ linux-2.6.10-vs1.9.3.17/fs/ext2/inode.c     2004-12-26 19:40:34.000000000 +0100
2448 @@ -31,6 +31,7 @@
2449  #include <linux/writeback.h>
2450  #include <linux/buffer_head.h>
2451  #include <linux/mpage.h>
2452 +#include <linux/vserver/xid.h>
2453  #include "ext2.h"
2454  #include "acl.h"
2455  
2456 @@ -52,6 +53,8 @@ static inline int ext2_inode_is_fast_sym
2457                 inode->i_blocks - ea_blocks == 0);
2458  }
2459  
2460 +static void ext2_truncate_nocheck (struct inode * inode);
2461 +
2462  /*
2463   * Called at the last iput() if i_nlink is zero.
2464   */
2465 @@ -65,7 +68,7 @@ void ext2_delete_inode (struct inode * i
2466  
2467         inode->i_size = 0;
2468         if (inode->i_blocks)
2469 -               ext2_truncate (inode);
2470 +               ext2_truncate_nocheck(inode);
2471         ext2_free_inode (inode);
2472  
2473         return;
2474 @@ -865,7 +868,7 @@ static void ext2_free_branches(struct in
2475                 ext2_free_data(inode, p, q);
2476  }
2477  
2478 -void ext2_truncate (struct inode * inode)
2479 +static void ext2_truncate_nocheck(struct inode * inode)
2480  {
2481         __le32 *i_data = EXT2_I(inode)->i_data;
2482         int addr_per_block = EXT2_ADDR_PER_BLOCK(inode->i_sb);
2483 @@ -882,8 +885,6 @@ void ext2_truncate (struct inode * inode
2484                 return;
2485         if (ext2_inode_is_fast_symlink(inode))
2486                 return;
2487 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2488 -               return;
2489  
2490         ext2_discard_prealloc(inode);
2491  
2492 @@ -1005,17 +1006,28 @@ Egdp:
2493         return ERR_PTR(-EIO);
2494  }
2495  
2496 +void ext2_truncate (struct inode * inode)
2497 +{
2498 +       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2499 +               return;
2500 +       ext2_truncate_nocheck(inode);
2501 +}
2502 +
2503  void ext2_set_inode_flags(struct inode *inode)
2504  {
2505         unsigned int flags = EXT2_I(inode)->i_flags;
2506  
2507 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2508 +       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_IUNLINK|S_BARRIER|S_NOATIME|S_DIRSYNC);
2509         if (flags & EXT2_SYNC_FL)
2510                 inode->i_flags |= S_SYNC;
2511         if (flags & EXT2_APPEND_FL)
2512                 inode->i_flags |= S_APPEND;
2513         if (flags & EXT2_IMMUTABLE_FL)
2514                 inode->i_flags |= S_IMMUTABLE;
2515 +       if (flags & EXT2_IUNLINK_FL)
2516 +               inode->i_flags |= S_IUNLINK;
2517 +       if (flags & EXT2_BARRIER_FL)
2518 +               inode->i_flags |= S_BARRIER;
2519         if (flags & EXT2_NOATIME_FL)
2520                 inode->i_flags |= S_NOATIME;
2521         if (flags & EXT2_DIRSYNC_FL)
2522 @@ -1028,6 +1040,8 @@ void ext2_read_inode (struct inode * ino
2523         ino_t ino = inode->i_ino;
2524         struct buffer_head * bh;
2525         struct ext2_inode * raw_inode = ext2_get_inode(inode->i_sb, ino, &bh);
2526 +       uid_t uid;
2527 +       gid_t gid;
2528         int n;
2529  
2530  #ifdef CONFIG_EXT2_FS_POSIX_ACL
2531 @@ -1038,12 +1052,17 @@ void ext2_read_inode (struct inode * ino
2532                 goto bad_inode;
2533  
2534         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2535 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2536 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2537 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2538 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2539         if (!(test_opt (inode->i_sb, NO_UID32))) {
2540 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2541 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2542 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2543 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2544         }
2545 +       inode->i_uid = INOXID_UID(XID_TAG(inode), uid, gid);
2546 +       inode->i_gid = INOXID_GID(XID_TAG(inode), uid, gid);
2547 +       inode->i_xid = INOXID_XID(XID_TAG(inode), uid, gid,
2548 +               le16_to_cpu(raw_inode->i_raw_xid));
2549 +
2550         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2551         inode->i_size = le32_to_cpu(raw_inode->i_size);
2552         inode->i_atime.tv_sec = le32_to_cpu(raw_inode->i_atime);
2553 @@ -1136,8 +1155,8 @@ static int ext2_update_inode(struct inod
2554         struct ext2_inode_info *ei = EXT2_I(inode);
2555         struct super_block *sb = inode->i_sb;
2556         ino_t ino = inode->i_ino;
2557 -       uid_t uid = inode->i_uid;
2558 -       gid_t gid = inode->i_gid;
2559 +       uid_t uid = XIDINO_UID(XID_TAG(inode), inode->i_uid, inode->i_xid);
2560 +       gid_t gid = XIDINO_GID(XID_TAG(inode), inode->i_gid, inode->i_xid);
2561         struct buffer_head * bh;
2562         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2563         int n;
2564 @@ -1172,6 +1191,9 @@ static int ext2_update_inode(struct inod
2565                 raw_inode->i_uid_high = 0;
2566                 raw_inode->i_gid_high = 0;
2567         }
2568 +#ifdef CONFIG_INOXID_INTERN
2569 +       raw_inode->i_raw_xid = cpu_to_le16(inode->i_xid);
2570 +#endif
2571         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2572         raw_inode->i_size = cpu_to_le32(inode->i_size);
2573         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2574 @@ -1249,6 +1271,27 @@ int ext2_sync_inode(struct inode *inode)
2575         return sync_inode(inode, &wbc);
2576  }
2577  
2578 +int ext2_setattr_flags(struct inode *inode, unsigned int flags)
2579 +{
2580 +       unsigned int oldflags, newflags;
2581 +
2582 +       oldflags = EXT2_I(inode)->i_flags;
2583 +       newflags = oldflags &
2584 +               ~(EXT2_IMMUTABLE_FL | EXT2_IUNLINK_FL | EXT2_BARRIER_FL);
2585 +       if (flags & ATTR_FLAG_IMMUTABLE)
2586 +               newflags |= EXT2_IMMUTABLE_FL;
2587 +       if (flags & ATTR_FLAG_IUNLINK)
2588 +               newflags |= EXT2_IUNLINK_FL;
2589 +       if (flags & ATTR_FLAG_BARRIER)
2590 +               newflags |= EXT2_BARRIER_FL;
2591 +
2592 +       if (oldflags ^ newflags) {
2593 +               EXT2_I(inode)->i_flags = newflags;
2594 +               inode->i_ctime = CURRENT_TIME;
2595 +       }
2596 +       return 0;
2597 +}
2598 +
2599  int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
2600  {
2601         struct inode *inode = dentry->d_inode;
2602 @@ -1258,11 +1301,15 @@ int ext2_setattr(struct dentry *dentry, 
2603         if (error)
2604                 return error;
2605         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2606 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2607 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2608 +           (iattr->ia_valid & ATTR_XID && iattr->ia_xid != inode->i_xid)) {
2609                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
2610                 if (error)
2611                         return error;
2612         }
2613 +       if (iattr->ia_valid & ATTR_ATTR_FLAG)
2614 +               ext2_setattr_flags(inode, iattr->ia_attr_flags);
2615 +
2616         error = inode_setattr(inode, iattr);
2617         if (!error && (iattr->ia_valid & ATTR_MODE))
2618                 error = ext2_acl_chmod(inode);
2619 diff -NurpP --minimal linux-2.6.10/fs/ext2/ioctl.c linux-2.6.10-vs1.9.3.17/fs/ext2/ioctl.c
2620 --- linux-2.6.10/fs/ext2/ioctl.c        2004-08-14 12:56:24.000000000 +0200
2621 +++ linux-2.6.10-vs1.9.3.17/fs/ext2/ioctl.c     2004-12-26 19:40:30.000000000 +0100
2622 @@ -49,7 +49,9 @@ int ext2_ioctl (struct inode * inode, st
2623                  *
2624                  * This test looks nicer. Thanks to Pauline Middelink
2625                  */
2626 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2627 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2628 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2629 +                       EXT2_IMMUTABLE_FL | EXT2_IUNLINK_FL))) {
2630                         if (!capable(CAP_LINUX_IMMUTABLE))
2631                                 return -EPERM;
2632                 }
2633 diff -NurpP --minimal linux-2.6.10/fs/ext2/namei.c linux-2.6.10-vs1.9.3.17/fs/ext2/namei.c
2634 --- linux-2.6.10/fs/ext2/namei.c        2004-12-25 01:55:20.000000000 +0100
2635 +++ linux-2.6.10-vs1.9.3.17/fs/ext2/namei.c     2004-12-26 19:40:34.000000000 +0100
2636 @@ -31,6 +31,7 @@
2637   */
2638  
2639  #include <linux/pagemap.h>
2640 +#include <linux/vserver/xid.h>
2641  #include "ext2.h"
2642  #include "xattr.h"
2643  #include "acl.h"
2644 @@ -81,6 +82,7 @@ static struct dentry *ext2_lookup(struct
2645                 inode = iget(dir->i_sb, ino);
2646                 if (!inode)
2647                         return ERR_PTR(-EACCES);
2648 +               vx_propagate_xid(nd, inode);
2649         }
2650         if (inode)
2651                 return d_splice_alias(inode, dentry);
2652 diff -NurpP --minimal linux-2.6.10/fs/ext2/super.c linux-2.6.10-vs1.9.3.17/fs/ext2/super.c
2653 --- linux-2.6.10/fs/ext2/super.c        2004-12-25 01:55:20.000000000 +0100
2654 +++ linux-2.6.10-vs1.9.3.17/fs/ext2/super.c     2004-12-26 19:40:34.000000000 +0100
2655 @@ -250,7 +250,7 @@ enum {
2656         Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
2657         Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
2658         Opt_nouid32, Opt_check, Opt_nocheck, Opt_debug, Opt_oldalloc, Opt_orlov, Opt_nobh,
2659 -       Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
2660 +       Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, Opt_tagxid,
2661         Opt_ignore, Opt_err,
2662  };
2663  
2664 @@ -279,6 +279,7 @@ static match_table_t tokens = {
2665         {Opt_nouser_xattr, "nouser_xattr"},
2666         {Opt_acl, "acl"},
2667         {Opt_noacl, "noacl"},
2668 +       {Opt_tagxid, "tagxid"},
2669         {Opt_ignore, "grpquota"},
2670         {Opt_ignore, "noquota"},
2671         {Opt_ignore, "quota"},
2672 @@ -342,6 +343,11 @@ static int parse_options (char * options
2673                 case Opt_nouid32:
2674                         set_opt (sbi->s_mount_opt, NO_UID32);
2675                         break;
2676 +#ifndef CONFIG_INOXID_NONE
2677 +               case Opt_tagxid:
2678 +                       set_opt (sbi->s_mount_opt, TAG_XID);
2679 +                       break;
2680 +#endif
2681                 case Opt_check:
2682  #ifdef CONFIG_EXT2_CHECK
2683                         set_opt (sbi->s_mount_opt, CHECK);
2684 @@ -624,6 +630,8 @@ static int ext2_fill_super(struct super_
2685         if (!parse_options ((char *) data, sbi))
2686                 goto failed_mount;
2687  
2688 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAG_XID)
2689 +               sb->s_flags |= MS_TAGXID;
2690         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2691                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2692                  MS_POSIXACL : 0);
2693 diff -NurpP --minimal linux-2.6.10/fs/ext2/xattr.c linux-2.6.10-vs1.9.3.17/fs/ext2/xattr.c
2694 --- linux-2.6.10/fs/ext2/xattr.c        2004-12-25 01:55:20.000000000 +0100
2695 +++ linux-2.6.10-vs1.9.3.17/fs/ext2/xattr.c     2004-12-26 19:40:35.000000000 +0100
2696 @@ -60,6 +60,7 @@
2697  #include <linux/mbcache.h>
2698  #include <linux/quotaops.h>
2699  #include <linux/rwsem.h>
2700 +#include <linux/vs_dlimit.h>
2701  #include "ext2.h"
2702  #include "xattr.h"
2703  #include "acl.h"
2704 @@ -643,8 +644,12 @@ ext2_xattr_set2(struct inode *inode, str
2705                                    the inode.  */
2706                                 ea_bdebug(new_bh, "reusing block");
2707  
2708 +                               error = -ENOSPC;
2709 +                               if (DLIMIT_ALLOC_BLOCK(sb, inode->i_xid, 1))
2710 +                                       goto cleanup;
2711                                 error = -EDQUOT;
2712                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
2713 +                                       DLIMIT_FREE_BLOCK(sb, inode->i_xid, 1);
2714                                         unlock_buffer(new_bh);
2715                                         goto cleanup;
2716                                 }
2717 @@ -724,6 +729,7 @@ ext2_xattr_set2(struct inode *inode, str
2718                         /* Decrement the refcount only. */
2719                         HDR(old_bh)->h_refcount = cpu_to_le32(
2720                                 le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
2721 +                       DLIMIT_FREE_BLOCK(sb, inode->i_xid, 1);
2722                         DQUOT_FREE_BLOCK(inode, 1);
2723                         mark_buffer_dirty(old_bh);
2724                         ea_bdebug(old_bh, "refcount now=%d",
2725 @@ -779,6 +785,7 @@ ext2_xattr_delete_inode(struct inode *in
2726                 mark_buffer_dirty(bh);
2727                 if (IS_SYNC(inode))
2728                         sync_dirty_buffer(bh);
2729 +               DLIMIT_FREE_BLOCK(inode->i_sb, inode->i_xid, 1);
2730                 DQUOT_FREE_BLOCK(inode, 1);
2731         }
2732         ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
2733 diff -NurpP --minimal linux-2.6.10/fs/ext3/balloc.c linux-2.6.10-vs1.9.3.17/fs/ext3/balloc.c
2734 --- linux-2.6.10/fs/ext3/balloc.c       2004-12-25 01:55:20.000000000 +0100
2735 +++ linux-2.6.10-vs1.9.3.17/fs/ext3/balloc.c    2004-12-26 19:40:35.000000000 +0100
2736 @@ -19,6 +19,7 @@
2737  #include <linux/ext3_jbd.h>
2738  #include <linux/quotaops.h>
2739  #include <linux/buffer_head.h>
2740 +#include <linux/vs_dlimit.h>
2741  
2742  /*
2743   * balloc.c contains the blocks allocation and deallocation routines
2744 @@ -462,8 +463,10 @@ void ext3_free_blocks(handle_t *handle, 
2745                 return;
2746         }
2747         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
2748 -       if (dquot_freed_blocks)
2749 +       if (dquot_freed_blocks) {
2750 +               DLIMIT_FREE_BLOCK(sb, inode->i_xid, dquot_freed_blocks);
2751                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
2752 +       }
2753         return;
2754  }
2755  
2756 @@ -1091,18 +1094,32 @@ out:
2757         return ret;
2758  }
2759  
2760 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
2761 +static int ext3_has_free_blocks(struct super_block *sb)
2762  {
2763 -       int free_blocks, root_blocks;
2764 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
2765 +       int free_blocks, root_blocks, cond;
2766  
2767         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2768         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
2769 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
2770 +
2771 +       vxdprintk(VXD_CBIT(dlim, 3),
2772 +               "ext3_has_free_blocks(%p): free=%u, root=%u",
2773 +               sb, free_blocks, root_blocks);
2774 +
2775 +       DLIMIT_ADJUST_BLOCK(sb, vx_current_xid(), &free_blocks, &root_blocks);
2776 +
2777 +       cond = (free_blocks < root_blocks + 1 &&
2778 +               !capable(CAP_SYS_RESOURCE) &&
2779                 sbi->s_resuid != current->fsuid &&
2780 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
2781 -               return 0;
2782 -       }
2783 -       return 1;
2784 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
2785 +
2786 +       vxdprintk(VXD_CBIT(dlim, 3),
2787 +               "ext3_has_free_blocks(%p): %u<%u+1, %c, %u!=%u r=%d",
2788 +               sb, free_blocks, root_blocks,
2789 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
2790 +               sbi->s_resuid, current->fsuid, cond?0:1);
2791 +
2792 +       return (cond ? 0 : 1);
2793  }
2794  
2795  /*
2796 @@ -1113,7 +1130,7 @@ static int ext3_has_free_blocks(struct e
2797   */
2798  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
2799  {
2800 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
2801 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
2802                 return 0;
2803  
2804         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
2805 @@ -1168,6 +1185,8 @@ int ext3_new_block(handle_t *handle, str
2806                 *errp = -EDQUOT;
2807                 return 0;
2808         }
2809 +       if (DLIMIT_ALLOC_BLOCK(sb, inode->i_xid, 1))
2810 +               goto out_dlimit;
2811  
2812         sbi = EXT3_SB(sb);
2813         es = EXT3_SB(sb)->s_es;
2814 @@ -1184,7 +1203,7 @@ int ext3_new_block(handle_t *handle, str
2815         if (test_opt(sb, RESERVATION) &&
2816                 S_ISREG(inode->i_mode) && (windowsz > 0))
2817                 my_rsv = rsv;
2818 -       if (!ext3_has_free_blocks(sbi)) {
2819 +       if (!ext3_has_free_blocks(sb)) {
2820                 *errp = -ENOSPC;
2821                 goto out;
2822         }
2823 @@ -1360,6 +1379,9 @@ allocated:
2824  io_error:
2825         *errp = -EIO;
2826  out:
2827 +       if (!performed_allocation)
2828 +               DLIMIT_FREE_BLOCK(sb, inode->i_xid, 1);
2829 +out_dlimit:
2830         if (fatal) {
2831                 *errp = fatal;
2832                 ext3_std_error(sb, fatal);
2833 diff -NurpP --minimal linux-2.6.10/fs/ext3/ialloc.c linux-2.6.10-vs1.9.3.17/fs/ext3/ialloc.c
2834 --- linux-2.6.10/fs/ext3/ialloc.c       2004-12-25 01:55:20.000000000 +0100
2835 +++ linux-2.6.10-vs1.9.3.17/fs/ext3/ialloc.c    2004-12-26 19:40:35.000000000 +0100
2836 @@ -23,6 +23,7 @@
2837  #include <linux/buffer_head.h>
2838  #include <linux/random.h>
2839  #include <linux/bitops.h>
2840 +#include <linux/vs_dlimit.h>
2841  
2842  #include <asm/byteorder.h>
2843  
2844 @@ -125,6 +126,7 @@ void ext3_free_inode (handle_t *handle, 
2845          */
2846         DQUOT_INIT(inode);
2847         ext3_xattr_delete_inode(handle, inode);
2848 +       DLIMIT_FREE_INODE(sb, inode->i_xid);
2849         DQUOT_FREE_INODE(inode);
2850         DQUOT_DROP(inode);
2851  
2852 @@ -443,6 +445,16 @@ struct inode *ext3_new_inode(handle_t *h
2853         inode = new_inode(sb);
2854         if (!inode)
2855                 return ERR_PTR(-ENOMEM);
2856 +
2857 +       if (sb->s_flags & MS_TAGXID)
2858 +               inode->i_xid = vx_current_xid();
2859 +       else
2860 +               inode->i_xid = 0;
2861 +
2862 +       if (DLIMIT_ALLOC_INODE(sb, inode->i_xid)) {
2863 +               err = -ENOSPC;
2864 +               goto out;
2865 +       }
2866         ei = EXT3_I(inode);
2867  
2868         sbi = EXT3_SB(sb);
2869 @@ -566,7 +578,8 @@ got:
2870         ei->i_dir_start_lookup = 0;
2871         ei->i_disksize = 0;
2872  
2873 -       ei->i_flags = EXT3_I(dir)->i_flags & ~EXT3_INDEX_FL;
2874 +       ei->i_flags = EXT3_I(dir)->i_flags &
2875 +               ~(EXT3_INDEX_FL|EXT3_IUNLINK_FL|EXT3_BARRIER_FL);
2876         if (S_ISLNK(mode))
2877                 ei->i_flags &= ~(EXT3_IMMUTABLE_FL|EXT3_APPEND_FL);
2878         /* dirsync only applies to directories */
2879 @@ -618,6 +631,7 @@ got:
2880         ext3_debug("allocating inode %lu\n", inode->i_ino);
2881         goto really_out;
2882  fail:
2883 +       DLIMIT_FREE_INODE(sb, inode->i_xid);
2884         ext3_std_error(sb, err);
2885  out:
2886         iput(inode);
2887 @@ -627,6 +641,7 @@ really_out:
2888         return ret;
2889  
2890  fail2:
2891 +       DLIMIT_FREE_INODE(sb, inode->i_xid);
2892         inode->i_flags |= S_NOQUOTA;
2893         inode->i_nlink = 0;
2894         iput(inode);
2895 diff -NurpP --minimal linux-2.6.10/fs/ext3/inode.c linux-2.6.10-vs1.9.3.17/fs/ext3/inode.c
2896 --- linux-2.6.10/fs/ext3/inode.c        2004-12-25 01:55:20.000000000 +0100
2897 +++ linux-2.6.10-vs1.9.3.17/fs/ext3/inode.c     2004-12-26 19:40:34.000000000 +0100
2898 @@ -36,6 +36,7 @@
2899  #include <linux/writeback.h>
2900  #include <linux/mpage.h>
2901  #include <linux/uio.h>
2902 +#include <linux/vserver/xid.h>
2903  #include "xattr.h"
2904  #include "acl.h"
2905  
2906 @@ -178,6 +179,8 @@ static int ext3_journal_test_restart(han
2907         return ext3_journal_restart(handle, blocks_for_truncate(inode));
2908  }
2909  
2910 +static void ext3_truncate_nocheck (struct inode *inode);
2911 +
2912  /*
2913   * Called at the last iput() if i_nlink is zero.
2914   */
2915 @@ -201,7 +204,7 @@ void ext3_delete_inode (struct inode * i
2916                 handle->h_sync = 1;
2917         inode->i_size = 0;
2918         if (inode->i_blocks)
2919 -               ext3_truncate(inode);
2920 +               ext3_truncate_nocheck(inode);
2921         /*
2922          * Kill off the orphan record which ext3_truncate created.
2923          * AKPM: I think this can be inside the above `if'.
2924 @@ -2048,7 +2051,7 @@ static void ext3_free_branches(handle_t 
2925   * ext3_truncate() run will find them and release them.
2926   */
2927  
2928 -void ext3_truncate(struct inode * inode)
2929 +void ext3_truncate_nocheck(struct inode * inode)
2930  {
2931         handle_t *handle;
2932         struct ext3_inode_info *ei = EXT3_I(inode);
2933 @@ -2069,8 +2072,6 @@ void ext3_truncate(struct inode * inode)
2934                 return;
2935         if (ext3_inode_is_fast_symlink(inode))
2936                 return;
2937 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2938 -               return;
2939  
2940         ext3_discard_reservation(inode);
2941  
2942 @@ -2380,17 +2381,28 @@ has_buffer:
2943         return 0;
2944  }
2945  
2946 +void ext3_truncate(struct inode * inode)
2947 +{
2948 +       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2949 +               return;
2950 +       ext3_truncate_nocheck(inode);
2951 +}
2952 +
2953  void ext3_set_inode_flags(struct inode *inode)
2954  {
2955         unsigned int flags = EXT3_I(inode)->i_flags;
2956  
2957 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2958 +       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_IUNLINK|S_BARRIER|S_NOATIME|S_DIRSYNC);
2959         if (flags & EXT3_SYNC_FL)
2960                 inode->i_flags |= S_SYNC;
2961         if (flags & EXT3_APPEND_FL)
2962                 inode->i_flags |= S_APPEND;
2963         if (flags & EXT3_IMMUTABLE_FL)
2964                 inode->i_flags |= S_IMMUTABLE;
2965 +       if (flags & EXT3_IUNLINK_FL)
2966 +               inode->i_flags |= S_IUNLINK;
2967 +       if (flags & EXT3_BARRIER_FL)
2968 +               inode->i_flags |= S_BARRIER;
2969         if (flags & EXT3_NOATIME_FL)
2970                 inode->i_flags |= S_NOATIME;
2971         if (flags & EXT3_DIRSYNC_FL)
2972 @@ -2404,6 +2416,8 @@ void ext3_read_inode(struct inode * inod
2973         struct ext3_inode_info *ei = EXT3_I(inode);
2974         struct buffer_head *bh;
2975         int block;
2976 +       uid_t uid;
2977 +       gid_t gid;
2978  
2979  #ifdef CONFIG_EXT3_FS_POSIX_ACL
2980         ei->i_acl = EXT3_ACL_NOT_CACHED;
2981 @@ -2416,12 +2430,17 @@ void ext3_read_inode(struct inode * inod
2982         bh = iloc.bh;
2983         raw_inode = ext3_raw_inode(&iloc);
2984         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2985 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2986 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2987 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2988 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2989         if(!(test_opt (inode->i_sb, NO_UID32))) {
2990 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2991 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2992 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2993 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2994         }
2995 +       inode->i_uid = INOXID_UID(XID_TAG(inode), uid, gid);
2996 +       inode->i_gid = INOXID_GID(XID_TAG(inode), uid, gid);
2997 +       inode->i_xid = INOXID_XID(XID_TAG(inode), uid, gid,
2998 +               le16_to_cpu(raw_inode->i_raw_xid));
2999 +
3000         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3001         inode->i_size = le32_to_cpu(raw_inode->i_size);
3002         inode->i_atime.tv_sec = le32_to_cpu(raw_inode->i_atime);
3003 @@ -2529,6 +2548,8 @@ static int ext3_do_update_inode(handle_t
3004         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3005         struct ext3_inode_info *ei = EXT3_I(inode);
3006         struct buffer_head *bh = iloc->bh;
3007 +       uid_t uid = XIDINO_UID(XID_TAG(inode), inode->i_uid, inode->i_xid);
3008 +       gid_t gid = XIDINO_GID(XID_TAG(inode), inode->i_gid, inode->i_xid);
3009         int err = 0, rc, block;
3010  
3011         /* For fields not not tracking in the in-memory inode,
3012 @@ -2538,29 +2559,32 @@ static int ext3_do_update_inode(handle_t
3013  
3014         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3015         if(!(test_opt(inode->i_sb, NO_UID32))) {
3016 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3017 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3018 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3019 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3020  /*
3021   * Fix up interoperability with old kernels. Otherwise, old inodes get
3022   * re-used with the upper 16 bits of the uid/gid intact
3023   */
3024                 if(!ei->i_dtime) {
3025                         raw_inode->i_uid_high =
3026 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3027 +                               cpu_to_le16(high_16_bits(uid));
3028                         raw_inode->i_gid_high =
3029 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3030 +                               cpu_to_le16(high_16_bits(gid));
3031                 } else {
3032                         raw_inode->i_uid_high = 0;
3033                         raw_inode->i_gid_high = 0;
3034                 }
3035         } else {
3036                 raw_inode->i_uid_low =
3037 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3038 +                       cpu_to_le16(fs_high2lowuid(uid));
3039                 raw_inode->i_gid_low =
3040 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3041 +                       cpu_to_le16(fs_high2lowgid(gid));
3042                 raw_inode->i_uid_high = 0;
3043                 raw_inode->i_gid_high = 0;
3044         }
3045 +#ifdef CONFIG_INOXID_INTERN
3046 +       raw_inode->i_raw_xid = cpu_to_le16(inode->i_xid);
3047 +#endif
3048         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3049         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3050         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3051 @@ -2682,6 +2706,44 @@ int ext3_write_inode(struct inode *inode
3052         return ext3_force_commit(inode->i_sb);
3053  }
3054  
3055 +int ext3_setattr_flags(struct inode *inode, unsigned int flags)
3056 +{
3057 +       unsigned int oldflags, newflags;
3058 +       int err = 0;
3059 +
3060 +       oldflags = EXT3_I(inode)->i_flags;
3061 +       newflags = oldflags &
3062 +               ~(EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL | EXT3_BARRIER_FL);
3063 +       if (flags & ATTR_FLAG_IMMUTABLE)
3064 +               newflags |= EXT3_IMMUTABLE_FL;
3065 +       if (flags & ATTR_FLAG_IUNLINK)
3066 +               newflags |= EXT3_IUNLINK_FL;
3067 +       if (flags & ATTR_FLAG_BARRIER)
3068 +               newflags |= EXT3_BARRIER_FL;
3069 +
3070 +       if (oldflags ^ newflags) {
3071 +               handle_t *handle;
3072 +               struct ext3_iloc iloc;
3073 +
3074 +               handle = ext3_journal_start(inode, 1);
3075 +               if (IS_ERR(handle))
3076 +                       return PTR_ERR(handle);
3077 +               if (IS_SYNC(inode))
3078 +                       handle->h_sync = 1;
3079 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3080 +               if (err)
3081 +                       goto flags_err;
3082 +
3083 +               EXT3_I(inode)->i_flags = newflags;
3084 +               inode->i_ctime = CURRENT_TIME;
3085 +
3086 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3087 +       flags_err:
3088 +               ext3_journal_stop(handle);
3089 +       }
3090 +       return err;
3091 +}
3092 +
3093  /*
3094   * ext3_setattr()
3095   *
3096 @@ -2710,7 +2772,8 @@ int ext3_setattr(struct dentry *dentry, 
3097                 return error;
3098  
3099         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3100 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3101 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3102 +               (ia_valid & ATTR_XID && attr->ia_xid != inode->i_xid)) {
3103                 handle_t *handle;
3104  
3105                 /* (user+group)*(old+new) structure, inode write (sb,
3106 @@ -2731,6 +2794,10 @@ int ext3_setattr(struct dentry *dentry, 
3107                         inode->i_uid = attr->ia_uid;
3108                 if (attr->ia_valid & ATTR_GID)
3109                         inode->i_gid = attr->ia_gid;
3110 +               if ((attr->ia_valid & ATTR_XID)
3111 +                       && inode->i_sb
3112 +                       && (inode->i_sb->s_flags & MS_TAGXID))
3113 +                       inode->i_xid = attr->ia_xid;
3114                 error = ext3_mark_inode_dirty(handle, inode);
3115                 ext3_journal_stop(handle);
3116         }
3117 @@ -2753,6 +2820,12 @@ int ext3_setattr(struct dentry *dentry, 
3118                 ext3_journal_stop(handle);
3119         }
3120  
3121 +       if (ia_valid & ATTR_ATTR_FLAG) {
3122 +               rc = ext3_setattr_flags(inode, attr->ia_attr_flags);
3123 +               if (!error)
3124 +                       error = rc;
3125 +       }
3126 +
3127         rc = inode_setattr(inode, attr);
3128  
3129         /* If inode_setattr's call to ext3_truncate failed to get a
3130 diff -NurpP --minimal linux-2.6.10/fs/ext3/ioctl.c linux-2.6.10-vs1.9.3.17/fs/ext3/ioctl.c
3131 --- linux-2.6.10/fs/ext3/ioctl.c        2004-12-25 01:55:20.000000000 +0100
3132 +++ linux-2.6.10-vs1.9.3.17/fs/ext3/ioctl.c     2004-12-26 19:40:36.000000000 +0100
3133 @@ -12,6 +12,7 @@
3134  #include <linux/ext3_fs.h>
3135  #include <linux/ext3_jbd.h>
3136  #include <linux/time.h>
3137 +#include <linux/vserver/xid.h>
3138  #include <asm/uaccess.h>
3139  
3140  
3141 @@ -58,7 +59,9 @@ int ext3_ioctl (struct inode * inode, st
3142                  *
3143                  * This test looks nicer. Thanks to Pauline Middelink
3144                  */
3145 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3146 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3147 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3148 +                       EXT3_IMMUTABLE_FL | EXT3_IUNLINK_FL))) {
3149                         if (!capable(CAP_LINUX_IMMUTABLE))
3150                                 return -EPERM;
3151                 }
3152 @@ -219,6 +222,38 @@ flags_err:
3153                 return err;
3154         }
3155  
3156 +#if defined(CONFIG_VSERVER_LEGACY) && !defined(CONFIG_INOXID_NONE)
3157 +       case EXT3_IOC_SETXID: {
3158 +               handle_t *handle;
3159 +               struct ext3_iloc iloc;
3160 +               int xid;
3161 +               int err;
3162 +
3163 +               /* fixme: if stealth, return -ENOTTY */
3164 +               if (!capable(CAP_CONTEXT))
3165 +                       return -EPERM;
3166 +               if (IS_RDONLY(inode))
3167 +                       return -EROFS;
3168 +               if (!(inode->i_sb->s_flags & MS_TAGXID))
3169 +                       return -ENOSYS;
3170 +               if (get_user(xid, (int *) arg))
3171 +                       return -EFAULT;
3172 +
3173 +               handle = ext3_journal_start(inode, 1);
3174 +               if (IS_ERR(handle))
3175 +                       return PTR_ERR(handle);
3176 +               err = ext3_reserve_inode_write(handle, inode, &iloc);
3177 +               if (err)
3178 +                       return err;
3179 +
3180 +               inode->i_xid = (xid & 0xFFFF);
3181 +               inode->i_ctime = CURRENT_TIME;
3182 +
3183 +               err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3184 +               ext3_journal_stop(handle);
3185 +               return err;
3186 +       }
3187 +#endif
3188  
3189         default:
3190                 return -ENOTTY;
3191 diff -NurpP --minimal linux-2.6.10/fs/ext3/namei.c linux-2.6.10-vs1.9.3.17/fs/ext3/namei.c
3192 --- linux-2.6.10/fs/ext3/namei.c        2004-12-25 01:55:20.000000000 +0100
3193 +++ linux-2.6.10-vs1.9.3.17/fs/ext3/namei.c     2004-12-26 19:40:30.000000000 +0100
3194 @@ -36,6 +36,7 @@
3195  #include <linux/quotaops.h>
3196  #include <linux/buffer_head.h>
3197  #include <linux/smp_lock.h>
3198 +#include <linux/vserver/xid.h>
3199  #include "xattr.h"
3200  #include "acl.h"
3201  
3202 @@ -989,6 +990,7 @@ static struct dentry *ext3_lookup(struct
3203  
3204                 if (!inode)
3205                         return ERR_PTR(-EACCES);
3206 +               vx_propagate_xid(nd, inode);
3207         }
3208         if (inode)
3209                 return d_splice_alias(inode, dentry);
3210 diff -NurpP --minimal linux-2.6.10/fs/ext3/super.c linux-2.6.10-vs1.9.3.17/fs/ext3/super.c
3211 --- linux-2.6.10/fs/ext3/super.c        2004-12-25 01:55:20.000000000 +0100
3212 +++ linux-2.6.10-vs1.9.3.17/fs/ext3/super.c     2004-12-26 19:40:34.000000000 +0100
3213 @@ -584,7 +584,7 @@ enum {
3214         Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
3215         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3216         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0,
3217 -       Opt_ignore, Opt_barrier, Opt_err, Opt_resize,
3218 +       Opt_tagxid, Opt_barrier, Opt_ignore, Opt_err, Opt_resize,
3219  };
3220  
3221  static match_table_t tokens = {
3222 @@ -627,6 +627,7 @@ static match_table_t tokens = {
3223         {Opt_grpjquota, "grpjquota=%s"},
3224         {Opt_jqfmt_vfsold, "jqfmt=vfsold"},
3225         {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
3226 +       {Opt_tagxid, "tagxid"},
3227         {Opt_ignore, "grpquota"},
3228         {Opt_ignore, "noquota"},
3229         {Opt_ignore, "quota"},
3230 @@ -722,6 +723,16 @@ static int parse_options (char * options
3231                 case Opt_nouid32:
3232                         set_opt (sbi->s_mount_opt, NO_UID32);
3233                         break;
3234 +#ifndef CONFIG_INOXID_NONE
3235 +               case Opt_tagxid:
3236 +                       if (is_remount) {
3237 +                               printk(KERN_ERR "EXT3-fs: cannot specify "
3238 +                                      "tagxid on remount\n");
3239 +                               return 0;
3240 +                       }
3241 +                       set_opt (sbi->s_mount_opt, TAG_XID);
3242 +                       break;
3243 +#endif
3244                 case Opt_check:
3245  #ifdef CONFIG_EXT3_CHECK
3246                         set_opt (sbi->s_mount_opt, CHECK);
3247 @@ -1313,6 +1324,8 @@ static int ext3_fill_super (struct super
3248         if (!parse_options ((char *) data, sb, &journal_inum, NULL, 0))
3249                 goto failed_mount;
3250  
3251 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAG_XID)
3252 +               sb->s_flags |= MS_TAGXID;
3253         sb->s_flags |= MS_ONE_SECOND;
3254         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3255                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3256 diff -NurpP --minimal linux-2.6.10/fs/ext3/xattr.c linux-2.6.10-vs1.9.3.17/fs/ext3/xattr.c
3257 --- linux-2.6.10/fs/ext3/xattr.c        2004-12-25 01:55:20.000000000 +0100
3258 +++ linux-2.6.10-vs1.9.3.17/fs/ext3/xattr.c     2004-12-26 19:40:35.000000000 +0100
3259 @@ -61,6 +61,7 @@
3260  #include <linux/mbcache.h>
3261  #include <linux/quotaops.h>
3262  #include <linux/rwsem.h>
3263 +#include <linux/vs_dlimit.h>
3264  #include "xattr.h"
3265  #include "acl.h"
3266  
3267 @@ -661,8 +662,12 @@ ext3_xattr_set_handle2(handle_t *handle,
3268                                    the inode. */
3269                                 ea_bdebug(new_bh, "reusing block");
3270  
3271 +                               error = -ENOSPC;
3272 +                               if (DLIMIT_ALLOC_BLOCK(sb, inode->i_xid, 1))
3273 +                                       goto cleanup;
3274                                 error = -EDQUOT;
3275                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
3276 +                                       DLIMIT_FREE_BLOCK(sb, inode->i_xid, 1);
3277                                         unlock_buffer(new_bh);
3278                                         journal_release_buffer(handle, new_bh,
3279                                                                credits);
3280 @@ -747,6 +752,7 @@ getblk_failed:
3281                         /* Decrement the refcount only. */
3282                         HDR(old_bh)->h_refcount = cpu_to_le32(
3283                                 le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
3284 +                       DLIMIT_FREE_BLOCK(sb, inode->i_xid, 1);
3285                         DQUOT_FREE_BLOCK(inode, 1);
3286                         ext3_journal_dirty_metadata(handle, old_bh);
3287                         ea_bdebug(old_bh, "refcount now=%d",
3288 @@ -838,6 +844,7 @@ ext3_xattr_delete_inode(handle_t *handle
3289                 ext3_journal_dirty_metadata(handle, bh);
3290                 if (IS_SYNC(inode))
3291                         handle->h_sync = 1;
3292 +               DLIMIT_FREE_BLOCK(inode->i_sb, inode->i_xid, 1);
3293                 DQUOT_FREE_BLOCK(inode, 1);
3294         }
3295         ea_bdebug(bh, "refcount now=%d", le32_to_cpu(HDR(bh)->h_refcount) - 1);
3296 diff -NurpP --minimal linux-2.6.10/fs/fcntl.c linux-2.6.10-vs1.9.3.17/fs/fcntl.c
3297 --- linux-2.6.10/fs/fcntl.c     2004-12-25 01:55:20.000000000 +0100
3298 +++ linux-2.6.10-vs1.9.3.17/fs/fcntl.c  2004-12-26 19:40:35.000000000 +0100
3299 @@ -15,6 +15,7 @@
3300  #include <linux/module.h>
3301  #include <linux/security.h>
3302  #include <linux/ptrace.h>
3303 +#include <linux/vs_limit.h>
3304  
3305  #include <asm/poll.h>
3306  #include <asm/siginfo.h>
3307 @@ -108,6 +109,8 @@ repeat:
3308         error = -EMFILE;
3309         if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
3310                 goto out;
3311 +       if (!vx_files_avail(1))
3312 +               goto out;
3313  
3314         error = expand_files(files, newfd);
3315         if (error < 0)
3316 @@ -140,6 +143,7 @@ static int dupfd(struct file *file, unsi
3317                 FD_SET(fd, files->open_fds);
3318                 FD_CLR(fd, files->close_on_exec);
3319                 spin_unlock(&files->file_lock);
3320 +               // vx_openfd_inc(fd);
3321                 fd_install(fd, file);
3322         } else {
3323                 spin_unlock(&files->file_lock);
3324 @@ -187,6 +191,7 @@ asmlinkage long sys_dup2(unsigned int ol
3325         FD_SET(newfd, files->open_fds);
3326         FD_CLR(newfd, files->close_on_exec);
3327         spin_unlock(&files->file_lock);
3328 +       // vx_openfd_inc(newfd);
3329  
3330         if (tofree)
3331                 filp_close(tofree, files);
3332 @@ -489,7 +494,7 @@ void send_sigio(struct fown_struct *fown
3333         
3334         read_lock(&tasklist_lock);
3335         if (pid > 0) {
3336 -               p = find_task_by_pid(pid);
3337 +               p = find_task_by_real_pid(pid);
3338                 if (p) {
3339                         send_sigio_to_task(p, fown, fd, band);
3340                 }
3341 @@ -524,7 +529,7 @@ int send_sigurg(struct fown_struct *fown
3342         
3343         read_lock(&tasklist_lock);
3344         if (pid > 0) {
3345 -               p = find_task_by_pid(pid);
3346 +               p = find_task_by_real_pid(pid);
3347                 if (p) {
3348                         send_sigurg_to_task(p, fown);
3349                 }
3350 diff -NurpP --minimal linux-2.6.10/fs/file_table.c linux-2.6.10-vs1.9.3.17/fs/file_table.c
3351 --- linux-2.6.10/fs/file_table.c        2004-12-25 01:55:20.000000000 +0100
3352 +++ linux-2.6.10-vs1.9.3.17/fs/file_table.c     2004-12-26 19:40:35.000000000 +0100
3353 @@ -16,6 +16,8 @@
3354  #include <linux/eventpoll.h>
3355  #include <linux/mount.h>
3356  #include <linux/cdev.h>
3357 +#include <linux/vs_limit.h>
3358 +#include <linux/vs_context.h>
3359  
3360  /* sysctl tunables... */
3361  struct files_stat_struct files_stat = {
3362 @@ -85,6 +87,9 @@ static int old_max;
3363                         f->f_owner.lock = RW_LOCK_UNLOCKED;
3364                         /* f->f_version: 0 */
3365                         INIT_LIST_HEAD(&f->f_list);
3366 +                       // set_vx_info(&f->f_vx_info, current->vx_info);
3367 +                       f->f_xid = vx_current_xid();
3368 +                       vx_files_inc(f);
3369                         return f;
3370                 }
3371         }
3372 @@ -137,6 +142,8 @@ void fastcall __fput(struct file *file)
3373         fops_put(file->f_op);
3374         if (file->f_mode & FMODE_WRITE)
3375                 put_write_access(inode);
3376 +       vx_files_dec(file);
3377 +       file->f_xid = 0;
3378         file_kill(file);
3379         file->f_dentry = NULL;
3380         file->f_vfsmnt = NULL;
3381 @@ -192,6 +199,8 @@ void put_filp(struct file *file)
3382  {
3383         if (atomic_dec_and_test(&file->f_count)) {
3384                 security_file_free(file);
3385 +               vx_files_dec(file);
3386 +               file->f_xid = 0;
3387                 file_kill(file);
3388                 file_free(file);
3389         }
3390 diff -NurpP --minimal linux-2.6.10/fs/inode.c linux-2.6.10-vs1.9.3.17/fs/inode.c
3391 --- linux-2.6.10/fs/inode.c     2004-12-25 01:55:20.000000000 +0100
3392 +++ linux-2.6.10-vs1.9.3.17/fs/inode.c  2004-12-26 19:40:34.000000000 +0100
3393 @@ -115,6 +115,10 @@ static struct inode *alloc_inode(struct 
3394                 struct address_space * const mapping = &inode->i_data;
3395  
3396                 inode->i_sb = sb;
3397 +               // inode->i_dqh = dqhget(sb->s_dqh);
3398 +
3399 +               /* essential because of inode slab reuse */
3400 +               inode->i_xid = 0;
3401                 inode->i_blkbits = sb->s_blocksize_bits;
3402                 inode->i_flags = 0;
3403                 atomic_set(&inode->i_count, 1);
3404 diff -NurpP --minimal linux-2.6.10/fs/ioctl.c linux-2.6.10-vs1.9.3.17/fs/ioctl.c
3405 --- linux-2.6.10/fs/ioctl.c     2004-12-25 01:55:20.000000000 +0100
3406 +++ linux-2.6.10-vs1.9.3.17/fs/ioctl.c  2004-12-26 19:40:36.000000000 +0100
3407 @@ -12,10 +12,18 @@
3408  #include <linux/fs.h>
3409  #include <linux/security.h>
3410  #include <linux/module.h>
3411 +#include <linux/proc_fs.h>
3412 +#include <linux/vserver/inode.h>
3413 +#include <linux/vserver/xid.h>
3414  
3415  #include <asm/uaccess.h>
3416  #include <asm/ioctls.h>
3417  
3418 +#ifdef CONFIG_VSERVER_LEGACY
3419 +extern int vx_proc_ioctl(struct inode *, struct file *,
3420 +       unsigned int, unsigned long);
3421 +#endif
3422 +
3423  static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
3424  {
3425         int error;
3426 @@ -123,6 +131,48 @@ asmlinkage long sys_ioctl(unsigned int f
3427                         else
3428                                 error = -ENOTTY;
3429                         break;
3430 +#ifdef CONFIG_VSERVER_LEGACY
3431 +#ifndef CONFIG_INOXID_NONE
3432 +               case FIOC_GETXID: {
3433 +                       struct inode *inode = filp->f_dentry->d_inode;
3434 +
3435 +                       /* fixme: if stealth, return -ENOTTY */
3436 +                       error = -EPERM;
3437 +                       if (capable(CAP_CONTEXT))
3438 +                               error = put_user(inode->i_xid, (int *) arg);
3439 +                       break;
3440 +               }
3441 +               case FIOC_SETXID: {
3442 +                       struct inode *inode = filp->f_dentry->d_inode;
3443 +                       int xid;
3444 +
3445 +                       /* fixme: if stealth, return -ENOTTY */
3446 +                       error = -EPERM;
3447 +                       if (!capable(CAP_CONTEXT))
3448 +                               break;
3449 +                       error = -EROFS;
3450 +                       if (IS_RDONLY(inode))
3451 +                               break;
3452 +                       error = -ENOSYS;
3453 +                       if (!(inode->i_sb->s_flags & MS_TAGXID))
3454 +                               break;
3455 +                       error = -EFAULT;
3456 +                       if (get_user(xid, (int *) arg))
3457 +                               break;
3458 +                       error = 0;
3459 +                       inode->i_xid = (xid & 0xFFFF);
3460 +                       inode->i_ctime = CURRENT_TIME;
3461 +                       mark_inode_dirty(inode);
3462 +                       break;
3463 +               }
3464 +#endif
3465 +               case FIOC_GETXFLG:
3466 +               case FIOC_SETXFLG:
3467 +                       error = -ENOTTY;
3468 +                       if (filp->f_dentry->d_inode->i_sb->s_magic == PROC_SUPER_MAGIC)
3469 +                               error = vx_proc_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
3470 +                       break;
3471 +#endif
3472                 default:
3473                         error = -ENOTTY;
3474                         if (S_ISREG(filp->f_dentry->d_inode->i_mode))
3475 diff -NurpP --minimal linux-2.6.10/fs/jfs/jfs_imap.c linux-2.6.10-vs1.9.3.17/fs/jfs/jfs_imap.c
3476 --- linux-2.6.10/fs/jfs/jfs_imap.c      2004-12-25 01:55:20.000000000 +0100
3477 +++ linux-2.6.10-vs1.9.3.17/fs/jfs/jfs_imap.c   2004-12-26 19:40:34.000000000 +0100
3478 @@ -45,6 +45,7 @@
3479  #include <linux/buffer_head.h>
3480  #include <linux/pagemap.h>
3481  #include <linux/quotaops.h>
3482 +#include <linux/vserver/xid.h>
3483  
3484  #include "jfs_incore.h"
3485  #include "jfs_filsys.h"
3486 @@ -3092,14 +3093,21 @@ static void duplicateIXtree(struct super
3487  static int copy_from_dinode(struct dinode * dip, struct inode *ip)
3488  {
3489         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3490 +       uid_t uid;
3491 +       gid_t gid;
3492  
3493         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3494         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3495  
3496         ip->i_mode = le32_to_cpu(dip->di_mode) & 0xffff;
3497         ip->i_nlink = le32_to_cpu(dip->di_nlink);
3498 -       ip->i_uid = le32_to_cpu(dip->di_uid);
3499 -       ip->i_gid = le32_to_cpu(dip->di_gid);
3500 +
3501 +       uid = le32_to_cpu(dip->di_uid);
3502 +       gid = le32_to_cpu(dip->di_gid);
3503 +       ip->i_uid = INOXID_UID(XID_TAG(ip), uid, gid);
3504 +       ip->i_gid = INOXID_GID(XID_TAG(ip), uid, gid);
3505 +       ip->i_xid = INOXID_XID(XID_TAG(ip), uid, gid, 0);
3506 +
3507         ip->i_size = le64_to_cpu(dip->di_size);
3508         ip->i_atime.tv_sec = le32_to_cpu(dip->di_atime.tv_sec);
3509         ip->i_atime.tv_nsec = le32_to_cpu(dip->di_atime.tv_nsec);
3510 @@ -3150,6 +3158,8 @@ static int copy_from_dinode(struct dinod
3511  static void copy_to_dinode(struct dinode * dip, struct inode *ip)
3512  {
3513         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3514 +       uid_t uid;
3515 +       gid_t gid;
3516  
3517         dip->di_fileset = cpu_to_le32(jfs_ip->fileset);
3518         dip->di_inostamp = cpu_to_le32(JFS_SBI(ip->i_sb)->inostamp);
3519 @@ -3158,8 +3168,11 @@ static void copy_to_dinode(struct dinode
3520         dip->di_size = cpu_to_le64(ip->i_size);
3521         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3522         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3523 -       dip->di_uid = cpu_to_le32(ip->i_uid);
3524 -       dip->di_gid = cpu_to_le32(ip->i_gid);
3525 +
3526 +       uid = XIDINO_UID(XID_TAG(ip), ip->i_uid, ip->i_xid);
3527 +       gid = XIDINO_GID(XID_TAG(ip), ip->i_gid, ip->i_xid);
3528 +       dip->di_uid = cpu_to_le32(uid);
3529 +       dip->di_gid = cpu_to_le32(gid);
3530         /*
3531          * mode2 is only needed for storing the higher order bits.
3532          * Trust i_mode for the lower order ones
3533 diff -NurpP --minimal linux-2.6.10/fs/namei.c linux-2.6.10-vs1.9.3.17/fs/namei.c
3534 --- linux-2.6.10/fs/namei.c     2004-12-25 01:55:21.000000000 +0100
3535 +++ linux-2.6.10-vs1.9.3.17/fs/namei.c  2004-12-26 19:40:34.000000000 +0100
3536 @@ -28,6 +28,10 @@
3537  #include <linux/syscalls.h>
3538  #include <linux/mount.h>
3539  #include <linux/audit.h>
3540 +#include <linux/proc_fs.h>
3541 +#include <linux/vserver/inode.h>
3542 +#include <linux/vserver/debug.h>
3543 +
3544  #include <asm/namei.h>
3545  #include <asm/uaccess.h>
3546  
3547 @@ -224,6 +228,24 @@ int generic_permission(struct inode *ino
3548         return -EACCES;
3549  }
3550  
3551 +static inline int xid_permission(struct inode *inode, int mask, struct nameidata *nd)
3552 +{
3553 +       if (IS_BARRIER(inode) && !vx_check(0, VX_ADMIN)) {
3554 +               vxwprintk(1, "xid=%d did hit the barrier.",
3555 +                       vx_current_xid());
3556 +               return -EACCES;
3557 +       }
3558 +       if (inode->i_xid == 0)
3559 +               return 0;
3560 +       if (vx_check(inode->i_xid, VX_ADMIN|VX_WATCH|VX_IDENT))
3561 +               return 0;
3562 +
3563 +       vxwprintk(1, "xid=%d denied access to %p[#%d,%lu] Â»%s«.",
3564 +               vx_current_xid(), inode, inode->i_xid, inode->i_ino,
3565 +               vxd_path(nd->dentry, nd->mnt));
3566 +       return -EACCES;
3567 +}
3568 +
3569  int permission(struct inode * inode,int mask, struct nameidata *nd)
3570  {
3571         int retval;
3572 @@ -232,6 +254,8 @@ int permission(struct inode * inode,int 
3573         /* Ordinary permission routines do not understand MAY_APPEND. */
3574         submask = mask & ~MAY_APPEND;
3575  
3576 +       if ((retval = xid_permission(inode, mask, nd)))
3577 +               return retval;
3578         if (inode->i_op && inode->i_op->permission)
3579                 retval = inode->i_op->permission(inode, submask, nd);
3580         else
3581 @@ -634,15 +658,33 @@ static int do_lookup(struct nameidata *n
3582  {
3583         struct vfsmount *mnt = nd->mnt;
3584         struct dentry *dentry = __d_lookup(nd->dentry, name);
3585 +       struct inode *inode;
3586  
3587         if (!dentry)
3588                 goto need_lookup;
3589         if (dentry->d_op && dentry->d_op->d_revalidate)
3590                 goto need_revalidate;
3591 +       inode = dentry->d_inode;
3592 +       if (!inode)
3593 +               goto done;
3594 +       if (!vx_check(inode->i_xid, VX_WATCH|VX_HOSTID|VX_IDENT))
3595 +               goto hidden;
3596 +       if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
3597 +               struct proc_dir_entry *de = PDE(inode);
3598 +
3599 +               if (de && !vx_hide_check(0, de->vx_flags))
3600 +                       goto hidden;
3601 +       }
3602  done:
3603         path->mnt = mnt;
3604         path->dentry = dentry;
3605         return 0;
3606 +hidden:
3607 +       vxwprintk(1, "xid=%d did lookup hidden %p[#%d,%lu] Â»%s«.",
3608 +               vx_current_xid(), inode, inode->i_xid, inode->i_ino,
3609 +               vxd_path(dentry, mnt));
3610 +       dput(dentry);
3611 +       return -ENOENT;
3612  
3613  need_lookup:
3614         dentry = real_lookup(nd->dentry, name, nd);
3615 @@ -1123,7 +1165,7 @@ static inline int may_delete(struct inod
3616         if (IS_APPEND(dir))
3617                 return -EPERM;
3618         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
3619 -           IS_IMMUTABLE(victim->d_inode))
3620 +               IS_IXORUNLINK(victim->d_inode))
3621                 return -EPERM;
3622         if (isdir) {
3623                 if (!S_ISDIR(victim->d_inode->i_mode))
3624 @@ -1929,7 +1971,7 @@ int vfs_link(struct dentry *old_dentry, 
3625         /*
3626          * A link to an append-only or immutable file cannot be created.
3627          */
3628 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3629 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3630                 return -EPERM;
3631         if (!dir->i_op || !dir->i_op->link)
3632                 return -EPERM;
3633 diff -NurpP --minimal linux-2.6.10/fs/namespace.c linux-2.6.10-vs1.9.3.17/fs/namespace.c
3634 --- linux-2.6.10/fs/namespace.c 2004-12-25 01:55:21.000000000 +0100
3635 +++ linux-2.6.10-vs1.9.3.17/fs/namespace.c      2004-12-26 19:40:34.000000000 +0100
3636 @@ -22,6 +22,9 @@
3637  #include <linux/namei.h>
3638  #include <linux/security.h>
3639  #include <linux/mount.h>
3640 +#include <linux/vserver/namespace.h>
3641 +#include <linux/vserver/xid.h>
3642 +
3643  #include <asm/uaccess.h>
3644  #include <asm/unistd.h>
3645  
3646 @@ -161,6 +164,7 @@ clone_mnt(struct vfsmount *old, struct d
3647                 mnt->mnt_mountpoint = mnt->mnt_root;
3648                 mnt->mnt_parent = mnt;
3649                 mnt->mnt_namespace = old->mnt_namespace;
3650 +               mnt->mnt_xid = old->mnt_xid;
3651  
3652                 /* stick the duplicate mount on the same expiry list
3653                  * as the original if that was on one */
3654 @@ -228,6 +232,7 @@ static int show_vfsmnt(struct seq_file *
3655                 { MS_MANDLOCK, ",mand" },
3656                 { MS_NOATIME, ",noatime" },
3657                 { MS_NODIRATIME, ",nodiratime" },
3658 +               { MS_TAGXID, ",tagxid" },
3659                 { 0, NULL }
3660         };
3661         static struct proc_fs_info mnt_info[] = {
3662 @@ -238,6 +243,11 @@ static int show_vfsmnt(struct seq_file *
3663         };
3664         struct proc_fs_info *fs_infop;
3665  
3666 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
3667 +               return 0;
3668 +       if (!vx_check_vfsmount(current->vx_info, mnt))
3669 +               return 0;
3670 +
3671         mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
3672         seq_putc(m, ' ');
3673         seq_path(m, mnt, mnt->mnt_root, " \t\n\\");
3674 @@ -252,6 +262,8 @@ static int show_vfsmnt(struct seq_file *
3675                 if (mnt->mnt_flags & fs_infop->flag)
3676                         seq_puts(m, fs_infop->str);
3677         }
3678 +       if (mnt->mnt_flags & MNT_XID)
3679 +               seq_printf(m, ",xid=%d", mnt->mnt_xid);
3680         if (mnt->mnt_sb->s_op->show_options)
3681                 err = mnt->mnt_sb->s_op->show_options(m, mnt);
3682         seq_puts(m, " 0 0\n");
3683 @@ -337,18 +349,12 @@ int may_umount(struct vfsmount *mnt)
3684  
3685  EXPORT_SYMBOL(may_umount);
3686  
3687 -void umount_tree(struct vfsmount *mnt)
3688 +static inline void __umount_list(struct list_head *kill)
3689  {
3690 -       struct vfsmount *p;
3691 -       LIST_HEAD(kill);
3692 -
3693 -       for (p = mnt; p; p = next_mnt(p, mnt)) {
3694 -               list_del(&p->mnt_list);
3695 -               list_add(&p->mnt_list, &kill);
3696 -       }
3697 +       struct vfsmount *mnt;
3698  
3699 -       while (!list_empty(&kill)) {
3700 -               mnt = list_entry(kill.next, struct vfsmount, mnt_list);
3701 +       while (!list_empty(kill)) {
3702 +               mnt = list_entry(kill->next, struct vfsmount, mnt_list);
3703                 list_del_init(&mnt->mnt_list);
3704                 list_del_init(&mnt->mnt_fslink);
3705                 if (mnt->mnt_parent == mnt) {
3706 @@ -364,6 +370,32 @@ void umount_tree(struct vfsmount *mnt)
3707         }
3708  }
3709  
3710 +void umount_tree(struct vfsmount *mnt)
3711 +{
3712 +       struct vfsmount *p;
3713 +       LIST_HEAD(kill);
3714 +
3715 +       for (p = mnt; p; p = next_mnt(p, mnt)) {
3716 +               list_del(&p->mnt_list);
3717 +               list_add(&p->mnt_list, &kill);
3718 +       }
3719 +       __umount_list(&kill);
3720 +}
3721 +
3722 +void umount_unused(struct vfsmount *mnt, struct fs_struct *fs)
3723 +{
3724 +       struct vfsmount *p;
3725 +       LIST_HEAD(kill);
3726 +
3727 +       for (p = mnt; p; p = next_mnt(p, mnt)) {
3728 +               if (p == fs->rootmnt || p == fs->pwdmnt)
3729 +                       continue;
3730 +               list_del(&p->mnt_list);
3731 +               list_add(&p->mnt_list, &kill);
3732 +       }
3733 +       __umount_list(&kill);
3734 +}
3735 +
3736  static int do_umount(struct vfsmount *mnt, int flags)
3737  {
3738         struct super_block * sb = mnt->mnt_sb;
3739 @@ -480,7 +512,7 @@ asmlinkage long sys_umount(char __user *
3740                 goto dput_and_out;
3741  
3742         retval = -EPERM;
3743 -       if (!capable(CAP_SYS_ADMIN))
3744 +       if (!capable(CAP_SYS_ADMIN) && !vx_ccaps(VXC_SECURE_MOUNT))
3745                 goto dput_and_out;
3746  
3747         retval = do_umount(nd.mnt, flags);
3748 @@ -507,6 +539,8 @@ static int mount_is_safe(struct nameidat
3749  {
3750         if (capable(CAP_SYS_ADMIN))
3751                 return 0;
3752 +       if (vx_ccaps(VXC_SECURE_MOUNT))
3753 +               return 0;
3754         return -EPERM;
3755  #ifdef notyet
3756         if (S_ISLNK(nd->dentry->d_inode->i_mode))
3757 @@ -618,11 +652,12 @@ out_unlock:
3758  /*
3759   * do loopback mount.
3760   */
3761 -static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
3762 +static int do_loopback(struct nameidata *nd, char *old_name, xid_t xid, int flags)
3763  {
3764         struct nameidata old_nd;
3765         struct vfsmount *mnt = NULL;
3766         int err = mount_is_safe(nd);
3767 +       int recurse = flags & MS_REC;
3768         if (err)
3769                 return err;
3770         if (!old_name || !*old_name)
3771 @@ -647,6 +682,10 @@ static int do_loopback(struct nameidata 
3772                 list_del_init(&mnt->mnt_fslink);
3773                 spin_unlock(&vfsmount_lock);
3774  
3775 +               if (flags & MS_XID) {
3776 +                       mnt->mnt_xid = xid;
3777 +                       mnt->mnt_flags |= MNT_XID;
3778 +               }
3779                 err = graft_tree(mnt, nd);
3780                 if (err) {
3781                         spin_lock(&vfsmount_lock);
3782 @@ -668,12 +707,12 @@ static int do_loopback(struct nameidata 
3783   */
3784  
3785  static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
3786 -                     void *data)
3787 +                     void *data, xid_t xid)
3788  {
3789         int err;
3790         struct super_block * sb = nd->mnt->mnt_sb;
3791  
3792 -       if (!capable(CAP_SYS_ADMIN))
3793 +       if (!capable(CAP_SYS_ADMIN) && !vx_ccaps(VXC_SECURE_REMOUNT))
3794                 return -EPERM;
3795  
3796         if (!check_mnt(nd->mnt))
3797 @@ -682,10 +721,15 @@ static int do_remount(struct nameidata *
3798         if (nd->dentry != nd->mnt->mnt_root)
3799                 return -EINVAL;
3800  
3801 +       if (vx_ccaps(VXC_SECURE_REMOUNT))
3802 +               mnt_flags |= MNT_NODEV;
3803         down_write(&sb->s_umount);
3804         err = do_remount_sb(sb, flags, data, 0);
3805 -       if (!err)
3806 +       if (!err) {
3807                 nd->mnt->mnt_flags=mnt_flags;
3808 +               if (flags & MS_XID)
3809 +                       nd->mnt->mnt_xid = xid;
3810 +       }
3811         up_write(&sb->s_umount);
3812         if (!err)
3813                 security_sb_post_remount(nd->mnt, flags, data);
3814 @@ -697,7 +741,7 @@ static int do_move_mount(struct nameidat
3815         struct nameidata old_nd, parent_nd;
3816         struct vfsmount *p;
3817         int err = 0;
3818 -       if (!capable(CAP_SYS_ADMIN))
3819 +       if (!capable(CAP_SYS_ADMIN) && !vx_ccaps(VXC_SECURE_MOUNT))
3820                 return -EPERM;
3821         if (!old_name || !*old_name)
3822                 return -EINVAL;
3823 @@ -769,7 +813,7 @@ static int do_new_mount(struct nameidata
3824                 return -EINVAL;
3825  
3826         /* we need capabilities... */
3827 -       if (!capable(CAP_SYS_ADMIN))
3828 +       if (!capable(CAP_SYS_ADMIN) && !vx_ccaps(VXC_SECURE_MOUNT))
3829                 return -EPERM;
3830  
3831         mnt = do_kern_mount(type, flags, name, data);
3832 @@ -1011,6 +1055,7 @@ long do_mount(char * dev_name, char * di
3833         struct nameidata nd;
3834         int retval = 0;
3835         int mnt_flags = 0;
3836 +       xid_t xid = 0;
3837  
3838         /* Discard magic */
3839         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
3840 @@ -1026,6 +1071,14 @@ long do_mount(char * dev_name, char * di
3841         if (data_page)
3842                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
3843  
3844 +       retval = vx_parse_xid(data_page, &xid, 1);
3845 +       if (retval) {
3846 +               mnt_flags |= MNT_XID;
3847 +               /* bind and re-mounts get xid flag */
3848 +               if (flags & (MS_BIND|MS_REMOUNT))
3849 +                       flags |= MS_XID;
3850 +       }
3851 +
3852         /* Separate the per-mountpoint flags */
3853         if (flags & MS_NOSUID)
3854                 mnt_flags |= MNT_NOSUID;
3855 @@ -1035,6 +1088,9 @@ long do_mount(char * dev_name, char * di
3856                 mnt_flags |= MNT_NOEXEC;
3857         flags &= ~(MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_ACTIVE);
3858  
3859 +       if (vx_ccaps(VXC_SECURE_MOUNT))
3860 +               mnt_flags |= MNT_NODEV;
3861 +
3862         /* ... and get the mountpoint */
3863         retval = path_lookup(dir_name, LOOKUP_FOLLOW, &nd);
3864         if (retval)
3865 @@ -1046,9 +1102,9 @@ long do_mount(char * dev_name, char * di
3866  
3867         if (flags & MS_REMOUNT)
3868                 retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
3869 -                                   data_page);
3870 +                                   data_page, xid);
3871         else if (flags & MS_BIND)
3872 -               retval = do_loopback(&nd, dev_name, flags & MS_REC);
3873 +               retval = do_loopback(&nd, dev_name, xid, flags);
3874         else if (flags & MS_MOVE)
3875                 retval = do_move_mount(&nd, dev_name);
3876         else
3877 @@ -1075,7 +1131,7 @@ int copy_namespace(int flags, struct tas
3878         if (!(flags & CLONE_NEWNS))
3879                 return 0;
3880  
3881 -       if (!capable(CAP_SYS_ADMIN)) {
3882 +       if (!capable(CAP_SYS_ADMIN) && !vx_ccaps(VXC_SECURE_MOUNT)) {
3883                 put_namespace(namespace);
3884                 return -EPERM;
3885         }
3886 diff -NurpP --minimal linux-2.6.10/fs/nfs/dir.c linux-2.6.10-vs1.9.3.17/fs/nfs/dir.c
3887 --- linux-2.6.10/fs/nfs/dir.c   2004-12-25 01:55:21.000000000 +0100
3888 +++ linux-2.6.10-vs1.9.3.17/fs/nfs/dir.c        2004-12-26 19:40:34.000000000 +0100
3889 @@ -31,6 +31,7 @@
3890  #include <linux/pagemap.h>
3891  #include <linux/smp_lock.h>
3892  #include <linux/namei.h>
3893 +#include <linux/vserver/xid.h>
3894  
3895  #include "delegation.h"
3896  
3897 @@ -759,6 +760,7 @@ static struct dentry *nfs_lookup(struct 
3898         inode = nfs_fhget(dentry->d_sb, &fhandle, &fattr);
3899         if (!inode)
3900                 goto out_unlock;
3901 +       vx_propagate_xid(nd, inode);
3902  no_entry:
3903         error = 0;
3904         d_add(dentry, inode);
3905 diff -NurpP --minimal linux-2.6.10/fs/nfs/inode.c linux-2.6.10-vs1.9.3.17/fs/nfs/inode.c
3906 --- linux-2.6.10/fs/nfs/inode.c 2004-10-23 05:06:17.000000000 +0200
3907 +++ linux-2.6.10-vs1.9.3.17/fs/nfs/inode.c      2004-12-26 19:40:34.000000000 +0100
3908 @@ -35,6 +35,7 @@
3909  #include <linux/mount.h>
3910  #include <linux/nfs_idmap.h>
3911  #include <linux/vfs.h>
3912 +#include <linux/vserver/xid.h>
3913  
3914  #include <asm/system.h>
3915  #include <asm/uaccess.h>
3916 @@ -313,6 +314,9 @@ nfs_sb_init(struct super_block *sb, rpc_
3917         }
3918         server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
3919  
3920 +       if (server->flags & NFS_MOUNT_TAGXID)
3921 +               sb->s_flags |= MS_TAGXID;
3922 +
3923         sb->s_maxbytes = fsinfo.maxfilesize;
3924         if (sb->s_maxbytes > MAX_LFS_FILESIZE) 
3925                 sb->s_maxbytes = MAX_LFS_FILESIZE; 
3926 @@ -367,6 +371,7 @@ nfs_create_client(struct nfs_server *ser
3927         clnt->cl_intr     = (server->flags & NFS_MOUNT_INTR) ? 1 : 0;
3928         clnt->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0;
3929         clnt->cl_droppriv = (server->flags & NFS_MOUNT_BROKEN_SUID) ? 1 : 0;
3930 +       clnt->cl_tagxid   = (server->flags & NFS_MOUNT_TAGXID) ? 1 : 0;
3931         clnt->cl_chatty   = 1;
3932  
3933         return clnt;
3934 @@ -524,6 +529,7 @@ static int nfs_show_options(struct seq_f
3935                 { NFS_MOUNT_NOAC, ",noac", "" },
3936                 { NFS_MOUNT_NONLM, ",nolock", ",lock" },
3937                 { NFS_MOUNT_BROKEN_SUID, ",broken_suid", "" },
3938 +               { NFS_MOUNT_TAGXID, ",tagxid", "" },
3939                 { 0, NULL, NULL }
3940         };
3941         struct proc_nfs_info *nfs_infop;
3942 @@ -688,8 +694,10 @@ nfs_fhget(struct super_block *sb, struct
3943                         nfsi->change_attr = fattr->change_attr;
3944                 inode->i_size = nfs_size_to_loff_t(fattr->size);
3945                 inode->i_nlink = fattr->nlink;
3946 -               inode->i_uid = fattr->uid;
3947 -               inode->i_gid = fattr->gid;
3948 +               inode->i_uid = INOXID_UID(XID_TAG(inode), fattr->uid, fattr->gid);
3949 +               inode->i_gid = INOXID_GID(XID_TAG(inode), fattr->uid, fattr->gid);
3950 +               inode->i_xid = INOXID_XID(XID_TAG(inode), fattr->uid, fattr->gid, 0);
3951 +                                        /* maybe fattr->xid someday */
3952                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
3953                         /*
3954                          * report the blocks in 512byte units
3955 @@ -715,7 +723,12 @@ nfs_fhget(struct super_block *sb, struct
3956  
3957  out:
3958         return inode;
3959 -
3960 +/*     FIXME
3961 +fail_dlim:
3962 +       make_bad_inode(inode);
3963 +       iput(inode);
3964 +       inode = NULL;
3965 +*/
3966  out_no_inode:
3967         printk("nfs_fhget: iget failed\n");
3968         goto out;
3969 @@ -761,6 +774,8 @@ nfs_setattr(struct dentry *dentry, struc
3970                         inode->i_uid = attr->ia_uid;
3971                 if ((attr->ia_valid & ATTR_GID) != 0)
3972                         inode->i_gid = attr->ia_gid;
3973 +               if ((attr->ia_valid & ATTR_XID) != 0)
3974 +                       inode->i_xid = attr->ia_xid;
3975                 if ((attr->ia_valid & ATTR_SIZE) != 0) {
3976                         inode->i_size = attr->ia_size;
3977                         vmtruncate(inode, attr->ia_size);
3978 @@ -1114,6 +1129,9 @@ int nfs_refresh_inode(struct inode *inod
3979         struct nfs_inode *nfsi = NFS_I(inode);
3980         loff_t cur_size, new_isize;
3981         int data_unstable;
3982 +       uid_t uid;
3983 +       gid_t gid;
3984 +       xid_t xid = 0;
3985  
3986         /* Do we hold a delegation? */
3987         if (nfs_have_delegation(inode, FMODE_READ))
3988 @@ -1157,10 +1175,15 @@ int nfs_refresh_inode(struct inode *inod
3989         } else if (S_ISREG(inode->i_mode) && new_isize > cur_size)
3990                         nfsi->flags |= NFS_INO_INVALID_ATTR;
3991  
3992 +       uid = INOXID_UID(XID_TAG(inode), fattr->uid, fattr->gid);
3993 +       gid = INOXID_GID(XID_TAG(inode), fattr->uid, fattr->gid);
3994 +       xid = INOXID_XID(XID_TAG(inode), fattr->uid, fattr->gid, 0);
3995 +
3996         /* Have any file permissions changed? */
3997         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
3998 -                       || inode->i_uid != fattr->uid
3999 -                       || inode->i_gid != fattr->gid)
4000 +                       || inode->i_uid != uid
4001 +                       || inode->i_gid != gid
4002 +                       || inode->i_xid != xid)
4003                 nfsi->flags |= NFS_INO_INVALID_ATTR;
4004  
4005         /* Has the link count changed? */
4006 @@ -1194,6 +1217,9 @@ static int nfs_update_inode(struct inode
4007         unsigned int    invalid = 0;
4008         loff_t          cur_isize;
4009         int data_unstable;
4010 +       uid_t           uid;
4011 +       gid_t           gid;
4012 +       xid_t           xid = 0;
4013  
4014         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
4015                         __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
4016 @@ -1276,9 +1302,14 @@ static int nfs_update_inode(struct inode
4017         memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
4018         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
4019  
4020 +       uid = INOXID_UID(XID_TAG(inode), fattr->uid, fattr->gid);
4021 +       gid = INOXID_GID(XID_TAG(inode), fattr->uid, fattr->gid);
4022 +       xid = INOXID_XID(XID_TAG(inode), fattr->uid, fattr->gid, 0);
4023 +
4024         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
4025 -           inode->i_uid != fattr->uid ||
4026 -           inode->i_gid != fattr->gid) {
4027 +           inode->i_uid != uid ||
4028 +           inode->i_gid != gid ||
4029 +           inode->i_xid != xid) {
4030                 struct rpc_cred **cred = &NFS_I(inode)->cache_access.cred;
4031                 if (*cred) {
4032                         put_rpccred(*cred);
4033 @@ -1289,8 +1320,9 @@ static int nfs_update_inode(struct inode
4034  
4035         inode->i_mode = fattr->mode;
4036         inode->i_nlink = fattr->nlink;
4037 -       inode->i_uid = fattr->uid;
4038 -       inode->i_gid = fattr->gid;
4039 +       inode->i_uid = uid;
4040 +       inode->i_gid = gid;
4041 +       inode->i_xid = xid;
4042  
4043         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
4044                 /*
4045 diff -NurpP --minimal linux-2.6.10/fs/nfs/nfs3xdr.c linux-2.6.10-vs1.9.3.17/fs/nfs/nfs3xdr.c
4046 --- linux-2.6.10/fs/nfs/nfs3xdr.c       2004-10-23 05:06:17.000000000 +0200
4047 +++ linux-2.6.10-vs1.9.3.17/fs/nfs/nfs3xdr.c    2004-12-26 19:40:34.000000000 +0100
4048 @@ -21,6 +21,7 @@
4049  #include <linux/nfs.h>
4050  #include <linux/nfs3.h>
4051  #include <linux/nfs_fs.h>
4052 +#include <linux/vserver/xid.h>
4053  
4054  #define NFSDBG_FACILITY                NFSDBG_XDR
4055  
4056 @@ -173,7 +174,7 @@ xdr_decode_fattr(u32 *p, struct nfs_fatt
4057  }
4058  
4059  static inline u32 *
4060 -xdr_encode_sattr(u32 *p, struct iattr *attr)
4061 +xdr_encode_sattr(u32 *p, struct iattr *attr, int tagxid)
4062  {
4063         if (attr->ia_valid & ATTR_MODE) {
4064                 *p++ = xdr_one;
4065 @@ -181,15 +182,17 @@ xdr_encode_sattr(u32 *p, struct iattr *a
4066         } else {
4067                 *p++ = xdr_zero;
4068         }
4069 -       if (attr->ia_valid & ATTR_UID) {
4070 +       if (attr->ia_valid & ATTR_UID ||
4071 +               (tagxid && (attr->ia_valid & ATTR_XID))) {
4072                 *p++ = xdr_one;
4073 -               *p++ = htonl(attr->ia_uid);
4074 +               *p++ = htonl(XIDINO_UID(tagxid, attr->ia_uid, attr->ia_xid));
4075         } else {
4076                 *p++ = xdr_zero;
4077         }
4078 -       if (attr->ia_valid & ATTR_GID) {
4079 +       if (attr->ia_valid & ATTR_GID ||
4080 +               (tagxid && (attr->ia_valid & ATTR_XID))) {
4081                 *p++ = xdr_one;
4082 -               *p++ = htonl(attr->ia_gid);
4083 +               *p++ = htonl(XIDINO_GID(tagxid, attr->ia_gid, attr->ia_xid));
4084         } else {
4085                 *p++ = xdr_zero;
4086         }
4087 @@ -274,7 +277,8 @@ static int
4088  nfs3_xdr_sattrargs(struct rpc_rqst *req, u32 *p, struct nfs3_sattrargs *args)
4089  {
4090         p = xdr_encode_fhandle(p, args->fh);
4091 -       p = xdr_encode_sattr(p, args->sattr);
4092 +       p = xdr_encode_sattr(p, args->sattr,
4093 +               req->rq_task->tk_client->cl_tagxid);
4094         *p++ = htonl(args->guard);
4095         if (args->guard)
4096                 p = xdr_encode_time3(p, &args->guardtime);
4097 @@ -365,7 +369,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
4098                 *p++ = args->verifier[0];
4099                 *p++ = args->verifier[1];
4100         } else
4101 -               p = xdr_encode_sattr(p, args->sattr);
4102 +               p = xdr_encode_sattr(p, args->sattr,
4103 +                       req->rq_task->tk_client->cl_tagxid);
4104  
4105         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
4106         return 0;
4107 @@ -379,7 +384,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
4108  {
4109         p = xdr_encode_fhandle(p, args->fh);
4110         p = xdr_encode_array(p, args->name, args->len);
4111 -       p = xdr_encode_sattr(p, args->sattr);
4112 +       p = xdr_encode_sattr(p, args->sattr,
4113 +               req->rq_task->tk_client->cl_tagxid);
4114         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
4115         return 0;
4116  }
4117 @@ -392,7 +398,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
4118  {
4119         p = xdr_encode_fhandle(p, args->fromfh);
4120         p = xdr_encode_array(p, args->fromname, args->fromlen);
4121 -       p = xdr_encode_sattr(p, args->sattr);
4122 +       p = xdr_encode_sattr(p, args->sattr,
4123 +               req->rq_task->tk_client->cl_tagxid);
4124         p = xdr_encode_array(p, args->topath, args->tolen);
4125         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
4126         return 0;
4127 @@ -407,7 +414,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
4128         p = xdr_encode_fhandle(p, args->fh);
4129         p = xdr_encode_array(p, args->name, args->len);
4130         *p++ = htonl(args->type);
4131 -       p = xdr_encode_sattr(p, args->sattr);
4132 +       p = xdr_encode_sattr(p, args->sattr,
4133 +               req->rq_task->tk_client->cl_tagxid);
4134         if (args->type == NF3CHR || args->type == NF3BLK) {
4135                 *p++ = htonl(MAJOR(args->rdev));
4136                 *p++ = htonl(MINOR(args->rdev));
4137 diff -NurpP --minimal linux-2.6.10/fs/nfs/nfsroot.c linux-2.6.10-vs1.9.3.17/fs/nfs/nfsroot.c
4138 --- linux-2.6.10/fs/nfs/nfsroot.c       2004-08-14 12:55:48.000000000 +0200
4139 +++ linux-2.6.10-vs1.9.3.17/fs/nfs/nfsroot.c    2004-12-26 19:40:34.000000000 +0100
4140 @@ -87,6 +87,7 @@
4141  #include <linux/root_dev.h>
4142  #include <net/ipconfig.h>
4143  #include <linux/parser.h>
4144 +#include <linux/vs_cvirt.h>
4145  
4146  /* Define this to allow debugging output */
4147  #undef NFSROOT_DEBUG
4148 @@ -124,7 +125,7 @@ enum {
4149         Opt_soft, Opt_hard, Opt_intr,
4150         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
4151         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
4152 -       Opt_broken_suid,
4153 +       Opt_broken_suid, Opt_tagxid,
4154         /* Error token */
4155         Opt_err
4156  };
4157 @@ -160,6 +161,7 @@ static match_table_t __initdata tokens =
4158         {Opt_tcp, "proto=tcp"},
4159         {Opt_tcp, "tcp"},
4160         {Opt_broken_suid, "broken_suid"},
4161 +       {Opt_tagxid, "tagxid"},
4162         {Opt_err, NULL}
4163         
4164  };
4165 @@ -271,6 +273,9 @@ static int __init root_nfs_parse(char *n
4166                         case Opt_broken_suid:
4167                                 nfs_data.flags |= NFS_MOUNT_BROKEN_SUID;
4168                                 break;
4169 +                       case Opt_tagxid:
4170 +                               nfs_data.flags |= NFS_MOUNT_TAGXID;
4171 +                               break;
4172                         default : 
4173                                 return 0;
4174                 }
4175 @@ -306,7 +311,7 @@ static int __init root_nfs_name(char *na
4176         /* Override them by options set on kernel command-line */
4177         root_nfs_parse(name, buf);
4178  
4179 -       cp = system_utsname.nodename;
4180 +       cp = vx_new_uts(nodename);
4181         if (strlen(buf) + strlen(cp) > NFS_MAXPATHLEN) {
4182                 printk(KERN_ERR "Root-NFS: Pathname for remote directory too long.\n");
4183                 return -1;
4184 diff -NurpP --minimal linux-2.6.10/fs/nfsd/auth.c linux-2.6.10-vs1.9.3.17/fs/nfsd/auth.c
4185 --- linux-2.6.10/fs/nfsd/auth.c 2004-08-14 12:56:14.000000000 +0200
4186 +++ linux-2.6.10-vs1.9.3.17/fs/nfsd/auth.c      2004-12-26 19:40:34.000000000 +0100
4187 @@ -9,6 +9,7 @@
4188  #include <linux/sunrpc/svc.h>
4189  #include <linux/sunrpc/svcauth.h>
4190  #include <linux/nfsd/nfsd.h>
4191 +#include <linux/vserver/xid.h>
4192  
4193  #define        CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))
4194  
4195 @@ -42,18 +43,20 @@ int nfsd_setuser(struct svc_rqst *rqstp,
4196         }
4197  
4198         if (cred->cr_uid != (uid_t) -1)
4199 -               current->fsuid = cred->cr_uid;
4200 +               current->fsuid = INOXID_UID(1, cred->cr_uid, cred->cr_gid);
4201         else
4202                 current->fsuid = exp->ex_anon_uid;
4203         if (cred->cr_gid != (gid_t) -1)
4204 -               current->fsgid = cred->cr_gid;
4205 +               current->fsgid = INOXID_GID(1, cred->cr_uid, cred->cr_gid);
4206         else
4207                 current->fsgid = exp->ex_anon_gid;
4208  
4209 +       current->xid = INOXID_XID(1, cred->cr_uid, cred->cr_gid, 0);
4210 +
4211         if (!cred->cr_group_info)
4212                 return -ENOMEM;
4213         ret = set_current_groups(cred->cr_group_info);
4214 -       if ((cred->cr_uid)) {
4215 +       if (INOXID_UID(1, cred->cr_uid, cred->cr_gid)) {
4216                 cap_t(current->cap_effective) &= ~CAP_NFSD_MASK;
4217         } else {
4218                 cap_t(current->cap_effective) |= (CAP_NFSD_MASK &
4219 diff -NurpP --minimal linux-2.6.10/fs/nfsd/nfs3xdr.c linux-2.6.10-vs1.9.3.17/fs/nfsd/nfs3xdr.c
4220 --- linux-2.6.10/fs/nfsd/nfs3xdr.c      2004-10-23 05:06:17.000000000 +0200
4221 +++ linux-2.6.10-vs1.9.3.17/fs/nfsd/nfs3xdr.c   2004-12-26 19:40:34.000000000 +0100
4222 @@ -21,6 +21,7 @@
4223  #include <linux/sunrpc/svc.h>
4224  #include <linux/nfsd/nfsd.h>
4225  #include <linux/nfsd/xdr3.h>
4226 +#include <linux/vserver/xid.h>
4227  
4228  #define NFSDDBG_FACILITY               NFSDDBG_XDR
4229  
4230 @@ -121,6 +122,8 @@ static inline u32 *
4231  decode_sattr3(u32 *p, struct iattr *iap)
4232  {
4233         u32     tmp;
4234 +       uid_t   uid = 0;
4235 +       gid_t   gid = 0;
4236  
4237         iap->ia_valid = 0;
4238  
4239 @@ -130,12 +133,15 @@ decode_sattr3(u32 *p, struct iattr *iap)
4240         }
4241         if (*p++) {
4242                 iap->ia_valid |= ATTR_UID;
4243 -               iap->ia_uid = ntohl(*p++);
4244 +               uid = ntohl(*p++);
4245         }
4246         if (*p++) {
4247                 iap->ia_valid |= ATTR_GID;
4248 -               iap->ia_gid = ntohl(*p++);
4249 +               gid = ntohl(*p++);
4250         }
4251 +       iap->ia_uid = INOXID_UID(1, uid, gid);
4252 +       iap->ia_gid = INOXID_GID(1, uid, gid);
4253 +       iap->ia_xid = INOXID_XID(1, uid, gid, 0);
4254         if (*p++) {
4255                 u64     newsize;
4256  
4257 @@ -176,8 +182,10 @@ encode_fattr3(struct svc_rqst *rqstp, u3
4258         *p++ = htonl(nfs3_ftypes[(stat.mode & S_IFMT) >> 12]);
4259         *p++ = htonl((u32) stat.mode);
4260         *p++ = htonl((u32) stat.nlink);
4261 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat.uid));
4262 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat.gid));
4263 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
4264 +               XIDINO_UID(XID_TAG(dentry->d_inode), stat.uid, stat.xid)));
4265 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
4266 +               XIDINO_GID(XID_TAG(dentry->d_inode), stat.gid, stat.xid)));
4267         if (S_ISLNK(stat.mode) && stat.size > NFS3_MAXPATHLEN) {
4268                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
4269         } else {
4270 diff -NurpP --minimal linux-2.6.10/fs/nfsd/nfs4xdr.c linux-2.6.10-vs1.9.3.17/fs/nfsd/nfs4xdr.c
4271 --- linux-2.6.10/fs/nfsd/nfs4xdr.c      2004-12-25 01:55:21.000000000 +0100
4272 +++ linux-2.6.10-vs1.9.3.17/fs/nfsd/nfs4xdr.c   2004-12-26 19:40:34.000000000 +0100
4273 @@ -57,6 +57,7 @@
4274  #include <linux/nfsd_idmap.h>
4275  #include <linux/nfs4.h>
4276  #include <linux/nfs4_acl.h>
4277 +#include <linux/vserver/xid.h>
4278  
4279  #define NFSDDBG_FACILITY               NFSDDBG_XDR
4280  
4281 @@ -1660,14 +1661,18 @@ out_acl:
4282                 WRITE32(stat.nlink);
4283         }
4284         if (bmval1 & FATTR4_WORD1_OWNER) {
4285 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
4286 +               status = nfsd4_encode_user(rqstp,
4287 +                       XIDINO_UID(XID_TAG(dentry->d_inode),
4288 +                       stat.uid, stat.xid), &p, &buflen);
4289                 if (status == nfserr_resource)
4290                         goto out_resource;
4291                 if (status)
4292                         goto out;
4293         }
4294         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
4295 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
4296 +               status = nfsd4_encode_group(rqstp,
4297 +                       XIDINO_GID(XID_TAG(dentry->d_inode),
4298 +                       stat.gid, stat.xid), &p, &buflen);
4299                 if (status == nfserr_resource)
4300                         goto out_resource;
4301                 if (status)
4302 diff -NurpP --minimal linux-2.6.10/fs/nfsd/nfsxdr.c linux-2.6.10-vs1.9.3.17/fs/nfsd/nfsxdr.c
4303 --- linux-2.6.10/fs/nfsd/nfsxdr.c       2004-08-14 12:54:47.000000000 +0200
4304 +++ linux-2.6.10-vs1.9.3.17/fs/nfsd/nfsxdr.c    2004-12-26 19:40:34.000000000 +0100
4305 @@ -15,6 +15,7 @@
4306  #include <linux/nfsd/nfsd.h>
4307  #include <linux/nfsd/xdr.h>
4308  #include <linux/mm.h>
4309 +#include <linux/vserver/xid.h>
4310  
4311  #define NFSDDBG_FACILITY               NFSDDBG_XDR
4312  
4313 @@ -96,6 +97,8 @@ static inline u32 *
4314  decode_sattr(u32 *p, struct iattr *iap)
4315  {
4316         u32     tmp, tmp1;
4317 +       uid_t   uid = 0;
4318 +       gid_t   gid = 0;
4319  
4320         iap->ia_valid = 0;
4321  
4322 @@ -109,12 +112,15 @@ decode_sattr(u32 *p, struct iattr *iap)
4323         }
4324         if ((tmp = ntohl(*p++)) != (u32)-1) {
4325                 iap->ia_valid |= ATTR_UID;
4326 -               iap->ia_uid = tmp;
4327 +               uid = tmp;
4328         }
4329         if ((tmp = ntohl(*p++)) != (u32)-1) {
4330                 iap->ia_valid |= ATTR_GID;
4331 -               iap->ia_gid = tmp;
4332 +               gid = tmp;
4333         }
4334 +       iap->ia_uid = INOXID_UID(1, uid, gid);
4335 +       iap->ia_gid = INOXID_GID(1, uid, gid);
4336 +       iap->ia_xid = INOXID_XID(1, uid, gid, 0);
4337         if ((tmp = ntohl(*p++)) != (u32)-1) {
4338                 iap->ia_valid |= ATTR_SIZE;
4339                 iap->ia_size = tmp;
4340 @@ -160,8 +166,10 @@ encode_fattr(struct svc_rqst *rqstp, u32
4341         *p++ = htonl(nfs_ftypes[type >> 12]);
4342         *p++ = htonl((u32) stat.mode);
4343         *p++ = htonl((u32) stat.nlink);
4344 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat.uid));
4345 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat.gid));
4346 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
4347 +               XIDINO_UID(XID_TAG(dentry->d_inode), stat.uid, stat.xid)));
4348 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
4349 +               XIDINO_GID(XID_TAG(dentry->d_inode), stat.gid, stat.xid)));
4350  
4351         if (S_ISLNK(type) && stat.size > NFS_MAXPATHLEN) {
4352                 *p++ = htonl(NFS_MAXPATHLEN);
4353 diff -NurpP --minimal linux-2.6.10/fs/open.c linux-2.6.10-vs1.9.3.17/fs/open.c
4354 --- linux-2.6.10/fs/open.c      2004-12-25 01:55:21.000000000 +0100
4355 +++ linux-2.6.10-vs1.9.3.17/fs/open.c   2004-12-26 19:40:35.000000000 +0100
4356 @@ -23,6 +23,9 @@
4357  #include <linux/fs.h>
4358  #include <linux/pagemap.h>
4359  #include <linux/syscalls.h>
4360 +#include <linux/vs_limit.h>
4361 +#include <linux/vs_dlimit.h>
4362 +#include <linux/vserver/xid.h>
4363  
4364  #include <asm/unistd.h>
4365  
4366 @@ -41,6 +44,8 @@ int vfs_statfs(struct super_block *sb, s
4367                         if (retval == 0 && buf->f_frsize == 0)
4368                                 buf->f_frsize = buf->f_bsize;
4369                 }
4370 +               if (!vx_check(0, VX_ADMIN|VX_WATCH))
4371 +                       vx_vsi_statfs(sb, buf);
4372         }
4373         return retval;
4374  }
4375 @@ -679,14 +684,15 @@ static int chown_common(struct dentry * 
4376         error = -EPERM;
4377         if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
4378                 goto out;
4379 +
4380         newattrs.ia_valid =  ATTR_CTIME;
4381         if (user != (uid_t) -1) {
4382                 newattrs.ia_valid |= ATTR_UID;
4383 -               newattrs.ia_uid = user;
4384 +               newattrs.ia_uid = vx_map_uid(user);
4385         }
4386         if (group != (gid_t) -1) {
4387                 newattrs.ia_valid |= ATTR_GID;
4388 -               newattrs.ia_gid = group;
4389 +               newattrs.ia_gid = vx_map_gid(group);
4390         }
4391         if (!S_ISDIR(inode->i_mode))
4392                 newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID;
4393 @@ -881,6 +887,7 @@ repeat:
4394         FD_SET(fd, files->open_fds);
4395         FD_CLR(fd, files->close_on_exec);
4396         files->next_fd = fd + 1;
4397 +       // vx_openfd_inc(fd);
4398  #if 1
4399         /* Sanity check */
4400         if (files->fd[fd] != NULL) {
4401 @@ -902,6 +909,7 @@ static inline void __put_unused_fd(struc
4402         __FD_CLR(fd, files->open_fds);
4403         if (fd < files->next_fd)
4404                 files->next_fd = fd;
4405 +       // vx_openfd_dec(fd);
4406  }
4407  
4408  void fastcall put_unused_fd(unsigned int fd)
4409 diff -NurpP --minimal linux-2.6.10/fs/proc/array.c linux-2.6.10-vs1.9.3.17/fs/proc/array.c
4410 --- linux-2.6.10/fs/proc/array.c        2004-12-25 01:55:21.000000000 +0100
4411 +++ linux-2.6.10-vs1.9.3.17/fs/proc/array.c     2004-12-26 19:40:36.000000000 +0100
4412 @@ -73,6 +73,9 @@
4413  #include <linux/highmem.h>
4414  #include <linux/file.h>
4415  #include <linux/times.h>
4416 +#include <linux/vs_context.h>
4417 +#include <linux/vs_network.h>
4418 +#include <linux/vs_cvirt.h>
4419  
4420  #include <asm/uaccess.h>
4421  #include <asm/pgtable.h>
4422 @@ -132,7 +135,8 @@ static const char *task_state_array[] = 
4423         "T (stopped)",          /*  4 */
4424         "T (tracing stop)",     /*  8 */
4425         "Z (zombie)",           /* 16 */
4426 -       "X (dead)"              /* 32 */
4427 +       "X (dead)",             /* 32 */
4428 +       "H (on hold)"           /* 64 */
4429  };
4430  
4431  static inline const char * get_task_state(struct task_struct *tsk)
4432 @@ -141,7 +145,8 @@ static inline const char * get_task_stat
4433                                             TASK_INTERRUPTIBLE |
4434                                             TASK_UNINTERRUPTIBLE |
4435                                             TASK_STOPPED |
4436 -                                           TASK_TRACED)) |
4437 +                                          TASK_TRACED |
4438 +                                          TASK_ONHOLD)) |
4439                         (tsk->exit_state & (EXIT_ZOMBIE |
4440                                             EXIT_DEAD));
4441         const char **p = &task_state_array[0];
4442 @@ -157,8 +162,13 @@ static inline char * task_state(struct t
4443  {
4444         struct group_info *group_info;
4445         int g;
4446 +       pid_t pid, ptgid, tppid, tgid;
4447  
4448         read_lock(&tasklist_lock);
4449 +       tgid = vx_map_tgid(p->tgid);
4450 +       pid = vx_map_pid(p->pid);
4451 +       ptgid = vx_map_pid(p->group_leader->real_parent->tgid);
4452 +       tppid = vx_map_pid(p->parent->pid);
4453         buffer += sprintf(buffer,
4454                 "State:\t%s\n"
4455                 "SleepAVG:\t%lu%%\n"
4456 @@ -170,9 +180,8 @@ static inline char * task_state(struct t
4457                 "Gid:\t%d\t%d\t%d\t%d\n",
4458                 get_task_state(p),
4459                 (p->sleep_avg/1024)*100/(1020000000/1024),
4460 -               p->tgid,
4461 -               p->pid, pid_alive(p) ? p->group_leader->real_parent->tgid : 0,
4462 -               pid_alive(p) && p->ptrace ? p->parent->pid : 0,
4463 +               tgid, pid, (pid > 1) ? ptgid : 0,
4464 +               pid_alive(p) && p->ptrace ? tppid : 0,
4465                 p->uid, p->euid, p->suid, p->fsuid,
4466                 p->gid, p->egid, p->sgid, p->fsgid);
4467         read_unlock(&tasklist_lock);
4468 @@ -283,6 +292,10 @@ static inline char *task_cap(struct task
4469  int proc_pid_status(struct task_struct *task, char * buffer)
4470  {
4471         char * orig = buffer;
4472 +#ifdef CONFIG_VSERVER_LEGACY
4473 +       struct vx_info *vxi;
4474 +       struct nx_info *nxi;
4475 +#endif
4476         struct mm_struct *mm = get_task_mm(task);
4477  
4478         buffer = task_name(task, buffer);
4479 @@ -294,6 +307,39 @@ int proc_pid_status(struct task_struct *
4480         }
4481         buffer = task_sig(task, buffer);
4482         buffer = task_cap(task, buffer);
4483 +
4484 +#ifdef CONFIG_VSERVER_LEGACY
4485 +       buffer += sprintf (buffer,"s_context: %d\n", vx_task_xid(task));
4486 +       vxi = task_get_vx_info(task);
4487 +       if (vxi) {
4488 +               buffer += sprintf (buffer,"ctxflags: %08llx\n"
4489 +                       ,(unsigned long long)vxi->vx_flags);
4490 +               buffer += sprintf (buffer,"initpid: %d\n"
4491 +                       ,vxi->vx_initpid);
4492 +       } else {
4493 +               buffer += sprintf (buffer,"ctxflags: none\n");
4494 +               buffer += sprintf (buffer,"initpid: none\n");
4495 +       }
4496 +       put_vx_info(vxi);
4497 +       nxi = task_get_nx_info(task);
4498 +       if (nxi) {
4499 +               int i;
4500 +
4501 +               buffer += sprintf (buffer,"ipv4root:");
4502 +               for (i=0; i<nxi->nbipv4; i++){
4503 +                       buffer += sprintf (buffer," %08x/%08x"
4504 +                               ,nxi->ipv4[i]
4505 +                               ,nxi->mask[i]);
4506 +               }
4507 +               *buffer++ = '\n';
4508 +               buffer += sprintf (buffer,"ipv4root_bcast: %08x\n"
4509 +                       ,nxi->v4_bcast);
4510 +       } else {
4511 +               buffer += sprintf (buffer,"ipv4root: 0\n");
4512 +               buffer += sprintf (buffer,"ipv4root_bcast: 0\n");
4513 +       }
4514 +       put_nx_info(nxi);
4515 +#endif
4516  #if defined(CONFIG_ARCH_S390)
4517         buffer = task_show_regs(task, buffer);
4518  #endif
4519 @@ -308,7 +354,7 @@ static int do_task_stat(struct task_stru
4520         sigset_t sigign, sigcatch;
4521         char state;
4522         int res;
4523 -       pid_t ppid, pgid = -1, sid = -1;
4524 +       pid_t pid, ppid, pgid = -1, sid = -1;
4525         int num_threads = 0;
4526         struct mm_struct *mm;
4527         unsigned long long start_time;
4528 @@ -370,7 +416,11 @@ static int do_task_stat(struct task_stru
4529                         stime += task->signal->stime;
4530                 }
4531         }
4532 -       ppid = pid_alive(task) ? task->group_leader->real_parent->tgid : 0;
4533 +       pid = vx_info_map_pid(task->vx_info, pid_alive(task) ? task->pid : 0);
4534 +       ppid = (!(pid > 1)) ? 0 : vx_info_map_tgid(task->vx_info,
4535 +               task->group_leader->real_parent->tgid);
4536 +       pgid = vx_info_map_pid(task->vx_info, pgid);
4537 +
4538         read_unlock(&tasklist_lock);
4539  
4540         if (!whole || num_threads<2)
4541 @@ -391,13 +441,25 @@ static int do_task_stat(struct task_stru
4542         /* convert timespec -> nsec*/
4543         start_time = (unsigned long long)task->start_time.tv_sec * NSEC_PER_SEC
4544                                 + task->start_time.tv_nsec;
4545 +
4546         /* convert nsec -> ticks */
4547         start_time = nsec_to_clock_t(start_time);
4548  
4549 +       /* fixup start time for virt uptime */
4550 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
4551 +               unsigned long long bias =
4552 +                       current->vx_info->cvirt.bias_clock;
4553 +
4554 +               if (start_time > bias)
4555 +                       start_time -= bias;
4556 +               else
4557 +                       start_time = 0;
4558 +       }
4559 +
4560         res = sprintf(buffer,"%d (%s) %c %d %d %d %d %d %lu %lu \
4561  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d %ld %llu %lu %ld %lu %lu %lu %lu %lu \
4562  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %lu %lu\n",
4563 -               task->pid,
4564 +               pid,
4565                 tcomm,
4566                 state,
4567                 ppid,
4568 diff -NurpP --minimal linux-2.6.10/fs/proc/base.c linux-2.6.10-vs1.9.3.17/fs/proc/base.c
4569 --- linux-2.6.10/fs/proc/base.c 2004-12-25 01:55:21.000000000 +0100
4570 +++ linux-2.6.10-vs1.9.3.17/fs/proc/base.c      2005-01-02 18:45:13.000000000 +0100
4571 @@ -32,6 +32,7 @@
4572  #include <linux/mount.h>
4573  #include <linux/security.h>
4574  #include <linux/ptrace.h>
4575 +#include <linux/vs_network.h>
4576  
4577  /*
4578   * For hysterical raisins we keep the same inumbers as in the old procfs.
4579 @@ -70,6 +71,8 @@ enum pid_directory_inos {
4580         PROC_TGID_ATTR_EXEC,
4581         PROC_TGID_ATTR_FSCREATE,
4582  #endif
4583 +       PROC_TGID_VX_INFO,
4584 +       PROC_TGID_IP_INFO,
4585         PROC_TGID_FD_DIR,
4586         PROC_TID_INO,
4587         PROC_TID_STATUS,
4588 @@ -96,6 +99,8 @@ enum pid_directory_inos {
4589         PROC_TID_ATTR_EXEC,
4590         PROC_TID_ATTR_FSCREATE,
4591  #endif
4592 +       PROC_TID_VX_INFO,
4593 +       PROC_TID_IP_INFO,
4594         PROC_TID_FD_DIR = 0x8000,       /* 0x8000-0xffff */
4595  };
4596  
4597 @@ -132,6 +137,8 @@ static struct pid_entry tgid_base_stuff[
4598  #ifdef CONFIG_SCHEDSTATS
4599         E(PROC_TGID_SCHEDSTAT, "schedstat", S_IFREG|S_IRUGO),
4600  #endif
4601 +       E(PROC_TGID_VX_INFO,   "vinfo",   S_IFREG|S_IRUGO),
4602 +       E(PROC_TGID_IP_INFO,   "ninfo",   S_IFREG|S_IRUGO),
4603         {0,0,NULL,0}
4604  };
4605  static struct pid_entry tid_base_stuff[] = {
4606 @@ -157,6 +164,8 @@ static struct pid_entry tid_base_stuff[]
4607  #ifdef CONFIG_SCHEDSTATS
4608         E(PROC_TID_SCHEDSTAT, "schedstat",S_IFREG|S_IRUGO),
4609  #endif
4610 +       E(PROC_TID_VX_INFO,    "vinfo",   S_IFREG|S_IRUGO),
4611 +       E(PROC_TID_IP_INFO,    "ninfo",   S_IFREG|S_IRUGO),
4612         {0,0,NULL,0}
4613  };
4614  
4615 @@ -961,6 +970,7 @@ static struct inode *proc_pid_make_inode
4616                 inode->i_uid = task->euid;
4617                 inode->i_gid = task->egid;
4618         }
4619 +       inode->i_xid = vx_task_xid(task);
4620         security_task_to_inode(task, inode);
4621  
4622  out:
4623 @@ -986,6 +996,11 @@ static int pid_revalidate(struct dentry 
4624  {
4625         struct inode *inode = dentry->d_inode;
4626         struct task_struct *task = proc_task(inode);
4627 +
4628 +       if (!vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
4629 +               goto out_drop;
4630 +       /* discard wrong fakeinit */
4631 +
4632         if (pid_alive(task)) {
4633                 if (proc_type(inode) == PROC_TGID_INO || proc_type(inode) == PROC_TID_INO || task_dumpable(task)) {
4634                         inode->i_uid = task->euid;
4635 @@ -997,6 +1012,7 @@ static int pid_revalidate(struct dentry 
4636                 security_task_to_inode(task, inode);
4637                 return 1;
4638         }
4639 +out_drop:
4640         d_drop(dentry);
4641         return 0;
4642  }
4643 @@ -1231,6 +1247,9 @@ static struct file_operations proc_tgid_
4644  static struct inode_operations proc_tgid_attr_inode_operations;
4645  #endif
4646  
4647 +extern int proc_pid_vx_info(struct task_struct *, char *);
4648 +extern int proc_pid_nx_info(struct task_struct *, char *);
4649 +
4650  /* SMP-safe */
4651  static struct dentry *proc_pident_lookup(struct inode *dir, 
4652                                          struct dentry *dentry,
4653 @@ -1377,6 +1396,16 @@ static struct dentry *proc_pident_lookup
4654                         ei->op.proc_read = proc_pid_schedstat;
4655                         break;
4656  #endif
4657 +               case PROC_TID_VX_INFO:
4658 +               case PROC_TGID_VX_INFO:
4659 +                       inode->i_fop = &proc_info_file_operations;
4660 +                       ei->op.proc_read = proc_pid_vx_info;
4661 +                       break;
4662 +               case PROC_TID_IP_INFO:
4663 +               case PROC_TGID_IP_INFO:
4664 +                       inode->i_fop = &proc_info_file_operations;
4665 +                       ei->op.proc_read = proc_pid_nx_info;
4666 +                       break;
4667                 default:
4668                         printk("procfs: impossible type (%d)",p->type);
4669                         iput(inode);
4670 @@ -1469,14 +1498,14 @@ static int proc_self_readlink(struct den
4671                               int buflen)
4672  {
4673         char tmp[30];
4674 -       sprintf(tmp, "%d", current->tgid);
4675 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
4676         return vfs_readlink(dentry,buffer,buflen,tmp);
4677  }
4678  
4679  static int proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
4680  {
4681         char tmp[30];
4682 -       sprintf(tmp, "%d", current->tgid);
4683 +       sprintf(tmp, "%d", vx_map_tgid(current->tgid));
4684         return vfs_follow_link(nd,tmp);
4685  }      
4686  
4687 @@ -1571,13 +1600,13 @@ struct dentry *proc_pid_lookup(struct in
4688         if (!task)
4689                 goto out;
4690  
4691 -       inode = proc_pid_make_inode(dir->i_sb, task, PROC_TGID_INO);
4692 +       if (!vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
4693 +               goto out_drop_task;
4694  
4695 +       inode = proc_pid_make_inode(dir->i_sb, task, PROC_TGID_INO);
4696 +       if (!inode)
4697 +               goto out_drop_task;
4698  
4699 -       if (!inode) {
4700 -               put_task_struct(task);
4701 -               goto out;
4702 -       }
4703         inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
4704         inode->i_op = &proc_tgid_base_inode_operations;
4705         inode->i_fop = &proc_tgid_base_operations;
4706 @@ -1602,6 +1631,8 @@ struct dentry *proc_pid_lookup(struct in
4707                 goto out;
4708         }
4709         return NULL;
4710 +out_drop_task:
4711 +       put_task_struct(task);
4712  out:
4713         return ERR_PTR(-ENOENT);
4714  }
4715 @@ -1617,6 +1648,8 @@ static struct dentry *proc_task_lookup(s
4716         tid = name_to_int(dentry);
4717         if (tid == ~0U)
4718                 goto out;
4719 +       if (vx_current_initpid(tid))
4720 +               goto out;
4721  
4722         read_lock(&tasklist_lock);
4723         task = find_task_by_pid(tid);
4724 @@ -1628,11 +1661,13 @@ static struct dentry *proc_task_lookup(s
4725         if (leader->tgid != task->tgid)
4726                 goto out_drop_task;
4727  
4728 -       inode = proc_pid_make_inode(dir->i_sb, task, PROC_TID_INO);
4729 -
4730 +       if (!vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
4731 +               goto out_drop_task;
4732  
4733 +       inode = proc_pid_make_inode(dir->i_sb, task, PROC_TID_INO);
4734         if (!inode)
4735                 goto out_drop_task;
4736 +
4737         inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
4738         inode->i_op = &proc_tid_base_inode_operations;
4739         inode->i_fop = &proc_tid_base_operations;
4740 @@ -1668,7 +1703,7 @@ static int get_tgid_list(int index, unsi
4741         read_lock(&tasklist_lock);
4742         p = NULL;
4743         if (version) {
4744 -               p = find_task_by_pid(version);
4745 +               p = find_task_by_real_pid(version);
4746                 if (p && !thread_group_leader(p))
4747                         p = NULL;
4748         }
4749 @@ -1680,11 +1715,14 @@ static int get_tgid_list(int index, unsi
4750  
4751         for ( ; p != &init_task; p = next_task(p)) {
4752                 int tgid = p->pid;
4753 +
4754                 if (!pid_alive(p))
4755                         continue;
4756 +               if (!vx_check(vx_task_xid(p), VX_WATCH|VX_IDENT))
4757 +                       continue;
4758                 if (--index >= 0)
4759                         continue;
4760 -               tgids[nr_tgids] = tgid;
4761 +               tgids[nr_tgids] = vx_map_tgid(tgid);
4762                 nr_tgids++;
4763                 if (nr_tgids >= PROC_MAXPIDS)
4764                         break;
4765 @@ -1714,9 +1752,11 @@ static int get_tid_list(int index, unsig
4766         if (pid_alive(task)) do {
4767                 int tid = task->pid;
4768  
4769 +               if (!vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
4770 +                       continue;
4771                 if (--index >= 0)
4772                         continue;
4773 -               tids[nr_tids] = tid;
4774 +               tids[nr_tids] = vx_map_pid(tid);
4775                 nr_tids++;
4776                 if (nr_tids >= PROC_MAXPIDS)
4777                         break;
4778 @@ -1792,11 +1832,14 @@ static int proc_task_readdir(struct file
4779         unsigned int nr_tids, i;
4780         struct dentry *dentry = filp->f_dentry;
4781         struct inode *inode = dentry->d_inode;
4782 +       struct task_struct *task = proc_task(inode);
4783         int retval = -ENOENT;
4784         ino_t ino;
4785         unsigned long pos = filp->f_pos;  /* avoiding "long long" filp->f_pos */
4786  
4787 -       if (!pid_alive(proc_task(inode)))
4788 +       if (!vx_check(vx_task_xid(task), VX_WATCH|VX_IDENT))
4789 +               goto out;
4790 +       if (!pid_alive(task))
4791                 goto out;
4792         retval = 0;
4793  
4794 diff -NurpP --minimal linux-2.6.10/fs/proc/generic.c linux-2.6.10-vs1.9.3.17/fs/proc/generic.c
4795 --- linux-2.6.10/fs/proc/generic.c      2004-12-25 01:55:21.000000000 +0100
4796 +++ linux-2.6.10-vs1.9.3.17/fs/proc/generic.c   2004-12-26 19:40:24.000000000 +0100
4797 @@ -19,6 +19,7 @@
4798  #include <linux/idr.h>
4799  #include <linux/namei.h>
4800  #include <linux/bitops.h>
4801 +#include <linux/vserver/inode.h>
4802  #include <asm/uaccess.h>
4803  
4804  static ssize_t proc_file_read(struct file *file, char __user *buf,
4805 @@ -372,11 +373,15 @@ struct dentry *proc_lookup(struct inode 
4806                 for (de = de->subdir; de ; de = de->next) {
4807                         if (de->namelen != dentry->d_name.len)
4808                                 continue;
4809 +                       if (!vx_hide_check(0, de->vx_flags))
4810 +                               continue;
4811                         if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
4812                                 unsigned int ino = de->low_ino;
4813  
4814                                 error = -EINVAL;
4815                                 inode = proc_get_inode(dir->i_sb, ino, de);
4816 +                               /* generic proc entries belong to the host */
4817 +                               inode->i_xid = 0;
4818                                 break;
4819                         }
4820                 }
4821 @@ -448,9 +453,12 @@ int proc_readdir(struct file * filp,
4822                         }
4823  
4824                         do {
4825 +                               if (!vx_hide_check(0, de->vx_flags))
4826 +                                       goto skip;
4827                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
4828                                             de->low_ino, de->mode >> 12) < 0)
4829                                         goto out;
4830 +                       skip:
4831                                 filp->f_pos++;
4832                                 de = de->next;
4833                         } while (de);
4834 @@ -562,6 +570,7 @@ static struct proc_dir_entry *proc_creat
4835         ent->namelen = len;
4836         ent->mode = mode;
4837         ent->nlink = nlink;
4838 +       ent->vx_flags = IATTR_PROC_DEFAULT;
4839   out:
4840         return ent;
4841  }
4842 @@ -582,7 +591,8 @@ struct proc_dir_entry *proc_symlink(cons
4843                                 kfree(ent->data);
4844                                 kfree(ent);
4845                                 ent = NULL;
4846 -                       }
4847 +                       } else
4848 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
4849                 } else {
4850                         kfree(ent);
4851                         ent = NULL;
4852 diff -NurpP --minimal linux-2.6.10/fs/proc/inode.c linux-2.6.10-vs1.9.3.17/fs/proc/inode.c
4853 --- linux-2.6.10/fs/proc/inode.c        2004-10-23 05:06:17.000000000 +0200
4854 +++ linux-2.6.10-vs1.9.3.17/fs/proc/inode.c     2004-12-26 19:40:24.000000000 +0100
4855 @@ -211,6 +211,8 @@ struct inode *proc_get_inode(struct supe
4856                         inode->i_uid = de->uid;
4857                         inode->i_gid = de->gid;
4858                 }
4859 +               if (de->vx_flags)
4860 +                       PROC_I(inode)->vx_flags = de->vx_flags;
4861                 if (de->size)
4862                         inode->i_size = de->size;
4863                 if (de->nlink)
4864 diff -NurpP --minimal linux-2.6.10/fs/proc/proc_misc.c linux-2.6.10-vs1.9.3.17/fs/proc/proc_misc.c
4865 --- linux-2.6.10/fs/proc/proc_misc.c    2004-12-25 01:55:21.000000000 +0100
4866 +++ linux-2.6.10-vs1.9.3.17/fs/proc/proc_misc.c 2004-12-26 19:40:30.000000000 +0100
4867 @@ -50,6 +50,8 @@
4868  #include <asm/tlb.h>
4869  #include <asm/div64.h>
4870  
4871 +#include <linux/vs_cvirt.h>
4872 +
4873  #define LOAD_INT(x) ((x) >> FSHIFT)
4874  #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
4875  /*
4876 @@ -81,17 +83,32 @@ static int proc_calc_metrics(char *page,
4877  static int loadavg_read_proc(char *page, char **start, off_t off,
4878                                  int count, int *eof, void *data)
4879  {
4880 +       unsigned int running, threads;
4881         int a, b, c;
4882         int len;
4883  
4884 -       a = avenrun[0] + (FIXED_1/200);
4885 -       b = avenrun[1] + (FIXED_1/200);
4886 -       c = avenrun[2] + (FIXED_1/200);
4887 -       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
4888 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
4889 +               struct vx_info *vxi = current->vx_info;
4890 +
4891 +               a = vxi->cvirt.load[0] + (FIXED_1/200);
4892 +               b = vxi->cvirt.load[1] + (FIXED_1/200);
4893 +               c = vxi->cvirt.load[2] + (FIXED_1/200);
4894 +
4895 +               running = atomic_read(&vxi->cvirt.nr_running);
4896 +               threads = atomic_read(&vxi->cvirt.nr_threads);
4897 +       } else {
4898 +               a = avenrun[0] + (FIXED_1/200);
4899 +               b = avenrun[1] + (FIXED_1/200);
4900 +               c = avenrun[2] + (FIXED_1/200);
4901 +
4902 +               running = nr_running();
4903 +               threads = nr_threads;
4904 +       }
4905 +       len = sprintf(page,"%d.%02d %d.%02d %d.%02d %d/%d %d\n",
4906                 LOAD_INT(a), LOAD_FRAC(a),
4907                 LOAD_INT(b), LOAD_FRAC(b),
4908                 LOAD_INT(c), LOAD_FRAC(c),
4909 -               nr_running(), nr_threads, last_pid);
4910 +               running, threads, last_pid);
4911         return proc_calc_metrics(page, start, off, count, eof, len);
4912  }
4913  
4914 @@ -140,6 +157,9 @@ static int uptime_read_proc(char *page, 
4915  
4916         do_posix_clock_monotonic_gettime(&uptime);
4917         jiffies_to_timespec(idle_jiffies, &idle);
4918 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
4919 +               vx_vsi_uptime(&uptime, &idle);
4920 +
4921         len = sprintf(page,"%lu.%02lu %lu.%02lu\n",
4922                         (unsigned long) uptime.tv_sec,
4923                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
4924 diff -NurpP --minimal linux-2.6.10/fs/proc/root.c linux-2.6.10-vs1.9.3.17/fs/proc/root.c
4925 --- linux-2.6.10/fs/proc/root.c 2004-12-25 01:55:21.000000000 +0100
4926 +++ linux-2.6.10-vs1.9.3.17/fs/proc/root.c      2004-12-26 19:40:24.000000000 +0100
4927 @@ -23,6 +23,9 @@ struct proc_dir_entry *proc_net, *proc_n
4928  #ifdef CONFIG_SYSCTL
4929  struct proc_dir_entry *proc_sys_root;
4930  #endif
4931 +struct proc_dir_entry *proc_virtual;
4932 +
4933 +extern void proc_vx_init(void);
4934  
4935  static struct super_block *proc_get_sb(struct file_system_type *fs_type,
4936         int flags, const char *dev_name, void *data)
4937 @@ -77,6 +80,7 @@ void __init proc_root_init(void)
4938         proc_device_tree_init();
4939  #endif
4940         proc_bus = proc_mkdir("bus", NULL);
4941 +       proc_vx_init();
4942  }
4943  
4944  static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry, struct nameidata *nd)
4945 diff -NurpP --minimal linux-2.6.10/fs/reiserfs/inode.c linux-2.6.10-vs1.9.3.17/fs/reiserfs/inode.c
4946 --- linux-2.6.10/fs/reiserfs/inode.c    2004-12-25 01:55:21.000000000 +0100
4947 +++ linux-2.6.10-vs1.9.3.17/fs/reiserfs/inode.c 2004-12-26 19:40:34.000000000 +0100
4948 @@ -17,6 +17,7 @@
4949  #include <linux/mpage.h>
4950  #include <linux/writeback.h>
4951  #include <linux/quotaops.h>
4952 +#include <linux/vserver/xid.h>
4953  
4954  extern int reiserfs_default_io_size; /* default io size devuned in super.c */
4955  
4956 @@ -1049,6 +1050,8 @@ static void init_inode (struct inode * i
4957      struct buffer_head * bh;
4958      struct item_head * ih;
4959      __u32 rdev;
4960 +    uid_t uid;
4961 +    gid_t gid;
4962      //int version = ITEM_VERSION_1;
4963  
4964      bh = PATH_PLAST_BUFFER (path);
4965 @@ -1072,12 +1075,13 @@ static void init_inode (struct inode * i
4966         struct stat_data_v1 * sd = (struct stat_data_v1 *)B_I_PITEM (bh, ih);
4967         unsigned long blocks;
4968  
4969 +       uid = sd_v1_uid(sd);
4970 +       gid = sd_v1_gid(sd);
4971 +
4972         set_inode_item_key_version (inode, KEY_FORMAT_3_5);
4973          set_inode_sd_version (inode, STAT_DATA_V1);
4974         inode->i_mode  = sd_v1_mode(sd);
4975         inode->i_nlink = sd_v1_nlink(sd);
4976 -       inode->i_uid   = sd_v1_uid(sd);
4977 -       inode->i_gid   = sd_v1_gid(sd);
4978         inode->i_size  = sd_v1_size(sd);
4979         inode->i_atime.tv_sec = sd_v1_atime(sd);
4980         inode->i_mtime.tv_sec = sd_v1_mtime(sd);
4981 @@ -1117,11 +1121,12 @@ static void init_inode (struct inode * i
4982         // (directories and symlinks)
4983         struct stat_data * sd = (struct stat_data *)B_I_PITEM (bh, ih);
4984  
4985 +       uid    = sd_v2_uid(sd);
4986 +       gid    = sd_v2_gid(sd);
4987 +
4988         inode->i_mode   = sd_v2_mode(sd);
4989         inode->i_nlink  = sd_v2_nlink(sd);
4990 -       inode->i_uid    = sd_v2_uid(sd);
4991         inode->i_size   = sd_v2_size(sd);
4992 -       inode->i_gid    = sd_v2_gid(sd);
4993         inode->i_mtime.tv_sec  = sd_v2_mtime(sd);
4994         inode->i_atime.tv_sec = sd_v2_atime(sd);
4995         inode->i_ctime.tv_sec  = sd_v2_ctime(sd);
4996 @@ -1148,6 +1153,9 @@ static void init_inode (struct inode * i
4997         REISERFS_I(inode)->i_attrs = sd_v2_attrs( sd );
4998         sd_attrs_to_i_attrs( sd_v2_attrs( sd ), inode );
4999      }
5000 +    inode->i_uid = INOXID_UID(XID_TAG(inode), uid, gid);
5001 +    inode->i_gid = INOXID_GID(XID_TAG(inode), uid, gid);
5002 +    inode->i_xid = INOXID_XID(XID_TAG(inode), uid, gid, 0);
5003  
5004      pathrelse (path);
5005      if (S_ISREG (inode->i_mode)) {
5006 @@ -1172,13 +1180,15 @@ static void init_inode (struct inode * i
5007  static void inode2sd (void * sd, struct inode * inode, loff_t size)
5008  {
5009      struct stat_data * sd_v2 = (struct stat_data *)sd;
5010 +    uid_t uid = XIDINO_UID(XID_TAG(inode), inode->i_uid, inode->i_xid);
5011 +    gid_t gid = XIDINO_GID(XID_TAG(inode), inode->i_gid, inode->i_xid);
5012      __u16 flags;
5013  
5014 +    set_sd_v2_uid(sd_v2, uid );
5015 +    set_sd_v2_gid(sd_v2, gid );
5016      set_sd_v2_mode(sd_v2, inode->i_mode );
5017      set_sd_v2_nlink(sd_v2, inode->i_nlink );
5018 -    set_sd_v2_uid(sd_v2, inode->i_uid );
5019      set_sd_v2_size(sd_v2, size );
5020 -    set_sd_v2_gid(sd_v2, inode->i_gid );
5021      set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec );
5022      set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec );
5023      set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec );
5024 @@ -2554,6 +2564,14 @@ void sd_attrs_to_i_attrs( __u16 sd_attrs
5025                         inode -> i_flags |= S_IMMUTABLE;
5026                 else
5027                         inode -> i_flags &= ~S_IMMUTABLE;
5028 +               if( sd_attrs & REISERFS_IUNLINK_FL )
5029 +                       inode -> i_flags |= S_IUNLINK;
5030 +               else
5031 +                       inode -> i_flags &= ~S_IUNLINK;
5032 +               if( sd_attrs & REISERFS_BARRIER_FL )
5033 +                       inode -> i_flags |= S_BARRIER;
5034 +               else
5035 +                       inode -> i_flags &= ~S_BARRIER;
5036                 if( sd_attrs & REISERFS_APPEND_FL )
5037                         inode -> i_flags |= S_APPEND;
5038                 else
5039 @@ -2576,6 +2594,14 @@ void i_attrs_to_sd_attrs( struct inode *
5040                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
5041                 else
5042                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
5043 +               if( inode -> i_flags & S_IUNLINK )
5044 +                       *sd_attrs |= REISERFS_IUNLINK_FL;
5045 +               else
5046 +                       *sd_attrs &= ~REISERFS_IUNLINK_FL;
5047 +               if( inode -> i_flags & S_BARRIER )
5048 +                       *sd_attrs |= REISERFS_BARRIER_FL;
5049 +               else
5050 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
5051                 if( inode -> i_flags & S_SYNC )
5052                         *sd_attrs |= REISERFS_SYNC_FL;
5053                 else
5054 @@ -2748,6 +2774,27 @@ static ssize_t reiserfs_direct_IO(int rw
5055                         offset, nr_segs, reiserfs_get_blocks_direct_io, NULL);
5056  }
5057  
5058 +int reiserfs_setattr_flags(struct inode *inode, unsigned int flags)
5059 +{
5060 +       unsigned int oldflags, newflags;
5061 +
5062 +       oldflags = REISERFS_I(inode)->i_flags;
5063 +       newflags = oldflags & ~(REISERFS_IMMUTABLE_FL |
5064 +               REISERFS_IUNLINK_FL | REISERFS_BARRIER_FL);
5065 +       if (flags & ATTR_FLAG_IMMUTABLE)
5066 +               newflags |= REISERFS_IMMUTABLE_FL;
5067 +       if (flags & ATTR_FLAG_IUNLINK)
5068 +               newflags |= REISERFS_IUNLINK_FL;
5069 +       if (flags & ATTR_FLAG_BARRIER)
5070 +               newflags |= REISERFS_BARRIER_FL;
5071 +
5072 +       if (oldflags ^ newflags) {
5073 +               REISERFS_I(inode)->i_flags = newflags;
5074 +               inode->i_ctime = CURRENT_TIME;
5075 +       }
5076 +       return 0;
5077 +}
5078 +
5079  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) {
5080      struct inode *inode = dentry->d_inode ;
5081      int error ;
5082 @@ -2791,6 +2838,10 @@ int reiserfs_setattr(struct dentry *dent
5083         }
5084  
5085      error = inode_change_ok(inode, attr) ;
5086 +
5087 +    if (!error && attr->ia_valid & ATTR_ATTR_FLAG)
5088 +       reiserfs_setattr_flags(inode, attr->ia_attr_flags);
5089 +
5090      if (!error) {
5091         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
5092             (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
5093 diff -NurpP --minimal linux-2.6.10/fs/reiserfs/ioctl.c linux-2.6.10-vs1.9.3.17/fs/reiserfs/ioctl.c
5094 --- linux-2.6.10/fs/reiserfs/ioctl.c    2004-08-14 12:55:19.000000000 +0200
5095 +++ linux-2.6.10-vs1.9.3.17/fs/reiserfs/ioctl.c 2004-12-26 19:40:30.000000000 +0100
5096 @@ -20,7 +20,7 @@
5097  int reiserfs_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
5098                 unsigned long arg)
5099  {
5100 -       unsigned int flags;
5101 +       unsigned int flags, oldflags;
5102  
5103         switch (cmd) {
5104             case REISERFS_IOC_UNPACK:
5105 @@ -36,6 +36,7 @@ int reiserfs_ioctl (struct inode * inode
5106         case REISERFS_IOC_GETFLAGS:
5107                 flags = REISERFS_I(inode) -> i_attrs;
5108                 i_attrs_to_sd_attrs( inode, ( __u16 * ) &flags );
5109 +               flags &= REISERFS_FL_USER_VISIBLE;
5110                 return put_user(flags, (int __user *) arg);
5111         case REISERFS_IOC_SETFLAGS: {
5112                 if (IS_RDONLY(inode))
5113 @@ -47,8 +48,12 @@ int reiserfs_ioctl (struct inode * inode
5114                 if (get_user(flags, (int __user *) arg))
5115                         return -EFAULT;
5116  
5117 -               if ( ( ( flags ^ REISERFS_I(inode) -> i_attrs) & ( REISERFS_IMMUTABLE_FL | REISERFS_APPEND_FL)) &&
5118 -                    !capable( CAP_LINUX_IMMUTABLE ) )
5119 +               oldflags = REISERFS_I(inode) -> i_attrs;
5120 +               if ( ( (oldflags & REISERFS_IMMUTABLE_FL) ||
5121 +                       ( (flags ^ oldflags) &
5122 +                       (REISERFS_IMMUTABLE_FL | REISERFS_IUNLINK_FL |
5123 +                        REISERFS_APPEND_FL) ) ) &&
5124 +                       !capable( CAP_LINUX_IMMUTABLE ) )
5125                         return -EPERM;
5126                         
5127                 if( ( flags & REISERFS_NOTAIL_FL ) &&
5128 @@ -59,6 +64,9 @@ int reiserfs_ioctl (struct inode * inode
5129                                 if( result )
5130                                         return result;
5131                 }
5132 +
5133 +               flags = flags & REISERFS_FL_USER_MODIFYABLE;
5134 +               flags |= oldflags & ~REISERFS_FL_USER_MODIFYABLE;
5135                 sd_attrs_to_i_attrs( flags, inode );
5136                 REISERFS_I(inode) -> i_attrs = flags;
5137                 inode->i_ctime = CURRENT_TIME;
5138 diff -NurpP --minimal linux-2.6.10/fs/reiserfs/namei.c linux-2.6.10-vs1.9.3.17/fs/reiserfs/namei.c
5139 --- linux-2.6.10/fs/reiserfs/namei.c    2004-12-25 01:55:21.000000000 +0100
5140 +++ linux-2.6.10-vs1.9.3.17/fs/reiserfs/namei.c 2004-12-26 19:40:34.000000000 +0100
5141 @@ -19,6 +19,7 @@
5142  #include <linux/reiserfs_xattr.h>
5143  #include <linux/smp_lock.h>
5144  #include <linux/quotaops.h>
5145 +#include <linux/vserver/xid.h>
5146  
5147  #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { i->i_nlink++; if (i->i_nlink >= REISERFS_LINK_MAX) i->i_nlink=1; }
5148  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) i->i_nlink--;
5149 @@ -350,6 +351,7 @@ static struct dentry * reiserfs_lookup (
5150             reiserfs_write_unlock(dir->i_sb);
5151             return ERR_PTR(-EACCES);
5152          }
5153 +       vx_propagate_xid(nd, inode);
5154  
5155         /* Propogate the priv_object flag so we know we're in the priv tree */
5156         if (is_reiserfs_priv_object (dir))
5157 diff -NurpP --minimal linux-2.6.10/fs/reiserfs/super.c linux-2.6.10-vs1.9.3.17/fs/reiserfs/super.c
5158 --- linux-2.6.10/fs/reiserfs/super.c    2004-12-25 01:55:21.000000000 +0100
5159 +++ linux-2.6.10-vs1.9.3.17/fs/reiserfs/super.c 2004-12-26 19:40:34.000000000 +0100
5160 @@ -757,6 +757,7 @@ static int reiserfs_parse_options (struc
5161         {"user_xattr",  .setmask = 1<<REISERFS_UNSUPPORTED_OPT},
5162         {"nouser_xattr",.clrmask = 1<<REISERFS_UNSUPPORTED_OPT},
5163  #endif
5164 +       {"tagxid",      .setmask = 1<<REISERFS_TAGXID},
5165  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
5166         {"acl",         .setmask = 1<<REISERFS_POSIXACL},
5167         {"noacl",       .clrmask = 1<<REISERFS_POSIXACL},
5168 diff -NurpP --minimal linux-2.6.10/fs/stat.c linux-2.6.10-vs1.9.3.17/fs/stat.c
5169 --- linux-2.6.10/fs/stat.c      2004-12-25 01:55:21.000000000 +0100
5170 +++ linux-2.6.10-vs1.9.3.17/fs/stat.c   2004-12-26 19:40:34.000000000 +0100
5171 @@ -27,6 +27,7 @@ void generic_fillattr(struct inode *inod
5172         stat->nlink = inode->i_nlink;
5173         stat->uid = inode->i_uid;
5174         stat->gid = inode->i_gid;
5175 +       stat->xid = inode->i_xid;
5176         stat->rdev = inode->i_rdev;
5177         stat->atime = inode->i_atime;
5178         stat->mtime = inode->i_mtime;
5179 diff -NurpP --minimal linux-2.6.10/fs/super.c linux-2.6.10-vs1.9.3.17/fs/super.c
5180 --- linux-2.6.10/fs/super.c     2004-12-25 01:55:21.000000000 +0100
5181 +++ linux-2.6.10-vs1.9.3.17/fs/super.c  2004-12-26 19:40:30.000000000 +0100
5182 @@ -37,6 +37,8 @@
5183  #include <linux/writeback.h>           /* for the emergency remount stuff */
5184  #include <linux/idr.h>
5185  #include <linux/kobject.h>
5186 +#include <linux/devpts_fs.h>
5187 +#include <linux/proc_fs.h>
5188  #include <asm/uaccess.h>
5189  
5190  
5191 @@ -824,6 +826,13 @@ do_kern_mount(const char *fstype, int fl
5192         sb = type->get_sb(type, flags, name, data);
5193         if (IS_ERR(sb))
5194                 goto out_free_secdata;
5195 +
5196 +       error = -EPERM;
5197 +       if (!capable(CAP_SYS_ADMIN) && !sb->s_bdev &&
5198 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
5199 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
5200 +               goto out_sb;
5201 +
5202         error = security_sb_kern_mount(sb, secdata);
5203         if (error)
5204                 goto out_sb;
5205 diff -NurpP --minimal linux-2.6.10/fs/sysfs/mount.c linux-2.6.10-vs1.9.3.17/fs/sysfs/mount.c
5206 --- linux-2.6.10/fs/sysfs/mount.c       2004-12-25 01:55:21.000000000 +0100
5207 +++ linux-2.6.10-vs1.9.3.17/fs/sysfs/mount.c    2004-12-26 19:40:30.000000000 +0100
5208 @@ -11,8 +11,6 @@
5209  
5210  #include "sysfs.h"
5211  
5212 -/* Random magic number */
5213 -#define SYSFS_MAGIC 0x62656572
5214  
5215  struct vfsmount *sysfs_mount;
5216  struct super_block * sysfs_sb = NULL;
5217 @@ -36,7 +34,7 @@ static int sysfs_fill_super(struct super
5218  
5219         sb->s_blocksize = PAGE_CACHE_SIZE;
5220         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
5221 -       sb->s_magic = SYSFS_MAGIC;
5222 +       sb->s_magic = SYSFS_SUPER_MAGIC;
5223         sb->s_op = &sysfs_ops;
5224         sysfs_sb = sb;
5225  
5226 diff -NurpP --minimal linux-2.6.10/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.10-vs1.9.3.17/fs/xfs/linux-2.6/xfs_ioctl.c
5227 --- linux-2.6.10/fs/xfs/linux-2.6/xfs_ioctl.c   2004-12-25 01:55:22.000000000 +0100
5228 +++ linux-2.6.10-vs1.9.3.17/fs/xfs/linux-2.6/xfs_ioctl.c        2004-12-26 19:40:31.000000000 +0100
5229 @@ -1008,6 +1008,8 @@ xfs_ioc_fsgeometry(
5230  #define LINUX_XFLAG_APPEND     0x00000020 /* writes to file may only append */
5231  #define LINUX_XFLAG_NODUMP     0x00000040 /* do not dump file */
5232  #define LINUX_XFLAG_NOATIME    0x00000080 /* do not update atime */
5233 +#define LINUX_XFLAG_BARRIER    0x00004000 /* chroot() barrier */
5234 +#define LINUX_XFLAG_IUNLINK    0x00008000 /* immutable unlink */
5235  
5236  STATIC unsigned int
5237  xfs_merge_ioc_xflags(
5238 @@ -1048,6 +1050,10 @@ xfs_di2lxflags(
5239  
5240         if (di_flags & XFS_DIFLAG_IMMUTABLE)
5241                 flags |= LINUX_XFLAG_IMMUTABLE;
5242 +       if (di_flags & XFS_DIFLAG_IUNLINK)
5243 +               flags |= LINUX_XFLAG_IUNLINK;
5244 +       if (di_flags & XFS_DIFLAG_BARRIER)
5245 +               flags |= LINUX_XFLAG_BARRIER;
5246         if (di_flags & XFS_DIFLAG_APPEND)
5247                 flags |= LINUX_XFLAG_APPEND;
5248         if (di_flags & XFS_DIFLAG_SYNC)
5249 diff -NurpP --minimal linux-2.6.10/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.10-vs1.9.3.17/fs/xfs/linux-2.6/xfs_iops.c
5250 --- linux-2.6.10/fs/xfs/linux-2.6/xfs_iops.c    2004-10-23 05:06:18.000000000 +0200
5251 +++ linux-2.6.10-vs1.9.3.17/fs/xfs/linux-2.6/xfs_iops.c 2004-12-26 19:40:31.000000000 +0100
5252 @@ -495,6 +495,28 @@ linvfs_getattr(
5253  }
5254  
5255  STATIC int
5256 +linvfs_setattr_flags(
5257 +       vattr_t *vap,
5258 +       unsigned int flags)
5259 +{
5260 +       unsigned int oldflags, newflags;
5261 +
5262 +       oldflags = vap->va_xflags;
5263 +       newflags = oldflags & ~(XFS_XFLAG_IMMUTABLE |
5264 +               XFS_XFLAG_IUNLINK | XFS_XFLAG_BARRIER);
5265 +       if (flags & ATTR_FLAG_IMMUTABLE)
5266 +               newflags |= XFS_XFLAG_IMMUTABLE;
5267 +       if (flags & ATTR_FLAG_IUNLINK)
5268 +               newflags |= XFS_XFLAG_IUNLINK;
5269 +       if (flags & ATTR_FLAG_BARRIER)
5270 +               newflags |= XFS_XFLAG_BARRIER;
5271 +
5272 +       if (oldflags ^ newflags)
5273 +               vap->va_xflags = newflags;
5274 +       return 0;
5275 +}
5276 +
5277 +STATIC int
5278  linvfs_setattr(
5279         struct dentry   *dentry,
5280         struct iattr    *attr)
5281 @@ -545,6 +567,11 @@ linvfs_setattr(
5282                 flags |= ATTR_NONBLOCK;
5283  #endif
5284  
5285 +       if (ia_valid & ATTR_ATTR_FLAG) {
5286 +               vattr.va_mask |= XFS_AT_XFLAGS;
5287 +               linvfs_setattr_flags(&vattr, attr->ia_attr_flags);
5288 +       }
5289 +
5290         VOP_SETATTR(vp, &vattr, flags, NULL, error);
5291         if (error)
5292                 return -error;
5293 diff -NurpP --minimal linux-2.6.10/fs/xfs/linux-2.6/xfs_super.c linux-2.6.10-vs1.9.3.17/fs/xfs/linux-2.6/xfs_super.c
5294 --- linux-2.6.10/fs/xfs/linux-2.6/xfs_super.c   2004-12-25 01:55:22.000000000 +0100
5295 +++ linux-2.6.10-vs1.9.3.17/fs/xfs/linux-2.6/xfs_super.c        2004-12-26 19:40:31.000000000 +0100
5296 @@ -192,6 +192,14 @@ xfs_revalidate_inode(
5297                 inode->i_flags |= S_IMMUTABLE;
5298         else
5299                 inode->i_flags &= ~S_IMMUTABLE;
5300 +       if (ip->i_d.di_flags & XFS_DIFLAG_IUNLINK)
5301 +               inode->i_flags |= S_IUNLINK;
5302 +       else
5303 +               inode->i_flags &= ~S_IUNLINK;
5304 +       if (ip->i_d.di_flags & XFS_DIFLAG_BARRIER)
5305 +               inode->i_flags |= S_BARRIER;
5306 +       else
5307 +               inode->i_flags &= ~S_BARRIER;
5308         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
5309                 inode->i_flags |= S_APPEND;
5310         else
5311 diff -NurpP --minimal linux-2.6.10/fs/xfs/linux-2.6/xfs_vnode.c linux-2.6.10-vs1.9.3.17/fs/xfs/linux-2.6/xfs_vnode.c
5312 --- linux-2.6.10/fs/xfs/linux-2.6/xfs_vnode.c   2004-10-23 05:06:18.000000000 +0200
5313 +++ linux-2.6.10-vs1.9.3.17/fs/xfs/linux-2.6/xfs_vnode.c        2004-12-26 19:40:31.000000000 +0100
5314 @@ -212,6 +212,14 @@ vn_revalidate_core(
5315                 inode->i_flags |= S_IMMUTABLE;
5316         else
5317                 inode->i_flags &= ~S_IMMUTABLE;
5318 +       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
5319 +               inode->i_flags |= S_IUNLINK;
5320 +       else
5321 +               inode->i_flags &= ~S_IUNLINK;
5322 +       if (vap->va_xflags & XFS_XFLAG_BARRIER)
5323 +               inode->i_flags |= S_BARRIER;
5324 +       else
5325 +               inode->i_flags &= ~S_BARRIER;
5326         if (vap->va_xflags & XFS_XFLAG_APPEND)
5327                 inode->i_flags |= S_APPEND;
5328         else
5329 diff -NurpP --minimal linux-2.6.10/fs/xfs/xfs_dinode.h linux-2.6.10-vs1.9.3.17/fs/xfs/xfs_dinode.h
5330 --- linux-2.6.10/fs/xfs/xfs_dinode.h    2004-10-23 05:06:18.000000000 +0200
5331 +++ linux-2.6.10-vs1.9.3.17/fs/xfs/xfs_dinode.h 2004-12-26 19:40:31.000000000 +0100
5332 @@ -459,6 +459,9 @@ xfs_dinode_t *xfs_buf_to_dinode(struct x
5333  #define XFS_DIFLAG_RTINHERIT_BIT 8     /* create with realtime bit set */
5334  #define XFS_DIFLAG_PROJINHERIT_BIT  9  /* create with parents projid */
5335  #define XFS_DIFLAG_NOSYMLINKS_BIT  10  /* disallow symlink creation */
5336 +#define XFS_DIFLAG_BARRIER_BIT  12     /* chroot() barrier */
5337 +#define XFS_DIFLAG_IUNLINK_BIT  13     /* immutable unlink */
5338 +
5339  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
5340  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
5341  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
5342 @@ -470,6 +473,9 @@ xfs_dinode_t *xfs_buf_to_dinode(struct x
5343  #define XFS_DIFLAG_RTINHERIT     (1 << XFS_DIFLAG_RTINHERIT_BIT)
5344  #define XFS_DIFLAG_PROJINHERIT   (1 << XFS_DIFLAG_PROJINHERIT_BIT)
5345  #define XFS_DIFLAG_NOSYMLINKS    (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
5346 +#define XFS_DIFLAG_BARRIER      (1 << XFS_DIFLAG_BARRIER_BIT)
5347 +#define XFS_DIFLAG_IUNLINK      (1 << XFS_DIFLAG_IUNLINK_BIT)
5348 +
5349  
5350  #define XFS_DIFLAG_ANY \
5351         (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
5352 diff -NurpP --minimal linux-2.6.10/fs/xfs/xfs_fs.h linux-2.6.10-vs1.9.3.17/fs/xfs/xfs_fs.h
5353 --- linux-2.6.10/fs/xfs/xfs_fs.h        2004-10-23 05:06:18.000000000 +0200
5354 +++ linux-2.6.10-vs1.9.3.17/fs/xfs/xfs_fs.h     2004-12-26 19:40:31.000000000 +0100
5355 @@ -79,6 +79,8 @@ struct fsxattr {
5356  #define XFS_XFLAG_RTINHERIT    0x00000100      /* create with rt bit set */
5357  #define XFS_XFLAG_PROJINHERIT  0x00000200      /* create with parents projid */
5358  #define XFS_XFLAG_NOSYMLINKS   0x00000400      /* disallow symlink creation */
5359 +#define XFS_XFLAG_BARRIER      0x00004000      /* chroot() barrier */
5360 +#define XFS_XFLAG_IUNLINK      0x00008000      /* immutable unlink */
5361  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
5362  
5363  /*
5364 diff -NurpP --minimal linux-2.6.10/fs/xfs/xfs_vnodeops.c linux-2.6.10-vs1.9.3.17/fs/xfs/xfs_vnodeops.c
5365 --- linux-2.6.10/fs/xfs/xfs_vnodeops.c  2004-10-23 05:06:19.000000000 +0200
5366 +++ linux-2.6.10-vs1.9.3.17/fs/xfs/xfs_vnodeops.c       2004-12-26 19:40:31.000000000 +0100
5367 @@ -832,6 +832,10 @@ xfs_setattr(
5368                         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
5369                         if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
5370                                 di_flags |= XFS_DIFLAG_IMMUTABLE;
5371 +                       if (vap->va_xflags & XFS_XFLAG_IUNLINK)
5372 +                               di_flags |= XFS_DIFLAG_IUNLINK;
5373 +                       if (vap->va_xflags & XFS_XFLAG_BARRIER)
5374 +                               di_flags |= XFS_DIFLAG_BARRIER;
5375                         if (vap->va_xflags & XFS_XFLAG_APPEND)
5376                                 di_flags |= XFS_DIFLAG_APPEND;
5377                         if (vap->va_xflags & XFS_XFLAG_SYNC)
5378 diff -NurpP --minimal linux-2.6.10/include/asm-alpha/unistd.h linux-2.6.10-vs1.9.3.17/include/asm-alpha/unistd.h
5379 --- linux-2.6.10/include/asm-alpha/unistd.h     2004-10-23 05:06:19.000000000 +0200
5380 +++ linux-2.6.10-vs1.9.3.17/include/asm-alpha/unistd.h  2004-12-26 19:40:24.000000000 +0100
5381 @@ -233,6 +233,7 @@
5382  #define __NR_osf_memcntl       260     /* not implemented */
5383  #define __NR_osf_fdatasync     261     /* not implemented */
5384  
5385 +#define __NR_vserver           273
5386  
5387  /*
5388   * Linux-specific system calls begin at 300
5389 diff -NurpP --minimal linux-2.6.10/include/asm-arm/tlb.h linux-2.6.10-vs1.9.3.17/include/asm-arm/tlb.h
5390 --- linux-2.6.10/include/asm-arm/tlb.h  2004-08-14 12:54:47.000000000 +0200
5391 +++ linux-2.6.10-vs1.9.3.17/include/asm-arm/tlb.h       2004-12-26 19:40:35.000000000 +0100
5392 @@ -58,7 +58,8 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
5393  
5394         if (rss < freed)
5395                 freed = rss;
5396 -       mm->rss = rss - freed;
5397 +       // mm->rss = rss - freed;
5398 +       vx_rsspages_sub(mm, freed);
5399  
5400         if (freed) {
5401                 flush_tlb_mm(mm);
5402 diff -NurpP --minimal linux-2.6.10/include/asm-arm26/tlb.h linux-2.6.10-vs1.9.3.17/include/asm-arm26/tlb.h
5403 --- linux-2.6.10/include/asm-arm26/tlb.h        2004-08-14 12:56:23.000000000 +0200
5404 +++ linux-2.6.10-vs1.9.3.17/include/asm-arm26/tlb.h     2004-12-26 19:40:35.000000000 +0100
5405 @@ -39,7 +39,8 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
5406  
5407          if (rss < freed)
5408                  freed = rss;
5409 -        mm->rss = rss - freed;
5410 +       // mm->rss = rss - freed;
5411 +       vx_rsspages_sub(mm, freed);
5412  
5413          if (freed) {
5414                  flush_tlb_mm(mm);
5415 diff -NurpP --minimal linux-2.6.10/include/asm-generic/tlb.h linux-2.6.10-vs1.9.3.17/include/asm-generic/tlb.h
5416 --- linux-2.6.10/include/asm-generic/tlb.h      2004-08-14 12:54:46.000000000 +0200
5417 +++ linux-2.6.10-vs1.9.3.17/include/asm-generic/tlb.h   2004-12-26 19:40:35.000000000 +0100
5418 @@ -15,6 +15,7 @@
5419  
5420  #include <linux/config.h>
5421  #include <linux/swap.h>
5422 +#include <linux/vs_memory.h>
5423  #include <asm/pgalloc.h>
5424  #include <asm/tlbflush.h>
5425  
5426 @@ -92,7 +93,8 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
5427  
5428         if (rss < freed)
5429                 freed = rss;
5430 -       mm->rss = rss - freed;
5431 +       // mm->rss = rss - freed;
5432 +       vx_rsspages_sub(mm, freed);
5433         tlb_flush_mmu(tlb, start, end);
5434  
5435         /* keep the page table cache within bounds */
5436 diff -NurpP --minimal linux-2.6.10/include/asm-i386/elf.h linux-2.6.10-vs1.9.3.17/include/asm-i386/elf.h
5437 --- linux-2.6.10/include/asm-i386/elf.h 2004-10-23 05:06:20.000000000 +0200
5438 +++ linux-2.6.10-vs1.9.3.17/include/asm-i386/elf.h      2004-12-26 19:40:36.000000000 +0100
5439 @@ -70,7 +70,7 @@ typedef struct user_fxsr_struct elf_fpxr
5440     the loader.  We need to make sure that it is out of the way of the program
5441     that it will "exec", and that there is sufficient room for the brk.  */
5442  
5443 -#define ELF_ET_DYN_BASE         (TASK_SIZE / 3 * 2)
5444 +#define ELF_ET_DYN_BASE                ((TASK_UNMAPPED_BASE) * 2)
5445  
5446  /* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
5447     now struct_user_regs, they are different) */
5448 diff -NurpP --minimal linux-2.6.10/include/asm-i386/page.h linux-2.6.10-vs1.9.3.17/include/asm-i386/page.h
5449 --- linux-2.6.10/include/asm-i386/page.h        2004-12-25 01:55:23.000000000 +0100
5450 +++ linux-2.6.10-vs1.9.3.17/include/asm-i386/page.h     2004-12-26 19:40:36.000000000 +0100
5451 @@ -120,16 +120,23 @@ extern int sysctl_legacy_va_layout;
5452  
5453  #endif /* __ASSEMBLY__ */
5454  
5455 -#ifdef __ASSEMBLY__
5456 +#if   defined(CONFIG_SPLIT_3GB)
5457  #define __PAGE_OFFSET          (0xC0000000)
5458 -#else
5459 -#define __PAGE_OFFSET          (0xC0000000UL)
5460 +#elif defined(CONFIG_SPLIT_25GB)
5461 +#define __PAGE_OFFSET          (0xA0000000)
5462 +#elif defined(CONFIG_SPLIT_2GB)
5463 +#define __PAGE_OFFSET          (0x80000000)
5464 +#elif defined(CONFIG_SPLIT_15GB)
5465 +#define __PAGE_OFFSET          (0x60000000)
5466 +#elif defined(CONFIG_SPLIT_1GB)
5467 +#define __PAGE_OFFSET          (0x40000000)
5468  #endif
5469  
5470 -
5471  #define PAGE_OFFSET            ((unsigned long)__PAGE_OFFSET)
5472  #define VMALLOC_RESERVE                ((unsigned long)__VMALLOC_RESERVE)
5473 -#define MAXMEM                 (-__PAGE_OFFSET-__VMALLOC_RESERVE)
5474 +#define __MAXMEM               (-__PAGE_OFFSET-__VMALLOC_RESERVE)
5475 +#define MAXMEM                 ((unsigned long)(-PAGE_OFFSET-VMALLOC_RESERVE))
5476 +
5477  #define __pa(x)                        ((unsigned long)(x)-PAGE_OFFSET)
5478  #define __va(x)                        ((void *)((unsigned long)(x)+PAGE_OFFSET))
5479  #define pfn_to_kaddr(pfn)      __va((pfn) << PAGE_SHIFT)
5480 diff -NurpP --minimal linux-2.6.10/include/asm-i386/param.h linux-2.6.10-vs1.9.3.17/include/asm-i386/param.h
5481 --- linux-2.6.10/include/asm-i386/param.h       2004-08-14 12:54:51.000000000 +0200
5482 +++ linux-2.6.10-vs1.9.3.17/include/asm-i386/param.h    2004-12-26 19:40:36.000000000 +0100
5483 @@ -1,8 +1,14 @@
5484  #ifndef _ASMi386_PARAM_H
5485  #define _ASMi386_PARAM_H
5486  
5487 +#include <linux/config.h>
5488 +
5489  #ifdef __KERNEL__
5490 -# define HZ            1000            /* Internal kernel timer frequency */
5491 +# ifdef CONFIG_KERNEL_HZ
5492 +#  define HZ           CONFIG_KERNEL_HZ
5493 +# else
5494 +#  define HZ           1000            /* Internal kernel timer frequency */
5495 +# endif
5496  # define USER_HZ       100             /* .. some user interfaces are in "ticks" */
5497  # define CLOCKS_PER_SEC                (USER_HZ)       /* like times() */
5498  #endif
5499 diff -NurpP --minimal linux-2.6.10/include/asm-i386/processor.h linux-2.6.10-vs1.9.3.17/include/asm-i386/processor.h
5500 --- linux-2.6.10/include/asm-i386/processor.h   2004-12-25 01:55:23.000000000 +0100
5501 +++ linux-2.6.10-vs1.9.3.17/include/asm-i386/processor.h        2004-12-26 19:40:36.000000000 +0100
5502 @@ -289,9 +289,10 @@ extern unsigned int BIOS_revision;
5503  extern unsigned int mca_pentium_flag;
5504  
5505  /*
5506 - * User space process size: 3GB (default).
5507 + * User space process size: (3GB default).
5508   */
5509 -#define TASK_SIZE      (PAGE_OFFSET)
5510 +#define __TASK_SIZE            (__PAGE_OFFSET)
5511 +#define TASK_SIZE              ((unsigned long)__TASK_SIZE)
5512  
5513  /* This decides where the kernel will search for a free chunk of vm
5514   * space during mmap's.
5515 diff -NurpP --minimal linux-2.6.10/include/asm-ia64/tlb.h linux-2.6.10-vs1.9.3.17/include/asm-ia64/tlb.h
5516 --- linux-2.6.10/include/asm-ia64/tlb.h 2004-10-23 05:06:20.000000000 +0200
5517 +++ linux-2.6.10-vs1.9.3.17/include/asm-ia64/tlb.h      2004-12-26 19:40:35.000000000 +0100
5518 @@ -41,6 +41,7 @@
5519  #include <linux/mm.h>
5520  #include <linux/pagemap.h>
5521  #include <linux/swap.h>
5522 +#include <linux/vs_memory.h>
5523  
5524  #include <asm/pgalloc.h>
5525  #include <asm/processor.h>
5526 @@ -165,7 +166,8 @@ tlb_finish_mmu (struct mmu_gather *tlb, 
5527  
5528         if (rss < freed)
5529                 freed = rss;
5530 -       mm->rss = rss - freed;
5531 +       // mm->rss = rss - freed;
5532 +       vx_rsspages_sub(mm, freed);
5533         /*
5534          * Note: tlb->nr may be 0 at this point, so we can't rely on tlb->start_addr and
5535          * tlb->end_addr.
5536 diff -NurpP --minimal linux-2.6.10/include/asm-parisc/unistd.h linux-2.6.10-vs1.9.3.17/include/asm-parisc/unistd.h
5537 --- linux-2.6.10/include/asm-parisc/unistd.h    2004-12-25 01:55:25.000000000 +0100
5538 +++ linux-2.6.10-vs1.9.3.17/include/asm-parisc/unistd.h 2004-12-26 19:40:24.000000000 +0100
5539 @@ -756,7 +756,9 @@
5540  #define __NR_get_mempolicy     (__NR_Linux + 261)
5541  #define __NR_set_mempolicy     (__NR_Linux + 262)
5542  
5543 -#define __NR_Linux_syscalls     263
5544 +#define __NR_vserver           (__NR_Linux + 273)
5545 +
5546 +#define __NR_Linux_syscalls    273
5547  
5548  #define HPUX_GATEWAY_ADDR       0xC0000004
5549  #define LINUX_GATEWAY_ADDR      0x100
5550 diff -NurpP --minimal linux-2.6.10/include/asm-ppc/unistd.h linux-2.6.10-vs1.9.3.17/include/asm-ppc/unistd.h
5551 --- linux-2.6.10/include/asm-ppc/unistd.h       2004-12-25 01:55:25.000000000 +0100
5552 +++ linux-2.6.10-vs1.9.3.17/include/asm-ppc/unistd.h    2004-12-26 19:40:24.000000000 +0100
5553 @@ -261,7 +261,7 @@
5554  #define __NR_fadvise64_64      254
5555  #define __NR_rtas              255
5556  /* Number 256 is reserved for sys_debug_setcontext */
5557 -/* Number 257 is reserved for vserver */
5558 +#define __NR_vserver           257
5559  /* Number 258 is reserved for new sys_remap_file_pages */
5560  /* Number 259 is reserved for new sys_mbind */
5561  /* Number 260 is reserved for new sys_get_mempolicy */
5562 diff -NurpP --minimal linux-2.6.10/include/asm-ppc64/unistd.h linux-2.6.10-vs1.9.3.17/include/asm-ppc64/unistd.h
5563 --- linux-2.6.10/include/asm-ppc64/unistd.h     2004-12-25 01:55:25.000000000 +0100
5564 +++ linux-2.6.10-vs1.9.3.17/include/asm-ppc64/unistd.h  2004-12-26 19:40:24.000000000 +0100
5565 @@ -267,7 +267,7 @@
5566  /* #define __NR_fadvise64_64   254     32bit only */
5567  #define __NR_rtas              255
5568  /* Number 256 is reserved for sys_debug_setcontext */
5569 -/* Number 257 is reserved for vserver */
5570 +#define __NR_vserver           257
5571  /* Number 258 is reserved for new sys_remap_file_pages */
5572  #define __NR_mbind             259
5573  #define __NR_get_mempolicy     260
5574 diff -NurpP --minimal linux-2.6.10/include/asm-s390/unistd.h linux-2.6.10-vs1.9.3.17/include/asm-s390/unistd.h
5575 --- linux-2.6.10/include/asm-s390/unistd.h      2004-12-25 01:55:25.000000000 +0100
5576 +++ linux-2.6.10-vs1.9.3.17/include/asm-s390/unistd.h   2004-12-26 19:40:24.000000000 +0100
5577 @@ -255,7 +255,7 @@
5578  #define __NR_clock_gettime     (__NR_timer_create+6)
5579  #define __NR_clock_getres      (__NR_timer_create+7)
5580  #define __NR_clock_nanosleep   (__NR_timer_create+8)
5581 -/* Number 263 is reserved for vserver */
5582 +#define __NR_vserver           263
5583  #define __NR_fadvise64_64      264
5584  #define __NR_statfs64          265
5585  #define __NR_fstatfs64         266
5586 diff -NurpP --minimal linux-2.6.10/include/asm-sparc/unistd.h linux-2.6.10-vs1.9.3.17/include/asm-sparc/unistd.h
5587 --- linux-2.6.10/include/asm-sparc/unistd.h     2004-12-25 01:55:26.000000000 +0100
5588 +++ linux-2.6.10-vs1.9.3.17/include/asm-sparc/unistd.h  2004-12-26 19:40:24.000000000 +0100
5589 @@ -283,7 +283,7 @@
5590  #define __NR_timer_getoverrun  264
5591  #define __NR_timer_delete      265
5592  #define __NR_timer_create      266
5593 -/* #define __NR_vserver                267 Reserved for VSERVER */
5594 +#define __NR_vserver           267
5595  #define __NR_io_setup          268
5596  #define __NR_io_destroy                269
5597  #define __NR_io_submit         270
5598 diff -NurpP --minimal linux-2.6.10/include/asm-sparc64/tlb.h linux-2.6.10-vs1.9.3.17/include/asm-sparc64/tlb.h
5599 --- linux-2.6.10/include/asm-sparc64/tlb.h      2004-08-14 12:55:48.000000000 +0200
5600 +++ linux-2.6.10-vs1.9.3.17/include/asm-sparc64/tlb.h   2004-12-26 19:40:35.000000000 +0100
5601 @@ -3,6 +3,8 @@
5602  
5603  #include <linux/config.h>
5604  #include <linux/swap.h>
5605 +#include <linux/vs_memory.h>
5606 +
5607  #include <asm/pgalloc.h>
5608  #include <asm/tlbflush.h>
5609  #include <asm/mmu_context.h>
5610 @@ -84,7 +86,8 @@ static inline void tlb_finish_mmu(struct
5611  
5612         if (rss < freed)
5613                 freed = rss;
5614 -       mm->rss = rss - freed;
5615 +       // mm->rss = rss - freed;
5616 +       vx_rsspages_sub(mm, freed);
5617  
5618         tlb_flush_mmu(mp);
5619  
5620 diff -NurpP --minimal linux-2.6.10/include/asm-sparc64/unistd.h linux-2.6.10-vs1.9.3.17/include/asm-sparc64/unistd.h
5621 --- linux-2.6.10/include/asm-sparc64/unistd.h   2004-12-25 01:55:26.000000000 +0100
5622 +++ linux-2.6.10-vs1.9.3.17/include/asm-sparc64/unistd.h        2004-12-26 19:40:24.000000000 +0100
5623 @@ -285,7 +285,7 @@
5624  #define __NR_timer_getoverrun  264
5625  #define __NR_timer_delete      265
5626  #define __NR_timer_create      266
5627 -/* #define __NR_vserver                267 Reserved for VSERVER */
5628 +#define __NR_vserver           267
5629  #define __NR_io_setup          268
5630  #define __NR_io_destroy                269
5631  #define __NR_io_submit         270
5632 diff -NurpP --minimal linux-2.6.10/include/asm-x86_64/unistd.h linux-2.6.10-vs1.9.3.17/include/asm-x86_64/unistd.h
5633 --- linux-2.6.10/include/asm-x86_64/unistd.h    2004-10-23 05:06:22.000000000 +0200
5634 +++ linux-2.6.10-vs1.9.3.17/include/asm-x86_64/unistd.h 2004-12-26 19:40:24.000000000 +0100
5635 @@ -531,9 +531,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
5636  #define __NR_utimes            235
5637  __SYSCALL(__NR_utimes, sys_utimes)
5638  #define __NR_vserver           236
5639 -__SYSCALL(__NR_vserver, sys_ni_syscall)
5640 -#define __NR_vserver           236
5641 -__SYSCALL(__NR_vserver, sys_ni_syscall)
5642 +__SYSCALL(__NR_vserver, sys_vserver)
5643  #define __NR_mbind             237
5644  __SYSCALL(__NR_mbind, sys_mbind)
5645  #define __NR_set_mempolicy     238
5646 diff -NurpP --minimal linux-2.6.10/include/linux/capability.h linux-2.6.10-vs1.9.3.17/include/linux/capability.h
5647 --- linux-2.6.10/include/linux/capability.h     2004-08-14 12:55:09.000000000 +0200
5648 +++ linux-2.6.10-vs1.9.3.17/include/linux/capability.h  2004-12-26 19:40:23.000000000 +0100
5649 @@ -235,6 +235,7 @@ typedef __u32 kernel_cap_t;
5650  /* Allow enabling/disabling tagged queuing on SCSI controllers and sending
5651     arbitrary SCSI commands */
5652  /* Allow setting encryption key on loopback filesystem */
5653 +/* Allow the selection of a security context */
5654  
5655  #define CAP_SYS_ADMIN        21
5656  
5657 @@ -284,6 +285,11 @@ typedef __u32 kernel_cap_t;
5658  
5659  #define CAP_LEASE            28
5660  
5661 +/* Allow context manipulations */
5662 +/* Allow changing context info on files */
5663 +
5664 +#define CAP_CONTEXT         29
5665 +
5666  #ifdef __KERNEL__
5667  /* 
5668   * Bounding set
5669 diff -NurpP --minimal linux-2.6.10/include/linux/cyclades.h linux-2.6.10-vs1.9.3.17/include/linux/cyclades.h
5670 --- linux-2.6.10/include/linux/cyclades.h       2004-10-23 05:06:22.000000000 +0200
5671 +++ linux-2.6.10-vs1.9.3.17/include/linux/cyclades.h    2004-12-26 19:40:36.000000000 +0100
5672 @@ -624,7 +624,11 @@ struct cyclades_port {
5673  #define        Cy_EVENT_DELTA_WAKEUP           6
5674  #define        Cy_EVENT_Z_RX_FULL              7
5675  
5676 +#if HZ < 2185
5677  #define        CLOSING_WAIT_DELAY      30*HZ
5678 +#else
5679 +#define        CLOSING_WAIT_DELAY      65534
5680 +#endif
5681  #define CY_CLOSING_WAIT_NONE   65535
5682  #define CY_CLOSING_WAIT_INF    0
5683  
5684 diff -NurpP --minimal linux-2.6.10/include/linux/devpts_fs.h linux-2.6.10-vs1.9.3.17/include/linux/devpts_fs.h
5685 --- linux-2.6.10/include/linux/devpts_fs.h      2004-08-14 12:55:59.000000000 +0200
5686 +++ linux-2.6.10-vs1.9.3.17/include/linux/devpts_fs.h   2004-12-26 19:40:30.000000000 +0100
5687 @@ -30,5 +30,7 @@ static inline void devpts_pty_kill(int n
5688  
5689  #endif
5690  
5691 +#define DEVPTS_SUPER_MAGIC     0x1cd1
5692 +
5693  
5694  #endif /* _LINUX_DEVPTS_FS_H */
5695 diff -NurpP --minimal linux-2.6.10/include/linux/dtlk.h linux-2.6.10-vs1.9.3.17/include/linux/dtlk.h
5696 --- linux-2.6.10/include/linux/dtlk.h   2004-08-14 12:56:01.000000000 +0200
5697 +++ linux-2.6.10-vs1.9.3.17/include/linux/dtlk.h        2004-12-26 19:40:36.000000000 +0100
5698 @@ -27,7 +27,7 @@
5699  
5700  #define DTLK_CLEAR 0x18                /* stops speech */
5701  
5702 -#define DTLK_MAX_RETRIES (loops_per_jiffy/(10000/HZ))
5703 +#define DTLK_MAX_RETRIES (HZ*(loops_per_jiffy >> 3)/1250)
5704  
5705         /* TTS Port Status Flags */
5706  #define TTS_READABLE     0x80  /* mask for bit which is nonzero if a
5707 diff -NurpP --minimal linux-2.6.10/include/linux/ext2_fs.h linux-2.6.10-vs1.9.3.17/include/linux/ext2_fs.h
5708 --- linux-2.6.10/include/linux/ext2_fs.h        2004-10-23 05:06:22.000000000 +0200
5709 +++ linux-2.6.10-vs1.9.3.17/include/linux/ext2_fs.h     2004-12-26 19:40:34.000000000 +0100
5710 @@ -192,10 +192,17 @@ struct ext2_group_desc
5711  #define EXT2_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
5712  #define EXT2_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
5713  #define EXT2_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
5714 +#define EXT2_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
5715 +#define EXT2_IUNLINK_FL                        0x08000000 /* Immutable unlink */
5716  #define EXT2_RESERVED_FL               0x80000000 /* reserved for ext2 lib */
5717  
5718 +#ifdef CONFIG_VSERVER_LEGACY
5719 +#define EXT2_FL_USER_VISIBLE           0x0803DFFF /* User visible flags */
5720 +#define EXT2_FL_USER_MODIFIABLE                0x080380FF /* User modifiable flags */
5721 +#else
5722  #define EXT2_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
5723  #define EXT2_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
5724 +#endif
5725  
5726  /*
5727   * ioctl commands
5728 @@ -240,7 +247,7 @@ struct ext2_inode {
5729                 struct {
5730                         __u8    l_i_frag;       /* Fragment number */
5731                         __u8    l_i_fsize;      /* Fragment size */
5732 -                       __u16   i_pad1;
5733 +                       __u16   l_i_xid;        /* LRU Context */
5734                         __le16  l_i_uid_high;   /* these 2 fields    */
5735                         __le16  l_i_gid_high;   /* were reserved2[0] */
5736                         __u32   l_i_reserved2;
5737 @@ -272,6 +279,7 @@ struct ext2_inode {
5738  #define i_gid_low      i_gid
5739  #define i_uid_high     osd2.linux2.l_i_uid_high
5740  #define i_gid_high     osd2.linux2.l_i_gid_high
5741 +#define i_raw_xid      osd2.linux2.l_i_xid
5742  #define i_reserved2    osd2.linux2.l_i_reserved2
5743  #endif
5744  
5745 @@ -312,6 +320,7 @@ struct ext2_inode {
5746  #define EXT2_MOUNT_NO_UID32            0x0200  /* Disable 32-bit UIDs */
5747  #define EXT2_MOUNT_XATTR_USER          0x4000  /* Extended user attributes */
5748  #define EXT2_MOUNT_POSIX_ACL           0x8000  /* POSIX Access Control Lists */
5749 +#define EXT2_MOUNT_TAG_XID             (1<<24) /* Enable Context Tags */
5750  
5751  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
5752  #define set_opt(o, opt)                        o |= EXT2_MOUNT_##opt
5753 diff -NurpP --minimal linux-2.6.10/include/linux/ext3_fs.h linux-2.6.10-vs1.9.3.17/include/linux/ext3_fs.h
5754 --- linux-2.6.10/include/linux/ext3_fs.h        2004-12-25 01:55:29.000000000 +0100
5755 +++ linux-2.6.10-vs1.9.3.17/include/linux/ext3_fs.h     2004-12-26 19:40:34.000000000 +0100
5756 @@ -185,10 +185,20 @@ struct ext3_group_desc
5757  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
5758  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
5759  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
5760 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
5761 +#define EXT3_IUNLINK_FL                        0x08000000 /* Immutable unlink */
5762  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
5763  
5764 +#ifdef CONFIG_VSERVER_LEGACY
5765 +#define EXT3_FL_USER_VISIBLE           0x0803DFFF /* User visible flags */
5766 +#define EXT3_FL_USER_MODIFIABLE                0x080380FF /* User modifiable flags */
5767 +#else
5768  #define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
5769  #define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
5770 +#endif
5771 +#ifdef CONFIG_VSERVER_LEGACY
5772 +#define EXT3_IOC_SETXID                        FIOC_SETXIDJ
5773 +#endif
5774  
5775  /*
5776   * Inode dynamic state flags
5777 @@ -273,7 +283,7 @@ struct ext3_inode {
5778                 struct {
5779                         __u8    l_i_frag;       /* Fragment number */
5780                         __u8    l_i_fsize;      /* Fragment size */
5781 -                       __u16   i_pad1;
5782 +                       __u16   l_i_xid;        /* LRU Context */
5783                         __le16  l_i_uid_high;   /* these 2 fields    */
5784                         __le16  l_i_gid_high;   /* were reserved2[0] */
5785                         __u32   l_i_reserved2;
5786 @@ -305,6 +315,7 @@ struct ext3_inode {
5787  #define i_gid_low      i_gid
5788  #define i_uid_high     osd2.linux2.l_i_uid_high
5789  #define i_gid_high     osd2.linux2.l_i_gid_high
5790 +#define i_raw_xid      osd2.linux2.l_i_xid
5791  #define i_reserved2    osd2.linux2.l_i_reserved2
5792  
5793  #elif defined(__GNU__)
5794 @@ -355,6 +366,7 @@ struct ext3_inode {
5795  #define EXT3_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
5796  #define EXT3_MOUNT_RESERVATION         0x10000 /* Preallocation */
5797  #define EXT3_MOUNT_BARRIER             0x20000 /* Use block barriers */
5798 +#define EXT3_MOUNT_TAG_XID             (1<<24) /* Enable Context Tags */
5799  
5800  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
5801  #ifndef _LINUX_EXT2_FS_H
5802 diff -NurpP --minimal linux-2.6.10/include/linux/fs.h linux-2.6.10-vs1.9.3.17/include/linux/fs.h
5803 --- linux-2.6.10/include/linux/fs.h     2004-12-25 01:55:29.000000000 +0100
5804 +++ linux-2.6.10-vs1.9.3.17/include/linux/fs.h  2004-12-26 19:40:34.000000000 +0100
5805 @@ -124,6 +124,8 @@ extern int dir_notify_enable;
5806  #define MS_VERBOSE     32768
5807  #define MS_POSIXACL    (1<<16) /* VFS does not apply the umask */
5808  #define MS_ONE_SECOND  (1<<17) /* fs has 1 sec a/m/ctime resolution */
5809 +#define MS_TAGXID      (1<<24) /* tag inodes with context information */
5810 +#define MS_XID         (1<<25) /* use specific xid for this mount */
5811  #define MS_ACTIVE      (1<<30)
5812  #define MS_NOUSER      (1<<31)
5813  
5814 @@ -150,6 +152,8 @@ extern int dir_notify_enable;
5815  #define S_DIRSYNC      64      /* Directory modifications are synchronous */
5816  #define S_NOCMTIME     128     /* Do not update file c/mtime */
5817  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
5818 +#define S_BARRIER      1024    /* Barrier for chroot() */
5819 +#define S_IUNLINK      2048    /* Immutable unlink */
5820  
5821  /*
5822   * Note that nosuid etc flags are inode-specific: setting some file-system
5823 @@ -176,11 +180,14 @@ extern int dir_notify_enable;
5824  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
5825  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
5826  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
5827 +#define IS_IUNLINK(inode)      ((inode)->i_flags & S_IUNLINK)
5828 +#define IS_IXORUNLINK(inode)   ((IS_IUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
5829  #define IS_NOATIME(inode)      (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
5830  #define IS_NODIRATIME(inode)   __IS_FLG(inode, MS_NODIRATIME)
5831  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
5832  #define IS_ONE_SECOND(inode)   __IS_FLG(inode, MS_ONE_SECOND)
5833  
5834 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_flags & S_BARRIER))
5835  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
5836  #define IS_NOCMTIME(inode)     ((inode)->i_flags & S_NOCMTIME)
5837  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
5838 @@ -262,6 +269,7 @@ typedef void (dio_iodone_t)(struct inode
5839  #define ATTR_ATTR_FLAG 1024
5840  #define ATTR_KILL_SUID 2048
5841  #define ATTR_KILL_SGID 4096
5842 +#define ATTR_XID       8192
5843  
5844  /*
5845   * This is the Inode Attributes structure, used for notify_change().  It
5846 @@ -277,6 +285,7 @@ struct iattr {
5847         umode_t         ia_mode;
5848         uid_t           ia_uid;
5849         gid_t           ia_gid;
5850 +       xid_t           ia_xid;
5851         loff_t          ia_size;
5852         struct timespec ia_atime;
5853         struct timespec ia_mtime;
5854 @@ -293,6 +302,9 @@ struct iattr {
5855  #define ATTR_FLAG_IMMUTABLE    8       /* Immutable file */
5856  #define ATTR_FLAG_NODIRATIME   16      /* Don't update atime for directory */
5857  
5858 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
5859 +#define ATTR_FLAG_IUNLINK      1024    /* Immutable unlink */
5860 +
5861  /*
5862   * Includes for diskquotas.
5863   */
5864 @@ -436,6 +448,7 @@ struct inode {
5865         unsigned int            i_nlink;
5866         uid_t                   i_uid;
5867         gid_t                   i_gid;
5868 +       xid_t                   i_xid;
5869         dev_t                   i_rdev;
5870         loff_t                  i_size;
5871         struct timespec         i_atime;
5872 @@ -588,6 +601,8 @@ struct file {
5873         unsigned int            f_uid, f_gid;
5874         struct file_ra_state    f_ra;
5875  
5876 +       xid_t                   f_xid;
5877 +
5878         unsigned long           f_version;
5879         void                    *f_security;
5880  
5881 --- linux-2.6.10/include/linux/init_task.h.orig 2005-01-06 11:59:13.000000000 +0100
5882 +++ linux-2.6.10/include/linux/init_task.h      2005-01-06 12:06:32.000000000 +0100
5883 @@ -114,6 +114,10 @@
5884         .journal_info   = NULL,                                         \
5885         .private_pages  = LIST_HEAD_INIT(tsk.private_pages),            \
5886         .private_pages_count = 0,                                       \
5887 +       .xid            = 0,                                            \
5888 +       .vx_info        = NULL,                                         \
5889 +       .nid            = 0,                                            \
5890 +       .nx_info        = NULL,                                         \
5891  }
5892  
5893  #endif
5894 diff -NurpP --minimal linux-2.6.10/include/linux/ip.h linux-2.6.10-vs1.9.3.17/include/linux/ip.h
5895 --- linux-2.6.10/include/linux/ip.h     2004-08-14 12:55:09.000000000 +0200
5896 +++ linux-2.6.10-vs1.9.3.17/include/linux/ip.h  2004-12-26 19:40:29.000000000 +0100
5897 @@ -111,6 +111,7 @@ struct inet_opt {
5898         /* Socket demultiplex comparisons on incoming packets. */
5899         __u32                   daddr;          /* Foreign IPv4 addr */
5900         __u32                   rcv_saddr;      /* Bound local IPv4 addr */
5901 +       __u32                   rcv_saddr2;     /* Second bound ipv4 addr, for ipv4root */
5902         __u16                   dport;          /* Destination port */
5903         __u16                   num;            /* Local port */
5904         __u32                   saddr;          /* Sending source */
5905 diff -NurpP --minimal linux-2.6.10/include/linux/ipc.h linux-2.6.10-vs1.9.3.17/include/linux/ipc.h
5906 --- linux-2.6.10/include/linux/ipc.h    2004-08-14 12:54:46.000000000 +0200
5907 +++ linux-2.6.10-vs1.9.3.17/include/linux/ipc.h 2004-12-26 19:40:29.000000000 +0100
5908 @@ -66,6 +66,7 @@ struct kern_ipc_perm
5909         mode_t          mode; 
5910         unsigned long   seq;
5911         void            *security;
5912 +       xid_t           xid;
5913  };
5914  
5915  #endif /* __KERNEL__ */
5916 diff -NurpP --minimal linux-2.6.10/include/linux/jiffies.h linux-2.6.10-vs1.9.3.17/include/linux/jiffies.h
5917 --- linux-2.6.10/include/linux/jiffies.h        2004-12-25 01:55:29.000000000 +0100
5918 +++ linux-2.6.10-vs1.9.3.17/include/linux/jiffies.h     2004-12-26 19:40:36.000000000 +0100
5919 @@ -38,6 +38,14 @@
5920  # define SHIFT_HZ      9
5921  #elif HZ >= 768 && HZ < 1536
5922  # define SHIFT_HZ      10
5923 +#elif HZ >= 1536 && HZ < 3072
5924 +# define SHIFT_HZ      11
5925 +#elif HZ >= 3072 && HZ < 6144
5926 +# define SHIFT_HZ      12
5927 +#elif HZ >= 6144 && HZ < 12288
5928 +# define SHIFT_HZ      13
5929 +#elif HZ >= 12288 && HZ < 24576
5930 +# define SHIFT_HZ      14
5931  #else
5932  # error You lose.
5933  #endif
5934 diff -NurpP --minimal linux-2.6.10/include/linux/mount.h linux-2.6.10-vs1.9.3.17/include/linux/mount.h
5935 --- linux-2.6.10/include/linux/mount.h  2004-12-25 01:55:29.000000000 +0100
5936 +++ linux-2.6.10-vs1.9.3.17/include/linux/mount.h       2004-12-26 19:40:34.000000000 +0100
5937 @@ -19,6 +19,7 @@
5938  #define MNT_NOSUID     1
5939  #define MNT_NODEV      2
5940  #define MNT_NOEXEC     4
5941 +#define MNT_XID                256
5942  
5943  struct vfsmount
5944  {
5945 @@ -36,6 +37,7 @@ struct vfsmount
5946         struct list_head mnt_list;
5947         struct list_head mnt_fslink;    /* link in fs-specific expiry list */
5948         struct namespace *mnt_namespace; /* containing namespace */
5949 +       xid_t mnt_xid;                  /* xid tagging used for vfsmount */
5950  };
5951  
5952  static inline struct vfsmount *mntget(struct vfsmount *mnt)
5953 diff -NurpP --minimal linux-2.6.10/include/linux/namespace.h linux-2.6.10-vs1.9.3.17/include/linux/namespace.h
5954 --- linux-2.6.10/include/linux/namespace.h      2004-08-14 12:55:33.000000000 +0200
5955 +++ linux-2.6.10-vs1.9.3.17/include/linux/namespace.h   2004-12-26 19:40:29.000000000 +0100
5956 @@ -13,6 +13,7 @@ struct namespace {
5957  };
5958  
5959  extern void umount_tree(struct vfsmount *);
5960 +extern void umount_unused(struct vfsmount *, struct fs_struct *);
5961  extern int copy_namespace(int, struct task_struct *);
5962  extern void __put_namespace(struct namespace *namespace);
5963  
5964 diff -NurpP --minimal linux-2.6.10/include/linux/net.h linux-2.6.10-vs1.9.3.17/include/linux/net.h
5965 --- linux-2.6.10/include/linux/net.h    2004-12-25 01:55:29.000000000 +0100
5966 +++ linux-2.6.10-vs1.9.3.17/include/linux/net.h 2004-12-26 19:40:29.000000000 +0100
5967 @@ -61,6 +61,8 @@ typedef enum {
5968  #define SOCK_ASYNC_NOSPACE     0
5969  #define SOCK_ASYNC_WAITDATA    1
5970  #define SOCK_NOSPACE           2
5971 +#define SOCK_PASS_CRED         16
5972 +#define SOCK_USER_SOCKET       17
5973  
5974  #ifndef ARCH_HAS_SOCKET_TYPES
5975  /** sock_type - Socket types
5976 @@ -111,7 +113,6 @@ struct socket {
5977         struct sock             *sk;
5978         wait_queue_head_t       wait;
5979         short                   type;
5980 -       unsigned char           passcred;
5981  };
5982  
5983  struct vm_area_struct;
5984 diff -NurpP --minimal linux-2.6.10/include/linux/nfs_mount.h linux-2.6.10-vs1.9.3.17/include/linux/nfs_mount.h
5985 --- linux-2.6.10/include/linux/nfs_mount.h      2004-08-14 12:54:47.000000000 +0200
5986 +++ linux-2.6.10-vs1.9.3.17/include/linux/nfs_mount.h   2004-12-26 19:40:34.000000000 +0100
5987 @@ -60,6 +60,7 @@ struct nfs_mount_data {
5988  #define NFS_MOUNT_BROKEN_SUID  0x0400  /* 4 */
5989  #define NFS_MOUNT_STRICTLOCK   0x1000  /* reserved for NFSv4 */
5990  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
5991 +#define NFS_MOUNT_TAGXID       0x8000  /* tagxid */
5992  #define NFS_MOUNT_FLAGMASK     0xFFFF
5993  
5994  #endif
5995 diff -NurpP --minimal linux-2.6.10/include/linux/proc_fs.h linux-2.6.10-vs1.9.3.17/include/linux/proc_fs.h
5996 --- linux-2.6.10/include/linux/proc_fs.h        2004-12-25 01:55:29.000000000 +0100
5997 +++ linux-2.6.10-vs1.9.3.17/include/linux/proc_fs.h     2004-12-26 19:40:24.000000000 +0100
5998 @@ -55,6 +55,7 @@ struct proc_dir_entry {
5999         nlink_t nlink;
6000         uid_t uid;
6001         gid_t gid;
6002 +       int vx_flags;
6003         unsigned long size;
6004         struct inode_operations * proc_iops;
6005         struct file_operations * proc_fops;
6006 @@ -243,9 +244,11 @@ extern struct kcore_list *kclist_del(voi
6007  struct proc_inode {
6008         struct task_struct *task;
6009         int type;
6010 +       int vx_flags;
6011         union {
6012                 int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
6013                 int (*proc_read)(struct task_struct *task, char *page);
6014 +               int (*proc_vid_read)(int vid, char *page);
6015         } op;
6016         struct proc_dir_entry *pde;
6017         struct inode vfs_inode;
6018 diff -NurpP --minimal linux-2.6.10/include/linux/ptrace.h linux-2.6.10-vs1.9.3.17/include/linux/ptrace.h
6019 --- linux-2.6.10/include/linux/ptrace.h 2004-12-25 01:55:29.000000000 +0100
6020 +++ linux-2.6.10-vs1.9.3.17/include/linux/ptrace.h      2004-12-26 19:40:14.000000000 +0100
6021 @@ -75,6 +75,8 @@
6022  
6023  #include <linux/compiler.h>            /* For unlikely.  */
6024  #include <linux/sched.h>               /* For struct task_struct.  */
6025 +#include <linux/vs_cvirt.h>
6026 +#include <linux/vs_context.h>
6027  
6028  extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len);
6029  extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len);
6030 diff -NurpP --minimal linux-2.6.10/include/linux/reiserfs_fs.h linux-2.6.10-vs1.9.3.17/include/linux/reiserfs_fs.h
6031 --- linux-2.6.10/include/linux/reiserfs_fs.h    2004-12-25 01:55:29.000000000 +0100
6032 +++ linux-2.6.10-vs1.9.3.17/include/linux/reiserfs_fs.h 2004-12-26 19:40:31.000000000 +0100
6033 @@ -889,6 +889,18 @@ struct stat_data_v1
6034  #define REISERFS_COMPR_FL     EXT2_COMPR_FL
6035  #define REISERFS_NOTAIL_FL    EXT2_NOTAIL_FL
6036  
6037 +/* unfortunately reiserfs sdattr is only 16 bit */
6038 +#define REISERFS_BARRIER_FL   (EXT2_BARRIER_FL >> 16)
6039 +#define REISERFS_IUNLINK_FL   (EXT2_IUNLINK_FL >> 16)
6040 +
6041 +#ifdef CONFIG_VSERVER_LEGACY
6042 +#define REISERFS_FL_USER_VISIBLE       (REISERFS_IUNLINK_FL|0x80FF)
6043 +#define REISERFS_FL_USER_MODIFYABLE    (REISERFS_IUNLINK_FL|0x80FF)
6044 +#else
6045 +#define REISERFS_FL_USER_VISIBLE       0x80FF
6046 +#define REISERFS_FL_USER_MODIFYABLE    0x80FF
6047 +#endif
6048 +
6049  /* persistent flags that file inherits from the parent directory */
6050  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
6051                                 REISERFS_SYNC_FL |      \
6052 diff -NurpP --minimal linux-2.6.10/include/linux/reiserfs_fs_sb.h linux-2.6.10-vs1.9.3.17/include/linux/reiserfs_fs_sb.h
6053 --- linux-2.6.10/include/linux/reiserfs_fs_sb.h 2004-12-25 01:55:29.000000000 +0100
6054 +++ linux-2.6.10-vs1.9.3.17/include/linux/reiserfs_fs_sb.h      2004-12-26 19:40:34.000000000 +0100
6055 @@ -457,6 +457,7 @@ enum reiserfs_mount_options {
6056      REISERFS_POSIXACL,
6057      REISERFS_BARRIER_NONE,
6058      REISERFS_BARRIER_FLUSH,
6059 +    REISERFS_TAGXID,
6060  
6061      /* Actions on error */
6062      REISERFS_ERROR_PANIC,
6063 diff -NurpP --minimal linux-2.6.10/include/linux/sched.h linux-2.6.10-vs1.9.3.17/include/linux/sched.h
6064 --- linux-2.6.10/include/linux/sched.h  2004-12-25 01:55:29.000000000 +0100
6065 +++ linux-2.6.10-vs1.9.3.17/include/linux/sched.h       2004-12-26 19:40:35.000000000 +0100
6066 @@ -30,6 +30,7 @@
6067  #include <linux/pid.h>
6068  #include <linux/percpu.h>
6069  #include <linux/topology.h>
6070 +#include <linux/vs_base.h>
6071  
6072  struct exec_domain;
6073  
6074 @@ -110,6 +111,7 @@ extern unsigned long nr_iowait(void);
6075  #define TASK_TRACED            8
6076  #define EXIT_ZOMBIE            16
6077  #define EXIT_DEAD              32
6078 +#define TASK_ONHOLD            64
6079  
6080  #define __set_task_state(tsk, state_value)             \
6081         do { (tsk)->state = (state_value); } while (0)
6082 @@ -236,6 +238,7 @@ struct mm_struct {
6083  
6084         /* Architecture-specific MM context */
6085         mm_context_t context;
6086 +       struct vx_info *mm_vx_info;
6087  
6088         /* Token based thrashing protection. */
6089         unsigned long swap_token_time;
6090 @@ -365,9 +368,10 @@ struct user_struct {
6091         /* Hash table maintenance information */
6092         struct list_head uidhash_list;
6093         uid_t uid;
6094 +       xid_t xid;
6095  };
6096  
6097 -extern struct user_struct *find_user(uid_t);
6098 +extern struct user_struct *find_user(xid_t, uid_t);
6099  
6100  extern struct user_struct root_user;
6101  #define INIT_USER (&root_user)
6102 @@ -630,6 +634,14 @@ struct task_struct {
6103         void *security;
6104         struct audit_context *audit_context;
6105  
6106 +/* vserver context data */
6107 +       xid_t xid;
6108 +       struct vx_info *vx_info;
6109 +
6110 +/* vserver network data */
6111 +       nid_t nid;
6112 +       struct nx_info *nx_info;
6113 +
6114  /* Thread group tracking */
6115         u32 parent_exec_id;
6116         u32 self_exec_id;
6117 @@ -768,13 +780,19 @@ extern struct task_struct init_task;
6118  
6119  extern struct   mm_struct init_mm;
6120  
6121 -#define find_task_by_pid(nr)   find_task_by_pid_type(PIDTYPE_PID, nr)
6122 +
6123 +#define find_task_by_real_pid(nr) \
6124 +       find_task_by_pid_type(PIDTYPE_PID, nr)
6125 +#define find_task_by_pid(nr) \
6126 +       find_task_by_pid_type(PIDTYPE_PID, \
6127 +               vx_rmap_pid(nr))
6128 +
6129  extern struct task_struct *find_task_by_pid_type(int type, int pid);
6130  extern void set_special_pids(pid_t session, pid_t pgrp);
6131  extern void __set_special_pids(pid_t session, pid_t pgrp);
6132  
6133  /* per-UID process charging. */
6134 -extern struct user_struct * alloc_uid(uid_t);
6135 +extern struct user_struct * alloc_uid(xid_t, uid_t);
6136  static inline struct user_struct *get_uid(struct user_struct *u)
6137  {
6138         atomic_inc(&u->__count);
6139 @@ -867,15 +885,28 @@ static inline int sas_ss_flags(unsigned 
6140  #ifdef CONFIG_SECURITY
6141  /* code is in security.c */
6142  extern int capable(int cap);
6143 +extern int vx_capable(int cap, int ccap);
6144  #else
6145  static inline int capable(int cap)
6146  {
6147 +       if (vx_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
6148 +               return 0;
6149         if (cap_raised(current->cap_effective, cap)) {
6150                 current->flags |= PF_SUPERPRIV;
6151                 return 1;
6152         }
6153         return 0;
6154  }
6155 +
6156 +static inline int vx_capable(int cap, int ccap)
6157 +{
6158 +       if (cap_raised(current->cap_effective, cap) &&
6159 +               vx_ccaps(ccap)) {
6160 +               current->flags |= PF_SUPERPRIV;
6161 +               return 1;
6162 +       }
6163 +       return 0;
6164 +}
6165  #endif
6166  
6167  /*
6168 diff -NurpP --minimal linux-2.6.10/include/linux/shmem_fs.h linux-2.6.10-vs1.9.3.17/include/linux/shmem_fs.h
6169 --- linux-2.6.10/include/linux/shmem_fs.h       2004-10-23 05:06:23.000000000 +0200
6170 +++ linux-2.6.10-vs1.9.3.17/include/linux/shmem_fs.h    2004-12-26 19:40:30.000000000 +0100
6171 @@ -8,6 +8,9 @@
6172  
6173  #define SHMEM_NR_DIRECT 16
6174  
6175 +#define TMPFS_SUPER_MAGIC      0x01021994
6176 +
6177 +
6178  struct shmem_inode_info {
6179         spinlock_t              lock;
6180         unsigned long           flags;
6181 diff -NurpP --minimal linux-2.6.10/include/linux/stat.h linux-2.6.10-vs1.9.3.17/include/linux/stat.h
6182 --- linux-2.6.10/include/linux/stat.h   2004-08-14 12:55:10.000000000 +0200
6183 +++ linux-2.6.10-vs1.9.3.17/include/linux/stat.h        2004-12-26 19:40:34.000000000 +0100
6184 @@ -63,6 +63,7 @@ struct kstat {
6185         unsigned int    nlink;
6186         uid_t           uid;
6187         gid_t           gid;
6188 +       xid_t           xid;
6189         dev_t           rdev;
6190         loff_t          size;
6191         struct timespec  atime;
6192 diff -NurpP --minimal linux-2.6.10/include/linux/sunrpc/auth.h linux-2.6.10-vs1.9.3.17/include/linux/sunrpc/auth.h
6193 --- linux-2.6.10/include/linux/sunrpc/auth.h    2004-08-14 12:55:33.000000000 +0200
6194 +++ linux-2.6.10-vs1.9.3.17/include/linux/sunrpc/auth.h 2004-12-26 19:40:34.000000000 +0100
6195 @@ -28,6 +28,7 @@
6196  struct auth_cred {
6197         uid_t   uid;
6198         gid_t   gid;
6199 +       xid_t   xid;
6200         struct group_info *group_info;
6201  };
6202  
6203 diff -NurpP --minimal linux-2.6.10/include/linux/sunrpc/clnt.h linux-2.6.10-vs1.9.3.17/include/linux/sunrpc/clnt.h
6204 --- linux-2.6.10/include/linux/sunrpc/clnt.h    2004-08-14 12:55:34.000000000 +0200
6205 +++ linux-2.6.10-vs1.9.3.17/include/linux/sunrpc/clnt.h 2004-12-26 19:40:34.000000000 +0100
6206 @@ -53,7 +53,8 @@ struct rpc_clnt {
6207                                 cl_autobind : 1,/* use getport() */
6208                                 cl_droppriv : 1,/* enable NFS suid hack */
6209                                 cl_oneshot  : 1,/* dispose after use */
6210 -                               cl_dead     : 1;/* abandoned */
6211 +                               cl_dead     : 1,/* abandoned */
6212 +                               cl_tagxid   : 1;/* do xid tagging */
6213  
6214         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
6215         struct rpc_portmap *    cl_pmap;        /* port mapping */
6216 --- linux-2.6.10/include/linux/sysctl.h.orig    2005-01-06 11:59:10.000000000 +0100
6217 +++ linux-2.6.10/include/linux/sysctl.h 2005-01-06 12:05:55.000000000 +0100
6218 @@ -135,6 +135,7 @@
6219         KERN_HZ_TIMER=65,       /* int: hz timer on or off */
6220         KERN_UNKNOWN_NMI_PANIC=66, /* int: unknown nmi panic flag */
6221         KERN_FBSPLASH=67,       /* string: path to fbsplash helper */
6222 +       KERN_VSHELPER=68,       /* string: path to vshelper policy agent */
6223  };
6224  
6225  
6226 diff -NurpP --minimal linux-2.6.10/include/linux/sysfs.h linux-2.6.10-vs1.9.3.17/include/linux/sysfs.h
6227 --- linux-2.6.10/include/linux/sysfs.h  2004-12-25 01:55:30.000000000 +0100
6228 +++ linux-2.6.10-vs1.9.3.17/include/linux/sysfs.h       2004-12-26 19:40:30.000000000 +0100
6229 @@ -11,6 +11,8 @@
6230  
6231  #include <asm/atomic.h>
6232  
6233 +#define SYSFS_SUPER_MAGIC      0x62656572
6234 +
6235  struct kobject;
6236  struct module;
6237  
6238 diff -NurpP --minimal linux-2.6.10/include/linux/types.h linux-2.6.10-vs1.9.3.17/include/linux/types.h
6239 --- linux-2.6.10/include/linux/types.h  2004-12-25 01:55:30.000000000 +0100
6240 +++ linux-2.6.10-vs1.9.3.17/include/linux/types.h       2004-12-26 19:40:23.000000000 +0100
6241 @@ -36,6 +36,8 @@ typedef __kernel_uid32_t      uid_t;
6242  typedef __kernel_gid32_t       gid_t;
6243  typedef __kernel_uid16_t        uid16_t;
6244  typedef __kernel_gid16_t        gid16_t;
6245 +typedef unsigned int           xid_t;
6246 +typedef unsigned int           nid_t;
6247  
6248  #ifdef CONFIG_UID16
6249  /* This is defined by include/asm-{arch}/posix_types.h */
6250 diff -NurpP --minimal linux-2.6.10/include/linux/vs_base.h linux-2.6.10-vs1.9.3.17/include/linux/vs_base.h
6251 --- linux-2.6.10/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
6252 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_base.h     2004-12-26 19:40:21.000000000 +0100
6253 @@ -0,0 +1,104 @@
6254 +#ifndef _VX_VS_BASE_H
6255 +#define _VX_VS_BASE_H
6256 +
6257 +
6258 +#include "vserver/context.h"
6259 +
6260 +
6261 +#define vx_task_xid(t) ((t)->xid)
6262 +
6263 +#define vx_current_xid() vx_task_xid(current)
6264 +
6265 +#define vx_check(c,m)  __vx_check(vx_current_xid(),c,m)
6266 +
6267 +#define vx_weak_check(c,m)     ((m) ? vx_check(c,m) : 1)
6268 +
6269 +
6270 +/*
6271 + * check current context for ADMIN/WATCH and
6272 + * optionally agains supplied argument
6273 + */
6274 +static inline int __vx_check(xid_t cid, xid_t id, unsigned int mode)
6275 +{
6276 +       if (mode & VX_ARG_MASK) {
6277 +               if ((mode & VX_IDENT) &&
6278 +                       (id == cid))
6279 +                       return 1;
6280 +       }
6281 +       if (mode & VX_ATR_MASK) {
6282 +               if ((mode & VX_DYNAMIC) &&
6283 +                       (id >= MIN_D_CONTEXT) &&
6284 +                       (id <= MAX_S_CONTEXT))
6285 +                       return 1;
6286 +               if ((mode & VX_STATIC) &&
6287 +                       (id > 1) && (id < MIN_D_CONTEXT))
6288 +                       return 1;
6289 +       }
6290 +       return (((mode & VX_ADMIN) && (cid == 0)) ||
6291 +               ((mode & VX_WATCH) && (cid == 1)) ||
6292 +               ((mode & VX_HOSTID) && (id == 0)));
6293 +}
6294 +
6295 +
6296 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
6297 +
6298 +#define vx_info_state(v,m)     (__vx_state(v) & (m))
6299 +
6300 +
6301 +/* generic flag merging */
6302 +
6303 +#define vx_check_flags(v,m,f)  (((v) & (m)) ^ (f))
6304 +
6305 +#define vx_mask_flags(v,f,m)   (((v) & ~(m)) | ((f) & (m)))
6306 +
6307 +#define vx_mask_mask(v,f,m)    (((v) & ~(m)) | ((v) & (f) & (m)))
6308 +
6309 +#define vx_check_bit(v,n)      ((v) & (1LL << (n)))
6310 +
6311 +
6312 +/* context flags */
6313 +
6314 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
6315 +
6316 +#define vx_current_flags()     __vx_flags(current->vx_info)
6317 +
6318 +#define vx_info_flags(v,m,f) \
6319 +       vx_check_flags(__vx_flags(v),(m),(f))
6320 +
6321 +#define task_vx_flags(t,m,f) \
6322 +       ((t) && vx_info_flags((t)->vx_info, (m), (f)))
6323 +
6324 +#define vx_flags(m,f)  vx_info_flags(current->vx_info,(m),(f))
6325 +
6326 +
6327 +/* context caps */
6328 +
6329 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
6330 +
6331 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
6332 +
6333 +#define vx_info_ccaps(v,c)     (__vx_ccaps(v) & (c))
6334 +
6335 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info,(c))
6336 +
6337 +
6338 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
6339 +
6340 +#define vx_info_mcaps(v,c)     (__vx_mcaps(v) & (c))
6341 +
6342 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info,(c))
6343 +
6344 +
6345 +#define vx_current_bcaps() \
6346 +       (((current->vx_info) && !vx_flags(VXF_STATE_SETUP, 0)) ? \
6347 +       current->vx_info->vx_bcaps : cap_bset)
6348 +
6349 +
6350 +#define vx_current_initpid(n) \
6351 +       (current->vx_info && \
6352 +       (current->vx_info->vx_initpid == (n)))
6353 +
6354 +
6355 +#else
6356 +#warning duplicate inclusion
6357 +#endif
6358 diff -NurpP --minimal linux-2.6.10/include/linux/vs_context.h linux-2.6.10-vs1.9.3.17/include/linux/vs_context.h
6359 --- linux-2.6.10/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
6360 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_context.h  2005-01-03 01:34:47.000000000 +0100
6361 @@ -0,0 +1,120 @@
6362 +#ifndef _VX_VS_CONTEXT_H
6363 +#define _VX_VS_CONTEXT_H
6364 +
6365 +
6366 +#include <linux/kernel.h>
6367 +#include "vserver/debug.h"
6368 +
6369 +
6370 +#define get_vx_info(i) __get_vx_info(i,__FILE__,__LINE__)
6371 +
6372 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
6373 +       const char *_file, int _line)
6374 +{
6375 +       if (!vxi)
6376 +               return NULL;
6377 +
6378 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
6379 +               vxi, vxi?vxi->vx_id:0, vxi?atomic_read(&vxi->vx_usecnt):0,
6380 +               _file, _line);
6381 +       vxh_get_vx_info(vxi);
6382 +
6383 +       atomic_inc(&vxi->vx_usecnt);
6384 +       return vxi;
6385 +}
6386 +
6387 +#define put_vx_info(i) __put_vx_info(i,__FILE__,__LINE__)
6388 +
6389 +static inline void __put_vx_info(struct vx_info *vxi, const char *_file, int _line)
6390 +{
6391 +       if (!vxi)
6392 +               return;
6393 +
6394 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
6395 +               vxi, vxi?vxi->vx_id:0, vxi?atomic_read(&vxi->vx_usecnt):0,
6396 +               _file, _line);
6397 +       vxh_put_vx_info(vxi);
6398 +
6399 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
6400 +               free_vx_info(vxi);
6401 +}
6402 +
6403 +#define set_vx_info(p,i) __set_vx_info(p,i,__FILE__,__LINE__)
6404 +
6405 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
6406 +       const char *_file, int _line)
6407 +{
6408 +       struct vx_info *vxo;
6409 +
6410 +       if (!vxi)
6411 +               return;
6412 +
6413 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d.%d])",
6414 +               vxi, vxi?vxi->vx_id:0,
6415 +               vxi?atomic_read(&vxi->vx_usecnt):0,
6416 +               vxi?atomic_read(&vxi->vx_refcnt):0,
6417 +               _file, _line);
6418 +       vxh_set_vx_info(vxi, vxp);
6419 +
6420 +       atomic_inc(&vxi->vx_refcnt);
6421 +       vxo = xchg(vxp, __get_vx_info(vxi, _file, _line));
6422 +       BUG_ON(vxo);
6423 +}
6424 +
6425 +#define clr_vx_info(p) __clr_vx_info(p,__FILE__,__LINE__)
6426 +
6427 +static inline void __clr_vx_info(struct vx_info **vxp,
6428 +       const char *_file, int _line)
6429 +{
6430 +       struct vx_info *vxo;
6431 +
6432 +       vxo = xchg(vxp, NULL);
6433 +       if (!vxo)
6434 +               return;
6435 +
6436 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d.%d])",
6437 +               vxo, vxo?vxo->vx_id:0,
6438 +               vxo?atomic_read(&vxo->vx_usecnt):0,
6439 +               vxo?atomic_read(&vxo->vx_refcnt):0,
6440 +               _file, _line);
6441 +       vxh_clr_vx_info(vxo, vxp);
6442 +
6443 +       if (atomic_dec_and_test(&vxo->vx_refcnt))
6444 +               unhash_vx_info(vxo);
6445 +       __put_vx_info(vxo, _file, _line);
6446 +}
6447 +
6448 +
6449 +#define task_get_vx_info(p)    __task_get_vx_info(p,__FILE__,__LINE__)
6450 +
6451 +static __inline__ struct vx_info *__task_get_vx_info(struct task_struct *p,
6452 +       const char *_file, int _line)
6453 +{
6454 +       struct vx_info *vxi;
6455 +
6456 +       task_lock(p);
6457 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
6458 +               p, _file, _line);
6459 +       vxi = __get_vx_info(p->vx_info, _file, _line);
6460 +       task_unlock(p);
6461 +       return vxi;
6462 +}
6463 +
6464 +
6465 +#define vx_verify_info(p,i)    \
6466 +       __vx_verify_info((p)->vx_info,i,__FILE__,__LINE__)
6467 +
6468 +static __inline__ void __vx_verify_info(
6469 +       struct vx_info *vxa, struct vx_info *vxb,
6470 +       const char *_file, int _line)
6471 +{
6472 +       if (vxa == vxb)
6473 +               return;
6474 +       printk(KERN_ERR "vx bad assumption (%p==%p) at %s:%d\n",
6475 +               vxa, vxb, _file, _line);
6476 +}
6477 +
6478 +
6479 +#else
6480 +#warning duplicate inclusion
6481 +#endif
6482 diff -NurpP --minimal linux-2.6.10/include/linux/vs_cvirt.h linux-2.6.10-vs1.9.3.17/include/linux/vs_cvirt.h
6483 --- linux-2.6.10/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
6484 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_cvirt.h    2004-12-26 19:40:21.000000000 +0100
6485 @@ -0,0 +1,109 @@
6486 +#ifndef _VX_VS_CVIRT_H
6487 +#define _VX_VS_CVIRT_H
6488 +
6489 +
6490 +#include "vserver/cvirt.h"
6491 +#include "vserver/debug.h"
6492 +
6493 +
6494 +/* utsname virtualization */
6495 +
6496 +static inline struct new_utsname *vx_new_utsname(void)
6497 +{
6498 +       if (current->vx_info)
6499 +               return &current->vx_info->cvirt.utsname;
6500 +       return &system_utsname;
6501 +}
6502 +
6503 +#define vx_new_uts(x)          ((vx_new_utsname())->x)
6504 +
6505 +
6506 +/* pid faking stuff */
6507 +
6508 +
6509 +#define vx_info_map_pid(v,p) \
6510 +       __vx_info_map_pid((v), (p), __FUNC__, __FILE__, __LINE__)
6511 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
6512 +#define vx_map_pid(p)  vx_info_map_pid(current->vx_info, p)
6513 +#define vx_map_tgid(p) vx_map_pid(p)
6514 +
6515 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
6516 +       const char *func, const char *file, int line)
6517 +{
6518 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
6519 +               vxfprintk(VXD_CBIT(cvirt, 2),
6520 +                       "vx_map_tgid: %p/%llx: %d -> %d",
6521 +                       vxi, (long long)vxi->vx_flags, pid,
6522 +                       (pid && pid == vxi->vx_initpid)?1:pid,
6523 +                       func, file, line);
6524 +               if (pid == 0)
6525 +                       return 0;
6526 +               if (pid == vxi->vx_initpid)
6527 +                       return 1;
6528 +       }
6529 +       return pid;
6530 +}
6531 +
6532 +#define vx_info_rmap_pid(v,p) \
6533 +       __vx_info_rmap_pid((v), (p), __FUNC__, __FILE__, __LINE__)
6534 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
6535 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
6536 +
6537 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
6538 +       const char *func, const char *file, int line)
6539 +{
6540 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
6541 +               vxfprintk(VXD_CBIT(cvirt, 2),
6542 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
6543 +                       vxi, (long long)vxi->vx_flags, pid,
6544 +                       (pid == 1)?vxi->vx_initpid:pid,
6545 +                       func, file, line);
6546 +               if ((pid == 1) && vxi->vx_initpid)
6547 +                       return vxi->vx_initpid;
6548 +               if (pid == vxi->vx_initpid)
6549 +                       return ~0U;
6550 +       }
6551 +       return pid;
6552 +}
6553 +
6554 +
6555 +static inline void vx_activate_task(struct task_struct *p)
6556 +{
6557 +       struct vx_info *vxi;
6558 +
6559 +       if ((vxi = p->vx_info)) {
6560 +               vx_update_load(vxi);
6561 +               atomic_inc(&vxi->cvirt.nr_running);
6562 +       }
6563 +}
6564 +
6565 +static inline void vx_deactivate_task(struct task_struct *p)
6566 +{
6567 +       struct vx_info *vxi;
6568 +
6569 +       if ((vxi = p->vx_info)) {
6570 +               vx_update_load(vxi);
6571 +               atomic_dec(&vxi->cvirt.nr_running);
6572 +       }
6573 +}
6574 +
6575 +static inline void vx_uninterruptible_inc(struct task_struct *p)
6576 +{
6577 +       struct vx_info *vxi;
6578 +
6579 +       if ((vxi = p->vx_info))
6580 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
6581 +}
6582 +
6583 +static inline void vx_uninterruptible_dec(struct task_struct *p)
6584 +{
6585 +       struct vx_info *vxi;
6586 +
6587 +       if ((vxi = p->vx_info))
6588 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
6589 +}
6590 +
6591 +
6592 +#else
6593 +#warning duplicate inclusion
6594 +#endif
6595 diff -NurpP --minimal linux-2.6.10/include/linux/vs_dlimit.h linux-2.6.10-vs1.9.3.17/include/linux/vs_dlimit.h
6596 --- linux-2.6.10/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
6597 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_dlimit.h   2004-12-26 19:40:21.000000000 +0100
6598 @@ -0,0 +1,206 @@
6599 +#ifndef _VX_VS_DLIMIT_H
6600 +#define _VX_VS_DLIMIT_H
6601 +
6602 +
6603 +#include "vserver/dlimit.h"
6604 +#include "vserver/debug.h"
6605 +
6606 +
6607 +#define get_dl_info(i) __get_dl_info(i,__FILE__,__LINE__)
6608 +
6609 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
6610 +       const char *_file, int _line)
6611 +{
6612 +       if (!dli)
6613 +               return NULL;
6614 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
6615 +               dli, dli?dli->dl_xid:0, dli?atomic_read(&dli->dl_usecnt):0,
6616 +               _file, _line);
6617 +       atomic_inc(&dli->dl_usecnt);
6618 +       return dli;
6619 +}
6620 +
6621 +
6622 +#define free_dl_info(i) \
6623 +       call_rcu(&i->dl_rcu, rcu_free_dl_info);
6624 +
6625 +#define put_dl_info(i) __put_dl_info(i,__FILE__,__LINE__)
6626 +
6627 +static inline void __put_dl_info(struct dl_info *dli,
6628 +       const char *_file, int _line)
6629 +{
6630 +       if (!dli)
6631 +               return;
6632 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
6633 +               dli, dli?dli->dl_xid:0, dli?atomic_read(&dli->dl_usecnt):0,
6634 +               _file, _line);
6635 +       if (atomic_dec_and_test(&dli->dl_usecnt))
6636 +               free_dl_info(dli);
6637 +}
6638 +
6639 +
6640 +#define __dlimit_char(d)       ((d)?'*':' ')
6641 +
6642 +static inline int __dl_alloc_space(struct super_block *sb,
6643 +       xid_t xid, dlsize_t nr, const char *file, int line)
6644 +{
6645 +       struct dl_info *dli = NULL;
6646 +       int ret = 0;
6647 +
6648 +       if (nr == 0)
6649 +               goto out;
6650 +       dli = locate_dl_info(sb, xid);
6651 +       if (!dli)
6652 +               goto out;
6653 +
6654 +       spin_lock(&dli->dl_lock);
6655 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
6656 +       if (!ret)
6657 +               dli->dl_space_used += nr;
6658 +       spin_unlock(&dli->dl_lock);
6659 +       put_dl_info(dli);
6660 +out:
6661 +       vxlprintk(VXD_CBIT(dlim, 1),
6662 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
6663 +               sb, xid, __dlimit_char(dli), (long long)nr,
6664 +               ret, file, line);
6665 +       return ret;
6666 +}
6667 +
6668 +static inline void __dl_free_space(struct super_block *sb,
6669 +       xid_t xid, dlsize_t nr, const char *_file, int _line)
6670 +{
6671 +       struct dl_info *dli = NULL;
6672 +
6673 +       if (nr == 0)
6674 +               goto out;
6675 +       dli = locate_dl_info(sb, xid);
6676 +       if (!dli)
6677 +               goto out;
6678 +
6679 +       spin_lock(&dli->dl_lock);
6680 +       if (dli->dl_space_used > nr)
6681 +               dli->dl_space_used -= nr;
6682 +       else
6683 +               dli->dl_space_used = 0;
6684 +       spin_unlock(&dli->dl_lock);
6685 +       put_dl_info(dli);
6686 +out:
6687 +       vxlprintk(VXD_CBIT(dlim, 1),
6688 +               "FREE  (%p,#%d)%c %lld bytes",
6689 +               sb, xid, __dlimit_char(dli), (long long)nr,
6690 +               _file, _line);
6691 +}
6692 +
6693 +static inline int __dl_alloc_inode(struct super_block *sb,
6694 +       xid_t xid, const char *_file, int _line)
6695 +{
6696 +       struct dl_info *dli;
6697 +       int ret = 0;
6698 +
6699 +       dli = locate_dl_info(sb, xid);
6700 +       if (!dli)
6701 +               goto out;
6702 +
6703 +       spin_lock(&dli->dl_lock);
6704 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
6705 +       if (!ret)
6706 +               dli->dl_inodes_used++;
6707 +#if 0
6708 +       else
6709 +               vxwprintk("DLIMIT hit (%p,#%d), inode %d>=%d @ %s:%d",
6710 +                       sb, xid,
6711 +                       dli->dl_inodes_used, dli->dl_inodes_total,
6712 +                       file, line);
6713 +#endif
6714 +       spin_unlock(&dli->dl_lock);
6715 +       put_dl_info(dli);
6716 +out:
6717 +       vxlprintk(VXD_CBIT(dlim, 0),
6718 +               "ALLOC (%p,#%d)%c inode (%d)",
6719 +               sb, xid, __dlimit_char(dli), ret, _file, _line);
6720 +       return ret;
6721 +}
6722 +
6723 +static inline void __dl_free_inode(struct super_block *sb,
6724 +       xid_t xid, const char *_file, int _line)
6725 +{
6726 +       struct dl_info *dli;
6727 +
6728 +       dli = locate_dl_info(sb, xid);
6729 +       if (!dli)
6730 +               goto out;
6731 +
6732 +       spin_lock(&dli->dl_lock);
6733 +       if (dli->dl_inodes_used > 1)
6734 +               dli->dl_inodes_used--;
6735 +       else
6736 +               dli->dl_inodes_used = 0;
6737 +       spin_unlock(&dli->dl_lock);
6738 +       put_dl_info(dli);
6739 +out:
6740 +       vxlprintk(VXD_CBIT(dlim, 0),
6741 +               "FREE  (%p,#%d)%c inode",
6742 +               sb, xid, __dlimit_char(dli), _file, _line);
6743 +}
6744 +
6745 +static inline void __dl_adjust_block(struct super_block *sb, xid_t xid,
6746 +       unsigned int *free_blocks, unsigned int *root_blocks,
6747 +       const char *_file, int _line)
6748 +{
6749 +       struct dl_info *dli;
6750 +       uint64_t broot, bfree;
6751 +
6752 +       dli = locate_dl_info(sb, xid);
6753 +       if (!dli)
6754 +               return;
6755 +
6756 +       spin_lock(&dli->dl_lock);
6757 +       broot = (dli->dl_space_total -
6758 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
6759 +               >> sb->s_blocksize_bits;
6760 +       bfree = (dli->dl_space_total - dli->dl_space_used)
6761 +                       >> sb->s_blocksize_bits;
6762 +       spin_unlock(&dli->dl_lock);
6763 +
6764 +       vxlprintk(VXD_CBIT(dlim, 2),
6765 +               "ADJUST: %lld,%lld on %d,%d [mult=%d]",
6766 +               (long long)bfree, (long long)broot,
6767 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
6768 +               _file, _line);
6769 +       if (free_blocks) {
6770 +               if (*free_blocks > bfree)
6771 +                       *free_blocks = bfree;
6772 +       }
6773 +       if (root_blocks) {
6774 +               if (*root_blocks > broot)
6775 +                       *root_blocks = broot;
6776 +       }
6777 +       put_dl_info(dli);
6778 +}
6779 +
6780 +
6781 +#define DLIMIT_ALLOC_BLOCK(sb, xid, nr) \
6782 +       __dl_alloc_space(sb, xid, \
6783 +               ((dlsize_t)(nr)) << (sb)->s_blocksize_bits, \
6784 +               __FILE__, __LINE__ )
6785 +
6786 +#define DLIMIT_FREE_BLOCK(sb, xid, nr) \
6787 +       __dl_free_space(sb, xid, \
6788 +               ((dlsize_t)(nr)) << (sb)->s_blocksize_bits, \
6789 +               __FILE__, __LINE__ )
6790 +
6791 +#define DLIMIT_ALLOC_INODE(sb, xid) \
6792 +       __dl_alloc_inode(sb, xid, __FILE__, __LINE__ )
6793 +
6794 +#define DLIMIT_FREE_INODE(sb, xid) \
6795 +       __dl_free_inode(sb, xid, __FILE__, __LINE__ )
6796 +
6797 +
6798 +#define DLIMIT_ADJUST_BLOCK(sb, xid, fb, rb) \
6799 +       __dl_adjust_block(sb, xid, fb, rb, __FILE__, __LINE__ )
6800 +
6801 +
6802 +#else
6803 +#warning duplicate inclusion
6804 +#endif
6805 diff -NurpP --minimal linux-2.6.10/include/linux/vs_limit.h linux-2.6.10-vs1.9.3.17/include/linux/vs_limit.h
6806 --- linux-2.6.10/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
6807 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_limit.h    2004-12-26 19:40:21.000000000 +0100
6808 @@ -0,0 +1,98 @@
6809 +#ifndef _VX_VS_LIMIT_H
6810 +#define _VX_VS_LIMIT_H
6811 +
6812 +
6813 +#include "vserver/limit.h"
6814 +#include "vserver/debug.h"
6815 +
6816 +
6817 +/* file limits */
6818 +
6819 +
6820 +static inline void __vx_acc_cres(struct vx_info *vxi,
6821 +       int res, int dir, void *_data, char *_file, int _line)
6822 +{
6823 +       if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
6824 +               VXD_RLIMIT(res, RLIMIT_NPROC) ||
6825 +               VXD_RLIMIT(res, VLIMIT_NSOCK))
6826 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5d%s (%p)",
6827 +                       (vxi?vxi->vx_id:-1), vlimit_name[res], res,
6828 +                       (vxi?atomic_read(&vxi->limit.rcur[res]):0),
6829 +                       (dir>0)?"++":"--", _data, _file, _line);
6830 +       if (vxi) {
6831 +               if (dir > 0)
6832 +                       atomic_inc(&vxi->limit.rcur[res]);
6833 +               else
6834 +                       atomic_dec(&vxi->limit.rcur[res]);
6835 +       }
6836 +}
6837 +
6838 +#define vx_acc_cres(v,d,p,r) \
6839 +       __vx_acc_cres((v), (r), (d), (p), __FILE__, __LINE__)
6840 +
6841 +#define vx_acc_cres_cond(x,d,p,r) \
6842 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0,\
6843 +       (r), (d), (p), __FILE__, __LINE__)
6844 +
6845 +#define vx_nproc_inc(p) \
6846 +       vx_acc_cres((p)->vx_info, 1, (p), RLIMIT_NPROC)
6847 +
6848 +#define vx_nproc_dec(p) \
6849 +       vx_acc_cres((p)->vx_info,-1, (p), RLIMIT_NPROC)
6850 +
6851 +#define vx_files_inc(f) \
6852 +       vx_acc_cres_cond((f)->f_xid, 1, (f), RLIMIT_NOFILE)
6853 +
6854 +#define vx_files_dec(f) \
6855 +       vx_acc_cres_cond((f)->f_xid,-1, (f), RLIMIT_NOFILE)
6856 +
6857 +
6858 +#define vx_cres_avail(v,n,r) \
6859 +       __vx_cres_avail((v), (r), (n), __FILE__, __LINE__)
6860 +
6861 +static inline int __vx_cres_avail(struct vx_info *vxi,
6862 +               int res, int num, char *_file, int _line)
6863 +{
6864 +       unsigned long value;
6865 +
6866 +       if (VXD_RLIMIT(res, RLIMIT_NOFILE) ||
6867 +               VXD_RLIMIT(res, RLIMIT_NPROC) ||
6868 +               VXD_RLIMIT(res, VLIMIT_NSOCK))
6869 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d",
6870 +                       (vxi?vxi->vx_id:-1), vlimit_name[res], res,
6871 +                       (vxi?vxi->limit.rlim[res]:1),
6872 +                       (vxi?atomic_read(&vxi->limit.rcur[res]):0),
6873 +                       num, _file, _line);
6874 +       if (!vxi)
6875 +               return 1;
6876 +       value = atomic_read(&vxi->limit.rcur[res]);
6877 +       if (value > vxi->limit.rmax[res])
6878 +               vxi->limit.rmax[res] = value;
6879 +       if (vxi->limit.rlim[res] == RLIM_INFINITY)
6880 +               return 1;
6881 +       if (value + num <= vxi->limit.rlim[res])
6882 +               return 1;
6883 +       atomic_inc(&vxi->limit.lhit[res]);
6884 +       return 0;
6885 +}
6886 +
6887 +#define vx_nproc_avail(n) \
6888 +       vx_cres_avail(current->vx_info, (n), RLIMIT_NPROC)
6889 +
6890 +#define vx_files_avail(n) \
6891 +       vx_cres_avail(current->vx_info, (n), RLIMIT_NOFILE)
6892 +
6893 +
6894 +/* socket limits */
6895 +
6896 +#define vx_sock_inc(s) \
6897 +       vx_acc_cres((s)->sk_vx_info, 1, (s), VLIMIT_NSOCK)
6898 +#define vx_sock_dec(s) \
6899 +       vx_acc_cres((s)->sk_vx_info,-1, (s), VLIMIT_NSOCK)
6900 +
6901 +#define vx_sock_avail(n) \
6902 +       vx_cres_avail(current->vx_info, (n), VLIMIT_NSOCK)
6903 +
6904 +#else
6905 +#warning duplicate inclusion
6906 +#endif
6907 diff -NurpP --minimal linux-2.6.10/include/linux/vs_memory.h linux-2.6.10-vs1.9.3.17/include/linux/vs_memory.h
6908 --- linux-2.6.10/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
6909 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_memory.h   2004-12-26 19:40:21.000000000 +0100
6910 @@ -0,0 +1,123 @@
6911 +#ifndef _VX_VS_MEMORY_H
6912 +#define _VX_VS_MEMORY_H
6913 +
6914 +
6915 +#include "vserver/limit.h"
6916 +#include "vserver/debug.h"
6917 +
6918 +
6919 +#define vx_acc_page(m, d, v, r) \
6920 +       __vx_acc_page(&(m->v), m->mm_vx_info, r, d, __FILE__, __LINE__)
6921 +
6922 +static inline void __vx_acc_page(unsigned long *v, struct vx_info *vxi,
6923 +               int res, int dir, char *file, int line)
6924 +{
6925 +       if (VXD_RLIMIT(res, RLIMIT_RSS) ||
6926 +               VXD_RLIMIT(res, RLIMIT_AS) ||
6927 +               VXD_RLIMIT(res, RLIMIT_MEMLOCK))
6928 +               vxlprintk(1, "vx_acc_page[%5d,%s,%2d]: %5d%s",
6929 +                       (vxi?vxi->vx_id:-1), vlimit_name[res], res,
6930 +                       (vxi?atomic_read(&vxi->limit.rcur[res]):0),
6931 +                       (dir?"++":"--"), file, line);
6932 +       if (v) {
6933 +               if (dir > 0)
6934 +                       ++(*v);
6935 +               else
6936 +                       --(*v);
6937 +       }
6938 +       if (vxi) {
6939 +               if (dir > 0)
6940 +                       atomic_inc(&vxi->limit.rcur[res]);
6941 +               else
6942 +                       atomic_dec(&vxi->limit.rcur[res]);
6943 +       }
6944 +}
6945 +
6946 +
6947 +#define vx_acc_pages(m, p, v, r) \
6948 +       __vx_acc_pages(&(m->v), m->mm_vx_info, r, p, __FILE__, __LINE__)
6949 +
6950 +static inline void __vx_acc_pages(unsigned long *v, struct vx_info *vxi,
6951 +               int res, int pages, char *_file, int _line)
6952 +{
6953 +       if (VXD_RLIMIT(res, RLIMIT_RSS) ||
6954 +               VXD_RLIMIT(res, RLIMIT_AS) ||
6955 +               VXD_RLIMIT(res, RLIMIT_MEMLOCK))
6956 +               vxlprintk(1, "vx_acc_pages[%5d,%s,%2d]: %5d += %5d",
6957 +                       (vxi?vxi->vx_id:-1), vlimit_name[res], res,
6958 +                       (vxi?atomic_read(&vxi->limit.rcur[res]):0),
6959 +                       pages, _file, _line);
6960 +       if (pages == 0)
6961 +               return;
6962 +       if (v)
6963 +               *v += pages;
6964 +       if (vxi)
6965 +               atomic_add(pages, &vxi->limit.rcur[res]);
6966 +}
6967 +
6968 +
6969 +
6970 +#define vx_acc_vmpage(m,d)     vx_acc_page(m, d, total_vm,  RLIMIT_AS)
6971 +#define vx_acc_vmlpage(m,d)    vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
6972 +#define vx_acc_rsspage(m,d)    vx_acc_page(m, d, rss,       RLIMIT_RSS)
6973 +
6974 +#define vx_acc_vmpages(m,p)    vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
6975 +#define vx_acc_vmlpages(m,p)   vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
6976 +#define vx_acc_rsspages(m,p)   vx_acc_pages(m, p, rss,       RLIMIT_RSS)
6977 +
6978 +#define vx_pages_add(s,r,p)    __vx_acc_pages(0, s, r, p, __FILE__, __LINE__)
6979 +#define vx_pages_sub(s,r,p)    vx_pages_add(s, r, -(p))
6980 +
6981 +#define vx_vmpages_inc(m)      vx_acc_vmpage(m, 1)
6982 +#define vx_vmpages_dec(m)      vx_acc_vmpage(m,-1)
6983 +#define vx_vmpages_add(m,p)    vx_acc_vmpages(m, p)
6984 +#define vx_vmpages_sub(m,p)    vx_acc_vmpages(m,-(p))
6985 +
6986 +#define vx_vmlocked_inc(m)     vx_acc_vmlpage(m, 1)
6987 +#define vx_vmlocked_dec(m)     vx_acc_vmlpage(m,-1)
6988 +#define vx_vmlocked_add(m,p)   vx_acc_vmlpages(m, p)
6989 +#define vx_vmlocked_sub(m,p)   vx_acc_vmlpages(m,-(p))
6990 +
6991 +#define vx_rsspages_inc(m)     vx_acc_rsspage(m, 1)
6992 +#define vx_rsspages_dec(m)     vx_acc_rsspage(m,-1)
6993 +#define vx_rsspages_add(m,p)   vx_acc_rsspages(m, p)
6994 +#define vx_rsspages_sub(m,p)   vx_acc_rsspages(m,-(p))
6995 +
6996 +
6997 +
6998 +#define vx_pages_avail(m, p, r) \
6999 +       __vx_pages_avail((m)->mm_vx_info, (r), (p), __FILE__, __LINE__)
7000 +
7001 +static inline int __vx_pages_avail(struct vx_info *vxi,
7002 +               int res, int pages, char *_file, int _line)
7003 +{
7004 +       unsigned long value;
7005 +
7006 +       if (VXD_RLIMIT(res, RLIMIT_RSS) ||
7007 +               VXD_RLIMIT(res, RLIMIT_AS) ||
7008 +               VXD_RLIMIT(res, RLIMIT_MEMLOCK))
7009 +               vxlprintk(1, "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d",
7010 +                       (vxi?vxi->vx_id:-1), vlimit_name[res], res,
7011 +                       (vxi?vxi->limit.rlim[res]:1),
7012 +                       (vxi?atomic_read(&vxi->limit.rcur[res]):0),
7013 +                       pages, _file, _line);
7014 +       if (!vxi)
7015 +               return 1;
7016 +       value = atomic_read(&vxi->limit.rcur[res]);
7017 +       if (value > vxi->limit.rmax[res])
7018 +               vxi->limit.rmax[res] = value;
7019 +       if (vxi->limit.rlim[res] == RLIM_INFINITY)
7020 +               return 1;
7021 +       if (value + pages <= vxi->limit.rlim[res])
7022 +               return 1;
7023 +       atomic_inc(&vxi->limit.lhit[res]);
7024 +       return 0;
7025 +}
7026 +
7027 +#define vx_vmpages_avail(m,p)  vx_pages_avail(m, p, RLIMIT_AS)
7028 +#define vx_vmlocked_avail(m,p) vx_pages_avail(m, p, RLIMIT_MEMLOCK)
7029 +#define vx_rsspages_avail(m,p) vx_pages_avail(m, p, RLIMIT_RSS)
7030 +
7031 +#else
7032 +#warning duplicate inclusion
7033 +#endif
7034 diff -NurpP --minimal linux-2.6.10/include/linux/vs_network.h linux-2.6.10-vs1.9.3.17/include/linux/vs_network.h
7035 --- linux-2.6.10/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
7036 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_network.h  2005-01-03 01:24:39.000000000 +0100
7037 @@ -0,0 +1,154 @@
7038 +#ifndef _NX_VS_NETWORK_H
7039 +#define _NX_VS_NETWORK_H
7040 +
7041 +
7042 +#include "vserver/network.h"
7043 +#include "vserver/debug.h"
7044 +
7045 +
7046 +#define get_nx_info(i) __get_nx_info(i,__FILE__,__LINE__)
7047 +
7048 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
7049 +       const char *_file, int _line)
7050 +{
7051 +       if (!nxi)
7052 +               return NULL;
7053 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
7054 +               nxi, nxi?nxi->nx_id:0, nxi?atomic_read(&nxi->nx_usecnt):0,
7055 +               _file, _line);
7056 +       atomic_inc(&nxi->nx_usecnt);
7057 +       return nxi;
7058 +}
7059 +
7060 +#define put_nx_info(i) __put_nx_info(i,__FILE__,__LINE__)
7061 +
7062 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
7063 +{
7064 +       if (!nxi)
7065 +               return;
7066 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
7067 +               nxi, nxi?nxi->nx_id:0, nxi?atomic_read(&nxi->nx_usecnt):0,
7068 +               _file, _line);
7069 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
7070 +               free_nx_info(nxi);
7071 +}
7072 +
7073 +#define set_nx_info(p,i) __set_nx_info(p,i,__FILE__,__LINE__)
7074 +
7075 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
7076 +       const char *_file, int _line)
7077 +{
7078 +       struct nx_info *nxo;
7079 +
7080 +       if (!nxi)
7081 +               return;
7082 +
7083 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d.%d])",
7084 +               nxi, nxi?nxi->nx_id:0,
7085 +               nxi?atomic_read(&nxi->nx_usecnt):0,
7086 +               nxi?atomic_read(&nxi->nx_refcnt):0,
7087 +               _file, _line);
7088 +
7089 +       atomic_inc(&nxi->nx_refcnt);
7090 +       nxo = xchg(nxp, __get_nx_info(nxi, _file, _line));
7091 +       BUG_ON(nxo);
7092 +}
7093 +
7094 +#define clr_nx_info(p) __clr_nx_info(p,__FILE__,__LINE__)
7095 +
7096 +static inline void __clr_nx_info(struct nx_info **nxp,
7097 +       const char *_file, int _line)
7098 +{
7099 +       struct nx_info *nxo;
7100 +
7101 +       nxo = xchg(nxp, NULL);
7102 +       if (!nxo)
7103 +               return;
7104 +
7105 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d.%d])",
7106 +               nxo, nxo?nxo->nx_id:0,
7107 +               nxo?atomic_read(&nxo->nx_usecnt):0,
7108 +               nxo?atomic_read(&nxo->nx_refcnt):0,
7109 +               _file, _line);
7110 +
7111 +       if (atomic_dec_and_test(&nxo->nx_refcnt))
7112 +               unhash_nx_info(nxo);
7113 +       __put_nx_info(nxo, _file, _line);
7114 +}
7115 +
7116 +
7117 +#define task_get_nx_info(i)    __task_get_nx_info(i,__FILE__,__LINE__)
7118 +
7119 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
7120 +       const char *_file, int _line)
7121 +{
7122 +       struct nx_info *nxi;
7123 +
7124 +       task_lock(p);
7125 +       nxi = __get_nx_info(p->nx_info, _file, _line);
7126 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
7127 +               p, _file, _line);
7128 +       task_unlock(p);
7129 +       return nxi;
7130 +}
7131 +
7132 +#define nx_verify_info(p,i)    \
7133 +       __nx_verify_info((p)->nx_info,i,__FILE__,__LINE__)
7134 +
7135 +static __inline__ void __nx_verify_info(
7136 +       struct nx_info *ipa, struct nx_info *ipb,
7137 +       const char *_file, int _line)
7138 +{
7139 +       if (ipa == ipb)
7140 +               return;
7141 +       printk(KERN_ERR "ip bad assumption (%p==%p) at %s:%d\n",
7142 +               ipa, ipb, _file, _line);
7143 +}
7144 +
7145 +
7146 +#define nx_task_nid(t) ((t)->nid)
7147 +
7148 +#define nx_current_nid() nx_task_nid(current)
7149 +
7150 +#define nx_check(c,m)  __nx_check(nx_current_nid(),c,m)
7151 +
7152 +#define nx_weak_check(c,m)     ((m) ? nx_check(c,m) : 1)
7153 +
7154 +
7155 +#define __nx_flags(v,m,f)      (((v) & (m)) ^ (f))
7156 +
7157 +#define __nx_task_flags(t,m,f) \
7158 +       (((t) && ((t)->nx_info)) ? \
7159 +               __nx_flags((t)->nx_info->nx_flags,(m),(f)) : 0)
7160 +
7161 +#define nx_current_flags() \
7162 +       ((current->nx_info) ? current->nx_info->nx_flags : 0)
7163 +
7164 +#define nx_flags(m,f)  __nx_flags(nx_current_flags(),(m),(f))
7165 +
7166 +
7167 +#define nx_current_ncaps() \
7168 +       ((current->nx_info) ? current->nx_info->nx_ncaps : 0)
7169 +
7170 +#define nx_ncaps(c)    (nx_current_ncaps() & (c))
7171 +
7172 +
7173 +static inline int addr_in_nx_info(struct nx_info *nxi, uint32_t addr)
7174 +{
7175 +       int n,i;
7176 +
7177 +       if (!nxi)
7178 +               return 1;
7179 +
7180 +       n = nxi->nbipv4;
7181 +       for (i=0; i<n; i++) {
7182 +               if (nxi->ipv4[i] == addr)
7183 +                       return 1;
7184 +       }
7185 +       return 0;
7186 +}
7187 +
7188 +
7189 +#else
7190 +#warning duplicate inclusion
7191 +#endif
7192 diff -NurpP --minimal linux-2.6.10/include/linux/vs_sched.h linux-2.6.10-vs1.9.3.17/include/linux/vs_sched.h
7193 --- linux-2.6.10/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
7194 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_sched.h    2004-12-26 19:40:21.000000000 +0100
7195 @@ -0,0 +1,73 @@
7196 +#ifndef _VX_VS_SCHED_H
7197 +#define _VX_VS_SCHED_H
7198 +
7199 +
7200 +#include "vserver/sched.h"
7201 +
7202 +
7203 +#define VAVAVOOM_RATIO          50
7204 +
7205 +#define MAX_PRIO_BIAS           20
7206 +#define MIN_PRIO_BIAS          -20
7207 +
7208 +
7209 +static inline int vx_tokens_avail(struct vx_info *vxi)
7210 +{
7211 +       return atomic_read(&vxi->sched.tokens);
7212 +}
7213 +
7214 +static inline void vx_consume_token(struct vx_info *vxi)
7215 +{
7216 +       atomic_dec(&vxi->sched.tokens);
7217 +}
7218 +
7219 +static inline int vx_need_resched(struct task_struct *p)
7220 +{
7221 +#ifdef CONFIG_VSERVER_HARDCPU
7222 +       struct vx_info *vxi = p->vx_info;
7223 +#endif
7224 +       int slice = --p->time_slice;
7225 +
7226 +#ifdef CONFIG_VSERVER_HARDCPU
7227 +       if (vxi) {
7228 +               int tokens;
7229 +
7230 +               if ((tokens = vx_tokens_avail(vxi)) > 0)
7231 +                       vx_consume_token(vxi);
7232 +               /* for tokens > 0, one token was consumed */
7233 +               if (tokens < 2)
7234 +                       return 1;
7235 +       }
7236 +#endif
7237 +       return (slice == 0);
7238 +}
7239 +
7240 +
7241 +static inline void vx_onhold_inc(struct vx_info *vxi)
7242 +{
7243 +       int onhold = atomic_read(&vxi->cvirt.nr_onhold);
7244 +
7245 +       atomic_inc(&vxi->cvirt.nr_onhold);
7246 +       if (!onhold)
7247 +               vxi->cvirt.onhold_last = jiffies;
7248 +}
7249 +
7250 +static inline void __vx_onhold_update(struct vx_info *vxi)
7251 +{
7252 +       int cpu = smp_processor_id();
7253 +       uint32_t now = jiffies;
7254 +       uint32_t delta = now - vxi->cvirt.onhold_last;
7255 +
7256 +       vxi->cvirt.onhold_last = now;
7257 +       vxi->sched.cpu[cpu].hold_ticks += delta;
7258 +}
7259 +
7260 +static inline void vx_onhold_dec(struct vx_info *vxi)
7261 +{
7262 +       if (atomic_dec_and_test(&vxi->cvirt.nr_onhold))
7263 +               __vx_onhold_update(vxi);
7264 +}
7265 +
7266 +#else
7267 +#warning duplicate inclusion
7268 +#endif
7269 diff -NurpP --minimal linux-2.6.10/include/linux/vs_socket.h linux-2.6.10-vs1.9.3.17/include/linux/vs_socket.h
7270 --- linux-2.6.10/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
7271 +++ linux-2.6.10-vs1.9.3.17/include/linux/vs_socket.h   2004-12-26 19:40:21.000000000 +0100
7272 @@ -0,0 +1,58 @@
7273 +#ifndef _VX_VS_SOCKET_H
7274 +#define _VX_VS_SOCKET_H
7275 +
7276 +
7277 +#include "vserver/debug.h"
7278 +
7279 +
7280 +/* socket accounting */
7281 +
7282 +#include <linux/socket.h>
7283 +
7284 +static inline int vx_sock_type(int family)
7285 +{
7286 +       int type = 4;
7287 +
7288 +       if (family > 0 && family < 3)
7289 +               type = family;
7290 +       else if (family == PF_INET6)
7291 +               type = 3;
7292 +       return type;
7293 +}
7294 +
7295 +#define vx_acc_sock(v,f,p,s) \
7296 +       __vx_acc_sock((v), (f), (p), (s), __FILE__, __LINE__)
7297 +
7298 +static inline void __vx_acc_sock(struct vx_info *vxi,
7299 +       int family, int pos, int size, char *file, int line)
7300 +{
7301 +       if (vxi) {
7302 +               int type = vx_sock_type(family);
7303 +
7304 +               atomic_inc(&vxi->cacct.sock[type][pos].count);
7305 +               atomic_add(size, &vxi->cacct.sock[type][pos].total);
7306 +       }
7307 +}
7308 +
7309 +#define vx_sock_recv(sk,s) \
7310 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, (s))
7311 +#define vx_sock_send(sk,s) \
7312 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, (s))
7313 +#define vx_sock_fail(sk,s) \
7314 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, (s))
7315 +
7316 +
7317 +#define sock_vx_init(s) do {           \
7318 +       (s)->sk_xid = 0;                \
7319 +       (s)->sk_vx_info = NULL;         \
7320 +       } while (0)
7321 +
7322 +#define sock_nx_init(s) do {           \
7323 +       (s)->sk_nid = 0;                \
7324 +       (s)->sk_nx_info = NULL;         \
7325 +       } while (0)
7326 +
7327 +
7328 +#else
7329 +#warning duplicate inclusion
7330 +#endif
7331 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/context.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/context.h
7332 --- linux-2.6.10/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
7333 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/context.h     2005-01-02 18:30:16.000000000 +0100
7334 @@ -0,0 +1,155 @@
7335 +#ifndef _VX_CONTEXT_H
7336 +#define _VX_CONTEXT_H
7337 +
7338 +#include <linux/types.h>
7339 +
7340 +
7341 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
7342 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
7343 +
7344 +#define VX_DYNAMIC_ID  ((uint32_t)-1)          /* id for dynamic context */
7345 +
7346 +/* context flags */
7347 +
7348 +#define VXF_INFO_LOCK          0x00000001
7349 +#define VXF_INFO_SCHED         0x00000002
7350 +#define VXF_INFO_NPROC         0x00000004
7351 +#define VXF_INFO_PRIVATE       0x00000008
7352 +
7353 +#define VXF_INFO_INIT          0x00000010
7354 +#define VXF_INFO_HIDE          0x00000020
7355 +#define VXF_INFO_ULIMIT                0x00000040
7356 +#define VXF_INFO_NSPACE                0x00000080
7357 +
7358 +#define VXF_SCHED_HARD         0x00000100
7359 +#define VXF_SCHED_PRIO         0x00000200
7360 +#define VXF_SCHED_PAUSE                0x00000400
7361 +
7362 +#define VXF_VIRT_MEM           0x00010000
7363 +#define VXF_VIRT_UPTIME                0x00020000
7364 +#define VXF_VIRT_CPU           0x00040000
7365 +#define VXF_VIRT_LOAD          0x00080000
7366 +
7367 +#define VXF_HIDE_MOUNT         0x01000000
7368 +#define VXF_HIDE_NETIF         0x02000000
7369 +
7370 +#define VXF_STATE_SETUP                (1ULL<<32)
7371 +#define VXF_STATE_INIT         (1ULL<<33)
7372 +
7373 +#define VXF_FORK_RSS           (1ULL<<48)
7374 +#define VXF_PROLIFIC           (1ULL<<49)
7375 +
7376 +#define VXF_IGNEG_NICE         (1ULL<<52)
7377 +
7378 +#define VXF_ONE_TIME           (0x0003ULL<<32)
7379 +
7380 +
7381 +/* context caps */
7382 +
7383 +#define        VXC_CAP_MASK            0x00000000
7384 +
7385 +#define VXC_SET_UTSNAME                0x00000001
7386 +#define VXC_SET_RLIMIT         0x00000002
7387 +
7388 +#define VXC_RAW_ICMP           0x00000100
7389 +
7390 +#define VXC_SECURE_MOUNT       0x00010000
7391 +#define VXC_SECURE_REMOUNT     0x00020000
7392 +
7393 +
7394 +/* vshelper sync commands */
7395 +
7396 +#define        VS_CONTEXT_CREATED      1
7397 +#define        VS_CONTEXT_DESTROY      2
7398 +
7399 +
7400 +#ifdef __KERNEL__
7401 +
7402 +#include <linux/list.h>
7403 +#include <linux/spinlock.h>
7404 +#include <linux/rcupdate.h>
7405 +
7406 +#include "limit_def.h"
7407 +#include "sched_def.h"
7408 +#include "cvirt_def.h"
7409 +
7410 +struct vx_info {
7411 +       struct hlist_node vx_hlist;             /* linked list of contexts */
7412 +       struct rcu_head vx_rcu;                 /* the rcu head */
7413 +       xid_t vx_id;                            /* context id */
7414 +       atomic_t vx_usecnt;                     /* usage count */
7415 +       atomic_t vx_refcnt;                     /* reference count */
7416 +       struct vx_info *vx_parent;              /* parent context */
7417 +       int vx_state;                           /* context state */
7418 +
7419 +       struct namespace *vx_namespace;         /* private namespace */
7420 +       struct fs_struct *vx_fs;                /* private namespace fs */
7421 +       uint64_t vx_flags;                      /* context flags */
7422 +       uint64_t vx_bcaps;                      /* bounding caps (system) */
7423 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
7424 +
7425 +       pid_t vx_initpid;                       /* PID of fake init process */
7426 +
7427 +       spinlock_t vx_lock;
7428 +       wait_queue_head_t vx_exit;              /* context exit waitqueue */
7429 +
7430 +       struct _vx_limit limit;                 /* vserver limits */
7431 +       struct _vx_sched sched;                 /* vserver scheduler */
7432 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
7433 +       struct _vx_cacct cacct;                 /* context accounting */
7434 +
7435 +       char vx_name[65];                       /* vserver name */
7436 +};
7437 +
7438 +
7439 +/* status flags */
7440 +
7441 +#define VXS_HASHED     0x0001
7442 +#define VXS_PAUSED     0x0010
7443 +#define VXS_ONHOLD     0x0020
7444 +#define VXS_SHUTDOWN   0x0100
7445 +#define VXS_DEFUNCT    0x1000
7446 +#define VXS_RELEASED   0x8000
7447 +
7448 +/* check conditions */
7449 +
7450 +#define VX_ADMIN       0x0001
7451 +#define VX_WATCH       0x0002
7452 +#define VX_HIDE                0x0004
7453 +#define VX_HOSTID      0x0008
7454 +
7455 +#define VX_IDENT       0x0010
7456 +#define VX_EQUIV       0x0020
7457 +#define VX_PARENT      0x0040
7458 +#define VX_CHILD       0x0080
7459 +
7460 +#define VX_ARG_MASK    0x00F0
7461 +
7462 +#define VX_DYNAMIC     0x0100
7463 +#define VX_STATIC      0x0200
7464 +
7465 +#define VX_ATR_MASK    0x0F00
7466 +
7467 +
7468 +struct rcu_head;
7469 +
7470 +extern void unhash_vx_info(struct vx_info *);
7471 +
7472 +extern void free_vx_info(struct vx_info *);
7473 +
7474 +extern struct vx_info *locate_vx_info(int);
7475 +extern struct vx_info *locate_or_create_vx_info(int);
7476 +
7477 +extern int get_xid_list(int, unsigned int *, int);
7478 +extern int vx_info_is_hashed(xid_t);
7479 +
7480 +extern int vx_migrate_task(struct task_struct *, struct vx_info *);
7481 +
7482 +// extern int proc_pid_vx_info(struct task_struct *, char *);
7483 +
7484 +extern long vs_context_state(unsigned int);
7485 +
7486 +#endif /* __KERNEL__ */
7487 +#else  /* _VX_CONTEXT_H */
7488 +#warning duplicate inclusion
7489 +#endif /* _VX_CONTEXT_H */
7490 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/context_cmd.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/context_cmd.h
7491 --- linux-2.6.10/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
7492 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/context_cmd.h 2004-12-26 19:40:36.000000000 +0100
7493 @@ -0,0 +1,73 @@
7494 +#ifndef _VX_CONTEXT_CMD_H
7495 +#define _VX_CONTEXT_CMD_H
7496 +
7497 +
7498 +/* vinfo commands */
7499 +
7500 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
7501 +
7502 +#ifdef __KERNEL__
7503 +extern int vc_task_xid(uint32_t, void __user *);
7504 +
7505 +#endif /* __KERNEL__ */
7506 +
7507 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
7508 +
7509 +struct vcmd_vx_info_v0 {
7510 +       uint32_t xid;
7511 +       uint32_t initpid;
7512 +       /* more to come */
7513 +};
7514 +
7515 +#ifdef __KERNEL__
7516 +extern int vc_vx_info(uint32_t, void __user *);
7517 +
7518 +#endif /* __KERNEL__ */
7519 +
7520 +
7521 +/* context commands */
7522 +
7523 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 0)
7524 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 0)
7525 +
7526 +#ifdef __KERNEL__
7527 +extern int vc_ctx_create(uint32_t, void __user *);
7528 +extern int vc_ctx_migrate(uint32_t, void __user *);
7529 +
7530 +#endif /* __KERNEL__ */
7531 +
7532 +
7533 +/* flag commands */
7534 +
7535 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
7536 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
7537 +
7538 +struct vcmd_ctx_flags_v0 {
7539 +       uint64_t flagword;
7540 +       uint64_t mask;
7541 +};
7542 +
7543 +#ifdef __KERNEL__
7544 +extern int vc_get_cflags(uint32_t, void __user *);
7545 +extern int vc_set_cflags(uint32_t, void __user *);
7546 +
7547 +#endif /* __KERNEL__ */
7548 +
7549 +
7550 +/* context caps commands */
7551 +
7552 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 0)
7553 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 0)
7554 +
7555 +struct vcmd_ctx_caps_v0 {
7556 +       uint64_t bcaps;
7557 +       uint64_t ccaps;
7558 +       uint64_t cmask;
7559 +};
7560 +
7561 +#ifdef __KERNEL__
7562 +extern int vc_get_ccaps(uint32_t, void __user *);
7563 +extern int vc_set_ccaps(uint32_t, void __user *);
7564 +
7565 +#endif /* __KERNEL__ */
7566 +#endif /* _VX_CONTEXT_CMD_H */
7567 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/cvirt.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/cvirt.h
7568 --- linux-2.6.10/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
7569 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/cvirt.h       2004-12-26 19:40:30.000000000 +0100
7570 @@ -0,0 +1,18 @@
7571 +#ifndef _VX_CVIRT_H
7572 +#define _VX_CVIRT_H
7573 +
7574 +#ifdef __KERNEL__
7575 +
7576 +struct timespec;
7577 +
7578 +void vx_vsi_uptime(struct timespec *, struct timespec *);
7579 +
7580 +
7581 +struct vx_info;
7582 +
7583 +void vx_update_load(struct vx_info *);
7584 +
7585 +#endif /* __KERNEL__ */
7586 +#else  /* _VX_CVIRT_H */
7587 +#warning duplicate inclusion
7588 +#endif /* _VX_CVIRT_H */
7589 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/cvirt_cmd.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/cvirt_cmd.h
7590 --- linux-2.6.10/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
7591 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/cvirt_cmd.h   2004-12-26 19:40:36.000000000 +0100
7592 @@ -0,0 +1,7 @@
7593 +#ifndef _VX_CVIRT_CMD_H
7594 +#define _VX_CVIRT_CMD_H
7595 +
7596 +/*  cvirt vserver commands */
7597 +
7598 +
7599 +#endif /* _VX_CVIRT_CMD_H */
7600 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/cvirt_def.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/cvirt_def.h
7601 --- linux-2.6.10/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
7602 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/cvirt_def.h   2004-12-26 19:40:36.000000000 +0100
7603 @@ -0,0 +1,59 @@
7604 +#ifndef _VX_CVIRT_DEF_H
7605 +#define _VX_CVIRT_DEF_H
7606 +
7607 +#include <linux/jiffies.h>
7608 +#include <linux/utsname.h>
7609 +#include <linux/spinlock.h>
7610 +#include <linux/time.h>
7611 +#include <asm/atomic.h>
7612 +
7613 +
7614 +struct _vx_usage_stat {
7615 +       uint64_t user;
7616 +       uint64_t nice;
7617 +       uint64_t system;
7618 +       uint64_t softirq;
7619 +       uint64_t irq;
7620 +       uint64_t idle;
7621 +       uint64_t iowait;
7622 +};
7623 +
7624 +/* context sub struct */
7625 +
7626 +struct _vx_cvirt {
7627 +       int max_threads;                /* maximum allowed threads */
7628 +       atomic_t nr_threads;            /* number of current threads */
7629 +       atomic_t nr_running;            /* number of running threads */
7630 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
7631 +
7632 +       atomic_t nr_onhold;             /* processes on hold */
7633 +       uint32_t onhold_last;           /* jiffies when put on hold */
7634 +
7635 +       struct timespec bias_idle;
7636 +       struct timespec bias_uptime;    /* context creation point */
7637 +       uint64_t bias_clock;            /* offset in clock_t */
7638 +
7639 +       struct new_utsname utsname;
7640 +
7641 +       spinlock_t load_lock;           /* lock for the load averages */
7642 +       atomic_t load_updates;          /* nr of load updates done so far */
7643 +       uint32_t load_last;             /* last time load was cacled */
7644 +       uint32_t load[3];               /* load averages 1,5,15 */
7645 +
7646 +       struct _vx_usage_stat cpustat[NR_CPUS];
7647 +};
7648 +
7649 +struct _vx_sock_acc {
7650 +       atomic_t count;
7651 +       atomic_t total;
7652 +};
7653 +
7654 +/* context sub struct */
7655 +
7656 +struct _vx_cacct {
7657 +       unsigned long total_forks;
7658 +
7659 +       struct _vx_sock_acc sock[5][3];
7660 +};
7661 +
7662 +#endif /* _VX_CVIRT_DEF_H */
7663 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/debug.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/debug.h
7664 --- linux-2.6.10/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
7665 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/debug.h       2005-01-02 09:44:49.000000000 +0100
7666 @@ -0,0 +1,268 @@
7667 +#ifndef _VX_DEBUG_H
7668 +#define _VX_DEBUG_H
7669 +
7670 +
7671 +#define VXD_CBIT(n,m)  (vx_debug_ ## n & (1 << (m)))
7672 +#define VXD_CMIN(n,m)  (vx_debug_ ## n > (m))
7673 +#define VXD_MASK(n,m)  (vx_debug_ ## n & (m))
7674 +
7675 +#define VXD_QPOS(v,p)  (((uint32_t)(v) >> ((p)*8)) & 0xFF)
7676 +#define VXD_QUAD(v)    VXD_QPOS(v,0), VXD_QPOS(v,1),           \
7677 +                       VXD_QPOS(v,2), VXD_QPOS(v,3)
7678 +
7679 +#define __FUNC__       __func__
7680 +
7681 +
7682 +#ifdef CONFIG_VSERVER_DEBUG
7683 +
7684 +extern unsigned int vx_debug_switch;
7685 +extern unsigned int vx_debug_xid;
7686 +extern unsigned int vx_debug_nid;
7687 +extern unsigned int vx_debug_net;
7688 +extern unsigned int vx_debug_limit;
7689 +extern unsigned int vx_debug_dlim;
7690 +extern unsigned int vx_debug_cvirt;
7691 +
7692 +
7693 +#define VX_LOGLEVEL    "vxD: "
7694 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
7695 +
7696 +#define vxdprintk(c,f,x...)                                    \
7697 +       do {                                                    \
7698 +               if (c)                                          \
7699 +                       printk(VX_LOGLEVEL f "\n" , ##x);       \
7700 +       } while (0)
7701 +
7702 +#define vxlprintk(c,f,x...)                                    \
7703 +       do {                                                    \
7704 +               if (c)                                          \
7705 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
7706 +       } while (0)
7707 +
7708 +#define vxfprintk(c,f,x...)                                    \
7709 +       do {                                                    \
7710 +               if (c)                                          \
7711 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
7712 +       } while (0)
7713 +
7714 +
7715 +#define vxwprintk(c,f,x...)                                    \
7716 +       do {                                                    \
7717 +               if (c)                                          \
7718 +                       printk(VX_WARNLEVEL f "\n" , ##x);      \
7719 +       } while (0)
7720 +
7721 +
7722 +#define vxd_path(d,m)                                          \
7723 +       ({ static char _buffer[PATH_MAX];                       \
7724 +          d_path((d), (m), _buffer, sizeof(_buffer)); })
7725 +
7726 +#else  /* CONFIG_VSERVER_DEBUG */
7727 +
7728 +#define vx_debug_switch 0
7729 +#define vx_debug_xid   0
7730 +#define vx_debug_nid   0
7731 +#define vx_debug_net   0
7732 +#define vx_debug_limit 0
7733 +#define vx_debug_dlim  0
7734 +#define vx_debug_cvirt 0
7735 +
7736 +#define vxdprintk(x...) do { } while (0)
7737 +#define vxlprintk(x...) do { } while (0)
7738 +#define vxfprintk(x...) do { } while (0)
7739 +#define vxwprintk(x...) do { } while (0)
7740 +
7741 +#define vxd_path       "<none>"
7742 +
7743 +#endif /* CONFIG_VSERVER_DEBUG */
7744 +
7745 +
7746 +/* history stuff */
7747 +
7748 +#ifdef CONFIG_VSERVER_HISTORY
7749 +
7750 +
7751 +extern unsigned volatile int vxh_active;
7752 +
7753 +struct _vxhe_vxi {
7754 +       struct vx_info *ptr;
7755 +       unsigned xid;
7756 +       unsigned usecnt;
7757 +       unsigned refcnt;
7758 +};
7759 +
7760 +struct _vxhe_set_clr {
7761 +       void *data;
7762 +};
7763 +
7764 +struct _vxhe_loc_lookup {
7765 +       unsigned arg;
7766 +};
7767 +
7768 +enum {
7769 +       VXH_UNUSED=0,
7770 +       VXH_THROW_OOPS=1,
7771 +
7772 +       VXH_GET_VX_INFO,
7773 +       VXH_PUT_VX_INFO,
7774 +       VXH_SET_VX_INFO,
7775 +       VXH_CLR_VX_INFO,
7776 +       VXH_ALLOC_VX_INFO,
7777 +       VXH_DEALLOC_VX_INFO,
7778 +       VXH_HASH_VX_INFO,
7779 +       VXH_UNHASH_VX_INFO,
7780 +       VXH_LOC_VX_INFO,
7781 +       VXH_LOOKUP_VX_INFO,
7782 +};
7783 +
7784 +struct _vx_hist_entry {
7785 +       void *loc;
7786 +       unsigned short seq;
7787 +       unsigned short type;
7788 +       struct _vxhe_vxi vxi;
7789 +       union {
7790 +               struct _vxhe_set_clr sc;
7791 +               struct _vxhe_loc_lookup ll;
7792 +       };
7793 +};
7794 +
7795 +struct _vx_hist_entry *vxh_advance(void *loc);
7796 +
7797 +#define        VXH_HERE()              \
7798 +       ({ __label__ here;      \
7799 +               here:;          \
7800 +               &&here; })
7801 +
7802 +
7803 +
7804 +static inline void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
7805 +{
7806 +       entry->vxi.ptr = vxi;
7807 +       if (vxi) {
7808 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
7809 +               entry->vxi.refcnt = atomic_read(&vxi->vx_refcnt);
7810 +               entry->vxi.xid = vxi->vx_id;
7811 +       }
7812 +}
7813 +
7814 +static inline void vxh_throw_oops(void)
7815 +{
7816 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7817 +
7818 +       entry->type = VXH_THROW_OOPS;
7819 +
7820 +       /* prevent further acquisition */
7821 +       vxh_active = 0;
7822 +}
7823 +
7824 +static inline void vxh_get_vx_info(struct vx_info *vxi)
7825 +{
7826 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7827 +
7828 +       __vxh_copy_vxi(entry, vxi);
7829 +       entry->type = VXH_GET_VX_INFO;
7830 +}
7831 +
7832 +static inline void vxh_put_vx_info(struct vx_info *vxi)
7833 +{
7834 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7835 +
7836 +       __vxh_copy_vxi(entry, vxi);
7837 +       entry->type = VXH_PUT_VX_INFO;
7838 +}
7839 +
7840 +static inline void vxh_set_vx_info(struct vx_info *vxi, void *data)
7841 +{
7842 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7843 +
7844 +       __vxh_copy_vxi(entry, vxi);
7845 +       entry->sc.data = data;
7846 +       entry->type = VXH_SET_VX_INFO;
7847 +}
7848 +
7849 +static inline void vxh_clr_vx_info(struct vx_info *vxi, void *data)
7850 +{
7851 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7852 +
7853 +       __vxh_copy_vxi(entry, vxi);
7854 +       entry->sc.data = data;
7855 +       entry->type = VXH_CLR_VX_INFO;
7856 +}
7857 +
7858 +static inline void vxh_alloc_vx_info(struct vx_info *vxi)
7859 +{
7860 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7861 +
7862 +       __vxh_copy_vxi(entry, vxi);
7863 +       entry->type = VXH_ALLOC_VX_INFO;
7864 +}
7865 +
7866 +static inline void vxh_dealloc_vx_info(struct vx_info *vxi)
7867 +{
7868 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7869 +
7870 +       __vxh_copy_vxi(entry, vxi);
7871 +       entry->type = VXH_DEALLOC_VX_INFO;
7872 +}
7873 +
7874 +static inline void vxh_hash_vx_info(struct vx_info *vxi)
7875 +{
7876 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7877 +
7878 +       __vxh_copy_vxi(entry, vxi);
7879 +       entry->type = VXH_HASH_VX_INFO;
7880 +}
7881 +
7882 +static inline void vxh_unhash_vx_info(struct vx_info *vxi)
7883 +{
7884 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7885 +
7886 +       __vxh_copy_vxi(entry, vxi);
7887 +       entry->type = VXH_UNHASH_VX_INFO;
7888 +}
7889 +
7890 +static inline void vxh_loc_vx_info(unsigned arg, struct vx_info *vxi)
7891 +{
7892 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7893 +
7894 +       __vxh_copy_vxi(entry, vxi);
7895 +       entry->ll.arg = arg;
7896 +       entry->type = VXH_LOC_VX_INFO;
7897 +}
7898 +
7899 +static inline void vxh_lookup_vx_info(unsigned arg, struct vx_info *vxi)
7900 +{
7901 +       struct _vx_hist_entry *entry = vxh_advance(VXH_HERE());
7902 +
7903 +       __vxh_copy_vxi(entry, vxi);
7904 +       entry->ll.arg = arg;
7905 +       entry->type = VXH_LOOKUP_VX_INFO;
7906 +}
7907 +
7908 +extern void vxh_dump_history(void);
7909 +
7910 +#else  /* CONFIG_VSERVER_HISTORY */
7911 +
7912 +#define        vxh_throw_oops()        do { } while (0)
7913 +
7914 +#define vxh_get_vx_info(v)     do { } while (0)
7915 +#define vxh_put_vx_info(v)     do { } while (0)
7916 +
7917 +#define vxh_set_vx_info(v,d)   do { } while (0)
7918 +#define vxh_clr_vx_info(v,d)   do { } while (0)
7919 +
7920 +#define vxh_alloc_vx_info(v)   do { } while (0)
7921 +#define vxh_dealloc_vx_info(v) do { } while (0)
7922 +
7923 +#define vxh_hash_vx_info(v)    do { } while (0)
7924 +#define vxh_unhash_vx_info(v)  do { } while (0)
7925 +
7926 +#define vxh_loc_vx_info(a,v)   do { } while (0)
7927 +#define vxh_lookup_vx_info(a,v) do { } while (0)
7928 +
7929 +#define vxh_dump_history()     do { } while (0)
7930 +
7931 +
7932 +#endif /* CONFIG_VSERVER_HISTORY */
7933 +
7934 +#endif /* _VX_DEBUG_H */
7935 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/debug_cmd.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/debug_cmd.h
7936 --- linux-2.6.10/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
7937 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/debug_cmd.h   2005-01-02 09:44:49.000000000 +0100
7938 @@ -0,0 +1,14 @@
7939 +#ifndef _VX_DEBUG_CMD_H
7940 +#define _VX_DEBUG_CMD_H
7941 +
7942 +
7943 +/* debug commands */
7944 +
7945 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
7946 +
7947 +#ifdef __KERNEL__
7948 +
7949 +extern int vc_dump_history(uint32_t);
7950 +
7951 +#endif /* __KERNEL__ */
7952 +#endif /* _VX_DEBUG_CMD_H */
7953 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/dlimit.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/dlimit.h
7954 --- linux-2.6.10/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
7955 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/dlimit.h      2004-12-26 19:40:35.000000000 +0100
7956 @@ -0,0 +1,85 @@
7957 +#ifndef _VX_DLIMIT_H
7958 +#define _VX_DLIMIT_H
7959 +
7960 +#include "switch.h"
7961 +#include <linux/spinlock.h>
7962 +
7963 +/*  inode vserver commands */
7964 +
7965 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
7966 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
7967 +
7968 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
7969 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
7970 +
7971 +
7972 +struct vcmd_ctx_dlimit_base_v0 {
7973 +       const char __user *name;
7974 +       uint32_t flags;
7975 +};
7976 +
7977 +struct vcmd_ctx_dlimit_v0 {
7978 +       const char __user *name;
7979 +       uint32_t space_used;                    /* used space in kbytes */
7980 +       uint32_t space_total;                   /* maximum space in kbytes */
7981 +       uint32_t inodes_used;                   /* used inodes */
7982 +       uint32_t inodes_total;                  /* maximum inodes */
7983 +       uint32_t reserved;                      /* reserved for root in % */
7984 +       uint32_t flags;
7985 +};
7986 +
7987 +#define CDLIM_UNSET            (0ULL)
7988 +#define CDLIM_INFINITY         (~0ULL)
7989 +#define CDLIM_KEEP             (~1ULL)
7990 +
7991 +
7992 +#ifdef __KERNEL__
7993 +
7994 +struct super_block;
7995 +
7996 +struct dl_info {
7997 +       struct hlist_node dl_hlist;             /* linked list of contexts */
7998 +       struct rcu_head dl_rcu;                 /* the rcu head */
7999 +       xid_t dl_xid;                           /* context id */
8000 +       atomic_t dl_usecnt;                     /* usage count */
8001 +       atomic_t dl_refcnt;                     /* reference count */
8002 +
8003 +       struct super_block *dl_sb;              /* associated superblock */
8004 +
8005 +//     struct rw_semaphore dl_sem;             /* protect the values */
8006 +       spinlock_t dl_lock;                     /* protect the values */
8007 +
8008 +       uint64_t dl_space_used;                 /* used space in bytes */
8009 +       uint64_t dl_space_total;                /* maximum space in bytes */
8010 +       uint32_t dl_inodes_used;                /* used inodes */
8011 +       uint32_t dl_inodes_total;               /* maximum inodes */
8012 +
8013 +       unsigned int dl_nrlmult;                /* non root limit mult */
8014 +};
8015 +
8016 +struct rcu_head;
8017 +
8018 +extern void rcu_free_dl_info(struct rcu_head *);
8019 +extern void unhash_dl_info(struct dl_info *);
8020 +
8021 +extern struct dl_info *locate_dl_info(struct super_block *, xid_t);
8022 +
8023 +
8024 +struct kstatfs;
8025 +
8026 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
8027 +
8028 +
8029 +extern int vc_add_dlimit(uint32_t, void __user *);
8030 +extern int vc_rem_dlimit(uint32_t, void __user *);
8031 +
8032 +extern int vc_set_dlimit(uint32_t, void __user *);
8033 +extern int vc_get_dlimit(uint32_t, void __user *);
8034 +
8035 +
8036 +typedef uint64_t dlsize_t;
8037 +
8038 +#endif /* __KERNEL__ */
8039 +#else  /* _VX_DLIMIT_H */
8040 +#warning duplicate inclusion
8041 +#endif /* _VX_DLIMIT_H */
8042 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/inode.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/inode.h
8043 --- linux-2.6.10/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
8044 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/inode.h       2004-12-26 19:40:30.000000000 +0100
8045 @@ -0,0 +1,69 @@
8046 +#ifndef _VX_INODE_H
8047 +#define _VX_INODE_H
8048 +
8049 +#include "switch.h"
8050 +
8051 +/*  inode vserver commands */
8052 +
8053 +#define VCMD_get_iattr_v0      VC_CMD(INODE, 1, 0)
8054 +#define VCMD_set_iattr_v0      VC_CMD(INODE, 2, 0)
8055 +
8056 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
8057 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
8058 +
8059 +struct vcmd_ctx_iattr_v0 {
8060 +       /* device handle in id */
8061 +       uint64_t ino;
8062 +       uint32_t xid;
8063 +       uint32_t flags;
8064 +       uint32_t mask;
8065 +};
8066 +
8067 +struct vcmd_ctx_iattr_v1 {
8068 +       const char __user *name;
8069 +       uint32_t xid;
8070 +       uint32_t flags;
8071 +       uint32_t mask;
8072 +};
8073 +
8074 +
8075 +#define IATTR_XID      0x01000000
8076 +
8077 +#define IATTR_ADMIN    0x00000001
8078 +#define IATTR_WATCH    0x00000002
8079 +#define IATTR_HIDE     0x00000004
8080 +#define IATTR_FLAGS    0x00000007
8081 +
8082 +#define IATTR_BARRIER  0x00010000
8083 +#define IATTR_IUNLINK  0x00020000
8084 +#define IATTR_IMMUTABLE 0x00040000
8085 +
8086 +
8087 +#ifdef CONFIG_VSERVER_PROC_SECURE
8088 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
8089 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
8090 +#else
8091 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
8092 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
8093 +#endif
8094 +
8095 +#ifdef __KERNEL__
8096 +
8097 +#define vx_hide_check(c,m)     (((m) & IATTR_HIDE) ? vx_check(c,m) : 1)
8098 +
8099 +extern int vc_get_iattr_v0(uint32_t, void __user *);
8100 +extern int vc_set_iattr_v0(uint32_t, void __user *);
8101 +
8102 +extern int vc_get_iattr(uint32_t, void __user *);
8103 +extern int vc_set_iattr(uint32_t, void __user *);
8104 +
8105 +#endif /* __KERNEL__ */
8106 +
8107 +/* inode ioctls */
8108 +
8109 +#define FIOC_GETXFLG   _IOR('x', 5, long)
8110 +#define FIOC_SETXFLG   _IOW('x', 6, long)
8111 +
8112 +#else  /* _VX_INODE_H */
8113 +#warning duplicate inclusion
8114 +#endif /* _VX_INODE_H */
8115 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/legacy.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/legacy.h
8116 --- linux-2.6.10/include/linux/vserver/legacy.h 1970-01-01 01:00:00.000000000 +0100
8117 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/legacy.h      2004-12-26 19:40:36.000000000 +0100
8118 @@ -0,0 +1,53 @@
8119 +#ifndef _VX_LEGACY_H
8120 +#define _VX_LEGACY_H
8121 +
8122 +#include "switch.h"
8123 +
8124 +/*  compatibiliy vserver commands */
8125 +
8126 +#define VCMD_new_s_context     VC_CMD(COMPAT, 1, 1)
8127 +#define VCMD_set_ipv4root      VC_CMD(COMPAT, 2, 3)
8128 +
8129 +#define VCMD_create_context    VC_CMD(VSETUP, 1, 0)
8130 +
8131 +/*  compatibiliy vserver arguments */
8132 +
8133 +struct vcmd_new_s_context_v1 {
8134 +       uint32_t remove_cap;
8135 +       uint32_t flags;
8136 +};
8137 +
8138 +struct vcmd_set_ipv4root_v3 {
8139 +       /* number of pairs in id */
8140 +       uint32_t broadcast;
8141 +       struct {
8142 +               uint32_t ip;
8143 +               uint32_t mask;
8144 +       } nx_mask_pair[NB_IPV4ROOT];
8145 +};
8146 +
8147 +
8148 +#define VX_INFO_LOCK           1       /* Can't request a new vx_id */
8149 +#define VX_INFO_NPROC          4       /* Limit number of processes in a context */
8150 +#define VX_INFO_PRIVATE                8       /* Noone can join this security context */
8151 +#define VX_INFO_INIT           16      /* This process wants to become the */
8152 +                                       /* logical process 1 of the security */
8153 +                                       /* context */
8154 +#define VX_INFO_HIDEINFO       32      /* Hide some information in /proc */
8155 +#define VX_INFO_ULIMIT         64      /* Use ulimit of the current process */
8156 +                                       /* to become the global limits */
8157 +                                       /* of the context */
8158 +#define VX_INFO_NAMESPACE      128     /* save private namespace */
8159 +
8160 +
8161 +#define NB_S_CONTEXT   16
8162 +
8163 +#define NB_IPV4ROOT    16
8164 +
8165 +
8166 +#ifdef __KERNEL__
8167 +extern int vc_new_s_context(uint32_t, void __user *);
8168 +extern int vc_set_ipv4root(uint32_t, void __user *);
8169 +
8170 +#endif /* __KERNEL__ */
8171 +#endif /* _VX_LEGACY_H */
8172 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/limit.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/limit.h
8173 --- linux-2.6.10/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
8174 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/limit.h       2004-12-26 19:40:35.000000000 +0100
8175 @@ -0,0 +1,20 @@
8176 +#ifndef _VX_LIMIT_H
8177 +#define _VX_LIMIT_H
8178 +
8179 +#ifdef __KERNEL__
8180 +
8181 +struct sysinfo;
8182 +
8183 +void vx_vsi_meminfo(struct sysinfo *);
8184 +void vx_vsi_swapinfo(struct sysinfo *);
8185 +
8186 +#define VXD_RLIMIT(r,l)                (VXD_CBIT(limit, (l)) && ((r) == (l)))
8187 +
8188 +#define NUM_LIMITS     20
8189 +
8190 +#define VLIMIT_NSOCK   16
8191 +
8192 +extern const char *vlimit_name[NUM_LIMITS];
8193 +
8194 +#endif /* __KERNEL__ */
8195 +#endif /* _VX_LIMIT_H */
8196 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/limit_cmd.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/limit_cmd.h
8197 --- linux-2.6.10/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
8198 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/limit_cmd.h   2004-12-26 19:40:36.000000000 +0100
8199 @@ -0,0 +1,36 @@
8200 +#ifndef _VX_LIMIT_CMD_H
8201 +#define _VX_LIMIT_CMD_H
8202 +
8203 +/*  rlimit vserver commands */
8204 +
8205 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
8206 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
8207 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
8208 +
8209 +struct vcmd_ctx_rlimit_v0 {
8210 +       uint32_t id;
8211 +       uint64_t minimum;
8212 +       uint64_t softlimit;
8213 +       uint64_t maximum;
8214 +};
8215 +
8216 +struct vcmd_ctx_rlimit_mask_v0 {
8217 +       uint32_t minimum;
8218 +       uint32_t softlimit;
8219 +       uint32_t maximum;
8220 +};
8221 +
8222 +#define CRLIM_UNSET            (0ULL)
8223 +#define CRLIM_INFINITY         (~0ULL)
8224 +#define CRLIM_KEEP             (~1ULL)
8225 +
8226 +#ifdef __KERNEL__
8227 +
8228 +#include <linux/compiler.h>
8229 +
8230 +extern int vc_get_rlimit(uint32_t, void __user *);
8231 +extern int vc_set_rlimit(uint32_t, void __user *);
8232 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
8233 +
8234 +#endif /* __KERNEL__ */
8235 +#endif /* _VX_LIMIT_CMD_H */
8236 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/limit_def.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/limit_def.h
8237 --- linux-2.6.10/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
8238 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/limit_def.h   2004-12-26 19:40:36.000000000 +0100
8239 @@ -0,0 +1,21 @@
8240 +#ifndef _VX_LIMIT_DEF_H
8241 +#define _VX_LIMIT_DEF_H
8242 +
8243 +#include <asm/atomic.h>
8244 +#include <asm/resource.h>
8245 +
8246 +#include "limit.h"
8247 +
8248 +/* context sub struct */
8249 +
8250 +struct _vx_limit {
8251 +       atomic_t ticks;
8252 +
8253 +       unsigned long rlim[NUM_LIMITS];         /* Context limit */
8254 +       unsigned long rmax[NUM_LIMITS];         /* Context maximum */
8255 +       atomic_t rcur[NUM_LIMITS];              /* Current value */
8256 +       atomic_t lhit[NUM_LIMITS];              /* Limit hits */
8257 +};
8258 +
8259 +
8260 +#endif /* _VX_LIMIT_DEF_H */
8261 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/namespace.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/namespace.h
8262 --- linux-2.6.10/include/linux/vserver/namespace.h      1970-01-01 01:00:00.000000000 +0100
8263 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/namespace.h   2004-12-26 19:40:29.000000000 +0100
8264 @@ -0,0 +1,60 @@
8265 +#ifndef _VX_NAMESPACE_H
8266 +#define _VX_NAMESPACE_H
8267 +
8268 +#include <linux/types.h>
8269 +
8270 +
8271 +/* virtual host info names */
8272 +
8273 +#define VCMD_vx_set_vhi_name   VC_CMD(VHOST, 1, 0)
8274 +#define VCMD_vx_get_vhi_name   VC_CMD(VHOST, 2, 0)
8275 +
8276 +struct vcmd_vx_vhi_name_v0 {
8277 +       uint32_t field;
8278 +       char name[65];
8279 +};
8280 +
8281 +
8282 +enum vx_vhi_name_field {
8283 +       VHIN_CONTEXT=0,
8284 +       VHIN_SYSNAME,
8285 +       VHIN_NODENAME,
8286 +       VHIN_RELEASE,
8287 +       VHIN_VERSION,
8288 +       VHIN_MACHINE,
8289 +       VHIN_DOMAINNAME,
8290 +};
8291 +
8292 +
8293 +#ifdef __KERNEL__
8294 +
8295 +#include <linux/compiler.h>
8296 +
8297 +extern int vc_set_vhi_name(uint32_t, void __user *);
8298 +extern int vc_get_vhi_name(uint32_t, void __user *);
8299 +
8300 +#endif /* __KERNEL__ */
8301 +
8302 +#define VCMD_enter_namespace   VC_CMD(PROCALT, 1, 0)
8303 +#define VCMD_cleanup_namespace VC_CMD(PROCALT, 2, 0)
8304 +#define VCMD_set_namespace     VC_CMD(PROCALT, 3, 0)
8305 +
8306 +#ifdef __KERNEL__
8307 +
8308 +struct vx_info;
8309 +struct namespace;
8310 +struct fs_struct;
8311 +struct vfsmount;
8312 +
8313 +extern int vx_check_vfsmount(struct vx_info *, struct vfsmount *);
8314 +
8315 +extern int vx_set_namespace(struct vx_info *, struct namespace *, struct fs_struct *);
8316 +
8317 +extern int vc_enter_namespace(uint32_t, void __user *);
8318 +extern int vc_cleanup_namespace(uint32_t, void __user *);
8319 +extern int vc_set_namespace(uint32_t, void __user *);
8320 +
8321 +#endif /* __KERNEL__ */
8322 +#else  /* _VX_NAMESPACE_H */
8323 +#warning duplicate inclusion
8324 +#endif /* _VX_NAMESPACE_H */
8325 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/network.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/network.h
8326 --- linux-2.6.10/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
8327 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/network.h     2005-01-02 18:34:28.000000000 +0100
8328 @@ -0,0 +1,73 @@
8329 +#ifndef _VX_NETWORK_H
8330 +#define _VX_NETWORK_H
8331 +
8332 +#include <linux/types.h>
8333 +
8334 +
8335 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
8336 +
8337 +#define NX_DYNAMIC_ID  ((uint32_t)-1)          /* id for dynamic context */
8338 +
8339 +#define NB_IPV4ROOT    16
8340 +
8341 +
8342 +#ifdef __KERNEL__
8343 +
8344 +#include <linux/list.h>
8345 +#include <linux/spinlock.h>
8346 +#include <linux/rcupdate.h>
8347 +#include <asm/atomic.h>
8348 +
8349 +
8350 +struct nx_info {
8351 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
8352 +       struct rcu_head nx_rcu;         /* the rcu head */
8353 +       nid_t nx_id;                    /* vnet id */
8354 +       atomic_t nx_usecnt;             /* usage count */
8355 +       atomic_t nx_refcnt;             /* reference count */
8356 +
8357 +       uint64_t nx_flags;              /* network flag word */
8358 +       uint64_t nx_ncaps;              /* network capabilities */
8359 +
8360 +       int nbipv4;
8361 +       __u32 ipv4[NB_IPV4ROOT];        /* Process can only bind to these IPs */
8362 +                                       /* The first one is used to connect */
8363 +                                       /* and for bind any service */
8364 +                                       /* The other must be used explicity */
8365 +       __u32 mask[NB_IPV4ROOT];        /* Netmask for each ipv4 */
8366 +                                       /* Used to select the proper source */
8367 +                                       /* address for sockets */
8368 +       __u32 v4_bcast;                 /* Broadcast address to receive UDP  */
8369 +
8370 +       char nx_name[65];               /* network context name */
8371 +};
8372 +
8373 +
8374 +struct rcu_head;
8375 +
8376 +extern void unhash_nx_info(struct nx_info *);
8377 +
8378 +extern void free_nx_info(struct nx_info *);
8379 +
8380 +extern struct nx_info *locate_nx_info(int);
8381 +extern struct nx_info *locate_or_create_nx_info(int);
8382 +
8383 +extern int get_nid_list(int, unsigned int *, int);
8384 +extern int nx_info_is_hashed(nid_t);
8385 +
8386 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
8387 +
8388 +struct in_ifaddr;
8389 +struct net_device;
8390 +
8391 +int ifa_in_nx_info(struct in_ifaddr *, struct nx_info *);
8392 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8393 +
8394 +struct sock;
8395 +
8396 +int nx_addr_conflict(struct nx_info *, uint32_t, struct sock *);
8397 +
8398 +#endif /* __KERNEL__ */
8399 +#else  /* _VX_NETWORK_H */
8400 +#warning duplicate inclusion
8401 +#endif /* _VX_NETWORK_H */
8402 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/network_cmd.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/network_cmd.h
8403 --- linux-2.6.10/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
8404 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/network_cmd.h 2004-12-26 19:40:36.000000000 +0100
8405 @@ -0,0 +1,81 @@
8406 +#ifndef _VX_NETWORK_CMD_H
8407 +#define _VX_NETWORK_CMD_H
8408 +
8409 +
8410 +/* vinfo commands */
8411 +
8412 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
8413 +
8414 +#ifdef __KERNEL__
8415 +extern int vc_task_nid(uint32_t, void __user *);
8416 +
8417 +#endif /* __KERNEL__ */
8418 +
8419 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
8420 +
8421 +struct vcmd_nx_info_v0 {
8422 +       uint32_t nid;
8423 +       /* more to come */
8424 +};
8425 +
8426 +#ifdef __KERNEL__
8427 +extern int vc_nx_info(uint32_t, void __user *);
8428 +
8429 +#endif /* __KERNEL__ */
8430 +
8431 +#define VCMD_net_create                VC_CMD(VNET, 1, 0)
8432 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
8433 +
8434 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
8435 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
8436 +
8437 +struct vcmd_net_nx_v0 {
8438 +       uint16_t type;
8439 +       uint16_t count;
8440 +       uint32_t ip[4];
8441 +       uint32_t mask[4];
8442 +       /* more to come */
8443 +};
8444 +
8445 +//     IPN_TYPE_IPV4
8446 +
8447 +
8448 +#ifdef __KERNEL__
8449 +extern int vc_net_create(uint32_t, void __user *);
8450 +extern int vc_net_migrate(uint32_t, void __user *);
8451 +
8452 +#endif /* __KERNEL__ */
8453 +
8454 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
8455 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
8456 +
8457 +struct vcmd_net_flags_v0 {
8458 +       uint64_t flagword;
8459 +       uint64_t mask;
8460 +};
8461 +
8462 +#ifdef __KERNEL__
8463 +extern int vc_get_nflags(uint32_t, void __user *);
8464 +extern int vc_set_nflags(uint32_t, void __user *);
8465 +
8466 +#endif /* __KERNEL__ */
8467 +
8468 +#define IPF_STATE_SETUP                (1ULL<<32)
8469 +
8470 +
8471 +#define IPF_ONE_TIME           (0x0001ULL<<32)
8472 +
8473 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
8474 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
8475 +
8476 +struct vcmd_net_caps_v0 {
8477 +       uint64_t ncaps;
8478 +       uint64_t cmask;
8479 +};
8480 +
8481 +#ifdef __KERNEL__
8482 +extern int vc_get_ncaps(uint32_t, void __user *);
8483 +extern int vc_set_ncaps(uint32_t, void __user *);
8484 +
8485 +#endif /* __KERNEL__ */
8486 +#endif /* _VX_CONTEXT_CMD_H */
8487 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/sched.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/sched.h
8488 --- linux-2.6.10/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
8489 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/sched.h       2004-12-26 19:40:30.000000000 +0100
8490 @@ -0,0 +1,25 @@
8491 +#ifndef _VX_SCHED_H
8492 +#define _VX_SCHED_H
8493 +
8494 +#ifdef __KERNEL__
8495 +
8496 +struct timespec;
8497 +
8498 +void vx_vsi_uptime(struct timespec *, struct timespec *);
8499 +
8500 +
8501 +struct vx_info;
8502 +
8503 +void vx_update_load(struct vx_info *);
8504 +
8505 +
8506 +struct task_struct;
8507 +
8508 +int effective_vavavoom(struct task_struct *, int);
8509 +
8510 +int vx_tokens_recalc(struct vx_info *);
8511 +
8512 +#endif /* __KERNEL__ */
8513 +#else  /* _VX_SCHED_H */
8514 +#warning duplicate inclusion
8515 +#endif /* _VX_SCHED_H */
8516 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/sched_cmd.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/sched_cmd.h
8517 --- linux-2.6.10/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
8518 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/sched_cmd.h   2004-12-26 19:40:36.000000000 +0100
8519 @@ -0,0 +1,47 @@
8520 +#ifndef _VX_SCHED_CMD_H
8521 +#define _VX_SCHED_CMD_H
8522 +
8523 +/*  sched vserver commands */
8524 +
8525 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
8526 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 3)
8527 +
8528 +struct vcmd_set_sched_v2 {
8529 +       int32_t fill_rate;
8530 +       int32_t interval;
8531 +       int32_t tokens;
8532 +       int32_t tokens_min;
8533 +       int32_t tokens_max;
8534 +       uint64_t cpu_mask;
8535 +};
8536 +
8537 +struct vcmd_set_sched_v3 {
8538 +       uint32_t set_mask;
8539 +       int32_t fill_rate;
8540 +       int32_t interval;
8541 +       int32_t tokens;
8542 +       int32_t tokens_min;
8543 +       int32_t tokens_max;
8544 +       int32_t priority_bias;
8545 +};
8546 +
8547 +
8548 +#define VXSM_FILL_RATE         0x0001
8549 +#define VXSM_INTERVAL          0x0002
8550 +#define VXSM_TOKENS            0x0010
8551 +#define VXSM_TOKENS_MIN                0x0020
8552 +#define VXSM_TOKENS_MAX                0x0040
8553 +#define VXSM_PRIO_BIAS         0x0100
8554 +
8555 +#define SCHED_KEEP             (-2)
8556 +
8557 +#ifdef __KERNEL__
8558 +
8559 +#include <linux/compiler.h>
8560 +
8561 +extern int vc_set_sched_v1(uint32_t, void __user *);
8562 +extern int vc_set_sched_v2(uint32_t, void __user *);
8563 +extern int vc_set_sched(uint32_t, void __user *);
8564 +
8565 +#endif /* __KERNEL__ */
8566 +#endif /* _VX_SCHED_CMD_H */
8567 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/sched_def.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/sched_def.h
8568 --- linux-2.6.10/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
8569 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/sched_def.h   2004-12-26 19:40:36.000000000 +0100
8570 @@ -0,0 +1,36 @@
8571 +#ifndef _VX_SCHED_DEF_H
8572 +#define _VX_SCHED_DEF_H
8573 +
8574 +#include <linux/spinlock.h>
8575 +#include <linux/jiffies.h>
8576 +#include <linux/cpumask.h>
8577 +#include <asm/atomic.h>
8578 +#include <asm/param.h>
8579 +
8580 +
8581 +struct _vx_ticks {
8582 +       uint64_t user_ticks;            /* token tick events */
8583 +       uint64_t sys_ticks;             /* token tick events */
8584 +       uint64_t hold_ticks;            /* token ticks paused */
8585 +       uint64_t unused[5];             /* cacheline ? */
8586 +};
8587 +
8588 +/* context sub struct */
8589 +
8590 +struct _vx_sched {
8591 +       atomic_t tokens;                /* number of CPU tokens */
8592 +       spinlock_t tokens_lock;         /* lock for token bucket */
8593 +
8594 +       int fill_rate;                  /* Fill rate: add X tokens... */
8595 +       int interval;                   /* Divisor:   per Y jiffies   */
8596 +       int tokens_min;                 /* Limit:     minimum for unhold */
8597 +       int tokens_max;                 /* Limit:     no more than N tokens */
8598 +       uint32_t jiffies;               /* last time accounted */
8599 +
8600 +       int priority_bias;              /* bias offset for priority */
8601 +       cpumask_t cpus_allowed;         /* cpu mask for context */
8602 +
8603 +       struct _vx_ticks cpu[NR_CPUS];
8604 +};
8605 +
8606 +#endif /* _VX_SCHED_DEF_H */
8607 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/signal.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/signal.h
8608 --- linux-2.6.10/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
8609 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/signal.h      2004-12-26 19:40:30.000000000 +0100
8610 @@ -0,0 +1,27 @@
8611 +#ifndef _VX_SIGNAL_H
8612 +#define _VX_SIGNAL_H
8613 +
8614 +#include "switch.h"
8615 +
8616 +/*  context signalling */
8617 +
8618 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
8619 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
8620 +
8621 +struct vcmd_ctx_kill_v0 {
8622 +       int32_t pid;
8623 +       int32_t sig;
8624 +};
8625 +
8626 +struct vcmd_wait_exit_v0 {
8627 +       int32_t a;
8628 +       int32_t b;
8629 +};
8630 +
8631 +#ifdef __KERNEL__
8632 +
8633 +extern int vc_ctx_kill(uint32_t, void __user *);
8634 +extern int vc_wait_exit(uint32_t, void __user *);
8635 +
8636 +#endif /* __KERNEL__ */
8637 +#endif /* _VX_SIGNAL_H */
8638 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/switch.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/switch.h
8639 --- linux-2.6.10/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
8640 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/switch.h      2005-01-02 09:44:49.000000000 +0100
8641 @@ -0,0 +1,97 @@
8642 +#ifndef _VX_SWITCH_H
8643 +#define _VX_SWITCH_H
8644 +
8645 +#include <linux/types.h>
8646 +
8647 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
8648 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
8649 +#define VC_VERSION(c)          ((c) & 0xFFF)
8650 +
8651 +#define VC_CMD(c,i,v)          ((((VC_CAT_ ## c) & 0x3F) << 24) \
8652 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
8653 +
8654 +/*
8655 +
8656 +  Syscall Matrix V2.8
8657 +
8658 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
8659 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
8660 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
8661 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
8662 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICES|       |
8663 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
8664 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
8665 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
8666 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
8667 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
8668 +  MEMORY |       |       |       |       |       |       | |SWAP   |       |
8669 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
8670 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
8671 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
8672 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
8673 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
8674 +  DISK   |       |       |       |       |DLIMIT |       | |INODE  |       |
8675 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
8676 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
8677 +  OTHER  |       |       |       |       |       |       | |VINFO  |       |
8678 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
8679 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
8680 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |       |       |
8681 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
8682 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
8683 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
8684 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
8685 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
8686 +
8687 +*/
8688 +
8689 +#define VC_CAT_VERSION         0
8690 +
8691 +#define VC_CAT_VSETUP          1
8692 +#define VC_CAT_VHOST           2
8693 +
8694 +#define VC_CAT_VPROC           9
8695 +#define VC_CAT_PROCALT         10
8696 +#define VC_CAT_PROCMIG         11
8697 +#define VC_CAT_PROCTRL         12
8698 +
8699 +#define VC_CAT_SCHED           14
8700 +
8701 +#define VC_CAT_VNET            25
8702 +#define VC_CAT_NETALT          26
8703 +#define VC_CAT_NETMIG          27
8704 +#define VC_CAT_NETCTRL         28
8705 +
8706 +#define VC_CAT_DLIMIT          36
8707 +#define VC_CAT_INODE           38
8708 +
8709 +#define VC_CAT_VINFO           46
8710 +#define VC_CAT_EVENT           48
8711 +
8712 +#define VC_CAT_FLAGS           52
8713 +#define VC_CAT_DEBUG           56
8714 +#define VC_CAT_RLIMIT          60
8715 +
8716 +#define VC_CAT_SYSTEST         61
8717 +#define VC_CAT_COMPAT          63
8718 +
8719 +/*  interface version */
8720 +
8721 +#define VCI_VERSION            0x00010025
8722 +
8723 +
8724 +/*  query version */
8725 +
8726 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
8727 +
8728 +
8729 +#ifdef __KERNEL__
8730 +
8731 +#include <linux/errno.h>
8732 +
8733 +
8734 +#else  /* __KERNEL__ */
8735 +#define __user
8736 +#endif /* __KERNEL__ */
8737 +
8738 +#endif /* _VX_SWITCH_H */
8739 diff -NurpP --minimal linux-2.6.10/include/linux/vserver/xid.h linux-2.6.10-vs1.9.3.17/include/linux/vserver/xid.h
8740 --- linux-2.6.10/include/linux/vserver/xid.h    1970-01-01 01:00:00.000000000 +0100
8741 +++ linux-2.6.10-vs1.9.3.17/include/linux/vserver/xid.h 2004-12-26 19:40:34.000000000 +0100
8742 @@ -0,0 +1,126 @@
8743 +#ifndef _VX_XID_H
8744 +#define _VX_XID_H
8745 +
8746 +
8747 +#define XID_TAG(in)    (!(in) || \
8748 +       (((struct inode *)in)->i_sb && \
8749 +       (((struct inode *)in)->i_sb->s_flags & MS_TAGXID)))
8750 +
8751 +
8752 +#ifdef CONFIG_INOXID_NONE
8753 +
8754 +#define MAX_UID                0xFFFFFFFF
8755 +#define MAX_GID                0xFFFFFFFF
8756 +
8757 +#define INOXID_XID(tag, uid, gid, xid) (0)
8758 +
8759 +#define XIDINO_UID(tag, uid, xid)      (uid)
8760 +#define XIDINO_GID(tag, gid, xid)      (gid)
8761 +
8762 +#endif
8763 +
8764 +
8765 +#ifdef CONFIG_INOXID_GID16
8766 +
8767 +#define MAX_UID                0xFFFFFFFF
8768 +#define MAX_GID                0x0000FFFF
8769 +
8770 +#define INOXID_XID(tag, uid, gid, xid) \
8771 +       ((tag) ? (((gid) >> 16) & 0xFFFF) : 0)
8772 +
8773 +#define XIDINO_UID(tag, uid, xid)      (uid)
8774 +#define XIDINO_GID(tag, gid, xid)      \
8775 +       ((tag) ? (((gid) & 0xFFFF) | ((xid) << 16)) : (gid))
8776 +
8777 +#endif
8778 +
8779 +
8780 +#ifdef CONFIG_INOXID_UGID24
8781 +
8782 +#define MAX_UID                0x00FFFFFF
8783 +#define MAX_GID                0x00FFFFFF
8784 +
8785 +#define INOXID_XID(tag, uid, gid, xid) \
8786 +       ((tag) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
8787 +
8788 +#define XIDINO_UID(tag, uid, xid)      \
8789 +       ((tag) ? (((uid) & 0xFFFFFF) | (((xid) & 0xFF00) << 16)) : (uid))
8790 +#define XIDINO_GID(tag, gid, xid)      \
8791 +       ((tag) ? (((gid) & 0xFFFFFF) | (((xid) & 0x00FF) << 24)) : (gid))
8792 +
8793 +#endif
8794 +
8795 +
8796 +#ifdef CONFIG_INOXID_UID16
8797 +
8798 +#define MAX_UID                0x0000FFFF
8799 +#define MAX_GID                0xFFFFFFFF
8800 +
8801 +#define INOXID_XID(tag, uid, gid, xid) \
8802 +       ((tag) ? ((uid) >> 16) & 0xFFFF) : 0)
8803 +
8804 +#define XIDINO_UID(tag, uid, xid)      \
8805 +       ((tag) ? (((uid) & 0xFFFF) | ((xid) << 16)) : (uid))
8806 +#define XIDINO_GID(tag, gid, xid)      (gid)
8807 +
8808 +#endif
8809 +
8810 +
8811 +#ifdef CONFIG_INOXID_INTERN
8812 +
8813 +#define MAX_UID                0xFFFFFFFF
8814 +#define MAX_GID                0xFFFFFFFF
8815 +
8816 +#define INOXID_XID(tag, uid, gid, xid) \
8817 +       ((tag) ? (xid) : 0)
8818 +
8819 +#define XIDINO_UID(tag, uid, xid)      (uid)
8820 +#define XIDINO_GID(tag, gid, xid)      (gid)
8821 +
8822 +#endif
8823 +
8824 +
8825 +#ifdef CONFIG_INOXID_RUNTIME
8826 +
8827 +#define MAX_UID                0xFFFFFFFF
8828 +#define MAX_GID                0xFFFFFFFF
8829 +
8830 +#define INOXID_XID(tag, uid, gid, xid) (0)
8831 +
8832 +#define XIDINO_UID(tag, uid, xid)      (uid)
8833 +#define XIDINO_GID(tag, gid, xid)      (gid)
8834 +
8835 +#endif
8836 +
8837 +
8838 +#define INOXID_UID(tag, uid, gid)      \
8839 +       ((tag) ? ((uid) & MAX_UID) : (uid))
8840 +#define INOXID_GID(tag, uid, gid)      \
8841 +       ((tag) ? ((gid) & MAX_GID) : (gid))
8842 +
8843 +
8844 +static inline uid_t vx_map_uid(uid_t uid)
8845 +{
8846 +       if ((uid > MAX_UID) && (uid != -1))
8847 +               uid = -2;
8848 +       return (uid & MAX_UID);
8849 +}
8850 +
8851 +static inline gid_t vx_map_gid(gid_t gid)
8852 +{
8853 +       if ((gid > MAX_GID) && (gid != -1))
8854 +               gid = -2;
8855 +       return (gid & MAX_GID);
8856 +}
8857 +
8858 +
8859 +#ifdef CONFIG_VSERVER_LEGACY
8860 +#define FIOC_GETXID    _IOR('x', 1, long)
8861 +#define FIOC_SETXID    _IOW('x', 2, long)
8862 +#define FIOC_SETXIDJ   _IOW('x', 3, long)
8863 +#endif
8864 +
8865 +int vx_parse_xid(char *string, xid_t *xid, int remove);
8866 +void vx_propagate_xid(struct nameidata *nd, struct inode *inode);
8867 +
8868 +#endif /* _VX_XID_H */
8869 diff -NurpP --minimal linux-2.6.10/include/net/af_unix.h linux-2.6.10-vs1.9.3.17/include/net/af_unix.h
8870 --- linux-2.6.10/include/net/af_unix.h  2004-10-23 05:06:24.000000000 +0200
8871 +++ linux-2.6.10-vs1.9.3.17/include/net/af_unix.h       2004-12-26 19:40:29.000000000 +0100
8872 @@ -11,9 +11,9 @@ extern rwlock_t unix_table_lock;
8873  
8874  extern atomic_t unix_tot_inflight;
8875  
8876 -static inline struct sock *first_unix_socket(int *i)
8877 +static inline struct sock *next_unix_socket_table(int *i)
8878  {
8879 -       for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
8880 +       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
8881                 if (!hlist_empty(&unix_socket_table[*i]))
8882                         return __sk_head(&unix_socket_table[*i]);
8883         }
8884 @@ -22,16 +22,19 @@ static inline struct sock *first_unix_so
8885  
8886  static inline struct sock *next_unix_socket(int *i, struct sock *s)
8887  {
8888 -       struct sock *next = sk_next(s);
8889 -       /* More in this chain? */
8890 -       if (next)
8891 -               return next;
8892 -       /* Look for next non-empty chain. */
8893 -       for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
8894 -               if (!hlist_empty(&unix_socket_table[*i]))
8895 -                       return __sk_head(&unix_socket_table[*i]);
8896 -       }
8897 -       return NULL;
8898 +       do {
8899 +               if (s)
8900 +                       s = sk_next(s);
8901 +               if (!s)
8902 +                       s = next_unix_socket_table(i);
8903 +       } while (s && !vx_check(s->sk_xid, VX_IDENT|VX_WATCH));
8904 +       return s;
8905 +}
8906 +
8907 +static inline struct sock *first_unix_socket(int *i)
8908 +{
8909 +       *i = 0;
8910 +       return next_unix_socket(i, NULL);
8911  }
8912  
8913  #define forall_unix_sockets(i, s) \
8914 diff -NurpP --minimal linux-2.6.10/include/net/lapb.h linux-2.6.10-vs1.9.3.17/include/net/lapb.h
8915 --- linux-2.6.10/include/net/lapb.h     2004-08-14 12:56:22.000000000 +0200
8916 +++ linux-2.6.10-vs1.9.3.17/include/net/lapb.h  2004-12-26 19:40:36.000000000 +0100
8917 @@ -57,7 +57,11 @@ enum {
8918  
8919  #define        LAPB_DEFAULT_MODE               (LAPB_STANDARD | LAPB_SLP | LAPB_DTE)
8920  #define        LAPB_DEFAULT_WINDOW             7               /* Window=7 */
8921 +#if HZ < 2185
8922  #define        LAPB_DEFAULT_T1                 (5 * HZ)        /* T1=5s    */
8923 +#else
8924 +#define        LAPB_DEFAULT_T1                 (65534)         /* T1=max   */
8925 +#endif
8926  #define        LAPB_DEFAULT_T2                 (1 * HZ)        /* T2=1s    */
8927  #define        LAPB_DEFAULT_N2                 20              /* N2=20    */
8928  
8929 diff -NurpP --minimal linux-2.6.10/include/net/route.h linux-2.6.10-vs1.9.3.17/include/net/route.h
8930 --- linux-2.6.10/include/net/route.h    2004-10-23 05:06:24.000000000 +0200
8931 +++ linux-2.6.10-vs1.9.3.17/include/net/route.h 2004-12-26 19:40:29.000000000 +0100
8932 @@ -33,6 +33,8 @@
8933  #include <linux/route.h>
8934  #include <linux/ip.h>
8935  #include <linux/cache.h>
8936 +#include <linux/vs_context.h>
8937 +#include <linux/vs_network.h>
8938  
8939  #ifndef __KERNEL__
8940  #warning This file is not supposed to be used outside of kernel.
8941 @@ -143,6 +145,59 @@ static inline char rt_tos2priority(u8 to
8942         return ip_tos2prio[IPTOS_TOS(tos)>>1];
8943  }
8944  
8945 +#define IPI_LOOPBACK   0x0100007f
8946 +
8947 +static inline int ip_find_src(struct nx_info *nxi, struct rtable **rp, struct flowi *fl)
8948 +{
8949 +       int err;
8950 +       int i, n = nxi->nbipv4;
8951 +       u32 ipv4root = nxi->ipv4[0];
8952 +
8953 +       if (ipv4root == 0)
8954 +               return 0;
8955 +
8956 +       if (fl->fl4_src == 0) {
8957 +               if (n > 1) {
8958 +                       u32 foundsrc;
8959 +
8960 +                       err = __ip_route_output_key(rp, fl);
8961 +                       if (err) {
8962 +                               fl->fl4_src = ipv4root;
8963 +                               err = __ip_route_output_key(rp, fl);
8964 +                       }
8965 +                       if (err)
8966 +                               return err;
8967 +
8968 +                       foundsrc = (*rp)->rt_src;
8969 +                       ip_rt_put(*rp);
8970 +
8971 +                       for (i=0; i<n; i++){
8972 +                               u32 mask = nxi->mask[i];
8973 +                               u32 ipv4 = nxi->ipv4[i];
8974 +                               u32 net4 = ipv4 & mask;
8975 +
8976 +                               if (foundsrc == ipv4) {
8977 +                                       fl->fl4_src = ipv4;
8978 +                                       break;
8979 +                               }
8980 +                               if (!fl->fl4_src && (foundsrc & mask) == net4)
8981 +                                       fl->fl4_src = ipv4;
8982 +                       }
8983 +               }
8984 +               if (fl->fl4_src == 0)
8985 +                       fl->fl4_src = (fl->fl4_dst == IPI_LOOPBACK)
8986 +                               ? IPI_LOOPBACK : ipv4root;
8987 +       } else {
8988 +               for (i=0; i<n; i++) {
8989 +                       if (nxi->ipv4[i] == fl->fl4_src)
8990 +                               break;
8991 +               }
8992 +               if (i == n)
8993 +                       return -EPERM;
8994 +       }
8995 +       return 0;
8996 +}
8997 +
8998  static inline int ip_route_connect(struct rtable **rp, u32 dst,
8999                                    u32 src, u32 tos, int oif, u8 protocol,
9000                                    u16 sport, u16 dport, struct sock *sk)
9001 @@ -157,7 +212,23 @@ static inline int ip_route_connect(struc
9002                                          .dport = dport } } };
9003  
9004         int err;
9005 -       if (!dst || !src) {
9006 +       struct nx_info *nx_info = current->nx_info;
9007 +
9008 +       if (sk)
9009 +               nx_info = sk->sk_nx_info;
9010 +       vxdprintk(VXD_CBIT(net, 4),
9011 +               "ip_route_connect(%p) %p,%p;%lx",
9012 +               sk, nx_info, sk->sk_socket,
9013 +               (sk->sk_socket?sk->sk_socket->flags:0));
9014 +
9015 +       if (nx_info) {
9016 +               err = ip_find_src(nx_info, rp, &fl);
9017 +               if (err)
9018 +                       return err;
9019 +               if (fl.fl4_dst == IPI_LOOPBACK && !vx_check(0, VX_ADMIN))
9020 +                       fl.fl4_dst = nx_info->ipv4[0];
9021 +       }
9022 +       if (!fl.fl4_dst || !fl.fl4_src) {
9023                 err = __ip_route_output_key(rp, &fl);
9024                 if (err)
9025                         return err;
9026 diff -NurpP --minimal linux-2.6.10/include/net/scm.h linux-2.6.10-vs1.9.3.17/include/net/scm.h
9027 --- linux-2.6.10/include/net/scm.h      2004-08-14 12:55:32.000000000 +0200
9028 +++ linux-2.6.10-vs1.9.3.17/include/net/scm.h   2004-12-26 19:40:29.000000000 +0100
9029 @@ -51,13 +51,13 @@ static __inline__ void scm_recv(struct s
9030  {
9031         if (!msg->msg_control)
9032         {
9033 -               if (sock->passcred || scm->fp)
9034 +               if (test_bit(SOCK_PASS_CRED, &sock->flags) || scm->fp)
9035                         msg->msg_flags |= MSG_CTRUNC;
9036                 scm_destroy(scm);
9037                 return;
9038         }
9039  
9040 -       if (sock->passcred)
9041 +       if (test_bit(SOCK_PASS_CRED, &sock->flags))
9042                 put_cmsg(msg, SOL_SOCKET, SCM_CREDENTIALS, sizeof(scm->creds), &scm->creds);
9043  
9044         if (!scm->fp)
9045 diff -NurpP --minimal linux-2.6.10/include/net/sock.h linux-2.6.10-vs1.9.3.17/include/net/sock.h
9046 --- linux-2.6.10/include/net/sock.h     2004-12-25 01:55:30.000000000 +0100
9047 +++ linux-2.6.10-vs1.9.3.17/include/net/sock.h  2004-12-26 19:40:29.000000000 +0100
9048 @@ -110,6 +110,10 @@ struct sock_common {
9049         struct hlist_node       skc_node;
9050         struct hlist_node       skc_bind_node;
9051         atomic_t                skc_refcnt;
9052 +       xid_t                   skc_xid;
9053 +       struct vx_info          *skc_vx_info;
9054 +       nid_t                   skc_nid;
9055 +       struct nx_info          *skc_nx_info;
9056  };
9057  
9058  /**
9059 @@ -191,6 +195,10 @@ struct sock {
9060  #define sk_node                        __sk_common.skc_node
9061  #define sk_bind_node           __sk_common.skc_bind_node
9062  #define sk_refcnt              __sk_common.skc_refcnt
9063 +#define sk_xid                 __sk_common.skc_xid
9064 +#define sk_vx_info             __sk_common.skc_vx_info
9065 +#define sk_nid                 __sk_common.skc_nid
9066 +#define sk_nx_info             __sk_common.skc_nx_info
9067         volatile unsigned char  sk_zapped;
9068         unsigned char           sk_shutdown;
9069         unsigned char           sk_use_write_queue;
9070 diff -NurpP --minimal linux-2.6.10/include/net/tcp.h linux-2.6.10-vs1.9.3.17/include/net/tcp.h
9071 --- linux-2.6.10/include/net/tcp.h      2004-12-25 01:55:30.000000000 +0100
9072 +++ linux-2.6.10-vs1.9.3.17/include/net/tcp.h   2004-12-26 19:40:36.000000000 +0100
9073 @@ -192,6 +192,10 @@ struct tcp_tw_bucket {
9074  #define tw_node                        __tw_common.skc_node
9075  #define tw_bind_node           __tw_common.skc_bind_node
9076  #define tw_refcnt              __tw_common.skc_refcnt
9077 +#define tw_xid                 __tw_common.skc_xid
9078 +#define tw_vx_info             __tw_common.skc_vx_info
9079 +#define tw_nid                 __tw_common.skc_nid
9080 +#define tw_nx_info             __tw_common.skc_nx_info
9081         volatile unsigned char  tw_substate;
9082         unsigned char           tw_rcv_wscale;
9083         __u16                   tw_sport;
9084 @@ -486,8 +490,8 @@ static __inline__ int tcp_sk_listen_hash
9085     so that we select tick to get range about 4 seconds.
9086   */
9087  
9088 -#if HZ <= 16 || HZ > 4096
9089 -# error Unsupported: HZ <= 16 or HZ > 4096
9090 +#if HZ <= 16 || HZ > 32768
9091 +# error Unsupported: HZ <= 16 or HZ > 32768
9092  #elif HZ <= 32
9093  # define TCP_TW_RECYCLE_TICK (5+2-TCP_TW_RECYCLE_SLOTS_LOG)
9094  #elif HZ <= 64
9095 @@ -502,8 +506,14 @@ static __inline__ int tcp_sk_listen_hash
9096  # define TCP_TW_RECYCLE_TICK (10+2-TCP_TW_RECYCLE_SLOTS_LOG)
9097  #elif HZ <= 2048
9098  # define TCP_TW_RECYCLE_TICK (11+2-TCP_TW_RECYCLE_SLOTS_LOG)
9099 -#else
9100 +#elif HZ <= 4096
9101  # define TCP_TW_RECYCLE_TICK (12+2-TCP_TW_RECYCLE_SLOTS_LOG)
9102 +#elif HZ <= 8192
9103 +# define TCP_TW_RECYCLE_TICK (13+2-TCP_TW_RECYCLE_SLOTS_LOG)
9104 +#elif HZ <= 16384
9105 +# define TCP_TW_RECYCLE_TICK (14+2-TCP_TW_RECYCLE_SLOTS_LOG)
9106 +#else
9107 +# define TCP_TW_RECYCLE_TICK (15+2-TCP_TW_RECYCLE_SLOTS_LOG)
9108  #endif
9109  
9110  #define BICTCP_1_OVER_BETA     8       /*
9111 diff -NurpP --minimal linux-2.6.10/init/main.c linux-2.6.10-vs1.9.3.17/init/main.c
9112 --- linux-2.6.10/init/main.c    2004-12-25 01:55:30.000000000 +0100
9113 +++ linux-2.6.10-vs1.9.3.17/init/main.c 2004-12-26 19:40:36.000000000 +0100
9114 @@ -216,8 +216,8 @@ void __devinit calibrate_delay(void)
9115                 loops_per_jiffy = preset_lpj;
9116                 printk("Calibrating delay loop (skipped)... "
9117                         "%lu.%02lu BogoMIPS preset\n",
9118 -                       loops_per_jiffy/(500000/HZ),
9119 -                       (loops_per_jiffy/(5000/HZ)) % 100);
9120 +                       HZ*(loops_per_jiffy >> 3)/62500,
9121 +                       (HZ*(loops_per_jiffy >> 3)/625) % 100);
9122         } else {
9123                 loops_per_jiffy = (1<<12);
9124  
9125 @@ -254,8 +254,8 @@ void __devinit calibrate_delay(void)
9126  
9127                 /* Round the value and print it */
9128                 printk("%lu.%02lu BogoMIPS (lpj=%lu)\n",
9129 -                       loops_per_jiffy/(500000/HZ),
9130 -                       (loops_per_jiffy/(5000/HZ)) % 100,
9131 +                       HZ*(loops_per_jiffy >> 3)/62500,
9132 +                       (HZ*(loops_per_jiffy >> 3)/625) % 100,
9133                         loops_per_jiffy);
9134         }
9135  
9136 diff -NurpP --minimal linux-2.6.10/ipc/msg.c linux-2.6.10-vs1.9.3.17/ipc/msg.c
9137 --- linux-2.6.10/ipc/msg.c      2004-12-25 01:55:30.000000000 +0100
9138 +++ linux-2.6.10-vs1.9.3.17/ipc/msg.c   2004-12-26 19:40:29.000000000 +0100
9139 @@ -97,6 +97,7 @@ static int newque (key_t key, int msgflg
9140  
9141         msq->q_perm.mode = (msgflg & S_IRWXUGO);
9142         msq->q_perm.key = key;
9143 +       msq->q_perm.xid = vx_current_xid();
9144  
9145         msq->q_perm.security = NULL;
9146         retval = security_msg_queue_alloc(msq);
9147 @@ -817,7 +818,11 @@ static int sysvipc_msg_read_proc(char *b
9148         for(i = 0; i <= msg_ids.max_id; i++) {
9149                 struct msg_queue * msq;
9150                 msq = msg_lock(i);
9151 -               if(msq != NULL) {
9152 +               if (msq) {
9153 +                       if (!vx_check(msq->q_perm.xid, VX_IDENT)) {
9154 +                               msg_unlock(msq);
9155 +                               continue;
9156 +                       }
9157                         len += sprintf(buffer + len, "%10d %10d  %4o  %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n",
9158                                 msq->q_perm.key,
9159                                 msg_buildid(i,msq->q_perm.seq),
9160 diff -NurpP --minimal linux-2.6.10/ipc/sem.c linux-2.6.10-vs1.9.3.17/ipc/sem.c
9161 --- linux-2.6.10/ipc/sem.c      2004-12-25 01:55:30.000000000 +0100
9162 +++ linux-2.6.10-vs1.9.3.17/ipc/sem.c   2004-12-26 19:40:29.000000000 +0100
9163 @@ -176,6 +176,7 @@ static int newary (key_t key, int nsems,
9164  
9165         sma->sem_perm.mode = (semflg & S_IRWXUGO);
9166         sma->sem_perm.key = key;
9167 +       sma->sem_perm.xid = vx_current_xid();
9168  
9169         sma->sem_perm.security = NULL;
9170         retval = security_sem_alloc(sma);
9171 @@ -1329,7 +1330,11 @@ static int sysvipc_sem_read_proc(char *b
9172         for(i = 0; i <= sem_ids.max_id; i++) {
9173                 struct sem_array *sma;
9174                 sma = sem_lock(i);
9175 -               if(sma) {
9176 +               if (sma) {
9177 +                       if (!vx_check(sma->sem_perm.xid, VX_IDENT)) {
9178 +                               sem_unlock(sma);
9179 +                               continue;
9180 +                       }
9181                         len += sprintf(buffer + len, "%10d %10d  %4o %10lu %5u %5u %5u %5u %10lu %10lu\n",
9182                                 sma->sem_perm.key,
9183                                 sem_buildid(i,sma->sem_perm.seq),
9184 diff -NurpP --minimal linux-2.6.10/ipc/shm.c linux-2.6.10-vs1.9.3.17/ipc/shm.c
9185 --- linux-2.6.10/ipc/shm.c      2004-12-25 01:55:30.000000000 +0100
9186 +++ linux-2.6.10-vs1.9.3.17/ipc/shm.c   2004-12-26 19:40:29.000000000 +0100
9187 @@ -193,6 +193,7 @@ static int newseg (key_t key, int shmflg
9188                 return -ENOMEM;
9189  
9190         shp->shm_perm.key = key;
9191 +       shp->shm_perm.xid = vx_current_xid();
9192         shp->shm_flags = (shmflg & S_IRWXUGO);
9193         shp->mlock_user = NULL;
9194  
9195 @@ -865,11 +866,15 @@ static int sysvipc_shm_read_proc(char *b
9196                 struct shmid_kernel* shp;
9197  
9198                 shp = shm_lock(i);
9199 -               if(shp!=NULL) {
9200 +               if (shp) {
9201  #define SMALL_STRING "%10d %10d  %4o %10u %5u %5u  %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
9202  #define BIG_STRING   "%10d %10d  %4o %21u %5u %5u  %5d %5u %5u %5u %5u %10lu %10lu %10lu\n"
9203                         char *format;
9204  
9205 +                       if (!vx_check(shp->shm_perm.xid, VX_IDENT)) {
9206 +                               shm_unlock(shp);
9207 +                               continue;
9208 +                       }
9209                         if (sizeof(size_t) <= sizeof(int))
9210                                 format = SMALL_STRING;
9211                         else
9212 diff -NurpP --minimal linux-2.6.10/ipc/util.c linux-2.6.10-vs1.9.3.17/ipc/util.c
9213 --- linux-2.6.10/ipc/util.c     2004-12-25 01:55:30.000000000 +0100
9214 +++ linux-2.6.10-vs1.9.3.17/ipc/util.c  2004-12-26 19:40:29.000000000 +0100
9215 @@ -107,7 +107,9 @@ int ipc_findkey(struct ipc_ids* ids, key
9216          */
9217         for (id = 0; id <= max_id; id++) {
9218                 p = ids->entries->p[id];
9219 -               if(p==NULL)
9220 +               if (p==NULL)
9221 +                       continue;
9222 +               if (!vx_check(p->xid, VX_IDENT))
9223                         continue;
9224                 if (key == p->key)
9225                         return id;
9226 @@ -420,6 +422,8 @@ int ipcperms (struct kern_ipc_perm *ipcp
9227  {      /* flag will most probably be 0 or S_...UGO from <linux/stat.h> */
9228         int requested_mode, granted_mode;
9229  
9230 +       if (!vx_check(ipcp->xid, VX_ADMIN|VX_IDENT)) /* maybe just VX_IDENT? */
9231 +               return -1;
9232         requested_mode = (flag >> 6) | (flag >> 3) | flag;
9233         granted_mode = ipcp->mode;
9234         if (current->euid == ipcp->cuid || current->euid == ipcp->uid)
9235 diff -NurpP --minimal linux-2.6.10/kernel/Makefile linux-2.6.10-vs1.9.3.17/kernel/Makefile
9236 --- linux-2.6.10/kernel/Makefile        2004-12-25 01:55:30.000000000 +0100
9237 +++ linux-2.6.10-vs1.9.3.17/kernel/Makefile     2004-12-26 19:40:23.000000000 +0100
9238 @@ -9,6 +9,9 @@ obj-y     = sched.o fork.o exec_domain.o
9239             rcupdate.o intermodule.o extable.o params.o posix-timers.o \
9240             kthread.o wait.o kfifo.o sys_ni.o
9241  
9242 +subdir-y       += vserver
9243 +obj-y    += vserver/vserver.o
9244 +
9245  obj-$(CONFIG_FUTEX) += futex.o
9246  obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
9247  obj-$(CONFIG_SMP) += cpu.o spinlock.o
9248 diff -NurpP --minimal linux-2.6.10/kernel/capability.c linux-2.6.10-vs1.9.3.17/kernel/capability.c
9249 --- linux-2.6.10/kernel/capability.c    2004-12-25 01:55:30.000000000 +0100
9250 +++ linux-2.6.10-vs1.9.3.17/kernel/capability.c 2004-12-26 19:40:14.000000000 +0100
9251 @@ -11,6 +11,8 @@
9252  #include <linux/module.h>
9253  #include <linux/security.h>
9254  #include <linux/syscalls.h>
9255 +#include <linux/vs_cvirt.h>
9256 +
9257  #include <asm/uaccess.h>
9258  
9259  unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
9260 diff -NurpP --minimal linux-2.6.10/kernel/exit.c linux-2.6.10-vs1.9.3.17/kernel/exit.c
9261 --- linux-2.6.10/kernel/exit.c  2004-12-25 01:55:30.000000000 +0100
9262 +++ linux-2.6.10-vs1.9.3.17/kernel/exit.c       2004-12-26 19:40:35.000000000 +0100
9263 @@ -26,6 +26,7 @@
9264  #include <linux/proc_fs.h>
9265  #include <linux/mempolicy.h>
9266  #include <linux/syscalls.h>
9267 +#include <linux/vs_limit.h>
9268  
9269  #include <asm/uaccess.h>
9270  #include <asm/unistd.h>
9271 @@ -40,6 +41,11 @@ int getrusage(struct task_struct *, int,
9272  static void __unhash_process(struct task_struct *p)
9273  {
9274         nr_threads--;
9275 +       /* tasklist_lock is held, is this sufficient? */
9276 +       if (p->vx_info) {
9277 +               atomic_dec(&p->vx_info->cvirt.nr_threads);
9278 +               vx_nproc_dec(p);
9279 +       }
9280         detach_pid(p, PIDTYPE_PID);
9281         detach_pid(p, PIDTYPE_TGID);
9282         if (thread_group_leader(p)) {
9283 @@ -226,6 +232,7 @@ void reparent_to_init(void)
9284         ptrace_unlink(current);
9285         /* Reparent to init */
9286         REMOVE_LINKS(current);
9287 +       /* FIXME handle vchild_reaper/initpid */
9288         current->parent = child_reaper;
9289         current->real_parent = child_reaper;
9290         SET_LINKS(current);
9291 @@ -370,6 +377,7 @@ static inline void close_files(struct fi
9292                                 struct file * file = xchg(&files->fd[i], NULL);
9293                                 if (file)
9294                                         filp_close(file, files);
9295 +                               // vx_openfd_dec(i);
9296                         }
9297                         i++;
9298                         set >>= 1;
9299 @@ -593,6 +601,7 @@ static inline void forget_original_paren
9300         struct task_struct *p, *reaper = father;
9301         struct list_head *_p, *_n;
9302  
9303 +       /* FIXME handle vchild_reaper/initpid */
9304         do {
9305                 reaper = next_thread(reaper);
9306                 if (reaper == father) {
9307 diff -NurpP --minimal linux-2.6.10/kernel/fork.c linux-2.6.10-vs1.9.3.17/kernel/fork.c
9308 --- linux-2.6.10/kernel/fork.c  2004-12-25 01:55:30.000000000 +0100
9309 +++ linux-2.6.10-vs1.9.3.17/kernel/fork.c       2005-01-03 01:23:16.000000000 +0100
9310 @@ -39,6 +39,9 @@
9311  #include <linux/audit.h>
9312  #include <linux/profile.h>
9313  #include <linux/rmap.h>
9314 +#include <linux/vs_network.h>
9315 +#include <linux/vs_limit.h>
9316 +#include <linux/vs_memory.h>
9317  
9318  #include <asm/pgtable.h>
9319  #include <asm/pgalloc.h>
9320 @@ -81,6 +84,8 @@ static kmem_cache_t *task_struct_cachep;
9321  void free_task(struct task_struct *tsk)
9322  {
9323         free_thread_info(tsk->thread_info);
9324 +       clr_vx_info(&tsk->vx_info);
9325 +       clr_nx_info(&tsk->nx_info);
9326         free_task_struct(tsk);
9327  }
9328  EXPORT_SYMBOL(free_task);
9329 @@ -302,6 +307,7 @@ static struct mm_struct * mm_init(struct
9330  
9331         if (likely(!mm_alloc_pgd(mm))) {
9332                 mm->def_flags = 0;
9333 +               set_vx_info(&mm->mm_vx_info, current->vx_info);
9334                 return mm;
9335         }
9336         free_mm(mm);
9337 @@ -333,6 +339,7 @@ void fastcall __mmdrop(struct mm_struct 
9338         BUG_ON(mm == &init_mm);
9339         mm_free_pgd(mm);
9340         destroy_context(mm);
9341 +       clr_vx_info(&mm->mm_vx_info);
9342         free_mm(mm);
9343  }
9344  
9345 @@ -459,6 +466,7 @@ static int copy_mm(unsigned long clone_f
9346  
9347         /* Copy the current MM stuff.. */
9348         memcpy(mm, oldmm, sizeof(*mm));
9349 +       mm->mm_vx_info = NULL;
9350         if (!mm_init(mm))
9351                 goto fail_nomem;
9352  
9353 @@ -791,6 +799,7 @@ static task_t *copy_process(unsigned lon
9354  {
9355         int retval;
9356         struct task_struct *p = NULL;
9357 +       struct vx_info *vxi;
9358  
9359         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
9360                 return ERR_PTR(-EINVAL);
9361 @@ -819,12 +828,32 @@ static task_t *copy_process(unsigned lon
9362         if (!p)
9363                 goto fork_out;
9364  
9365 +       p->vx_info = NULL;
9366 +       set_vx_info(&p->vx_info, current->vx_info);
9367 +       p->nx_info = NULL;
9368 +       set_nx_info(&p->nx_info, current->nx_info);
9369 +
9370 +       /* check vserver memory */
9371 +       if (p->mm && !(clone_flags & CLONE_VM)) {
9372 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
9373 +                       vx_pages_add(p->mm->mm_vx_info, RLIMIT_AS, p->mm->total_vm);
9374 +               else
9375 +                       goto bad_fork_free;
9376 +       }
9377 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
9378 +               if (!vx_rsspages_avail(p->mm, p->mm->rss))
9379 +                       goto bad_fork_cleanup_vm;
9380 +       }
9381 +
9382         retval = -EAGAIN;
9383 +       if (!vx_nproc_avail(1))
9384 +               goto bad_fork_cleanup_vm;
9385 +
9386         if (atomic_read(&p->user->processes) >=
9387                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
9388                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
9389                                 p->user != &root_user)
9390 -                       goto bad_fork_free;
9391 +                       goto bad_fork_cleanup_vm;
9392         }
9393  
9394         atomic_inc(&p->user->__count);
9395 @@ -1020,6 +1049,12 @@ static task_t *copy_process(unsigned lon
9396         }
9397  
9398         nr_threads++;
9399 +       /* p is copy of current */
9400 +       vxi = p->vx_info;
9401 +       if (vxi) {
9402 +               atomic_inc(&vxi->cvirt.nr_threads);
9403 +               vx_nproc_inc(p);
9404 +       }
9405         write_unlock_irq(&tasklist_lock);
9406         retval = 0;
9407  
9408 @@ -1062,6 +1097,9 @@ bad_fork_cleanup_count:
9409         put_group_info(p->group_info);
9410         atomic_dec(&p->user->processes);
9411         free_uid(p->user);
9412 +bad_fork_cleanup_vm:
9413 +       if (p->mm && !(clone_flags & CLONE_VM))
9414 +               vx_pages_sub(p->mm->mm_vx_info, RLIMIT_AS, p->mm->total_vm);
9415  bad_fork_free:
9416         free_task(p);
9417         goto fork_out;
9418 diff -NurpP --minimal linux-2.6.10/kernel/kthread.c linux-2.6.10-vs1.9.3.17/kernel/kthread.c
9419 --- linux-2.6.10/kernel/kthread.c       2004-08-14 12:56:22.000000000 +0200
9420 +++ linux-2.6.10-vs1.9.3.17/kernel/kthread.c    2004-12-26 19:40:30.000000000 +0100
9421 @@ -108,7 +108,7 @@ static void keventd_create_kthread(void 
9422                 create->result = ERR_PTR(pid);
9423         } else {
9424                 wait_for_completion(&create->started);
9425 -               create->result = find_task_by_pid(pid);
9426 +               create->result = find_task_by_real_pid(pid);
9427         }
9428         complete(&create->done);
9429  }
9430 diff -NurpP --minimal linux-2.6.10/kernel/posix-timers.c linux-2.6.10-vs1.9.3.17/kernel/posix-timers.c
9431 --- linux-2.6.10/kernel/posix-timers.c  2004-12-25 01:55:30.000000000 +0100
9432 +++ linux-2.6.10-vs1.9.3.17/kernel/posix-timers.c       2004-12-26 19:40:30.000000000 +0100
9433 @@ -46,6 +46,7 @@
9434  #include <linux/syscalls.h>
9435  #include <linux/wait.h>
9436  #include <linux/workqueue.h>
9437 +#include <linux/vs_cvirt.h>
9438  
9439  #ifndef div_long_long_rem
9440  #include <asm/div64.h>
9441 @@ -469,7 +470,7 @@ static inline struct task_struct * good_
9442         struct task_struct *rtn = current->group_leader;
9443  
9444         if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
9445 -               (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
9446 +               (!(rtn = find_task_by_real_pid(event->sigev_notify_thread_id)) ||
9447                  rtn->tgid != current->tgid ||
9448                  (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
9449                 return NULL;
9450 diff -NurpP --minimal linux-2.6.10/kernel/printk.c linux-2.6.10-vs1.9.3.17/kernel/printk.c
9451 --- linux-2.6.10/kernel/printk.c        2004-12-25 01:55:30.000000000 +0100
9452 +++ linux-2.6.10-vs1.9.3.17/kernel/printk.c     2004-12-26 19:40:36.000000000 +0100
9453 @@ -251,7 +251,10 @@ int do_syslog(int type, char __user * bu
9454         unsigned long i, j, limit, count;
9455         int do_clear = 0;
9456         char c;
9457 -       int error = 0;
9458 +       int error = -EPERM;
9459 +
9460 +       if (!vx_check(0, VX_ADMIN|VX_WATCH))
9461 +               return error;
9462  
9463         error = security_syslog(type);
9464         if (error)
9465 @@ -521,6 +524,8 @@ asmlinkage int printk(const char *fmt, .
9466         return r;
9467  }
9468  
9469 +static volatile int printk_cpu = -1;
9470 +
9471  asmlinkage int vprintk(const char *fmt, va_list args)
9472  {
9473         unsigned long flags;
9474 @@ -529,11 +534,12 @@ asmlinkage int vprintk(const char *fmt, 
9475         static char printk_buf[1024];
9476         static int log_level_unknown = 1;
9477  
9478 -       if (unlikely(oops_in_progress))
9479 +       if (unlikely(oops_in_progress && printk_cpu == smp_processor_id()))
9480                 zap_locks();
9481  
9482         /* This stops the holder of console_sem just where we want him */
9483         spin_lock_irqsave(&logbuf_lock, flags);
9484 +       printk_cpu = smp_processor_id();
9485  
9486         /* Emit the output into the temporary buffer */
9487         printed_len = vscnprintf(printk_buf, sizeof(printk_buf), fmt, args);
9488 diff -NurpP --minimal linux-2.6.10/kernel/sched.c linux-2.6.10-vs1.9.3.17/kernel/sched.c
9489 --- linux-2.6.10/kernel/sched.c 2004-12-25 01:55:30.000000000 +0100
9490 +++ linux-2.6.10-vs1.9.3.17/kernel/sched.c      2004-12-26 19:40:30.000000000 +0100
9491 @@ -47,6 +47,9 @@
9492  #include <asm/tlb.h>
9493  
9494  #include <asm/unistd.h>
9495 +#include <linux/vs_context.h>
9496 +#include <linux/vs_cvirt.h>
9497 +#include <linux/vs_sched.h>
9498  
9499  #ifdef CONFIG_NUMA
9500  #define cpu_to_node_mask(cpu) node_to_cpumask(cpu_to_node(cpu))
9501 @@ -244,6 +247,10 @@ struct runqueue {
9502         task_t *migration_thread;
9503         struct list_head migration_queue;
9504  #endif
9505 +#ifdef CONFIG_VSERVER_HARDCPU
9506 +       struct list_head hold_queue;
9507 +       int idle_tokens;
9508 +#endif
9509  
9510  #ifdef CONFIG_SCHEDSTATS
9511         /* latency stats */
9512 @@ -617,6 +624,9 @@ static int effective_prio(task_t *p)
9513         bonus = CURRENT_BONUS(p) - MAX_BONUS / 2;
9514  
9515         prio = p->static_prio - bonus;
9516 +       if (task_vx_flags(p, VXF_SCHED_PRIO, 0))
9517 +               prio += effective_vavavoom(p, MAX_USER_PRIO);
9518 +
9519         if (prio < MAX_RT_PRIO)
9520                 prio = MAX_RT_PRIO;
9521         if (prio > MAX_PRIO-1)
9522 @@ -762,19 +772,27 @@ static void activate_task(task_t *p, run
9523         }
9524         p->timestamp = now;
9525  
9526 +       vx_activate_task(p);
9527         __activate_task(p, rq);
9528  }
9529  
9530  /*
9531   * deactivate_task - remove a task from the runqueue.
9532   */
9533 -static void deactivate_task(struct task_struct *p, runqueue_t *rq)
9534 +static void __deactivate_task(struct task_struct *p, runqueue_t *rq)
9535  {
9536         rq->nr_running--;
9537         dequeue_task(p, p->array);
9538         p->array = NULL;
9539  }
9540  
9541 +static inline
9542 +void deactivate_task(struct task_struct *p, runqueue_t *rq)
9543 +{
9544 +       vx_deactivate_task(p);
9545 +       __deactivate_task(p, rq);
9546 +}
9547 +
9548  /*
9549   * resched_task - mark a task 'to be rescheduled now'.
9550   *
9551 @@ -1109,6 +1127,9 @@ out_activate:
9552          * to be considered on this CPU.)
9553          */
9554         activate_task(p, rq, cpu == this_cpu);
9555 +       /* this is to get the accounting behind the load update */
9556 +       if (old_state == TASK_UNINTERRUPTIBLE)
9557 +               vx_uninterruptible_dec(p);
9558         if (!sync || cpu != this_cpu) {
9559                 if (TASK_PREEMPTS_CURR(p, rq))
9560                         resched_task(rq->curr);
9561 @@ -1231,6 +1252,7 @@ void fastcall wake_up_new_task(task_t * 
9562  
9563         p->prio = effective_prio(p);
9564  
9565 +       vx_activate_task(p);
9566         if (likely(cpu == this_cpu)) {
9567                 if (!(clone_flags & CLONE_VM)) {
9568                         /*
9569 @@ -2287,12 +2309,18 @@ void scheduler_tick(int user_ticks, int 
9570         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
9571         runqueue_t *rq = this_rq();
9572         task_t *p = current;
9573 +       struct vx_info *vxi = p->vx_info;
9574  
9575         rq->timestamp_last_tick = sched_clock();
9576  
9577         if (rcu_pending(cpu))
9578                 rcu_check_callbacks(cpu, user_ticks);
9579  
9580 +       if (vxi) {
9581 +               vxi->sched.cpu[cpu].user_ticks += user_ticks;
9582 +               vxi->sched.cpu[cpu].sys_ticks += sys_ticks;
9583 +       }
9584 +
9585         /* note: this timer irq context must be accounted for as well */
9586         if (hardirq_count() - HARDIRQ_OFFSET) {
9587                 cpustat->irq += sys_ticks;
9588 @@ -2305,10 +2333,18 @@ void scheduler_tick(int user_ticks, int 
9589         if (p == rq->idle) {
9590                 if (atomic_read(&rq->nr_iowait) > 0)
9591                         cpustat->iowait += sys_ticks;
9592 +                       // vx_cpustat_acc(vxi, iowait, cpu, cpustat, sys_ticks);
9593                 else
9594                         cpustat->idle += sys_ticks;
9595 +                       // vx_cpustat_acc(vxi, idle, cpu, cpustat, sys_ticks);
9596 +
9597                 if (wake_priority_sleeper(rq))
9598                         goto out;
9599 +
9600 +#ifdef CONFIG_VSERVER_HARDCPU_IDLE
9601 +               if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
9602 +                       set_need_resched();
9603 +#endif
9604                 rebalance_tick(cpu, rq, SCHED_IDLE);
9605                 return;
9606         }
9607 @@ -2347,7 +2383,7 @@ void scheduler_tick(int user_ticks, int 
9608                 }
9609                 goto out_unlock;
9610         }
9611 -       if (!--p->time_slice) {
9612 +       if (vx_need_resched(p)) {
9613                 dequeue_task(p, rq->active);
9614                 set_tsk_need_resched(p);
9615                 p->prio = effective_prio(p);
9616 @@ -2533,6 +2569,10 @@ asmlinkage void __sched schedule(void)
9617         struct list_head *queue;
9618         unsigned long long now;
9619         unsigned long run_time;
9620 +#ifdef CONFIG_VSERVER_HARDCPU
9621 +       struct vx_info *vxi;
9622 +       int maxidle = -HZ;
9623 +#endif
9624         int cpu, idx;
9625  
9626         /*
9627 @@ -2596,12 +2636,53 @@ need_resched_nonpreemptible:
9628                                 unlikely(signal_pending(prev))))
9629                         prev->state = TASK_RUNNING;
9630                 else {
9631 -                       if (prev->state == TASK_UNINTERRUPTIBLE)
9632 +                       if (prev->state == TASK_UNINTERRUPTIBLE) {
9633                                 rq->nr_uninterruptible++;
9634 +                               vx_uninterruptible_inc(prev);
9635 +                       }
9636                         deactivate_task(prev, rq);
9637                 }
9638         }
9639  
9640 +#ifdef CONFIG_VSERVER_HARDCPU
9641 +       if (!list_empty(&rq->hold_queue)) {
9642 +               struct list_head *l, *n;
9643 +               int ret;
9644 +
9645 +               vxi = NULL;
9646 +               list_for_each_safe(l, n, &rq->hold_queue) {
9647 +                       next = list_entry(l, task_t, run_list);
9648 +                       if (vxi == next->vx_info)
9649 +                               continue;
9650 +
9651 +                       vxi = next->vx_info;
9652 +                       ret = vx_tokens_recalc(vxi);
9653 +                       // tokens = vx_tokens_avail(next);
9654 +
9655 +                       if (ret > 0) {
9656 +                               list_del(&next->run_list);
9657 +                               next->state &= ~TASK_ONHOLD;
9658 +                               // one less waiting
9659 +                               vx_onhold_dec(vxi);
9660 +                               array = rq->expired;
9661 +                               next->prio = MAX_PRIO-1;
9662 +                               enqueue_task(next, array);
9663 +                               rq->nr_running++;
9664 +                               if (next->static_prio < rq->best_expired_prio)
9665 +                                       rq->best_expired_prio = next->static_prio;
9666 +
9667 +                               // printk("··· %8lu unhold %p [%d]\n", jiffies, next, next->prio);
9668 +                               break;
9669 +                       }
9670 +                       if ((ret < 0) && (maxidle < ret))
9671 +                               maxidle = ret;
9672 +               }
9673 +       }
9674 +       rq->idle_tokens = -maxidle;
9675 +
9676 +pick_next:
9677 +#endif
9678 +
9679         cpu = smp_processor_id();
9680         if (unlikely(!rq->nr_running)) {
9681  go_idle:
9682 @@ -2650,6 +2731,26 @@ go_idle:
9683         queue = array->queue + idx;
9684         next = list_entry(queue->next, task_t, run_list);
9685  
9686 +#ifdef CONFIG_VSERVER_HARDCPU
9687 +       vxi = next->vx_info;
9688 +       if (vx_info_flags(vxi, VXF_SCHED_PAUSE|VXF_SCHED_HARD, 0)) {
9689 +               int ret = vx_tokens_recalc(vxi);
9690 +
9691 +               if (unlikely(ret <= 0)) {
9692 +                       if (ret && (rq->idle_tokens > -ret))
9693 +                               rq->idle_tokens = -ret;
9694 +                       __deactivate_task(next, rq);
9695 +                       recalc_task_prio(next, now);
9696 +                       // a new one on hold
9697 +                       vx_onhold_inc(vxi);
9698 +                       next->state |= TASK_ONHOLD;
9699 +                       list_add_tail(&next->run_list, &rq->hold_queue);
9700 +                       //printk("··· %8lu hold   %p [%d]\n", jiffies, next, next->prio);
9701 +                       goto pick_next;
9702 +               }
9703 +       }
9704 +#endif
9705 +
9706         if (!rt_task(next) && next->activated > 0) {
9707                 unsigned long long delta = now - next->timestamp;
9708  
9709 @@ -3009,6 +3110,8 @@ asmlinkage long sys_nice(int increment)
9710          * and we have a single winner.
9711          */
9712         if (increment < 0) {
9713 +               if (vx_flags(VXF_IGNEG_NICE, 0))
9714 +                       return 0;
9715                 if (!capable(CAP_SYS_NICE))
9716                         return -EPERM;
9717                 if (increment < -40)
9718 @@ -3166,6 +3269,7 @@ recheck:
9719         oldprio = p->prio;
9720         __setscheduler(p, policy, lp.sched_priority);
9721         if (array) {
9722 +               vx_activate_task(p);
9723                 __activate_task(p, task_rq(p));
9724                 /*
9725                  * Reschedule if we are currently running on this runqueue and
9726 @@ -4596,6 +4700,9 @@ void __init sched_init(void)
9727                 rq->migration_thread = NULL;
9728                 INIT_LIST_HEAD(&rq->migration_queue);
9729  #endif
9730 +#ifdef CONFIG_VSERVER_HARDCPU
9731 +               INIT_LIST_HEAD(&rq->hold_queue);
9732 +#endif
9733                 atomic_set(&rq->nr_iowait, 0);
9734  
9735                 for (j = 0; j < 2; j++) {
9736 diff -NurpP --minimal linux-2.6.10/kernel/signal.c linux-2.6.10-vs1.9.3.17/kernel/signal.c
9737 --- linux-2.6.10/kernel/signal.c        2004-12-25 01:55:30.000000000 +0100
9738 +++ linux-2.6.10-vs1.9.3.17/kernel/signal.c     2004-12-26 19:40:30.000000000 +0100
9739 @@ -621,17 +621,26 @@ static int check_kill_permission(int sig
9740                                  struct task_struct *t)
9741  {
9742         int error = -EINVAL;
9743 +       int user;
9744 +
9745         if (sig < 0 || sig > _NSIG)
9746                 return error;
9747 +
9748 +       user = (!info || ((unsigned long)info != 1 &&
9749 +               (unsigned long)info != 2 && SI_FROMUSER(info)));
9750 +
9751         error = -EPERM;
9752 -       if ((!info || ((unsigned long)info != 1 &&
9753 -                       (unsigned long)info != 2 && SI_FROMUSER(info)))
9754 -           && ((sig != SIGCONT) ||
9755 +       if (user && ((sig != SIGCONT) ||
9756                 (current->signal->session != t->signal->session))
9757             && (current->euid ^ t->suid) && (current->euid ^ t->uid)
9758             && (current->uid ^ t->suid) && (current->uid ^ t->uid)
9759             && !capable(CAP_KILL))
9760                 return error;
9761 +
9762 +       error = -ESRCH;
9763 +       if (user && !vx_check(vx_task_xid(t), VX_ADMIN|VX_IDENT))
9764 +               return error;
9765 +
9766         return security_task_kill(t, info, sig);
9767  }
9768  
9769 diff -NurpP --minimal linux-2.6.10/kernel/sys.c linux-2.6.10-vs1.9.3.17/kernel/sys.c
9770 --- linux-2.6.10/kernel/sys.c   2004-12-25 01:55:30.000000000 +0100
9771 +++ linux-2.6.10-vs1.9.3.17/kernel/sys.c        2004-12-26 19:40:35.000000000 +0100
9772 @@ -11,6 +11,7 @@
9773  #include <linux/mman.h>
9774  #include <linux/smp_lock.h>
9775  #include <linux/notifier.h>
9776 +#include <linux/kmod.h>
9777  #include <linux/reboot.h>
9778  #include <linux/prctl.h>
9779  #include <linux/init.h>
9780 @@ -23,6 +24,7 @@
9781  #include <linux/security.h>
9782  #include <linux/dcookies.h>
9783  #include <linux/suspend.h>
9784 +#include <linux/vs_cvirt.h>
9785  
9786  #include <linux/compat.h>
9787  #include <linux/syscalls.h>
9788 @@ -225,7 +227,10 @@ static int set_one_prio(struct task_stru
9789                 goto out;
9790         }
9791         if (niceval < task_nice(p) && !capable(CAP_SYS_NICE)) {
9792 -               error = -EACCES;
9793 +               if (vx_flags(VXF_IGNEG_NICE, 0))
9794 +                       error = 0;
9795 +               else
9796 +                       error = -EACCES;
9797                 goto out;
9798         }
9799         no_nice = security_task_setnice(p, niceval);
9800 @@ -277,7 +282,8 @@ asmlinkage long sys_setpriority(int whic
9801                         if (!who)
9802                                 who = current->uid;
9803                         else
9804 -                               if ((who != current->uid) && !(user = find_user(who)))
9805 +                               if ((who != current->uid) &&
9806 +                                       !(user = find_user(vx_current_xid(), who)))
9807                                         goto out_unlock;        /* No processes for this user */
9808  
9809                         do_each_thread(g, p)
9810 @@ -335,7 +341,8 @@ asmlinkage long sys_getpriority(int whic
9811                         if (!who)
9812                                 who = current->uid;
9813                         else
9814 -                               if ((who != current->uid) && !(user = find_user(who)))
9815 +                               if ((who != current->uid) &&
9816 +                                       !(user = find_user(vx_current_xid(), who)))
9817                                         goto out_unlock;        /* No processes for this user */
9818  
9819                         do_each_thread(g, p)
9820 @@ -355,6 +362,7 @@ out_unlock:
9821         return retval;
9822  }
9823  
9824 +long vs_reboot(unsigned int, void *);
9825  
9826  /*
9827   * Reboot system call: for obvious reasons only root may call it,
9828 @@ -380,6 +388,9 @@ asmlinkage long sys_reboot(int magic1, i
9829                         magic2 != LINUX_REBOOT_MAGIC2C))
9830                 return -EINVAL;
9831  
9832 +       if (!vx_check(0, VX_ADMIN|VX_WATCH))
9833 +               return vs_reboot(cmd, arg);
9834 +
9835         lock_kernel();
9836         switch (cmd) {
9837         case LINUX_REBOOT_CMD_RESTART:
9838 @@ -577,7 +588,7 @@ static int set_user(uid_t new_ruid, int 
9839  {
9840         struct user_struct *new_user;
9841  
9842 -       new_user = alloc_uid(new_ruid);
9843 +       new_user = alloc_uid(vx_current_xid(), new_ruid);
9844         if (!new_user)
9845                 return -EAGAIN;
9846  
9847 @@ -946,14 +957,17 @@ asmlinkage long sys_setpgid(pid_t pid, p
9848  {
9849         struct task_struct *p;
9850         int err = -EINVAL;
9851 +       pid_t rpgid;
9852  
9853         if (!pid)
9854 -               pid = current->pid;
9855 +               pid = vx_map_pid(current->pid);
9856         if (!pgid)
9857                 pgid = pid;
9858         if (pgid < 0)
9859                 return -EINVAL;
9860  
9861 +       rpgid = vx_rmap_pid(pgid);
9862 +
9863         /* From this point forward we keep holding onto the tasklist lock
9864          * so that our parent does not change from under us. -DaveM
9865          */
9866 @@ -988,22 +1002,22 @@ asmlinkage long sys_setpgid(pid_t pid, p
9867         if (pgid != pid) {
9868                 struct task_struct *p;
9869  
9870 -               do_each_task_pid(pgid, PIDTYPE_PGID, p) {
9871 +               do_each_task_pid(rpgid, PIDTYPE_PGID, p) {
9872                         if (p->signal->session == current->signal->session)
9873                                 goto ok_pgid;
9874 -               } while_each_task_pid(pgid, PIDTYPE_PGID, p);
9875 +               } while_each_task_pid(rpgid, PIDTYPE_PGID, p);
9876                 goto out;
9877         }
9878  
9879  ok_pgid:
9880 -       err = security_task_setpgid(p, pgid);
9881 +       err = security_task_setpgid(p, rpgid);
9882         if (err)
9883                 goto out;
9884  
9885 -       if (process_group(p) != pgid) {
9886 +       if (process_group(p) != rpgid) {
9887                 detach_pid(p, PIDTYPE_PGID);
9888 -               p->signal->pgrp = pgid;
9889 -               attach_pid(p, PIDTYPE_PGID, pgid);
9890 +               p->signal->pgrp = rpgid;
9891 +               attach_pid(p, PIDTYPE_PGID, rpgid);
9892         }
9893  
9894         err = 0;
9895 @@ -1016,7 +1030,7 @@ out:
9896  asmlinkage long sys_getpgid(pid_t pid)
9897  {
9898         if (!pid) {
9899 -               return process_group(current);
9900 +               return vx_rmap_pid(process_group(current));
9901         } else {
9902                 int retval;
9903                 struct task_struct *p;
9904 @@ -1028,7 +1042,7 @@ asmlinkage long sys_getpgid(pid_t pid)
9905                 if (p) {
9906                         retval = security_task_getpgid(p);
9907                         if (!retval)
9908 -                               retval = process_group(p);
9909 +                               retval = vx_rmap_pid(process_group(p));
9910                 }
9911                 read_unlock(&tasklist_lock);
9912                 return retval;
9913 @@ -1364,7 +1378,7 @@ asmlinkage long sys_newuname(struct new_
9914         int errno = 0;
9915  
9916         down_read(&uts_sem);
9917 -       if (copy_to_user(name,&system_utsname,sizeof *name))
9918 +       if (copy_to_user(name, vx_new_utsname(), sizeof *name))
9919                 errno = -EFAULT;
9920         up_read(&uts_sem);
9921         return errno;
9922 @@ -1375,15 +1389,17 @@ asmlinkage long sys_sethostname(char __u
9923         int errno;
9924         char tmp[__NEW_UTS_LEN];
9925  
9926 -       if (!capable(CAP_SYS_ADMIN))
9927 +       if (!capable(CAP_SYS_ADMIN) && !vx_ccaps(VXC_SET_UTSNAME))
9928                 return -EPERM;
9929         if (len < 0 || len > __NEW_UTS_LEN)
9930                 return -EINVAL;
9931         down_write(&uts_sem);
9932         errno = -EFAULT;
9933         if (!copy_from_user(tmp, name, len)) {
9934 -               memcpy(system_utsname.nodename, tmp, len);
9935 -               system_utsname.nodename[len] = 0;
9936 +               char *ptr = vx_new_uts(nodename);
9937 +
9938 +               memcpy(ptr, tmp, len);
9939 +               ptr[len] = 0;
9940                 errno = 0;
9941         }
9942         up_write(&uts_sem);
9943 @@ -1395,15 +1411,17 @@ asmlinkage long sys_sethostname(char __u
9944  asmlinkage long sys_gethostname(char __user *name, int len)
9945  {
9946         int i, errno;
9947 +       char *ptr;
9948  
9949         if (len < 0)
9950                 return -EINVAL;
9951         down_read(&uts_sem);
9952 -       i = 1 + strlen(system_utsname.nodename);
9953 +       ptr = vx_new_uts(nodename);
9954 +       i = 1 + strlen(ptr);
9955         if (i > len)
9956                 i = len;
9957         errno = 0;
9958 -       if (copy_to_user(name, system_utsname.nodename, i))
9959 +       if (copy_to_user(name, ptr, i))
9960                 errno = -EFAULT;
9961         up_read(&uts_sem);
9962         return errno;
9963 @@ -1420,7 +1438,7 @@ asmlinkage long sys_setdomainname(char _
9964         int errno;
9965         char tmp[__NEW_UTS_LEN];
9966  
9967 -       if (!capable(CAP_SYS_ADMIN))
9968 +       if (!capable(CAP_SYS_ADMIN) && !vx_ccaps(VXC_SET_UTSNAME))
9969                 return -EPERM;
9970         if (len < 0 || len > __NEW_UTS_LEN)
9971                 return -EINVAL;
9972 @@ -1428,8 +1446,10 @@ asmlinkage long sys_setdomainname(char _
9973         down_write(&uts_sem);
9974         errno = -EFAULT;
9975         if (!copy_from_user(tmp, name, len)) {
9976 -               memcpy(system_utsname.domainname, tmp, len);
9977 -               system_utsname.domainname[len] = 0;
9978 +               char *ptr = vx_new_uts(domainname);
9979 +
9980 +               memcpy(ptr, tmp, len);
9981 +               ptr[len] = 0;
9982                 errno = 0;
9983         }
9984         up_write(&uts_sem);
9985 @@ -1486,7 +1506,7 @@ asmlinkage long sys_setrlimit(unsigned i
9986                 return -EINVAL;
9987         old_rlim = current->signal->rlim + resource;
9988         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
9989 -           !capable(CAP_SYS_RESOURCE))
9990 +           !capable(CAP_SYS_RESOURCE) && !vx_ccaps(VXC_SET_RLIMIT))
9991                 return -EPERM;
9992         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > NR_OPEN)
9993                         return -EPERM;
9994 diff -NurpP --minimal linux-2.6.10/kernel/sysctl.c linux-2.6.10-vs1.9.3.17/kernel/sysctl.c
9995 --- linux-2.6.10/kernel/sysctl.c        2004-12-25 01:55:30.000000000 +0100
9996 +++ linux-2.6.10-vs1.9.3.17/kernel/sysctl.c     2004-12-26 19:40:34.000000000 +0100
9997 @@ -86,6 +86,7 @@ extern char modprobe_path[];
9998  #ifdef CONFIG_HOTPLUG
9999  extern char hotplug_path[];
10000  #endif
10001 +extern char vshelper_path[];
10002  #ifdef CONFIG_CHR_DEV_SG
10003  extern int sg_big_buff;
10004  #endif
10005 @@ -400,6 +401,15 @@ static ctl_table kern_table[] = {
10006                 .strategy       = &sysctl_string,
10007         },
10008  #endif
10009 +       {
10010 +               .ctl_name       = KERN_VSHELPER,
10011 +               .procname       = "vshelper",
10012 +               .data           = &vshelper_path,
10013 +               .maxlen         = 256,
10014 +               .mode           = 0644,
10015 +               .proc_handler   = &proc_dostring,
10016 +               .strategy       = &sysctl_string,
10017 +       },
10018  #ifdef CONFIG_CHR_DEV_SG
10019         {
10020                 .ctl_name       = KERN_SG_BIG_BUFF,
10021 diff -NurpP --minimal linux-2.6.10/kernel/timer.c linux-2.6.10-vs1.9.3.17/kernel/timer.c
10022 --- linux-2.6.10/kernel/timer.c 2004-12-25 01:55:30.000000000 +0100
10023 +++ linux-2.6.10-vs1.9.3.17/kernel/timer.c      2004-12-26 19:40:36.000000000 +0100
10024 @@ -32,6 +32,8 @@
10025  #include <linux/jiffies.h>
10026  #include <linux/cpu.h>
10027  #include <linux/syscalls.h>
10028 +#include <linux/vs_cvirt.h>
10029 +#include <linux/vserver/sched.h>
10030  
10031  #include <asm/uaccess.h>
10032  #include <asm/unistd.h>
10033 @@ -677,7 +679,11 @@ static void second_overflow(void)
10034         if (ltemp > (MAXPHASE / MINSEC) << SHIFT_UPDATE)
10035             ltemp = (MAXPHASE / MINSEC) << SHIFT_UPDATE;
10036         time_offset += ltemp;
10037 +       #if SHIFT_SCALE - SHIFT_HZ - SHIFT_UPDATE > 0
10038         time_adj = -ltemp << (SHIFT_SCALE - SHIFT_HZ - SHIFT_UPDATE);
10039 +       #else
10040 +       time_adj = -ltemp >> (SHIFT_HZ + SHIFT_UPDATE - SHIFT_SCALE);
10041 +       #endif
10042      } else {
10043         ltemp = time_offset;
10044         if (!(time_status & STA_FLL))
10045 @@ -685,7 +691,11 @@ static void second_overflow(void)
10046         if (ltemp > (MAXPHASE / MINSEC) << SHIFT_UPDATE)
10047             ltemp = (MAXPHASE / MINSEC) << SHIFT_UPDATE;
10048         time_offset -= ltemp;
10049 +       #if SHIFT_SCALE - SHIFT_HZ - SHIFT_UPDATE > 0
10050         time_adj = ltemp << (SHIFT_SCALE - SHIFT_HZ - SHIFT_UPDATE);
10051 +       #else
10052 +       time_adj = ltemp >> (SHIFT_HZ + SHIFT_UPDATE - SHIFT_SCALE);
10053 +       #endif
10054      }
10055  
10056      /*
10057 @@ -1006,7 +1016,7 @@ asmlinkage unsigned long sys_alarm(unsig
10058   */
10059  asmlinkage long sys_getpid(void)
10060  {
10061 -       return current->tgid;
10062 +       return vx_map_tgid(current->tgid);
10063  }
10064  
10065  /*
10066 @@ -1050,7 +1060,7 @@ asmlinkage long sys_getppid(void)
10067  #endif
10068                 break;
10069         }
10070 -       return pid;
10071 +       return vx_map_pid(pid);
10072  }
10073  
10074  asmlinkage long sys_getuid(void)
10075 @@ -1258,6 +1268,8 @@ asmlinkage long sys_sysinfo(struct sysin
10076                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
10077                         tp.tv_sec++;
10078                 }
10079 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
10080 +                       vx_vsi_uptime(&tp, NULL);
10081                 val.uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
10082  
10083                 val.loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
10084 @@ -1267,6 +1279,9 @@ asmlinkage long sys_sysinfo(struct sysin
10085                 val.procs = nr_threads;
10086         } while (read_seqretry(&xtime_lock, seq));
10087  
10088 +/*     if (vx_flags(VXF_VIRT_CPU, 0))
10089 +               vx_vsi_cpu(val);
10090 +*/
10091         si_meminfo(&val);
10092         si_swapinfo(&val);
10093  
10094 diff -NurpP --minimal linux-2.6.10/kernel/user.c linux-2.6.10-vs1.9.3.17/kernel/user.c
10095 --- linux-2.6.10/kernel/user.c  2004-12-25 01:55:30.000000000 +0100
10096 +++ linux-2.6.10-vs1.9.3.17/kernel/user.c       2004-12-26 19:40:29.000000000 +0100
10097 @@ -21,8 +21,8 @@
10098  #define UIDHASH_BITS           8
10099  #define UIDHASH_SZ             (1 << UIDHASH_BITS)
10100  #define UIDHASH_MASK           (UIDHASH_SZ - 1)
10101 -#define __uidhashfn(uid)       (((uid >> UIDHASH_BITS) + uid) & UIDHASH_MASK)
10102 -#define uidhashentry(uid)      (uidhash_table + __uidhashfn((uid)))
10103 +#define __uidhashfn(xid,uid)   ((((uid) >> UIDHASH_BITS) + ((uid)^(xid))) & UIDHASH_MASK)
10104 +#define uidhashentry(xid,uid)  (uidhash_table + __uidhashfn((xid),(uid)))
10105  
10106  static kmem_cache_t *uid_cachep;
10107  static struct list_head uidhash_table[UIDHASH_SZ];
10108 @@ -54,7 +54,7 @@ static inline void uid_hash_remove(struc
10109         list_del(&up->uidhash_list);
10110  }
10111  
10112 -static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *hashent)
10113 +static inline struct user_struct *uid_hash_find(xid_t xid, uid_t uid, struct list_head *hashent)
10114  {
10115         struct list_head *up;
10116  
10117 @@ -63,7 +63,7 @@ static inline struct user_struct *uid_ha
10118  
10119                 user = list_entry(up, struct user_struct, uidhash_list);
10120  
10121 -               if(user->uid == uid) {
10122 +               if(user->uid == uid && user->xid == xid) {
10123                         atomic_inc(&user->__count);
10124                         return user;
10125                 }
10126 @@ -78,12 +78,12 @@ static inline struct user_struct *uid_ha
10127   *
10128   * If the user_struct could not be found, return NULL.
10129   */
10130 -struct user_struct *find_user(uid_t uid)
10131 +struct user_struct *find_user(xid_t xid, uid_t uid)
10132  {
10133         struct user_struct *ret;
10134  
10135         spin_lock(&uidhash_lock);
10136 -       ret = uid_hash_find(uid, uidhashentry(uid));
10137 +       ret = uid_hash_find(xid, uid, uidhashentry(xid, uid));
10138         spin_unlock(&uidhash_lock);
10139         return ret;
10140  }
10141 @@ -99,13 +99,13 @@ void free_uid(struct user_struct *up)
10142         }
10143  }
10144  
10145 -struct user_struct * alloc_uid(uid_t uid)
10146 +struct user_struct * alloc_uid(xid_t xid, uid_t uid)
10147  {
10148 -       struct list_head *hashent = uidhashentry(uid);
10149 +       struct list_head *hashent = uidhashentry(xid, uid);
10150         struct user_struct *up;
10151  
10152         spin_lock(&uidhash_lock);
10153 -       up = uid_hash_find(uid, hashent);
10154 +       up = uid_hash_find(xid, uid, hashent);
10155         spin_unlock(&uidhash_lock);
10156  
10157         if (!up) {
10158 @@ -115,6 +115,7 @@ struct user_struct * alloc_uid(uid_t uid
10159                 if (!new)
10160                         return NULL;
10161                 new->uid = uid;
10162 +               new->xid = xid;
10163                 atomic_set(&new->__count, 1);
10164                 atomic_set(&new->processes, 0);
10165                 atomic_set(&new->files, 0);
10166 @@ -133,7 +134,7 @@ struct user_struct * alloc_uid(uid_t uid
10167                  * on adding the same user already..
10168                  */
10169                 spin_lock(&uidhash_lock);
10170 -               up = uid_hash_find(uid, hashent);
10171 +               up = uid_hash_find(xid, uid, hashent);
10172                 if (up) {
10173                         key_put(new->uid_keyring);
10174                         key_put(new->session_keyring);
10175 @@ -179,7 +180,7 @@ static int __init uid_cache_init(void)
10176  
10177         /* Insert the root user immediately (init already runs as root) */
10178         spin_lock(&uidhash_lock);
10179 -       uid_hash_insert(&root_user, uidhashentry(0));
10180 +       uid_hash_insert(&root_user, uidhashentry(0,0));
10181         spin_unlock(&uidhash_lock);
10182  
10183         return 0;
10184 diff -NurpP --minimal linux-2.6.10/kernel/vserver/Kconfig linux-2.6.10-vs1.9.3.17/kernel/vserver/Kconfig
10185 --- linux-2.6.10/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
10186 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/Kconfig      2005-01-02 09:44:49.000000000 +0100
10187 @@ -0,0 +1,114 @@
10188 +#
10189 +# Linux VServer configuration
10190 +#
10191 +
10192 +menu "Linux VServer"
10193 +
10194 +config VSERVER_LEGACY
10195 +       bool    "Enable Legacy Kernel API"
10196 +       default y
10197 +       help
10198 +         This enables the legacy API used in vs1.xx, which allows
10199 +         to use older tools (for migration purposes).
10200 +
10201 +config VSERVER_PROC_SECURE
10202 +       bool    "Enable Proc Security"
10203 +       depends on PROC_FS
10204 +       default y
10205 +       help
10206 +         Hide proc entries by default for xid>1
10207 +
10208 +config VSERVER_HARDCPU
10209 +       bool    "Enable Hard CPU Limits"
10210 +       depends on EXPERIMENTAL
10211 +       default n
10212 +       help
10213 +         Activate the Hard CPU Limits
10214 +
10215 +config VSERVER_HARDCPU_IDLE
10216 +       bool    "Limit the IDLE task"
10217 +       depends on VSERVER_HARDCPU
10218 +       default n
10219 +       help
10220 +         Limit the idle slices, so the the next context
10221 +         will be scheduled as soon as possible.
10222 +         might improve interactivity/latency but
10223 +         increases scheduling overhead.
10224 +
10225 +choice
10226 +       prompt  "Persistent Inode Context Tagging"
10227 +       default INOXID_UGID24
10228 +       help
10229 +         This adds persistent context information to filesystems
10230 +         mounted with the tagxid option. Tagging is a requirement
10231 +         for per context disk limits and per context quota.
10232 +
10233 +
10234 +config INOXID_NONE
10235 +       bool    "Disabled"
10236 +       help
10237 +         no context information is store for inodes
10238 +
10239 +config INOXID_UID16
10240 +       bool    "UID16/GID32"
10241 +       help
10242 +         reduces UID to 16 bit, but leaves GID at 32 bit.
10243 +
10244 +config INOXID_GID16
10245 +       bool    "UID32/GID16"
10246 +       help
10247 +         reduces GID to 16 bit, but leaves UID at 32 bit.
10248 +
10249 +config INOXID_UGID24
10250 +       bool    "UID24/GID24"
10251 +       help
10252 +         uses the upper 8bit from UID and GID for XID tagging
10253 +         which leaves 24bit for UID/GID each, which should be
10254 +         more than sufficient for normal use.
10255 +
10256 +config INOXID_INTERN
10257 +       bool    "UID32/GID32"
10258 +       help
10259 +         this uses otherwise reserved inode fields in the on
10260 +         disk representation, which limits the use to a few
10261 +         filesystems (currently ext2 and ext3)
10262 +
10263 +config INOXID_RUNTIME
10264 +       bool    "Runtime"
10265 +       depends on EXPERIMENTAL
10266 +       help
10267 +         inodes are tagged when first accessed, this doesn't
10268 +         require any persistant information, but might give
10269 +         funny results for mixed access.
10270 +
10271 +endchoice
10272 +
10273 +config VSERVER_DEBUG
10274 +       bool    "Compile Debugging Code"
10275 +       default n
10276 +       help
10277 +         Set this to yes if you want to be able to activate
10278 +         debugging output at runtime. It adds a probably small
10279 +         overhead (~ ??%) to all vserver related functions and
10280 +         increases the kernel size by about 20k.
10281 +
10282 +config VSERVER_HISTORY
10283 +       bool    "Compile History Tracing"
10284 +       depends on VSERVER_DEBUG
10285 +       default n
10286 +       help
10287 +         Set this to yes if you want to record the history of
10288 +         linux-vserver activities, so they can be replayed on
10289 +         a kernel panic (oops)
10290 +
10291 +config VSERVER_HISTORY_SIZE
10292 +       int "Per CPU History Size (32-65536)"
10293 +       depends on VSERVER_HISTORY
10294 +       range 32 65536
10295 +       default 64
10296 +       help
10297 +         This allows you to specify the number of entries in
10298 +         the per CPU history buffer.
10299 +
10300 +endmenu
10301 +
10302 diff -NurpP --minimal linux-2.6.10/kernel/vserver/Makefile linux-2.6.10-vs1.9.3.17/kernel/vserver/Makefile
10303 --- linux-2.6.10/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
10304 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/Makefile     2005-01-02 09:44:49.000000000 +0100
10305 @@ -0,0 +1,14 @@
10306 +#
10307 +# Makefile for the Linux vserver routines.
10308 +#
10309 +
10310 +
10311 +obj-y          += vserver.o
10312 +
10313 +vserver-y      := switch.o context.o namespace.o sched.o network.o inode.o \
10314 +                  limit.o cvirt.o signal.o proc.o helper.o init.o dlimit.o
10315 +
10316 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o
10317 +vserver-$(CONFIG_VSERVER_LEGACY) += legacy.o
10318 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
10319 +
10320 diff -NurpP --minimal linux-2.6.10/kernel/vserver/context.c linux-2.6.10-vs1.9.3.17/kernel/vserver/context.c
10321 --- linux-2.6.10/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
10322 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/context.c    2005-01-05 15:51:26.000000000 +0100
10323 @@ -0,0 +1,796 @@
10324 +/*
10325 + *  linux/kernel/vserver/context.c
10326 + *
10327 + *  Virtual Server: Context Support
10328 + *
10329 + *  Copyright (C) 2003-2005  Herbert Pötzl
10330 + *
10331 + *  V0.01  context helper
10332 + *  V0.02  vx_ctx_kill syscall command
10333 + *  V0.03  replaced context_info calls
10334 + *  V0.04  redesign of struct (de)alloc
10335 + *  V0.05  rlimit basic implementation
10336 + *  V0.06  task_xid and info commands
10337 + *  V0.07  context flags and caps
10338 + *  V0.08  switch to RCU based hash
10339 + *  V0.09  revert to non RCU for now
10340 + *  V0.10  and back to working RCU hash
10341 + *
10342 + */
10343 +
10344 +#include <linux/config.h>
10345 +#include <linux/slab.h>
10346 +#include <linux/types.h>
10347 +#include <linux/namespace.h>
10348 +
10349 +#include <linux/sched.h>
10350 +#include <linux/vserver/network.h>
10351 +#include <linux/vserver/legacy.h>
10352 +#include <linux/vserver/limit.h>
10353 +#include <linux/vserver/debug.h>
10354 +
10355 +#include <linux/vs_context.h>
10356 +#include <linux/vserver/context_cmd.h>
10357 +
10358 +#include <asm/errno.h>
10359 +
10360 +#include "cvirt_init.h"
10361 +#include "limit_init.h"
10362 +#include "sched_init.h"
10363 +
10364 +
10365 +/*     __alloc_vx_info()
10366 +
10367 +       * allocate an initialized vx_info struct
10368 +       * doesn't make it visible (hash)                        */
10369 +
10370 +static struct vx_info *__alloc_vx_info(xid_t xid)
10371 +{
10372 +       struct vx_info *new = NULL;
10373 +
10374 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
10375 +
10376 +       /* would this benefit from a slab cache? */
10377 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
10378 +       if (!new)
10379 +               return 0;
10380 +
10381 +       memset (new, 0, sizeof(struct vx_info));
10382 +       new->vx_id = xid;
10383 +       INIT_RCU_HEAD(&new->vx_rcu);
10384 +       INIT_HLIST_NODE(&new->vx_hlist);
10385 +       atomic_set(&new->vx_refcnt, 0);
10386 +       atomic_set(&new->vx_usecnt, 0);
10387 +       new->vx_parent = NULL;
10388 +       new->vx_state = 0;
10389 +       new->vx_lock = SPIN_LOCK_UNLOCKED;
10390 +       init_waitqueue_head(&new->vx_exit);
10391 +
10392 +       /* rest of init goes here */
10393 +       vx_info_init_limit(&new->limit);
10394 +       vx_info_init_sched(&new->sched);
10395 +       vx_info_init_cvirt(&new->cvirt);
10396 +       vx_info_init_cacct(&new->cacct);
10397 +
10398 +
10399 +       new->vx_flags = VXF_STATE_SETUP|VXF_STATE_INIT;
10400 +       new->vx_bcaps = CAP_INIT_EFF_SET;
10401 +       new->vx_ccaps = 0;
10402 +
10403 +       vxdprintk(VXD_CBIT(xid, 0),
10404 +               "alloc_vx_info(%d) = %p", xid, new);
10405 +       vxh_alloc_vx_info(new);
10406 +       return new;
10407 +}
10408 +
10409 +/*     __dealloc_vx_info()
10410 +
10411 +       * final disposal of vx_info                             */
10412 +
10413 +static void __dealloc_vx_info(struct vx_info *vxi)
10414 +{
10415 +       vxdprintk(VXD_CBIT(xid, 0),
10416 +               "dealloc_vx_info(%p)", vxi);
10417 +       vxh_dealloc_vx_info(vxi);
10418 +
10419 +       vxi->vx_hlist.next = LIST_POISON1;
10420 +       vxi->vx_id = -1;
10421 +
10422 +       vx_info_exit_limit(&vxi->limit);
10423 +       vx_info_exit_sched(&vxi->sched);
10424 +       vx_info_exit_cvirt(&vxi->cvirt);
10425 +       vx_info_exit_cacct(&vxi->cacct);
10426 +
10427 +
10428 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
10429 +       BUG_ON(atomic_read(&vxi->vx_refcnt));
10430 +
10431 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
10432 +       // BUG_ON(!vx_state(vxi, VXS_DEFUNCT));
10433 +
10434 +       vxi->vx_state |= VXS_RELEASED;
10435 +       kfree(vxi);
10436 +}
10437 +
10438 +static inline int __free_vx_info(struct vx_info *vxi)
10439 +{
10440 +       int usecnt, refcnt;
10441 +
10442 +       BUG_ON(!vxi);
10443 +
10444 +       usecnt = atomic_read(&vxi->vx_usecnt);
10445 +       BUG_ON(usecnt < 0);
10446 +
10447 +       refcnt = atomic_read(&vxi->vx_refcnt);
10448 +       BUG_ON(refcnt < 0);
10449 +
10450 +       if (!usecnt)
10451 +               __dealloc_vx_info(vxi);
10452 +       return usecnt;
10453 +}
10454 +
10455 +static void __rcu_put_vx_info(struct rcu_head *head)
10456 +{
10457 +       struct vx_info *vxi = container_of(head, struct vx_info, vx_rcu);
10458 +
10459 +       vxdprintk(VXD_CBIT(xid, 3),
10460 +               "__rcu_put_vx_info(%p[#%d]): %d,%d",
10461 +               vxi, vxi->vx_id,
10462 +               atomic_read(&vxi->vx_usecnt),
10463 +               atomic_read(&vxi->vx_refcnt));
10464 +       put_vx_info(vxi);
10465 +}
10466 +
10467 +void __shutdown_vx_info(struct vx_info *vxi)
10468 +{
10469 +       struct namespace *namespace;
10470 +       struct fs_struct *fs;
10471 +
10472 +       might_sleep();
10473 +
10474 +       namespace = xchg(&vxi->vx_namespace, NULL);
10475 +       if (namespace)
10476 +               put_namespace(namespace);
10477 +
10478 +       fs = xchg(&vxi->vx_fs, NULL);
10479 +       if (fs)
10480 +               put_fs_struct(fs);
10481 +}
10482 +
10483 +/* exported stuff */
10484 +
10485 +void free_vx_info(struct vx_info *vxi)
10486 +{
10487 +       /* context shutdown is mandatory */
10488 +       // BUG_ON(vxi->vx_state != VXS_SHUTDOWN);
10489 +
10490 +       BUG_ON(vxi->vx_state & VXS_HASHED);
10491 +
10492 +       BUG_ON(vxi->vx_namespace);
10493 +       BUG_ON(vxi->vx_fs);
10494 +
10495 +       BUG_ON(__free_vx_info(vxi));
10496 +}
10497 +
10498 +
10499 +/*     hash table for vx_info hash */
10500 +
10501 +#define VX_HASH_SIZE   13
10502 +
10503 +struct hlist_head vx_info_hash[VX_HASH_SIZE];
10504 +
10505 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
10506 +
10507 +
10508 +static inline unsigned int __hashval(xid_t xid)
10509 +{
10510 +       return (xid % VX_HASH_SIZE);
10511 +}
10512 +
10513 +
10514 +
10515 +/*     __hash_vx_info()
10516 +
10517 +       * add the vxi to the global hash table
10518 +       * requires the hash_lock to be held                     */
10519 +
10520 +static inline void __hash_vx_info(struct vx_info *vxi)
10521 +{
10522 +       struct hlist_head *head;
10523 +
10524 +       vxdprintk(VXD_CBIT(xid, 4),
10525 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
10526 +       vxh_hash_vx_info(vxi);
10527 +
10528 +       get_vx_info(vxi);
10529 +       vxi->vx_state |= VXS_HASHED;
10530 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
10531 +       hlist_add_head_rcu(&vxi->vx_hlist, head);
10532 +}
10533 +
10534 +/*     __unhash_vx_info()
10535 +
10536 +       * remove the vxi from the global hash table
10537 +       * requires the hash_lock to be held                     */
10538 +
10539 +static inline void __unhash_vx_info(struct vx_info *vxi)
10540 +{
10541 +       vxdprintk(VXD_CBIT(xid, 4),
10542 +               "__unhash_vx_info: %p[#%d]", vxi, vxi->vx_id);
10543 +       vxh_unhash_vx_info(vxi);
10544 +
10545 +       vxi->vx_state &= ~VXS_HASHED;
10546 +       hlist_del_rcu(&vxi->vx_hlist);
10547 +
10548 +       call_rcu(&vxi->vx_rcu, __rcu_put_vx_info);
10549 +}
10550 +
10551 +
10552 +/*     __lookup_vx_info()
10553 +
10554 +       * requires the rcu_read_lock()
10555 +       * doesn't increment the vx_refcnt                       */
10556 +
10557 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
10558 +{
10559 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
10560 +       struct hlist_node *pos;
10561 +       struct vx_info *vxi;
10562 +
10563 +       hlist_for_each_rcu(pos, head) {
10564 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
10565 +
10566 +               if ((vxi->vx_id == xid) &&
10567 +                       vx_info_state(vxi, VXS_HASHED))
10568 +                       goto found;
10569 +       }
10570 +       vxi = NULL;
10571 +found:
10572 +       vxdprintk(VXD_CBIT(xid, 0),
10573 +               "__lookup_vx_info(#%u): %p[#%u]",
10574 +               xid, vxi, vxi?vxi->vx_id:0);
10575 +       vxh_lookup_vx_info(xid, vxi);
10576 +       return vxi;
10577 +}
10578 +
10579 +
10580 +/*     __vx_dynamic_id()
10581 +
10582 +       * find unused dynamic xid
10583 +       * requires the rcu_read_lock()
10584 +       * requires the hash_lock to be held                     */
10585 +
10586 +static inline xid_t __vx_dynamic_id(void)
10587 +{
10588 +       static xid_t seq = MAX_S_CONTEXT;
10589 +       xid_t barrier = seq;
10590 +
10591 +       do {
10592 +               if (++seq > MAX_S_CONTEXT)
10593 +                       seq = MIN_D_CONTEXT;
10594 +               if (!__lookup_vx_info(seq)) {
10595 +                       vxdprintk(VXD_CBIT(xid, 4),
10596 +                               "__vx_dynamic_id: [#%d]", seq);
10597 +                       return seq;
10598 +               }
10599 +       } while (barrier != seq);
10600 +       return 0;
10601 +}
10602 +
10603 +/*     __loc_vx_info()
10604 +
10605 +       * locate or create the requested context
10606 +       * get() it and if new hash it                           */
10607 +
10608 +static struct vx_info * __loc_vx_info(int id, int *err)
10609 +{
10610 +       struct vx_info *new, *vxi = NULL;
10611 +
10612 +       vxdprintk(VXD_CBIT(xid, 1), "loc_vx_info(%d)*", id);
10613 +
10614 +       if (!(new = __alloc_vx_info(id))) {
10615 +               *err = -ENOMEM;
10616 +               return NULL;
10617 +       }
10618 +
10619 +       /* FIXME is this required at all ? */
10620 +       rcu_read_lock();
10621 +       /* required to make dynamic xids unique */
10622 +       spin_lock(&vx_info_hash_lock);
10623 +
10624 +       /* dynamic context requested */
10625 +       if (id == VX_DYNAMIC_ID) {
10626 +               id = __vx_dynamic_id();
10627 +               if (!id) {
10628 +                       printk(KERN_ERR "no dynamic context available.\n");
10629 +                       goto out_unlock;
10630 +               }
10631 +               new->vx_id = id;
10632 +       }
10633 +       /* existing context requested */
10634 +       else if ((vxi = __lookup_vx_info(id))) {
10635 +               /* context in setup is not available */
10636 +               if (vxi->vx_flags & VXF_STATE_SETUP) {
10637 +                       vxdprintk(VXD_CBIT(xid, 0),
10638 +                               "loc_vx_info(%d) = %p (not available)", id, vxi);
10639 +                       vxi = NULL;
10640 +                       *err = -EBUSY;
10641 +               } else {
10642 +                       vxdprintk(VXD_CBIT(xid, 0),
10643 +                               "loc_vx_info(%d) = %p (found)", id, vxi);
10644 +                       get_vx_info(vxi);
10645 +                       *err = 0;
10646 +               }
10647 +               goto out_unlock;
10648 +       }
10649 +
10650 +       /* new context requested */
10651 +       vxdprintk(VXD_CBIT(xid, 0),
10652 +               "loc_vx_info(%d) = %p (new)", id, new);
10653 +       __hash_vx_info(get_vx_info(new));
10654 +       vxi = new, new = NULL;
10655 +       *err = 1;
10656 +
10657 +out_unlock:
10658 +       spin_unlock(&vx_info_hash_lock);
10659 +       rcu_read_unlock();
10660 +       vxh_loc_vx_info(id, vxi);
10661 +       if (new)
10662 +               __dealloc_vx_info(new);
10663 +       return vxi;
10664 +}
10665 +
10666 +
10667 +
10668 +/*     exported stuff                                          */
10669 +
10670 +
10671 +void unhash_vx_info(struct vx_info *vxi)
10672 +{
10673 +       __shutdown_vx_info(vxi);
10674 +       spin_lock(&vx_info_hash_lock);
10675 +       __unhash_vx_info(vxi);
10676 +       spin_unlock(&vx_info_hash_lock);
10677 +}
10678 +
10679 +/*     locate_vx_info()
10680 +
10681 +       * search for a vx_info and get() it
10682 +       * negative id means current                             */
10683 +
10684 +struct vx_info *locate_vx_info(int id)
10685 +{
10686 +       struct vx_info *vxi;
10687 +
10688 +       if (id < 0) {
10689 +               vxi = get_vx_info(current->vx_info);
10690 +       } else {
10691 +               rcu_read_lock();
10692 +               vxi = get_vx_info(__lookup_vx_info(id));
10693 +               rcu_read_unlock();
10694 +       }
10695 +       return vxi;
10696 +}
10697 +
10698 +/*     vx_info_is_hashed()
10699 +
10700 +       * verify that xid is still hashed                       */
10701 +
10702 +int vx_info_is_hashed(xid_t xid)
10703 +{
10704 +       int hashed;
10705 +
10706 +       rcu_read_lock();
10707 +       hashed = (__lookup_vx_info(xid) != NULL);
10708 +       rcu_read_unlock();
10709 +       return hashed;
10710 +}
10711 +
10712 +#ifdef CONFIG_VSERVER_LEGACY
10713 +
10714 +#if 0
10715 +struct vx_info *alloc_vx_info(xid_t xid)
10716 +{
10717 +       return __alloc_vx_info(xid);
10718 +}
10719 +#endif
10720 +
10721 +struct vx_info *locate_or_create_vx_info(int id)
10722 +{
10723 +       int err;
10724 +
10725 +       return __loc_vx_info(id, &err);
10726 +}
10727 +
10728 +#endif
10729 +
10730 +#ifdef CONFIG_PROC_FS
10731 +
10732 +int get_xid_list(int index, unsigned int *xids, int size)
10733 +{
10734 +       int hindex, nr_xids = 0;
10735 +
10736 +       rcu_read_lock();
10737 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
10738 +               struct hlist_head *head = &vx_info_hash[hindex];
10739 +               struct hlist_node *pos;
10740 +
10741 +               hlist_for_each_rcu(pos, head) {
10742 +                       struct vx_info *vxi;
10743 +
10744 +                       if (--index > 0)
10745 +                               continue;
10746 +
10747 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
10748 +                       xids[nr_xids] = vxi->vx_id;
10749 +                       if (++nr_xids >= size)
10750 +                               goto out;
10751 +               }
10752 +       }
10753 +out:
10754 +       rcu_read_unlock();
10755 +       return nr_xids;
10756 +}
10757 +#endif
10758 +
10759 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
10760 +{
10761 +       struct user_struct *new_user, *old_user;
10762 +
10763 +       if (!p || !vxi)
10764 +               BUG();
10765 +       new_user = alloc_uid(vxi->vx_id, p->uid);
10766 +       if (!new_user)
10767 +               return -ENOMEM;
10768 +
10769 +       old_user = p->user;
10770 +       if (new_user != old_user) {
10771 +               atomic_inc(&new_user->processes);
10772 +               atomic_dec(&old_user->processes);
10773 +               p->user = new_user;
10774 +       }
10775 +       free_uid(old_user);
10776 +       return 0;
10777 +}
10778 +
10779 +void vx_mask_bcaps(struct task_struct *p)
10780 +{
10781 +       struct vx_info *vxi = p->vx_info;
10782 +
10783 +       p->cap_effective &= vxi->vx_bcaps;
10784 +       p->cap_inheritable &= vxi->vx_bcaps;
10785 +       p->cap_permitted &= vxi->vx_bcaps;
10786 +}
10787 +
10788 +
10789 +#include <linux/file.h>
10790 +
10791 +static inline int vx_nofiles_task(struct task_struct *tsk)
10792 +{
10793 +       struct files_struct *files = tsk->files;
10794 +       unsigned long *obptr;
10795 +       int count, total;
10796 +
10797 +       spin_lock(&files->file_lock);
10798 +       obptr = files->open_fds->fds_bits;
10799 +       count = files->max_fds / (sizeof(unsigned long) * 8);
10800 +       for (total = 0; count > 0; count--) {
10801 +               if (*obptr)
10802 +                       total += hweight_long(*obptr);
10803 +               obptr++;
10804 +       }
10805 +       spin_unlock(&files->file_lock);
10806 +       return total;
10807 +}
10808 +
10809 +#if 0
10810 +
10811 +static inline int vx_openfd_task(struct task_struct *tsk)
10812 +{
10813 +       struct files_struct *files = tsk->files;
10814 +       const unsigned long *bptr;
10815 +       int count, total;
10816 +
10817 +       spin_lock(&files->file_lock);
10818 +       bptr = files->open_fds->fds_bits;
10819 +       count = files->max_fds / (sizeof(unsigned long) * 8);
10820 +       for (total = 0; count > 0; count--) {
10821 +               if (*bptr)
10822 +                       total += hweight_long(*bptr);
10823 +               bptr++;
10824 +       }
10825 +       spin_unlock(&files->file_lock);
10826 +       return total;
10827 +}
10828 +
10829 +#endif
10830 +
10831 +/*
10832 + *     migrate task to new context
10833 + *     gets vxi, puts old_vxi on change
10834 + */
10835 +
10836 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi)
10837 +{
10838 +       struct vx_info *old_vxi;
10839 +       int ret = 0;
10840 +
10841 +       if (!p || !vxi)
10842 +               BUG();
10843 +
10844 +       old_vxi = task_get_vx_info(p);
10845 +       if (old_vxi == vxi)
10846 +               goto out;
10847 +
10848 +       vxdprintk(VXD_CBIT(xid, 5),
10849 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
10850 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
10851 +
10852 +       if (!(ret = vx_migrate_user(p, vxi))) {
10853 +               int nofiles;
10854 +
10855 +               task_lock(p);
10856 +               // openfd = vx_openfd_task(p);
10857 +               nofiles = vx_nofiles_task(p);
10858 +
10859 +               if (old_vxi) {
10860 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
10861 +                       atomic_dec(&old_vxi->cvirt.nr_running);
10862 +                       atomic_dec(&old_vxi->limit.rcur[RLIMIT_NPROC]);
10863 +                       /* FIXME: what about the struct files here? */
10864 +                       // atomic_sub(nofiles, &old_vxi->limit.rcur[RLIMIT_NOFILE]);
10865 +                       // atomic_sub(openfd, &old_vxi->limit.rcur[RLIMIT_OPENFD]);
10866 +               }
10867 +               atomic_inc(&vxi->cvirt.nr_threads);
10868 +               atomic_inc(&vxi->cvirt.nr_running);
10869 +               atomic_inc(&vxi->limit.rcur[RLIMIT_NPROC]);
10870 +               /* FIXME: what about the struct files here? */
10871 +               // atomic_add(nofiles, &vxi->limit.rcur[RLIMIT_NOFILE]);
10872 +               // atomic_add(openfd, &vxi->limit.rcur[RLIMIT_OPENFD]);
10873 +
10874 +               vxdprintk(VXD_CBIT(xid, 5),
10875 +                       "moved task %p into vxi:%p[#%d]",
10876 +                       p, vxi, vxi->vx_id);
10877 +
10878 +               /* should be handled in set_vx_info !! */
10879 +               if (old_vxi)
10880 +                       clr_vx_info(&p->vx_info);
10881 +               set_vx_info(&p->vx_info, vxi);
10882 +               p->xid = vxi->vx_id;
10883 +               vx_mask_bcaps(p);
10884 +               task_unlock(p);
10885 +
10886 +               /* obsoleted by clr/set */
10887 +               // put_vx_info(old_vxi);
10888 +       }
10889 +out:
10890 +       put_vx_info(old_vxi);
10891 +       return ret;
10892 +}
10893 +
10894 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
10895 +{
10896 +       if (!vxi)
10897 +               return -EINVAL;
10898 +       if (vxi->vx_initpid)
10899 +               return -EPERM;
10900 +
10901 +       vxdprintk(VXD_CBIT(xid, 6),
10902 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
10903 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
10904 +
10905 +       vxi->vx_initpid = p->tgid;
10906 +       return 0;
10907 +}
10908 +
10909 +
10910 +/* vserver syscall commands below here */
10911 +
10912 +/* taks xid and vx_info functions */
10913 +
10914 +#include <asm/uaccess.h>
10915 +
10916 +
10917 +int vc_task_xid(uint32_t id, void __user *data)
10918 +{
10919 +       xid_t xid;
10920 +
10921 +       if (id) {
10922 +               struct task_struct *tsk;
10923 +
10924 +               if (!vx_check(0, VX_ADMIN|VX_WATCH))
10925 +                       return -EPERM;
10926 +
10927 +               read_lock(&tasklist_lock);
10928 +               tsk = find_task_by_real_pid(id);
10929 +               xid = (tsk) ? tsk->xid : -ESRCH;
10930 +               read_unlock(&tasklist_lock);
10931 +       }
10932 +       else
10933 +               xid = vx_current_xid();
10934 +       return xid;
10935 +}
10936 +
10937 +
10938 +int vc_vx_info(uint32_t id, void __user *data)
10939 +{
10940 +       struct vx_info *vxi;
10941 +       struct vcmd_vx_info_v0 vc_data;
10942 +
10943 +       if (!vx_check(0, VX_ADMIN))
10944 +               return -ENOSYS;
10945 +       if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RESOURCE))
10946 +               return -EPERM;
10947 +
10948 +       vxi = locate_vx_info(id);
10949 +       if (!vxi)
10950 +               return -ESRCH;
10951 +
10952 +       vc_data.xid = vxi->vx_id;
10953 +       vc_data.initpid = vxi->vx_initpid;
10954 +       put_vx_info(vxi);
10955 +
10956 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
10957 +               return -EFAULT;
10958 +       return 0;
10959 +}
10960 +
10961 +
10962 +/* context functions */
10963 +
10964 +int vc_ctx_create(uint32_t xid, void __user *data)
10965 +{
10966 +       struct vx_info *new_vxi;
10967 +       int ret;
10968 +
10969 +       if (!capable(CAP_SYS_ADMIN))
10970 +               return -EPERM;
10971 +
10972 +       if ((xid >= MIN_D_CONTEXT) && (xid != VX_DYNAMIC_ID))
10973 +               return -EINVAL;
10974 +
10975 +       if (xid < 1)
10976 +               return -EINVAL;
10977 +
10978 +       new_vxi = __loc_vx_info(xid, &ret);
10979 +       if (!new_vxi)
10980 +               return ret;
10981 +       if (!(new_vxi->vx_flags & VXF_STATE_SETUP)) {
10982 +               ret = -EEXIST;
10983 +               goto out_put;
10984 +       }
10985 +
10986 +       ret = new_vxi->vx_id;
10987 +       vx_migrate_task(current, new_vxi);
10988 +       /* if this fails, we might end up with a hashed vx_info */
10989 +out_put:
10990 +       put_vx_info(new_vxi);
10991 +       return ret;
10992 +}
10993 +
10994 +
10995 +int vc_ctx_migrate(uint32_t id, void __user *data)
10996 +{
10997 +       struct vx_info *vxi;
10998 +
10999 +       if (!capable(CAP_SYS_ADMIN))
11000 +               return -EPERM;
11001 +
11002 +       /* dirty hack until Spectator becomes a cap */
11003 +       if (id == 1) {
11004 +               current->xid = 1;
11005 +               return 0;
11006 +       }
11007 +
11008 +       vxi = locate_vx_info(id);
11009 +       if (!vxi)
11010 +               return -ESRCH;
11011 +       vx_migrate_task(current, vxi);
11012 +       put_vx_info(vxi);
11013 +       return 0;
11014 +}
11015 +
11016 +
11017 +int vc_get_cflags(uint32_t id, void __user *data)
11018 +{
11019 +       struct vx_info *vxi;
11020 +       struct vcmd_ctx_flags_v0 vc_data;
11021 +
11022 +       if (!capable(CAP_SYS_ADMIN))
11023 +               return -EPERM;
11024 +
11025 +       vxi = locate_vx_info(id);
11026 +       if (!vxi)
11027 +               return -ESRCH;
11028 +
11029 +       vc_data.flagword = vxi->vx_flags;
11030 +
11031 +       /* special STATE flag handling */
11032 +       vc_data.mask = vx_mask_flags(~0UL, vxi->vx_flags, VXF_ONE_TIME);
11033 +
11034 +       put_vx_info(vxi);
11035 +
11036 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
11037 +               return -EFAULT;
11038 +       return 0;
11039 +}
11040 +
11041 +int vc_set_cflags(uint32_t id, void __user *data)
11042 +{
11043 +       struct vx_info *vxi;
11044 +       struct vcmd_ctx_flags_v0 vc_data;
11045 +       uint64_t mask, trigger;
11046 +
11047 +       if (!capable(CAP_SYS_ADMIN))
11048 +               return -EPERM;
11049 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
11050 +               return -EFAULT;
11051 +
11052 +       vxi = locate_vx_info(id);
11053 +       if (!vxi)
11054 +               return -ESRCH;
11055 +
11056 +       /* special STATE flag handling */
11057 +       mask = vx_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
11058 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
11059 +
11060 +       if (trigger & VXF_STATE_SETUP)
11061 +               vx_mask_bcaps(current);
11062 +       if (trigger & VXF_STATE_INIT)
11063 +               if (vxi == current->vx_info)
11064 +                       vx_set_init(vxi, current);
11065 +
11066 +       vxi->vx_flags = vx_mask_flags(vxi->vx_flags,
11067 +               vc_data.flagword, mask);
11068 +       put_vx_info(vxi);
11069 +       return 0;
11070 +}
11071 +
11072 +int vc_get_ccaps(uint32_t id, void __user *data)
11073 +{
11074 +       struct vx_info *vxi;
11075 +       struct vcmd_ctx_caps_v0 vc_data;
11076 +
11077 +       if (!capable(CAP_SYS_ADMIN))
11078 +               return -EPERM;
11079 +
11080 +       vxi = locate_vx_info(id);
11081 +       if (!vxi)
11082 +               return -ESRCH;
11083 +
11084 +       vc_data.bcaps = vxi->vx_bcaps;
11085 +       vc_data.ccaps = vxi->vx_ccaps;
11086 +       vc_data.cmask = ~0UL;
11087 +       put_vx_info(vxi);
11088 +
11089 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
11090 +               return -EFAULT;
11091 +       return 0;
11092 +}
11093 +
11094 +int vc_set_ccaps(uint32_t id, void __user *data)
11095 +{
11096 +       struct vx_info *vxi;
11097 +       struct vcmd_ctx_caps_v0 vc_data;
11098 +
11099 +       if (!capable(CAP_SYS_ADMIN))
11100 +               return -EPERM;
11101 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
11102 +               return -EFAULT;
11103 +
11104 +       vxi = locate_vx_info(id);
11105 +       if (!vxi)
11106 +               return -ESRCH;
11107 +
11108 +       vxi->vx_bcaps &= vc_data.bcaps;
11109 +       vxi->vx_ccaps = vx_mask_flags(vxi->vx_ccaps,
11110 +               vc_data.ccaps, vc_data.cmask);
11111 +       put_vx_info(vxi);
11112 +       return 0;
11113 +}
11114 +
11115 +#include <linux/module.h>
11116 +
11117 +EXPORT_SYMBOL_GPL(free_vx_info);
11118 +EXPORT_SYMBOL_GPL(unhash_vx_info);
11119 +
11120 diff -NurpP --minimal linux-2.6.10/kernel/vserver/cvirt.c linux-2.6.10-vs1.9.3.17/kernel/vserver/cvirt.c
11121 --- linux-2.6.10/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
11122 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/cvirt.c      2004-12-26 19:40:30.000000000 +0100
11123 @@ -0,0 +1,97 @@
11124 +/*
11125 + *  linux/kernel/vserver/cvirt.c
11126 + *
11127 + *  Virtual Server: Context Virtualization
11128 + *
11129 + *  Copyright (C) 2004  Herbert Pötzl
11130 + *
11131 + *  V0.01  broken out from limit.c
11132 + *
11133 + */
11134 +
11135 +#include <linux/config.h>
11136 +#include <linux/sched.h>
11137 +#include <linux/types.h>
11138 +#include <linux/vs_context.h>
11139 +#include <linux/vs_cvirt.h>
11140 +#include <linux/vserver/switch.h>
11141 +
11142 +#include <asm/errno.h>
11143 +#include <asm/uaccess.h>
11144 +
11145 +
11146 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
11147 +{
11148 +       struct vx_info *vxi = current->vx_info;
11149 +
11150 +       set_normalized_timespec(uptime,
11151 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
11152 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
11153 +       if (!idle)
11154 +               return;
11155 +       set_normalized_timespec(idle,
11156 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
11157 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
11158 +       return;
11159 +}
11160 +
11161 +uint64_t vx_idle_jiffies(void)
11162 +{
11163 +       return init_task.utime + init_task.stime;
11164 +}
11165 +
11166 +
11167 +
11168 +static inline uint32_t __update_loadavg(uint32_t load,
11169 +       int wsize, int delta, int n)
11170 +{
11171 +       unsigned long long calc, prev;
11172 +
11173 +       /* just set it to n */
11174 +       if (unlikely(delta >= wsize))
11175 +               return (n << FSHIFT);
11176 +
11177 +       calc = delta * n;
11178 +       calc <<= FSHIFT;
11179 +       prev = (wsize - delta);
11180 +       prev *= load;
11181 +       calc += prev;
11182 +       do_div(calc, wsize);
11183 +       return calc;
11184 +}
11185 +
11186 +
11187 +void vx_update_load(struct vx_info *vxi)
11188 +{
11189 +       uint32_t now, last, delta;
11190 +       unsigned int nr_running, nr_uninterruptible;
11191 +       unsigned int total;
11192 +
11193 +       spin_lock(&vxi->cvirt.load_lock);
11194 +
11195 +       now = jiffies;
11196 +       last = vxi->cvirt.load_last;
11197 +       delta = now - last;
11198 +
11199 +       if (delta < 5*HZ)
11200 +               goto out;
11201 +
11202 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
11203 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
11204 +       total = nr_running + nr_uninterruptible;
11205 +
11206 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
11207 +               60*HZ, delta, total);
11208 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
11209 +               5*60*HZ, delta, total);
11210 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
11211 +               15*60*HZ, delta, total);
11212 +
11213 +       vxi->cvirt.load_last = now;
11214 +out:
11215 +       atomic_inc(&vxi->cvirt.load_updates);
11216 +       spin_unlock(&vxi->cvirt.load_lock);
11217 +}
11218 +
11219 +
11220 +
11221 diff -NurpP --minimal linux-2.6.10/kernel/vserver/cvirt_init.h linux-2.6.10-vs1.9.3.17/kernel/vserver/cvirt_init.h
11222 --- linux-2.6.10/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
11223 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/cvirt_init.h 2004-12-26 19:40:36.000000000 +0100
11224 @@ -0,0 +1,66 @@
11225 +
11226 +extern uint64_t vx_idle_jiffies(void);
11227 +
11228 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
11229 +{
11230 +       uint64_t idle_jiffies = vx_idle_jiffies();
11231 +       uint64_t nsuptime;
11232 +
11233 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
11234 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
11235 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
11236 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
11237 +
11238 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
11239 +       atomic_set(&cvirt->nr_threads, 0);
11240 +       atomic_set(&cvirt->nr_running, 0);
11241 +       atomic_set(&cvirt->nr_uninterruptible, 0);
11242 +       atomic_set(&cvirt->nr_onhold, 0);
11243 +
11244 +       down_read(&uts_sem);
11245 +       cvirt->utsname = system_utsname;
11246 +       up_read(&uts_sem);
11247 +
11248 +       spin_lock_init(&cvirt->load_lock);
11249 +       cvirt->load_last = jiffies;
11250 +       atomic_set(&cvirt->load_updates, 0);
11251 +       cvirt->load[0] = 0;
11252 +       cvirt->load[1] = 0;
11253 +       cvirt->load[2] = 0;
11254 +}
11255 +
11256 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
11257 +{
11258 +#ifdef CONFIG_VSERVER_DEBUG
11259 +       int value;
11260 +
11261 +       vxwprintk((value = atomic_read(&cvirt->nr_threads)),
11262 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
11263 +               cvirt, value);
11264 +       vxwprintk((value = atomic_read(&cvirt->nr_running)),
11265 +               "!!! cvirt: %p[nr_running] = %d on exit.",
11266 +               cvirt, value);
11267 +       vxwprintk((value = atomic_read(&cvirt->nr_uninterruptible)),
11268 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
11269 +               cvirt, value);
11270 +#endif
11271 +       return;
11272 +}
11273 +
11274 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
11275 +{
11276 +       int i,j;
11277 +
11278 +       for (i=0; i<5; i++) {
11279 +               for (j=0; j<3; j++) {
11280 +                       atomic_set(&cacct->sock[i][j].count, 0);
11281 +                       atomic_set(&cacct->sock[i][j].total, 0);
11282 +               }
11283 +       }
11284 +}
11285 +
11286 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
11287 +{
11288 +       return;
11289 +}
11290 +
11291 diff -NurpP --minimal linux-2.6.10/kernel/vserver/cvirt_proc.h linux-2.6.10-vs1.9.3.17/kernel/vserver/cvirt_proc.h
11292 --- linux-2.6.10/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
11293 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/cvirt_proc.h 2004-12-26 19:40:36.000000000 +0100
11294 @@ -0,0 +1,90 @@
11295 +#ifndef _VX_CVIRT_PROC_H
11296 +#define _VX_CVIRT_PROC_H
11297 +
11298 +#include <linux/sched.h>
11299 +
11300 +
11301 +#define LOAD_INT(x) ((x) >> FSHIFT)
11302 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
11303 +
11304 +static inline int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
11305 +{
11306 +       int length = 0;
11307 +       int a, b, c;
11308 +
11309 +       length += sprintf(buffer + length,
11310 +               "BiasUptime:\t%lu.%02lu\n",
11311 +                       (unsigned long)cvirt->bias_uptime.tv_sec,
11312 +                       (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
11313 +       length += sprintf(buffer + length,
11314 +               "SysName:\t%.*s\n"
11315 +               "NodeName:\t%.*s\n"
11316 +               "Release:\t%.*s\n"
11317 +               "Version:\t%.*s\n"
11318 +               "Machine:\t%.*s\n"
11319 +               "DomainName:\t%.*s\n"
11320 +               ,__NEW_UTS_LEN, cvirt->utsname.sysname
11321 +               ,__NEW_UTS_LEN, cvirt->utsname.nodename
11322 +               ,__NEW_UTS_LEN, cvirt->utsname.release
11323 +               ,__NEW_UTS_LEN, cvirt->utsname.version
11324 +               ,__NEW_UTS_LEN, cvirt->utsname.machine
11325 +               ,__NEW_UTS_LEN, cvirt->utsname.domainname
11326 +               );
11327 +
11328 +       a = cvirt->load[0] + (FIXED_1/200);
11329 +       b = cvirt->load[1] + (FIXED_1/200);
11330 +       c = cvirt->load[2] + (FIXED_1/200);
11331 +       length += sprintf(buffer + length,
11332 +               "nr_threads:\t%d\n"
11333 +               "nr_running:\t%d\n"
11334 +               "nr_unintr:\t%d\n"
11335 +               "nr_onhold:\t%d\n"
11336 +               "load_updates:\t%d\n"
11337 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
11338 +               ,atomic_read(&cvirt->nr_threads)
11339 +               ,atomic_read(&cvirt->nr_running)
11340 +               ,atomic_read(&cvirt->nr_uninterruptible)
11341 +               ,atomic_read(&cvirt->nr_onhold)
11342 +               ,atomic_read(&cvirt->load_updates)
11343 +               ,LOAD_INT(a), LOAD_FRAC(a)
11344 +               ,LOAD_INT(b), LOAD_FRAC(b)
11345 +               ,LOAD_INT(c), LOAD_FRAC(c)
11346 +               );
11347 +       return length;
11348 +}
11349 +
11350 +
11351 +static inline long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11352 +{
11353 +       return atomic_read(&cacct->sock[type][pos].count);
11354 +}
11355 +
11356 +
11357 +static inline long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11358 +{
11359 +       return atomic_read(&cacct->sock[type][pos].total);
11360 +}
11361 +
11362 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
11363 +{
11364 +       int i,j, length = 0;
11365 +       static char *type[] = { "UNSPEC", "UNIX", "INET", "INET6", "OTHER" };
11366 +
11367 +       for (i=0; i<5; i++) {
11368 +               length += sprintf(buffer + length,
11369 +                       "%s:", type[i]);
11370 +               for (j=0; j<3; j++) {
11371 +                       length += sprintf(buffer + length,
11372 +                               "\t%12lu/%-12lu"
11373 +                               ,vx_sock_count(cacct, i, j)
11374 +                               ,vx_sock_total(cacct, i, j)
11375 +                               );
11376 +               }
11377 +               buffer[length++] = '\n';
11378 +       }
11379 +       length += sprintf(buffer + length,
11380 +               "forks:\t%lu\n", cacct->total_forks);
11381 +       return length;
11382 +}
11383 +
11384 +#endif /* _VX_CVIRT_PROC_H */
11385 diff -NurpP --minimal linux-2.6.10/kernel/vserver/dlimit.c linux-2.6.10-vs1.9.3.17/kernel/vserver/dlimit.c
11386 --- linux-2.6.10/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
11387 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/dlimit.c     2004-12-26 19:40:35.000000000 +0100
11388 @@ -0,0 +1,450 @@
11389 +/*
11390 + *  linux/kernel/vserver/dlimit.c
11391 + *
11392 + *  Virtual Server: Context Disk Limits
11393 + *
11394 + *  Copyright (C) 2004  Herbert Pötzl
11395 + *
11396 + *  V0.01  initial version
11397 + *
11398 + */
11399 +
11400 +#include <linux/config.h>
11401 +#include <linux/fs.h>
11402 +#include <linux/namespace.h>
11403 +#include <linux/namei.h>
11404 +#include <linux/statfs.h>
11405 +#include <linux/vserver/switch.h>
11406 +#include <linux/vs_context.h>
11407 +#include <linux/vs_dlimit.h>
11408 +
11409 +#include <asm/errno.h>
11410 +#include <asm/uaccess.h>
11411 +
11412 +/*     __alloc_dl_info()
11413 +
11414 +       * allocate an initialized dl_info struct
11415 +       * doesn't make it visible (hash)                        */
11416 +
11417 +static struct dl_info *__alloc_dl_info(struct super_block *sb, xid_t xid)
11418 +{
11419 +       struct dl_info *new = NULL;
11420 +
11421 +       vxdprintk(VXD_CBIT(dlim, 5),
11422 +               "alloc_dl_info(%p,%d)*", sb, xid);
11423 +
11424 +       /* would this benefit from a slab cache? */
11425 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
11426 +       if (!new)
11427 +               return 0;
11428 +
11429 +       memset (new, 0, sizeof(struct dl_info));
11430 +       new->dl_xid = xid;
11431 +       new->dl_sb = sb;
11432 +       INIT_RCU_HEAD(&new->dl_rcu);
11433 +       INIT_HLIST_NODE(&new->dl_hlist);
11434 +       spin_lock_init(&new->dl_lock);
11435 +       atomic_set(&new->dl_refcnt, 0);
11436 +       atomic_set(&new->dl_usecnt, 0);
11437 +
11438 +       /* rest of init goes here */
11439 +
11440 +       vxdprintk(VXD_CBIT(dlim, 4),
11441 +               "alloc_dl_info(%p,%d) = %p", sb, xid, new);
11442 +       return new;
11443 +}
11444 +
11445 +/*     __dealloc_dl_info()
11446 +
11447 +       * final disposal of dl_info                             */
11448 +
11449 +static void __dealloc_dl_info(struct dl_info *dli)
11450 +{
11451 +       vxdprintk(VXD_CBIT(dlim, 4),
11452 +               "dealloc_dl_info(%p)", dli);
11453 +
11454 +       dli->dl_hlist.next = LIST_POISON1;
11455 +       dli->dl_xid = -1;
11456 +       dli->dl_sb = 0;
11457 +
11458 +       BUG_ON(atomic_read(&dli->dl_usecnt));
11459 +       BUG_ON(atomic_read(&dli->dl_refcnt));
11460 +
11461 +       kfree(dli);
11462 +}
11463 +
11464 +
11465 +/*     hash table for dl_info hash */
11466 +
11467 +#define DL_HASH_SIZE   13
11468 +
11469 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
11470 +
11471 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
11472 +
11473 +
11474 +static inline unsigned int __hashval(struct super_block *sb, xid_t xid)
11475 +{
11476 +       return ((xid ^ (unsigned long)sb) % DL_HASH_SIZE);
11477 +}
11478 +
11479 +
11480 +
11481 +/*     __hash_dl_info()
11482 +
11483 +       * add the dli to the global hash table
11484 +       * requires the hash_lock to be held                     */
11485 +
11486 +static inline void __hash_dl_info(struct dl_info *dli)
11487 +{
11488 +       struct hlist_head *head;
11489 +
11490 +       vxdprintk(VXD_CBIT(dlim, 6),
11491 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_xid);
11492 +       get_dl_info(dli);
11493 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_xid)];
11494 +       hlist_add_head_rcu(&dli->dl_hlist, head);
11495 +}
11496 +
11497 +/*     __unhash_dl_info()
11498 +
11499 +       * remove the dli from the global hash table
11500 +       * requires the hash_lock to be held                     */
11501 +
11502 +static inline void __unhash_dl_info(struct dl_info *dli)
11503 +{
11504 +       vxdprintk(VXD_CBIT(dlim, 6),
11505 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_xid);
11506 +       hlist_del_rcu(&dli->dl_hlist);
11507 +       put_dl_info(dli);
11508 +}
11509 +
11510 +
11511 +/*     __lookup_dl_info()
11512 +
11513 +       * requires the rcu_read_lock()
11514 +       * doesn't increment the dl_refcnt                       */
11515 +
11516 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, xid_t xid)
11517 +{
11518 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, xid)];
11519 +       struct hlist_node *pos;
11520 +
11521 +       hlist_for_each_rcu(pos, head) {
11522 +               struct dl_info *dli =
11523 +                       hlist_entry(pos, struct dl_info, dl_hlist);
11524 +
11525 +               if (dli->dl_xid == xid && dli->dl_sb == sb) {
11526 +                       return dli;
11527 +               }
11528 +       }
11529 +       return NULL;
11530 +}
11531 +
11532 +
11533 +struct dl_info *locate_dl_info(struct super_block *sb, xid_t xid)
11534 +{
11535 +       struct dl_info *dli;
11536 +
11537 +       rcu_read_lock();
11538 +       dli = get_dl_info(__lookup_dl_info(sb, xid));
11539 +       vxdprintk(VXD_CBIT(dlim, 7),
11540 +               "locate_dl_info(%p,#%d) = %p", sb, xid, dli);
11541 +       rcu_read_unlock();
11542 +       return dli;
11543 +}
11544 +
11545 +void rcu_free_dl_info(struct rcu_head *head)
11546 +{
11547 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
11548 +       int usecnt, refcnt;
11549 +
11550 +       BUG_ON(!dli || !head);
11551 +
11552 +       usecnt = atomic_read(&dli->dl_usecnt);
11553 +       BUG_ON(usecnt < 0);
11554 +
11555 +       refcnt = atomic_read(&dli->dl_refcnt);
11556 +       BUG_ON(refcnt < 0);
11557 +
11558 +       vxdprintk(VXD_CBIT(dlim, 3),
11559 +               "rcu_free_dl_info(%p)", dli);
11560 +       if (!usecnt)
11561 +               __dealloc_dl_info(dli);
11562 +       else
11563 +               printk("!!! rcu didn't free\n");
11564 +}
11565 +
11566 +
11567 +
11568 +
11569 +int vc_add_dlimit(uint32_t id, void __user *data)
11570 +{
11571 +       struct nameidata nd;
11572 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
11573 +       int ret;
11574 +
11575 +       if (!vx_check(0, VX_ADMIN))
11576 +               return -ENOSYS;
11577 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
11578 +               return -EFAULT;
11579 +
11580 +       ret = user_path_walk_link(vc_data.name, &nd);
11581 +       if (!ret) {
11582 +               struct super_block *sb;
11583 +               struct dl_info *dli;
11584 +
11585 +               ret = -EINVAL;
11586 +               if (!nd.dentry->d_inode)
11587 +                       goto out_release;
11588 +               if (!(sb = nd.dentry->d_inode->i_sb))
11589 +                       goto out_release;
11590 +
11591 +               dli = __alloc_dl_info(sb, id);
11592 +               spin_lock(&dl_info_hash_lock);
11593 +
11594 +               ret = -EEXIST;
11595 +               if (__lookup_dl_info(sb, id))
11596 +                       goto out_unlock;
11597 +               __hash_dl_info(dli);
11598 +               dli = NULL;
11599 +               ret = 0;
11600 +
11601 +       out_unlock:
11602 +               spin_unlock(&dl_info_hash_lock);
11603 +               if (dli)
11604 +                       __dealloc_dl_info(dli);
11605 +       out_release:
11606 +               path_release(&nd);
11607 +       }
11608 +       return ret;
11609 +}
11610 +
11611 +
11612 +int vc_rem_dlimit(uint32_t id, void __user *data)
11613 +{
11614 +       struct nameidata nd;
11615 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
11616 +       int ret;
11617 +
11618 +       if (!vx_check(0, VX_ADMIN))
11619 +               return -ENOSYS;
11620 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
11621 +               return -EFAULT;
11622 +
11623 +       ret = user_path_walk_link(vc_data.name, &nd);
11624 +       if (!ret) {
11625 +               struct super_block *sb;
11626 +               struct dl_info *dli;
11627 +
11628 +               ret = -EINVAL;
11629 +               if (!nd.dentry->d_inode)
11630 +                       goto out_release;
11631 +               if (!(sb = nd.dentry->d_inode->i_sb))
11632 +                       goto out_release;
11633 +
11634 +               spin_lock(&dl_info_hash_lock);
11635 +               dli = __lookup_dl_info(sb, id);
11636 +
11637 +               ret = -ESRCH;
11638 +               if (!dli)
11639 +                       goto out_unlock;
11640 +
11641 +               __unhash_dl_info(dli);
11642 +               ret = 0;
11643 +
11644 +       out_unlock:
11645 +               spin_unlock(&dl_info_hash_lock);
11646 +       out_release:
11647 +               path_release(&nd);
11648 +       }
11649 +       return ret;
11650 +}
11651 +
11652 +
11653 +int vc_set_dlimit(uint32_t id, void __user *data)
11654 +{
11655 +       struct nameidata nd;
11656 +       struct vcmd_ctx_dlimit_v0 vc_data;
11657 +       int ret;
11658 +
11659 +       if (!vx_check(0, VX_ADMIN))
11660 +               return -ENOSYS;
11661 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
11662 +               return -EFAULT;
11663 +
11664 +       ret = user_path_walk_link(vc_data.name, &nd);
11665 +       if (!ret) {
11666 +               struct super_block *sb;
11667 +               struct dl_info *dli;
11668 +
11669 +               ret = -EINVAL;
11670 +               if (!nd.dentry->d_inode)
11671 +                       goto out_release;
11672 +               if (!(sb = nd.dentry->d_inode->i_sb))
11673 +                       goto out_release;
11674 +               if ((vc_data.reserved != (uint32_t)CDLIM_KEEP &&
11675 +                       vc_data.reserved > 100) ||
11676 +                       (vc_data.inodes_used != (uint32_t)CDLIM_KEEP &&
11677 +                       vc_data.inodes_used > vc_data.inodes_total) ||
11678 +                       (vc_data.space_used != (uint32_t)CDLIM_KEEP &&
11679 +                       vc_data.space_used > vc_data.space_total))
11680 +                       goto out_release;
11681 +
11682 +               ret = -ESRCH;
11683 +               dli = locate_dl_info(sb, id);
11684 +               if (!dli)
11685 +                       goto out_release;
11686 +
11687 +               spin_lock(&dli->dl_lock);
11688 +
11689 +               if (vc_data.inodes_used != (uint32_t)CDLIM_KEEP)
11690 +                       dli->dl_inodes_used = vc_data.inodes_used;
11691 +               if (vc_data.inodes_total != (uint32_t)CDLIM_KEEP)
11692 +                       dli->dl_inodes_total = vc_data.inodes_total;
11693 +               if (vc_data.space_used != (uint32_t)CDLIM_KEEP) {
11694 +                       dli->dl_space_used = vc_data.space_used;
11695 +                       dli->dl_space_used <<= 10;
11696 +               }
11697 +               if (vc_data.space_total == (uint32_t)CDLIM_INFINITY)
11698 +                       dli->dl_space_total = (uint64_t)CDLIM_INFINITY;
11699 +               else if (vc_data.space_total != (uint32_t)CDLIM_KEEP) {
11700 +                       dli->dl_space_total = vc_data.space_total;
11701 +                       dli->dl_space_total <<= 10;
11702 +               }
11703 +               if (vc_data.reserved != (uint32_t)CDLIM_KEEP)
11704 +                       dli->dl_nrlmult = (1 << 10) * (100 - vc_data.reserved) / 100;
11705 +
11706 +               spin_unlock(&dli->dl_lock);
11707 +
11708 +               put_dl_info(dli);
11709 +               ret = 0;
11710 +
11711 +       out_release:
11712 +               path_release(&nd);
11713 +       }
11714 +       return ret;
11715 +}
11716 +
11717 +int vc_get_dlimit(uint32_t id, void __user *data)
11718 +{
11719 +       struct nameidata nd;
11720 +       struct vcmd_ctx_dlimit_v0 vc_data;
11721 +       int ret;
11722 +
11723 +       if (!vx_check(0, VX_ADMIN))
11724 +               return -ENOSYS;
11725 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
11726 +               return -EFAULT;
11727 +
11728 +       ret = user_path_walk_link(vc_data.name, &nd);
11729 +       if (!ret) {
11730 +               struct super_block *sb;
11731 +               struct dl_info *dli;
11732 +
11733 +               ret = -EINVAL;
11734 +               if (!nd.dentry->d_inode)
11735 +                       goto out_release;
11736 +               if (!(sb = nd.dentry->d_inode->i_sb))
11737 +                       goto out_release;
11738 +               if (vc_data.reserved > 100 ||
11739 +                       vc_data.inodes_used > vc_data.inodes_total ||
11740 +                       vc_data.space_used > vc_data.space_total)
11741 +                       goto out_release;
11742 +
11743 +               ret = -ESRCH;
11744 +               dli = locate_dl_info(sb, id);
11745 +               if (!dli)
11746 +                       goto out_release;
11747 +
11748 +               spin_lock(&dli->dl_lock);
11749 +               vc_data.inodes_used = dli->dl_inodes_used;
11750 +               vc_data.inodes_total = dli->dl_inodes_total;
11751 +               vc_data.space_used = dli->dl_space_used >> 10;
11752 +               if (dli->dl_space_total == (uint64_t)CDLIM_INFINITY)
11753 +                       vc_data.space_total = (uint32_t)CDLIM_INFINITY;
11754 +               else
11755 +                       vc_data.space_total = dli->dl_space_total >> 10;
11756 +
11757 +               vc_data.reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
11758 +               spin_unlock(&dli->dl_lock);
11759 +
11760 +               put_dl_info(dli);
11761 +               ret = -EFAULT;
11762 +               if (copy_to_user(data, &vc_data, sizeof(vc_data)))
11763 +                       goto out_release;
11764 +
11765 +               ret = 0;
11766 +       out_release:
11767 +               path_release(&nd);
11768 +       }
11769 +       return ret;
11770 +}
11771 +
11772 +
11773 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
11774 +{
11775 +       struct dl_info *dli;
11776 +       __u64 blimit, bfree, bavail;
11777 +       __u32 ifree;
11778 +
11779 +       dli = locate_dl_info(sb, vx_current_xid());
11780 +       if (!dli)
11781 +               return;
11782 +
11783 +       spin_lock(&dli->dl_lock);
11784 +       if (dli->dl_inodes_total == (uint32_t)CDLIM_INFINITY)
11785 +               goto no_ilim;
11786 +
11787 +       /* reduce max inodes available to limit */
11788 +       if (buf->f_files > dli->dl_inodes_total)
11789 +               buf->f_files = dli->dl_inodes_total;
11790 +
11791 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
11792 +       /* reduce free inodes to min */
11793 +       if (ifree < buf->f_ffree)
11794 +               buf->f_ffree = ifree;
11795 +
11796 +no_ilim:
11797 +       if (dli->dl_space_total == (uint64_t)CDLIM_INFINITY)
11798 +               goto no_blim;
11799 +
11800 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
11801 +
11802 +       if (dli->dl_space_total < dli->dl_space_used)
11803 +               bfree = 0;
11804 +       else
11805 +               bfree = (dli->dl_space_total - dli->dl_space_used)
11806 +                       >> sb->s_blocksize_bits;
11807 +
11808 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
11809 +       if (bavail < dli->dl_space_used)
11810 +               bavail = 0;
11811 +       else
11812 +               bavail = (bavail - dli->dl_space_used)
11813 +                       >> sb->s_blocksize_bits;
11814 +
11815 +       /* reduce max space available to limit */
11816 +       if (buf->f_blocks > blimit)
11817 +               buf->f_blocks = blimit;
11818 +
11819 +       /* reduce free space to min */
11820 +       if (bfree < buf->f_bfree)
11821 +               buf->f_bfree = bfree;
11822 +
11823 +       /* reduce avail space to min */
11824 +       if (bavail < buf->f_bavail)
11825 +               buf->f_bavail = bavail;
11826 +
11827 +no_blim:
11828 +       spin_unlock(&dli->dl_lock);
11829 +       put_dl_info(dli);
11830 +
11831 +       return;
11832 +}
11833 +
11834 +#include <linux/module.h>
11835 +
11836 +EXPORT_SYMBOL_GPL(locate_dl_info);
11837 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
11838 +
11839 diff -NurpP --minimal linux-2.6.10/kernel/vserver/helper.c linux-2.6.10-vs1.9.3.17/kernel/vserver/helper.c
11840 --- linux-2.6.10/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
11841 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/helper.c     2004-12-26 19:40:34.000000000 +0100
11842 @@ -0,0 +1,122 @@
11843 +/*
11844 + *  linux/kernel/vserver/helper.c
11845 + *
11846 + *  Virtual Context Support
11847 + *
11848 + *  Copyright (C) 2004  Herbert Pötzl
11849 + *
11850 + *  V0.01  basic helper
11851 + *
11852 + */
11853 +
11854 +#include <linux/config.h>
11855 +#include <linux/errno.h>
11856 +#include <linux/reboot.h>
11857 +#include <linux/kmod.h>
11858 +#include <linux/sched.h>
11859 +#include <linux/vs_context.h>
11860 +
11861 +#include <asm/uaccess.h>
11862 +#include <asm/unistd.h>
11863 +
11864 +
11865 +char vshelper_path[255] = "/sbin/vshelper";
11866 +
11867 +
11868 +/*
11869 + *      vshelper path is set via /proc/sys
11870 + *      invoked by vserver sys_reboot(), with
11871 + *      the following arguments
11872 + *
11873 + *      argv [0] = vshelper_path;
11874 + *      argv [1] = action: "restart", "halt", "poweroff", ...
11875 + *      argv [2] = context identifier
11876 + *      argv [3] = additional argument (restart2)
11877 + *
11878 + *      envp [*] = type-specific parameters
11879 + */
11880 +
11881 +long vs_reboot(unsigned int cmd, void * arg)
11882 +{
11883 +       char id_buf[8], cmd_buf[32];
11884 +       char uid_buf[32], pid_buf[32];
11885 +       char buffer[256];
11886 +
11887 +       char *argv[] = {vshelper_path, NULL, id_buf, NULL, 0};
11888 +       char *envp[] = {"HOME=/", "TERM=linux",
11889 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
11890 +                       uid_buf, pid_buf, cmd_buf, 0};
11891 +
11892 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vx_current_xid());
11893 +
11894 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
11895 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
11896 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
11897 +
11898 +       switch (cmd) {
11899 +       case LINUX_REBOOT_CMD_RESTART:
11900 +               argv[1] = "restart";
11901 +               break;
11902 +
11903 +       case LINUX_REBOOT_CMD_HALT:
11904 +               argv[1] = "halt";
11905 +               break;
11906 +
11907 +       case LINUX_REBOOT_CMD_POWER_OFF:
11908 +               argv[1] = "poweroff";
11909 +               break;
11910 +
11911 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
11912 +               argv[1] = "swsusp";
11913 +               break;
11914 +
11915 +       case LINUX_REBOOT_CMD_RESTART2:
11916 +               if (strncpy_from_user(&buffer[0], (char *)arg, sizeof(buffer) - 1) < 0)
11917 +                       return -EFAULT;
11918 +               argv[3] = buffer;
11919 +       default:
11920 +               argv[1] = "restart2";
11921 +               break;
11922 +       }
11923 +
11924 +       /* maybe we should wait ? */
11925 +       if (call_usermodehelper(*argv, argv, envp, 0)) {
11926 +               printk( KERN_WARNING
11927 +                       "vs_reboot(): failed to exec (%s %s %s %s)\n",
11928 +                       vshelper_path, argv[1], argv[2], argv[3]);
11929 +               return -EPERM;
11930 +       }
11931 +       return 0;
11932 +}
11933 +
11934 +long vs_context_state(unsigned int cmd)
11935 +{
11936 +       char id_buf[8], cmd_buf[32];
11937 +
11938 +       char *argv[] = {vshelper_path, NULL, id_buf, NULL, 0};
11939 +       char *envp[] = {"HOME=/", "TERM=linux",
11940 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
11941 +
11942 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vx_current_xid());
11943 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
11944 +
11945 +       switch (cmd) {
11946 +       case VS_CONTEXT_CREATED:
11947 +               argv[1] = "startup";
11948 +               break;
11949 +       case VS_CONTEXT_DESTROY:
11950 +               argv[1] = "shutdown";
11951 +               break;
11952 +       default:
11953 +               return 0;
11954 +       }
11955 +
11956 +       if (call_usermodehelper(*argv, argv, envp, 1)) {
11957 +               printk( KERN_WARNING
11958 +                       "vs_context_state(): failed to exec (%s %s %s %s)\n",
11959 +                       vshelper_path, argv[1], argv[2], argv[3]);
11960 +               return 0;
11961 +       }
11962 +       return 0;
11963 +}
11964 +
11965 diff -NurpP --minimal linux-2.6.10/kernel/vserver/history.c linux-2.6.10-vs1.9.3.17/kernel/vserver/history.c
11966 --- linux-2.6.10/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
11967 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/history.c    2005-01-04 17:56:33.000000000 +0100
11968 @@ -0,0 +1,167 @@
11969 +/*
11970 + *  kernel/vserver/history.c
11971 + *
11972 + *  Virtual Context History Backtrace
11973 + *
11974 + *  Copyright (C) 2004-2005  Herbert Pötzl
11975 + *
11976 + *  V0.01  basic structure
11977 + *  V0.02  hash/unhash and trace
11978 + *
11979 + */
11980 +
11981 +#include <linux/config.h>
11982 +#include <linux/errno.h>
11983 +#include <linux/module.h>
11984 +#include <linux/types.h>
11985 +#include <linux/ctype.h>
11986 +
11987 +#include <asm/uaccess.h>
11988 +#include <asm/atomic.h>
11989 +#include <asm/unistd.h>
11990 +
11991 +#include <linux/vserver/debug.h>
11992 +
11993 +
11994 +#ifdef CONFIG_VSERVER_HISTORY
11995 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
11996 +#else
11997 +#define VXH_SIZE       64
11998 +#endif
11999 +
12000 +struct _vx_history {
12001 +       unsigned int counter;
12002 +
12003 +       struct _vx_hist_entry entry[VXH_SIZE+1];
12004 +};
12005 +
12006 +
12007 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
12008 +
12009 +unsigned volatile int vxh_active = 1;
12010 +
12011 +static atomic_t sequence = ATOMIC_INIT(0);
12012 +
12013 +
12014 +struct _vx_hist_entry *vxh_advance(void *loc)
12015 +{
12016 +       unsigned int cpu = smp_processor_id();
12017 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
12018 +       struct _vx_hist_entry *entry;
12019 +       unsigned int index;
12020 +
12021 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
12022 +       entry = &hist->entry[index];
12023 +
12024 +       entry->seq = atomic_inc_return(&sequence);
12025 +       entry->loc = loc;
12026 +       return entry;
12027 +}
12028 +
12029 +
12030 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
12031 +
12032 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
12033 +
12034 +
12035 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
12036 +
12037 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                   \
12038 +                       (e)->vxi.ptr?(e)->vxi.xid:0,    \
12039 +                       (e)->vxi.ptr?(e)->vxi.usecnt:0, \
12040 +                       (e)->vxi.ptr?(e)->vxi.refcnt:0
12041 +
12042 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
12043 +{
12044 +       switch (e->type) {
12045 +       case VXH_THROW_OOPS:
12046 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
12047 +               break;
12048 +
12049 +       case VXH_GET_VX_INFO:
12050 +       case VXH_PUT_VX_INFO:
12051 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
12052 +                       VXH_LOC_ARGS(e),
12053 +                       (e->type==VXH_GET_VX_INFO)?"get":"put",
12054 +                       VXH_VXI_ARGS(e));
12055 +               break;
12056 +
12057 +       case VXH_SET_VX_INFO:
12058 +       case VXH_CLR_VX_INFO:
12059 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
12060 +                       VXH_LOC_ARGS(e),
12061 +                       (e->type==VXH_SET_VX_INFO)?"set":"clr",
12062 +                       VXH_VXI_ARGS(e), e->sc.data);
12063 +               break;
12064 +
12065 +       case VXH_ALLOC_VX_INFO:
12066 +       case VXH_DEALLOC_VX_INFO:
12067 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
12068 +                       VXH_LOC_ARGS(e),
12069 +                       (e->type==VXH_ALLOC_VX_INFO)?"alloc":"dealloc",
12070 +                       VXH_VXI_ARGS(e));
12071 +               break;
12072 +
12073 +       case VXH_HASH_VX_INFO:
12074 +       case VXH_UNHASH_VX_INFO:
12075 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
12076 +                       VXH_LOC_ARGS(e),
12077 +                       (e->type==VXH_HASH_VX_INFO)?"hash":"unhash",
12078 +                       VXH_VXI_ARGS(e));
12079 +               break;
12080 +
12081 +       case VXH_LOC_VX_INFO:
12082 +       case VXH_LOOKUP_VX_INFO:
12083 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
12084 +                       VXH_LOC_ARGS(e),
12085 +                       (e->type==VXH_LOC_VX_INFO)?"loc":"lookup",
12086 +                       e->ll.arg, VXH_VXI_ARGS(e));
12087 +               break;
12088 +       }
12089 +}
12090 +
12091 +static void __vxh_dump_history(void)
12092 +{
12093 +       unsigned int i,j;
12094 +
12095 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
12096 +               atomic_read(&sequence), NR_CPUS);
12097 +
12098 +       for (i=0; i < VXH_SIZE; i++) {
12099 +               for (j=0; j < NR_CPUS; j++) {
12100 +                       struct _vx_history *hist =
12101 +                               &per_cpu(vx_history_buffer, j);
12102 +                       unsigned int index = (hist->counter-i) % VXH_SIZE;
12103 +                       struct _vx_hist_entry *entry = &hist->entry[index];
12104 +
12105 +                       vxh_dump_entry(entry, j);
12106 +               }
12107 +       }
12108 +}
12109 +
12110 +void   vxh_dump_history(void)
12111 +{
12112 +       vxh_active = 0;
12113 +#ifdef CONFIG_SMP
12114 +       local_irq_enable();
12115 +       smp_send_stop();
12116 +       local_irq_disable();
12117 +#endif
12118 +       __vxh_dump_history();
12119 +}
12120 +
12121 +
12122 +/* vserver syscall commands below here */
12123 +
12124 +
12125 +int    vc_dump_history(uint32_t id)
12126 +{
12127 +       vxh_active = 0;
12128 +       __vxh_dump_history();
12129 +       vxh_active = 1;
12130 +
12131 +       return 0;
12132 +}
12133 +
12134 +EXPORT_SYMBOL_GPL(vxh_advance);
12135 +
12136 diff -NurpP --minimal linux-2.6.10/kernel/vserver/init.c linux-2.6.10-vs1.9.3.17/kernel/vserver/init.c
12137 --- linux-2.6.10/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
12138 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/init.c       2004-12-26 19:40:23.000000000 +0100
12139 @@ -0,0 +1,44 @@
12140 +/*
12141 + *  linux/kernel/init.c
12142 + *
12143 + *  Virtual Server Init
12144 + *
12145 + *  Copyright (C) 2004  Herbert Pötzl
12146 + *
12147 + *  V0.01  basic structure
12148 + *
12149 + */
12150 +
12151 +#include <linux/config.h>
12152 +#include <linux/errno.h>
12153 +#include <linux/init.h>
12154 +#include <linux/module.h>
12155 +
12156 +int    vserver_register_sysctl(void);
12157 +void   vserver_unregister_sysctl(void);
12158 +
12159 +
12160 +static int __init init_vserver(void)
12161 +{
12162 +       int ret = 0;
12163 +
12164 +#ifdef CONFIG_VSERVER_DEBUG
12165 +       vserver_register_sysctl();
12166 +#endif
12167 +       return ret;
12168 +}
12169 +
12170 +
12171 +static void __exit exit_vserver(void)
12172 +{
12173 +
12174 +#ifdef CONFIG_VSERVER_DEBUG
12175 +       vserver_unregister_sysctl();
12176 +#endif
12177 +       return;
12178 +}
12179 +
12180 +
12181 +module_init(init_vserver);
12182 +module_exit(exit_vserver);
12183 +
12184 diff -NurpP --minimal linux-2.6.10/kernel/vserver/inode.c linux-2.6.10-vs1.9.3.17/kernel/vserver/inode.c
12185 --- linux-2.6.10/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
12186 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/inode.c      2004-12-26 19:40:30.000000000 +0100
12187 @@ -0,0 +1,306 @@
12188 +/*
12189 + *  linux/kernel/vserver/inode.c
12190 + *
12191 + *  Virtual Server: File System Support
12192 + *
12193 + *  Copyright (C) 2004  Herbert Pötzl
12194 + *
12195 + *  V0.01  separated from vcontext V0.05
12196 + *
12197 + */
12198 +
12199 +#include <linux/config.h>
12200 +#include <linux/sched.h>
12201 +#include <linux/vs_context.h>
12202 +#include <linux/proc_fs.h>
12203 +#include <linux/devpts_fs.h>
12204 +#include <linux/namei.h>
12205 +#include <linux/mount.h>
12206 +#include <linux/parser.h>
12207 +#include <linux/vserver/inode.h>
12208 +#include <linux/vserver/xid.h>
12209 +
12210 +#include <asm/errno.h>
12211 +#include <asm/uaccess.h>
12212 +
12213 +
12214 +static int __vc_get_iattr(struct inode *in, uint32_t *xid, uint32_t *flags, uint32_t *mask)
12215 +{
12216 +       struct proc_dir_entry *entry;
12217 +
12218 +       if (!in || !in->i_sb)
12219 +               return -ESRCH;
12220 +
12221 +       *flags = IATTR_XID
12222 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
12223 +               | (IS_IUNLINK(in) ? IATTR_IUNLINK : 0)
12224 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
12225 +       *mask = IATTR_IUNLINK | IATTR_IMMUTABLE;
12226 +
12227 +       if (S_ISDIR(in->i_mode))
12228 +               *mask |= IATTR_BARRIER;
12229 +
12230 +       if (in->i_sb->s_flags & MS_TAGXID) {
12231 +               *xid = in->i_xid;
12232 +               *mask |= IATTR_XID;
12233 +       }
12234 +
12235 +       switch (in->i_sb->s_magic) {
12236 +       case PROC_SUPER_MAGIC:
12237 +               entry = PROC_I(in)->pde;
12238 +
12239 +               // check for specific inodes ?
12240 +               if (entry)
12241 +                       *mask |= IATTR_FLAGS;
12242 +               if (entry)
12243 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
12244 +               else
12245 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
12246 +               break;
12247 +
12248 +       case DEVPTS_SUPER_MAGIC:
12249 +               *xid = in->i_xid;
12250 +               *mask |= IATTR_XID;
12251 +               break;
12252 +
12253 +       default:
12254 +               break;
12255 +       }
12256 +       return 0;
12257 +}
12258 +
12259 +int vc_get_iattr(uint32_t id, void __user *data)
12260 +{
12261 +       struct nameidata nd;
12262 +       struct vcmd_ctx_iattr_v1 vc_data = { .xid = -1 };
12263 +       int ret;
12264 +
12265 +       if (!vx_check(0, VX_ADMIN))
12266 +               return -ENOSYS;
12267 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
12268 +               return -EFAULT;
12269 +
12270 +       ret = user_path_walk_link(vc_data.name, &nd);
12271 +       if (!ret) {
12272 +               ret = __vc_get_iattr(nd.dentry->d_inode,
12273 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
12274 +               path_release(&nd);
12275 +       }
12276 +
12277 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
12278 +               ret = -EFAULT;
12279 +       return ret;
12280 +}
12281 +
12282 +static int __vc_set_iattr(struct dentry *de, uint32_t *xid, uint32_t *flags, uint32_t *mask)
12283 +{
12284 +       struct inode *in = de->d_inode;
12285 +       int error = 0, is_proc = 0, has_xid = 0;
12286 +
12287 +       if (!in || !in->i_sb)
12288 +               return -ESRCH;
12289 +
12290 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
12291 +       if ((*mask & IATTR_FLAGS) && !is_proc)
12292 +               return -EINVAL;
12293 +
12294 +       has_xid = (in->i_sb->s_flags & MS_TAGXID) ||
12295 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
12296 +       if ((*mask & IATTR_XID) && !has_xid)
12297 +               return -EINVAL;
12298 +
12299 +       down(&in->i_sem);
12300 +       if (*mask & IATTR_XID)
12301 +               in->i_xid = *xid;
12302 +
12303 +       if (*mask & IATTR_FLAGS) {
12304 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
12305 +               unsigned int iflags = PROC_I(in)->vx_flags;
12306 +
12307 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
12308 +                       | (*flags & IATTR_FLAGS);
12309 +               PROC_I(in)->vx_flags = iflags;
12310 +               if (entry)
12311 +                       entry->vx_flags = iflags;
12312 +       }
12313 +
12314 +       if (*mask & (IATTR_BARRIER | IATTR_IUNLINK | IATTR_IMMUTABLE)) {
12315 +               struct iattr attr;
12316 +
12317 +               attr.ia_valid = ATTR_ATTR_FLAG;
12318 +               attr.ia_attr_flags =
12319 +                       (IS_IMMUTABLE(in) ? ATTR_FLAG_IMMUTABLE : 0) |
12320 +                       (IS_IUNLINK(in) ? ATTR_FLAG_IUNLINK : 0) |
12321 +                       (IS_BARRIER(in) ? ATTR_FLAG_BARRIER : 0);
12322 +
12323 +               if (*mask & IATTR_IMMUTABLE) {
12324 +                       if (*flags & IATTR_IMMUTABLE)
12325 +                               attr.ia_attr_flags |= ATTR_FLAG_IMMUTABLE;
12326 +                       else
12327 +                               attr.ia_attr_flags &= ~ATTR_FLAG_IMMUTABLE;
12328 +               }
12329 +               if (*mask & IATTR_IUNLINK) {
12330 +                       if (*flags & IATTR_IUNLINK)
12331 +                               attr.ia_attr_flags |= ATTR_FLAG_IUNLINK;
12332 +                       else
12333 +                               attr.ia_attr_flags &= ~ATTR_FLAG_IUNLINK;
12334 +               }
12335 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
12336 +                       if (*flags & IATTR_BARRIER)
12337 +                               attr.ia_attr_flags |= ATTR_FLAG_BARRIER;
12338 +                       else
12339 +                               attr.ia_attr_flags &= ~ATTR_FLAG_BARRIER;
12340 +               }
12341 +               if (in->i_op && in->i_op->setattr)
12342 +                       error = in->i_op->setattr(de, &attr);
12343 +               else {
12344 +                       error = inode_change_ok(in, &attr);
12345 +                       if (!error)
12346 +                               error = inode_setattr(in, &attr);
12347 +               }
12348 +       }
12349 +
12350 +       mark_inode_dirty(in);
12351 +       up(&in->i_sem);
12352 +       return 0;
12353 +}
12354 +
12355 +int vc_set_iattr(uint32_t id, void __user *data)
12356 +{
12357 +       struct nameidata nd;
12358 +       struct vcmd_ctx_iattr_v1 vc_data;
12359 +       int ret;
12360 +
12361 +       if (!capable(CAP_SYS_ADMIN) || !capable(CAP_LINUX_IMMUTABLE))
12362 +               return -EPERM;
12363 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
12364 +               return -EFAULT;
12365 +
12366 +       ret = user_path_walk_link(vc_data.name, &nd);
12367 +       if (!ret) {
12368 +               ret = __vc_set_iattr(nd.dentry,
12369 +                       &vc_data.xid, &vc_data.flags, &vc_data.mask);
12370 +               path_release(&nd);
12371 +       }
12372 +
12373 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
12374 +               ret = -EFAULT;
12375 +       return ret;
12376 +}
12377 +
12378 +
12379 +#ifdef CONFIG_VSERVER_LEGACY
12380 +
12381 +#define PROC_DYNAMIC_FIRST 0xF0000000UL
12382 +
12383 +int vx_proc_ioctl(struct inode * inode, struct file * filp,
12384 +       unsigned int cmd, unsigned long arg)
12385 +{
12386 +       struct proc_dir_entry *entry;
12387 +       int error = 0;
12388 +       int flags;
12389 +
12390 +       if (inode->i_ino < PROC_DYNAMIC_FIRST)
12391 +               return -ENOTTY;
12392 +
12393 +       entry = PROC_I(inode)->pde;
12394 +       if (!entry)
12395 +               return -ENOTTY;
12396 +
12397 +       switch(cmd) {
12398 +       case FIOC_GETXFLG: {
12399 +               /* fixme: if stealth, return -ENOTTY */
12400 +               error = -EPERM;
12401 +               flags = entry->vx_flags;
12402 +               if (capable(CAP_CONTEXT))
12403 +                       error = put_user(flags, (int *) arg);
12404 +               break;
12405 +       }
12406 +       case FIOC_SETXFLG: {
12407 +               /* fixme: if stealth, return -ENOTTY */
12408 +               error = -EPERM;
12409 +               if (!capable(CAP_CONTEXT))
12410 +                       break;
12411 +               error = -EROFS;
12412 +               if (IS_RDONLY(inode))
12413 +                       break;
12414 +               error = -EFAULT;
12415 +               if (get_user(flags, (int *) arg))
12416 +                       break;
12417 +               error = 0;
12418 +               entry->vx_flags = flags;
12419 +               break;
12420 +       }
12421 +       default:
12422 +               return -ENOTTY;
12423 +       }
12424 +       return error;
12425 +}
12426 +#endif
12427 +
12428 +
12429 +int vx_parse_xid(char *string, xid_t *xid, int remove)
12430 +{
12431 +       static match_table_t tokens = {
12432 +               {1, "xid=%u"},
12433 +               {0, NULL}
12434 +       };
12435 +       substring_t args[MAX_OPT_ARGS];
12436 +       int token, option = 0;
12437 +
12438 +       if (!string)
12439 +               return 0;
12440 +
12441 +       token = match_token(string, tokens, args);
12442 +       if (token && xid && !match_int(args, &option))
12443 +               *xid = option;
12444 +
12445 +       vxdprintk(VXD_CBIT(xid, 7),
12446 +               "vx_parse_xid(»%s«): %d:#%d",
12447 +               string, token, option);
12448 +
12449 +       if (token && remove) {
12450 +               char *p = strstr(string, "xid=");
12451 +               char *q = p;
12452 +
12453 +               if (p) {
12454 +                       while (*q != '\0' && *q != ',')
12455 +                               q++;
12456 +                       while (*q)
12457 +                               *p++ = *q++;
12458 +                       while (*p)
12459 +                               *p++ = '\0';
12460 +               }
12461 +       }
12462 +       return token;
12463 +}
12464 +
12465 +void vx_propagate_xid(struct nameidata *nd, struct inode *inode)
12466 +{
12467 +       xid_t new_xid = 0;
12468 +       struct vfsmount *mnt;
12469 +       int propagate;
12470 +
12471 +       if (!nd)
12472 +               return;
12473 +       mnt = nd->mnt;
12474 +       if (!mnt)
12475 +               return;
12476 +
12477 +       propagate = (mnt->mnt_flags & MNT_XID);
12478 +       if (propagate)
12479 +               new_xid = mnt->mnt_xid;
12480 +
12481 +       vxdprintk(VXD_CBIT(xid, 7),
12482 +               "vx_propagate_xid(%p[#%lu.%d]): %d,%d",
12483 +               inode, inode->i_ino, inode->i_xid,
12484 +               new_xid, (propagate)?1:0);
12485 +
12486 +       if (propagate)
12487 +               inode->i_xid = new_xid;
12488 +}
12489 +
12490 +#include <linux/module.h>
12491 +
12492 +EXPORT_SYMBOL_GPL(vx_propagate_xid);
12493 +
12494 diff -NurpP --minimal linux-2.6.10/kernel/vserver/legacy.c linux-2.6.10-vs1.9.3.17/kernel/vserver/legacy.c
12495 --- linux-2.6.10/kernel/vserver/legacy.c        1970-01-01 01:00:00.000000000 +0100
12496 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/legacy.c     2004-12-26 19:40:36.000000000 +0100
12497 @@ -0,0 +1,176 @@
12498 +/*
12499 + *  linux/kernel/vserver/legacy.c
12500 + *
12501 + *  Virtual Server: Legacy Funtions
12502 + *
12503 + *  Copyright (C) 2001-2003  Jacques Gelinas
12504 + *  Copyright (C) 2003-2004  Herbert Pötzl
12505 + *
12506 + *  V0.01  broken out from vcontext.c V0.05
12507 + *
12508 + */
12509 +
12510 +#include <linux/config.h>
12511 +#include <linux/sched.h>
12512 +#include <linux/vs_context.h>
12513 +#include <linux/vs_network.h>
12514 +#include <linux/vserver/legacy.h>
12515 +#include <linux/vserver/namespace.h>
12516 +#include <linux/namespace.h>
12517 +
12518 +#include <asm/errno.h>
12519 +#include <asm/uaccess.h>
12520 +
12521 +
12522 +
12523 +static int vx_set_initpid(struct vx_info *vxi, int pid)
12524 +{
12525 +       if (vxi->vx_initpid)
12526 +               return -EPERM;
12527 +
12528 +       vxi->vx_initpid = pid;
12529 +       return 0;
12530 +}
12531 +
12532 +int vc_new_s_context(uint32_t ctx, void __user *data)
12533 +{
12534 +       int ret = -ENOMEM;
12535 +       struct vcmd_new_s_context_v1 vc_data;
12536 +       struct vx_info *new_vxi;
12537 +
12538 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
12539 +               return -EFAULT;
12540 +
12541 +       /* legacy hack, will be removed soon */
12542 +       if (ctx == -2) {
12543 +               /* assign flags and initpid */
12544 +               if (!current->vx_info)
12545 +                       return -EINVAL;
12546 +               ret = 0;
12547 +               if (vc_data.flags & VX_INFO_INIT)
12548 +                       ret = vx_set_initpid(current->vx_info, current->tgid);
12549 +               if (ret == 0) {
12550 +                       /* We keep the same vx_id, but lower the capabilities */
12551 +                       current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
12552 +                       // current->cap_bset &= (~vc_data.remove_cap);
12553 +                       ret = vx_current_xid();
12554 +                       current->vx_info->vx_flags |= vc_data.flags;
12555 +               }
12556 +               return ret;
12557 +       }
12558 +
12559 +       if (!vx_check(0, VX_ADMIN) || !capable(CAP_SYS_ADMIN)
12560 +               /* might make sense in the future, or not ... */
12561 +               || vx_flags(VX_INFO_LOCK, 0))
12562 +               return -EPERM;
12563 +
12564 +       /* ugly hack for Spectator */
12565 +       if (ctx == 1) {
12566 +               current->xid = 1;
12567 +               return 0;
12568 +       }
12569 +
12570 +       if (((ctx > MAX_S_CONTEXT) && (ctx != VX_DYNAMIC_ID)) ||
12571 +               (ctx == 0))
12572 +               return -EINVAL;
12573 +
12574 +       if ((ctx == VX_DYNAMIC_ID) || (ctx < MIN_D_CONTEXT))
12575 +               new_vxi = locate_or_create_vx_info(ctx);
12576 +       else
12577 +               new_vxi = locate_vx_info(ctx);
12578 +
12579 +       if (!new_vxi)
12580 +               return -EINVAL;
12581 +
12582 +       ret = -EPERM;
12583 +       if (!vx_info_flags(new_vxi, VXF_STATE_SETUP, 0) &&
12584 +               vx_info_flags(new_vxi, VX_INFO_PRIVATE, 0))
12585 +               goto out_put;
12586 +
12587 +       new_vxi->vx_flags &= ~(VXF_STATE_SETUP|VXF_STATE_INIT);
12588 +
12589 +       ret = vx_migrate_task(current, new_vxi);
12590 +       if (ret == 0) {
12591 +               current->vx_info->vx_bcaps &= (~vc_data.remove_cap);
12592 +               // current->cap_bset &= (~vc_data.remove_cap);
12593 +               new_vxi->vx_flags |= vc_data.flags;
12594 +               if (vc_data.flags & VX_INFO_INIT)
12595 +                       vx_set_initpid(new_vxi, current->tgid);
12596 +               if (vc_data.flags & VX_INFO_NAMESPACE)
12597 +                       vx_set_namespace(new_vxi,
12598 +                               current->namespace, current->fs);
12599 +               if (vc_data.flags & VX_INFO_NPROC)
12600 +                       new_vxi->limit.rlim[RLIMIT_NPROC] =
12601 +                               current->signal->rlim[RLIMIT_NPROC].rlim_max;
12602 +               ret = new_vxi->vx_id;
12603 +       }
12604 +out_put:
12605 +       put_vx_info(new_vxi);
12606 +       return ret;
12607 +}
12608 +
12609 +
12610 +extern struct nx_info *create_nx_info(void);
12611 +
12612 +/*  set ipv4 root (syscall) */
12613 +
12614 +int vc_set_ipv4root(uint32_t nbip, void __user *data)
12615 +{
12616 +       int i, err = -EPERM;
12617 +       struct vcmd_set_ipv4root_v3 vc_data;
12618 +       struct nx_info *new_nxi, *nxi = current->nx_info;
12619 +
12620 +       if (nbip < 0 || nbip > NB_IPV4ROOT)
12621 +               return -EINVAL;
12622 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
12623 +               return -EFAULT;
12624 +
12625 +       if (!nxi || nxi->ipv4[0] == 0 || capable(CAP_NET_ADMIN))
12626 +               // We are allowed to change everything
12627 +               err = 0;
12628 +       else if (nxi) {
12629 +               int found = 0;
12630 +
12631 +               // We are allowed to select a subset of the currently
12632 +               // installed IP numbers. No new one allowed
12633 +               // We can't change the broadcast address though
12634 +               for (i=0; i<nbip; i++) {
12635 +                       int j;
12636 +                       __u32 nxip = vc_data.nx_mask_pair[i].ip;
12637 +                       for (j=0; j<nxi->nbipv4; j++) {
12638 +                               if (nxip == nxi->ipv4[j]) {
12639 +                                       found++;
12640 +                                       break;
12641 +                               }
12642 +                       }
12643 +               }
12644 +               if ((found == nbip) &&
12645 +                       (vc_data.broadcast == nxi->v4_bcast))
12646 +                       err = 0;
12647 +       }
12648 +       if (err)
12649 +               return err;
12650 +
12651 +       new_nxi = create_nx_info();
12652 +       if (!new_nxi)
12653 +               return -EINVAL;
12654 +
12655 +       new_nxi->nbipv4 = nbip;
12656 +       for (i=0; i<nbip; i++) {
12657 +               new_nxi->ipv4[i] = vc_data.nx_mask_pair[i].ip;
12658 +               new_nxi->mask[i] = vc_data.nx_mask_pair[i].mask;
12659 +       }
12660 +       new_nxi->v4_bcast = vc_data.broadcast;
12661 +       // current->nx_info = new_nxi;
12662 +       if (nxi) {
12663 +               printk("!!! switching nx_info %p->%p\n", nxi, new_nxi);
12664 +               clr_nx_info(&current->nx_info);
12665 +       }
12666 +       nx_migrate_task(current, new_nxi);
12667 +       // set_nx_info(&current->nx_info, new_nxi);
12668 +       // current->nid = new_nxi->nx_id;
12669 +       put_nx_info(new_nxi);
12670 +       return 0;
12671 +}
12672 +
12673 +
12674 diff -NurpP --minimal linux-2.6.10/kernel/vserver/limit.c linux-2.6.10-vs1.9.3.17/kernel/vserver/limit.c
12675 --- linux-2.6.10/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
12676 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/limit.c      2004-12-26 19:40:35.000000000 +0100
12677 @@ -0,0 +1,165 @@
12678 +/*
12679 + *  linux/kernel/vserver/limit.c
12680 + *
12681 + *  Virtual Server: Context Limits
12682 + *
12683 + *  Copyright (C) 2004  Herbert Pötzl
12684 + *
12685 + *  V0.01  broken out from vcontext V0.05
12686 + *
12687 + */
12688 +
12689 +#include <linux/config.h>
12690 +#include <linux/module.h>
12691 +#include <linux/vs_context.h>
12692 +#include <linux/vs_limit.h>
12693 +#include <linux/vserver/limit.h>
12694 +#include <linux/vserver/switch.h>
12695 +#include <linux/vserver/limit_cmd.h>
12696 +
12697 +#include <asm/errno.h>
12698 +#include <asm/uaccess.h>
12699 +
12700 +
12701 +const char *vlimit_name[NUM_LIMITS] = {
12702 +       [RLIMIT_CPU]            = "CPU",
12703 +       [RLIMIT_RSS]            = "RSS",
12704 +       [RLIMIT_NPROC]          = "NPROC",
12705 +       [RLIMIT_NOFILE] = "NOFILE",
12706 +       [RLIMIT_MEMLOCK]        = "VML",
12707 +       [RLIMIT_AS]             = "VM",
12708 +       [RLIMIT_LOCKS]          = "LOCKS",
12709 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
12710 +       [VLIMIT_NSOCK]          = "NSOCK",
12711 +};
12712 +
12713 +EXPORT_SYMBOL_GPL(vlimit_name);
12714 +
12715 +
12716 +static int is_valid_rlimit(int id)
12717 +{
12718 +       int valid = 0;
12719 +
12720 +       switch (id) {
12721 +               case RLIMIT_NPROC:
12722 +               case RLIMIT_AS:
12723 +               case RLIMIT_RSS:
12724 +               case RLIMIT_MEMLOCK:
12725 +               case RLIMIT_NOFILE:
12726 +                       valid = 1;
12727 +                       break;
12728 +       }
12729 +       return valid;
12730 +}
12731 +
12732 +static inline uint64_t vc_get_rlim(struct vx_info *vxi, int id)
12733 +{
12734 +       unsigned long limit;
12735 +
12736 +       limit = vxi->limit.rlim[id];
12737 +       if (limit == RLIM_INFINITY)
12738 +               return CRLIM_INFINITY;
12739 +       return limit;
12740 +}
12741 +
12742 +int vc_get_rlimit(uint32_t id, void __user *data)
12743 +{
12744 +       struct vx_info *vxi;
12745 +       struct vcmd_ctx_rlimit_v0 vc_data;
12746 +
12747 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
12748 +               return -EFAULT;
12749 +       if (!is_valid_rlimit(vc_data.id))
12750 +               return -ENOTSUPP;
12751 +
12752 +       vxi = locate_vx_info(id);
12753 +       if (!vxi)
12754 +               return -ESRCH;
12755 +
12756 +       vc_data.maximum = vc_get_rlim(vxi, vc_data.id);
12757 +       vc_data.minimum = CRLIM_UNSET;
12758 +       vc_data.softlimit = CRLIM_UNSET;
12759 +       put_vx_info(vxi);
12760 +
12761 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
12762 +               return -EFAULT;
12763 +       return 0;
12764 +}
12765 +
12766 +int vc_set_rlimit(uint32_t id, void __user *data)
12767 +{
12768 +       struct vx_info *vxi;
12769 +       struct vcmd_ctx_rlimit_v0 vc_data;
12770 +
12771 +       if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RESOURCE))
12772 +               return -EPERM;
12773 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
12774 +               return -EFAULT;
12775 +       if (!is_valid_rlimit(vc_data.id))
12776 +               return -ENOTSUPP;
12777 +
12778 +       vxi = locate_vx_info(id);
12779 +       if (!vxi)
12780 +               return -ESRCH;
12781 +
12782 +       if (vc_data.maximum != CRLIM_KEEP)
12783 +               vxi->limit.rlim[vc_data.id] = vc_data.maximum;
12784 +       put_vx_info(vxi);
12785 +
12786 +       return 0;
12787 +}
12788 +
12789 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
12790 +{
12791 +       static struct vcmd_ctx_rlimit_mask_v0 mask = {
12792 +                       /* minimum */
12793 +               0
12794 +               ,       /* softlimit */
12795 +               0
12796 +               ,       /* maximum */
12797 +               (1 << RLIMIT_NPROC) |
12798 +               (1 << RLIMIT_NOFILE) |
12799 +               (1 << RLIMIT_MEMLOCK) |
12800 +               (1 << RLIMIT_AS) |
12801 +               (1 << RLIMIT_RSS)
12802 +               };
12803 +
12804 +       if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RESOURCE))
12805 +               return -EPERM;
12806 +       if (copy_to_user(data, &mask, sizeof(mask)))
12807 +               return -EFAULT;
12808 +       return 0;
12809 +}
12810 +
12811 +
12812 +void vx_vsi_meminfo(struct sysinfo *val)
12813 +{
12814 +       struct vx_info *vxi = current->vx_info;
12815 +       unsigned long v;
12816 +
12817 +       v = vxi->limit.rlim[RLIMIT_RSS];
12818 +       if (v != RLIM_INFINITY)
12819 +               val->totalram = min(val->totalram, v);
12820 +       v = atomic_read(&vxi->limit.rcur[RLIMIT_RSS]);
12821 +       val->freeram = (v < val->totalram) ? val->totalram - v : 0;
12822 +       val->bufferram = 0;
12823 +       val->totalhigh = 0;
12824 +       val->freehigh = 0;
12825 +       return;
12826 +}
12827 +
12828 +void vx_vsi_swapinfo(struct sysinfo *val)
12829 +{
12830 +       struct vx_info *vxi = current->vx_info;
12831 +       unsigned long v, w;
12832 +
12833 +       v = vxi->limit.rlim[RLIMIT_RSS];
12834 +       w = vxi->limit.rlim[RLIMIT_AS];
12835 +       if (w != RLIM_INFINITY)
12836 +               val->totalswap = min(val->totalswap, w -
12837 +               ((v != RLIM_INFINITY) ? v : 0));
12838 +       w = atomic_read(&vxi->limit.rcur[RLIMIT_AS]);
12839 +       val->freeswap = (w < val->totalswap) ? val->totalswap - w : 0;
12840 +       return;
12841 +}
12842 +
12843 diff -NurpP --minimal linux-2.6.10/kernel/vserver/limit_init.h linux-2.6.10-vs1.9.3.17/kernel/vserver/limit_init.h
12844 --- linux-2.6.10/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
12845 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/limit_init.h 2004-12-26 19:40:36.000000000 +0100
12846 @@ -0,0 +1,28 @@
12847 +
12848 +static inline void vx_info_init_limit(struct _vx_limit *limit)
12849 +{
12850 +       int lim;
12851 +
12852 +       for (lim=0; lim<NUM_LIMITS; lim++) {
12853 +               limit->rlim[lim] = RLIM_INFINITY;
12854 +               limit->rmax[lim] = 0;
12855 +               atomic_set(&limit->rcur[lim], 0);
12856 +               atomic_set(&limit->lhit[lim], 0);
12857 +       }
12858 +}
12859 +
12860 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
12861 +{
12862 +#ifdef CONFIG_VSERVER_DEBUG
12863 +       unsigned long value;
12864 +       unsigned int lim;
12865 +
12866 +       for (lim=0; lim<NUM_LIMITS; lim++) {
12867 +               value = atomic_read(&limit->rcur[lim]);
12868 +               vxwprintk(value,
12869 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
12870 +                       limit, vlimit_name[lim], lim, value);
12871 +       }
12872 +#endif
12873 +}
12874 +
12875 diff -NurpP --minimal linux-2.6.10/kernel/vserver/limit_proc.h linux-2.6.10-vs1.9.3.17/kernel/vserver/limit_proc.h
12876 --- linux-2.6.10/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
12877 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/limit_proc.h 2004-12-26 19:40:36.000000000 +0100
12878 @@ -0,0 +1,48 @@
12879 +#ifndef _VX_LIMIT_PROC_H
12880 +#define _VX_LIMIT_PROC_H
12881 +
12882 +
12883 +static inline void vx_limit_fixup(struct _vx_limit *limit)
12884 +{
12885 +       unsigned long value;
12886 +       unsigned int lim;
12887 +
12888 +       for (lim=0; lim<NUM_LIMITS; lim++) {
12889 +               value = atomic_read(&limit->rcur[lim]);
12890 +               if (value > limit->rmax[lim])
12891 +                       limit->rmax[lim] = value;
12892 +               if (limit->rmax[lim] > limit->rlim[lim])
12893 +                       limit->rmax[lim] = limit->rlim[lim];
12894 +       }
12895 +}
12896 +
12897 +#define VX_LIMIT_FMT   ":\t%10d\t%10ld\t%10ld\t%6d\n"
12898 +
12899 +#define VX_LIMIT_ARG(r)                                \
12900 +               ,atomic_read(&limit->rcur[r])   \
12901 +               ,limit->rmax[r]                 \
12902 +               ,limit->rlim[r]                 \
12903 +               ,atomic_read(&limit->lhit[r])
12904 +
12905 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
12906 +{
12907 +       vx_limit_fixup(limit);
12908 +       return sprintf(buffer,
12909 +               "PROC"  VX_LIMIT_FMT
12910 +               "VM"    VX_LIMIT_FMT
12911 +               "VML"   VX_LIMIT_FMT
12912 +               "RSS"   VX_LIMIT_FMT
12913 +               "FILES" VX_LIMIT_FMT
12914 +               "SOCK"  VX_LIMIT_FMT
12915 +               VX_LIMIT_ARG(RLIMIT_NPROC)
12916 +               VX_LIMIT_ARG(RLIMIT_AS)
12917 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK)
12918 +               VX_LIMIT_ARG(RLIMIT_RSS)
12919 +               VX_LIMIT_ARG(RLIMIT_NOFILE)
12920 +               VX_LIMIT_ARG(VLIMIT_NSOCK)
12921 +               );
12922 +}
12923 +
12924 +#endif /* _VX_LIMIT_PROC_H */
12925 +
12926 +
12927 diff -NurpP --minimal linux-2.6.10/kernel/vserver/namespace.c linux-2.6.10-vs1.9.3.17/kernel/vserver/namespace.c
12928 --- linux-2.6.10/kernel/vserver/namespace.c     1970-01-01 01:00:00.000000000 +0100
12929 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/namespace.c  2004-12-26 19:40:29.000000000 +0100
12930 @@ -0,0 +1,240 @@
12931 +/*
12932 + *  linux/kernel/vserver/namespace.c
12933 + *
12934 + *  Virtual Server: Context Namespace Support
12935 + *
12936 + *  Copyright (C) 2003-2004  Herbert Pötzl
12937 + *
12938 + *  V0.01  broken out from context.c 0.07
12939 + *  V0.02  added task locking for namespace
12940 + *
12941 + */
12942 +
12943 +#include <linux/config.h>
12944 +#include <linux/utsname.h>
12945 +#include <linux/sched.h>
12946 +#include <linux/vs_context.h>
12947 +#include <linux/vserver/namespace.h>
12948 +#include <linux/dcache.h>
12949 +#include <linux/mount.h>
12950 +#include <linux/fs.h>
12951 +
12952 +#include <asm/errno.h>
12953 +#include <asm/uaccess.h>
12954 +
12955 +
12956 +int vx_check_vfsmount(struct vx_info *vxi, struct vfsmount *mnt)
12957 +{
12958 +       struct vfsmount *root_mnt, *altroot_mnt;
12959 +       struct dentry *root, *altroot, *point;
12960 +       int r1, r2, s1, s2, ret = 0;
12961 +
12962 +       if (!vxi || !mnt)
12963 +               return 1;
12964 +
12965 +       spin_lock(&dcache_lock);
12966 +       altroot_mnt = current->fs->rootmnt;
12967 +       altroot = current->fs->root;
12968 +       point = altroot;
12969 +
12970 +       if (vxi->vx_fs) {
12971 +               root_mnt = vxi->vx_fs->rootmnt;
12972 +               root = vxi->vx_fs->root;
12973 +       } else {
12974 +               root_mnt = altroot_mnt;
12975 +               root = altroot;
12976 +       }
12977 +       /* printk("··· %p:%p/%p:%p ",
12978 +               root_mnt, root, altroot_mnt, altroot);  */
12979 +
12980 +       while ((mnt != mnt->mnt_parent) &&
12981 +               (mnt != root_mnt) && (mnt != altroot_mnt)) {
12982 +               point = mnt->mnt_mountpoint;
12983 +               mnt = mnt->mnt_parent;
12984 +       }
12985 +
12986 +       r1 = (mnt == root_mnt);
12987 +       s1 = is_subdir(point, root);
12988 +       r2 = (mnt == altroot_mnt);
12989 +       s2 = is_subdir(point, altroot);
12990 +
12991 +       ret = (((mnt == root_mnt) && is_subdir(point, root)) ||
12992 +               ((mnt == altroot_mnt) && is_subdir(point, altroot)));
12993 +       /* printk("··· for %p:%p -> %d:%d/%d:%d = %d\n",
12994 +               mnt, point, r1, s1, r2, s2, ret);       */
12995 +       spin_unlock(&dcache_lock);
12996 +
12997 +       return (r2 && s2);
12998 +}
12999 +
13000 +
13001 +/* virtual host info names */
13002 +
13003 +static char * vx_vhi_name(struct vx_info *vxi, int id)
13004 +{
13005 +       switch (id) {
13006 +               case VHIN_CONTEXT:
13007 +                       return vxi->vx_name;
13008 +               case VHIN_SYSNAME:
13009 +                       return vxi->cvirt.utsname.sysname;
13010 +               case VHIN_NODENAME:
13011 +                       return vxi->cvirt.utsname.nodename;
13012 +               case VHIN_RELEASE:
13013 +                       return vxi->cvirt.utsname.release;
13014 +               case VHIN_VERSION:
13015 +                       return vxi->cvirt.utsname.version;
13016 +               case VHIN_MACHINE:
13017 +                       return vxi->cvirt.utsname.machine;
13018 +               case VHIN_DOMAINNAME:
13019 +                       return vxi->cvirt.utsname.domainname;
13020 +               default:
13021 +                       return NULL;
13022 +       }
13023 +       return NULL;
13024 +}
13025 +
13026 +int vc_set_vhi_name(uint32_t id, void __user *data)
13027 +{
13028 +       struct vx_info *vxi;
13029 +       struct vcmd_vx_vhi_name_v0 vc_data;
13030 +       char *name;
13031 +
13032 +       if (!capable(CAP_SYS_ADMIN))
13033 +               return -EPERM;
13034 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
13035 +               return -EFAULT;
13036 +
13037 +       vxi = locate_vx_info(id);
13038 +       if (!vxi)
13039 +               return -ESRCH;
13040 +
13041 +       name = vx_vhi_name(vxi, vc_data.field);
13042 +       if (name)
13043 +               memcpy(name, vc_data.name, 65);
13044 +       put_vx_info(vxi);
13045 +       return (name ? 0 : -EFAULT);
13046 +}
13047 +
13048 +int vc_get_vhi_name(uint32_t id, void __user *data)
13049 +{
13050 +       struct vx_info *vxi;
13051 +       struct vcmd_vx_vhi_name_v0 vc_data;
13052 +       char *name;
13053 +
13054 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
13055 +               return -EFAULT;
13056 +
13057 +       vxi = locate_vx_info(id);
13058 +       if (!vxi)
13059 +               return -ESRCH;
13060 +
13061 +       name = vx_vhi_name(vxi, vc_data.field);
13062 +       if (!name)
13063 +               goto out_put;
13064 +
13065 +       memcpy(vc_data.name, name, 65);
13066 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
13067 +               return -EFAULT;
13068 +out_put:
13069 +       put_vx_info(vxi);
13070 +       return (name ? 0 : -EFAULT);
13071 +}
13072 +
13073 +/* namespace functions */
13074 +
13075 +#include <linux/namespace.h>
13076 +
13077 +int vx_set_namespace(struct vx_info *vxi, struct namespace *ns, struct fs_struct *fs)
13078 +{
13079 +       struct fs_struct *fs_copy;
13080 +
13081 +       if (vxi->vx_namespace)
13082 +               return -EPERM;
13083 +       if (!ns || !fs)
13084 +               return -EINVAL;
13085 +
13086 +       fs_copy = copy_fs_struct(fs);
13087 +       if (!fs_copy)
13088 +               return -ENOMEM;
13089 +
13090 +       get_namespace(ns);
13091 +       vxi->vx_namespace = ns;
13092 +       vxi->vx_fs = fs_copy;
13093 +       return 0;
13094 +}
13095 +
13096 +int vc_enter_namespace(uint32_t id, void *data)
13097 +{
13098 +       struct vx_info *vxi;
13099 +       struct fs_struct *old_fs, *fs;
13100 +       struct namespace *old_ns;
13101 +       int ret = 0;
13102 +
13103 +       if (!vx_check(0, VX_ADMIN))
13104 +               return -ENOSYS;
13105 +
13106 +       vxi = locate_vx_info(id);
13107 +       if (!vxi)
13108 +               return -ESRCH;
13109 +
13110 +       ret = -EINVAL;
13111 +       if (!vxi->vx_namespace)
13112 +               goto out_put;
13113 +
13114 +       ret = -ENOMEM;
13115 +       fs = copy_fs_struct(vxi->vx_fs);
13116 +       if (!fs)
13117 +               goto out_put;
13118 +
13119 +       ret = 0;
13120 +       task_lock(current);
13121 +       old_ns = current->namespace;
13122 +       old_fs = current->fs;
13123 +       get_namespace(vxi->vx_namespace);
13124 +       current->namespace = vxi->vx_namespace;
13125 +       current->fs = fs;
13126 +       task_unlock(current);
13127 +
13128 +       put_namespace(old_ns);
13129 +       put_fs_struct(old_fs);
13130 +out_put:
13131 +       put_vx_info(vxi);
13132 +       return ret;
13133 +}
13134 +
13135 +int vc_cleanup_namespace(uint32_t id, void *data)
13136 +{
13137 +       down_write(&current->namespace->sem);
13138 +       spin_lock(&vfsmount_lock);
13139 +       umount_unused(current->namespace->root, current->fs);
13140 +       spin_unlock(&vfsmount_lock);
13141 +       up_write(&current->namespace->sem);
13142 +       return 0;
13143 +}
13144 +
13145 +int vc_set_namespace(uint32_t id, void __user *data)
13146 +{
13147 +       struct fs_struct *fs;
13148 +       struct namespace *ns;
13149 +       struct vx_info *vxi;
13150 +       int ret;
13151 +
13152 +       if (vx_check(0, VX_ADMIN|VX_WATCH))
13153 +               return -ENOSYS;
13154 +
13155 +       task_lock(current);
13156 +       vxi = get_vx_info(current->vx_info);
13157 +       fs = current->fs;
13158 +       atomic_inc(&fs->count);
13159 +       ns = current->namespace;
13160 +       get_namespace(current->namespace);
13161 +       task_unlock(current);
13162 +
13163 +       ret = vx_set_namespace(vxi, ns, fs);
13164 +
13165 +       put_namespace(ns);
13166 +       put_fs_struct(fs);
13167 +       put_vx_info(vxi);
13168 +       return ret;
13169 +}
13170 +
13171 diff -NurpP --minimal linux-2.6.10/kernel/vserver/network.c linux-2.6.10-vs1.9.3.17/kernel/vserver/network.c
13172 --- linux-2.6.10/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
13173 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/network.c    2005-01-04 14:22:07.000000000 +0100
13174 @@ -0,0 +1,715 @@
13175 +/*
13176 + *  linux/kernel/vserver/network.c
13177 + *
13178 + *  Virtual Server: Network Support
13179 + *
13180 + *  Copyright (C) 2003-2004  Herbert Pötzl
13181 + *
13182 + *  V0.01  broken out from vcontext V0.05
13183 + *  V0.02  cleaned up implementation
13184 + *  V0.03  added equiv nx commands
13185 + *  V0.04  switch to RCU based hash
13186 + *
13187 + */
13188 +
13189 +#include <linux/config.h>
13190 +#include <linux/slab.h>
13191 +#include <linux/vserver/network_cmd.h>
13192 +#include <linux/rcupdate.h>
13193 +#include <net/tcp.h>
13194 +
13195 +#include <asm/errno.h>
13196 +
13197 +
13198 +/*     __alloc_nx_info()
13199 +
13200 +       * allocate an initialized nx_info struct
13201 +       * doesn't make it visible (hash)                        */
13202 +
13203 +static struct nx_info *__alloc_nx_info(nid_t nid)
13204 +{
13205 +       struct nx_info *new = NULL;
13206 +
13207 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
13208 +
13209 +       /* would this benefit from a slab cache? */
13210 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
13211 +       if (!new)
13212 +               return 0;
13213 +
13214 +       memset (new, 0, sizeof(struct nx_info));
13215 +       new->nx_id = nid;
13216 +       INIT_RCU_HEAD(&new->nx_rcu);
13217 +       INIT_HLIST_NODE(&new->nx_hlist);
13218 +       atomic_set(&new->nx_refcnt, 0);
13219 +       atomic_set(&new->nx_usecnt, 0);
13220 +
13221 +       /* rest of init goes here */
13222 +
13223 +       vxdprintk(VXD_CBIT(nid, 0),
13224 +               "alloc_nx_info() = %p", new);
13225 +       return new;
13226 +}
13227 +
13228 +/*     __dealloc_nx_info()
13229 +
13230 +       * final disposal of nx_info                             */
13231 +
13232 +static void __dealloc_nx_info(struct nx_info *nxi)
13233 +{
13234 +       vxdprintk(VXD_CBIT(nid, 0),
13235 +               "dealloc_nx_info(%p)", nxi);
13236 +
13237 +       nxi->nx_hlist.next = LIST_POISON1;
13238 +       nxi->nx_id = -1;
13239 +
13240 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
13241 +       BUG_ON(atomic_read(&nxi->nx_refcnt));
13242 +
13243 +       kfree(nxi);
13244 +}
13245 +
13246 +static inline int __free_nx_info(struct nx_info *nxi)
13247 +{
13248 +       int usecnt, refcnt;
13249 +
13250 +       BUG_ON(!nxi);
13251 +
13252 +       usecnt = atomic_read(&nxi->nx_usecnt);
13253 +       BUG_ON(usecnt < 0);
13254 +
13255 +       refcnt = atomic_read(&nxi->nx_refcnt);
13256 +       BUG_ON(refcnt < 0);
13257 +
13258 +       if (!usecnt)
13259 +               __dealloc_nx_info(nxi);
13260 +       return usecnt;
13261 +}
13262 +
13263 +static void __rcu_put_nx_info(struct rcu_head *head)
13264 +{
13265 +       struct nx_info *nxi = container_of(head, struct nx_info, nx_rcu);
13266 +
13267 +       vxdprintk(VXD_CBIT(nid, 3),
13268 +               "__rcu_put_nx_info(%p[#%d]): %d,%d",
13269 +               nxi, nxi->nx_id,
13270 +               atomic_read(&nxi->nx_usecnt),
13271 +               atomic_read(&nxi->nx_refcnt));
13272 +       put_nx_info(nxi);
13273 +}
13274 +
13275 +
13276 +/*     hash table for nx_info hash */
13277 +
13278 +#define NX_HASH_SIZE   13
13279 +
13280 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
13281 +
13282 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
13283 +
13284 +
13285 +static inline unsigned int __hashval(nid_t nid)
13286 +{
13287 +       return (nid % NX_HASH_SIZE);
13288 +}
13289 +
13290 +
13291 +
13292 +/*     __hash_nx_info()
13293 +
13294 +       * add the nxi to the global hash table
13295 +       * requires the hash_lock to be held                     */
13296 +
13297 +static inline void __hash_nx_info(struct nx_info *nxi)
13298 +{
13299 +       struct hlist_head *head;
13300 +
13301 +       vxdprintk(VXD_CBIT(nid, 4),
13302 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
13303 +       get_nx_info(nxi);
13304 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
13305 +       hlist_add_head_rcu(&nxi->nx_hlist, head);
13306 +}
13307 +
13308 +/*     __unhash_nx_info()
13309 +
13310 +       * remove the nxi from the global hash table
13311 +       * requires the hash_lock to be held                     */
13312 +
13313 +static inline void __unhash_nx_info(struct nx_info *nxi)
13314 +{
13315 +       vxdprintk(VXD_CBIT(nid, 4),
13316 +               "__unhash_nx_info: %p[#%d]", nxi, nxi->nx_id);
13317 +       hlist_del_rcu(&nxi->nx_hlist);
13318 +       call_rcu(&nxi->nx_rcu, __rcu_put_nx_info);
13319 +}
13320 +
13321 +
13322 +/*     __lookup_nx_info()
13323 +
13324 +       * requires the rcu_read_lock()
13325 +       * doesn't increment the nx_refcnt                       */
13326 +
13327 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
13328 +{
13329 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
13330 +       struct hlist_node *pos;
13331 +
13332 +       hlist_for_each_rcu(pos, head) {
13333 +               struct nx_info *nxi =
13334 +                       hlist_entry(pos, struct nx_info, nx_hlist);
13335 +
13336 +               if (nxi->nx_id == nid) {
13337 +                       return nxi;
13338 +               }
13339 +       }
13340 +       return NULL;
13341 +}
13342 +
13343 +
13344 +/*     __nx_dynamic_id()
13345 +
13346 +       * find unused dynamic nid
13347 +       * requires the rcu_read_lock()
13348 +       * requires the hash_lock to be held                     */
13349 +
13350 +static inline nid_t __nx_dynamic_id(void)
13351 +{
13352 +       static nid_t seq = MAX_N_CONTEXT;
13353 +       nid_t barrier = seq;
13354 +
13355 +       do {
13356 +               if (++seq > MAX_N_CONTEXT)
13357 +                       seq = MIN_D_CONTEXT;
13358 +               if (!__lookup_nx_info(seq)) {
13359 +                       vxdprintk(VXD_CBIT(nid, 4),
13360 +                               "__nx_dynamic_id: [#%d]", seq);
13361 +                       return seq;
13362 +               }
13363 +       } while (barrier != seq);
13364 +       return 0;
13365 +}
13366 +
13367 +/*     __loc_nx_info()
13368 +
13369 +       * locate or create the requested context
13370 +       * get() it and if new hash it                           */
13371 +
13372 +static struct nx_info * __loc_nx_info(int id, int *err)
13373 +{
13374 +       struct nx_info *new, *nxi = NULL;
13375 +
13376 +       vxdprintk(VXD_CBIT(nid, 1), "loc_nx_info(%d)*", id);
13377 +
13378 +       if (!(new = __alloc_nx_info(id))) {
13379 +               *err = -ENOMEM;
13380 +               return NULL;
13381 +       }
13382 +
13383 +       /* FIXME is this required at all ? */
13384 +       rcu_read_lock();
13385 +       /* required to make dynamic xids unique */
13386 +       spin_lock(&nx_info_hash_lock);
13387 +
13388 +       /* dynamic context requested */
13389 +       if (id == NX_DYNAMIC_ID) {
13390 +               id = __nx_dynamic_id();
13391 +               if (!id) {
13392 +                       printk(KERN_ERR "no dynamic context available.\n");
13393 +                       goto out_unlock;
13394 +               }
13395 +               new->nx_id = id;
13396 +       }
13397 +       /* existing context requested */
13398 +       else if ((nxi = __lookup_nx_info(id))) {
13399 +               /* context in setup is not available */
13400 +               if (nxi->nx_flags & VXF_STATE_SETUP) {
13401 +                       vxdprintk(VXD_CBIT(nid, 0),
13402 +                               "loc_nx_info(%d) = %p (not available)", id, nxi);
13403 +                       nxi = NULL;
13404 +                       *err = -EBUSY;
13405 +               } else {
13406 +                       vxdprintk(VXD_CBIT(nid, 0),
13407 +                               "loc_nx_info(%d) = %p (found)", id, nxi);
13408 +                       get_nx_info(nxi);
13409 +                       *err = 0;
13410 +               }
13411 +               goto out_unlock;
13412 +       }
13413 +
13414 +       /* new context requested */
13415 +       vxdprintk(VXD_CBIT(nid, 0),
13416 +               "loc_nx_info(%d) = %p (new)", id, new);
13417 +       __hash_nx_info(get_nx_info(new));
13418 +       nxi = new, new = NULL;
13419 +       *err = 1;
13420 +
13421 +out_unlock:
13422 +       spin_unlock(&nx_info_hash_lock);
13423 +       rcu_read_unlock();
13424 +       if (new)
13425 +               __dealloc_nx_info(new);
13426 +       return nxi;
13427 +}
13428 +
13429 +
13430 +
13431 +/*     exported stuff                                          */
13432 +
13433 +void free_nx_info(struct nx_info *nxi)
13434 +{
13435 +       BUG_ON(__free_nx_info(nxi));
13436 +}
13437 +
13438 +void unhash_nx_info(struct nx_info *nxi)
13439 +{
13440 +       spin_lock(&nx_info_hash_lock);
13441 +       __unhash_nx_info(nxi);
13442 +       spin_unlock(&nx_info_hash_lock);
13443 +}
13444 +
13445 +/*     locate_nx_info()
13446 +
13447 +       * search for a nx_info and get() it
13448 +       * negative id means current                             */
13449 +
13450 +struct nx_info *locate_nx_info(int id)
13451 +{
13452 +       struct nx_info *nxi;
13453 +
13454 +       if (id < 0) {
13455 +               nxi = get_nx_info(current->nx_info);
13456 +       } else {
13457 +               rcu_read_lock();
13458 +               nxi = get_nx_info(__lookup_nx_info(id));
13459 +               rcu_read_unlock();
13460 +       }
13461 +       return nxi;
13462 +}
13463 +
13464 +/*     nx_info_is_hashed()
13465 +
13466 +       * verify that nid is still hashed                       */
13467 +
13468 +int nx_info_is_hashed(nid_t nid)
13469 +{
13470 +       int hashed;
13471 +
13472 +       rcu_read_lock();
13473 +       hashed = (__lookup_nx_info(nid) != NULL);
13474 +       rcu_read_unlock();
13475 +       return hashed;
13476 +}
13477 +
13478 +#ifdef CONFIG_VSERVER_LEGACY
13479 +
13480 +struct nx_info *locate_or_create_nx_info(int id)
13481 +{
13482 +       int err;
13483 +
13484 +       return __loc_nx_info(id, &err);
13485 +}
13486 +
13487 +struct nx_info *create_nx_info(void)
13488 +{
13489 +       struct nx_info *new;
13490 +       int err;
13491 +
13492 +       vxdprintk(VXD_CBIT(nid, 5), "create_nx_info(%s)", "void");
13493 +       if (!(new = __loc_nx_info(NX_DYNAMIC_ID, &err)))
13494 +               return NULL;
13495 +       return new;
13496 +}
13497 +
13498 +
13499 +#endif
13500 +
13501 +#ifdef CONFIG_PROC_FS
13502 +
13503 +int get_nid_list(int index, unsigned int *nids, int size)
13504 +{
13505 +       int hindex, nr_nids = 0;
13506 +
13507 +       rcu_read_lock();
13508 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
13509 +               struct hlist_head *head = &nx_info_hash[hindex];
13510 +               struct hlist_node *pos;
13511 +
13512 +               hlist_for_each_rcu(pos, head) {
13513 +                       struct nx_info *nxi;
13514 +
13515 +                       if (--index > 0)
13516 +                               continue;
13517 +
13518 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
13519 +                       nids[nr_nids] = nxi->nx_id;
13520 +                       if (++nr_nids >= size)
13521 +                               goto out;
13522 +               }
13523 +       }
13524 +out:
13525 +       rcu_read_unlock();
13526 +       return nr_nids;
13527 +}
13528 +#endif
13529 +
13530 +
13531 +/*
13532 + *     migrate task to new network
13533 + */
13534 +
13535 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
13536 +{
13537 +       struct nx_info *old_nxi;
13538 +       int ret = 0;
13539 +
13540 +       if (!p || !nxi)
13541 +               BUG();
13542 +
13543 +       vxdprintk(VXD_CBIT(nid, 5),
13544 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
13545 +               p, nxi, nxi->nx_id,
13546 +               atomic_read(&nxi->nx_usecnt),
13547 +               atomic_read(&nxi->nx_refcnt));
13548 +
13549 +       old_nxi = task_get_nx_info(p);
13550 +       if (old_nxi == nxi)
13551 +               goto out;
13552 +
13553 +       task_lock(p);
13554 +       /* should be handled in set_nx_info !! */
13555 +       if (old_nxi)
13556 +               clr_nx_info(&p->nx_info);
13557 +       set_nx_info(&p->nx_info, nxi);
13558 +       p->nid = nxi->nx_id;
13559 +       task_unlock(p);
13560 +
13561 +       /* obsoleted by clr/set */
13562 +       // put_nx_info(old_nxi);
13563 +out:
13564 +       put_nx_info(old_nxi);
13565 +       return ret;
13566 +}
13567 +
13568 +
13569 +#include <linux/netdevice.h>
13570 +#include <linux/inetdevice.h>
13571 +
13572 +
13573 +int ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13574 +{
13575 +       if (!nxi)
13576 +               return 1;
13577 +       if (!ifa)
13578 +               return 0;
13579 +       return addr_in_nx_info(nxi, ifa->ifa_address);
13580 +}
13581 +
13582 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
13583 +{
13584 +       struct in_device *in_dev = __in_dev_get(dev);
13585 +       struct in_ifaddr **ifap = NULL;
13586 +       struct in_ifaddr *ifa = NULL;
13587 +
13588 +       if (!nxi)
13589 +               return 1;
13590 +       if (!in_dev)
13591 +               return 0;
13592 +
13593 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
13594 +               ifap = &ifa->ifa_next) {
13595 +               if (addr_in_nx_info(nxi, ifa->ifa_address))
13596 +                       return 1;
13597 +       }
13598 +       return 0;
13599 +}
13600 +
13601 +/*
13602 + *     check if address is covered by socket
13603 + *
13604 + *     sk:     the socket to check against
13605 + *     addr:   the address in question (must be != 0)
13606 + */
13607 +static inline int __addr_in_socket(struct sock *sk, uint32_t addr)
13608 +{
13609 +       struct nx_info *nxi = sk->sk_nx_info;
13610 +       uint32_t saddr = tcp_v4_rcv_saddr(sk);
13611 +
13612 +       vxdprintk(VXD_CBIT(net, 5),
13613 +               "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx",
13614 +               sk, VXD_QUAD(addr), nxi, VXD_QUAD(saddr), sk->sk_socket,
13615 +               (sk->sk_socket?sk->sk_socket->flags:0));
13616 +
13617 +       if (saddr) {
13618 +               /* direct address match */
13619 +               return (saddr == addr);
13620 +       } else if (nxi) {
13621 +               /* match against nx_info */
13622 +               return addr_in_nx_info(nxi, addr);
13623 +       } else {
13624 +               /* unrestricted any socket */
13625 +               return 1;
13626 +       }
13627 +}
13628 +
13629 +
13630 +int nx_addr_conflict(struct nx_info *nxi, uint32_t addr, struct sock *sk)
13631 +{
13632 +       vxdprintk(VXD_CBIT(net, 2),
13633 +               "nx_addr_conflict(%p,%p) %d.%d,%d.%d",
13634 +               nxi, sk, VXD_QUAD(addr));
13635 +
13636 +       if (addr) {
13637 +               /* check real address */
13638 +               return __addr_in_socket(sk, addr);
13639 +       } else if (nxi) {
13640 +               /* check against nx_info */
13641 +               int i, n = nxi->nbipv4;
13642 +
13643 +               for (i=0; i<n; i++)
13644 +                       if (__addr_in_socket(sk, nxi->ipv4[i]))
13645 +                               return 1;
13646 +               return 0;
13647 +       } else {
13648 +               /* check against any */
13649 +               return 1;
13650 +       }
13651 +}
13652 +
13653 +
13654 +/* vserver syscall commands below here */
13655 +
13656 +/* taks nid and nx_info functions */
13657 +
13658 +#include <asm/uaccess.h>
13659 +
13660 +
13661 +int vc_task_nid(uint32_t id, void __user *data)
13662 +{
13663 +       nid_t nid;
13664 +
13665 +       if (id) {
13666 +               struct task_struct *tsk;
13667 +
13668 +               if (!vx_check(0, VX_ADMIN|VX_WATCH))
13669 +                       return -EPERM;
13670 +
13671 +               read_lock(&tasklist_lock);
13672 +               tsk = find_task_by_real_pid(id);
13673 +               nid = (tsk) ? tsk->nid : -ESRCH;
13674 +               read_unlock(&tasklist_lock);
13675 +       }
13676 +       else
13677 +               nid = current->nid;
13678 +       return nid;
13679 +}
13680 +
13681 +
13682 +int vc_nx_info(uint32_t id, void __user *data)
13683 +{
13684 +       struct nx_info *nxi;
13685 +       struct vcmd_nx_info_v0 vc_data;
13686 +
13687 +       if (!vx_check(0, VX_ADMIN))
13688 +               return -ENOSYS;
13689 +       if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RESOURCE))
13690 +               return -EPERM;
13691 +
13692 +       nxi = locate_nx_info(id);
13693 +       if (!nxi)
13694 +               return -ESRCH;
13695 +
13696 +       vc_data.nid = nxi->nx_id;
13697 +       put_nx_info(nxi);
13698 +
13699 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
13700 +               return -EFAULT;
13701 +       return 0;
13702 +}
13703 +
13704 +
13705 +/* network functions */
13706 +
13707 +int vc_net_create(uint32_t nid, void __user *data)
13708 +{
13709 +       // int ret = -ENOMEM;
13710 +       struct nx_info *new_nxi;
13711 +       int ret;
13712 +
13713 +       if (!capable(CAP_SYS_ADMIN))
13714 +               return -EPERM;
13715 +
13716 +       if ((nid >= MIN_D_CONTEXT) && (nid != VX_DYNAMIC_ID))
13717 +               return -EINVAL;
13718 +
13719 +       if (nid < 1)
13720 +               return -EINVAL;
13721 +
13722 +       new_nxi = __loc_nx_info(nid, &ret);
13723 +       if (!new_nxi)
13724 +               return ret;
13725 +       if (!(new_nxi->nx_flags & VXF_STATE_SETUP)) {
13726 +               ret = -EEXIST;
13727 +               goto out_put;
13728 +       }
13729 +
13730 +       ret = new_nxi->nx_id;
13731 +       nx_migrate_task(current, new_nxi);
13732 +out_put:
13733 +       put_nx_info(new_nxi);
13734 +       return ret;
13735 +}
13736 +
13737 +
13738 +int vc_net_migrate(uint32_t id, void __user *data)
13739 +{
13740 +       struct nx_info *nxi;
13741 +
13742 +       if (!capable(CAP_SYS_ADMIN))
13743 +               return -EPERM;
13744 +
13745 +       nxi = locate_nx_info(id);
13746 +       if (!nxi)
13747 +               return -ESRCH;
13748 +       nx_migrate_task(current, nxi);
13749 +       put_nx_info(nxi);
13750 +       return 0;
13751 +}
13752 +
13753 +int vc_net_add(uint32_t id, void __user *data)
13754 +{
13755 +       struct nx_info *nxi;
13756 +       struct vcmd_net_nx_v0 vc_data;
13757 +
13758 +       if (!capable(CAP_SYS_ADMIN))
13759 +               return -EPERM;
13760 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
13761 +               return -EFAULT;
13762 +
13763 +       nxi = locate_nx_info(id);
13764 +       if (!nxi)
13765 +               return -ESRCH;
13766 +
13767 +       // add ip to net context here
13768 +       put_nx_info(nxi);
13769 +       return 0;
13770 +}
13771 +
13772 +int vc_net_remove(uint32_t id, void __user *data)
13773 +{
13774 +       struct nx_info *nxi;
13775 +       struct vcmd_net_nx_v0 vc_data;
13776 +
13777 +       if (!capable(CAP_SYS_ADMIN))
13778 +               return -EPERM;
13779 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
13780 +               return -EFAULT;
13781 +
13782 +       nxi = locate_nx_info(id);
13783 +       if (!nxi)
13784 +               return -ESRCH;
13785 +
13786 +       // rem ip from net context here
13787 +       put_nx_info(nxi);
13788 +       return 0;
13789 +}
13790 +
13791 +
13792 +
13793 +int vc_get_nflags(uint32_t id, void __user *data)
13794 +{
13795 +       struct nx_info *nxi;
13796 +       struct vcmd_net_flags_v0 vc_data;
13797 +
13798 +       if (!capable(CAP_SYS_ADMIN))
13799 +               return -EPERM;
13800 +
13801 +       nxi = locate_nx_info(id);
13802 +       if (!nxi)
13803 +               return -ESRCH;
13804 +
13805 +       vc_data.flagword = nxi->nx_flags;
13806 +
13807 +       /* special STATE flag handling */
13808 +       vc_data.mask = vx_mask_flags(~0UL, nxi->nx_flags, IPF_ONE_TIME);
13809 +
13810 +       put_nx_info(nxi);
13811 +
13812 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
13813 +               return -EFAULT;
13814 +       return 0;
13815 +}
13816 +
13817 +int vc_set_nflags(uint32_t id, void __user *data)
13818 +{
13819 +       struct nx_info *nxi;
13820 +       struct vcmd_net_flags_v0 vc_data;
13821 +       uint64_t mask, trigger;
13822 +
13823 +       if (!capable(CAP_SYS_ADMIN))
13824 +               return -EPERM;
13825 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
13826 +               return -EFAULT;
13827 +
13828 +       nxi = locate_nx_info(id);
13829 +       if (!nxi)
13830 +               return -ESRCH;
13831 +
13832 +       /* special STATE flag handling */
13833 +       mask = vx_mask_mask(vc_data.mask, nxi->nx_flags, IPF_ONE_TIME);
13834 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
13835 +       // if (trigger & IPF_STATE_SETUP)
13836 +
13837 +       nxi->nx_flags = vx_mask_flags(nxi->nx_flags,
13838 +               vc_data.flagword, mask);
13839 +       put_nx_info(nxi);
13840 +       return 0;
13841 +}
13842 +
13843 +int vc_get_ncaps(uint32_t id, void __user *data)
13844 +{
13845 +       struct nx_info *nxi;
13846 +       struct vcmd_net_caps_v0 vc_data;
13847 +
13848 +       if (!capable(CAP_SYS_ADMIN))
13849 +               return -EPERM;
13850 +
13851 +       nxi = locate_nx_info(id);
13852 +       if (!nxi)
13853 +               return -ESRCH;
13854 +
13855 +       vc_data.ncaps = nxi->nx_ncaps;
13856 +       vc_data.cmask = ~0UL;
13857 +       put_nx_info(nxi);
13858 +
13859 +       if (copy_to_user (data, &vc_data, sizeof(vc_data)))
13860 +               return -EFAULT;
13861 +       return 0;
13862 +}
13863 +
13864 +int vc_set_ncaps(uint32_t id, void __user *data)
13865 +{
13866 +       struct nx_info *nxi;
13867 +       struct vcmd_net_caps_v0 vc_data;
13868 +
13869 +       if (!capable(CAP_SYS_ADMIN))
13870 +               return -EPERM;
13871 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
13872 +               return -EFAULT;
13873 +
13874 +       nxi = locate_nx_info(id);
13875 +       if (!nxi)
13876 +               return -ESRCH;
13877 +
13878 +       nxi->nx_ncaps = vx_mask_flags(nxi->nx_ncaps,
13879 +               vc_data.ncaps, vc_data.cmask);
13880 +       put_nx_info(nxi);
13881 +       return 0;
13882 +}
13883 +
13884 +
13885 +#include <linux/module.h>
13886 +
13887 +EXPORT_SYMBOL_GPL(free_nx_info);
13888 +EXPORT_SYMBOL_GPL(unhash_nx_info);
13889 +
13890 diff -NurpP --minimal linux-2.6.10/kernel/vserver/proc.c linux-2.6.10-vs1.9.3.17/kernel/vserver/proc.c
13891 --- linux-2.6.10/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
13892 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/proc.c       2004-12-26 19:40:24.000000000 +0100
13893 @@ -0,0 +1,903 @@
13894 +/*
13895 + *  linux/kernel/vserver/proc.c
13896 + *
13897 + *  Virtual Context Support
13898 + *
13899 + *  Copyright (C) 2003-2004  Herbert Pötzl
13900 + *
13901 + *  V0.01  basic structure
13902 + *  V0.02  adaptation vs1.3.0
13903 + *  V0.03  proc permissions
13904 + *  V0.04  locking/generic
13905 + *  V0.05  next generation procfs
13906 + *  V0.06  inode validation
13907 + *  V0.07  generic rewrite vid
13908 + *
13909 + */
13910 +
13911 +#include <linux/config.h>
13912 +#include <linux/errno.h>
13913 +#include <linux/proc_fs.h>
13914 +#include <linux/sched.h>
13915 +#include <linux/vs_context.h>
13916 +#include <linux/vs_network.h>
13917 +#include <linux/vs_cvirt.h>
13918 +
13919 +#include <linux/vserver/switch.h>
13920 +
13921 +#include <asm/uaccess.h>
13922 +#include <asm/unistd.h>
13923 +
13924 +#include "cvirt_proc.h"
13925 +#include "limit_proc.h"
13926 +#include "sched_proc.h"
13927 +
13928 +static struct proc_dir_entry *proc_virtual;
13929 +
13930 +static struct proc_dir_entry *proc_vnet;
13931 +
13932 +
13933 +enum vid_directory_inos {
13934 +       PROC_XID_INO = 32,
13935 +       PROC_XID_INFO,
13936 +       PROC_XID_STATUS,
13937 +       PROC_XID_LIMIT,
13938 +       PROC_XID_SCHED,
13939 +       PROC_XID_CVIRT,
13940 +       PROC_XID_CACCT,
13941 +
13942 +       PROC_NID_INO = 64,
13943 +       PROC_NID_INFO,
13944 +       PROC_NID_STATUS,
13945 +};
13946 +
13947 +#define PROC_VID_MASK  0x60
13948 +
13949 +
13950 +/* first the actual feeds */
13951 +
13952 +
13953 +static int proc_virtual_info(int vid, char *buffer)
13954 +{
13955 +       return sprintf(buffer,
13956 +               "VCIVersion:\t%04x:%04x\n"
13957 +               "VCISyscall:\t%d\n"
13958 +               ,VCI_VERSION >> 16
13959 +               ,VCI_VERSION & 0xFFFF
13960 +               ,__NR_vserver
13961 +               );
13962 +}
13963 +
13964 +
13965 +int proc_xid_info (int vid, char *buffer)
13966 +{
13967 +       struct vx_info *vxi;
13968 +       int length;
13969 +
13970 +       vxi = locate_vx_info(vid);
13971 +       if (!vxi)
13972 +               return 0;
13973 +       length = sprintf(buffer,
13974 +               "ID:\t%d\n"
13975 +               "Info:\t%p\n"
13976 +               "Init:\t%d\n"
13977 +               ,vxi->vx_id
13978 +               ,vxi
13979 +               ,vxi->vx_initpid
13980 +               );
13981 +       put_vx_info(vxi);
13982 +       return length;
13983 +}
13984 +
13985 +int proc_xid_status (int vid, char *buffer)
13986 +{
13987 +       struct vx_info *vxi;
13988 +       int length;
13989 +
13990 +       vxi = locate_vx_info(vid);
13991 +       if (!vxi)
13992 +               return 0;
13993 +       length = sprintf(buffer,
13994 +               "UseCnt:\t%d\n"
13995 +               "RefCnt:\t%d\n"
13996 +               "Flags:\t%016llx\n"
13997 +               "BCaps:\t%016llx\n"
13998 +               "CCaps:\t%016llx\n"
13999 +               "Ticks:\t%d\n"
14000 +               ,atomic_read(&vxi->vx_usecnt)
14001 +               ,atomic_read(&vxi->vx_refcnt)
14002 +               ,(unsigned long long)vxi->vx_flags
14003 +               ,(unsigned long long)vxi->vx_bcaps
14004 +               ,(unsigned long long)vxi->vx_ccaps
14005 +               ,atomic_read(&vxi->limit.ticks)
14006 +               );
14007 +       put_vx_info(vxi);
14008 +       return length;
14009 +}
14010 +
14011 +int proc_xid_limit (int vid, char *buffer)
14012 +{
14013 +       struct vx_info *vxi;
14014 +       int length;
14015 +
14016 +       vxi = locate_vx_info(vid);
14017 +       if (!vxi)
14018 +               return 0;
14019 +       length = vx_info_proc_limit(&vxi->limit, buffer);
14020 +       put_vx_info(vxi);
14021 +       return length;
14022 +}
14023 +
14024 +int proc_xid_sched (int vid, char *buffer)
14025 +{
14026 +       struct vx_info *vxi;
14027 +       int length;
14028 +
14029 +       vxi = locate_vx_info(vid);
14030 +       if (!vxi)
14031 +               return 0;
14032 +       length = vx_info_proc_sched(&vxi->sched, buffer);
14033 +       put_vx_info(vxi);
14034 +       return length;
14035 +}
14036 +
14037 +int proc_xid_cvirt (int vid, char *buffer)
14038 +{
14039 +       struct vx_info *vxi;
14040 +       int length;
14041 +
14042 +       vxi = locate_vx_info(vid);
14043 +       if (!vxi)
14044 +               return 0;
14045 +       vx_update_load(vxi);
14046 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
14047 +       put_vx_info(vxi);
14048 +       return length;
14049 +}
14050 +
14051 +int proc_xid_cacct (int vid, char *buffer)
14052 +{
14053 +       struct vx_info *vxi;
14054 +       int length;
14055 +
14056 +       vxi = locate_vx_info(vid);
14057 +       if (!vxi)
14058 +               return 0;
14059 +       length = vx_info_proc_cacct(&vxi->cacct, buffer);
14060 +       put_vx_info(vxi);
14061 +       return length;
14062 +}
14063 +
14064 +
14065 +static int proc_vnet_info(int vid, char *buffer)
14066 +{
14067 +       return sprintf(buffer,
14068 +               "VCIVersion:\t%04x:%04x\n"
14069 +               "VCISyscall:\t%d\n"
14070 +               ,VCI_VERSION >> 16
14071 +               ,VCI_VERSION & 0xFFFF
14072 +               ,__NR_vserver
14073 +               );
14074 +}
14075 +
14076 +#define atoquad(a) \
14077 +       (((a)>>0) & 0xff), (((a)>>8) & 0xff), \
14078 +       (((a)>>16) & 0xff), (((a)>>24) & 0xff)
14079 +
14080 +int proc_nid_info (int vid, char *buffer)
14081 +{
14082 +       struct nx_info *nxi;
14083 +       int length, i;
14084 +
14085 +       nxi = locate_nx_info(vid);
14086 +       if (!nxi)
14087 +               return 0;
14088 +       length = sprintf(buffer,
14089 +               "ID:\t%d\n"
14090 +               "Info:\t%p\n"
14091 +               ,nxi->nx_id
14092 +               ,nxi
14093 +               );
14094 +       for (i=0; i<nxi->nbipv4; i++) {
14095 +               length += sprintf(buffer + length,
14096 +                       "%d:\t%d.%d.%d.%d/%d.%d.%d.%d\n", i,
14097 +                       atoquad(nxi->ipv4[i]),
14098 +                       atoquad(nxi->mask[i]));
14099 +       }
14100 +       put_nx_info(nxi);
14101 +       return length;
14102 +}
14103 +
14104 +int proc_nid_status (int vid, char *buffer)
14105 +{
14106 +       struct nx_info *nxi;
14107 +       int length;
14108 +
14109 +       nxi = locate_nx_info(vid);
14110 +       if (!nxi)
14111 +               return 0;
14112 +       length = sprintf(buffer,
14113 +               "UseCnt:\t%d\n"
14114 +               "RefCnt:\t%d\n"
14115 +               ,atomic_read(&nxi->nx_usecnt)
14116 +               ,atomic_read(&nxi->nx_refcnt)
14117 +               );
14118 +       put_nx_info(nxi);
14119 +       return length;
14120 +}
14121 +
14122 +/* here the inode helpers */
14123 +
14124 +
14125 +#define fake_ino(id,nr) (((nr) & 0xFFFF) | \
14126 +                       (((id) & 0xFFFF) << 16))
14127 +
14128 +#define inode_vid(i)   (((i)->i_ino >> 16) & 0xFFFF)
14129 +#define inode_type(i)  ((i)->i_ino & 0xFFFF)
14130 +
14131 +#define MAX_MULBY10    ((~0U-9)/10)
14132 +
14133 +
14134 +static struct inode *proc_vid_make_inode(struct super_block * sb,
14135 +       int vid, int ino)
14136 +{
14137 +       struct inode *inode = new_inode(sb);
14138 +
14139 +       if (!inode)
14140 +               goto out;
14141 +
14142 +       inode->i_mtime = inode->i_atime =
14143 +               inode->i_ctime = CURRENT_TIME;
14144 +       inode->i_ino = fake_ino(vid, ino);
14145 +
14146 +       inode->i_uid = 0;
14147 +       inode->i_gid = 0;
14148 +       // inode->i_xid = xid;
14149 +out:
14150 +       return inode;
14151 +}
14152 +
14153 +static int proc_vid_revalidate(struct dentry * dentry, struct nameidata *nd)
14154 +{
14155 +       struct inode * inode = dentry->d_inode;
14156 +       int vid, hashed=0;
14157 +
14158 +       vid = inode_vid(inode);
14159 +       switch (inode_type(inode) & PROC_VID_MASK) {
14160 +               case PROC_XID_INO:
14161 +                       hashed = vx_info_is_hashed(vid);
14162 +                       break;
14163 +               case PROC_NID_INO:
14164 +                       hashed = nx_info_is_hashed(vid);
14165 +                       break;
14166 +       }
14167 +       if (hashed)
14168 +               return 1;
14169 +       d_drop(dentry);
14170 +       return 0;
14171 +}
14172 +
14173 +/*
14174 +static int proc_vid_delete_dentry(struct dentry * dentry)
14175 +{
14176 +       return 1;
14177 +}
14178 +*/
14179 +
14180 +
14181 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
14182 +
14183 +static ssize_t proc_vid_info_read(struct file * file, char * buf,
14184 +                         size_t count, loff_t *ppos)
14185 +{
14186 +       struct inode * inode = file->f_dentry->d_inode;
14187 +       unsigned long page;
14188 +       ssize_t length;
14189 +       ssize_t end;
14190 +       int vid;
14191 +
14192 +       if (count > PROC_BLOCK_SIZE)
14193 +               count = PROC_BLOCK_SIZE;
14194 +       if (!(page = __get_free_page(GFP_KERNEL)))
14195 +               return -ENOMEM;
14196 +
14197 +       vid = inode_vid(inode);
14198 +       length = PROC_I(inode)->op.proc_vid_read(vid, (char*)page);
14199 +
14200 +       if (length < 0) {
14201 +               free_page(page);
14202 +               return length;
14203 +       }
14204 +       /* Static 4kB (or whatever) block capacity */
14205 +       if (*ppos >= length) {
14206 +               free_page(page);
14207 +               return 0;
14208 +       }
14209 +       if (count + *ppos > length)
14210 +               count = length - *ppos;
14211 +       end = count + *ppos;
14212 +       copy_to_user(buf, (char *) page + *ppos, count);
14213 +       *ppos = end;
14214 +       free_page(page);
14215 +       return count;
14216 +}
14217 +
14218 +
14219 +
14220 +
14221 +
14222 +/* here comes the lower level (vid) */
14223 +
14224 +static struct file_operations proc_vid_info_file_operations = {
14225 +       read:           proc_vid_info_read,
14226 +};
14227 +
14228 +static struct dentry_operations proc_vid_dentry_operations = {
14229 +       d_revalidate:   proc_vid_revalidate,
14230 +//     d_delete:       proc_vid_delete_dentry,
14231 +};
14232 +
14233 +
14234 +struct vid_entry {
14235 +       int type;
14236 +       int len;
14237 +       char *name;
14238 +       mode_t mode;
14239 +};
14240 +
14241 +#define E(type,name,mode) {(type),sizeof(name)-1,(name),(mode)}
14242 +
14243 +static struct vid_entry vx_base_stuff[] = {
14244 +       E(PROC_XID_INFO,        "info",         S_IFREG|S_IRUGO),
14245 +       E(PROC_XID_STATUS,      "status",       S_IFREG|S_IRUGO),
14246 +       E(PROC_XID_LIMIT,       "limit",        S_IFREG|S_IRUGO),
14247 +       E(PROC_XID_SCHED,       "sched",        S_IFREG|S_IRUGO),
14248 +       E(PROC_XID_CVIRT,       "cvirt",        S_IFREG|S_IRUGO),
14249 +       E(PROC_XID_CACCT,       "cacct",        S_IFREG|S_IRUGO),
14250 +       {0,0,NULL,0}
14251 +};
14252 +
14253 +static struct vid_entry vn_base_stuff[] = {
14254 +       E(PROC_NID_INFO,        "info",         S_IFREG|S_IRUGO),
14255 +       E(PROC_NID_STATUS,      "status",       S_IFREG|S_IRUGO),
14256 +       {0,0,NULL,0}
14257 +};
14258 +
14259 +
14260 +
14261 +static struct dentry *proc_vid_lookup(struct inode *dir,
14262 +       struct dentry *dentry, struct nameidata *nd)
14263 +{
14264 +       struct inode *inode;
14265 +       struct vid_entry *p;
14266 +       int error;
14267 +
14268 +       error = -ENOENT;
14269 +       inode = NULL;
14270 +
14271 +       switch (inode_type(dir)) {
14272 +               case PROC_XID_INO:
14273 +                       p = vx_base_stuff;
14274 +                       break;
14275 +               case PROC_NID_INO:
14276 +                       p = vn_base_stuff;
14277 +                       break;
14278 +               default:
14279 +                       goto out;
14280 +       }
14281 +
14282 +       for (; p->name; p++) {
14283 +               if (p->len != dentry->d_name.len)
14284 +                       continue;
14285 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
14286 +                       break;
14287 +       }
14288 +       if (!p->name)
14289 +               goto out;
14290 +
14291 +       error = -EINVAL;
14292 +       inode = proc_vid_make_inode(dir->i_sb, inode_vid(dir), p->type);
14293 +       if (!inode)
14294 +               goto out;
14295 +
14296 +       switch(p->type) {
14297 +               case PROC_XID_INFO:
14298 +                       PROC_I(inode)->op.proc_vid_read = proc_xid_info;
14299 +                       break;
14300 +               case PROC_XID_STATUS:
14301 +                       PROC_I(inode)->op.proc_vid_read = proc_xid_status;
14302 +                       break;
14303 +               case PROC_XID_LIMIT:
14304 +                       PROC_I(inode)->op.proc_vid_read = proc_xid_limit;
14305 +                       break;
14306 +               case PROC_XID_SCHED:
14307 +                       PROC_I(inode)->op.proc_vid_read = proc_xid_sched;
14308 +                       break;
14309 +               case PROC_XID_CVIRT:
14310 +                       PROC_I(inode)->op.proc_vid_read = proc_xid_cvirt;
14311 +                       break;
14312 +               case PROC_XID_CACCT:
14313 +                       PROC_I(inode)->op.proc_vid_read = proc_xid_cacct;
14314 +                       break;
14315 +
14316 +               case PROC_NID_INFO:
14317 +                       PROC_I(inode)->op.proc_vid_read = proc_nid_info;
14318 +                       break;
14319 +               case PROC_NID_STATUS:
14320 +                       PROC_I(inode)->op.proc_vid_read = proc_nid_status;
14321 +                       break;
14322 +
14323 +               default:
14324 +                       printk("procfs: impossible type (%d)",p->type);
14325 +                       iput(inode);
14326 +                       return ERR_PTR(-EINVAL);
14327 +       }
14328 +       inode->i_mode = p->mode;
14329 +//     inode->i_op = &proc_vid_info_inode_operations;
14330 +       inode->i_fop = &proc_vid_info_file_operations;
14331 +       inode->i_nlink = 1;
14332 +       inode->i_flags|=S_IMMUTABLE;
14333 +
14334 +       dentry->d_op = &proc_vid_dentry_operations;
14335 +       d_add(dentry, inode);
14336 +       error = 0;
14337 +out:
14338 +       return ERR_PTR(error);
14339 +}
14340 +
14341 +
14342 +static int proc_vid_readdir(struct file * filp,
14343 +       void * dirent, filldir_t filldir)
14344 +{
14345 +       int i, size;
14346 +       struct inode *inode = filp->f_dentry->d_inode;
14347 +       struct vid_entry *p;
14348 +
14349 +       i = filp->f_pos;
14350 +       switch (i) {
14351 +               case 0:
14352 +                       if (filldir(dirent, ".", 1, i,
14353 +                               inode->i_ino, DT_DIR) < 0)
14354 +                               return 0;
14355 +                       i++;
14356 +                       filp->f_pos++;
14357 +                       /* fall through */
14358 +               case 1:
14359 +                       if (filldir(dirent, "..", 2, i,
14360 +                               PROC_ROOT_INO, DT_DIR) < 0)
14361 +                               return 0;
14362 +                       i++;
14363 +                       filp->f_pos++;
14364 +                       /* fall through */
14365 +               default:
14366 +                       i -= 2;
14367 +                       switch (inode_type(inode)) {
14368 +                               case PROC_XID_INO:
14369 +                                       size = sizeof(vx_base_stuff);
14370 +                                       p = vx_base_stuff + i;
14371 +                                       break;
14372 +                               case PROC_NID_INO:
14373 +                                       size = sizeof(vn_base_stuff);
14374 +                                       p = vn_base_stuff + i;
14375 +                                       break;
14376 +                               default:
14377 +                                       return 1;
14378 +                       }
14379 +                       if (i >= size/sizeof(struct vid_entry))
14380 +                               return 1;
14381 +                       while (p->name) {
14382 +                               if (filldir(dirent, p->name, p->len,
14383 +                                       filp->f_pos, fake_ino(inode_vid(inode),
14384 +                                       p->type), p->mode >> 12) < 0)
14385 +                                       return 0;
14386 +                               filp->f_pos++;
14387 +                               p++;
14388 +                       }
14389 +       }
14390 +       return 1;
14391 +}
14392 +
14393 +
14394 +
14395 +
14396 +/* now the upper level (virtual) */
14397 +
14398 +static struct file_operations proc_vid_file_operations = {
14399 +       read:           generic_read_dir,
14400 +       readdir:        proc_vid_readdir,
14401 +};
14402 +
14403 +static struct inode_operations proc_vid_inode_operations = {
14404 +       lookup:         proc_vid_lookup,
14405 +};
14406 +
14407 +
14408 +
14409 +static __inline__ int atovid(const char *str, int len)
14410 +{
14411 +       int vid, c;
14412 +
14413 +       vid = 0;
14414 +       while (len-- > 0) {
14415 +               c = *str - '0';
14416 +               str++;
14417 +               if (c > 9)
14418 +                       return -1;
14419 +               if (vid >= MAX_MULBY10)
14420 +                       return -1;
14421 +               vid *= 10;
14422 +               vid += c;
14423 +               if (!vid)
14424 +                       return -1;
14425 +       }
14426 +       return vid;
14427 +}
14428 +
14429 +
14430 +struct dentry *proc_virtual_lookup(struct inode *dir,
14431 +       struct dentry * dentry, struct nameidata *nd)
14432 +{
14433 +       int xid, len, ret;
14434 +       struct vx_info *vxi;
14435 +       const char *name;
14436 +       struct inode *inode;
14437 +
14438 +       name = dentry->d_name.name;
14439 +       len = dentry->d_name.len;
14440 +       ret = -ENOMEM;
14441 +
14442 +       if (len == 7 && !memcmp(name, "current", 7)) {
14443 +               inode = new_inode(dir->i_sb);
14444 +               if (!inode)
14445 +                       goto out;
14446 +               inode->i_mtime = inode->i_atime =
14447 +                       inode->i_ctime = CURRENT_TIME;
14448 +               inode->i_ino = fake_ino(1, PROC_XID_INO);
14449 +               inode->i_mode = S_IFLNK|S_IRWXUGO;
14450 +               inode->i_uid = inode->i_gid = 0;
14451 +               inode->i_size = 64;
14452 +//             inode->i_op = &proc_current_inode_operations;
14453 +               d_add(dentry, inode);
14454 +               return NULL;
14455 +       }
14456 +       if (len == 4 && !memcmp(name, "info", 4)) {
14457 +               inode = proc_vid_make_inode(dir->i_sb, 0, PROC_XID_INFO);
14458 +               if (!inode)
14459 +                       goto out;
14460 +               inode->i_fop = &proc_vid_info_file_operations;
14461 +               PROC_I(inode)->op.proc_vid_read = proc_virtual_info;
14462 +               inode->i_mode = S_IFREG|S_IRUGO;
14463 +//             inode->i_size = 64;
14464 +//             inode->i_op = &proc_current_inode_operations;
14465 +               d_add(dentry, inode);
14466 +               return NULL;
14467 +       }
14468 +
14469 +       ret = -ENOENT;
14470 +       xid = atovid(name, len);
14471 +       if (xid < 0)
14472 +               goto out;
14473 +       vxi = locate_vx_info(xid);
14474 +       if (!vxi)
14475 +               goto out;
14476 +
14477 +       inode = NULL;
14478 +       if (vx_check(xid, VX_ADMIN|VX_WATCH|VX_IDENT))
14479 +               inode = proc_vid_make_inode(dir->i_sb,
14480 +                       vxi->vx_id, PROC_XID_INO);
14481 +       if (!inode)
14482 +               goto out_release;
14483 +
14484 +       inode->i_mode = S_IFDIR|S_IRUGO;
14485 +       inode->i_op = &proc_vid_inode_operations;
14486 +       inode->i_fop = &proc_vid_file_operations;
14487 +       inode->i_nlink = 2;
14488 +       inode->i_flags|=S_IMMUTABLE;
14489 +
14490 +       dentry->d_op = &proc_vid_dentry_operations;
14491 +       d_add(dentry, inode);
14492 +       ret = 0;
14493 +
14494 +out_release:
14495 +       put_vx_info(vxi);
14496 +out:
14497 +       return ERR_PTR(ret);
14498 +}
14499 +
14500 +
14501 +struct dentry *proc_vnet_lookup(struct inode *dir,
14502 +       struct dentry * dentry, struct nameidata *nd)
14503 +{
14504 +       int nid, len, ret;
14505 +       struct nx_info *nxi;
14506 +       const char *name;
14507 +       struct inode *inode;
14508 +
14509 +       name = dentry->d_name.name;
14510 +       len = dentry->d_name.len;
14511 +       ret = -ENOMEM;
14512 +       if (len == 7 && !memcmp(name, "current", 7)) {
14513 +               inode = new_inode(dir->i_sb);
14514 +               if (!inode)
14515 +                       goto out;
14516 +               inode->i_mtime = inode->i_atime =
14517 +                       inode->i_ctime = CURRENT_TIME;
14518 +               inode->i_ino = fake_ino(1, PROC_NID_INO);
14519 +               inode->i_mode = S_IFLNK|S_IRWXUGO;
14520 +               inode->i_uid = inode->i_gid = 0;
14521 +               inode->i_size = 64;
14522 +//             inode->i_op = &proc_current_inode_operations;
14523 +               d_add(dentry, inode);
14524 +               return NULL;
14525 +       }
14526 +       if (len == 4 && !memcmp(name, "info", 4)) {
14527 +               inode = proc_vid_make_inode(dir->i_sb, 0, PROC_NID_INFO);
14528 +               if (!inode)
14529 +                       goto out;
14530 +               inode->i_fop = &proc_vid_info_file_operations;
14531 +               PROC_I(inode)->op.proc_vid_read = proc_vnet_info;
14532 +               inode->i_mode = S_IFREG|S_IRUGO;
14533 +//             inode->i_size = 64;
14534 +//             inode->i_op = &proc_current_inode_operations;
14535 +               d_add(dentry, inode);
14536 +               return NULL;
14537 +       }
14538 +
14539 +       ret = -ENOENT;
14540 +       nid = atovid(name, len);
14541 +       if (nid < 0)
14542 +               goto out;
14543 +       nxi = locate_nx_info(nid);
14544 +       if (!nxi)
14545 +               goto out;
14546 +
14547 +       inode = NULL;
14548 +       if (1)
14549 +               inode = proc_vid_make_inode(dir->i_sb,
14550 +                       nxi->nx_id, PROC_NID_INO);
14551 +       if (!inode)
14552 +               goto out_release;
14553 +
14554 +       inode->i_mode = S_IFDIR|S_IRUGO;
14555 +       inode->i_op = &proc_vid_inode_operations;
14556 +       inode->i_fop = &proc_vid_file_operations;
14557 +       inode->i_nlink = 2;
14558 +       inode->i_flags|=S_IMMUTABLE;
14559 +
14560 +       dentry->d_op = &proc_vid_dentry_operations;
14561 +       d_add(dentry, inode);
14562 +       ret = 0;
14563 +
14564 +out_release:
14565 +       put_nx_info(nxi);
14566 +out:
14567 +       return ERR_PTR(ret);
14568 +}
14569 +
14570 +
14571 +
14572 +
14573 +#define PROC_NUMBUF 10
14574 +#define PROC_MAXVIDS 32
14575 +
14576 +int proc_virtual_readdir(struct file * filp,
14577 +       void * dirent, filldir_t filldir)
14578 +{
14579 +       unsigned int xid_array[PROC_MAXVIDS];
14580 +       char buf[PROC_NUMBUF];
14581 +       unsigned int nr = filp->f_pos-3;
14582 +       unsigned int nr_xids, i;
14583 +       ino_t ino;
14584 +
14585 +       switch ((long)filp->f_pos) {
14586 +               case 0:
14587 +                       ino = fake_ino(0, PROC_XID_INO);
14588 +                       if (filldir(dirent, ".", 1,
14589 +                               filp->f_pos, ino, DT_DIR) < 0)
14590 +                               return 0;
14591 +                       filp->f_pos++;
14592 +                       /* fall through */
14593 +               case 1:
14594 +                       ino = filp->f_dentry->d_parent->d_inode->i_ino;
14595 +                       if (filldir(dirent, "..", 2,
14596 +                               filp->f_pos, ino, DT_DIR) < 0)
14597 +                               return 0;
14598 +                       filp->f_pos++;
14599 +                       /* fall through */
14600 +               case 2:
14601 +                       ino = fake_ino(0, PROC_XID_INFO);
14602 +                       if (filldir(dirent, "info", 4,
14603 +                               filp->f_pos, ino, DT_LNK) < 0)
14604 +                               return 0;
14605 +                       filp->f_pos++;
14606 +                       /* fall through */
14607 +               case 3:
14608 +                       if (vx_current_xid() > 1) {
14609 +                               ino = fake_ino(1, PROC_XID_INO);
14610 +                               if (filldir(dirent, "current", 7,
14611 +                                       filp->f_pos, ino, DT_LNK) < 0)
14612 +                                       return 0;
14613 +                       }
14614 +                       filp->f_pos++;
14615 +       }
14616 +
14617 +       nr_xids = get_xid_list(nr, xid_array, PROC_MAXVIDS);
14618 +       for (i = 0; i < nr_xids; i++) {
14619 +               int xid = xid_array[i];
14620 +               ino_t ino = fake_ino(xid, PROC_XID_INO);
14621 +               unsigned int j = PROC_NUMBUF;
14622 +
14623 +               do buf[--j] = '0' + (xid % 10); while (xid/=10);
14624 +
14625 +               if (filldir(dirent, buf+j, PROC_NUMBUF-j,
14626 +                       filp->f_pos, ino, DT_DIR) < 0)
14627 +                       break;
14628 +               filp->f_pos++;
14629 +       }
14630 +       return 0;
14631 +}
14632 +
14633 +
14634 +static struct file_operations proc_virtual_dir_operations = {
14635 +       read:           generic_read_dir,
14636 +       readdir:        proc_virtual_readdir,
14637 +};
14638 +
14639 +static struct inode_operations proc_virtual_dir_inode_operations = {
14640 +       lookup:         proc_virtual_lookup,
14641 +};
14642 +
14643 +
14644 +int proc_vnet_readdir(struct file * filp,
14645 +       void * dirent, filldir_t filldir)
14646 +{
14647 +       unsigned int nid_array[PROC_MAXVIDS];
14648 +       char buf[PROC_NUMBUF];
14649 +       unsigned int nr = filp->f_pos-3;
14650 +       unsigned int nr_nids, i;
14651 +       ino_t ino;
14652 +
14653 +       switch ((long)filp->f_pos) {
14654 +               case 0:
14655 +                       ino = fake_ino(0, PROC_NID_INO);
14656 +                       if (filldir(dirent, ".", 1,
14657 +                               filp->f_pos, ino, DT_DIR) < 0)
14658 +                               return 0;
14659 +                       filp->f_pos++;
14660 +                       /* fall through */
14661 +               case 1:
14662 +                       ino = filp->f_dentry->d_parent->d_inode->i_ino;
14663 +                       if (filldir(dirent, "..", 2,
14664 +                               filp->f_pos, ino, DT_DIR) < 0)
14665 +                               return 0;
14666 +                       filp->f_pos++;
14667 +                       /* fall through */
14668 +               case 2:
14669 +                       ino = fake_ino(0, PROC_NID_INFO);
14670 +                       if (filldir(dirent, "info", 4,
14671 +                               filp->f_pos, ino, DT_LNK) < 0)
14672 +                               return 0;
14673 +                       filp->f_pos++;
14674 +                       /* fall through */
14675 +               case 3:
14676 +                       if (vx_current_xid() > 1) {
14677 +                               ino = fake_ino(1, PROC_NID_INO);
14678 +                               if (filldir(dirent, "current", 7,
14679 +                                       filp->f_pos, ino, DT_LNK) < 0)
14680 +                                       return 0;
14681 +                       }
14682 +                       filp->f_pos++;
14683 +       }
14684 +
14685 +       nr_nids = get_nid_list(nr, nid_array, PROC_MAXVIDS);
14686 +       for (i = 0; i < nr_nids; i++) {
14687 +               int nid = nid_array[i];
14688 +               ino_t ino = fake_ino(nid, PROC_NID_INO);
14689 +               unsigned long j = PROC_NUMBUF;
14690 +
14691 +               do buf[--j] = '0' + (nid % 10); while (nid/=10);
14692 +
14693 +               if (filldir(dirent, buf+j, PROC_NUMBUF-j,
14694 +                       filp->f_pos, ino, DT_DIR) < 0)
14695 +                       break;
14696 +               filp->f_pos++;
14697 +       }
14698 +       return 0;
14699 +}
14700 +
14701 +
14702 +static struct file_operations proc_vnet_dir_operations = {
14703 +       read:           generic_read_dir,
14704 +       readdir:        proc_vnet_readdir,
14705 +};
14706 +
14707 +static struct inode_operations proc_vnet_dir_inode_operations = {
14708 +       lookup:         proc_vnet_lookup,
14709 +};
14710 +
14711 +
14712 +
14713 +void proc_vx_init(void)
14714 +{
14715 +       struct proc_dir_entry *ent;
14716 +
14717 +       ent = proc_mkdir("virtual", 0);
14718 +       if (ent) {
14719 +               ent->proc_fops = &proc_virtual_dir_operations;
14720 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
14721 +       }
14722 +       proc_virtual = ent;
14723 +
14724 +       ent = proc_mkdir("virtnet", 0);
14725 +       if (ent) {
14726 +               ent->proc_fops = &proc_vnet_dir_operations;
14727 +               ent->proc_iops = &proc_vnet_dir_inode_operations;
14728 +       }
14729 +       proc_vnet = ent;
14730 +}
14731 +
14732 +
14733 +
14734 +
14735 +/* per pid info */
14736 +
14737 +
14738 +char *task_vx_info(struct task_struct *p, char *buffer)
14739 +{
14740 +       struct vx_info *vxi;
14741 +
14742 +       buffer += sprintf (buffer,"XID:\t%d\n", vx_task_xid(p));
14743 +       vxi = task_get_vx_info(p);
14744 +       if (vxi && !vx_flags(VXF_INFO_HIDE, 0)) {
14745 +               buffer += sprintf (buffer,"BCaps:\t%016llx\n"
14746 +                       ,(unsigned long long)vxi->vx_bcaps);
14747 +               buffer += sprintf (buffer,"CCaps:\t%016llx\n"
14748 +                       ,(unsigned long long)vxi->vx_ccaps);
14749 +               buffer += sprintf (buffer,"CFlags:\t%016llx\n"
14750 +                       ,(unsigned long long)vxi->vx_flags);
14751 +               buffer += sprintf (buffer,"CIPid:\t%d\n"
14752 +                       ,vxi->vx_initpid);
14753 +       }
14754 +       put_vx_info(vxi);
14755 +       return buffer;
14756 +}
14757 +
14758 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
14759 +{
14760 +       char * orig = buffer;
14761 +
14762 +       buffer = task_vx_info(p, buffer);
14763 +       return buffer - orig;
14764 +}
14765 +
14766 +char *task_nx_info(struct task_struct *p, char *buffer)
14767 +{
14768 +       struct nx_info *nxi;
14769 +
14770 +       buffer += sprintf (buffer,"NID:\t%d\n", nx_task_nid(p));
14771 +       nxi = task_get_nx_info(p);
14772 +       if (nxi && !vx_flags(VXF_INFO_HIDE, 0)) {
14773 +               int i;
14774 +
14775 +               for (i=0; i<nxi->nbipv4; i++){
14776 +                       buffer += sprintf (buffer,
14777 +                               "V4Root[%d]:\t%d.%d.%d.%d/%d.%d.%d.%d\n", i
14778 +                               ,NIPQUAD(nxi->ipv4[i])
14779 +                               ,NIPQUAD(nxi->mask[i]));
14780 +               }
14781 +               buffer += sprintf (buffer,
14782 +                       "V4Root[bcast]:\t%d.%d.%d.%d\n"
14783 +                       ,NIPQUAD(nxi->v4_bcast));
14784 +       }
14785 +       put_nx_info(nxi);
14786 +       return buffer;
14787 +}
14788 +
14789 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
14790 +{
14791 +       char * orig = buffer;
14792 +
14793 +       buffer = task_nx_info(p, buffer);
14794 +       return buffer - orig;
14795 +}
14796 +
14797 diff -NurpP --minimal linux-2.6.10/kernel/vserver/sched.c linux-2.6.10-vs1.9.3.17/kernel/vserver/sched.c
14798 --- linux-2.6.10/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
14799 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/sched.c      2004-12-26 19:40:30.000000000 +0100
14800 @@ -0,0 +1,225 @@
14801 +/*
14802 + *  linux/kernel/vserver/sched.c
14803 + *
14804 + *  Virtual Server: Scheduler Support
14805 + *
14806 + *  Copyright (C) 2004  Herbert Pötzl
14807 + *
14808 + *  V0.01  adapted Sam Vilains version to 2.6.3
14809 + *  V0.02  removed legacy interface
14810 + *
14811 + */
14812 +
14813 +#include <linux/config.h>
14814 +#include <linux/sched.h>
14815 +// #include <linux/vs_base.h>
14816 +#include <linux/vs_context.h>
14817 +#include <linux/vs_sched.h>
14818 +#include <linux/vserver/sched_cmd.h>
14819 +
14820 +#include <asm/errno.h>
14821 +#include <asm/uaccess.h>
14822 +
14823 +
14824 +/*
14825 + * recalculate the context's scheduling tokens
14826 + *
14827 + * ret > 0 : number of tokens available
14828 + * ret = 0 : context is paused
14829 + * ret < 0 : number of jiffies until new tokens arrive
14830 + *
14831 + */
14832 +int vx_tokens_recalc(struct vx_info *vxi)
14833 +{
14834 +       long delta, tokens = 0;
14835 +
14836 +       if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
14837 +               /* we are paused */
14838 +               return 0;
14839 +
14840 +       delta = jiffies - vxi->sched.jiffies;
14841 +
14842 +       if (delta >= vxi->sched.interval) {
14843 +               /* lockdown scheduler info */
14844 +               spin_lock(&vxi->sched.tokens_lock);
14845 +
14846 +               /* calc integral token part */
14847 +               delta = jiffies - vxi->sched.jiffies;
14848 +               tokens = delta / vxi->sched.interval;
14849 +               delta = tokens * vxi->sched.interval;
14850 +               tokens *= vxi->sched.fill_rate;
14851 +
14852 +               atomic_add(tokens, &vxi->sched.tokens);
14853 +               vxi->sched.jiffies += delta;
14854 +               tokens = atomic_read(&vxi->sched.tokens);
14855 +
14856 +               if (tokens > vxi->sched.tokens_max) {
14857 +                       tokens = vxi->sched.tokens_max;
14858 +                       atomic_set(&vxi->sched.tokens, tokens);
14859 +               }
14860 +               spin_unlock(&vxi->sched.tokens_lock);
14861 +       } else {
14862 +               /* no new tokens */
14863 +               tokens = vx_tokens_avail(vxi);
14864 +               if (tokens <= 0)
14865 +                       vxi->vx_state |= VXS_ONHOLD;
14866 +               if (tokens < vxi->sched.tokens_min) {
14867 +                       /* enough tokens will be available in */
14868 +                       if (vxi->sched.tokens_min == 0)
14869 +                               return delta - vxi->sched.interval;
14870 +                       return delta - vxi->sched.interval *
14871 +                               vxi->sched.tokens_min / vxi->sched.fill_rate;
14872 +               }
14873 +       }
14874 +
14875 +       /* we have some tokens left */
14876 +       if (vx_info_state(vxi, VXS_ONHOLD) &&
14877 +               (tokens >= vxi->sched.tokens_min))
14878 +               vxi->vx_state &= ~VXS_ONHOLD;
14879 +       if (vx_info_state(vxi, VXS_ONHOLD))
14880 +               tokens -= vxi->sched.tokens_min;
14881 +
14882 +       return tokens;
14883 +}
14884 +
14885 +/*
14886 + * effective_prio - return the priority that is based on the static
14887 + * priority but is modified by bonuses/penalties.
14888 + *
14889 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14890 + * into a -4 ... 0 ... +4 bonus/penalty range.
14891 + *
14892 + * Additionally, we scale another amount based on the number of
14893 + * CPU tokens currently held by the context, if the process is
14894 + * part of a context (and the appropriate SCHED flag is set).
14895 + * This ranges from -5 ... 0 ... +15, quadratically.
14896 + *
14897 + * So, the total bonus is -9 .. 0 .. +19
14898 + * We use ~50% of the full 0...39 priority range so that:
14899 + *
14900 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14901 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14902 + *    unless that context is far exceeding its CPU allocation.
14903 + *
14904 + * Both properties are important to certain workloads.
14905 + */
14906 +int effective_vavavoom(task_t *p, int max_prio)
14907 +{
14908 +       struct vx_info *vxi = p->vx_info;
14909 +       int vavavoom, max;
14910 +
14911 +       /* lots of tokens = lots of vavavoom
14912 +        *      no tokens = no vavavoom      */
14913 +       if ((vavavoom = atomic_read(&vxi->sched.tokens)) >= 0) {
14914 +               max = vxi->sched.tokens_max;
14915 +               vavavoom = max - vavavoom;
14916 +               max = max * max;
14917 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14918 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14919 +               /*  alternative, geometric mapping
14920 +               vavavoom = -( MAX_USER_PRIO*VAVAVOOM_RATIO/100 * vavavoom
14921 +                       / vxi->sched.tokens_max -
14922 +                       MAX_USER_PRIO*VAVAVOOM_RATIO/100/2); */
14923 +       } else
14924 +               vavavoom = 0;
14925 +       /* vavavoom = ( MAX_USER_PRIO*VAVAVOOM_RATIO/100*tokens_left(p) -
14926 +               MAX_USER_PRIO*VAVAVOOM_RATIO/100/2); */
14927 +
14928 +       return vavavoom;
14929 +}
14930 +
14931 +
14932 +int vc_set_sched_v2(uint32_t xid, void __user *data)
14933 +{
14934 +       struct vcmd_set_sched_v2 vc_data;
14935 +       struct vx_info *vxi;
14936 +
14937 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
14938 +               return -EFAULT;
14939 +
14940 +       vxi = locate_vx_info(xid);
14941 +       if (!vxi)
14942 +               return -EINVAL;
14943 +
14944 +       spin_lock(&vxi->sched.tokens_lock);
14945 +
14946 +       if (vc_data.interval != SCHED_KEEP)
14947 +               vxi->sched.interval = vc_data.interval;
14948 +       if (vc_data.fill_rate != SCHED_KEEP)
14949 +               vxi->sched.fill_rate = vc_data.fill_rate;
14950 +       if (vc_data.tokens_min != SCHED_KEEP)
14951 +               vxi->sched.tokens_min = vc_data.tokens_min;
14952 +       if (vc_data.tokens_max != SCHED_KEEP)
14953 +               vxi->sched.tokens_max = vc_data.tokens_max;
14954 +       if (vc_data.tokens != SCHED_KEEP)
14955 +               atomic_set(&vxi->sched.tokens, vc_data.tokens);
14956 +
14957 +       /* Sanity check the resultant values */
14958 +       if (vxi->sched.fill_rate <= 0)
14959 +               vxi->sched.fill_rate = 1;
14960 +       if (vxi->sched.interval <= 0)
14961 +               vxi->sched.interval = HZ;
14962 +       if (vxi->sched.tokens_max == 0)
14963 +               vxi->sched.tokens_max = 1;
14964 +       if (atomic_read(&vxi->sched.tokens) > vxi->sched.tokens_max)
14965 +               atomic_set(&vxi->sched.tokens, vxi->sched.tokens_max);
14966 +       if (vxi->sched.tokens_min > vxi->sched.tokens_max)
14967 +               vxi->sched.tokens_min = vxi->sched.tokens_max;
14968 +
14969 +       spin_unlock(&vxi->sched.tokens_lock);
14970 +       put_vx_info(vxi);
14971 +       return 0;
14972 +}
14973 +
14974 +
14975 +int vc_set_sched(uint32_t xid, void __user *data)
14976 +{
14977 +       struct vcmd_set_sched_v3 vc_data;
14978 +       struct vx_info *vxi;
14979 +       unsigned int set_mask;
14980 +
14981 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
14982 +               return -EFAULT;
14983 +
14984 +       vxi = locate_vx_info(xid);
14985 +       if (!vxi)
14986 +               return -EINVAL;
14987 +
14988 +       set_mask = vc_data.set_mask;
14989 +
14990 +       spin_lock(&vxi->sched.tokens_lock);
14991 +
14992 +       if (set_mask & VXSM_FILL_RATE)
14993 +               vxi->sched.fill_rate = vc_data.fill_rate;
14994 +       if (set_mask & VXSM_INTERVAL)
14995 +               vxi->sched.interval = vc_data.interval;
14996 +       if (set_mask & VXSM_TOKENS)
14997 +               atomic_set(&vxi->sched.tokens, vc_data.tokens);
14998 +       if (set_mask & VXSM_TOKENS_MIN)
14999 +               vxi->sched.tokens_min = vc_data.tokens_min;
15000 +       if (set_mask & VXSM_TOKENS_MAX)
15001 +               vxi->sched.tokens_max = vc_data.tokens_max;
15002 +       if (set_mask & VXSM_PRIO_BIAS)
15003 +               vxi->sched.priority_bias = vc_data.priority_bias;
15004 +
15005 +       /* Sanity check the resultant values */
15006 +       if (vxi->sched.fill_rate <= 0)
15007 +               vxi->sched.fill_rate = 1;
15008 +       if (vxi->sched.interval <= 0)
15009 +               vxi->sched.interval = HZ;
15010 +       if (vxi->sched.tokens_max == 0)
15011 +               vxi->sched.tokens_max = 1;
15012 +       if (atomic_read(&vxi->sched.tokens) > vxi->sched.tokens_max)
15013 +               atomic_set(&vxi->sched.tokens, vxi->sched.tokens_max);
15014 +       if (vxi->sched.tokens_min > vxi->sched.tokens_max)
15015 +               vxi->sched.tokens_min = vxi->sched.tokens_max;
15016 +       if (vxi->sched.priority_bias > MAX_PRIO_BIAS)
15017 +               vxi->sched.priority_bias = MAX_PRIO_BIAS;
15018 +       if (vxi->sched.priority_bias < MIN_PRIO_BIAS)
15019 +               vxi->sched.priority_bias = MIN_PRIO_BIAS;
15020 +
15021 +       spin_unlock(&vxi->sched.tokens_lock);
15022 +       put_vx_info(vxi);
15023 +       return 0;
15024 +}
15025 +
15026 diff -NurpP --minimal linux-2.6.10/kernel/vserver/sched_init.h linux-2.6.10-vs1.9.3.17/kernel/vserver/sched_init.h
15027 --- linux-2.6.10/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
15028 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/sched_init.h 2004-12-26 19:40:36.000000000 +0100
15029 @@ -0,0 +1,29 @@
15030 +
15031 +static inline void vx_info_init_sched(struct _vx_sched *sched)
15032 +{
15033 +       int i;
15034 +
15035 +       /* scheduling; hard code starting values as constants */
15036 +       sched->fill_rate        = 1;
15037 +       sched->interval         = 4;
15038 +       sched->tokens_min       = HZ >> 4;
15039 +       sched->tokens_max       = HZ >> 1;
15040 +       sched->jiffies          = jiffies;
15041 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
15042 +
15043 +       atomic_set(&sched->tokens, HZ >> 2);
15044 +       sched->cpus_allowed     = CPU_MASK_ALL;
15045 +       sched->priority_bias    = 0;
15046 +
15047 +       for_each_cpu(i) {
15048 +               sched->cpu[i].user_ticks        = 0;
15049 +               sched->cpu[i].sys_ticks         = 0;
15050 +               sched->cpu[i].hold_ticks        = 0;
15051 +       }
15052 +}
15053 +
15054 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
15055 +{
15056 +       return;
15057 +}
15058 +
15059 diff -NurpP --minimal linux-2.6.10/kernel/vserver/sched_proc.h linux-2.6.10-vs1.9.3.17/kernel/vserver/sched_proc.h
15060 --- linux-2.6.10/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
15061 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/sched_proc.h 2004-12-26 19:40:36.000000000 +0100
15062 @@ -0,0 +1,38 @@
15063 +#ifndef _VX_SCHED_PROC_H
15064 +#define _VX_SCHED_PROC_H
15065 +
15066 +
15067 +static inline int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
15068 +{
15069 +       int length = 0;
15070 +       int i;
15071 +
15072 +       length += sprintf(buffer,
15073 +               "Token:\t\t%8d\n"
15074 +               "FillRate:\t%8d\n"
15075 +               "Interval:\t%8d\n"
15076 +               "TokensMin:\t%8d\n"
15077 +               "TokensMax:\t%8d\n"
15078 +               "PrioBias:\t%8d\n"
15079 +               ,atomic_read(&sched->tokens)
15080 +               ,sched->fill_rate
15081 +               ,sched->interval
15082 +               ,sched->tokens_min
15083 +               ,sched->tokens_max
15084 +               ,sched->priority_bias
15085 +               );
15086 +
15087 +       for_each_online_cpu(i) {
15088 +               length += sprintf(buffer + length,
15089 +                       "cpu %d: %lld %lld %lld\n"
15090 +                       ,i
15091 +                       ,(long long)sched->cpu[i].user_ticks
15092 +                       ,(long long)sched->cpu[i].sys_ticks
15093 +                       ,(long long)sched->cpu[i].hold_ticks
15094 +                       );
15095 +       }
15096 +
15097 +       return length;
15098 +}
15099 +
15100 +#endif /* _VX_SCHED_PROC_H */
15101 diff -NurpP --minimal linux-2.6.10/kernel/vserver/signal.c linux-2.6.10-vs1.9.3.17/kernel/vserver/signal.c
15102 --- linux-2.6.10/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
15103 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/signal.c     2004-12-26 19:40:30.000000000 +0100
15104 @@ -0,0 +1,126 @@
15105 +/*
15106 + *  linux/kernel/vserver/signal.c
15107 + *
15108 + *  Virtual Server: Signal Support
15109 + *
15110 + *  Copyright (C) 2003-2004  Herbert Pötzl
15111 + *
15112 + *  V0.01  broken out from vcontext V0.05
15113 + *
15114 + */
15115 +
15116 +#include <linux/config.h>
15117 +#include <linux/sched.h>
15118 +
15119 +#include <asm/errno.h>
15120 +#include <asm/uaccess.h>
15121 +
15122 +#include <linux/vs_context.h>
15123 +#include <linux/vserver/signal.h>
15124 +
15125 +
15126 +int vc_ctx_kill(uint32_t id, void __user *data)
15127 +{
15128 +       int retval, count=0;
15129 +       struct vcmd_ctx_kill_v0 vc_data;
15130 +       struct siginfo info;
15131 +       struct task_struct *p;
15132 +       struct vx_info *vxi;
15133 +
15134 +       if (!vx_check(0, VX_ADMIN))
15135 +               return -ENOSYS;
15136 +       if (copy_from_user (&vc_data, data, sizeof(vc_data)))
15137 +               return -EFAULT;
15138 +
15139 +       info.si_signo = vc_data.sig;
15140 +       info.si_errno = 0;
15141 +       info.si_code = SI_USER;
15142 +       info.si_pid = current->pid;
15143 +       info.si_uid = current->uid;
15144 +
15145 +       vxi = locate_vx_info(id);
15146 +       if (!vxi)
15147 +               return -ESRCH;
15148 +
15149 +       retval = -ESRCH;
15150 +       read_lock(&tasklist_lock);
15151 +       switch (vc_data.pid) {
15152 +       case -1:
15153 +       case  0:
15154 +               for_each_process(p) {
15155 +                       int err = 0;
15156 +
15157 +                       if (vx_task_xid(p) != id || p->pid <= 1 ||
15158 +                               (vc_data.pid && vxi->vx_initpid == p->pid) ||
15159 +                               !thread_group_leader(p))
15160 +                               continue;
15161 +
15162 +                       err = send_sig_info(vc_data.sig, &info, p);
15163 +                       ++count;
15164 +                       if (err != -EPERM)
15165 +                               retval = err;
15166 +               }
15167 +               break;
15168 +
15169 +       default:
15170 +       p = find_task_by_real_pid(vc_data.pid);
15171 +               if (p) {
15172 +                       if (!thread_group_leader(p)) {
15173 +                               struct task_struct *tg;
15174 +
15175 +                               tg = find_task_by_real_pid(p->tgid);
15176 +                               if (tg)
15177 +                                       p = tg;
15178 +                       }
15179 +                       if ((id == -1) || (vx_task_xid(p) == id))
15180 +                               retval = send_sig_info(vc_data.sig, &info, p);
15181 +               }
15182 +               break;
15183 +       }
15184 +       read_unlock(&tasklist_lock);
15185 +       put_vx_info(vxi);
15186 +       return retval;
15187 +}
15188 +
15189 +
15190 +static int __wait_exit(struct vx_info *vxi)
15191 +{
15192 +       DECLARE_WAITQUEUE(wait, current);
15193 +       int ret = 0;
15194 +
15195 +       add_wait_queue(&vxi->vx_exit, &wait);
15196 +       set_current_state(TASK_INTERRUPTIBLE);
15197 +
15198 +wait:
15199 +       if (vx_info_state(vxi, VXS_DEFUNCT))
15200 +               goto out;
15201 +       if (signal_pending(current)) {
15202 +               ret = -ERESTARTSYS;
15203 +               goto out;
15204 +       }
15205 +       schedule();
15206 +       goto wait;
15207 +
15208 +out:
15209 +       set_current_state(TASK_RUNNING);
15210 +       remove_wait_queue(&vxi->vx_exit, &wait);
15211 +       return ret;
15212 +}
15213 +
15214 +
15215 +
15216 +int vc_wait_exit(uint32_t id, void __user *data)
15217 +{
15218 +//     struct vcmd_wait_exit_v0 vc_data;
15219 +       struct vx_info *vxi;
15220 +       int ret;
15221 +
15222 +       vxi = locate_vx_info(id);
15223 +       if (!vxi)
15224 +               return -ESRCH;
15225 +
15226 +       ret = __wait_exit(vxi);
15227 +       put_vx_info(vxi);
15228 +       return ret;
15229 +}
15230 +
15231 diff -NurpP --minimal linux-2.6.10/kernel/vserver/switch.c linux-2.6.10-vs1.9.3.17/kernel/vserver/switch.c
15232 --- linux-2.6.10/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
15233 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/switch.c     2005-01-02 10:40:56.000000000 +0100
15234 @@ -0,0 +1,206 @@
15235 +/*
15236 + *  linux/kernel/vserver/switch.c
15237 + *
15238 + *  Virtual Server: Syscall Switch
15239 + *
15240 + *  Copyright (C) 2003-2005  Herbert Pötzl
15241 + *
15242 + *  V0.01  syscall switch
15243 + *  V0.02  added signal to context
15244 + *  V0.03  added rlimit functions
15245 + *  V0.04  added iattr, task/xid functions
15246 + *  V0.05  added debug/history stuff
15247 + *
15248 + */
15249 +
15250 +#include <linux/config.h>
15251 +#include <linux/linkage.h>
15252 +#include <linux/sched.h>
15253 +#include <asm/errno.h>
15254 +
15255 +#include <linux/vserver/network.h>
15256 +#include <linux/vserver/switch.h>
15257 +#include <linux/vserver/debug.h>
15258 +
15259 +
15260 +static inline int
15261 +vc_get_version(uint32_t id)
15262 +{
15263 +       return VCI_VERSION;
15264 +}
15265 +
15266 +#include <linux/vserver/context_cmd.h>
15267 +#include <linux/vserver/cvirt_cmd.h>
15268 +#include <linux/vserver/limit_cmd.h>
15269 +#include <linux/vserver/network_cmd.h>
15270 +#include <linux/vserver/sched_cmd.h>
15271 +#include <linux/vserver/debug_cmd.h>
15272 +
15273 +#include <linux/vserver/legacy.h>
15274 +#include <linux/vserver/namespace.h>
15275 +#include <linux/vserver/inode.h>
15276 +#include <linux/vserver/signal.h>
15277 +#include <linux/vserver/dlimit.h>
15278 +
15279 +
15280 +extern asmlinkage long
15281 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
15282 +{
15283 +       vxdprintk(VXD_CBIT(switch, 0),
15284 +               "vc: VCMD_%02d_%d[%d], %d",
15285 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
15286 +               VC_VERSION(cmd), id);
15287 +
15288 +#ifdef CONFIG_VSERVER_LEGACY
15289 +       if (!capable(CAP_CONTEXT) &&
15290 +               /* dirty hack for capremove */
15291 +               !(cmd==VCMD_new_s_context && id==-2))
15292 +               return -EPERM;
15293 +#else
15294 +       if (!capable(CAP_CONTEXT))
15295 +               return -EPERM;
15296 +#endif
15297 +
15298 +       switch (cmd) {
15299 +       case VCMD_get_version:
15300 +               return vc_get_version(id);
15301 +
15302 +       case VCMD_dump_history:
15303 +#ifdef CONFIG_VSERVER_HISTORY
15304 +               return vc_dump_history(id);
15305 +#else
15306 +               return -ENOSYS;
15307 +#endif
15308 +
15309 +#ifdef CONFIG_VSERVER_LEGACY
15310 +       case VCMD_new_s_context:
15311 +               return vc_new_s_context(id, data);
15312 +       case VCMD_set_ipv4root:
15313 +               return vc_set_ipv4root(id, data);
15314 +#endif
15315 +
15316 +       case VCMD_task_xid:
15317 +               return vc_task_xid(id, data);
15318 +       case VCMD_vx_info:
15319 +               return vc_vx_info(id, data);
15320 +
15321 +       case VCMD_task_nid:
15322 +               return vc_task_nid(id, data);
15323 +       case VCMD_nx_info:
15324 +               return vc_nx_info(id, data);
15325 +
15326 +       case VCMD_set_namespace:
15327 +               return vc_set_namespace(id, data);
15328 +       case VCMD_cleanup_namespace:
15329 +               return vc_cleanup_namespace(id, data);
15330 +       }
15331 +
15332 +       /* those are allowed while in setup too */
15333 +       if (!vx_check(0, VX_ADMIN|VX_WATCH) &&
15334 +               !vx_flags(VXF_STATE_SETUP,0))
15335 +               return -EPERM;
15336 +
15337 +#ifdef CONFIG_VSERVER_LEGACY
15338 +       switch (cmd) {
15339 +       case VCMD_set_cflags:
15340 +       case VCMD_set_ccaps:
15341 +               if (vx_check(0, VX_WATCH))
15342 +                       return 0;
15343 +       }
15344 +#endif
15345 +
15346 +       switch (cmd) {
15347 +       case VCMD_get_rlimit:
15348 +               return vc_get_rlimit(id, data);
15349 +       case VCMD_set_rlimit:
15350 +               return vc_set_rlimit(id, data);
15351 +       case VCMD_get_rlimit_mask:
15352 +               return vc_get_rlimit_mask(id, data);
15353 +
15354 +       case VCMD_vx_get_vhi_name:
15355 +               return vc_get_vhi_name(id, data);
15356 +       case VCMD_vx_set_vhi_name:
15357 +               return vc_set_vhi_name(id, data);
15358 +
15359 +       case VCMD_set_cflags:
15360 +               return vc_set_cflags(id, data);
15361 +       case VCMD_get_cflags:
15362 +               return vc_get_cflags(id, data);
15363 +
15364 +       case VCMD_set_ccaps:
15365 +               return vc_set_ccaps(id, data);
15366 +       case VCMD_get_ccaps:
15367 +               return vc_get_ccaps(id, data);
15368 +
15369 +       case VCMD_set_nflags:
15370 +               return vc_set_nflags(id, data);
15371 +       case VCMD_get_nflags:
15372 +               return vc_get_nflags(id, data);
15373 +
15374 +       case VCMD_set_ncaps:
15375 +               return vc_set_ncaps(id, data);
15376 +       case VCMD_get_ncaps:
15377 +               return vc_get_ncaps(id, data);
15378 +
15379 +       case VCMD_set_sched_v2:
15380 +               return vc_set_sched_v2(id, data);
15381 +       /* this is version 3 */
15382 +       case VCMD_set_sched:
15383 +               return vc_set_sched(id, data);
15384 +
15385 +       case VCMD_add_dlimit:
15386 +               return vc_add_dlimit(id, data);
15387 +       case VCMD_rem_dlimit:
15388 +               return vc_rem_dlimit(id, data);
15389 +       case VCMD_set_dlimit:
15390 +               return vc_set_dlimit(id, data);
15391 +       case VCMD_get_dlimit:
15392 +               return vc_get_dlimit(id, data);
15393 +       }
15394 +
15395 +       /* below here only with VX_ADMIN */
15396 +       if (!vx_check(0, VX_ADMIN|VX_WATCH))
15397 +               return -EPERM;
15398 +
15399 +       switch (cmd) {
15400 +       case VCMD_ctx_kill:
15401 +               return vc_ctx_kill(id, data);
15402 +
15403 +       case VCMD_wait_exit:
15404 +               return vc_wait_exit(id, data);
15405 +
15406 +       case VCMD_create_context:
15407 +#ifdef CONFIG_VSERVER_LEGACY
15408 +               return vc_ctx_create(id, data);
15409 +#else
15410 +               return -ENOSYS;
15411 +#endif
15412 +
15413 +       case VCMD_get_iattr:
15414 +               return vc_get_iattr(id, data);
15415 +       case VCMD_set_iattr:
15416 +               return vc_set_iattr(id, data);
15417 +
15418 +       case VCMD_enter_namespace:
15419 +               return vc_enter_namespace(id, data);
15420 +
15421 +       case VCMD_ctx_create:
15422 +#ifdef CONFIG_VSERVER_LEGACY
15423 +               if (id == 1) {
15424 +                       current->xid = 1;
15425 +                       return 1;
15426 +               }
15427 +#endif
15428 +               return vc_ctx_create(id, data);
15429 +       case VCMD_ctx_migrate:
15430 +               return vc_ctx_migrate(id, data);
15431 +
15432 +       case VCMD_net_create:
15433 +               return vc_net_create(id, data);
15434 +       case VCMD_net_migrate:
15435 +               return vc_net_migrate(id, data);
15436 +
15437 +       }
15438 +       return -ENOSYS;
15439 +}
15440 +
15441 diff -NurpP --minimal linux-2.6.10/kernel/vserver/sysctl.c linux-2.6.10-vs1.9.3.17/kernel/vserver/sysctl.c
15442 --- linux-2.6.10/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
15443 +++ linux-2.6.10-vs1.9.3.17/kernel/vserver/sysctl.c     2004-12-26 19:40:35.000000000 +0100
15444 @@ -0,0 +1,204 @@
15445 +/*
15446 + *  linux/kernel/sysctl.c
15447 + *
15448 + *  Virtual Context Support
15449 + *
15450 + *  Copyright (C) 2004  Herbert Pötzl
15451 + *
15452 + *  V0.01  basic structure
15453 + *
15454 + */
15455 +
15456 +#include <linux/config.h>
15457 +#include <linux/errno.h>
15458 +#include <linux/module.h>
15459 +#include <linux/types.h>
15460 +#include <linux/ctype.h>
15461 +#include <linux/sysctl.h>
15462 +#include <linux/fs.h>
15463 +
15464 +#include <asm/uaccess.h>
15465 +#include <asm/unistd.h>
15466 +
15467 +
15468 +#define CTL_VSERVER    4242    /* unused? */
15469 +
15470 +enum {
15471 +       CTL_DEBUG_SWITCH = 1,
15472 +       CTL_DEBUG_XID,
15473 +       CTL_DEBUG_NID,
15474 +       CTL_DEBUG_NET,
15475 +       CTL_DEBUG_LIMIT,
15476 +       CTL_DEBUG_DLIM,
15477 +       CTL_DEBUG_CVIRT,
15478 +};
15479 +
15480 +
15481 +unsigned int vx_debug_switch = 0;
15482 +unsigned int vx_debug_xid = 0;
15483 +unsigned int vx_debug_nid = 0;
15484 +unsigned int vx_debug_net = 0;
15485 +unsigned int vx_debug_limit = 0;
15486 +unsigned int vx_debug_dlim = 0;
15487 +unsigned int vx_debug_cvirt = 0;
15488 +
15489 +
15490 +static struct ctl_table_header *vserver_table_header;
15491 +static ctl_table vserver_table[];
15492 +
15493 +
15494 +void vserver_register_sysctl(void)
15495 +{
15496 +       if (!vserver_table_header) {
15497 +               vserver_table_header = register_sysctl_table(vserver_table, 1);
15498 +       }
15499 +
15500 +}
15501 +
15502 +void vserver_unregister_sysctl(void)
15503 +{
15504 +       if (vserver_table_header) {
15505 +               unregister_sysctl_table(vserver_table_header);
15506 +               vserver_table_header = NULL;
15507 +       }
15508 +}
15509 +
15510 +
15511 +static int proc_dodebug(ctl_table *table, int write,
15512 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
15513 +{
15514 +       char            tmpbuf[20], *p, c;
15515 +       unsigned int    value;
15516 +       size_t          left, len;
15517 +
15518 +       if ((*ppos && !write) || !*lenp) {
15519 +               *lenp = 0;
15520 +               return 0;
15521 +       }
15522 +
15523 +       left = *lenp;
15524 +
15525 +       if (write) {
15526 +               if (!access_ok(VERIFY_READ, buffer, left))
15527 +                       return -EFAULT;
15528 +               p = (char *) buffer;
15529 +               while (left && __get_user(c, p) >= 0 && isspace(c))
15530 +                       left--, p++;
15531 +               if (!left)
15532 +                       goto done;
15533 +
15534 +               if (left > sizeof(tmpbuf) - 1)
15535 +                       return -EINVAL;
15536 +               if (copy_from_user(tmpbuf, p, left))
15537 +                       return -EFAULT;
15538 +               tmpbuf[left] = '\0';
15539 +
15540 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
15541 +                       value = 10 * value + (*p - '0');
15542 +               if (*p && !isspace(*p))
15543 +                       return -EINVAL;
15544 +               while (left && isspace(*p))
15545 +                       left--, p++;
15546 +               *(unsigned int *) table->data = value;
15547 +       } else {
15548 +               if (!access_ok(VERIFY_WRITE, buffer, left))
15549 +                       return -EFAULT;
15550 +               len = sprintf(tmpbuf, "%d", *(unsigned int *) table->data);
15551 +               if (len > left)
15552 +                       len = left;
15553 +               if (__copy_to_user(buffer, tmpbuf, len))
15554 +                       return -EFAULT;
15555 +               if ((left -= len) > 0) {
15556 +                       if (put_user('\n', (char *)buffer + len))
15557 +                               return -EFAULT;
15558 +                       left--;
15559 +               }
15560 +       }
15561 +
15562 +done:
15563 +       *lenp -= left;
15564 +       *ppos += *lenp;
15565 +       return 0;
15566 +}
15567 +
15568 +
15569 +
15570 +static ctl_table debug_table[] = {
15571 +       {
15572 +               .ctl_name       = CTL_DEBUG_SWITCH,
15573 +               .procname       = "debug_switch",
15574 +               .data           = &vx_debug_switch,
15575 +               .maxlen         = sizeof(int),
15576 +               .mode           = 0644,
15577 +               .proc_handler   = &proc_dodebug
15578 +       },
15579 +       {
15580 +               .ctl_name       = CTL_DEBUG_XID,
15581 +               .procname       = "debug_xid",
15582 +               .data           = &vx_debug_xid,
15583 +               .maxlen         = sizeof(int),
15584 +               .mode           = 0644,
15585 +               .proc_handler   = &proc_dodebug
15586 +       },
15587 +       {
15588 +               .ctl_name       = CTL_DEBUG_NID,
15589 +               .procname       = "debug_nid",
15590 +               .data           = &vx_debug_nid,
15591 +               .maxlen         = sizeof(int),
15592 +               .mode           = 0644,
15593 +               .proc_handler   = &proc_dodebug
15594 +       },
15595 +       {
15596 +               .ctl_name       = CTL_DEBUG_NET,
15597 +               .procname       = "debug_net",
15598 +               .data           = &vx_debug_net,
15599 +               .maxlen         = sizeof(int),
15600 +               .mode           = 0644,
15601 +               .proc_handler   = &proc_dodebug
15602 +       },
15603 +       {
15604 +               .ctl_name       = CTL_DEBUG_LIMIT,
15605 +               .procname       = "debug_limit",
15606 +               .data           = &vx_debug_limit,
15607 +               .maxlen         = sizeof(int),
15608 +               .mode           = 0644,
15609 +               .proc_handler   = &proc_dodebug
15610 +       },
15611 +       {
15612 +               .ctl_name       = CTL_DEBUG_DLIM,
15613 +               .procname       = "debug_dlim",
15614 +               .data           = &vx_debug_dlim,
15615 +               .maxlen         = sizeof(int),
15616 +               .mode           = 0644,
15617 +               .proc_handler   = &proc_dodebug
15618 +       },
15619 +       {
15620 +               .ctl_name       = CTL_DEBUG_CVIRT,
15621 +               .procname       = "debug_cvirt",
15622 +               .data           = &vx_debug_cvirt,
15623 +               .maxlen         = sizeof(int),
15624 +               .mode           = 0644,
15625 +               .proc_handler   = &proc_dodebug
15626 +       },
15627 +       { .ctl_name = 0 }
15628 +};
15629 +
15630 +static ctl_table vserver_table[] = {
15631 +       {
15632 +               .ctl_name       = CTL_VSERVER,
15633 +               .procname       = "vserver",
15634 +               .mode           = 0555,
15635 +               .child          = debug_table
15636 +       },
15637 +       { .ctl_name = 0 }
15638 +};
15639 +
15640 +
15641 +EXPORT_SYMBOL_GPL(vx_debug_switch);
15642 +EXPORT_SYMBOL_GPL(vx_debug_xid);
15643 +EXPORT_SYMBOL_GPL(vx_debug_nid);
15644 +EXPORT_SYMBOL_GPL(vx_debug_net);
15645 +EXPORT_SYMBOL_GPL(vx_debug_limit);
15646 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
15647 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
15648 +
15649 diff -NurpP --minimal linux-2.6.10/mm/fremap.c linux-2.6.10-vs1.9.3.17/mm/fremap.c
15650 --- linux-2.6.10/mm/fremap.c    2004-12-25 01:55:31.000000000 +0100
15651 +++ linux-2.6.10-vs1.9.3.17/mm/fremap.c 2004-12-26 19:40:35.000000000 +0100
15652 @@ -15,6 +15,7 @@
15653  #include <linux/rmap.h>
15654  #include <linux/module.h>
15655  #include <linux/syscalls.h>
15656 +#include <linux/vs_memory.h>
15657  
15658  #include <asm/mmu_context.h>
15659  #include <asm/cacheflush.h>
15660 @@ -39,7 +40,8 @@ static inline void zap_pte(struct mm_str
15661                                         set_page_dirty(page);
15662                                 page_remove_rmap(page);
15663                                 page_cache_release(page);
15664 -                               mm->rss--;
15665 +                               // mm->rss--;
15666 +                               vx_rsspages_dec(mm);
15667                         }
15668                 }
15669         } else {
15670 @@ -67,6 +69,9 @@ int install_page(struct mm_struct *mm, s
15671         pgd = pgd_offset(mm, addr);
15672         spin_lock(&mm->page_table_lock);
15673  
15674 +       if (!vx_rsspages_avail(mm, 1))
15675 +               goto err_unlock;
15676 +
15677         pmd = pmd_alloc(mm, pgd, addr);
15678         if (!pmd)
15679                 goto err_unlock;
15680 @@ -87,7 +92,8 @@ int install_page(struct mm_struct *mm, s
15681  
15682         zap_pte(mm, vma, addr, pte);
15683  
15684 -       mm->rss++;
15685 +       // mm->rss++;
15686 +       vx_rsspages_inc(mm);
15687         flush_icache_page(vma, page);
15688         set_pte(pte, mk_pte(page, prot));
15689         page_add_file_rmap(page);
15690 diff -NurpP --minimal linux-2.6.10/mm/memory.c linux-2.6.10-vs1.9.3.17/mm/memory.c
15691 --- linux-2.6.10/mm/memory.c    2004-12-25 01:55:31.000000000 +0100
15692 +++ linux-2.6.10-vs1.9.3.17/mm/memory.c 2004-12-26 19:40:35.000000000 +0100
15693 @@ -283,6 +283,10 @@ skip_copy_pte_range:
15694                                 struct page *page;
15695                                 unsigned long pfn;
15696  
15697 +                               if (!vx_rsspages_avail(dst, 1)) {
15698 +                                       spin_unlock(&src->page_table_lock);
15699 +                                       goto nomem;
15700 +                               }
15701                                 /* copy_one_pte */
15702  
15703                                 if (pte_none(pte))
15704 @@ -333,7 +337,8 @@ skip_copy_pte_range:
15705                                         pte = pte_mkclean(pte);
15706                                 pte = pte_mkold(pte);
15707                                 get_page(page);
15708 -                               dst->rss++;
15709 +                               // dst->rss++;
15710 +                               vx_rsspages_inc(dst);
15711                                 if (PageAnon(page))
15712                                         dst->anon_rss++;
15713                                 set_pte(dst_pte, pte);
15714 @@ -1112,7 +1117,8 @@ static int do_wp_page(struct mm_struct *
15715                 if (PageAnon(old_page))
15716                         mm->anon_rss--;
15717                 if (PageReserved(old_page))
15718 -                       ++mm->rss;
15719 +                       // ++mm->rss;
15720 +                       vx_rsspages_inc(mm);
15721                 else
15722                         page_remove_rmap(old_page);
15723                 break_cow(vma, new_page, address, page_table);
15724 @@ -1370,6 +1376,10 @@ static int do_swap_page(struct mm_struct
15725                 grab_swap_token();
15726         }
15727  
15728 +       if (!vx_rsspages_avail(mm, 1)) {
15729 +               ret = VM_FAULT_OOM;
15730 +               goto out;
15731 +       }
15732         mark_page_accessed(page);
15733         lock_page(page);
15734  
15735 @@ -1394,7 +1404,8 @@ static int do_swap_page(struct mm_struct
15736         if (vm_swap_full())
15737                 remove_exclusive_swap_page(page);
15738  
15739 -       mm->rss++;
15740 +       // mm->rss++;
15741 +       vx_rsspages_inc(mm);
15742         pte = mk_pte(page, vma->vm_page_prot);
15743         if (write_access && can_share_swap_page(page)) {
15744                 pte = maybe_mkwrite(pte_mkdirty(pte), vma);
15745 @@ -1445,6 +1456,9 @@ do_anonymous_page(struct mm_struct *mm, 
15746  
15747                 if (unlikely(anon_vma_prepare(vma)))
15748                         goto no_mem;
15749 +               if (!vx_rsspages_avail(mm, 1))
15750 +                       goto no_mem;
15751 +
15752                 page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
15753                 if (!page)
15754                         goto no_mem;
15755 @@ -1459,7 +1473,8 @@ do_anonymous_page(struct mm_struct *mm, 
15756                         spin_unlock(&mm->page_table_lock);
15757                         goto out;
15758                 }
15759 -               mm->rss++;
15760 +               // mm->rss++;
15761 +               vx_rsspages_inc(mm);
15762                 entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
15763                                                          vma->vm_page_prot)),
15764                                       vma);
15765 @@ -1522,6 +1537,8 @@ retry:
15766                 return VM_FAULT_SIGBUS;
15767         if (new_page == NOPAGE_OOM)
15768                 return VM_FAULT_OOM;
15769 +       if (!vx_rsspages_avail(mm, 1))
15770 +               return VM_FAULT_OOM;
15771  
15772         /*
15773          * Should we do an early C-O-W break?
15774 @@ -1568,7 +1585,8 @@ retry:
15775         /* Only go through if we didn't race with anybody else... */
15776         if (pte_none(*page_table)) {
15777                 if (!PageReserved(new_page))
15778 -                       ++mm->rss;
15779 +                       // ++mm->rss;
15780 +                       vx_rsspages_inc(mm);
15781                 flush_icache_page(vma, new_page);
15782                 entry = mk_pte(new_page, vma->vm_page_prot);
15783                 if (write_access)
15784 diff -NurpP --minimal linux-2.6.10/mm/mlock.c linux-2.6.10-vs1.9.3.17/mm/mlock.c
15785 --- linux-2.6.10/mm/mlock.c     2004-12-25 01:55:31.000000000 +0100
15786 +++ linux-2.6.10-vs1.9.3.17/mm/mlock.c  2004-12-26 19:40:35.000000000 +0100
15787 @@ -8,6 +8,7 @@
15788  #include <linux/mman.h>
15789  #include <linux/mm.h>
15790  #include <linux/syscalls.h>
15791 +#include <linux/vs_memory.h>
15792  
15793  
15794  static int mlock_fixup(struct vm_area_struct * vma, 
15795 @@ -51,7 +52,8 @@ static int mlock_fixup(struct vm_area_st
15796                         ret = make_pages_present(start, end);
15797         }
15798  
15799 -       vma->vm_mm->locked_vm -= pages;
15800 +       // vma->vm_mm->locked_vm -= pages;
15801 +       vx_vmlocked_sub(vma->vm_mm, pages);
15802  out:
15803         return ret;
15804  }
15805 @@ -103,7 +105,7 @@ static int do_mlock(unsigned long start,
15806  
15807  asmlinkage long sys_mlock(unsigned long start, size_t len)
15808  {
15809 -       unsigned long locked;
15810 +       unsigned long locked, grow;
15811         unsigned long lock_limit;
15812         int error = -ENOMEM;
15813  
15814 @@ -114,8 +116,10 @@ asmlinkage long sys_mlock(unsigned long 
15815         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
15816         start &= PAGE_MASK;
15817  
15818 -       locked = len >> PAGE_SHIFT;
15819 -       locked += current->mm->locked_vm;
15820 +       grow = len >> PAGE_SHIFT;
15821 +       if (!vx_vmlocked_avail(current->mm, grow))
15822 +               goto out;
15823 +       locked = current->mm->locked_vm + grow;
15824  
15825         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
15826         lock_limit >>= PAGE_SHIFT;
15827 @@ -123,6 +127,7 @@ asmlinkage long sys_mlock(unsigned long 
15828         /* check against resource limits */
15829         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
15830                 error = do_mlock(start, len, 1);
15831 +out:
15832         up_write(&current->mm->mmap_sem);
15833         return error;
15834  }
15835 @@ -182,6 +187,8 @@ asmlinkage long sys_mlockall(int flags)
15836         lock_limit >>= PAGE_SHIFT;
15837  
15838         ret = -ENOMEM;
15839 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
15840 +               goto out;
15841         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
15842             capable(CAP_IPC_LOCK))
15843                 ret = do_mlockall(flags);
15844 diff -NurpP --minimal linux-2.6.10/mm/mmap.c linux-2.6.10-vs1.9.3.17/mm/mmap.c
15845 --- linux-2.6.10/mm/mmap.c      2004-12-25 01:55:31.000000000 +0100
15846 +++ linux-2.6.10-vs1.9.3.17/mm/mmap.c   2004-12-26 19:40:35.000000000 +0100
15847 @@ -908,6 +908,10 @@ munmap_back:
15848             > current->signal->rlim[RLIMIT_AS].rlim_cur)
15849                 return -ENOMEM;
15850  
15851 +       /* check context space, maybe only Private writable mapping? */
15852 +       if (!vx_vmpages_avail(mm, len >> PAGE_SHIFT))
15853 +               return -ENOMEM;
15854 +
15855         if (accountable && (!(flags & MAP_NORESERVE) ||
15856                             sysctl_overcommit_memory == OVERCOMMIT_NEVER)) {
15857                 if (vm_flags & VM_SHARED) {
15858 @@ -1007,10 +1011,12 @@ munmap_back:
15859                 kmem_cache_free(vm_area_cachep, vma);
15860         }
15861  out:   
15862 -       mm->total_vm += len >> PAGE_SHIFT;
15863 +       // mm->total_vm += len >> PAGE_SHIFT;
15864 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
15865         __vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
15866         if (vm_flags & VM_LOCKED) {
15867 -               mm->locked_vm += len >> PAGE_SHIFT;
15868 +               // mm->locked_vm += len >> PAGE_SHIFT;
15869 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
15870                 make_pages_present(addr, addr + len);
15871         }
15872         if (flags & MAP_POPULATE) {
15873 @@ -1347,8 +1353,9 @@ int expand_stack(struct vm_area_struct *
15874         address &= PAGE_MASK;
15875         grow = (address - vma->vm_end) >> PAGE_SHIFT;
15876  
15877 -       /* Overcommit.. */
15878 -       if (security_vm_enough_memory(grow)) {
15879 +       /* Overcommit.. vx check first to avoid vm_unacct_memory() */
15880 +       if (!vx_vmpages_avail(vma->vm_mm, grow) ||
15881 +               security_vm_enough_memory(grow)) {
15882                 anon_vma_unlock(vma);
15883                 return -ENOMEM;
15884         }
15885 @@ -1361,9 +1368,11 @@ int expand_stack(struct vm_area_struct *
15886                 return -ENOMEM;
15887         }
15888         vma->vm_end = address;
15889 -       vma->vm_mm->total_vm += grow;
15890 +       // vma->vm_mm->total_vm += grow;
15891 +       vx_vmpages_add(vma->vm_mm, grow);
15892         if (vma->vm_flags & VM_LOCKED)
15893 -               vma->vm_mm->locked_vm += grow;
15894 +               // vma->vm_mm->locked_vm += grow;
15895 +               vx_vmlocked_add(vma->vm_mm, grow);
15896         __vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, grow);
15897         anon_vma_unlock(vma);
15898         return 0;
15899 @@ -1409,8 +1418,9 @@ int expand_stack(struct vm_area_struct *
15900         address &= PAGE_MASK;
15901         grow = (vma->vm_start - address) >> PAGE_SHIFT;
15902  
15903 -       /* Overcommit.. */
15904 -       if (security_vm_enough_memory(grow)) {
15905 +       /* Overcommit.. vx check first to avoid vm_unacct_memory() */
15906 +       if (!vx_vmpages_avail(vma->vm_mm, grow) ||
15907 +               security_vm_enough_memory(grow)) {
15908                 anon_vma_unlock(vma);
15909                 return -ENOMEM;
15910         }
15911 @@ -1424,9 +1434,11 @@ int expand_stack(struct vm_area_struct *
15912         }
15913         vma->vm_start = address;
15914         vma->vm_pgoff -= grow;
15915 -       vma->vm_mm->total_vm += grow;
15916 +       // vma->vm_mm->total_vm += grow;
15917 +       vx_vmpages_add(vma->vm_mm, grow);
15918         if (vma->vm_flags & VM_LOCKED)
15919 -               vma->vm_mm->locked_vm += grow;
15920 +               // vma->vm_mm->locked_vm += grow;
15921 +               vx_vmlocked_add(vma->vm_mm, grow);
15922         __vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, grow);
15923         anon_vma_unlock(vma);
15924         return 0;
15925 @@ -1530,9 +1542,12 @@ static void unmap_vma(struct mm_struct *
15926  {
15927         size_t len = area->vm_end - area->vm_start;
15928  
15929 -       area->vm_mm->total_vm -= len >> PAGE_SHIFT;
15930 +       // area->vm_mm->total_vm -= len >> PAGE_SHIFT;
15931 +       vx_vmpages_sub(area->vm_mm, len >> PAGE_SHIFT);
15932 +
15933         if (area->vm_flags & VM_LOCKED)
15934 -               area->vm_mm->locked_vm -= len >> PAGE_SHIFT;
15935 +               // area->vm_mm->locked_vm -= len >> PAGE_SHIFT;
15936 +               vx_vmlocked_sub(area->vm_mm, len >> PAGE_SHIFT);
15937         vm_stat_unaccount(area);
15938         area->vm_mm->unmap_area(area);
15939         remove_vm_struct(area);
15940 @@ -1767,6 +1782,8 @@ unsigned long do_brk(unsigned long addr,
15941                 locked += len;
15942                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
15943                         return -EAGAIN;
15944 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
15945 +                       return -ENOMEM;
15946         }
15947  
15948         /*
15949 @@ -1788,7 +1805,8 @@ unsigned long do_brk(unsigned long addr,
15950         if (mm->map_count > sysctl_max_map_count)
15951                 return -ENOMEM;
15952  
15953 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
15954 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
15955 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
15956                 return -ENOMEM;
15957  
15958         flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
15959 @@ -1816,9 +1834,11 @@ unsigned long do_brk(unsigned long addr,
15960         vma->vm_page_prot = protection_map[flags & 0x0f];
15961         vma_link(mm, vma, prev, rb_link, rb_parent);
15962  out:
15963 -       mm->total_vm += len >> PAGE_SHIFT;
15964 +       // mm->total_vm += len >> PAGE_SHIFT;
15965 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
15966         if (flags & VM_LOCKED) {
15967 -               mm->locked_vm += len >> PAGE_SHIFT;
15968 +               // mm->locked_vm += len >> PAGE_SHIFT;
15969 +               vx_vmlocked_add(mm, len >> PAGE_SHIFT);
15970                 make_pages_present(addr, addr + len);
15971         }
15972         return addr;
15973 @@ -1850,9 +1870,12 @@ void exit_mmap(struct mm_struct *mm)
15974         vma = mm->mmap;
15975         mm->mmap = mm->mmap_cache = NULL;
15976         mm->mm_rb = RB_ROOT;
15977 -       mm->rss = 0;
15978 -       mm->total_vm = 0;
15979 -       mm->locked_vm = 0;
15980 +       // mm->rss = 0;
15981 +       vx_rsspages_sub(mm, mm->rss);
15982 +       // mm->total_vm = 0;
15983 +       vx_vmpages_sub(mm, mm->total_vm);
15984 +       // mm->locked_vm = 0;
15985 +       vx_vmlocked_sub(mm, mm->locked_vm);
15986  
15987         spin_unlock(&mm->page_table_lock);
15988  
15989 diff -NurpP --minimal linux-2.6.10/mm/mremap.c linux-2.6.10-vs1.9.3.17/mm/mremap.c
15990 --- linux-2.6.10/mm/mremap.c    2004-12-25 01:55:31.000000000 +0100
15991 +++ linux-2.6.10-vs1.9.3.17/mm/mremap.c 2004-12-26 19:40:35.000000000 +0100
15992 @@ -17,6 +17,7 @@
15993  #include <linux/highmem.h>
15994  #include <linux/security.h>
15995  #include <linux/syscalls.h>
15996 +#include <linux/vs_memory.h>
15997  
15998  #include <asm/uaccess.h>
15999  #include <asm/cacheflush.h>
16000 @@ -224,10 +225,12 @@ static unsigned long move_vma(struct vm_
16001                         vma->vm_next->vm_flags |= VM_ACCOUNT;
16002         }
16003  
16004 -       mm->total_vm += new_len >> PAGE_SHIFT;
16005 +       // mm->total_vm += new_len >> PAGE_SHIFT;
16006 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
16007         __vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
16008         if (vm_flags & VM_LOCKED) {
16009 -               mm->locked_vm += new_len >> PAGE_SHIFT;
16010 +               // mm->locked_vm += new_len >> PAGE_SHIFT;
16011 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
16012                 if (new_len > old_len)
16013                         make_pages_present(new_addr + old_len,
16014                                            new_addr + new_len);
16015 @@ -333,11 +336,18 @@ unsigned long do_mremap(unsigned long ad
16016                 ret = -EAGAIN;
16017                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
16018                         goto out;
16019 +               ret = -ENOMEM;
16020 +               if (!vx_vmlocked_avail(current->mm,
16021 +                       (new_len - old_len) >> PAGE_SHIFT))
16022 +                       goto out;
16023         }
16024         ret = -ENOMEM;
16025         if ((current->mm->total_vm << PAGE_SHIFT) + (new_len - old_len)
16026             > current->signal->rlim[RLIMIT_AS].rlim_cur)
16027                 goto out;
16028 +       /* check context space, maybe only Private writable mapping? */
16029 +       if (!vx_vmpages_avail(current->mm, (new_len - old_len) >> PAGE_SHIFT))
16030 +               goto out;
16031  
16032         if (vma->vm_flags & VM_ACCOUNT) {
16033                 charged = (new_len - old_len) >> PAGE_SHIFT;
16034 @@ -361,11 +371,13 @@ unsigned long do_mremap(unsigned long ad
16035                         vma_adjust(vma, vma->vm_start,
16036                                 addr + new_len, vma->vm_pgoff, NULL);
16037  
16038 -                       current->mm->total_vm += pages;
16039 +                       // current->mm->total_vm += pages;
16040 +                       vx_vmpages_add(current->mm, pages);
16041                         __vm_stat_account(vma->vm_mm, vma->vm_flags,
16042                                                         vma->vm_file, pages);
16043                         if (vma->vm_flags & VM_LOCKED) {
16044 -                               current->mm->locked_vm += pages;
16045 +                               // current->mm->locked_vm += pages;
16046 +                               vx_vmlocked_add(vma->vm_mm, pages);
16047                                 make_pages_present(addr + old_len,
16048                                                    addr + new_len);
16049                         }
16050 diff -NurpP --minimal linux-2.6.10/mm/nommu.c linux-2.6.10-vs1.9.3.17/mm/nommu.c
16051 --- linux-2.6.10/mm/nommu.c     2004-12-25 01:55:31.000000000 +0100
16052 +++ linux-2.6.10-vs1.9.3.17/mm/nommu.c  2004-12-26 19:40:35.000000000 +0100
16053 @@ -440,7 +440,8 @@ unsigned long do_mmap_pgoff(
16054  
16055         tblock->next = current->mm->context.tblock.next;
16056         current->mm->context.tblock.next = tblock;
16057 -       current->mm->total_vm += len >> PAGE_SHIFT;
16058 +       // current->mm->total_vm += len >> PAGE_SHIFT;
16059 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
16060  
16061  #ifdef DEBUG
16062         printk("do_mmap:\n");
16063 @@ -494,7 +495,8 @@ int do_munmap(struct mm_struct * mm, uns
16064         realalloc -= kobjsize(tblock);
16065         askedalloc -= sizeof(struct mm_tblock_struct);
16066         kfree(tblock);
16067 -       mm->total_vm -= len >> PAGE_SHIFT;
16068 +       // mm->total_vm -= len >> PAGE_SHIFT;
16069 +       vx_vmpages_sub(mm, len >> PAGE_SHIFT);
16070  
16071  #ifdef DEBUG
16072         show_process_blocks();
16073 @@ -507,7 +509,8 @@ int do_munmap(struct mm_struct * mm, uns
16074  void exit_mmap(struct mm_struct * mm)
16075  {
16076         struct mm_tblock_struct *tmp;
16077 -       mm->total_vm = 0;
16078 +       // mm->total_vm = 0;
16079 +       vx_vmpages_sub(mm, mm->total_vm);
16080  
16081         if (!mm)
16082                 return;
16083 diff -NurpP --minimal linux-2.6.10/mm/oom_kill.c linux-2.6.10-vs1.9.3.17/mm/oom_kill.c
16084 --- linux-2.6.10/mm/oom_kill.c  2004-10-23 05:06:25.000000000 +0200
16085 +++ linux-2.6.10-vs1.9.3.17/mm/oom_kill.c       2004-12-26 19:40:35.000000000 +0100
16086 @@ -55,6 +55,7 @@ static unsigned long badness(struct task
16087          * The memory size of the process is the basis for the badness.
16088          */
16089         points = p->mm->total_vm;
16090 +       /* FIXME add vserver badness ;) */
16091  
16092         /*
16093          * CPU time is in tens of seconds and run time is in thousands
16094 diff -NurpP --minimal linux-2.6.10/mm/page_alloc.c linux-2.6.10-vs1.9.3.17/mm/page_alloc.c
16095 --- linux-2.6.10/mm/page_alloc.c        2004-12-25 01:55:31.000000000 +0100
16096 +++ linux-2.6.10-vs1.9.3.17/mm/page_alloc.c     2004-12-26 19:40:30.000000000 +0100
16097 @@ -32,6 +32,7 @@
16098  #include <linux/sysctl.h>
16099  #include <linux/cpu.h>
16100  #include <linux/nodemask.h>
16101 +#include <linux/vs_limit.h>
16102  
16103  #include <asm/tlbflush.h>
16104  
16105 @@ -1011,6 +1012,8 @@ void si_meminfo(struct sysinfo *val)
16106         val->freehigh = 0;
16107  #endif
16108         val->mem_unit = PAGE_SIZE;
16109 +       if (vx_flags(VXF_VIRT_MEM, 0))
16110 +               vx_vsi_meminfo(val);
16111  }
16112  
16113  EXPORT_SYMBOL(si_meminfo);
16114 diff -NurpP --minimal linux-2.6.10/mm/rmap.c linux-2.6.10-vs1.9.3.17/mm/rmap.c
16115 --- linux-2.6.10/mm/rmap.c      2004-12-25 01:55:31.000000000 +0100
16116 +++ linux-2.6.10-vs1.9.3.17/mm/rmap.c   2004-12-26 19:40:35.000000000 +0100
16117 @@ -53,6 +53,7 @@
16118  #include <linux/init.h>
16119  #include <linux/rmap.h>
16120  #include <linux/rcupdate.h>
16121 +#include <linux/vs_memory.h>
16122  
16123  #include <asm/tlbflush.h>
16124  
16125 @@ -595,7 +596,8 @@ static int try_to_unmap_one(struct page 
16126                 mm->anon_rss--;
16127         }
16128  
16129 -       mm->rss--;
16130 +       // mm->rss--;
16131 +       vx_rsspages_dec(mm);
16132         page_remove_rmap(page);
16133         page_cache_release(page);
16134  
16135 @@ -695,7 +697,8 @@ static void try_to_unmap_cluster(unsigne
16136  
16137                 page_remove_rmap(page);
16138                 page_cache_release(page);
16139 -               mm->rss--;
16140 +               // mm->rss--;
16141 +               vx_rsspages_dec(mm);
16142                 (*mapcount)--;
16143         }
16144  
16145 diff -NurpP --minimal linux-2.6.10/mm/shmem.c linux-2.6.10-vs1.9.3.17/mm/shmem.c
16146 --- linux-2.6.10/mm/shmem.c     2004-12-25 01:55:31.000000000 +0100
16147 +++ linux-2.6.10-vs1.9.3.17/mm/shmem.c  2004-12-26 19:40:30.000000000 +0100
16148 @@ -51,7 +51,6 @@
16149  #include <asm/pgtable.h>
16150  
16151  /* This magic number is used in glibc for posix shared memory */
16152 -#define TMPFS_MAGIC    0x01021994
16153  
16154  #define ENTRIES_PER_PAGE (PAGE_CACHE_SIZE/sizeof(unsigned long))
16155  #define ENTRIES_PER_PAGEPAGE (ENTRIES_PER_PAGE*ENTRIES_PER_PAGE)
16156 @@ -1604,7 +1603,7 @@ static int shmem_statfs(struct super_blo
16157  {
16158         struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
16159  
16160 -       buf->f_type = TMPFS_MAGIC;
16161 +       buf->f_type = TMPFS_SUPER_MAGIC;
16162         buf->f_bsize = PAGE_CACHE_SIZE;
16163         buf->f_namelen = NAME_MAX;
16164         if (sbinfo) {
16165 @@ -2002,7 +2001,7 @@ static int shmem_fill_super(struct super
16166         sb->s_maxbytes = SHMEM_MAX_BYTES;
16167         sb->s_blocksize = PAGE_CACHE_SIZE;
16168         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
16169 -       sb->s_magic = TMPFS_MAGIC;
16170 +       sb->s_magic = TMPFS_SUPER_MAGIC;
16171         sb->s_op = &shmem_ops;
16172         inode = shmem_get_inode(sb, S_IFDIR | mode, 0);
16173         if (!inode)
16174 diff -NurpP --minimal linux-2.6.10/mm/swapfile.c linux-2.6.10-vs1.9.3.17/mm/swapfile.c
16175 --- linux-2.6.10/mm/swapfile.c  2004-12-25 01:55:31.000000000 +0100
16176 +++ linux-2.6.10-vs1.9.3.17/mm/swapfile.c       2004-12-26 19:40:35.000000000 +0100
16177 @@ -30,6 +30,7 @@
16178  #include <asm/pgtable.h>
16179  #include <asm/tlbflush.h>
16180  #include <linux/swapops.h>
16181 +#include <linux/vs_memory.h>
16182  
16183  spinlock_t swaplock = SPIN_LOCK_UNLOCKED;
16184  unsigned int nr_swapfiles;
16185 @@ -431,7 +432,8 @@ static void
16186  unuse_pte(struct vm_area_struct *vma, unsigned long address, pte_t *dir,
16187         swp_entry_t entry, struct page *page)
16188  {
16189 -       vma->vm_mm->rss++;
16190 +       // vma->vm_mm->rss++;
16191 +       vx_rsspages_inc(vma->vm_mm);
16192         get_page(page);
16193         set_pte(dir, pte_mkold(mk_pte(page, vma->vm_page_prot)));
16194         page_add_anon_rmap(page, vma, address);
16195 @@ -1626,6 +1628,8 @@ void si_swapinfo(struct sysinfo *val)
16196         val->freeswap = nr_swap_pages + nr_to_be_unused;
16197         val->totalswap = total_swap_pages + nr_to_be_unused;
16198         swap_list_unlock();
16199 +       if (vx_flags(VXF_VIRT_MEM, 0))
16200 +               vx_vsi_swapinfo(val);
16201  }
16202  
16203  /*
16204 diff -NurpP --minimal linux-2.6.10/mm/vmscan.c linux-2.6.10-vs1.9.3.17/mm/vmscan.c
16205 --- linux-2.6.10/mm/vmscan.c    2004-12-25 01:55:31.000000000 +0100
16206 +++ linux-2.6.10-vs1.9.3.17/mm/vmscan.c 2004-12-26 19:40:30.000000000 +0100
16207 @@ -1238,7 +1238,7 @@ static int __init kswapd_init(void)
16208         swap_setup();
16209         for_each_pgdat(pgdat)
16210                 pgdat->kswapd
16211 -               = find_task_by_pid(kernel_thread(kswapd, pgdat, CLONE_KERNEL));
16212 +               = find_task_by_real_pid(kernel_thread(kswapd, pgdat, CLONE_KERNEL));
16213         total_memory = nr_free_pagecache_pages();
16214         hotcpu_notifier(cpu_callback, 0);
16215         return 0;
16216 diff -NurpP --minimal linux-2.6.10/net/core/dev.c linux-2.6.10-vs1.9.3.17/net/core/dev.c
16217 --- linux-2.6.10/net/core/dev.c 2004-12-25 01:55:31.000000000 +0100
16218 +++ linux-2.6.10-vs1.9.3.17/net/core/dev.c      2004-12-26 19:40:29.000000000 +0100
16219 @@ -112,6 +112,7 @@
16220  #include <linux/wireless.h>            /* Note : will define WIRELESS_EXT */
16221  #include <net/iw_handler.h>
16222  #endif /* CONFIG_NET_RADIO */
16223 +#include <linux/vs_network.h>
16224  #include <asm/current.h>
16225  
16226  /* This define, if set, will randomly drop a packet when congestion
16227 @@ -1893,6 +1894,9 @@ static int dev_ifconf(char __user *arg)
16228  
16229         total = 0;
16230         for (dev = dev_base; dev; dev = dev->next) {
16231 +               if (vx_flags(VXF_HIDE_NETIF, 0) &&
16232 +                       !dev_in_nx_info(dev, current->nx_info))
16233 +                       continue;
16234                 for (i = 0; i < NPROTO; i++) {
16235                         if (gifconf_list[i]) {
16236                                 int done;
16237 @@ -1953,6 +1957,10 @@ void dev_seq_stop(struct seq_file *seq, 
16238  
16239  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
16240  {
16241 +       struct nx_info *nxi = current->nx_info;
16242 +
16243 +       if (vx_flags(VXF_HIDE_NETIF, 0) && !dev_in_nx_info(dev, nxi))
16244 +               return;
16245         if (dev->get_stats) {
16246                 struct net_device_stats *stats = dev->get_stats(dev);
16247  
16248 diff -NurpP --minimal linux-2.6.10/net/core/rtnetlink.c linux-2.6.10-vs1.9.3.17/net/core/rtnetlink.c
16249 --- linux-2.6.10/net/core/rtnetlink.c   2004-10-23 05:06:25.000000000 +0200
16250 +++ linux-2.6.10-vs1.9.3.17/net/core/rtnetlink.c        2004-12-26 19:40:29.000000000 +0100
16251 @@ -251,6 +251,9 @@ int rtnetlink_dump_ifinfo(struct sk_buff
16252         for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) {
16253                 if (idx < s_idx)
16254                         continue;
16255 +               if (vx_info_flags(skb->sk->sk_vx_info, VXF_HIDE_NETIF, 0) &&
16256 +                       !dev_in_nx_info(dev, skb->sk->sk_nx_info))
16257 +                       continue;
16258                 if (rtnetlink_fill_ifinfo(skb, dev, RTM_NEWLINK, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq, 0) <= 0)
16259                         break;
16260         }
16261 @@ -416,6 +419,9 @@ void rtmsg_ifinfo(int type, struct net_d
16262                                sizeof(struct rtnl_link_ifmap) +
16263                                sizeof(struct rtnl_link_stats) + 128);
16264  
16265 +       if (vx_flags(VXF_HIDE_NETIF, 0) &&
16266 +               !dev_in_nx_info(dev, current->nx_info))
16267 +               return;
16268         skb = alloc_skb(size, GFP_KERNEL);
16269         if (!skb)
16270                 return;
16271 diff -NurpP --minimal linux-2.6.10/net/core/sock.c linux-2.6.10-vs1.9.3.17/net/core/sock.c
16272 --- linux-2.6.10/net/core/sock.c        2004-12-25 01:55:31.000000000 +0100
16273 +++ linux-2.6.10-vs1.9.3.17/net/core/sock.c     2004-12-26 19:40:29.000000000 +0100
16274 @@ -122,6 +122,7 @@
16275  #include <linux/ipsec.h>
16276  
16277  #include <linux/filter.h>
16278 +#include <linux/vs_socket.h>
16279  
16280  #ifdef CONFIG_INET
16281  #include <net/tcp.h>
16282 @@ -333,7 +334,10 @@ int sock_setsockopt(struct socket *sock,
16283                         break;
16284  
16285                 case SO_PASSCRED:
16286 -                       sock->passcred = valbool;
16287 +                       if (valbool)
16288 +                               set_bit(SOCK_PASS_CRED, &sock->flags);
16289 +                       else
16290 +                               clear_bit(SOCK_PASS_CRED, &sock->flags);
16291                         break;
16292  
16293                 case SO_TIMESTAMP:
16294 @@ -557,7 +561,7 @@ int sock_getsockopt(struct socket *sock,
16295                         break; 
16296  
16297                 case SO_PASSCRED:
16298 -                       v.val = sock->passcred;
16299 +                       v.val = test_bit(SOCK_PASS_CRED, &sock->flags)?1:0;
16300                         break;
16301  
16302                 case SO_PEERCRED:
16303 @@ -632,6 +636,8 @@ struct sock *sk_alloc(int family, int pr
16304                         sock_lock_init(sk);
16305                 }
16306                 sk->sk_slab = slab;
16307 +               sock_vx_init(sk);
16308 +               sock_nx_init(sk);
16309                 
16310                 if (security_sk_alloc(sk, family, priority)) {
16311                         kmem_cache_free(slab, sk);
16312 @@ -662,6 +668,8 @@ void sk_free(struct sock *sk)
16313                        __FUNCTION__, atomic_read(&sk->sk_omem_alloc));
16314  
16315         security_sk_free(sk);
16316 +       BUG_ON(sk->sk_vx_info);
16317 +       BUG_ON(sk->sk_nx_info);
16318         kmem_cache_free(sk->sk_slab, sk);
16319         module_put(owner);
16320  }
16321 @@ -1199,6 +1207,11 @@ void sock_init_data(struct socket *sock,
16322         sk->sk_stamp.tv_sec     = -1L;
16323         sk->sk_stamp.tv_usec    = -1L;
16324  
16325 +       sk->sk_vx_info          =       NULL;
16326 +       sk->sk_xid              =       0;
16327 +       sk->sk_nx_info          =       NULL;
16328 +       sk->sk_nid              =       0;
16329 +
16330         atomic_set(&sk->sk_refcnt, 1);
16331  }
16332  
16333 diff -NurpP --minimal linux-2.6.10/net/ipv4/af_inet.c linux-2.6.10-vs1.9.3.17/net/ipv4/af_inet.c
16334 --- linux-2.6.10/net/ipv4/af_inet.c     2004-12-25 01:55:31.000000000 +0100
16335 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/af_inet.c  2004-12-26 19:40:29.000000000 +0100
16336 @@ -112,6 +112,7 @@
16337  #ifdef CONFIG_IP_MROUTE
16338  #include <linux/mroute.h>
16339  #endif
16340 +#include <linux/vs_limit.h>
16341  
16342  DEFINE_SNMP_STAT(struct linux_mib, net_statistics);
16343  
16344 @@ -153,6 +154,13 @@ void inet_sock_destruct(struct sock *sk)
16345  
16346         if (inet->opt)
16347                 kfree(inet->opt);
16348 +
16349 +       vx_sock_dec(sk);
16350 +       clr_vx_info(&sk->sk_vx_info);
16351 +       sk->sk_xid = -1;
16352 +       clr_nx_info(&sk->sk_nx_info);
16353 +       sk->sk_nid = -1;
16354 +
16355         dst_release(sk->sk_dst_cache);
16356  #ifdef INET_REFCNT_DEBUG
16357         atomic_dec(&inet_sock_nr);
16358 @@ -266,8 +274,11 @@ static int inet_create(struct socket *so
16359         if (!answer)
16360                 goto out_rcu_unlock;
16361         err = -EPERM;
16362 +       if ((protocol == IPPROTO_ICMP) && vx_ccaps(VXC_RAW_ICMP))
16363 +               goto override;
16364         if (answer->capability > 0 && !capable(answer->capability))
16365                 goto out_rcu_unlock;
16366 +override:
16367         err = -EPROTONOSUPPORT;
16368         if (!protocol)
16369                 goto out_rcu_unlock;
16370 @@ -316,6 +327,12 @@ static int inet_create(struct socket *so
16371         sk->sk_protocol    = protocol;
16372         sk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
16373  
16374 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
16375 +       sk->sk_xid = vx_current_xid();
16376 +       vx_sock_inc(sk);
16377 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
16378 +       sk->sk_nid = nx_current_nid();
16379 +
16380         inet->uc_ttl    = -1;
16381         inet->mc_loop   = 1;
16382         inet->mc_ttl    = 1;
16383 @@ -377,6 +394,11 @@ int inet_release(struct socket *sock)
16384                     !(current->flags & PF_EXITING))
16385                         timeout = sk->sk_lingertime;
16386                 sock->sk = NULL;
16387 +               vx_sock_dec(sk);
16388 +               clr_vx_info(&sk->sk_vx_info);
16389 +               sk->sk_xid = -1;
16390 +               clr_nx_info(&sk->sk_nx_info);
16391 +               sk->sk_nid = -1;
16392                 sk->sk_prot->close(sk, timeout);
16393         }
16394         return 0;
16395 @@ -393,6 +415,10 @@ int inet_bind(struct socket *sock, struc
16396         unsigned short snum;
16397         int chk_addr_ret;
16398         int err;
16399 +       __u32 s_addr;   /* Address used for validation */
16400 +       __u32 s_addr1;  /* Address used for socket */
16401 +       __u32 s_addr2;  /* Broadcast address for the socket */
16402 +       struct nx_info *nxi = sk->sk_nx_info;
16403  
16404         /* If the socket has its own bind function then use it. (RAW) */
16405         if (sk->sk_prot->bind) {
16406 @@ -403,7 +429,40 @@ int inet_bind(struct socket *sock, struc
16407         if (addr_len < sizeof(struct sockaddr_in))
16408                 goto out;
16409  
16410 -       chk_addr_ret = inet_addr_type(addr->sin_addr.s_addr);
16411 +       s_addr = addr->sin_addr.s_addr;
16412 +       s_addr1 = s_addr;
16413 +       s_addr2 = 0xffffffffl;
16414 +
16415 +       vxdprintk(VXD_CBIT(net, 3),
16416 +               "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d",
16417 +               sk, sk->sk_nx_info, sk->sk_socket,
16418 +               (sk->sk_socket?sk->sk_socket->flags:0),
16419 +               VXD_QUAD(s_addr));
16420 +       if (nxi) {
16421 +               __u32 v4_bcast = nxi->v4_bcast;
16422 +               __u32 ipv4root = nxi->ipv4[0];
16423 +               int nbipv4 = nxi->nbipv4;
16424 +
16425 +               if (s_addr == 0) {
16426 +                       /* bind to any for 1-n */
16427 +                       s_addr = ipv4root;
16428 +                       s_addr1 = (nbipv4 > 1) ? 0 : s_addr;
16429 +                       s_addr2 = v4_bcast;
16430 +               } else if (s_addr == 0x0100007f) {
16431 +                       /* rewrite localhost to ipv4root */
16432 +                       s_addr = ipv4root;
16433 +                       s_addr1 = ipv4root;
16434 +               } else if (s_addr != v4_bcast) {
16435 +                       /* normal address bind */
16436 +                       if (!addr_in_nx_info(nxi, s_addr))
16437 +                               return -EADDRNOTAVAIL;
16438 +               }
16439 +       }
16440 +       chk_addr_ret = inet_addr_type(s_addr);
16441 +
16442 +       vxdprintk(VXD_CBIT(net, 3),
16443 +               "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d",
16444 +               sk, VXD_QUAD(s_addr), VXD_QUAD(s_addr1), VXD_QUAD(s_addr2));
16445  
16446         /* Not specified by any standard per-se, however it breaks too
16447          * many applications when removed.  It is unfortunate since
16448 @@ -415,7 +474,7 @@ int inet_bind(struct socket *sock, struc
16449         err = -EADDRNOTAVAIL;
16450         if (!sysctl_ip_nonlocal_bind &&
16451             !inet->freebind &&
16452 -           addr->sin_addr.s_addr != INADDR_ANY &&
16453 +           s_addr != INADDR_ANY &&
16454             chk_addr_ret != RTN_LOCAL &&
16455             chk_addr_ret != RTN_MULTICAST &&
16456             chk_addr_ret != RTN_BROADCAST)
16457 @@ -440,7 +499,8 @@ int inet_bind(struct socket *sock, struc
16458         if (sk->sk_state != TCP_CLOSE || inet->num)
16459                 goto out_release_sock;
16460  
16461 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
16462 +       inet->rcv_saddr = inet->saddr = s_addr1;
16463 +       inet->rcv_saddr2 = s_addr2;
16464         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
16465                 inet->saddr = 0;  /* Use device */
16466  
16467 diff -NurpP --minimal linux-2.6.10/net/ipv4/devinet.c linux-2.6.10-vs1.9.3.17/net/ipv4/devinet.c
16468 --- linux-2.6.10/net/ipv4/devinet.c     2004-12-25 01:55:31.000000000 +0100
16469 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/devinet.c  2004-12-26 19:40:29.000000000 +0100
16470 @@ -489,6 +489,33 @@ static __inline__ int inet_abc_len(u32 a
16471         return rc;
16472  }
16473  
16474 +/*
16475 +       Check that a device is not member of the ipv4root assigned to the process
16476 +       Return true if this is the case
16477 +
16478 +       If the process is not bound to specific IP, then it returns 0 (all
16479 +       interface are fine).
16480 +*/
16481 +static inline int devinet_notiproot (struct in_ifaddr *ifa)
16482 +{
16483 +       int ret = 0;
16484 +       struct nx_info *nxi;
16485 +
16486 +       if ((nxi = current->nx_info)) {
16487 +               int i;
16488 +               int nbip = nxi->nbipv4;
16489 +               __u32 addr = ifa->ifa_local;
16490 +               ret = 1;
16491 +               for (i=0; i<nbip; i++) {
16492 +                       if(nxi->ipv4[i] == addr) {
16493 +                               ret = 0;
16494 +                               break;
16495 +                       }
16496 +               }
16497 +       }
16498 +       return ret;
16499 +}
16500 +
16501  
16502  int devinet_ioctl(unsigned int cmd, void __user *arg)
16503  {
16504 @@ -596,6 +623,9 @@ int devinet_ioctl(unsigned int cmd, void
16505         ret = -EADDRNOTAVAIL;
16506         if (!ifa && cmd != SIOCSIFADDR && cmd != SIOCSIFFLAGS)
16507                 goto done;
16508 +       if (vx_flags(VXF_HIDE_NETIF, 0) &&
16509 +               !ifa_in_nx_info(ifa, current->nx_info))
16510 +               goto done;
16511  
16512         switch(cmd) {
16513         case SIOCGIFADDR:       /* Get interface address */
16514 @@ -739,6 +769,9 @@ static int inet_gifconf(struct net_devic
16515                 goto out;
16516  
16517         for (; ifa; ifa = ifa->ifa_next) {
16518 +               if (vx_flags(VXF_HIDE_NETIF, 0) &&
16519 +                       !ifa_in_nx_info(ifa, current->nx_info))
16520 +                       continue;
16521                 if (!buf) {
16522                         done += sizeof(ifr);
16523                         continue;
16524 @@ -1045,6 +1078,7 @@ static int inet_dump_ifaddr(struct sk_bu
16525         struct net_device *dev;
16526         struct in_device *in_dev;
16527         struct in_ifaddr *ifa;
16528 +       struct sock *sk = skb->sk;
16529         int s_ip_idx, s_idx = cb->args[0];
16530  
16531         s_ip_idx = ip_idx = cb->args[1];
16532 @@ -1062,6 +1096,9 @@ static int inet_dump_ifaddr(struct sk_bu
16533  
16534                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
16535                      ifa = ifa->ifa_next, ip_idx++) {
16536 +                       if (sk && vx_info_flags(sk->sk_vx_info, VXF_HIDE_NETIF, 0) &&
16537 +                               !ifa_in_nx_info(ifa, sk->sk_nx_info))
16538 +                               continue;
16539                         if (ip_idx < s_ip_idx)
16540                                 continue;
16541                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
16542 diff -NurpP --minimal linux-2.6.10/net/ipv4/fib_hash.c linux-2.6.10-vs1.9.3.17/net/ipv4/fib_hash.c
16543 --- linux-2.6.10/net/ipv4/fib_hash.c    2004-12-25 01:55:31.000000000 +0100
16544 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/fib_hash.c 2004-12-26 19:40:29.000000000 +0100
16545 @@ -1022,6 +1022,8 @@ static unsigned fib_flag_trans(int type,
16546         return flags;
16547  }
16548  
16549 +extern int dev_in_nx_info(struct net_device *, struct nx_info *);
16550 +
16551  /* 
16552   *     This outputs /proc/net/route.
16553   *
16554 @@ -1052,7 +1054,8 @@ static int fib_seq_show(struct seq_file 
16555         prefix  = f->fn_key;
16556         mask    = FZ_MASK(iter->zone);
16557         flags   = fib_flag_trans(fa->fa_type, mask, fi);
16558 -       if (fi)
16559 +       if (fi && (!vx_flags(VXF_HIDE_NETIF, 0) ||
16560 +               dev_in_nx_info(fi->fib_dev, current->nx_info)))
16561                 snprintf(bf, sizeof(bf),
16562                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u",
16563                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
16564 diff -NurpP --minimal linux-2.6.10/net/ipv4/netfilter/ip_conntrack_proto_sctp.c linux-2.6.10-vs1.9.3.17/net/ipv4/netfilter/ip_conntrack_proto_sctp.c
16565 --- linux-2.6.10/net/ipv4/netfilter/ip_conntrack_proto_sctp.c   2004-10-23 05:06:26.000000000 +0200
16566 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/netfilter/ip_conntrack_proto_sctp.c        2004-12-26 19:40:36.000000000 +0100
16567 @@ -61,7 +61,11 @@ static const char *sctp_conntrack_names[
16568  unsigned long ip_ct_sctp_timeout_closed            =  10 SECS;
16569  unsigned long ip_ct_sctp_timeout_cookie_wait       =   3 SECS;
16570  unsigned long ip_ct_sctp_timeout_cookie_echoed     =   3 SECS;
16571 -unsigned long ip_ct_sctp_timeout_established       =   5 DAYS;
16572 +#if HZ < 9942
16573 +unsigned long ip_ct_sctp_timeout_established       =  5U DAYS;
16574 +#else
16575 +unsigned long ip_ct_sctp_timeout_established       =  2U DAYS;
16576 +#endif
16577  unsigned long ip_ct_sctp_timeout_shutdown_sent     = 300 SECS / 1000;
16578  unsigned long ip_ct_sctp_timeout_shutdown_recd     = 300 SECS / 1000;
16579  unsigned long ip_ct_sctp_timeout_shutdown_ack_sent =   3 SECS;
16580 diff -NurpP --minimal linux-2.6.10/net/ipv4/netfilter/ip_conntrack_proto_tcp.c linux-2.6.10-vs1.9.3.17/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
16581 --- linux-2.6.10/net/ipv4/netfilter/ip_conntrack_proto_tcp.c    2004-12-25 01:55:31.000000000 +0100
16582 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/netfilter/ip_conntrack_proto_tcp.c 2004-12-26 19:40:36.000000000 +0100
16583 @@ -88,7 +88,11 @@ static const char *tcp_conntrack_names[]
16584  
16585  unsigned long ip_ct_tcp_timeout_syn_sent =      2 MINS;
16586  unsigned long ip_ct_tcp_timeout_syn_recv =     60 SECS;
16587 -unsigned long ip_ct_tcp_timeout_established =   5 DAYS;
16588 +#if HZ < 9942
16589 +unsigned long ip_ct_tcp_timeout_established =  5U DAYS;
16590 +#else
16591 +unsigned long ip_ct_tcp_timeout_established =  2U DAYS;
16592 +#endif
16593  unsigned long ip_ct_tcp_timeout_fin_wait =      2 MINS;
16594  unsigned long ip_ct_tcp_timeout_close_wait =   60 SECS;
16595  unsigned long ip_ct_tcp_timeout_last_ack =     30 SECS;
16596 diff -NurpP --minimal linux-2.6.10/net/ipv4/netfilter/ipt_owner.c linux-2.6.10-vs1.9.3.17/net/ipv4/netfilter/ipt_owner.c
16597 --- linux-2.6.10/net/ipv4/netfilter/ipt_owner.c 2004-08-14 12:56:22.000000000 +0200
16598 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/netfilter/ipt_owner.c      2004-12-26 19:40:30.000000000 +0100
16599 @@ -61,7 +61,7 @@ match_pid(const struct sk_buff *skb, pid
16600         int i;
16601  
16602         read_lock(&tasklist_lock);
16603 -       p = find_task_by_pid(pid);
16604 +       p = find_task_by_real_pid(pid);
16605         if (!p)
16606                 goto out;
16607         task_lock(p);
16608 diff -NurpP --minimal linux-2.6.10/net/ipv4/raw.c linux-2.6.10-vs1.9.3.17/net/ipv4/raw.c
16609 --- linux-2.6.10/net/ipv4/raw.c 2004-12-25 01:55:31.000000000 +0100
16610 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/raw.c      2004-12-26 19:40:29.000000000 +0100
16611 @@ -102,6 +102,27 @@ static void raw_v4_unhash(struct sock *s
16612         write_unlock_bh(&raw_v4_lock);
16613  }
16614  
16615 +
16616 +/*
16617 + *     Check if a given address matches for a socket
16618 + *
16619 + *     nxi:            the socket's nx_info if any
16620 + *     addr:           to be verified address
16621 + *     saddr/baddr:    socket addresses
16622 + */
16623 +static inline int raw_addr_match (
16624 +       struct nx_info *nxi,
16625 +       uint32_t addr,
16626 +       uint32_t saddr,
16627 +       uint32_t baddr)
16628 +{
16629 +       if (addr && (saddr == addr || baddr == addr))
16630 +               return 1;
16631 +       if (!saddr)
16632 +               return addr_in_nx_info(nxi, addr);
16633 +       return 0;
16634 +}
16635 +
16636  struct sock *__raw_v4_lookup(struct sock *sk, unsigned short num,
16637                              unsigned long raddr, unsigned long laddr,
16638                              int dif)
16639 @@ -113,7 +134,8 @@ struct sock *__raw_v4_lookup(struct sock
16640  
16641                 if (inet->num == num                                    &&
16642                     !(inet->daddr && inet->daddr != raddr)              &&
16643 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
16644 +                   raw_addr_match(sk->sk_nx_info, laddr,
16645 +                       inet->rcv_saddr, inet->rcv_saddr2)              &&
16646                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
16647                         goto found; /* gotcha */
16648         }
16649 @@ -308,6 +330,10 @@ static int raw_send_hdrinc(struct sock *
16650  
16651                 iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
16652         }
16653 +       err = -EPERM;
16654 +       if (!vx_check(0, VX_ADMIN) && !capable(CAP_NET_RAW)
16655 +               && (!addr_in_nx_info(sk->sk_nx_info, iph->saddr)))
16656 +               goto error;
16657  
16658         err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
16659                       dst_output);
16660 @@ -480,6 +506,12 @@ static int raw_sendmsg(struct kiocb *ioc
16661                 if (!inet->hdrincl)
16662                         raw_probe_proto_opt(&fl, msg);
16663  
16664 +               if (sk->sk_nx_info) {
16665 +                       err = ip_find_src(sk->sk_nx_info, &rt, &fl);
16666 +
16667 +                       if (err)
16668 +                               goto done;
16669 +               }
16670                 err = ip_route_output_flow(&rt, &fl, sk, !(msg->msg_flags&MSG_DONTWAIT));
16671         }
16672         if (err)
16673 @@ -742,7 +774,8 @@ static struct sock *raw_get_first(struct
16674                 struct hlist_node *node;
16675  
16676                 sk_for_each(sk, node, &raw_v4_htable[state->bucket])
16677 -                       if (sk->sk_family == PF_INET)
16678 +                       if (sk->sk_family == PF_INET &&
16679 +                               vx_check(sk->sk_xid, VX_WATCH|VX_IDENT))
16680                                 goto found;
16681         }
16682         sk = NULL;
16683 @@ -758,7 +791,8 @@ static struct sock *raw_get_next(struct 
16684                 sk = sk_next(sk);
16685  try_again:
16686                 ;
16687 -       } while (sk && sk->sk_family != PF_INET);
16688 +       } while (sk && (sk->sk_family != PF_INET ||
16689 +               !vx_check(sk->sk_xid, VX_WATCH|VX_IDENT)));
16690  
16691         if (!sk && ++state->bucket < RAWV4_HTABLE_SIZE) {
16692                 sk = sk_head(&raw_v4_htable[state->bucket]);
16693 diff -NurpP --minimal linux-2.6.10/net/ipv4/tcp_ipv4.c linux-2.6.10-vs1.9.3.17/net/ipv4/tcp_ipv4.c
16694 --- linux-2.6.10/net/ipv4/tcp_ipv4.c    2004-12-25 01:55:31.000000000 +0100
16695 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/tcp_ipv4.c 2004-12-26 19:40:29.000000000 +0100
16696 @@ -74,6 +74,7 @@
16697  #include <linux/stddef.h>
16698  #include <linux/proc_fs.h>
16699  #include <linux/seq_file.h>
16700 +#include <linux/vserver/debug.h>
16701  
16702  extern int sysctl_ip_dynaddr;
16703  int sysctl_tcp_tw_reuse;
16704 @@ -181,7 +182,6 @@ void tcp_bind_hash(struct sock *sk, stru
16705  
16706  static inline int tcp_bind_conflict(struct sock *sk, struct tcp_bind_bucket *tb)
16707  {
16708 -       const u32 sk_rcv_saddr = tcp_v4_rcv_saddr(sk);
16709         struct sock *sk2;
16710         struct hlist_node *node;
16711         int reuse = sk->sk_reuse;
16712 @@ -194,9 +194,8 @@ static inline int tcp_bind_conflict(stru
16713                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
16714                         if (!reuse || !sk2->sk_reuse ||
16715                             sk2->sk_state == TCP_LISTEN) {
16716 -                               const u32 sk2_rcv_saddr = tcp_v4_rcv_saddr(sk2);
16717 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
16718 -                                   sk2_rcv_saddr == sk_rcv_saddr)
16719 +                               if (nx_addr_conflict(sk->sk_nx_info,
16720 +                                       tcp_v4_rcv_saddr(sk), sk2))
16721                                         break;
16722                         }
16723                 }
16724 @@ -405,6 +404,26 @@ void tcp_unhash(struct sock *sk)
16725                 wake_up(&tcp_lhash_wait);
16726  }
16727  
16728 +
16729 +/*
16730 + *      Check if a given address matches for a tcp socket
16731 + *
16732 + *      nxi:   the socket's nx_info if any
16733 + *      addr:  to be verified address
16734 + *      saddr: socket addresses
16735 + */
16736 +static inline int tcp_addr_match (
16737 +       struct nx_info *nxi,
16738 +       uint32_t addr,
16739 +       uint32_t saddr)
16740 +{
16741 +       if (addr && (saddr == addr))
16742 +               return 1;
16743 +       if (!saddr)
16744 +               return addr_in_nx_info(nxi, addr);
16745 +       return 0;
16746 +}
16747 +
16748  /* Don't inline this cruft.  Here are some nice properties to
16749   * exploit here.  The BSD API does not allow a listening TCP
16750   * to specify the remote port nor the remote address for the
16751 @@ -426,11 +445,10 @@ static struct sock *__tcp_v4_lookup_list
16752                         __u32 rcv_saddr = inet->rcv_saddr;
16753  
16754                         score = (sk->sk_family == PF_INET ? 1 : 0);
16755 -                       if (rcv_saddr) {
16756 -                               if (rcv_saddr != daddr)
16757 -                                       continue;
16758 +                       if (tcp_addr_match(sk->sk_nx_info, daddr, rcv_saddr))
16759                                 score+=2;
16760 -                       }
16761 +                       else
16762 +                               continue;
16763                         if (sk->sk_bound_dev_if) {
16764                                 if (sk->sk_bound_dev_if != dif)
16765                                         continue;
16766 @@ -460,8 +478,8 @@ static inline struct sock *tcp_v4_lookup
16767                 struct inet_opt *inet = inet_sk((sk = __sk_head(head)));
16768  
16769                 if (inet->num == hnum && !sk->sk_node.next &&
16770 -                   (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
16771                     (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
16772 +                   tcp_addr_match(sk->sk_nx_info, daddr, inet->rcv_saddr) &&
16773                     !sk->sk_bound_dev_if)
16774                         goto sherry_cache;
16775                 sk = __tcp_v4_lookup_listener(head, daddr, hnum, dif);
16776 @@ -2163,6 +2181,12 @@ static void *listening_get_next(struct s
16777                 req = req->dl_next;
16778                 while (1) {
16779                         while (req) {
16780 +                               vxdprintk(VXD_CBIT(net, 6),
16781 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
16782 +                                       (req->sk)?req->sk->sk_xid:0, vx_current_xid());
16783 +                               if (req->sk &&
16784 +                                       !vx_check(req->sk->sk_xid, VX_IDENT|VX_WATCH))
16785 +                                       continue;
16786                                 if (req->class->family == st->family) {
16787                                         cur = req;
16788                                         goto out;
16789 @@ -2187,6 +2211,10 @@ get_req:
16790         }
16791  get_sk:
16792         sk_for_each_from(sk, node) {
16793 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
16794 +                       sk, sk->sk_xid, vx_current_xid());
16795 +               if (!vx_check(sk->sk_xid, VX_IDENT|VX_WATCH))
16796 +                       continue;
16797                 if (sk->sk_family == st->family) {
16798                         cur = sk;
16799                         goto out;
16800 @@ -2235,18 +2263,26 @@ static void *established_get_first(struc
16801                
16802                 read_lock(&tcp_ehash[st->bucket].lock);
16803                 sk_for_each(sk, node, &tcp_ehash[st->bucket].chain) {
16804 -                       if (sk->sk_family != st->family) {
16805 +                       vxdprintk(VXD_CBIT(net, 6),
16806 +                               "sk,egf: %p [#%d] (from %d)",
16807 +                               sk, sk->sk_xid, vx_current_xid());
16808 +                       if (!vx_check(sk->sk_xid, VX_IDENT|VX_WATCH))
16809 +                               continue;
16810 +                       if (sk->sk_family != st->family)
16811                                 continue;
16812 -                       }
16813                         rc = sk;
16814                         goto out;
16815                 }
16816                 st->state = TCP_SEQ_STATE_TIME_WAIT;
16817                 tw_for_each(tw, node,
16818                             &tcp_ehash[st->bucket + tcp_ehash_size].chain) {
16819 -                       if (tw->tw_family != st->family) {
16820 +                       vxdprintk(VXD_CBIT(net, 6),
16821 +                               "tw: %p [#%d] (from %d)",
16822 +                               tw, tw->tw_xid, vx_current_xid());
16823 +                       if (!vx_check(tw->tw_xid, VX_IDENT|VX_WATCH))
16824 +                               continue;
16825 +                       if (tw->tw_family != st->family)
16826                                 continue;
16827 -                       }
16828                         rc = tw;
16829                         goto out;
16830                 }
16831 @@ -2270,7 +2306,8 @@ static void *established_get_next(struct
16832                 tw = cur;
16833                 tw = tw_next(tw);
16834  get_tw:
16835 -               while (tw && tw->tw_family != st->family) {
16836 +               while (tw && (tw->tw_family != st->family ||
16837 +                       !vx_check(tw->tw_xid, VX_IDENT|VX_WATCH))) {
16838                         tw = tw_next(tw);
16839                 }
16840                 if (tw) {
16841 @@ -2290,6 +2327,11 @@ get_tw:
16842                 sk = sk_next(sk);
16843  
16844         sk_for_each_from(sk, node) {
16845 +               vxdprintk(VXD_CBIT(net, 6),
16846 +                       "sk,egn: %p [#%d] (from %d)",
16847 +                       sk, sk->sk_xid, vx_current_xid());
16848 +               if (!vx_check(sk->sk_xid, VX_IDENT|VX_WATCH))
16849 +                       continue;
16850                 if (sk->sk_family == st->family)
16851                         goto found;
16852         }
16853 diff -NurpP --minimal linux-2.6.10/net/ipv4/tcp_minisocks.c linux-2.6.10-vs1.9.3.17/net/ipv4/tcp_minisocks.c
16854 --- linux-2.6.10/net/ipv4/tcp_minisocks.c       2004-12-25 01:55:31.000000000 +0100
16855 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/tcp_minisocks.c    2004-12-26 19:40:29.000000000 +0100
16856 @@ -29,6 +29,9 @@
16857  #include <net/inet_common.h>
16858  #include <net/xfrm.h>
16859  
16860 +#include <linux/vs_limit.h>
16861 +#include <linux/vs_socket.h>
16862 +
16863  #ifdef CONFIG_SYSCTL
16864  #define SYNC_INIT 0 /* let the user enable it */
16865  #else
16866 @@ -362,6 +365,11 @@ void tcp_time_wait(struct sock *sk, int 
16867                 tw->tw_ts_recent_stamp  = tp->ts_recent_stamp;
16868                 tw_dead_node_init(tw);
16869  
16870 +               tw->tw_xid              = sk->sk_xid;
16871 +               tw->tw_vx_info          = NULL;
16872 +               tw->tw_nid              = sk->sk_nid;
16873 +               tw->tw_nx_info          = NULL;
16874 +
16875  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
16876                 if (tw->tw_family == PF_INET6) {
16877                         struct ipv6_pinfo *np = inet6_sk(sk);
16878 @@ -697,6 +705,8 @@ struct sock *tcp_create_openreq_child(st
16879                 newsk->sk_state = TCP_SYN_RECV;
16880  
16881                 /* SANITY */
16882 +               sock_vx_init(newsk);
16883 +               sock_nx_init(newsk);
16884                 sk_node_init(&newsk->sk_node);
16885                 tcp_sk(newsk)->bind_hash = NULL;
16886  
16887 @@ -795,6 +805,12 @@ struct sock *tcp_create_openreq_child(st
16888                 newsk->sk_err = 0;
16889                 newsk->sk_priority = 0;
16890                 atomic_set(&newsk->sk_refcnt, 2);
16891 +
16892 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
16893 +               newsk->sk_xid = sk->sk_xid;
16894 +               vx_sock_inc(newsk);
16895 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
16896 +               newsk->sk_nid = sk->sk_nid;
16897  #ifdef INET_REFCNT_DEBUG
16898                 atomic_inc(&inet_sock_nr);
16899  #endif
16900 diff -NurpP --minimal linux-2.6.10/net/ipv4/udp.c linux-2.6.10-vs1.9.3.17/net/ipv4/udp.c
16901 --- linux-2.6.10/net/ipv4/udp.c 2004-12-25 01:55:31.000000000 +0100
16902 +++ linux-2.6.10-vs1.9.3.17/net/ipv4/udp.c      2004-12-26 19:40:29.000000000 +0100
16903 @@ -174,14 +174,12 @@ gotit:
16904                         struct inet_opt *inet2 = inet_sk(sk2);
16905  
16906                         if (inet2->num == snum &&
16907 -                           sk2 != sk &&
16908 -                           !ipv6_only_sock(sk2) &&
16909 +                           sk2 != sk && !ipv6_only_sock(sk2) &&
16910                             (!sk2->sk_bound_dev_if ||
16911                              !sk->sk_bound_dev_if ||
16912                              sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
16913 -                           (!inet2->rcv_saddr ||
16914 -                            !inet->rcv_saddr ||
16915 -                            inet2->rcv_saddr == inet->rcv_saddr) &&
16916 +                           nx_addr_conflict(sk->sk_nx_info,
16917 +                            tcp_v4_rcv_saddr(sk), sk2) &&
16918                             (!sk2->sk_reuse || !sk->sk_reuse))
16919                                 goto fail;
16920                 }
16921 @@ -216,6 +214,17 @@ static void udp_v4_unhash(struct sock *s
16922         write_unlock_bh(&udp_hash_lock);
16923  }
16924  
16925 +static inline int udp_in_list(struct nx_info *nx_info, u32 addr)
16926 +{
16927 +       int n = nx_info->nbipv4;
16928 +       int i;
16929 +
16930 +       for (i=0; i<n; i++)
16931 +               if (nx_info->ipv4[i] == addr)
16932 +                       return 1;
16933 +       return 0;
16934 +}
16935 +
16936  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
16937   * harder than this. -DaveM
16938   */
16939 @@ -235,6 +244,11 @@ struct sock *udp_v4_lookup_longway(u32 s
16940                                 if (inet->rcv_saddr != daddr)
16941                                         continue;
16942                                 score+=2;
16943 +                       } else if (sk->sk_nx_info) {
16944 +                               if (udp_in_list(sk->sk_nx_info, daddr))
16945 +                                       score+=2;
16946 +                               else
16947 +                                       continue;
16948                         }
16949                         if (inet->daddr) {
16950                                 if (inet->daddr != saddr)
16951 @@ -290,7 +304,8 @@ static inline struct sock *udp_v4_mcast_
16952                 if (inet->num != hnum                                   ||
16953                     (inet->daddr && inet->daddr != rmt_addr)            ||
16954                     (inet->dport != rmt_port && inet->dport)            ||
16955 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
16956 +                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr &&
16957 +                    inet->rcv_saddr2 && inet->rcv_saddr2 != loc_addr)  ||
16958                     ipv6_only_sock(s)                                   ||
16959                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
16960                         continue;
16961 @@ -599,6 +614,15 @@ int udp_sendmsg(struct kiocb *iocb, stru
16962                                     .uli_u = { .ports =
16963                                                { .sport = inet->sport,
16964                                                  .dport = dport } } };
16965 +               struct nx_info *nxi = sk->sk_nx_info;
16966 +
16967 +               if (nxi) {
16968 +                       err = ip_find_src(nxi, &rt, &fl);
16969 +                       if (err)
16970 +                               goto out;
16971 +                       if (daddr == IPI_LOOPBACK && !vx_check(0, VX_ADMIN))
16972 +                               daddr = fl.fl4_dst = nxi->ipv4[0];
16973 +               }
16974                 err = ip_route_output_flow(&rt, &fl, sk, !(msg->msg_flags&MSG_DONTWAIT));
16975                 if (err)
16976                         goto out;
16977 @@ -1380,8 +1404,10 @@ static struct sock *udp_get_first(struct
16978  
16979         for (state->bucket = 0; state->bucket < UDP_HTABLE_SIZE; ++state->bucket) {
16980                 struct hlist_node *node;
16981 +
16982                 sk_for_each(sk, node, &udp_hash[state->bucket]) {
16983 -                       if (sk->sk_family == state->family)
16984 +                       if (sk->sk_family == state->family &&
16985 +                               vx_check(sk->sk_xid, VX_WATCH|VX_IDENT))
16986                                 goto found;
16987                 }
16988         }
16989 @@ -1398,7 +1424,8 @@ static struct sock *udp_get_next(struct 
16990                 sk = sk_next(sk);
16991  try_again:
16992                 ;
16993 -       } while (sk && sk->sk_family != state->family);
16994 +       } while (sk && (sk->sk_family != state->family ||
16995 +               !vx_check(sk->sk_xid, VX_WATCH|VX_IDENT)));
16996  
16997         if (!sk && ++state->bucket < UDP_HTABLE_SIZE) {
16998                 sk = sk_head(&udp_hash[state->bucket]);
16999 diff -NurpP --minimal linux-2.6.10/net/ipv6/addrconf.c linux-2.6.10-vs1.9.3.17/net/ipv6/addrconf.c
17000 --- linux-2.6.10/net/ipv6/addrconf.c    2004-12-25 01:55:31.000000000 +0100
17001 +++ linux-2.6.10-vs1.9.3.17/net/ipv6/addrconf.c 2004-12-26 19:40:29.000000000 +0100
17002 @@ -2659,6 +2659,10 @@ static int inet6_dump_addr(struct sk_buf
17003         struct ifmcaddr6 *ifmca;
17004         struct ifacaddr6 *ifaca;
17005  
17006 +       /* no ipv6 inside a vserver for now */
17007 +       if (skb->sk && skb->sk->sk_vx_info)
17008 +               return skb->len;
17009 +
17010         s_idx = cb->args[0];
17011         s_ip_idx = ip_idx = cb->args[1];
17012         read_lock(&dev_base_lock);
17013 @@ -2878,6 +2882,10 @@ static int inet6_dump_ifinfo(struct sk_b
17014         struct net_device *dev;
17015         struct inet6_dev *idev;
17016  
17017 +       /* no ipv6 inside a vserver for now */
17018 +       if (skb->sk && skb->sk->sk_vx_info)
17019 +               return skb->len;
17020 +
17021         read_lock(&dev_base_lock);
17022         for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) {
17023                 if (idx < s_idx)
17024 diff -NurpP --minimal linux-2.6.10/net/ipv6/netfilter/ip6t_owner.c linux-2.6.10-vs1.9.3.17/net/ipv6/netfilter/ip6t_owner.c
17025 --- linux-2.6.10/net/ipv6/netfilter/ip6t_owner.c        2004-12-25 01:55:32.000000000 +0100
17026 +++ linux-2.6.10-vs1.9.3.17/net/ipv6/netfilter/ip6t_owner.c     2004-12-26 19:40:30.000000000 +0100
17027 @@ -28,7 +28,7 @@ match_pid(const struct sk_buff *skb, pid
17028         int i;
17029  
17030         read_lock(&tasklist_lock);
17031 -       p = find_task_by_pid(pid);
17032 +       p = find_task_by_real_pid(pid);
17033         if (!p)
17034                 goto out;
17035         task_lock(p);
17036 diff -NurpP --minimal linux-2.6.10/net/netlink/af_netlink.c linux-2.6.10-vs1.9.3.17/net/netlink/af_netlink.c
17037 --- linux-2.6.10/net/netlink/af_netlink.c       2004-12-25 01:55:32.000000000 +0100
17038 +++ linux-2.6.10-vs1.9.3.17/net/netlink/af_netlink.c    2004-12-26 19:40:29.000000000 +0100
17039 @@ -50,6 +50,9 @@
17040  #include <linux/bitops.h>
17041  #include <linux/mm.h>
17042  #include <linux/types.h>
17043 +#include <linux/vs_context.h>
17044 +#include <linux/vs_network.h>
17045 +#include <linux/vs_limit.h>
17046  #include <net/sock.h>
17047  #include <net/scm.h>
17048  
17049 @@ -361,6 +364,12 @@ static int netlink_create(struct socket 
17050         init_waitqueue_head(&nlk->wait);
17051         sk->sk_destruct = netlink_sock_destruct;
17052  
17053 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
17054 +       sk->sk_xid = vx_current_xid();
17055 +       vx_sock_inc(sk);
17056 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
17057 +       sk->sk_nid = nx_current_nid();
17058 +
17059         sk->sk_protocol = protocol;
17060         return 0;
17061  }
17062 @@ -402,6 +411,12 @@ static int netlink_release(struct socket
17063                 notifier_call_chain(&netlink_chain, NETLINK_URELEASE, &n);
17064         }       
17065         
17066 +       vx_sock_dec(sk);
17067 +       clr_vx_info(&sk->sk_vx_info);
17068 +       sk->sk_xid = -1;
17069 +       clr_nx_info(&sk->sk_nx_info);
17070 +       sk->sk_nid = -1;
17071 +
17072         sock_put(sk);
17073         return 0;
17074  }
17075 diff -NurpP --minimal linux-2.6.10/net/socket.c linux-2.6.10-vs1.9.3.17/net/socket.c
17076 --- linux-2.6.10/net/socket.c   2004-12-25 01:55:32.000000000 +0100
17077 +++ linux-2.6.10-vs1.9.3.17/net/socket.c        2004-12-26 19:40:29.000000000 +0100
17078 @@ -93,6 +93,7 @@
17079  
17080  #include <net/sock.h>
17081  #include <linux/netfilter.h>
17082 +#include <linux/vs_socket.h>
17083  
17084  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
17085  static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
17086 @@ -287,7 +288,7 @@ static struct inode *sock_alloc_inode(st
17087         ei->socket.ops = NULL;
17088         ei->socket.sk = NULL;
17089         ei->socket.file = NULL;
17090 -       ei->socket.passcred = 0;
17091 +       ei->socket.flags = 0;
17092  
17093         return &ei->vfs_inode;
17094  }
17095 @@ -531,7 +532,7 @@ static inline int __sock_sendmsg(struct 
17096                                  struct msghdr *msg, size_t size)
17097  {
17098         struct sock_iocb *si = kiocb_to_siocb(iocb);
17099 -       int err;
17100 +       int err, len;
17101  
17102         si->sock = sock;
17103         si->scm = NULL;
17104 @@ -542,7 +543,21 @@ static inline int __sock_sendmsg(struct 
17105         if (err)
17106                 return err;
17107  
17108 -       return sock->ops->sendmsg(iocb, sock, msg, size);
17109 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
17110 +       if (sock->sk) {
17111 +               if (len == size)
17112 +                       vx_sock_send(sock->sk, size);
17113 +               else
17114 +                       vx_sock_fail(sock->sk, size);
17115 +       }
17116 +       vxdprintk(VXD_CBIT(net, 7),
17117 +               "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d",
17118 +               sock, sock->sk,
17119 +               (sock->sk)?sock->sk->sk_nx_info:0,
17120 +               (sock->sk)?sock->sk->sk_vx_info:0,
17121 +               (sock->sk)?sock->sk->sk_xid:0,
17122 +               (unsigned int)size, len);
17123 +       return len;
17124  }
17125  
17126  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
17127 @@ -580,7 +595,7 @@ int kernel_sendmsg(struct socket *sock, 
17128  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock, 
17129                                  struct msghdr *msg, size_t size, int flags)
17130  {
17131 -       int err;
17132 +       int err, len;
17133         struct sock_iocb *si = kiocb_to_siocb(iocb);
17134  
17135         si->sock = sock;
17136 @@ -593,7 +608,17 @@ static inline int __sock_recvmsg(struct 
17137         if (err)
17138                 return err;
17139  
17140 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
17141 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
17142 +       if ((len >= 0) && sock->sk)
17143 +               vx_sock_recv(sock->sk, len);
17144 +       vxdprintk(VXD_CBIT(net, 7),
17145 +               "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d",
17146 +               sock, sock->sk,
17147 +               (sock->sk)?sock->sk->sk_nx_info:0,
17148 +               (sock->sk)?sock->sk->sk_vx_info:0,
17149 +               (sock->sk)?sock->sk->sk_xid:0,
17150 +               (unsigned int)size, len);
17151 +       return len;
17152  }
17153  
17154  int sock_recvmsg(struct socket *sock, struct msghdr *msg, 
17155 @@ -1085,6 +1110,10 @@ static int __sock_create(int family, int
17156         if (type < 0 || type >= SOCK_MAX)
17157                 return -EINVAL;
17158  
17159 +       /* disable IPv6 inside vservers for now */
17160 +       if (family == PF_INET6 && !vx_check(0, VX_ADMIN))
17161 +               return -EAFNOSUPPORT;
17162 +
17163         /* Compatibility.
17164  
17165            This uglymoron is moved from INET layer to here to avoid
17166 @@ -1193,6 +1222,7 @@ asmlinkage long sys_socket(int family, i
17167         if (retval < 0)
17168                 goto out;
17169  
17170 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
17171         retval = sock_map_fd(sock);
17172         if (retval < 0)
17173                 goto out_release;
17174 @@ -1223,10 +1253,12 @@ asmlinkage long sys_socketpair(int famil
17175         err = sock_create(family, type, protocol, &sock1);
17176         if (err < 0)
17177                 goto out;
17178 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
17179  
17180         err = sock_create(family, type, protocol, &sock2);
17181         if (err < 0)
17182                 goto out_release_1;
17183 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
17184  
17185         err = sock1->ops->socketpair(sock1, sock2);
17186         if (err < 0) 
17187 diff -NurpP --minimal linux-2.6.10/net/sunrpc/auth.c linux-2.6.10-vs1.9.3.17/net/sunrpc/auth.c
17188 --- linux-2.6.10/net/sunrpc/auth.c      2004-08-14 12:55:32.000000000 +0200
17189 +++ linux-2.6.10-vs1.9.3.17/net/sunrpc/auth.c   2004-12-26 19:40:34.000000000 +0100
17190 @@ -14,6 +14,7 @@
17191  #include <linux/socket.h>
17192  #include <linux/sunrpc/clnt.h>
17193  #include <linux/spinlock.h>
17194 +#include <linux/vserver/xid.h>
17195  
17196  #ifdef RPC_DEBUG
17197  # define RPCDBG_FACILITY       RPCDBG_AUTH
17198 @@ -261,6 +262,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
17199         get_group_info(current->group_info);
17200         acred.uid = current->fsuid;
17201         acred.gid = current->fsgid;
17202 +       acred.xid = vx_current_xid();
17203         acred.group_info = current->group_info;
17204  
17205         dprintk("RPC:     looking up %s cred\n",
17206 @@ -280,6 +282,7 @@ rpcauth_bindcred(struct rpc_task *task)
17207         get_group_info(current->group_info);
17208         acred.uid = current->fsuid;
17209         acred.gid = current->fsgid;
17210 +       acred.xid = vx_current_xid();
17211         acred.group_info = current->group_info;
17212  
17213         dprintk("RPC: %4d looking up %s cred\n",
17214 diff -NurpP --minimal linux-2.6.10/net/sunrpc/auth_unix.c linux-2.6.10-vs1.9.3.17/net/sunrpc/auth_unix.c
17215 --- linux-2.6.10/net/sunrpc/auth_unix.c 2004-08-14 12:55:33.000000000 +0200
17216 +++ linux-2.6.10-vs1.9.3.17/net/sunrpc/auth_unix.c      2004-12-26 19:40:34.000000000 +0100
17217 @@ -13,14 +13,17 @@
17218  #include <linux/in.h>
17219  #include <linux/sunrpc/clnt.h>
17220  #include <linux/sunrpc/auth.h>
17221 +#include <linux/vserver/xid.h>
17222  
17223  #define NFS_NGROUPS    16
17224  
17225  struct unx_cred {
17226         struct rpc_cred         uc_base;
17227         gid_t                   uc_gid;
17228 +       xid_t                   uc_xid;
17229         uid_t                   uc_puid;                /* process uid */
17230         gid_t                   uc_pgid;                /* process gid */
17231 +       xid_t                   uc_pxid;                /* process xid */
17232         gid_t                   uc_gids[NFS_NGROUPS];
17233  };
17234  #define uc_uid                 uc_base.cr_uid
17235 @@ -80,6 +83,7 @@ unx_create_cred(struct rpc_auth *auth, s
17236         if (flags & RPC_TASK_ROOTCREDS) {
17237                 cred->uc_uid = cred->uc_puid = 0;
17238                 cred->uc_gid = cred->uc_pgid = 0;
17239 +               cred->uc_xid = cred->uc_pxid = vx_current_xid();
17240                 cred->uc_gids[0] = NOGROUP;
17241         } else {
17242                 int groups = acred->group_info->ngroups;
17243 @@ -88,8 +92,10 @@ unx_create_cred(struct rpc_auth *auth, s
17244  
17245                 cred->uc_uid = acred->uid;
17246                 cred->uc_gid = acred->gid;
17247 +               cred->uc_xid = acred->xid;
17248                 cred->uc_puid = current->uid;
17249                 cred->uc_pgid = current->gid;
17250 +               cred->uc_pxid = vx_current_xid();
17251                 for (i = 0; i < groups; i++)
17252                         cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
17253                 if (i < NFS_NGROUPS)
17254 @@ -122,8 +128,10 @@ unx_match(struct auth_cred *acred, struc
17255  
17256                 if (cred->uc_uid != acred->uid
17257                  || cred->uc_gid != acred->gid
17258 +                || cred->uc_xid != acred->xid
17259                  || cred->uc_puid != current->uid
17260 -                || cred->uc_pgid != current->gid)
17261 +                || cred->uc_pgid != current->gid
17262 +                || cred->uc_pxid != vx_current_xid())
17263                         return 0;
17264  
17265                 groups = acred->group_info->ngroups;
17266 @@ -149,7 +157,7 @@ unx_marshal(struct rpc_task *task, u32 *
17267         struct rpc_clnt *clnt = task->tk_client;
17268         struct unx_cred *cred = (struct unx_cred *) task->tk_msg.rpc_cred;
17269         u32             *base, *hold;
17270 -       int             i;
17271 +       int             i, tagxid;
17272  
17273         *p++ = htonl(RPC_AUTH_UNIX);
17274         base = p++;
17275 @@ -159,14 +167,19 @@ unx_marshal(struct rpc_task *task, u32 *
17276          * Copy the UTS nodename captured when the client was created.
17277          */
17278         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
17279 +       tagxid = task->tk_client->cl_tagxid;
17280  
17281         /* Note: we don't use real uid if it involves raising privilege */
17282         if (ruid && cred->uc_puid != 0 && cred->uc_pgid != 0) {
17283 -               *p++ = htonl((u32) cred->uc_puid);
17284 -               *p++ = htonl((u32) cred->uc_pgid);
17285 +               *p++ = htonl((u32) XIDINO_UID(tagxid,
17286 +                       cred->uc_puid, cred->uc_pxid));
17287 +               *p++ = htonl((u32) XIDINO_GID(tagxid,
17288 +                       cred->uc_pgid, cred->uc_pxid));
17289         } else {
17290 -               *p++ = htonl((u32) cred->uc_uid);
17291 -               *p++ = htonl((u32) cred->uc_gid);
17292 +               *p++ = htonl((u32) XIDINO_UID(tagxid,
17293 +                       cred->uc_uid, cred->uc_xid));
17294 +               *p++ = htonl((u32) XIDINO_GID(tagxid,
17295 +                       cred->uc_gid, cred->uc_xid));
17296         }
17297         hold = p++;
17298         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
17299 diff -NurpP --minimal linux-2.6.10/net/unix/af_unix.c linux-2.6.10-vs1.9.3.17/net/unix/af_unix.c
17300 --- linux-2.6.10/net/unix/af_unix.c     2004-12-25 01:55:32.000000000 +0100
17301 +++ linux-2.6.10-vs1.9.3.17/net/unix/af_unix.c  2004-12-26 19:40:29.000000000 +0100
17302 @@ -118,6 +118,9 @@
17303  #include <linux/mount.h>
17304  #include <net/checksum.h>
17305  #include <linux/security.h>
17306 +#include <linux/vs_context.h>
17307 +#include <linux/vs_network.h>
17308 +#include <linux/vs_limit.h>
17309  
17310  int sysctl_unix_max_dgram_qlen = 10;
17311  
17312 @@ -394,6 +397,9 @@ static int unix_release_sock (struct soc
17313                 mntput(mnt);
17314         }
17315  
17316 +       vx_sock_dec(sk);
17317 +       clr_vx_info(&sk->sk_vx_info);
17318 +       clr_nx_info(&sk->sk_nx_info);
17319         sock_put(sk);
17320  
17321         /* ---- Socket is dead now and most probably destroyed ---- */
17322 @@ -550,6 +556,11 @@ static struct sock * unix_create1(struct
17323         sock_init_data(sock,sk);
17324         sk_set_owner(sk, THIS_MODULE);
17325  
17326 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
17327 +       sk->sk_xid = vx_current_xid();
17328 +       vx_sock_inc(sk);
17329 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
17330 +
17331         sk->sk_write_space      = unix_write_space;
17332         sk->sk_max_ack_backlog  = sysctl_unix_max_dgram_qlen;
17333         sk->sk_destruct         = unix_sock_destructor;
17334 @@ -861,7 +872,7 @@ static int unix_dgram_connect(struct soc
17335                         goto out;
17336                 alen = err;
17337  
17338 -               if (sock->passcred && !unix_sk(sk)->addr &&
17339 +               if (test_bit(SOCK_PASS_CRED, &sock->flags) && !unix_sk(sk)->addr &&
17340                     (err = unix_autobind(sock)) != 0)
17341                         goto out;
17342  
17343 @@ -952,7 +963,8 @@ static int unix_stream_connect(struct so
17344                 goto out;
17345         addr_len = err;
17346  
17347 -       if (sock->passcred && !u->addr && (err = unix_autobind(sock)) != 0)
17348 +       if (test_bit(SOCK_PASS_CRED, &sock->flags)
17349 +               && !u->addr && (err = unix_autobind(sock)) != 0)
17350                 goto out;
17351  
17352         timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
17353 @@ -1286,7 +1298,8 @@ static int unix_dgram_sendmsg(struct kio
17354                         goto out;
17355         }
17356  
17357 -       if (sock->passcred && !u->addr && (err = unix_autobind(sock)) != 0)
17358 +       if (test_bit(SOCK_PASS_CRED, &sock->flags)
17359 +               && !u->addr && (err = unix_autobind(sock)) != 0)
17360                 goto out;
17361  
17362         err = -EMSGSIZE;
17363 diff -NurpP --minimal linux-2.6.10/security/commoncap.c linux-2.6.10-vs1.9.3.17/security/commoncap.c
17364 --- linux-2.6.10/security/commoncap.c   2004-12-25 01:55:32.000000000 +0100
17365 +++ linux-2.6.10-vs1.9.3.17/security/commoncap.c        2004-12-26 19:40:23.000000000 +0100
17366 @@ -142,7 +142,7 @@ void cap_bprm_apply_creds (struct linux_
17367         /* Derived from fs/exec.c:compute_creds. */
17368         kernel_cap_t new_permitted, working;
17369  
17370 -       new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
17371 +       new_permitted = cap_intersect (bprm->cap_permitted, vx_current_bcaps());
17372         working = cap_intersect (bprm->cap_inheritable,
17373                                  current->cap_inheritable);
17374         new_permitted = cap_combine (new_permitted, working);
17375 diff -NurpP --minimal linux-2.6.10/security/security.c linux-2.6.10-vs1.9.3.17/security/security.c
17376 --- linux-2.6.10/security/security.c    2004-12-25 01:55:33.000000000 +0100
17377 +++ linux-2.6.10-vs1.9.3.17/security/security.c 2004-12-26 19:40:23.000000000 +0100
17378 @@ -185,6 +185,8 @@ int mod_unreg_security(const char *name,
17379   */
17380  int capable(int cap)
17381  {
17382 +       if (vx_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
17383 +               return 0;
17384         if (security_ops->capable(current, cap)) {
17385                 /* capability denied */
17386                 return 0;
17387 @@ -195,9 +197,24 @@ int capable(int cap)
17388         return 1;
17389  }
17390  
17391 +int vx_capable(int cap, int ccap)
17392 +{
17393 +       if (security_ops->capable(current, cap)) {
17394 +               /* capability denied */
17395 +               return 0;
17396 +       }
17397 +       if (!vx_ccaps(ccap))
17398 +               return 0;
17399 +
17400 +       /* capability granted */
17401 +       current->flags |= PF_SUPERPRIV;
17402 +       return 1;
17403 +}
17404 +
17405  EXPORT_SYMBOL_GPL(register_security);
17406  EXPORT_SYMBOL_GPL(unregister_security);
17407  EXPORT_SYMBOL_GPL(mod_reg_security);
17408  EXPORT_SYMBOL_GPL(mod_unreg_security);
17409  EXPORT_SYMBOL(capable);
17410 +EXPORT_SYMBOL(vx_capable);
17411  EXPORT_SYMBOL(security_ops);
This page took 1.454949 seconds and 3 git commands to generate.