]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- up to 3.7.7; add delta-addrlock-fix04.diff vserver fix
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.7.1/Documentation/vserver/debug.txt linux-3.7.1-vs2.3.5.5/Documentation/vserver/debug.txt
2 --- linux-3.7.1/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.7.1-vs2.3.5.5/Documentation/vserver/debug.txt       2012-12-18 15:13:16.000000000 +0000
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
13 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
14 +       "FREE  (%p,#%d)%c inode"
15 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 +       "FREE  (%p,#%d)%c %lld bytes"
17 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 +       "rcu_free_dl_info(%p)"
21 + 4  10 "alloc_dl_info(%p,%d) = %p"
22 +       "dealloc_dl_info(%p)"
23 +       "get_dl_info(%p[#%d.%d])"
24 +       "put_dl_info(%p[#%d.%d])"
25 + 5  20 "alloc_dl_info(%p,%d)*"
26 + 6  40 "__hash_dl_info: %p[#%d]"
27 +       "__unhash_dl_info: %p[#%d]"
28 + 7  80 "locate_dl_info(%p,#%d) = %p"
29 +
30 +debug_misc:
31 +
32 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 +       "new_dqhash: %p [#0x%08x]"
34 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 +       "vroot_get_real_bdev not set"
38 + 1   2 "cow_break_link(»%s«)"
39 +       "temp copy »%s«"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path »%s«"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %d"
48 + 3   8 "fput(new_file=%p[#%d])"
49 +       "fput(old_file=%p[#%d])"
50 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 +       "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5  20 "vs_reboot(%p[#%d],%d)"
53 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
54 +
55 +debug_net:
56 +
57 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6  40 "sk,egf: %p [#%d] (from %d)"
63 +       "sk,egn: %p [#%d] (from %d)"
64 +       "sk,req: %p [#%d] (from %d)"
65 +       "sk: %p [#%d] (from %d)"
66 +       "tw: %p [#%d] (from %d)"
67 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
69 +
70 +debug_nid:
71 +
72 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
73 +       "alloc_nx_info(%d) = %p"
74 +       "create_nx_info(%d) (dynamic rejected)"
75 +       "create_nx_info(%d) = %p (already there)"
76 +       "create_nx_info(%d) = %p (new)"
77 +       "dealloc_nx_info(%p)"
78 + 1   2 "alloc_nx_info(%d)*"
79 +       "create_nx_info(%d)*"
80 + 2   4 "get_nx_info(%p[#%d.%d])"
81 +       "put_nx_info(%p[#%d.%d])"
82 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 +       "clr_nx_info(%p[#%d.%d])"
84 +       "init_nx_info(%p[#%d.%d])"
85 +       "release_nx_info(%p[#%d.%d.%d]) %p"
86 +       "set_nx_info(%p[#%d.%d])"
87 + 4  10 "__hash_nx_info: %p[#%d]"
88 +       "__nx_dynamic_id: [#%d]"
89 +       "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5  20 "moved task %p into nxi:%p[#%d]"
91 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 +       "task_get_nx_info(%p)"
93 + 6  40 "nx_clear_persistent(%p[#%d])"
94 +
95 +debug_quota:
96 +
97 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1   2 "quota_sync_dqh(%p,%d)"
99 +       "sync_dquots(%p,%d)"
100 +       "sync_dquots_dqh(%p,%d)"
101 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
102 +
103 +debug_switch:
104 +
105 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4  10 "%s: (%s %s) returned %s with %d"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
116 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
117 +       "alloc_vx_info(%d) = %p"
118 +       "alloc_vx_info(%d)*"
119 +       "create_vx_info(%d) (dynamic rejected)"
120 +       "create_vx_info(%d) = %p (already there)"
121 +       "create_vx_info(%d) = %p (new)"
122 +       "dealloc_vx_info(%p)"
123 +       "loc_vx_info(%d) = %p (found)"
124 +       "loc_vx_info(%d) = %p (new)"
125 +       "loc_vx_info(%d) = %p (not available)"
126 + 1   2 "create_vx_info(%d)*"
127 +       "loc_vx_info(%d)*"
128 + 2   4 "get_vx_info(%p[#%d.%d])"
129 +       "put_vx_info(%p[#%d.%d])"
130 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 +       "clr_vx_info(%p[#%d.%d])"
132 +       "init_vx_info(%p[#%d.%d])"
133 +       "release_vx_info(%p[#%d.%d.%d]) %p"
134 +       "set_vx_info(%p[#%d.%d])"
135 + 4  10 "__hash_vx_info: %p[#%d]"
136 +       "__unhash_vx_info: %p[#%d.%d.%d]"
137 +       "__vx_dynamic_id: [#%d]"
138 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 +       "moved task %p into vxi:%p[#%d]"
141 +       "task_get_vx_info(%p)"
142 +       "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6  40 "vx_clear_persistent(%p[#%d])"
144 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 +       "vx_set_persistent(%p[#%d])"
147 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-3.7.1/arch/alpha/Kconfig linux-3.7.1-vs2.3.5.5/arch/alpha/Kconfig
160 --- linux-3.7.1/arch/alpha/Kconfig      2012-12-11 03:30:57.000000000 +0000
161 +++ linux-3.7.1-vs2.3.5.5/arch/alpha/Kconfig    2012-12-18 15:13:16.000000000 +0000
162 @@ -668,6 +668,8 @@ config DUMMY_CONSOLE
163         depends on VGA_HOSE
164         default y
165  
166 +source "kernel/vserver/Kconfig"
167 +
168  source "security/Kconfig"
169  
170  source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.7.1/arch/alpha/kernel/systbls.S linux-3.7.1-vs2.3.5.5/arch/alpha/kernel/systbls.S
172 --- linux-3.7.1/arch/alpha/kernel/systbls.S     2012-12-11 03:30:57.000000000 +0000
173 +++ linux-3.7.1-vs2.3.5.5/arch/alpha/kernel/systbls.S   2012-12-18 15:13:16.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175         .quad sys_stat64                        /* 425 */
176         .quad sys_lstat64
177         .quad sys_fstat64
178 -       .quad sys_ni_syscall                    /* sys_vserver */
179 +       .quad sys_vserver                       /* sys_vserver */
180         .quad sys_ni_syscall                    /* sys_mbind */
181         .quad sys_ni_syscall                    /* sys_get_mempolicy */
182         .quad sys_ni_syscall                    /* sys_set_mempolicy */
183 diff -NurpP --minimal linux-3.7.1/arch/alpha/kernel/traps.c linux-3.7.1-vs2.3.5.5/arch/alpha/kernel/traps.c
184 --- linux-3.7.1/arch/alpha/kernel/traps.c       2012-12-11 03:30:57.000000000 +0000
185 +++ linux-3.7.1-vs2.3.5.5/arch/alpha/kernel/traps.c     2012-12-18 15:13:16.000000000 +0000
186 @@ -184,7 +184,8 @@ die_if_kernel(char * str, struct pt_regs
187  #ifdef CONFIG_SMP
188         printk("CPU %d ", hard_smp_processor_id());
189  #endif
190 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
191 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
192 +               task_pid_nr(current), current->xid, str, err);
193         dik_show_regs(regs, r9_15);
194         add_taint(TAINT_DIE);
195         dik_show_trace((unsigned long *)(regs+1));
196 diff -NurpP --minimal linux-3.7.1/arch/arm/Kconfig linux-3.7.1-vs2.3.5.5/arch/arm/Kconfig
197 --- linux-3.7.1/arch/arm/Kconfig        2012-12-11 03:30:57.000000000 +0000
198 +++ linux-3.7.1-vs2.3.5.5/arch/arm/Kconfig      2012-12-18 15:13:16.000000000 +0000
199 @@ -2307,6 +2307,8 @@ source "fs/Kconfig"
200  
201  source "arch/arm/Kconfig.debug"
202  
203 +source "kernel/vserver/Kconfig"
204 +
205  source "security/Kconfig"
206  
207  source "crypto/Kconfig"
208 diff -NurpP --minimal linux-3.7.1/arch/arm/kernel/calls.S linux-3.7.1-vs2.3.5.5/arch/arm/kernel/calls.S
209 --- linux-3.7.1/arch/arm/kernel/calls.S 2012-12-11 03:30:57.000000000 +0000
210 +++ linux-3.7.1-vs2.3.5.5/arch/arm/kernel/calls.S       2012-12-18 15:13:16.000000000 +0000
211 @@ -322,7 +322,7 @@
212  /* 310 */      CALL(sys_request_key)
213                 CALL(sys_keyctl)
214                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */  CALL(sys_ni_syscall)
216 +               CALL(sys_vserver)
217                 CALL(sys_ioprio_set)
218  /* 315 */      CALL(sys_ioprio_get)
219                 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-3.7.1/arch/arm/kernel/process.c linux-3.7.1-vs2.3.5.5/arch/arm/kernel/process.c
221 --- linux-3.7.1/arch/arm/kernel/process.c       2012-12-11 03:30:57.000000000 +0000
222 +++ linux-3.7.1-vs2.3.5.5/arch/arm/kernel/process.c     2012-12-18 15:13:16.000000000 +0000
223 @@ -337,7 +337,8 @@ void __show_regs(struct pt_regs *regs)
224  void show_regs(struct pt_regs * regs)
225  {
226         printk("\n");
227 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
228 +       printk("Pid: %d[#%u], comm: %20s\n",
229 +               task_pid_nr(current), current->xid, current->comm);
230         __show_regs(regs);
231         dump_stack();
232  }
233 diff -NurpP --minimal linux-3.7.1/arch/arm/kernel/traps.c linux-3.7.1-vs2.3.5.5/arch/arm/kernel/traps.c
234 --- linux-3.7.1/arch/arm/kernel/traps.c 2012-12-11 03:30:57.000000000 +0000
235 +++ linux-3.7.1-vs2.3.5.5/arch/arm/kernel/traps.c       2012-12-18 15:13:16.000000000 +0000
236 @@ -249,8 +249,8 @@ static int __die(const char *str, int er
237  
238         print_modules();
239         __show_regs(regs);
240 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
241 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
242 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
243 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
244  
245         if (!user_mode(regs) || in_interrupt()) {
246                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
247 diff -NurpP --minimal linux-3.7.1/arch/cris/Kconfig linux-3.7.1-vs2.3.5.5/arch/cris/Kconfig
248 --- linux-3.7.1/arch/cris/Kconfig       2012-12-11 03:30:57.000000000 +0000
249 +++ linux-3.7.1-vs2.3.5.5/arch/cris/Kconfig     2012-12-18 15:13:16.000000000 +0000
250 @@ -670,6 +670,8 @@ source "drivers/staging/Kconfig"
251  
252  source "arch/cris/Kconfig.debug"
253  
254 +source "kernel/vserver/Kconfig"
255 +
256  source "security/Kconfig"
257  
258  source "crypto/Kconfig"
259 diff -NurpP --minimal linux-3.7.1/arch/h8300/Kconfig linux-3.7.1-vs2.3.5.5/arch/h8300/Kconfig
260 --- linux-3.7.1/arch/h8300/Kconfig      2012-12-11 03:30:57.000000000 +0000
261 +++ linux-3.7.1-vs2.3.5.5/arch/h8300/Kconfig    2012-12-18 15:13:16.000000000 +0000
262 @@ -217,6 +217,8 @@ source "fs/Kconfig"
263  
264  source "arch/h8300/Kconfig.debug"
265  
266 +source "kernel/vserver/Kconfig"
267 +
268  source "security/Kconfig"
269  
270  source "crypto/Kconfig"
271 diff -NurpP --minimal linux-3.7.1/arch/ia64/Kconfig linux-3.7.1-vs2.3.5.5/arch/ia64/Kconfig
272 --- linux-3.7.1/arch/ia64/Kconfig       2012-12-11 03:30:57.000000000 +0000
273 +++ linux-3.7.1-vs2.3.5.5/arch/ia64/Kconfig     2012-12-18 15:13:16.000000000 +0000
274 @@ -644,6 +644,8 @@ source "fs/Kconfig"
275  
276  source "arch/ia64/Kconfig.debug"
277  
278 +source "kernel/vserver/Kconfig"
279 +
280  source "security/Kconfig"
281  
282  source "crypto/Kconfig"
283 diff -NurpP --minimal linux-3.7.1/arch/ia64/kernel/entry.S linux-3.7.1-vs2.3.5.5/arch/ia64/kernel/entry.S
284 --- linux-3.7.1/arch/ia64/kernel/entry.S        2012-12-11 03:30:57.000000000 +0000
285 +++ linux-3.7.1-vs2.3.5.5/arch/ia64/kernel/entry.S      2012-12-18 15:13:16.000000000 +0000
286 @@ -1714,7 +1714,7 @@ sys_call_table:
287         data8 sys_mq_notify
288         data8 sys_mq_getsetattr
289         data8 sys_kexec_load
290 -       data8 sys_ni_syscall                    // reserved for vserver
291 +       data8 sys_vserver
292         data8 sys_waitid                        // 1270
293         data8 sys_add_key
294         data8 sys_request_key
295 diff -NurpP --minimal linux-3.7.1/arch/ia64/kernel/process.c linux-3.7.1-vs2.3.5.5/arch/ia64/kernel/process.c
296 --- linux-3.7.1/arch/ia64/kernel/process.c      2012-12-11 03:30:57.000000000 +0000
297 +++ linux-3.7.1-vs2.3.5.5/arch/ia64/kernel/process.c    2012-12-18 15:13:16.000000000 +0000
298 @@ -111,8 +111,8 @@ show_regs (struct pt_regs *regs)
299         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
300  
301         print_modules();
302 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
303 -                       smp_processor_id(), current->comm);
304 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
305 +                       current->xid, smp_processor_id(), current->comm);
306         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
307                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
308                init_utsname()->release);
309 diff -NurpP --minimal linux-3.7.1/arch/ia64/kernel/ptrace.c linux-3.7.1-vs2.3.5.5/arch/ia64/kernel/ptrace.c
310 --- linux-3.7.1/arch/ia64/kernel/ptrace.c       2012-12-11 03:30:57.000000000 +0000
311 +++ linux-3.7.1-vs2.3.5.5/arch/ia64/kernel/ptrace.c     2012-12-18 15:13:16.000000000 +0000
312 @@ -21,6 +21,7 @@
313  #include <linux/regset.h>
314  #include <linux/elf.h>
315  #include <linux/tracehook.h>
316 +#include <linux/vs_base.h>
317  
318  #include <asm/pgtable.h>
319  #include <asm/processor.h>
320 diff -NurpP --minimal linux-3.7.1/arch/ia64/kernel/traps.c linux-3.7.1-vs2.3.5.5/arch/ia64/kernel/traps.c
321 --- linux-3.7.1/arch/ia64/kernel/traps.c        2012-12-11 03:30:57.000000000 +0000
322 +++ linux-3.7.1-vs2.3.5.5/arch/ia64/kernel/traps.c      2012-12-18 15:13:16.000000000 +0000
323 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
324         put_cpu();
325  
326         if (++die.lock_owner_depth < 3) {
327 -               printk("%s[%d]: %s %ld [%d]\n",
328 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
329 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
330 +                       current->comm, task_pid_nr(current), current->xid,
331 +                       str, err, ++die_counter);
332                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
333                     != NOTIFY_STOP)
334                         show_regs(regs);
335 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
336                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
337                                 last.time = current_jiffies + 5 * HZ;
338                                 printk(KERN_WARNING
339 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
340 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
341 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
342 +                                       current->comm, task_pid_nr(current), current->xid,
343 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
344                         }
345                 }
346         }
347 diff -NurpP --minimal linux-3.7.1/arch/m32r/kernel/traps.c linux-3.7.1-vs2.3.5.5/arch/m32r/kernel/traps.c
348 --- linux-3.7.1/arch/m32r/kernel/traps.c        2012-12-11 03:30:57.000000000 +0000
349 +++ linux-3.7.1-vs2.3.5.5/arch/m32r/kernel/traps.c      2012-12-18 15:13:16.000000000 +0000
350 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
351         } else {
352                 printk("SPI: %08lx\n", sp);
353         }
354 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
355 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
356 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
357 +               current->comm, task_pid_nr(current), current->xid,
358 +               0xffff & i, 4096+(unsigned long)current);
359  
360         /*
361          * When in-kernel, we also print out the stack and code at the
362 diff -NurpP --minimal linux-3.7.1/arch/m68k/Kconfig linux-3.7.1-vs2.3.5.5/arch/m68k/Kconfig
363 --- linux-3.7.1/arch/m68k/Kconfig       2012-12-11 03:30:57.000000000 +0000
364 +++ linux-3.7.1-vs2.3.5.5/arch/m68k/Kconfig     2012-12-18 15:13:16.000000000 +0000
365 @@ -135,6 +135,8 @@ source "fs/Kconfig"
366  
367  source "arch/m68k/Kconfig.debug"
368  
369 +source "kernel/vserver/Kconfig"
370 +
371  source "security/Kconfig"
372  
373  source "crypto/Kconfig"
374 diff -NurpP --minimal linux-3.7.1/arch/mips/Kconfig linux-3.7.1-vs2.3.5.5/arch/mips/Kconfig
375 --- linux-3.7.1/arch/mips/Kconfig       2012-12-11 03:30:57.000000000 +0000
376 +++ linux-3.7.1-vs2.3.5.5/arch/mips/Kconfig     2012-12-18 15:13:16.000000000 +0000
377 @@ -2574,6 +2574,8 @@ source "fs/Kconfig"
378  
379  source "arch/mips/Kconfig.debug"
380  
381 +source "kernel/vserver/Kconfig"
382 +
383  source "security/Kconfig"
384  
385  source "crypto/Kconfig"
386 diff -NurpP --minimal linux-3.7.1/arch/mips/kernel/ptrace.c linux-3.7.1-vs2.3.5.5/arch/mips/kernel/ptrace.c
387 --- linux-3.7.1/arch/mips/kernel/ptrace.c       2012-12-11 03:30:57.000000000 +0000
388 +++ linux-3.7.1-vs2.3.5.5/arch/mips/kernel/ptrace.c     2012-12-18 15:13:16.000000000 +0000
389 @@ -25,6 +25,7 @@
390  #include <linux/security.h>
391  #include <linux/audit.h>
392  #include <linux/seccomp.h>
393 +#include <linux/vs_base.h>
394  
395  #include <asm/byteorder.h>
396  #include <asm/cpu.h>
397 @@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
398         void __user *datavp = (void __user *) data;
399         unsigned long __user *datalp = (void __user *) data;
400  
401 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
402 +               goto out;
403 +
404         switch (request) {
405         /* when I and D space are separate, these will need to be fixed. */
406         case PTRACE_PEEKTEXT: /* read word at location addr. */
407 diff -NurpP --minimal linux-3.7.1/arch/mips/kernel/scall32-o32.S linux-3.7.1-vs2.3.5.5/arch/mips/kernel/scall32-o32.S
408 --- linux-3.7.1/arch/mips/kernel/scall32-o32.S  2012-12-11 03:30:57.000000000 +0000
409 +++ linux-3.7.1-vs2.3.5.5/arch/mips/kernel/scall32-o32.S        2012-12-18 15:13:16.000000000 +0000
410 @@ -512,7 +512,7 @@ einval:     li      v0, -ENOSYS
411         sys     sys_mq_timedreceive     5
412         sys     sys_mq_notify           2       /* 4275 */
413         sys     sys_mq_getsetattr       3
414 -       sys     sys_ni_syscall          0       /* sys_vserver */
415 +       sys     sys_vserver             3
416         sys     sys_waitid              5
417         sys     sys_ni_syscall          0       /* available, was setaltroot */
418         sys     sys_add_key             5       /* 4280 */
419 diff -NurpP --minimal linux-3.7.1/arch/mips/kernel/scall64-64.S linux-3.7.1-vs2.3.5.5/arch/mips/kernel/scall64-64.S
420 --- linux-3.7.1/arch/mips/kernel/scall64-64.S   2012-12-11 03:30:57.000000000 +0000
421 +++ linux-3.7.1-vs2.3.5.5/arch/mips/kernel/scall64-64.S 2012-12-18 15:13:16.000000000 +0000
422 @@ -351,7 +351,7 @@ sys_call_table:
423         PTR     sys_mq_timedreceive
424         PTR     sys_mq_notify
425         PTR     sys_mq_getsetattr               /* 5235 */
426 -       PTR     sys_ni_syscall                  /* sys_vserver */
427 +       PTR     sys_vserver
428         PTR     sys_waitid
429         PTR     sys_ni_syscall                  /* available, was setaltroot */
430         PTR     sys_add_key
431 diff -NurpP --minimal linux-3.7.1/arch/mips/kernel/scall64-n32.S linux-3.7.1-vs2.3.5.5/arch/mips/kernel/scall64-n32.S
432 --- linux-3.7.1/arch/mips/kernel/scall64-n32.S  2012-12-11 03:30:57.000000000 +0000
433 +++ linux-3.7.1-vs2.3.5.5/arch/mips/kernel/scall64-n32.S        2012-12-18 15:13:16.000000000 +0000
434 @@ -350,7 +350,7 @@ EXPORT(sysn32_call_table)
435         PTR     compat_sys_mq_timedreceive
436         PTR     compat_sys_mq_notify
437         PTR     compat_sys_mq_getsetattr
438 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
439 +       PTR     sys32_vserver                   /* 6240 */
440         PTR     compat_sys_waitid
441         PTR     sys_ni_syscall                  /* available, was setaltroot */
442         PTR     sys_add_key
443 diff -NurpP --minimal linux-3.7.1/arch/mips/kernel/scall64-o32.S linux-3.7.1-vs2.3.5.5/arch/mips/kernel/scall64-o32.S
444 --- linux-3.7.1/arch/mips/kernel/scall64-o32.S  2012-12-11 03:30:57.000000000 +0000
445 +++ linux-3.7.1-vs2.3.5.5/arch/mips/kernel/scall64-o32.S        2012-12-18 15:13:16.000000000 +0000
446 @@ -469,7 +469,7 @@ sys_call_table:
447         PTR     compat_sys_mq_timedreceive
448         PTR     compat_sys_mq_notify            /* 4275 */
449         PTR     compat_sys_mq_getsetattr
450 -       PTR     sys_ni_syscall                  /* sys_vserver */
451 +       PTR     sys32_vserver
452         PTR     sys_32_waitid
453         PTR     sys_ni_syscall                  /* available, was setaltroot */
454         PTR     sys_add_key                     /* 4280 */
455 diff -NurpP --minimal linux-3.7.1/arch/mips/kernel/traps.c linux-3.7.1-vs2.3.5.5/arch/mips/kernel/traps.c
456 --- linux-3.7.1/arch/mips/kernel/traps.c        2012-12-11 03:30:57.000000000 +0000
457 +++ linux-3.7.1-vs2.3.5.5/arch/mips/kernel/traps.c      2012-12-18 15:13:16.000000000 +0000
458 @@ -347,9 +347,10 @@ void show_registers(struct pt_regs *regs
459  
460         __show_regs(regs);
461         print_modules();
462 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
463 -              current->comm, current->pid, current_thread_info(), current,
464 -             field, current_thread_info()->tp_value);
465 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
466 +               current->comm, task_pid_nr(current), current->xid,
467 +               current_thread_info(), current,
468 +               field, current_thread_info()->tp_value);
469         if (cpu_has_userlocal) {
470                 unsigned long tls;
471  
472 diff -NurpP --minimal linux-3.7.1/arch/parisc/Kconfig linux-3.7.1-vs2.3.5.5/arch/parisc/Kconfig
473 --- linux-3.7.1/arch/parisc/Kconfig     2012-12-11 03:30:57.000000000 +0000
474 +++ linux-3.7.1-vs2.3.5.5/arch/parisc/Kconfig   2012-12-18 15:13:16.000000000 +0000
475 @@ -284,6 +284,8 @@ source "fs/Kconfig"
476  
477  source "arch/parisc/Kconfig.debug"
478  
479 +source "kernel/vserver/Kconfig"
480 +
481  source "security/Kconfig"
482  
483  source "crypto/Kconfig"
484 diff -NurpP --minimal linux-3.7.1/arch/parisc/kernel/syscall_table.S linux-3.7.1-vs2.3.5.5/arch/parisc/kernel/syscall_table.S
485 --- linux-3.7.1/arch/parisc/kernel/syscall_table.S      2012-12-11 03:30:57.000000000 +0000
486 +++ linux-3.7.1-vs2.3.5.5/arch/parisc/kernel/syscall_table.S    2012-12-18 15:13:16.000000000 +0000
487 @@ -361,7 +361,7 @@
488         ENTRY_COMP(mbind)               /* 260 */
489         ENTRY_COMP(get_mempolicy)
490         ENTRY_COMP(set_mempolicy)
491 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
492 +       ENTRY_DIFF(vserver)
493         ENTRY_SAME(add_key)
494         ENTRY_SAME(request_key)         /* 265 */
495         ENTRY_SAME(keyctl)
496 diff -NurpP --minimal linux-3.7.1/arch/parisc/kernel/traps.c linux-3.7.1-vs2.3.5.5/arch/parisc/kernel/traps.c
497 --- linux-3.7.1/arch/parisc/kernel/traps.c      2012-12-11 03:30:57.000000000 +0000
498 +++ linux-3.7.1-vs2.3.5.5/arch/parisc/kernel/traps.c    2012-12-18 15:13:16.000000000 +0000
499 @@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
500                 if (err == 0)
501                         return; /* STFU */
502  
503 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
504 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
505 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
506 +                       current->comm, task_pid_nr(current), current->xid,
507 +                       str, err, regs->iaoq[0]);
508  #ifdef PRINT_USER_FAULTS
509                 /* XXX for debugging only */
510                 show_regs(regs);
511 @@ -269,8 +270,8 @@ void die_if_kernel(char *str, struct pt_
512                 pdc_console_restart();
513         
514         if (err)
515 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
516 -                       current->comm, task_pid_nr(current), str, err);
517 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
518 +                       current->comm, task_pid_nr(current), current->xid, str, err);
519  
520         /* Wot's wrong wif bein' racy? */
521         if (current->thread.flags & PARISC_KERNEL_DEATH) {
522 diff -NurpP --minimal linux-3.7.1/arch/parisc/mm/fault.c linux-3.7.1-vs2.3.5.5/arch/parisc/mm/fault.c
523 --- linux-3.7.1/arch/parisc/mm/fault.c  2012-12-11 03:30:57.000000000 +0000
524 +++ linux-3.7.1-vs2.3.5.5/arch/parisc/mm/fault.c        2012-12-18 15:13:16.000000000 +0000
525 @@ -237,8 +237,9 @@ bad_area:
526  
527  #ifdef PRINT_USER_FAULTS
528                 printk(KERN_DEBUG "\n");
529 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
530 -                   task_pid_nr(tsk), tsk->comm, code, address);
531 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
532 +                   "command='%s' type=%lu address=0x%08lx\n",
533 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
534                 if (vma) {
535                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
536                                         vma->vm_start, vma->vm_end);
537 diff -NurpP --minimal linux-3.7.1/arch/powerpc/Kconfig linux-3.7.1-vs2.3.5.5/arch/powerpc/Kconfig
538 --- linux-3.7.1/arch/powerpc/Kconfig    2012-12-11 03:30:57.000000000 +0000
539 +++ linux-3.7.1-vs2.3.5.5/arch/powerpc/Kconfig  2012-12-18 15:13:16.000000000 +0000
540 @@ -1014,6 +1014,8 @@ source "lib/Kconfig"
541  
542  source "arch/powerpc/Kconfig.debug"
543  
544 +source "kernel/vserver/Kconfig"
545 +
546  source "security/Kconfig"
547  
548  config KEYS_COMPAT
549 diff -NurpP --minimal linux-3.7.1/arch/powerpc/include/uapi/asm/unistd.h linux-3.7.1-vs2.3.5.5/arch/powerpc/include/uapi/asm/unistd.h
550 --- linux-3.7.1/arch/powerpc/include/uapi/asm/unistd.h  2012-12-11 03:30:57.000000000 +0000
551 +++ linux-3.7.1-vs2.3.5.5/arch/powerpc/include/uapi/asm/unistd.h        2012-12-18 15:13:16.000000000 +0000
552 @@ -275,7 +275,7 @@
553  #endif
554  #define __NR_rtas              255
555  #define __NR_sys_debug_setcontext 256
556 -/* Number 257 is reserved for vserver */
557 +#define __NR_vserver           257
558  #define __NR_migrate_pages     258
559  #define __NR_mbind             259
560  #define __NR_get_mempolicy     260
561 diff -NurpP --minimal linux-3.7.1/arch/powerpc/kernel/process.c linux-3.7.1-vs2.3.5.5/arch/powerpc/kernel/process.c
562 --- linux-3.7.1/arch/powerpc/kernel/process.c   2012-12-11 03:30:57.000000000 +0000
563 +++ linux-3.7.1-vs2.3.5.5/arch/powerpc/kernel/process.c 2012-12-18 15:13:16.000000000 +0000
564 @@ -660,8 +660,9 @@ void show_regs(struct pt_regs * regs)
565  #else
566                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
567  #endif
568 -       printk("TASK = %p[%d] '%s' THREAD: %p",
569 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
570 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
571 +              current, task_pid_nr(current), current->xid,
572 +              current->comm, task_thread_info(current));
573  
574  #ifdef CONFIG_SMP
575         printk(" CPU: %d", raw_smp_processor_id());
576 diff -NurpP --minimal linux-3.7.1/arch/powerpc/kernel/traps.c linux-3.7.1-vs2.3.5.5/arch/powerpc/kernel/traps.c
577 --- linux-3.7.1/arch/powerpc/kernel/traps.c     2012-12-11 03:30:57.000000000 +0000
578 +++ linux-3.7.1-vs2.3.5.5/arch/powerpc/kernel/traps.c   2012-12-18 15:13:16.000000000 +0000
579 @@ -1120,8 +1120,9 @@ void nonrecoverable_exception(struct pt_
580  
581  void trace_syscall(struct pt_regs *regs)
582  {
583 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
584 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
585 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
586 +              current, task_pid_nr(current), current->xid,
587 +              regs->nip, regs->link, regs->gpr[0],
588                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
589  }
590  
591 diff -NurpP --minimal linux-3.7.1/arch/s390/Kconfig linux-3.7.1-vs2.3.5.5/arch/s390/Kconfig
592 --- linux-3.7.1/arch/s390/Kconfig       2012-12-11 03:30:57.000000000 +0000
593 +++ linux-3.7.1-vs2.3.5.5/arch/s390/Kconfig     2012-12-18 15:13:16.000000000 +0000
594 @@ -530,6 +530,8 @@ source "fs/Kconfig"
595  
596  source "arch/s390/Kconfig.debug"
597  
598 +source "kernel/vserver/Kconfig"
599 +
600  source "security/Kconfig"
601  
602  source "crypto/Kconfig"
603 diff -NurpP --minimal linux-3.7.1/arch/s390/include/asm/tlb.h linux-3.7.1-vs2.3.5.5/arch/s390/include/asm/tlb.h
604 --- linux-3.7.1/arch/s390/include/asm/tlb.h     2012-12-11 03:30:57.000000000 +0000
605 +++ linux-3.7.1-vs2.3.5.5/arch/s390/include/asm/tlb.h   2012-12-18 15:13:16.000000000 +0000
606 @@ -24,6 +24,7 @@
607  #include <linux/mm.h>
608  #include <linux/pagemap.h>
609  #include <linux/swap.h>
610 +
611  #include <asm/processor.h>
612  #include <asm/pgalloc.h>
613  #include <asm/tlbflush.h>
614 diff -NurpP --minimal linux-3.7.1/arch/s390/include/uapi/asm/unistd.h linux-3.7.1-vs2.3.5.5/arch/s390/include/uapi/asm/unistd.h
615 --- linux-3.7.1/arch/s390/include/uapi/asm/unistd.h     2012-12-11 03:30:57.000000000 +0000
616 +++ linux-3.7.1-vs2.3.5.5/arch/s390/include/uapi/asm/unistd.h   2012-12-18 15:13:16.000000000 +0000
617 @@ -200,7 +200,7 @@
618  #define __NR_clock_gettime     (__NR_timer_create+6)
619  #define __NR_clock_getres      (__NR_timer_create+7)
620  #define __NR_clock_nanosleep   (__NR_timer_create+8)
621 -/* Number 263 is reserved for vserver */
622 +#define __NR_vserver           263
623  #define __NR_statfs64          265
624  #define __NR_fstatfs64         266
625  #define __NR_remap_file_pages  267
626 diff -NurpP --minimal linux-3.7.1/arch/s390/kernel/ptrace.c linux-3.7.1-vs2.3.5.5/arch/s390/kernel/ptrace.c
627 --- linux-3.7.1/arch/s390/kernel/ptrace.c       2012-12-11 03:30:57.000000000 +0000
628 +++ linux-3.7.1-vs2.3.5.5/arch/s390/kernel/ptrace.c     2012-12-18 15:13:16.000000000 +0000
629 @@ -21,6 +21,7 @@
630  #include <linux/tracehook.h>
631  #include <linux/seccomp.h>
632  #include <linux/compat.h>
633 +#include <linux/vs_base.h>
634  #include <trace/syscall.h>
635  #include <asm/segment.h>
636  #include <asm/page.h>
637 diff -NurpP --minimal linux-3.7.1/arch/s390/kernel/syscalls.S linux-3.7.1-vs2.3.5.5/arch/s390/kernel/syscalls.S
638 --- linux-3.7.1/arch/s390/kernel/syscalls.S     2012-12-11 03:30:57.000000000 +0000
639 +++ linux-3.7.1-vs2.3.5.5/arch/s390/kernel/syscalls.S   2012-12-18 15:13:16.000000000 +0000
640 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
641  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
642  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
643  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
644 -NI_SYSCALL                                                     /* reserved for vserver */
645 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
646  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
647  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
648  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
649 diff -NurpP --minimal linux-3.7.1/arch/sh/Kconfig linux-3.7.1-vs2.3.5.5/arch/sh/Kconfig
650 --- linux-3.7.1/arch/sh/Kconfig 2012-12-11 03:30:57.000000000 +0000
651 +++ linux-3.7.1-vs2.3.5.5/arch/sh/Kconfig       2012-12-18 15:13:16.000000000 +0000
652 @@ -945,6 +945,8 @@ source "fs/Kconfig"
653  
654  source "arch/sh/Kconfig.debug"
655  
656 +source "kernel/vserver/Kconfig"
657 +
658  source "security/Kconfig"
659  
660  source "crypto/Kconfig"
661 diff -NurpP --minimal linux-3.7.1/arch/sh/kernel/irq.c linux-3.7.1-vs2.3.5.5/arch/sh/kernel/irq.c
662 --- linux-3.7.1/arch/sh/kernel/irq.c    2012-12-11 03:30:57.000000000 +0000
663 +++ linux-3.7.1-vs2.3.5.5/arch/sh/kernel/irq.c  2012-12-18 15:13:16.000000000 +0000
664 @@ -14,6 +14,7 @@
665  #include <linux/ftrace.h>
666  #include <linux/delay.h>
667  #include <linux/ratelimit.h>
668 +// #include <linux/vs_context.h>
669  #include <asm/processor.h>
670  #include <asm/machvec.h>
671  #include <asm/uaccess.h>
672 diff -NurpP --minimal linux-3.7.1/arch/sparc/Kconfig linux-3.7.1-vs2.3.5.5/arch/sparc/Kconfig
673 --- linux-3.7.1/arch/sparc/Kconfig      2012-12-11 03:30:57.000000000 +0000
674 +++ linux-3.7.1-vs2.3.5.5/arch/sparc/Kconfig    2012-12-18 15:13:16.000000000 +0000
675 @@ -564,6 +564,8 @@ source "fs/Kconfig"
676  
677  source "arch/sparc/Kconfig.debug"
678  
679 +source "kernel/vserver/Kconfig"
680 +
681  source "security/Kconfig"
682  
683  source "crypto/Kconfig"
684 diff -NurpP --minimal linux-3.7.1/arch/sparc/include/uapi/asm/unistd.h linux-3.7.1-vs2.3.5.5/arch/sparc/include/uapi/asm/unistd.h
685 --- linux-3.7.1/arch/sparc/include/uapi/asm/unistd.h    2012-12-11 03:30:57.000000000 +0000
686 +++ linux-3.7.1-vs2.3.5.5/arch/sparc/include/uapi/asm/unistd.h  2012-12-18 15:13:16.000000000 +0000
687 @@ -332,7 +332,7 @@
688  #define __NR_timer_getoverrun  264
689  #define __NR_timer_delete      265
690  #define __NR_timer_create      266
691 -/* #define __NR_vserver                267 Reserved for VSERVER */
692 +#define __NR_vserver           267
693  #define __NR_io_setup          268
694  #define __NR_io_destroy                269
695  #define __NR_io_submit         270
696 diff -NurpP --minimal linux-3.7.1/arch/sparc/kernel/systbls_32.S linux-3.7.1-vs2.3.5.5/arch/sparc/kernel/systbls_32.S
697 --- linux-3.7.1/arch/sparc/kernel/systbls_32.S  2012-12-11 03:30:57.000000000 +0000
698 +++ linux-3.7.1-vs2.3.5.5/arch/sparc/kernel/systbls_32.S        2012-12-18 15:13:16.000000000 +0000
699 @@ -70,7 +70,7 @@ sys_call_table:
700  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
701  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
702  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
703 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
704 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
705  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
706  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
707  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
708 diff -NurpP --minimal linux-3.7.1/arch/sparc/kernel/systbls_64.S linux-3.7.1-vs2.3.5.5/arch/sparc/kernel/systbls_64.S
709 --- linux-3.7.1/arch/sparc/kernel/systbls_64.S  2012-12-11 03:30:57.000000000 +0000
710 +++ linux-3.7.1-vs2.3.5.5/arch/sparc/kernel/systbls_64.S        2012-12-18 15:13:16.000000000 +0000
711 @@ -71,7 +71,7 @@ sys_call_table32:
712  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys_nis_syscall
713         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
714  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
715 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
716 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
717  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
718         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
719  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
720 @@ -149,7 +149,7 @@ sys_call_table:
721  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
722         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
723  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
724 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
725 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
726  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
727         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
728  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
729 diff -NurpP --minimal linux-3.7.1/arch/um/Kconfig.rest linux-3.7.1-vs2.3.5.5/arch/um/Kconfig.rest
730 --- linux-3.7.1/arch/um/Kconfig.rest    2012-12-11 03:30:57.000000000 +0000
731 +++ linux-3.7.1-vs2.3.5.5/arch/um/Kconfig.rest  2012-12-18 15:13:16.000000000 +0000
732 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
733  
734  source "fs/Kconfig"
735  
736 +source "kernel/vserver/Kconfig"
737 +
738  source "security/Kconfig"
739  
740  source "crypto/Kconfig"
741 diff -NurpP --minimal linux-3.7.1/arch/um/include/shared/kern_constants.h linux-3.7.1-vs2.3.5.5/arch/um/include/shared/kern_constants.h
742 --- linux-3.7.1/arch/um/include/shared/kern_constants.h 1970-01-01 00:00:00.000000000 +0000
743 +++ linux-3.7.1-vs2.3.5.5/arch/um/include/shared/kern_constants.h       2012-12-18 15:13:16.000000000 +0000
744 @@ -0,0 +1 @@
745 +#include "../../../../include/generated/asm-offsets.h"
746 diff -NurpP --minimal linux-3.7.1/arch/um/include/shared/user_constants.h linux-3.7.1-vs2.3.5.5/arch/um/include/shared/user_constants.h
747 --- linux-3.7.1/arch/um/include/shared/user_constants.h 1970-01-01 00:00:00.000000000 +0000
748 +++ linux-3.7.1-vs2.3.5.5/arch/um/include/shared/user_constants.h       2012-12-18 15:13:16.000000000 +0000
749 @@ -0,0 +1,40 @@
750 +/*
751 + * DO NOT MODIFY.
752 + *
753 + * This file was generated by arch/um/Makefile
754 + *
755 + */
756 +
757 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
758 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
759 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
760 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
761 +#define HOST_RBX 5 /* RBX      # */
762 +#define HOST_RCX 11 /* RCX     # */
763 +#define HOST_RDI 14 /* RDI     # */
764 +#define HOST_RSI 13 /* RSI     # */
765 +#define HOST_RDX 12 /* RDX     # */
766 +#define HOST_RBP 4 /* RBP      # */
767 +#define HOST_RAX 10 /* RAX     # */
768 +#define HOST_R8 9 /* R8        # */
769 +#define HOST_R9 8 /* R9        # */
770 +#define HOST_R10 7 /* R10      # */
771 +#define HOST_R11 6 /* R11      # */
772 +#define HOST_R12 3 /* R12      # */
773 +#define HOST_R13 2 /* R13      # */
774 +#define HOST_R14 1 /* R14      # */
775 +#define HOST_R15 0 /* R15      # */
776 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
777 +#define HOST_CS 17 /* CS       # */
778 +#define HOST_SS 20 /* SS       # */
779 +#define HOST_EFLAGS 18 /* EFLAGS       # */
780 +#define HOST_IP 16 /* RIP      # */
781 +#define HOST_SP 19 /* RSP      # */
782 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
783 +#define UM_POLLIN 1 /* POLLIN  # */
784 +#define UM_POLLPRI 2 /* POLLPRI        # */
785 +#define UM_POLLOUT 4 /* POLLOUT        # */
786 +#define UM_PROT_READ 1 /* PROT_READ    # */
787 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
788 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
789 +
790 diff -NurpP --minimal linux-3.7.1/arch/x86/Kconfig linux-3.7.1-vs2.3.5.5/arch/x86/Kconfig
791 --- linux-3.7.1/arch/x86/Kconfig        2012-12-11 03:30:57.000000000 +0000
792 +++ linux-3.7.1-vs2.3.5.5/arch/x86/Kconfig      2012-12-18 15:13:16.000000000 +0000
793 @@ -2248,6 +2248,8 @@ source "fs/Kconfig"
794  
795  source "arch/x86/Kconfig.debug"
796  
797 +source "kernel/vserver/Kconfig"
798 +
799  source "security/Kconfig"
800  
801  source "crypto/Kconfig"
802 diff -NurpP --minimal linux-3.7.1/arch/x86/syscalls/syscall_32.tbl linux-3.7.1-vs2.3.5.5/arch/x86/syscalls/syscall_32.tbl
803 --- linux-3.7.1/arch/x86/syscalls/syscall_32.tbl        2012-12-11 03:30:57.000000000 +0000
804 +++ linux-3.7.1-vs2.3.5.5/arch/x86/syscalls/syscall_32.tbl      2012-12-18 15:13:16.000000000 +0000
805 @@ -279,7 +279,7 @@
806  270    i386    tgkill                  sys_tgkill
807  271    i386    utimes                  sys_utimes                      compat_sys_utimes
808  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
809 -273    i386    vserver
810 +273    i386    vserver                 sys_vserver                     sys32_vserver
811  274    i386    mbind                   sys_mbind
812  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
813  276    i386    set_mempolicy           sys_set_mempolicy
814 diff -NurpP --minimal linux-3.7.1/arch/x86/syscalls/syscall_64.tbl linux-3.7.1-vs2.3.5.5/arch/x86/syscalls/syscall_64.tbl
815 --- linux-3.7.1/arch/x86/syscalls/syscall_64.tbl        2012-12-11 03:30:57.000000000 +0000
816 +++ linux-3.7.1-vs2.3.5.5/arch/x86/syscalls/syscall_64.tbl      2012-12-18 15:13:16.000000000 +0000
817 @@ -242,7 +242,7 @@
818  233    common  epoll_ctl               sys_epoll_ctl
819  234    common  tgkill                  sys_tgkill
820  235    common  utimes                  sys_utimes
821 -236    64      vserver
822 +236    64      vserver                 sys_vserver
823  237    common  mbind                   sys_mbind
824  238    common  set_mempolicy           sys_set_mempolicy
825  239    common  get_mempolicy           sys_get_mempolicy
826 diff -NurpP --minimal linux-3.7.1/drivers/block/Kconfig linux-3.7.1-vs2.3.5.5/drivers/block/Kconfig
827 --- linux-3.7.1/drivers/block/Kconfig   2012-12-11 03:30:57.000000000 +0000
828 +++ linux-3.7.1-vs2.3.5.5/drivers/block/Kconfig 2012-12-18 15:13:16.000000000 +0000
829 @@ -291,6 +291,13 @@ config BLK_DEV_CRYPTOLOOP
830  
831  source "drivers/block/drbd/Kconfig"
832  
833 +config BLK_DEV_VROOT
834 +       tristate "Virtual Root device support"
835 +       depends on QUOTACTL
836 +       ---help---
837 +         Saying Y here will allow you to use quota/fs ioctls on a shared
838 +         partition within a virtual server without compromising security.
839 +
840  config BLK_DEV_NBD
841         tristate "Network block device support"
842         depends on NET
843 diff -NurpP --minimal linux-3.7.1/drivers/block/Makefile linux-3.7.1-vs2.3.5.5/drivers/block/Makefile
844 --- linux-3.7.1/drivers/block/Makefile  2012-12-11 03:30:57.000000000 +0000
845 +++ linux-3.7.1-vs2.3.5.5/drivers/block/Makefile        2012-12-18 15:13:16.000000000 +0000
846 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
847  obj-$(CONFIG_VIODASD)          += viodasd.o
848  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
849  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
850 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
851  
852  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
853  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
854 diff -NurpP --minimal linux-3.7.1/drivers/block/loop.c linux-3.7.1-vs2.3.5.5/drivers/block/loop.c
855 --- linux-3.7.1/drivers/block/loop.c    2012-12-11 03:30:57.000000000 +0000
856 +++ linux-3.7.1-vs2.3.5.5/drivers/block/loop.c  2012-12-18 15:13:16.000000000 +0000
857 @@ -76,6 +76,7 @@
858  #include <linux/sysfs.h>
859  #include <linux/miscdevice.h>
860  #include <linux/falloc.h>
861 +#include <linux/vs_context.h>
862  
863  #include <asm/uaccess.h>
864  
865 @@ -869,6 +870,7 @@ static int loop_set_fd(struct loop_devic
866         lo->lo_blocksize = lo_blocksize;
867         lo->lo_device = bdev;
868         lo->lo_flags = lo_flags;
869 +       lo->lo_xid = vx_current_xid();
870         lo->lo_backing_file = file;
871         lo->transfer = transfer_none;
872         lo->ioctl = NULL;
873 @@ -1014,6 +1016,7 @@ static int loop_clr_fd(struct loop_devic
874         lo->lo_sizelimit = 0;
875         lo->lo_encrypt_key_size = 0;
876         lo->lo_thread = NULL;
877 +       lo->lo_xid = 0;
878         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
879         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
880         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
881 @@ -1055,7 +1058,7 @@ loop_set_status(struct loop_device *lo,
882  
883         if (lo->lo_encrypt_key_size &&
884             !uid_eq(lo->lo_key_owner, uid) &&
885 -           !capable(CAP_SYS_ADMIN))
886 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
887                 return -EPERM;
888         if (lo->lo_state != Lo_bound)
889                 return -ENXIO;
890 @@ -1145,7 +1148,8 @@ loop_get_status(struct loop_device *lo,
891         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
892         info->lo_encrypt_type =
893                 lo->lo_encryption ? lo->lo_encryption->number : 0;
894 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
895 +       if (lo->lo_encrypt_key_size &&
896 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
897                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
898                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
899                        lo->lo_encrypt_key_size);
900 @@ -1505,6 +1509,11 @@ static int lo_open(struct block_device *
901                 goto out;
902         }
903  
904 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
905 +               err = -EACCES;
906 +               goto out;
907 +       }
908 +
909         mutex_lock(&lo->lo_ctl_mutex);
910         lo->lo_refcnt++;
911         mutex_unlock(&lo->lo_ctl_mutex);
912 diff -NurpP --minimal linux-3.7.1/drivers/block/vroot.c linux-3.7.1-vs2.3.5.5/drivers/block/vroot.c
913 --- linux-3.7.1/drivers/block/vroot.c   1970-01-01 00:00:00.000000000 +0000
914 +++ linux-3.7.1-vs2.3.5.5/drivers/block/vroot.c 2012-12-18 15:13:16.000000000 +0000
915 @@ -0,0 +1,291 @@
916 +/*
917 + *  linux/drivers/block/vroot.c
918 + *
919 + *  written by Herbert Pötzl, 9/11/2002
920 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
921 + *
922 + *  based on the loop.c code by Theodore Ts'o.
923 + *
924 + * Copyright (C) 2002-2007 by Herbert Pötzl.
925 + * Redistribution of this file is permitted under the
926 + * GNU General Public License.
927 + *
928 + */
929 +
930 +#include <linux/module.h>
931 +#include <linux/moduleparam.h>
932 +#include <linux/file.h>
933 +#include <linux/major.h>
934 +#include <linux/blkdev.h>
935 +#include <linux/slab.h>
936 +
937 +#include <linux/vroot.h>
938 +#include <linux/vs_context.h>
939 +
940 +
941 +static int max_vroot = 8;
942 +
943 +static struct vroot_device *vroot_dev;
944 +static struct gendisk **disks;
945 +
946 +
947 +static int vroot_set_dev(
948 +       struct vroot_device *vr,
949 +       struct block_device *bdev,
950 +       unsigned int arg)
951 +{
952 +       struct block_device *real_bdev;
953 +       struct file *file;
954 +       struct inode *inode;
955 +       int error;
956 +
957 +       error = -EBUSY;
958 +       if (vr->vr_state != Vr_unbound)
959 +               goto out;
960 +
961 +       error = -EBADF;
962 +       file = fget(arg);
963 +       if (!file)
964 +               goto out;
965 +
966 +       error = -EINVAL;
967 +       inode = file->f_dentry->d_inode;
968 +
969 +
970 +       if (S_ISBLK(inode->i_mode)) {
971 +               real_bdev = inode->i_bdev;
972 +               vr->vr_device = real_bdev;
973 +               __iget(real_bdev->bd_inode);
974 +       } else
975 +               goto out_fput;
976 +
977 +       vxdprintk(VXD_CBIT(misc, 0),
978 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
979 +               vr->vr_number, VXD_DEV(real_bdev));
980 +
981 +       vr->vr_state = Vr_bound;
982 +       error = 0;
983 +
984 + out_fput:
985 +       fput(file);
986 + out:
987 +       return error;
988 +}
989 +
990 +static int vroot_clr_dev(
991 +       struct vroot_device *vr,
992 +       struct block_device *bdev)
993 +{
994 +       struct block_device *real_bdev;
995 +
996 +       if (vr->vr_state != Vr_bound)
997 +               return -ENXIO;
998 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
999 +               return -EBUSY;
1000 +
1001 +       real_bdev = vr->vr_device;
1002 +
1003 +       vxdprintk(VXD_CBIT(misc, 0),
1004 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1005 +               vr->vr_number, VXD_DEV(real_bdev));
1006 +
1007 +       bdput(real_bdev);
1008 +       vr->vr_state = Vr_unbound;
1009 +       vr->vr_device = NULL;
1010 +       return 0;
1011 +}
1012 +
1013 +
1014 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1015 +       unsigned int cmd, unsigned long arg)
1016 +{
1017 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1018 +       int err;
1019 +
1020 +       down(&vr->vr_ctl_mutex);
1021 +       switch (cmd) {
1022 +       case VROOT_SET_DEV:
1023 +               err = vroot_set_dev(vr, bdev, arg);
1024 +               break;
1025 +       case VROOT_CLR_DEV:
1026 +               err = vroot_clr_dev(vr, bdev);
1027 +               break;
1028 +       default:
1029 +               err = -EINVAL;
1030 +               break;
1031 +       }
1032 +       up(&vr->vr_ctl_mutex);
1033 +       return err;
1034 +}
1035 +
1036 +static int vr_open(struct block_device *bdev, fmode_t mode)
1037 +{
1038 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1039 +
1040 +       down(&vr->vr_ctl_mutex);
1041 +       vr->vr_refcnt++;
1042 +       up(&vr->vr_ctl_mutex);
1043 +       return 0;
1044 +}
1045 +
1046 +static int vr_release(struct gendisk *disk, fmode_t mode)
1047 +{
1048 +       struct vroot_device *vr = disk->private_data;
1049 +
1050 +       down(&vr->vr_ctl_mutex);
1051 +       --vr->vr_refcnt;
1052 +       up(&vr->vr_ctl_mutex);
1053 +       return 0;
1054 +}
1055 +
1056 +static struct block_device_operations vr_fops = {
1057 +       .owner =        THIS_MODULE,
1058 +       .open =         vr_open,
1059 +       .release =      vr_release,
1060 +       .ioctl =        vr_ioctl,
1061 +};
1062 +
1063 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1064 +{
1065 +       printk("vroot_make_request %p, %p\n", q, bio);
1066 +       bio_io_error(bio);
1067 +}
1068 +
1069 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1070 +{
1071 +       struct inode *inode = bdev->bd_inode;
1072 +       struct vroot_device *vr;
1073 +       struct block_device *real_bdev;
1074 +       int minor = iminor(inode);
1075 +
1076 +       vr = &vroot_dev[minor];
1077 +       real_bdev = vr->vr_device;
1078 +
1079 +       vxdprintk(VXD_CBIT(misc, 0),
1080 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1081 +               vr->vr_number, VXD_DEV(real_bdev));
1082 +
1083 +       if (vr->vr_state != Vr_bound)
1084 +               return ERR_PTR(-ENXIO);
1085 +
1086 +       __iget(real_bdev->bd_inode);
1087 +       return real_bdev;
1088 +}
1089 +
1090 +
1091 +
1092 +/*
1093 + * And now the modules code and kernel interface.
1094 + */
1095 +
1096 +module_param(max_vroot, int, 0);
1097 +
1098 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1099 +MODULE_LICENSE("GPL");
1100 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1101 +
1102 +MODULE_AUTHOR ("Herbert Pötzl");
1103 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1104 +
1105 +
1106 +int __init vroot_init(void)
1107 +{
1108 +       int err, i;
1109 +
1110 +       if (max_vroot < 1 || max_vroot > 256) {
1111 +               max_vroot = MAX_VROOT_DEFAULT;
1112 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1113 +                       "(must be between 1 and 256), "
1114 +                       "using default (%d)\n", max_vroot);
1115 +       }
1116 +
1117 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1118 +               return -EIO;
1119 +
1120 +       err = -ENOMEM;
1121 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1122 +       if (!vroot_dev)
1123 +               goto out_mem1;
1124 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1125 +
1126 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1127 +       if (!disks)
1128 +               goto out_mem2;
1129 +
1130 +       for (i = 0; i < max_vroot; i++) {
1131 +               disks[i] = alloc_disk(1);
1132 +               if (!disks[i])
1133 +                       goto out_mem3;
1134 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1135 +               if (!disks[i]->queue)
1136 +                       goto out_mem3;
1137 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1138 +       }
1139 +
1140 +       for (i = 0; i < max_vroot; i++) {
1141 +               struct vroot_device *vr = &vroot_dev[i];
1142 +               struct gendisk *disk = disks[i];
1143 +
1144 +               memset(vr, 0, sizeof(*vr));
1145 +               sema_init(&vr->vr_ctl_mutex, 1);
1146 +               vr->vr_number = i;
1147 +               disk->major = VROOT_MAJOR;
1148 +               disk->first_minor = i;
1149 +               disk->fops = &vr_fops;
1150 +               sprintf(disk->disk_name, "vroot%d", i);
1151 +               disk->private_data = vr;
1152 +       }
1153 +
1154 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1155 +       if (err)
1156 +               goto out_mem3;
1157 +
1158 +       for (i = 0; i < max_vroot; i++)
1159 +               add_disk(disks[i]);
1160 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1161 +       return 0;
1162 +
1163 +out_mem3:
1164 +       while (i--)
1165 +               put_disk(disks[i]);
1166 +       kfree(disks);
1167 +out_mem2:
1168 +       kfree(vroot_dev);
1169 +out_mem1:
1170 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1171 +       printk(KERN_ERR "vroot: ran out of memory\n");
1172 +       return err;
1173 +}
1174 +
1175 +void vroot_exit(void)
1176 +{
1177 +       int i;
1178 +
1179 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1180 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1181 +
1182 +       for (i = 0; i < max_vroot; i++) {
1183 +               del_gendisk(disks[i]);
1184 +               put_disk(disks[i]);
1185 +       }
1186 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1187 +
1188 +       kfree(disks);
1189 +       kfree(vroot_dev);
1190 +}
1191 +
1192 +module_init(vroot_init);
1193 +module_exit(vroot_exit);
1194 +
1195 +#ifndef MODULE
1196 +
1197 +static int __init max_vroot_setup(char *str)
1198 +{
1199 +       max_vroot = simple_strtol(str, NULL, 0);
1200 +       return 1;
1201 +}
1202 +
1203 +__setup("max_vroot=", max_vroot_setup);
1204 +
1205 +#endif
1206 +
1207 diff -NurpP --minimal linux-3.7.1/drivers/infiniband/Kconfig linux-3.7.1-vs2.3.5.5/drivers/infiniband/Kconfig
1208 --- linux-3.7.1/drivers/infiniband/Kconfig      2012-12-11 03:30:57.000000000 +0000
1209 +++ linux-3.7.1-vs2.3.5.5/drivers/infiniband/Kconfig    2012-12-18 15:13:16.000000000 +0000
1210 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1211  config INFINIBAND_ADDR_TRANS
1212         bool
1213         depends on INET
1214 -       depends on !(INFINIBAND = y && IPV6 = m)
1215 +       depends on !(INFINIBAND = y && IPV6 = y)
1216         default y
1217  
1218  source "drivers/infiniband/hw/mthca/Kconfig"
1219 diff -NurpP --minimal linux-3.7.1/drivers/infiniband/core/addr.c linux-3.7.1-vs2.3.5.5/drivers/infiniband/core/addr.c
1220 --- linux-3.7.1/drivers/infiniband/core/addr.c  2012-12-11 03:30:57.000000000 +0000
1221 +++ linux-3.7.1-vs2.3.5.5/drivers/infiniband/core/addr.c        2012-12-18 15:13:16.000000000 +0000
1222 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1223  
1224         if (ipv6_addr_any(&fl6.saddr)) {
1225                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1226 -                                        &fl6.daddr, 0, &fl6.saddr);
1227 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1228                 if (ret)
1229                         goto put;
1230  
1231 diff -NurpP --minimal linux-3.7.1/drivers/md/dm-ioctl.c linux-3.7.1-vs2.3.5.5/drivers/md/dm-ioctl.c
1232 --- linux-3.7.1/drivers/md/dm-ioctl.c   2012-12-11 03:30:57.000000000 +0000
1233 +++ linux-3.7.1-vs2.3.5.5/drivers/md/dm-ioctl.c 2012-12-18 15:13:16.000000000 +0000
1234 @@ -16,6 +16,7 @@
1235  #include <linux/dm-ioctl.h>
1236  #include <linux/hdreg.h>
1237  #include <linux/compat.h>
1238 +#include <linux/vs_context.h>
1239  
1240  #include <asm/uaccess.h>
1241  
1242 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1243         unsigned int h = hash_str(str);
1244  
1245         list_for_each_entry (hc, _name_buckets + h, name_list)
1246 -               if (!strcmp(hc->name, str)) {
1247 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1248 +                       !strcmp(hc->name, str)) {
1249                         dm_get(hc->md);
1250                         return hc;
1251                 }
1252 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1253         unsigned int h = hash_str(str);
1254  
1255         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1256 -               if (!strcmp(hc->uuid, str)) {
1257 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1258 +                       !strcmp(hc->uuid, str)) {
1259                         dm_get(hc->md);
1260                         return hc;
1261                 }
1262 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1263  static struct hash_cell *__get_dev_cell(uint64_t dev)
1264  {
1265         struct mapped_device *md;
1266 -       struct hash_cell *hc;
1267 +       struct hash_cell *hc = NULL;
1268  
1269         md = dm_get_md(huge_decode_dev(dev));
1270         if (!md)
1271                 return NULL;
1272  
1273 -       hc = dm_get_mdptr(md);
1274 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1275 +               hc = dm_get_mdptr(md);
1276 +
1277         if (!hc) {
1278                 dm_put(md);
1279                 return NULL;
1280 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1281  
1282  static int remove_all(struct dm_ioctl *param, size_t param_size)
1283  {
1284 +       if (!vx_check(0, VS_ADMIN))
1285 +               return -EPERM;
1286 +
1287         dm_hash_remove_all(1);
1288         param->data_size = 0;
1289         return 0;
1290 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1291          */
1292         for (i = 0; i < NUM_BUCKETS; i++) {
1293                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1294 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1295 +                               continue;
1296                         needed += sizeof(struct dm_name_list);
1297                         needed += strlen(hc->name) + 1;
1298                         needed += ALIGN_MASK;
1299 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1300          */
1301         for (i = 0; i < NUM_BUCKETS; i++) {
1302                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1303 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1304 +                               continue;
1305                         if (old_nl)
1306                                 old_nl->next = (uint32_t) ((void *) nl -
1307                                                            (void *) old_nl);
1308 @@ -1619,8 +1631,8 @@ static int ctl_ioctl(uint command, struc
1309         ioctl_fn fn = NULL;
1310         size_t input_param_size;
1311  
1312 -       /* only root can play with this */
1313 -       if (!capable(CAP_SYS_ADMIN))
1314 +       /* only root and certain contexts can play with this */
1315 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1316                 return -EACCES;
1317  
1318         if (_IOC_TYPE(command) != DM_IOCTL)
1319 diff -NurpP --minimal linux-3.7.1/drivers/md/dm.c linux-3.7.1-vs2.3.5.5/drivers/md/dm.c
1320 --- linux-3.7.1/drivers/md/dm.c 2012-12-11 03:30:57.000000000 +0000
1321 +++ linux-3.7.1-vs2.3.5.5/drivers/md/dm.c       2012-12-18 15:13:16.000000000 +0000
1322 @@ -19,6 +19,7 @@
1323  #include <linux/idr.h>
1324  #include <linux/hdreg.h>
1325  #include <linux/delay.h>
1326 +#include <linux/vs_base.h>
1327  
1328  #include <trace/events/block.h>
1329  
1330 @@ -137,6 +138,7 @@ struct mapped_device {
1331         rwlock_t map_lock;
1332         atomic_t holders;
1333         atomic_t open_count;
1334 +       xid_t xid;
1335  
1336         unsigned long flags;
1337  
1338 @@ -345,6 +347,7 @@ int dm_deleting_md(struct mapped_device
1339  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1340  {
1341         struct mapped_device *md;
1342 +       int ret = -ENXIO;
1343  
1344         spin_lock(&_minor_lock);
1345  
1346 @@ -353,18 +356,19 @@ static int dm_blk_open(struct block_devi
1347                 goto out;
1348  
1349         if (test_bit(DMF_FREEING, &md->flags) ||
1350 -           dm_deleting_md(md)) {
1351 -               md = NULL;
1352 +           dm_deleting_md(md))
1353 +               goto out;
1354 +
1355 +       ret = -EACCES;
1356 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1357                 goto out;
1358 -       }
1359  
1360         dm_get(md);
1361         atomic_inc(&md->open_count);
1362 -
1363 +       ret = 0;
1364  out:
1365         spin_unlock(&_minor_lock);
1366 -
1367 -       return md ? 0 : -ENXIO;
1368 +       return ret;
1369  }
1370  
1371  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1372 @@ -575,6 +579,14 @@ int dm_set_geometry(struct mapped_device
1373         return 0;
1374  }
1375  
1376 +/*
1377 + * Get the xid associated with a dm device
1378 + */
1379 +xid_t dm_get_xid(struct mapped_device *md)
1380 +{
1381 +       return md->xid;
1382 +}
1383 +
1384  /*-----------------------------------------------------------------
1385   * CRUD START:
1386   *   A more elegant soln is in the works that uses the queue
1387 @@ -1852,6 +1864,7 @@ static struct mapped_device *alloc_dev(i
1388         INIT_LIST_HEAD(&md->uevent_list);
1389         spin_lock_init(&md->uevent_lock);
1390  
1391 +       md->xid = vx_current_xid();
1392         md->queue = blk_alloc_queue(GFP_KERNEL);
1393         if (!md->queue)
1394                 goto bad_queue;
1395 diff -NurpP --minimal linux-3.7.1/drivers/md/dm.h linux-3.7.1-vs2.3.5.5/drivers/md/dm.h
1396 --- linux-3.7.1/drivers/md/dm.h 2012-12-11 03:30:57.000000000 +0000
1397 +++ linux-3.7.1-vs2.3.5.5/drivers/md/dm.h       2012-12-18 15:13:16.000000000 +0000
1398 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1399  struct dm_table;
1400  struct dm_md_mempools;
1401  
1402 +xid_t dm_get_xid(struct mapped_device *md);
1403 +
1404  /*-----------------------------------------------------------------
1405   * Internal table functions.
1406   *---------------------------------------------------------------*/
1407 diff -NurpP --minimal linux-3.7.1/drivers/net/tun.c linux-3.7.1-vs2.3.5.5/drivers/net/tun.c
1408 --- linux-3.7.1/drivers/net/tun.c       2012-12-11 03:30:57.000000000 +0000
1409 +++ linux-3.7.1-vs2.3.5.5/drivers/net/tun.c     2012-12-18 15:13:16.000000000 +0000
1410 @@ -64,6 +64,7 @@
1411  #include <linux/nsproxy.h>
1412  #include <linux/virtio_net.h>
1413  #include <linux/rcupdate.h>
1414 +#include <linux/vs_network.h>
1415  #include <net/net_namespace.h>
1416  #include <net/netns/generic.h>
1417  #include <net/rtnetlink.h>
1418 @@ -123,6 +124,7 @@ struct tun_struct {
1419         unsigned int            flags;
1420         kuid_t                  owner;
1421         kgid_t                  group;
1422 +       nid_t                   nid;
1423  
1424         struct net_device       *dev;
1425         netdev_features_t       set_features;
1426 @@ -1034,6 +1036,7 @@ static void tun_setup(struct net_device
1427  
1428         tun->owner = INVALID_UID;
1429         tun->group = INVALID_GID;
1430 +       tun->nid = nx_current_nid();
1431  
1432         dev->ethtool_ops = &tun_ethtool_ops;
1433         dev->destructor = tun_free_netdev;
1434 @@ -1198,7 +1201,7 @@ static int tun_set_iff(struct net *net,
1435  
1436                 if (((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1437                      (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1438 -                   !capable(CAP_NET_ADMIN))
1439 +                    !cap_raised(current_cap(), CAP_NET_ADMIN))
1440                         return -EPERM;
1441                 err = security_tun_dev_attach(tun->socket.sk);
1442                 if (err < 0)
1443 @@ -1212,7 +1215,7 @@ static int tun_set_iff(struct net *net,
1444                 char *name;
1445                 unsigned long flags = 0;
1446  
1447 -               if (!capable(CAP_NET_ADMIN))
1448 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1449                         return -EPERM;
1450                 err = security_tun_dev_create();
1451                 if (err < 0)
1452 @@ -1283,6 +1286,9 @@ static int tun_set_iff(struct net *net,
1453  
1454                 sk->sk_destruct = tun_sock_destruct;
1455  
1456 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1457 +                       return -EPERM;
1458 +
1459                 err = tun_attach(tun, file);
1460                 if (err < 0)
1461                         goto failed;
1462 @@ -1478,6 +1484,16 @@ static long __tun_chr_ioctl(struct file
1463                           from_kgid(&init_user_ns, tun->group));
1464                 break;
1465  
1466 +       case TUNSETNID:
1467 +               if (!capable(CAP_CONTEXT))
1468 +                       return -EPERM;
1469 +
1470 +               /* Set nid owner of the device */
1471 +               tun->nid = (nid_t) arg;
1472 +
1473 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1474 +               break;
1475 +
1476         case TUNSETLINK:
1477                 /* Only allow setting the type when the interface is down */
1478                 if (tun->dev->flags & IFF_UP) {
1479 diff -NurpP --minimal linux-3.7.1/drivers/staging/csr/csr_wifi_hip_xbv.c linux-3.7.1-vs2.3.5.5/drivers/staging/csr/csr_wifi_hip_xbv.c
1480 --- linux-3.7.1/drivers/staging/csr/csr_wifi_hip_xbv.c  2012-12-11 03:30:57.000000000 +0000
1481 +++ linux-3.7.1-vs2.3.5.5/drivers/staging/csr/csr_wifi_hip_xbv.c        2012-12-18 15:13:16.000000000 +0000
1482 @@ -55,7 +55,7 @@ typedef struct
1483  {
1484      char t_name[4];
1485      u32     t_len;
1486 -} tag_t;
1487 +} ctag_t;
1488  
1489  
1490  #define TAG_EQ(i, v)    (((i)[0] == (v)[0]) &&  \
1491 @@ -90,7 +90,7 @@ typedef struct
1492      u32 ptr;
1493  } xbv_stack_t;
1494  
1495 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag);
1496 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag);
1497  static s32 read_bytes(card_t *card, ct_t *ct, void *buf, u32 len);
1498  static s32 read_uint(card_t *card, ct_t *ct, u32 *u, u32 len);
1499  static s32 xbv_check(xbv1_t *fwinfo, const xbv_stack_t *stack,
1500 @@ -160,7 +160,7 @@ static u32 write_fwdl_to_ptdl(void *buf,
1501  CsrResult xbv1_parse(card_t *card, fwreadfn_t readfn, void *dlpriv, xbv1_t *fwinfo)
1502  {
1503      ct_t ct;
1504 -    tag_t tag;
1505 +    ctag_t tag;
1506      xbv_stack_t stack;
1507  
1508      ct.dlpriv = dlpriv;
1509 @@ -505,7 +505,7 @@ static u32 xbv2uint(u8 *ptr, s32 len)
1510  }
1511  
1512  
1513 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag)
1514 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag)
1515  {
1516      u8 buf[8];
1517      s32 n;
1518 diff -NurpP --minimal linux-3.7.1/drivers/tty/sysrq.c linux-3.7.1-vs2.3.5.5/drivers/tty/sysrq.c
1519 --- linux-3.7.1/drivers/tty/sysrq.c     2012-12-11 03:30:57.000000000 +0000
1520 +++ linux-3.7.1-vs2.3.5.5/drivers/tty/sysrq.c   2012-12-18 15:13:16.000000000 +0000
1521 @@ -41,6 +41,7 @@
1522  #include <linux/slab.h>
1523  #include <linux/input.h>
1524  #include <linux/uaccess.h>
1525 +#include <linux/vserver/debug.h>
1526  
1527  #include <asm/ptrace.h>
1528  #include <asm/irq_regs.h>
1529 @@ -398,6 +399,21 @@ static struct sysrq_key_op sysrq_unrt_op
1530         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1531  };
1532  
1533 +
1534 +#ifdef CONFIG_VSERVER_DEBUG
1535 +static void sysrq_handle_vxinfo(int key)
1536 +{
1537 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1538 +}
1539 +
1540 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1541 +       .handler        = sysrq_handle_vxinfo,
1542 +       .help_msg       = "conteXt",
1543 +       .action_msg     = "Show Context Info",
1544 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1545 +};
1546 +#endif
1547 +
1548  /* Key Operations table and lock */
1549  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1550  
1551 @@ -453,7 +469,11 @@ static struct sysrq_key_op *sysrq_key_ta
1552         &sysrq_showstate_blocked_op,    /* w */
1553         /* x: May be registered on ppc/powerpc for xmon */
1554         /* x: May be registered on sparc64 for global PMU dump */
1555 +#ifdef CONFIG_VSERVER_DEBUG
1556 +       &sysrq_showvxinfo_op,           /* x */
1557 +#else
1558         NULL,                           /* x */
1559 +#endif
1560         /* y: May be registered on sparc64 for global register dump */
1561         NULL,                           /* y */
1562         &sysrq_ftrace_dump_op,          /* z */
1563 @@ -468,6 +488,8 @@ static int sysrq_key_table_key2index(int
1564                 retval = key - '0';
1565         else if ((key >= 'a') && (key <= 'z'))
1566                 retval = key + 10 - 'a';
1567 +       else if ((key >= 'A') && (key <= 'Z'))
1568 +               retval = key + 10 - 'A';
1569         else
1570                 retval = -1;
1571         return retval;
1572 diff -NurpP --minimal linux-3.7.1/drivers/tty/tty_io.c linux-3.7.1-vs2.3.5.5/drivers/tty/tty_io.c
1573 --- linux-3.7.1/drivers/tty/tty_io.c    2012-12-11 03:30:57.000000000 +0000
1574 +++ linux-3.7.1-vs2.3.5.5/drivers/tty/tty_io.c  2012-12-18 15:13:16.000000000 +0000
1575 @@ -104,6 +104,7 @@
1576  
1577  #include <linux/kmod.h>
1578  #include <linux/nsproxy.h>
1579 +#include <linux/vs_pid.h>
1580  
1581  #undef TTY_DEBUG_HANGUP
1582  
1583 @@ -2139,7 +2140,8 @@ static int tiocsti(struct tty_struct *tt
1584         char ch, mbz = 0;
1585         struct tty_ldisc *ld;
1586  
1587 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1588 +       if (((current->signal->tty != tty) &&
1589 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1590                 return -EPERM;
1591         if (get_user(ch, p))
1592                 return -EFAULT;
1593 @@ -2426,6 +2428,7 @@ static int tiocspgrp(struct tty_struct *
1594                 return -ENOTTY;
1595         if (get_user(pgrp_nr, p))
1596                 return -EFAULT;
1597 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1598         if (pgrp_nr < 0)
1599                 return -EINVAL;
1600         rcu_read_lock();
1601 diff -NurpP --minimal linux-3.7.1/fs/attr.c linux-3.7.1-vs2.3.5.5/fs/attr.c
1602 --- linux-3.7.1/fs/attr.c       2012-12-11 03:30:57.000000000 +0000
1603 +++ linux-3.7.1-vs2.3.5.5/fs/attr.c     2012-12-18 15:13:16.000000000 +0000
1604 @@ -15,6 +15,9 @@
1605  #include <linux/security.h>
1606  #include <linux/evm.h>
1607  #include <linux/ima.h>
1608 +#include <linux/proc_fs.h>
1609 +#include <linux/devpts_fs.h>
1610 +#include <linux/vs_tag.h>
1611  
1612  /**
1613   * inode_change_ok - check if attribute changes to an inode are allowed
1614 @@ -75,6 +78,10 @@ int inode_change_ok(const struct inode *
1615                         return -EPERM;
1616         }
1617  
1618 +       /* check for inode tag permission */
1619 +       if (dx_permission(inode, MAY_WRITE))
1620 +               return -EACCES;
1621 +
1622         return 0;
1623  }
1624  EXPORT_SYMBOL(inode_change_ok);
1625 @@ -145,6 +152,8 @@ void setattr_copy(struct inode *inode, c
1626                 inode->i_uid = attr->ia_uid;
1627         if (ia_valid & ATTR_GID)
1628                 inode->i_gid = attr->ia_gid;
1629 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1630 +               inode->i_tag = attr->ia_tag;
1631         if (ia_valid & ATTR_ATIME)
1632                 inode->i_atime = timespec_trunc(attr->ia_atime,
1633                                                 inode->i_sb->s_time_gran);
1634 @@ -174,7 +183,8 @@ int notify_change(struct dentry * dentry
1635  
1636         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1637  
1638 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1639 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1640 +               ATTR_TAG | ATTR_TIMES_SET)) {
1641                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1642                         return -EPERM;
1643         }
1644 diff -NurpP --minimal linux-3.7.1/fs/block_dev.c linux-3.7.1-vs2.3.5.5/fs/block_dev.c
1645 --- linux-3.7.1/fs/block_dev.c  2012-12-11 03:30:57.000000000 +0000
1646 +++ linux-3.7.1-vs2.3.5.5/fs/block_dev.c        2012-12-18 15:13:16.000000000 +0000
1647 @@ -27,6 +27,7 @@
1648  #include <linux/namei.h>
1649  #include <linux/log2.h>
1650  #include <linux/cleancache.h>
1651 +#include <linux/vs_device.h>
1652  #include <asm/uaccess.h>
1653  #include "internal.h"
1654  
1655 @@ -528,6 +529,7 @@ struct block_device *bdget(dev_t dev)
1656                 bdev->bd_invalidated = 0;
1657                 inode->i_mode = S_IFBLK;
1658                 inode->i_rdev = dev;
1659 +               inode->i_mdev = dev;
1660                 inode->i_bdev = bdev;
1661                 inode->i_data.a_ops = &def_blk_aops;
1662                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1663 @@ -574,6 +576,11 @@ EXPORT_SYMBOL(bdput);
1664  static struct block_device *bd_acquire(struct inode *inode)
1665  {
1666         struct block_device *bdev;
1667 +       dev_t mdev;
1668 +
1669 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1670 +               return NULL;
1671 +       inode->i_mdev = mdev;
1672  
1673         spin_lock(&bdev_lock);
1674         bdev = inode->i_bdev;
1675 @@ -584,7 +591,7 @@ static struct block_device *bd_acquire(s
1676         }
1677         spin_unlock(&bdev_lock);
1678  
1679 -       bdev = bdget(inode->i_rdev);
1680 +       bdev = bdget(mdev);
1681         if (bdev) {
1682                 spin_lock(&bdev_lock);
1683                 if (!inode->i_bdev) {
1684 diff -NurpP --minimal linux-3.7.1/fs/btrfs/ctree.h linux-3.7.1-vs2.3.5.5/fs/btrfs/ctree.h
1685 --- linux-3.7.1/fs/btrfs/ctree.h        2012-12-11 03:30:57.000000000 +0000
1686 +++ linux-3.7.1-vs2.3.5.5/fs/btrfs/ctree.h      2012-12-18 15:13:16.000000000 +0000
1687 @@ -692,11 +692,14 @@ struct btrfs_inode_item {
1688         /* modification sequence number for NFS */
1689         __le64 sequence;
1690  
1691 +       __le16 tag;
1692         /*
1693          * a little future expansion, for more than this we can
1694          * just grow the inode item and version it
1695          */
1696 -       __le64 reserved[4];
1697 +       __le16 reserved16;
1698 +       __le32 reserved32;
1699 +       __le64 reserved[3];
1700         struct btrfs_timespec atime;
1701         struct btrfs_timespec ctime;
1702         struct btrfs_timespec mtime;
1703 @@ -1757,6 +1760,8 @@ struct btrfs_ioctl_defrag_range_args {
1704  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1705  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1706  
1707 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1708 +
1709  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1710  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1711  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1712 @@ -2025,6 +2030,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1713  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1714  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1715  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1716 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1717  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1718  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1719  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1720 @@ -2078,6 +2084,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1721  
1722  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1723  
1724 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1725 +#define BTRFS_INODE_BARRIER            (1 << 25)
1726 +#define BTRFS_INODE_COW                        (1 << 26)
1727 +
1728  
1729  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1730  
1731 @@ -3363,6 +3373,7 @@ extern const struct dentry_operations bt
1732  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1733  void btrfs_update_iflags(struct inode *inode);
1734  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1735 +int btrfs_sync_flags(struct inode *inode, int, int);
1736  int btrfs_defrag_file(struct inode *inode, struct file *file,
1737                       struct btrfs_ioctl_defrag_range_args *range,
1738                       u64 newer_than, unsigned long max_pages);
1739 diff -NurpP --minimal linux-3.7.1/fs/btrfs/disk-io.c linux-3.7.1-vs2.3.5.5/fs/btrfs/disk-io.c
1740 --- linux-3.7.1/fs/btrfs/disk-io.c      2012-12-11 03:30:57.000000000 +0000
1741 +++ linux-3.7.1-vs2.3.5.5/fs/btrfs/disk-io.c    2012-12-18 15:13:16.000000000 +0000
1742 @@ -2197,6 +2197,9 @@ int open_ctree(struct super_block *sb,
1743                 goto fail_alloc;
1744         }
1745  
1746 +       if (btrfs_test_opt(tree_root, TAGGED))
1747 +               sb->s_flags |= MS_TAGGED;
1748 +
1749         features = btrfs_super_incompat_flags(disk_super) &
1750                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1751         if (features) {
1752 diff -NurpP --minimal linux-3.7.1/fs/btrfs/inode.c linux-3.7.1-vs2.3.5.5/fs/btrfs/inode.c
1753 --- linux-3.7.1/fs/btrfs/inode.c        2012-12-11 03:30:57.000000000 +0000
1754 +++ linux-3.7.1-vs2.3.5.5/fs/btrfs/inode.c      2012-12-18 15:13:16.000000000 +0000
1755 @@ -39,6 +39,7 @@
1756  #include <linux/slab.h>
1757  #include <linux/ratelimit.h>
1758  #include <linux/mount.h>
1759 +#include <linux/vs_tag.h>
1760  #include "compat.h"
1761  #include "ctree.h"
1762  #include "disk-io.h"
1763 @@ -2530,6 +2531,8 @@ static void btrfs_read_locked_inode(stru
1764         struct btrfs_key location;
1765         int maybe_acls;
1766         u32 rdev;
1767 +       uid_t uid;
1768 +       gid_t gid;
1769         int ret;
1770         bool filled = false;
1771  
1772 @@ -2557,8 +2560,13 @@ static void btrfs_read_locked_inode(stru
1773                                     struct btrfs_inode_item);
1774         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1775         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1776 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1777 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1778 +
1779 +       uid = btrfs_inode_uid(leaf, inode_item);
1780 +       gid = btrfs_inode_gid(leaf, inode_item);
1781 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
1782 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
1783 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
1784 +               btrfs_inode_tag(leaf, inode_item)));
1785         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1786  
1787         tspec = btrfs_inode_atime(inode_item);
1788 @@ -2648,8 +2656,16 @@ static void fill_inode_item(struct btrfs
1789                             struct btrfs_inode_item *item,
1790                             struct inode *inode)
1791  {
1792 -       btrfs_set_inode_uid(leaf, item, i_uid_read(inode));
1793 -       btrfs_set_inode_gid(leaf, item, i_gid_read(inode));
1794 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
1795 +               i_uid_read(inode), i_tag_read(inode));
1796 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
1797 +               i_gid_read(inode), i_tag_read(inode));
1798 +
1799 +       btrfs_set_inode_uid(leaf, item, uid);
1800 +       btrfs_set_inode_gid(leaf, item, gid);
1801 +#ifdef CONFIG_TAGGING_INTERN
1802 +       btrfs_set_inode_tag(leaf, item, i_tag_read(inode));
1803 +#endif
1804         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1805         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1806         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1807 @@ -7786,11 +7802,13 @@ static const struct inode_operations btr
1808         .listxattr      = btrfs_listxattr,
1809         .removexattr    = btrfs_removexattr,
1810         .permission     = btrfs_permission,
1811 +       .sync_flags     = btrfs_sync_flags,
1812         .get_acl        = btrfs_get_acl,
1813  };
1814  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1815         .lookup         = btrfs_lookup,
1816         .permission     = btrfs_permission,
1817 +       .sync_flags     = btrfs_sync_flags,
1818         .get_acl        = btrfs_get_acl,
1819  };
1820  
1821 diff -NurpP --minimal linux-3.7.1/fs/btrfs/ioctl.c linux-3.7.1-vs2.3.5.5/fs/btrfs/ioctl.c
1822 --- linux-3.7.1/fs/btrfs/ioctl.c        2012-12-11 03:30:57.000000000 +0000
1823 +++ linux-3.7.1-vs2.3.5.5/fs/btrfs/ioctl.c      2012-12-18 15:13:16.000000000 +0000
1824 @@ -74,10 +74,13 @@ static unsigned int btrfs_flags_to_ioctl
1825  {
1826         unsigned int iflags = 0;
1827  
1828 -       if (flags & BTRFS_INODE_SYNC)
1829 -               iflags |= FS_SYNC_FL;
1830         if (flags & BTRFS_INODE_IMMUTABLE)
1831                 iflags |= FS_IMMUTABLE_FL;
1832 +       if (flags & BTRFS_INODE_IXUNLINK)
1833 +               iflags |= FS_IXUNLINK_FL;
1834 +
1835 +       if (flags & BTRFS_INODE_SYNC)
1836 +               iflags |= FS_SYNC_FL;
1837         if (flags & BTRFS_INODE_APPEND)
1838                 iflags |= FS_APPEND_FL;
1839         if (flags & BTRFS_INODE_NODUMP)
1840 @@ -94,28 +97,78 @@ static unsigned int btrfs_flags_to_ioctl
1841         else if (flags & BTRFS_INODE_NOCOMPRESS)
1842                 iflags |= FS_NOCOMP_FL;
1843  
1844 +       if (flags & BTRFS_INODE_BARRIER)
1845 +               iflags |= FS_BARRIER_FL;
1846 +       if (flags & BTRFS_INODE_COW)
1847 +               iflags |= FS_COW_FL;
1848         return iflags;
1849  }
1850  
1851  /*
1852 - * Update inode->i_flags based on the btrfs internal flags.
1853 + * Update inode->i_(v)flags based on the btrfs internal flags.
1854   */
1855  void btrfs_update_iflags(struct inode *inode)
1856  {
1857         struct btrfs_inode *ip = BTRFS_I(inode);
1858  
1859 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1860 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1861 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1862  
1863 -       if (ip->flags & BTRFS_INODE_SYNC)
1864 -               inode->i_flags |= S_SYNC;
1865         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1866                 inode->i_flags |= S_IMMUTABLE;
1867 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1868 +               inode->i_flags |= S_IXUNLINK;
1869 +
1870 +       if (ip->flags & BTRFS_INODE_SYNC)
1871 +               inode->i_flags |= S_SYNC;
1872         if (ip->flags & BTRFS_INODE_APPEND)
1873                 inode->i_flags |= S_APPEND;
1874         if (ip->flags & BTRFS_INODE_NOATIME)
1875                 inode->i_flags |= S_NOATIME;
1876         if (ip->flags & BTRFS_INODE_DIRSYNC)
1877                 inode->i_flags |= S_DIRSYNC;
1878 +
1879 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1880 +
1881 +       if (ip->flags & BTRFS_INODE_BARRIER)
1882 +               inode->i_vflags |= V_BARRIER;
1883 +       if (ip->flags & BTRFS_INODE_COW)
1884 +               inode->i_vflags |= V_COW;
1885 +}
1886 +
1887 +/*
1888 + * Update btrfs internal flags from inode->i_(v)flags.
1889 + */
1890 +void btrfs_update_flags(struct inode *inode)
1891 +{
1892 +       struct btrfs_inode *ip = BTRFS_I(inode);
1893 +
1894 +       unsigned int flags = inode->i_flags;
1895 +       unsigned int vflags = inode->i_vflags;
1896 +
1897 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1898 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1899 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1900 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1901 +
1902 +       if (flags & S_IMMUTABLE)
1903 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1904 +       if (flags & S_IXUNLINK)
1905 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1906 +
1907 +       if (flags & S_SYNC)
1908 +               ip->flags |= BTRFS_INODE_SYNC;
1909 +       if (flags & S_APPEND)
1910 +               ip->flags |= BTRFS_INODE_APPEND;
1911 +       if (flags & S_NOATIME)
1912 +               ip->flags |= BTRFS_INODE_NOATIME;
1913 +       if (flags & S_DIRSYNC)
1914 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1915 +
1916 +       if (vflags & V_BARRIER)
1917 +               ip->flags |= BTRFS_INODE_BARRIER;
1918 +       if (vflags & V_COW)
1919 +               ip->flags |= BTRFS_INODE_COW;
1920  }
1921  
1922  /*
1923 @@ -131,6 +184,7 @@ void btrfs_inherit_iflags(struct inode *
1924                 return;
1925  
1926         flags = BTRFS_I(dir)->flags;
1927 +       flags &= ~BTRFS_INODE_BARRIER;
1928  
1929         if (flags & BTRFS_INODE_NOCOMPRESS) {
1930                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1931 @@ -146,6 +200,30 @@ void btrfs_inherit_iflags(struct inode *
1932         btrfs_update_iflags(inode);
1933  }
1934  
1935 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1936 +{
1937 +       struct btrfs_inode *ip = BTRFS_I(inode);
1938 +       struct btrfs_root *root = ip->root;
1939 +       struct btrfs_trans_handle *trans;
1940 +       int ret;
1941 +
1942 +       trans = btrfs_join_transaction(root);
1943 +       BUG_ON(!trans);
1944 +
1945 +       inode->i_flags = flags;
1946 +       inode->i_vflags = vflags;
1947 +       btrfs_update_flags(inode);
1948 +
1949 +       ret = btrfs_update_inode(trans, root, inode);
1950 +       BUG_ON(ret);
1951 +
1952 +       btrfs_update_iflags(inode);
1953 +       inode->i_ctime = CURRENT_TIME;
1954 +       btrfs_end_transaction(trans, root);
1955 +
1956 +       return 0;
1957 +}
1958 +
1959  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1960  {
1961         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1962 @@ -208,21 +286,27 @@ static int btrfs_ioctl_setflags(struct f
1963  
1964         flags = btrfs_mask_flags(inode->i_mode, flags);
1965         oldflags = btrfs_flags_to_ioctl(ip->flags);
1966 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1967 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1968 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1969                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1970                         ret = -EPERM;
1971                         goto out_unlock;
1972                 }
1973         }
1974  
1975 -       if (flags & FS_SYNC_FL)
1976 -               ip->flags |= BTRFS_INODE_SYNC;
1977 -       else
1978 -               ip->flags &= ~BTRFS_INODE_SYNC;
1979         if (flags & FS_IMMUTABLE_FL)
1980                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1981         else
1982                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1983 +       if (flags & FS_IXUNLINK_FL)
1984 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1985 +       else
1986 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1987 +
1988 +       if (flags & FS_SYNC_FL)
1989 +               ip->flags |= BTRFS_INODE_SYNC;
1990 +       else
1991 +               ip->flags &= ~BTRFS_INODE_SYNC;
1992         if (flags & FS_APPEND_FL)
1993                 ip->flags |= BTRFS_INODE_APPEND;
1994         else
1995 diff -NurpP --minimal linux-3.7.1/fs/btrfs/super.c linux-3.7.1-vs2.3.5.5/fs/btrfs/super.c
1996 --- linux-3.7.1/fs/btrfs/super.c        2012-12-11 03:30:57.000000000 +0000
1997 +++ linux-3.7.1-vs2.3.5.5/fs/btrfs/super.c      2012-12-18 15:13:16.000000000 +0000
1998 @@ -312,7 +312,7 @@ enum {
1999         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
2000         Opt_check_integrity, Opt_check_integrity_including_extent_data,
2001         Opt_check_integrity_print_mask, Opt_fatal_errors,
2002 -       Opt_err,
2003 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2004  };
2005  
2006  static match_table_t tokens = {
2007 @@ -352,6 +352,9 @@ static match_table_t tokens = {
2008         {Opt_check_integrity_including_extent_data, "check_int_data"},
2009         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
2010         {Opt_fatal_errors, "fatal_errors=%s"},
2011 +       {Opt_tag, "tag"},
2012 +       {Opt_notag, "notag"},
2013 +       {Opt_tagid, "tagid=%u"},
2014         {Opt_err, NULL},
2015  };
2016  
2017 @@ -614,6 +617,22 @@ int btrfs_parse_options(struct btrfs_roo
2018                                 goto out;
2019                         }
2020                         break;
2021 +#ifndef CONFIG_TAGGING_NONE
2022 +               case Opt_tag:
2023 +                       printk(KERN_INFO "btrfs: use tagging\n");
2024 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2025 +                       break;
2026 +               case Opt_notag:
2027 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2028 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2029 +                       break;
2030 +#endif
2031 +#ifdef CONFIG_PROPAGATE
2032 +               case Opt_tagid:
2033 +                       /* use args[0] */
2034 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2035 +                       break;
2036 +#endif
2037                 case Opt_err:
2038                         printk(KERN_INFO "btrfs: unrecognized mount option "
2039                                "'%s'\n", p);
2040 @@ -1211,6 +1230,12 @@ static int btrfs_remount(struct super_bl
2041         btrfs_resize_thread_pool(fs_info,
2042                 fs_info->thread_pool_size, old_thread_pool_size);
2043  
2044 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2045 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2046 +                       sb->s_id);
2047 +               return -EINVAL;
2048 +       }
2049 +
2050         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2051                 return 0;
2052  
2053 diff -NurpP --minimal linux-3.7.1/fs/char_dev.c linux-3.7.1-vs2.3.5.5/fs/char_dev.c
2054 --- linux-3.7.1/fs/char_dev.c   2012-12-11 03:30:57.000000000 +0000
2055 +++ linux-3.7.1-vs2.3.5.5/fs/char_dev.c 2012-12-18 15:13:16.000000000 +0000
2056 @@ -21,6 +21,8 @@
2057  #include <linux/mutex.h>
2058  #include <linux/backing-dev.h>
2059  #include <linux/tty.h>
2060 +#include <linux/vs_context.h>
2061 +#include <linux/vs_device.h>
2062  
2063  #include "internal.h"
2064  
2065 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2066         struct cdev *p;
2067         struct cdev *new = NULL;
2068         int ret = 0;
2069 +       dev_t mdev;
2070 +
2071 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2072 +               return -EPERM;
2073 +       inode->i_mdev = mdev;
2074  
2075         spin_lock(&cdev_lock);
2076         p = inode->i_cdev;
2077         if (!p) {
2078                 struct kobject *kobj;
2079                 int idx;
2080 +
2081                 spin_unlock(&cdev_lock);
2082 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2083 +
2084 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2085                 if (!kobj)
2086                         return -ENXIO;
2087                 new = container_of(kobj, struct cdev, kobj);
2088 diff -NurpP --minimal linux-3.7.1/fs/dcache.c linux-3.7.1-vs2.3.5.5/fs/dcache.c
2089 --- linux-3.7.1/fs/dcache.c     2012-12-11 03:30:57.000000000 +0000
2090 +++ linux-3.7.1-vs2.3.5.5/fs/dcache.c   2012-12-18 15:13:16.000000000 +0000
2091 @@ -37,6 +37,7 @@
2092  #include <linux/rculist_bl.h>
2093  #include <linux/prefetch.h>
2094  #include <linux/ratelimit.h>
2095 +#include <linux/vs_limit.h>
2096  #include "internal.h"
2097  #include "mount.h"
2098  
2099 @@ -617,6 +618,8 @@ int d_invalidate(struct dentry * dentry)
2100                 spin_lock(&dentry->d_lock);
2101         }
2102  
2103 +       vx_dentry_dec(dentry);
2104 +
2105         /*
2106          * Somebody else still using it?
2107          *
2108 @@ -646,6 +649,7 @@ EXPORT_SYMBOL(d_invalidate);
2109  static inline void __dget_dlock(struct dentry *dentry)
2110  {
2111         dentry->d_count++;
2112 +       vx_dentry_inc(dentry);
2113  }
2114  
2115  static inline void __dget(struct dentry *dentry)
2116 @@ -1276,6 +1280,9 @@ struct dentry *__d_alloc(struct super_bl
2117         struct dentry *dentry;
2118         char *dname;
2119  
2120 +       if (!vx_dentry_avail(1))
2121 +               return NULL;
2122 +
2123         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2124         if (!dentry)
2125                 return NULL;
2126 @@ -1308,6 +1315,7 @@ struct dentry *__d_alloc(struct super_bl
2127  
2128         dentry->d_count = 1;
2129         dentry->d_flags = 0;
2130 +       vx_dentry_inc(dentry);
2131         spin_lock_init(&dentry->d_lock);
2132         seqcount_init(&dentry->d_seq);
2133         dentry->d_inode = NULL;
2134 @@ -2012,6 +2020,7 @@ struct dentry *__d_lookup(struct dentry
2135                 }
2136  
2137                 dentry->d_count++;
2138 +               vx_dentry_inc(dentry);
2139                 found = dentry;
2140                 spin_unlock(&dentry->d_lock);
2141                 break;
2142 diff -NurpP --minimal linux-3.7.1/fs/devpts/inode.c linux-3.7.1-vs2.3.5.5/fs/devpts/inode.c
2143 --- linux-3.7.1/fs/devpts/inode.c       2012-12-11 03:30:57.000000000 +0000
2144 +++ linux-3.7.1-vs2.3.5.5/fs/devpts/inode.c     2012-12-18 15:13:16.000000000 +0000
2145 @@ -25,6 +25,7 @@
2146  #include <linux/parser.h>
2147  #include <linux/fsnotify.h>
2148  #include <linux/seq_file.h>
2149 +#include <linux/vs_base.h>
2150  
2151  #define DEVPTS_DEFAULT_MODE 0600
2152  /*
2153 @@ -36,6 +37,21 @@
2154  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2155  #define PTMX_MINOR     2
2156  
2157 +static int devpts_permission(struct inode *inode, int mask)
2158 +{
2159 +       int ret = -EACCES;
2160 +
2161 +       /* devpts is xid tagged */
2162 +       if (vx_check((xid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2163 +               ret = generic_permission(inode, mask);
2164 +       return ret;
2165 +}
2166 +
2167 +static struct inode_operations devpts_file_inode_operations = {
2168 +       .permission     = devpts_permission,
2169 +};
2170 +
2171 +
2172  /*
2173   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2174   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2175 @@ -336,6 +352,34 @@ static int devpts_show_options(struct se
2176         return 0;
2177  }
2178  
2179 +static int devpts_filter(struct dentry *de)
2180 +{
2181 +       xid_t xid = 0;
2182 +
2183 +       /* devpts is xid tagged */
2184 +       if (de && de->d_inode)
2185 +               xid = (xid_t)i_tag_read(de->d_inode);
2186 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2187 +       else
2188 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2189 +                       de->d_name.len, de->d_name.name);
2190 +#endif
2191 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2192 +}
2193 +
2194 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2195 +{
2196 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2197 +}
2198 +
2199 +static struct file_operations devpts_dir_operations = {
2200 +       .open           = dcache_dir_open,
2201 +       .release        = dcache_dir_close,
2202 +       .llseek         = dcache_dir_lseek,
2203 +       .read           = generic_read_dir,
2204 +       .readdir        = devpts_readdir,
2205 +};
2206 +
2207  static const struct super_operations devpts_sops = {
2208         .statfs         = simple_statfs,
2209         .remount_fs     = devpts_remount,
2210 @@ -379,8 +423,10 @@ devpts_fill_super(struct super_block *s,
2211         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2212         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2213         inode->i_op = &simple_dir_inode_operations;
2214 -       inode->i_fop = &simple_dir_operations;
2215 +       inode->i_fop = &devpts_dir_operations;
2216         set_nlink(inode, 2);
2217 +       /* devpts is xid tagged */
2218 +       i_tag_write(inode, (tag_t)vx_current_xid());
2219  
2220         s->s_root = d_make_root(inode);
2221         if (s->s_root)
2222 @@ -572,6 +618,9 @@ int devpts_pty_new(struct inode *ptmx_in
2223         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2224         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2225         init_special_inode(inode, S_IFCHR|opts->mode, device);
2226 +       /* devpts is xid tagged */
2227 +       i_tag_write(inode, (tag_t)vx_current_xid());
2228 +       inode->i_op = &devpts_file_inode_operations;
2229         inode->i_private = tty;
2230         tty->driver_data = inode;
2231  
2232 diff -NurpP --minimal linux-3.7.1/fs/ext2/balloc.c linux-3.7.1-vs2.3.5.5/fs/ext2/balloc.c
2233 --- linux-3.7.1/fs/ext2/balloc.c        2012-12-11 03:30:57.000000000 +0000
2234 +++ linux-3.7.1-vs2.3.5.5/fs/ext2/balloc.c      2012-12-18 15:13:16.000000000 +0000
2235 @@ -699,7 +699,6 @@ ext2_try_to_allocate(struct super_block
2236                         start = 0;
2237                 end = EXT2_BLOCKS_PER_GROUP(sb);
2238         }
2239 -
2240         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2241  
2242  repeat:
2243 diff -NurpP --minimal linux-3.7.1/fs/ext2/ext2.h linux-3.7.1-vs2.3.5.5/fs/ext2/ext2.h
2244 --- linux-3.7.1/fs/ext2/ext2.h  2012-12-11 03:30:57.000000000 +0000
2245 +++ linux-3.7.1-vs2.3.5.5/fs/ext2/ext2.h        2012-12-18 15:13:16.000000000 +0000
2246 @@ -244,8 +244,12 @@ struct ext2_group_desc
2247  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2248  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2249  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2250 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2251  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2252  
2253 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2254 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2255 +
2256  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2257  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2258  
2259 @@ -329,7 +333,8 @@ struct ext2_inode {
2260                         __u16   i_pad1;
2261                         __le16  l_i_uid_high;   /* these 2 fields    */
2262                         __le16  l_i_gid_high;   /* were reserved2[0] */
2263 -                       __u32   l_i_reserved2;
2264 +                       __le16  l_i_tag;        /* Context Tag */
2265 +                       __u16   l_i_reserved2;
2266                 } linux2;
2267                 struct {
2268                         __u8    h_i_frag;       /* Fragment number */
2269 @@ -357,6 +362,7 @@ struct ext2_inode {
2270  #define i_gid_low      i_gid
2271  #define i_uid_high     osd2.linux2.l_i_uid_high
2272  #define i_gid_high     osd2.linux2.l_i_gid_high
2273 +#define i_raw_tag      osd2.linux2.l_i_tag
2274  #define i_reserved2    osd2.linux2.l_i_reserved2
2275  
2276  /*
2277 @@ -384,6 +390,7 @@ struct ext2_inode {
2278  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2279  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2280  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2281 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2282  
2283  
2284  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2285 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2286  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2287  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2288                        u64 start, u64 len);
2289 +extern int ext2_sync_flags(struct inode *, int, int);
2290  
2291  /* ioctl.c */
2292  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2293 diff -NurpP --minimal linux-3.7.1/fs/ext2/file.c linux-3.7.1-vs2.3.5.5/fs/ext2/file.c
2294 --- linux-3.7.1/fs/ext2/file.c  2012-12-11 03:30:57.000000000 +0000
2295 +++ linux-3.7.1-vs2.3.5.5/fs/ext2/file.c        2012-12-18 15:13:16.000000000 +0000
2296 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2297         .setattr        = ext2_setattr,
2298         .get_acl        = ext2_get_acl,
2299         .fiemap         = ext2_fiemap,
2300 +       .sync_flags     = ext2_sync_flags,
2301  };
2302 diff -NurpP --minimal linux-3.7.1/fs/ext2/ialloc.c linux-3.7.1-vs2.3.5.5/fs/ext2/ialloc.c
2303 --- linux-3.7.1/fs/ext2/ialloc.c        2012-12-11 03:30:57.000000000 +0000
2304 +++ linux-3.7.1-vs2.3.5.5/fs/ext2/ialloc.c      2012-12-18 15:13:16.000000000 +0000
2305 @@ -17,6 +17,7 @@
2306  #include <linux/backing-dev.h>
2307  #include <linux/buffer_head.h>
2308  #include <linux/random.h>
2309 +#include <linux/vs_tag.h>
2310  #include "ext2.h"
2311  #include "xattr.h"
2312  #include "acl.h"
2313 @@ -547,6 +548,7 @@ got:
2314                 inode->i_mode = mode;
2315                 inode->i_uid = current_fsuid();
2316                 inode->i_gid = dir->i_gid;
2317 +               inode->i_tag = dx_current_fstag(sb);
2318         } else
2319                 inode_init_owner(inode, dir, mode);
2320  
2321 diff -NurpP --minimal linux-3.7.1/fs/ext2/inode.c linux-3.7.1-vs2.3.5.5/fs/ext2/inode.c
2322 --- linux-3.7.1/fs/ext2/inode.c 2012-12-11 03:30:57.000000000 +0000
2323 +++ linux-3.7.1-vs2.3.5.5/fs/ext2/inode.c       2012-12-18 15:13:16.000000000 +0000
2324 @@ -31,6 +31,7 @@
2325  #include <linux/mpage.h>
2326  #include <linux/fiemap.h>
2327  #include <linux/namei.h>
2328 +#include <linux/vs_tag.h>
2329  #include "ext2.h"
2330  #include "acl.h"
2331  #include "xip.h"
2332 @@ -1165,7 +1166,7 @@ static void ext2_truncate_blocks(struct
2333                 return;
2334         if (ext2_inode_is_fast_symlink(inode))
2335                 return;
2336 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2337 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2338                 return;
2339         __ext2_truncate_blocks(inode, offset);
2340  }
2341 @@ -1256,36 +1257,61 @@ void ext2_set_inode_flags(struct inode *
2342  {
2343         unsigned int flags = EXT2_I(inode)->i_flags;
2344  
2345 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2346 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2347 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2348 +
2349 +
2350 +       if (flags & EXT2_IMMUTABLE_FL)
2351 +               inode->i_flags |= S_IMMUTABLE;
2352 +       if (flags & EXT2_IXUNLINK_FL)
2353 +               inode->i_flags |= S_IXUNLINK;
2354 +
2355         if (flags & EXT2_SYNC_FL)
2356                 inode->i_flags |= S_SYNC;
2357         if (flags & EXT2_APPEND_FL)
2358                 inode->i_flags |= S_APPEND;
2359 -       if (flags & EXT2_IMMUTABLE_FL)
2360 -               inode->i_flags |= S_IMMUTABLE;
2361         if (flags & EXT2_NOATIME_FL)
2362                 inode->i_flags |= S_NOATIME;
2363         if (flags & EXT2_DIRSYNC_FL)
2364                 inode->i_flags |= S_DIRSYNC;
2365 +
2366 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2367 +
2368 +       if (flags & EXT2_BARRIER_FL)
2369 +               inode->i_vflags |= V_BARRIER;
2370 +       if (flags & EXT2_COW_FL)
2371 +               inode->i_vflags |= V_COW;
2372  }
2373  
2374  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2375  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2376  {
2377         unsigned int flags = ei->vfs_inode.i_flags;
2378 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2379 +
2380 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2381 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2382 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2383 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2384 +
2385 +       if (flags & S_IMMUTABLE)
2386 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2387 +       if (flags & S_IXUNLINK)
2388 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2389  
2390 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2391 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2392         if (flags & S_SYNC)
2393                 ei->i_flags |= EXT2_SYNC_FL;
2394         if (flags & S_APPEND)
2395                 ei->i_flags |= EXT2_APPEND_FL;
2396 -       if (flags & S_IMMUTABLE)
2397 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2398         if (flags & S_NOATIME)
2399                 ei->i_flags |= EXT2_NOATIME_FL;
2400         if (flags & S_DIRSYNC)
2401                 ei->i_flags |= EXT2_DIRSYNC_FL;
2402 +
2403 +       if (vflags & V_BARRIER)
2404 +               ei->i_flags |= EXT2_BARRIER_FL;
2405 +       if (vflags & V_COW)
2406 +               ei->i_flags |= EXT2_COW_FL;
2407  }
2408  
2409  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2410 @@ -1321,8 +1347,10 @@ struct inode *ext2_iget (struct super_bl
2411                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2412                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2413         }
2414 -       i_uid_write(inode, i_uid);
2415 -       i_gid_write(inode, i_gid);
2416 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2417 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2418 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2419 +               le16_to_cpu(raw_inode->i_raw_tag)));
2420         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2421         inode->i_size = le32_to_cpu(raw_inode->i_size);
2422         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2423 @@ -1420,8 +1448,10 @@ static int __ext2_write_inode(struct ino
2424         struct ext2_inode_info *ei = EXT2_I(inode);
2425         struct super_block *sb = inode->i_sb;
2426         ino_t ino = inode->i_ino;
2427 -       uid_t uid = i_uid_read(inode);
2428 -       gid_t gid = i_gid_read(inode);
2429 +       uid_t uid = TAGINO_UID(DX_TAG(inode),
2430 +               i_uid_read(inode), i_tag_read(inode));
2431 +       gid_t gid = TAGINO_GID(DX_TAG(inode),
2432 +               i_gid_read(inode), i_tag_read(inode));
2433         struct buffer_head * bh;
2434         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2435         int n;
2436 @@ -1457,6 +1487,9 @@ static int __ext2_write_inode(struct ino
2437                 raw_inode->i_uid_high = 0;
2438                 raw_inode->i_gid_high = 0;
2439         }
2440 +#ifdef CONFIG_TAGGING_INTERN
2441 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2442 +#endif
2443         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2444         raw_inode->i_size = cpu_to_le32(inode->i_size);
2445         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2446 @@ -1537,7 +1570,8 @@ int ext2_setattr(struct dentry *dentry,
2447         if (is_quota_modification(inode, iattr))
2448                 dquot_initialize(inode);
2449         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2450 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2451 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2452 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2453                 error = dquot_transfer(inode, iattr);
2454                 if (error)
2455                         return error;
2456 diff -NurpP --minimal linux-3.7.1/fs/ext2/ioctl.c linux-3.7.1-vs2.3.5.5/fs/ext2/ioctl.c
2457 --- linux-3.7.1/fs/ext2/ioctl.c 2012-12-11 03:30:57.000000000 +0000
2458 +++ linux-3.7.1-vs2.3.5.5/fs/ext2/ioctl.c       2012-12-18 15:13:16.000000000 +0000
2459 @@ -17,6 +17,16 @@
2460  #include <asm/uaccess.h>
2461  
2462  
2463 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2464 +{
2465 +       inode->i_flags = flags;
2466 +       inode->i_vflags = vflags;
2467 +       ext2_get_inode_flags(EXT2_I(inode));
2468 +       inode->i_ctime = CURRENT_TIME_SEC;
2469 +       mark_inode_dirty(inode);
2470 +       return 0;
2471 +}
2472 +
2473  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2474  {
2475         struct inode *inode = filp->f_dentry->d_inode;
2476 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2477  
2478                 flags = ext2_mask_flags(inode->i_mode, flags);
2479  
2480 +               if (IS_BARRIER(inode)) {
2481 +                       vxwprintk_task(1, "messing with the barrier.");
2482 +                       return -EACCES;
2483 +               }
2484 +
2485                 mutex_lock(&inode->i_mutex);
2486                 /* Is it quota file? Do not allow user to mess with it */
2487                 if (IS_NOQUOTA(inode)) {
2488 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2489                  *
2490                  * This test looks nicer. Thanks to Pauline Middelink
2491                  */
2492 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2493 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2494 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2495 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2496                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2497                                 mutex_unlock(&inode->i_mutex);
2498                                 ret = -EPERM;
2499 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2500                         }
2501                 }
2502  
2503 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2504 +               flags &= EXT2_FL_USER_MODIFIABLE;
2505                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2506                 ei->i_flags = flags;
2507  
2508 diff -NurpP --minimal linux-3.7.1/fs/ext2/namei.c linux-3.7.1-vs2.3.5.5/fs/ext2/namei.c
2509 --- linux-3.7.1/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2510 +++ linux-3.7.1-vs2.3.5.5/fs/ext2/namei.c       2012-12-18 15:13:16.000000000 +0000
2511 @@ -32,6 +32,7 @@
2512  
2513  #include <linux/pagemap.h>
2514  #include <linux/quotaops.h>
2515 +#include <linux/vs_tag.h>
2516  #include "ext2.h"
2517  #include "xattr.h"
2518  #include "acl.h"
2519 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2520                                         (unsigned long) ino);
2521                         return ERR_PTR(-EIO);
2522                 }
2523 +               dx_propagate_tag(nd, inode);
2524         }
2525         return d_splice_alias(inode, dentry);
2526  }
2527 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2528         .removexattr    = generic_removexattr,
2529  #endif
2530         .setattr        = ext2_setattr,
2531 +       .sync_flags     = ext2_sync_flags,
2532         .get_acl        = ext2_get_acl,
2533  };
2534  
2535 diff -NurpP --minimal linux-3.7.1/fs/ext2/super.c linux-3.7.1-vs2.3.5.5/fs/ext2/super.c
2536 --- linux-3.7.1/fs/ext2/super.c 2012-12-11 03:30:57.000000000 +0000
2537 +++ linux-3.7.1-vs2.3.5.5/fs/ext2/super.c       2012-12-18 15:13:16.000000000 +0000
2538 @@ -395,7 +395,8 @@ enum {
2539         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2540         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2541         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2542 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2543 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2544 +       Opt_tag, Opt_notag, Opt_tagid
2545  };
2546  
2547  static const match_table_t tokens = {
2548 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2549         {Opt_acl, "acl"},
2550         {Opt_noacl, "noacl"},
2551         {Opt_xip, "xip"},
2552 +       {Opt_tag, "tag"},
2553 +       {Opt_notag, "notag"},
2554 +       {Opt_tagid, "tagid=%u"},
2555         {Opt_grpquota, "grpquota"},
2556         {Opt_ignore, "noquota"},
2557         {Opt_quota, "quota"},
2558 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2559                 case Opt_nouid32:
2560                         set_opt (sbi->s_mount_opt, NO_UID32);
2561                         break;
2562 +#ifndef CONFIG_TAGGING_NONE
2563 +               case Opt_tag:
2564 +                       set_opt (sbi->s_mount_opt, TAGGED);
2565 +                       break;
2566 +               case Opt_notag:
2567 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2568 +                       break;
2569 +#endif
2570 +#ifdef CONFIG_PROPAGATE
2571 +               case Opt_tagid:
2572 +                       /* use args[0] */
2573 +                       set_opt (sbi->s_mount_opt, TAGGED);
2574 +                       break;
2575 +#endif
2576                 case Opt_nocheck:
2577                         clear_opt (sbi->s_mount_opt, CHECK);
2578                         break;
2579 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2580         if (!parse_options((char *) data, sb))
2581                 goto failed_mount;
2582  
2583 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2584 +               sb->s_flags |= MS_TAGGED;
2585         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2586                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2587                  MS_POSIXACL : 0);
2588 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2589                 err = -EINVAL;
2590                 goto restore_opts;
2591         }
2592 +
2593 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2594 +               !(sb->s_flags & MS_TAGGED)) {
2595 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2596 +                      sb->s_id);
2597 +               err = -EINVAL;
2598 +               goto restore_opts;
2599 +       }
2600  
2601         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2602                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2603 diff -NurpP --minimal linux-3.7.1/fs/ext3/ext3.h linux-3.7.1-vs2.3.5.5/fs/ext3/ext3.h
2604 --- linux-3.7.1/fs/ext3/ext3.h  2012-12-11 03:30:57.000000000 +0000
2605 +++ linux-3.7.1-vs2.3.5.5/fs/ext3/ext3.h        2012-12-18 15:13:16.000000000 +0000
2606 @@ -151,10 +151,14 @@ struct ext3_group_desc
2607  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2608  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2609  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2610 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2611  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2612  
2613 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2614 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2615 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2616 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2617 +
2618 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2619 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2620  
2621  /* Flags that should be inherited by new inodes from their parent. */
2622  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2623 @@ -290,7 +294,8 @@ struct ext3_inode {
2624                         __u16   i_pad1;
2625                         __le16  l_i_uid_high;   /* these 2 fields    */
2626                         __le16  l_i_gid_high;   /* were reserved2[0] */
2627 -                       __u32   l_i_reserved2;
2628 +                       __le16  l_i_tag;        /* Context Tag */
2629 +                       __u16   l_i_reserved2;
2630                 } linux2;
2631                 struct {
2632                         __u8    h_i_frag;       /* Fragment number */
2633 @@ -320,6 +325,7 @@ struct ext3_inode {
2634  #define i_gid_low      i_gid
2635  #define i_uid_high     osd2.linux2.l_i_uid_high
2636  #define i_gid_high     osd2.linux2.l_i_gid_high
2637 +#define i_raw_tag      osd2.linux2.l_i_tag
2638  #define i_reserved2    osd2.linux2.l_i_reserved2
2639  
2640  /*
2641 @@ -364,6 +370,7 @@ struct ext3_inode {
2642  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2643  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2644                                                   * error in ordered mode */
2645 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2646  
2647  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2648  #ifndef _LINUX_EXT2_FS_H
2649 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2650  extern void ext3_set_aops(struct inode *inode);
2651  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2652                        u64 start, u64 len);
2653 +extern int ext3_sync_flags(struct inode *, int, int);
2654  
2655  /* ioctl.c */
2656  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2657 diff -NurpP --minimal linux-3.7.1/fs/ext3/file.c linux-3.7.1-vs2.3.5.5/fs/ext3/file.c
2658 --- linux-3.7.1/fs/ext3/file.c  2012-12-11 03:30:57.000000000 +0000
2659 +++ linux-3.7.1-vs2.3.5.5/fs/ext3/file.c        2012-12-18 15:13:16.000000000 +0000
2660 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2661  #endif
2662         .get_acl        = ext3_get_acl,
2663         .fiemap         = ext3_fiemap,
2664 +       .sync_flags     = ext3_sync_flags,
2665  };
2666  
2667 diff -NurpP --minimal linux-3.7.1/fs/ext3/ialloc.c linux-3.7.1-vs2.3.5.5/fs/ext3/ialloc.c
2668 --- linux-3.7.1/fs/ext3/ialloc.c        2012-12-11 03:30:57.000000000 +0000
2669 +++ linux-3.7.1-vs2.3.5.5/fs/ext3/ialloc.c      2012-12-18 15:13:16.000000000 +0000
2670 @@ -14,6 +14,7 @@
2671  
2672  #include <linux/quotaops.h>
2673  #include <linux/random.h>
2674 +#include <linux/vs_tag.h>
2675  
2676  #include "ext3.h"
2677  #include "xattr.h"
2678 @@ -469,6 +470,7 @@ got:
2679                 inode->i_mode = mode;
2680                 inode->i_uid = current_fsuid();
2681                 inode->i_gid = dir->i_gid;
2682 +               inode->i_tag = dx_current_fstag(sb);
2683         } else
2684                 inode_init_owner(inode, dir, mode);
2685  
2686 diff -NurpP --minimal linux-3.7.1/fs/ext3/inode.c linux-3.7.1-vs2.3.5.5/fs/ext3/inode.c
2687 --- linux-3.7.1/fs/ext3/inode.c 2012-12-11 03:30:57.000000000 +0000
2688 +++ linux-3.7.1-vs2.3.5.5/fs/ext3/inode.c       2012-12-18 15:13:16.000000000 +0000
2689 @@ -27,6 +27,8 @@
2690  #include <linux/writeback.h>
2691  #include <linux/mpage.h>
2692  #include <linux/namei.h>
2693 +#include <linux/vs_tag.h>
2694 +
2695  #include "ext3.h"
2696  #include "xattr.h"
2697  #include "acl.h"
2698 @@ -2848,36 +2850,60 @@ void ext3_set_inode_flags(struct inode *
2699  {
2700         unsigned int flags = EXT3_I(inode)->i_flags;
2701  
2702 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2703 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2704 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2705 +
2706 +       if (flags & EXT3_IMMUTABLE_FL)
2707 +               inode->i_flags |= S_IMMUTABLE;
2708 +       if (flags & EXT3_IXUNLINK_FL)
2709 +               inode->i_flags |= S_IXUNLINK;
2710 +
2711         if (flags & EXT3_SYNC_FL)
2712                 inode->i_flags |= S_SYNC;
2713         if (flags & EXT3_APPEND_FL)
2714                 inode->i_flags |= S_APPEND;
2715 -       if (flags & EXT3_IMMUTABLE_FL)
2716 -               inode->i_flags |= S_IMMUTABLE;
2717         if (flags & EXT3_NOATIME_FL)
2718                 inode->i_flags |= S_NOATIME;
2719         if (flags & EXT3_DIRSYNC_FL)
2720                 inode->i_flags |= S_DIRSYNC;
2721 +
2722 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2723 +
2724 +       if (flags & EXT3_BARRIER_FL)
2725 +               inode->i_vflags |= V_BARRIER;
2726 +       if (flags & EXT3_COW_FL)
2727 +               inode->i_vflags |= V_COW;
2728  }
2729  
2730  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2731  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2732  {
2733         unsigned int flags = ei->vfs_inode.i_flags;
2734 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2735 +
2736 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2737 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2738 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2739 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2740 +
2741 +       if (flags & S_IMMUTABLE)
2742 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2743 +       if (flags & S_IXUNLINK)
2744 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2745  
2746 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2747 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2748         if (flags & S_SYNC)
2749                 ei->i_flags |= EXT3_SYNC_FL;
2750         if (flags & S_APPEND)
2751                 ei->i_flags |= EXT3_APPEND_FL;
2752 -       if (flags & S_IMMUTABLE)
2753 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2754         if (flags & S_NOATIME)
2755                 ei->i_flags |= EXT3_NOATIME_FL;
2756         if (flags & S_DIRSYNC)
2757                 ei->i_flags |= EXT3_DIRSYNC_FL;
2758 +
2759 +       if (vflags & V_BARRIER)
2760 +               ei->i_flags |= EXT3_BARRIER_FL;
2761 +       if (vflags & V_COW)
2762 +               ei->i_flags |= EXT3_COW_FL;
2763  }
2764  
2765  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2766 @@ -2915,8 +2941,10 @@ struct inode *ext3_iget(struct super_blo
2767                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2768                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2769         }
2770 -       i_uid_write(inode, i_uid);
2771 -       i_gid_write(inode, i_gid);
2772 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2773 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2774 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2775 +               le16_to_cpu(raw_inode->i_raw_tag)));
2776         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2777         inode->i_size = le32_to_cpu(raw_inode->i_size);
2778         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2779 @@ -3088,8 +3116,10 @@ again:
2780  
2781         ext3_get_inode_flags(ei);
2782         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2783 -       i_uid = i_uid_read(inode);
2784 -       i_gid = i_gid_read(inode);
2785 +       i_uid = TAGINO_UID(DX_TAG(inode),
2786 +               i_uid_read(inode), i_tag_read(inode));
2787 +       i_gid = TAGINO_GID(DX_TAG(inode),
2788 +               i_gid_read(inode), i_tag_read(inode));
2789         if(!(test_opt(inode->i_sb, NO_UID32))) {
2790                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2791                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2792 @@ -3114,6 +3144,9 @@ again:
2793                 raw_inode->i_uid_high = 0;
2794                 raw_inode->i_gid_high = 0;
2795         }
2796 +#ifdef CONFIG_TAGGING_INTERN
2797 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2798 +#endif
2799         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2800         disksize = cpu_to_le32(ei->i_disksize);
2801         if (disksize != raw_inode->i_size) {
2802 @@ -3282,7 +3315,8 @@ int ext3_setattr(struct dentry *dentry,
2803         if (is_quota_modification(inode, attr))
2804                 dquot_initialize(inode);
2805         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2806 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2807 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2808 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2809                 handle_t *handle;
2810  
2811                 /* (user+group)*(old+new) structure, inode write (sb,
2812 @@ -3304,6 +3338,8 @@ int ext3_setattr(struct dentry *dentry,
2813                         inode->i_uid = attr->ia_uid;
2814                 if (attr->ia_valid & ATTR_GID)
2815                         inode->i_gid = attr->ia_gid;
2816 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2817 +                       inode->i_tag = attr->ia_tag;
2818                 error = ext3_mark_inode_dirty(handle, inode);
2819                 ext3_journal_stop(handle);
2820         }
2821 diff -NurpP --minimal linux-3.7.1/fs/ext3/ioctl.c linux-3.7.1-vs2.3.5.5/fs/ext3/ioctl.c
2822 --- linux-3.7.1/fs/ext3/ioctl.c 2012-12-11 03:30:57.000000000 +0000
2823 +++ linux-3.7.1-vs2.3.5.5/fs/ext3/ioctl.c       2012-12-18 15:13:16.000000000 +0000
2824 @@ -12,6 +12,34 @@
2825  #include <asm/uaccess.h>
2826  #include "ext3.h"
2827  
2828 +
2829 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2830 +{
2831 +       handle_t *handle = NULL;
2832 +       struct ext3_iloc iloc;
2833 +       int err;
2834 +
2835 +       handle = ext3_journal_start(inode, 1);
2836 +       if (IS_ERR(handle))
2837 +               return PTR_ERR(handle);
2838 +
2839 +       if (IS_SYNC(inode))
2840 +               handle->h_sync = 1;
2841 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2842 +       if (err)
2843 +               goto flags_err;
2844 +
2845 +       inode->i_flags = flags;
2846 +       inode->i_vflags = vflags;
2847 +       ext3_get_inode_flags(EXT3_I(inode));
2848 +       inode->i_ctime = CURRENT_TIME_SEC;
2849 +
2850 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2851 +flags_err:
2852 +       ext3_journal_stop(handle);
2853 +       return err;
2854 +}
2855 +
2856  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2857  {
2858         struct inode *inode = filp->f_dentry->d_inode;
2859 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2860  
2861                 flags = ext3_mask_flags(inode->i_mode, flags);
2862  
2863 +               if (IS_BARRIER(inode)) {
2864 +                       vxwprintk_task(1, "messing with the barrier.");
2865 +                       return -EACCES;
2866 +               }
2867 +
2868                 mutex_lock(&inode->i_mutex);
2869  
2870                 /* Is it quota file? Do not allow user to mess with it */
2871 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2872                  *
2873                  * This test looks nicer. Thanks to Pauline Middelink
2874                  */
2875 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2876 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2877 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2878 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2879                         if (!capable(CAP_LINUX_IMMUTABLE))
2880                                 goto flags_out;
2881                 }
2882 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2883                 if (err)
2884                         goto flags_err;
2885  
2886 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2887 +               flags &= EXT3_FL_USER_MODIFIABLE;
2888                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2889                 ei->i_flags = flags;
2890  
2891 diff -NurpP --minimal linux-3.7.1/fs/ext3/namei.c linux-3.7.1-vs2.3.5.5/fs/ext3/namei.c
2892 --- linux-3.7.1/fs/ext3/namei.c 2012-12-11 03:30:57.000000000 +0000
2893 +++ linux-3.7.1-vs2.3.5.5/fs/ext3/namei.c       2012-12-18 15:13:16.000000000 +0000
2894 @@ -25,6 +25,8 @@
2895   */
2896  
2897  #include <linux/quotaops.h>
2898 +#include <linux/vs_tag.h>
2899 +
2900  #include "ext3.h"
2901  #include "namei.h"
2902  #include "xattr.h"
2903 @@ -919,6 +921,7 @@ restart:
2904                                         submit_bh(READ | REQ_META | REQ_PRIO,
2905                                                   bh);
2906                                 }
2907 +               dx_propagate_tag(nd, inode);
2908                         }
2909                 }
2910                 if ((bh = bh_use[ra_ptr++]) == NULL)
2911 @@ -2528,6 +2531,7 @@ const struct inode_operations ext3_dir_i
2912         .listxattr      = ext3_listxattr,
2913         .removexattr    = generic_removexattr,
2914  #endif
2915 +       .sync_flags     = ext3_sync_flags,
2916         .get_acl        = ext3_get_acl,
2917  };
2918  
2919 diff -NurpP --minimal linux-3.7.1/fs/ext3/super.c linux-3.7.1-vs2.3.5.5/fs/ext3/super.c
2920 --- linux-3.7.1/fs/ext3/super.c 2012-12-11 03:30:57.000000000 +0000
2921 +++ linux-3.7.1-vs2.3.5.5/fs/ext3/super.c       2012-12-18 15:13:16.000000000 +0000
2922 @@ -816,7 +816,8 @@ enum {
2923         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2924         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2925         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2926 -       Opt_resize, Opt_usrquota, Opt_grpquota
2927 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2928 +       Opt_tag, Opt_notag, Opt_tagid
2929  };
2930  
2931  static const match_table_t tokens = {
2932 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2933         {Opt_barrier, "barrier"},
2934         {Opt_nobarrier, "nobarrier"},
2935         {Opt_resize, "resize"},
2936 +       {Opt_tag, "tag"},
2937 +       {Opt_notag, "notag"},
2938 +       {Opt_tagid, "tagid=%u"},
2939         {Opt_err, NULL},
2940  };
2941  
2942 @@ -1038,6 +1042,20 @@ static int parse_options (char *options,
2943                 case Opt_nouid32:
2944                         set_opt (sbi->s_mount_opt, NO_UID32);
2945                         break;
2946 +#ifndef CONFIG_TAGGING_NONE
2947 +               case Opt_tag:
2948 +                       set_opt (sbi->s_mount_opt, TAGGED);
2949 +                       break;
2950 +               case Opt_notag:
2951 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2952 +                       break;
2953 +#endif
2954 +#ifdef CONFIG_PROPAGATE
2955 +               case Opt_tagid:
2956 +                       /* use args[0] */
2957 +                       set_opt (sbi->s_mount_opt, TAGGED);
2958 +                       break;
2959 +#endif
2960                 case Opt_nocheck:
2961                         clear_opt (sbi->s_mount_opt, CHECK);
2962                         break;
2963 @@ -1738,6 +1756,9 @@ static int ext3_fill_super (struct super
2964                             NULL, 0))
2965                 goto failed_mount;
2966  
2967 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2968 +               sb->s_flags |= MS_TAGGED;
2969 +
2970         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2971                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2972  
2973 @@ -2622,6 +2643,14 @@ static int ext3_remount (struct super_bl
2974         if (test_opt(sb, ABORT))
2975                 ext3_abort(sb, __func__, "Abort forced by user");
2976  
2977 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2978 +               !(sb->s_flags & MS_TAGGED)) {
2979 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2980 +                       sb->s_id);
2981 +               err = -EINVAL;
2982 +               goto restore_opts;
2983 +       }
2984 +
2985         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2986                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2987  
2988 diff -NurpP --minimal linux-3.7.1/fs/ext4/ext4.h linux-3.7.1-vs2.3.5.5/fs/ext4/ext4.h
2989 --- linux-3.7.1/fs/ext4/ext4.h  2012-12-11 03:30:57.000000000 +0000
2990 +++ linux-3.7.1-vs2.3.5.5/fs/ext4/ext4.h        2012-12-18 15:13:16.000000000 +0000
2991 @@ -392,8 +392,12 @@ struct flex_groups {
2992  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2993  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2994  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2995 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2996  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2997  
2998 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2999 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3000 +
3001  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3002  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3003  
3004 @@ -665,7 +669,7 @@ struct ext4_inode {
3005                         __le16  l_i_uid_high;   /* these 2 fields */
3006                         __le16  l_i_gid_high;   /* were reserved2[0] */
3007                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
3008 -                       __le16  l_i_reserved;
3009 +                       __le16  l_i_tag;        /* Context Tag */
3010                 } linux2;
3011                 struct {
3012                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3013 @@ -783,6 +787,7 @@ do {                                                                               \
3014  #define i_gid_low      i_gid
3015  #define i_uid_high     osd2.linux2.l_i_uid_high
3016  #define i_gid_high     osd2.linux2.l_i_gid_high
3017 +#define i_raw_tag      osd2.linux2.l_i_tag
3018  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
3019  
3020  #elif defined(__GNU__)
3021 @@ -961,6 +966,7 @@ struct ext4_inode_info {
3022  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3023  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3024  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3025 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3026  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3027  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3028  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3029 @@ -2412,6 +2418,7 @@ extern int ext4_map_blocks(handle_t *han
3030                            struct ext4_map_blocks *map, int flags);
3031  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3032                         __u64 start, __u64 len);
3033 +extern int ext4_sync_flags(struct inode *, int, int);
3034  /* move_extent.c */
3035  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3036                              __u64 start_orig, __u64 start_donor,
3037 diff -NurpP --minimal linux-3.7.1/fs/ext4/file.c linux-3.7.1-vs2.3.5.5/fs/ext4/file.c
3038 --- linux-3.7.1/fs/ext4/file.c  2012-12-11 03:30:57.000000000 +0000
3039 +++ linux-3.7.1-vs2.3.5.5/fs/ext4/file.c        2012-12-18 15:13:16.000000000 +0000
3040 @@ -334,5 +334,6 @@ const struct inode_operations ext4_file_
3041  #endif
3042         .get_acl        = ext4_get_acl,
3043         .fiemap         = ext4_fiemap,
3044 +       .sync_flags     = ext4_sync_flags,
3045  };
3046  
3047 diff -NurpP --minimal linux-3.7.1/fs/ext4/ialloc.c linux-3.7.1-vs2.3.5.5/fs/ext4/ialloc.c
3048 --- linux-3.7.1/fs/ext4/ialloc.c        2012-12-11 03:30:57.000000000 +0000
3049 +++ linux-3.7.1-vs2.3.5.5/fs/ext4/ialloc.c      2012-12-18 15:13:16.000000000 +0000
3050 @@ -22,6 +22,7 @@
3051  #include <linux/random.h>
3052  #include <linux/bitops.h>
3053  #include <linux/blkdev.h>
3054 +#include <linux/vs_tag.h>
3055  #include <asm/byteorder.h>
3056  
3057  #include "ext4.h"
3058 @@ -848,6 +849,7 @@ got:
3059                 inode->i_mode = mode;
3060                 inode->i_uid = current_fsuid();
3061                 inode->i_gid = dir->i_gid;
3062 +               inode->i_tag = dx_current_fstag(sb);
3063         } else
3064                 inode_init_owner(inode, dir, mode);
3065  
3066 diff -NurpP --minimal linux-3.7.1/fs/ext4/inode.c linux-3.7.1-vs2.3.5.5/fs/ext4/inode.c
3067 --- linux-3.7.1/fs/ext4/inode.c 2012-12-11 03:30:57.000000000 +0000
3068 +++ linux-3.7.1-vs2.3.5.5/fs/ext4/inode.c       2012-12-18 15:13:16.000000000 +0000
3069 @@ -37,6 +37,7 @@
3070  #include <linux/printk.h>
3071  #include <linux/slab.h>
3072  #include <linux/ratelimit.h>
3073 +#include <linux/vs_tag.h>
3074  
3075  #include "ext4_jbd2.h"
3076  #include "xattr.h"
3077 @@ -3695,41 +3696,64 @@ void ext4_set_inode_flags(struct inode *
3078  {
3079         unsigned int flags = EXT4_I(inode)->i_flags;
3080  
3081 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3082 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3083 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3084 +
3085 +       if (flags & EXT4_IMMUTABLE_FL)
3086 +               inode->i_flags |= S_IMMUTABLE;
3087 +       if (flags & EXT4_IXUNLINK_FL)
3088 +               inode->i_flags |= S_IXUNLINK;
3089 +
3090         if (flags & EXT4_SYNC_FL)
3091                 inode->i_flags |= S_SYNC;
3092         if (flags & EXT4_APPEND_FL)
3093                 inode->i_flags |= S_APPEND;
3094 -       if (flags & EXT4_IMMUTABLE_FL)
3095 -               inode->i_flags |= S_IMMUTABLE;
3096         if (flags & EXT4_NOATIME_FL)
3097                 inode->i_flags |= S_NOATIME;
3098         if (flags & EXT4_DIRSYNC_FL)
3099                 inode->i_flags |= S_DIRSYNC;
3100 +
3101 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3102 +
3103 +       if (flags & EXT4_BARRIER_FL)
3104 +               inode->i_vflags |= V_BARRIER;
3105 +       if (flags & EXT4_COW_FL)
3106 +               inode->i_vflags |= V_COW;
3107  }
3108  
3109  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3110  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3111  {
3112 -       unsigned int vfs_fl;
3113 +       unsigned int vfs_fl, vfs_vf;
3114         unsigned long old_fl, new_fl;
3115  
3116         do {
3117                 vfs_fl = ei->vfs_inode.i_flags;
3118 +               vfs_vf = ei->vfs_inode.i_vflags;
3119                 old_fl = ei->i_flags;
3120                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3121                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3122 -                               EXT4_DIRSYNC_FL);
3123 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3124 +                               EXT4_COW_FL);
3125 +
3126 +               if (vfs_fl & S_IMMUTABLE)
3127 +                       new_fl |= EXT4_IMMUTABLE_FL;
3128 +               if (vfs_fl & S_IXUNLINK)
3129 +                       new_fl |= EXT4_IXUNLINK_FL;
3130 +
3131                 if (vfs_fl & S_SYNC)
3132                         new_fl |= EXT4_SYNC_FL;
3133                 if (vfs_fl & S_APPEND)
3134                         new_fl |= EXT4_APPEND_FL;
3135 -               if (vfs_fl & S_IMMUTABLE)
3136 -                       new_fl |= EXT4_IMMUTABLE_FL;
3137                 if (vfs_fl & S_NOATIME)
3138                         new_fl |= EXT4_NOATIME_FL;
3139                 if (vfs_fl & S_DIRSYNC)
3140                         new_fl |= EXT4_DIRSYNC_FL;
3141 +
3142 +               if (vfs_vf & V_BARRIER)
3143 +                       new_fl |= EXT4_BARRIER_FL;
3144 +               if (vfs_vf & V_COW)
3145 +                       new_fl |= EXT4_COW_FL;
3146         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3147  }
3148  
3149 @@ -3821,8 +3845,10 @@ struct inode *ext4_iget(struct super_blo
3150                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3151                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3152         }
3153 -       i_uid_write(inode, i_uid);
3154 -       i_gid_write(inode, i_gid);
3155 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3156 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3157 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3158 +               le16_to_cpu(raw_inode->i_raw_tag)));
3159         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3160  
3161         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3162 @@ -4046,8 +4072,10 @@ static int ext4_do_update_inode(handle_t
3163  
3164         ext4_get_inode_flags(ei);
3165         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3166 -       i_uid = i_uid_read(inode);
3167 -       i_gid = i_gid_read(inode);
3168 +       i_uid = TAGINO_UID(DX_TAG(inode),
3169 +               i_uid_read(inode), i_tag_read(inode));
3170 +       i_gid = TAGINO_GID(DX_TAG(inode),
3171 +               i_gid_read(inode), i_tag_read(inode));
3172         if (!(test_opt(inode->i_sb, NO_UID32))) {
3173                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3174                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3175 @@ -4070,6 +4098,9 @@ static int ext4_do_update_inode(handle_t
3176                 raw_inode->i_uid_high = 0;
3177                 raw_inode->i_gid_high = 0;
3178         }
3179 +#ifdef CONFIG_TAGGING_INTERN
3180 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3181 +#endif
3182         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3183  
3184         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3185 @@ -4258,7 +4289,8 @@ int ext4_setattr(struct dentry *dentry,
3186         if (is_quota_modification(inode, attr))
3187                 dquot_initialize(inode);
3188         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3189 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3190 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3191 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3192                 handle_t *handle;
3193  
3194                 /* (user+group)*(old+new) structure, inode write (sb,
3195 @@ -4280,6 +4312,8 @@ int ext4_setattr(struct dentry *dentry,
3196                         inode->i_uid = attr->ia_uid;
3197                 if (attr->ia_valid & ATTR_GID)
3198                         inode->i_gid = attr->ia_gid;
3199 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3200 +                       inode->i_tag = attr->ia_tag;
3201                 error = ext4_mark_inode_dirty(handle, inode);
3202                 ext4_journal_stop(handle);
3203         }
3204 diff -NurpP --minimal linux-3.7.1/fs/ext4/ioctl.c linux-3.7.1-vs2.3.5.5/fs/ext4/ioctl.c
3205 --- linux-3.7.1/fs/ext4/ioctl.c 2012-12-11 03:30:57.000000000 +0000
3206 +++ linux-3.7.1-vs2.3.5.5/fs/ext4/ioctl.c       2012-12-18 15:13:16.000000000 +0000
3207 @@ -14,12 +14,40 @@
3208  #include <linux/compat.h>
3209  #include <linux/mount.h>
3210  #include <linux/file.h>
3211 +#include <linux/vs_tag.h>
3212  #include <asm/uaccess.h>
3213  #include "ext4_jbd2.h"
3214  #include "ext4.h"
3215  
3216  #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3217  
3218 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3219 +{
3220 +       handle_t *handle = NULL;
3221 +       struct ext4_iloc iloc;
3222 +       int err;
3223 +
3224 +       handle = ext4_journal_start(inode, 1);
3225 +       if (IS_ERR(handle))
3226 +               return PTR_ERR(handle);
3227 +
3228 +       if (IS_SYNC(inode))
3229 +               ext4_handle_sync(handle);
3230 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3231 +       if (err)
3232 +               goto flags_err;
3233 +
3234 +       inode->i_flags = flags;
3235 +       inode->i_vflags = vflags;
3236 +       ext4_get_inode_flags(EXT4_I(inode));
3237 +       inode->i_ctime = ext4_current_time(inode);
3238 +
3239 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3240 +flags_err:
3241 +       ext4_journal_stop(handle);
3242 +       return err;
3243 +}
3244 +
3245  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3246  {
3247         struct inode *inode = filp->f_dentry->d_inode;
3248 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3249  
3250                 flags = ext4_mask_flags(inode->i_mode, flags);
3251  
3252 +               if (IS_BARRIER(inode)) {
3253 +                       vxwprintk_task(1, "messing with the barrier.");
3254 +                       return -EACCES;
3255 +               }
3256 +
3257                 err = -EPERM;
3258                 mutex_lock(&inode->i_mutex);
3259                 /* Is it quota file? Do not allow user to mess with it */
3260 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3261                  *
3262                  * This test looks nicer. Thanks to Pauline Middelink
3263                  */
3264 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3265 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3266 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3267 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3268                         if (!capable(CAP_LINUX_IMMUTABLE))
3269                                 goto flags_out;
3270                 }
3271 diff -NurpP --minimal linux-3.7.1/fs/ext4/namei.c linux-3.7.1-vs2.3.5.5/fs/ext4/namei.c
3272 --- linux-3.7.1/fs/ext4/namei.c 2012-12-11 03:30:57.000000000 +0000
3273 +++ linux-3.7.1-vs2.3.5.5/fs/ext4/namei.c       2012-12-18 15:13:16.000000000 +0000
3274 @@ -34,6 +34,7 @@
3275  #include <linux/quotaops.h>
3276  #include <linux/buffer_head.h>
3277  #include <linux/bio.h>
3278 +#include <linux/vs_tag.h>
3279  #include "ext4.h"
3280  #include "ext4_jbd2.h"
3281  
3282 @@ -1232,6 +1233,7 @@ restart:
3283                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3284                                                     1, &bh);
3285                         }
3286 +               dx_propagate_tag(nd, inode);
3287                 }
3288                 if ((bh = bh_use[ra_ptr++]) == NULL)
3289                         goto next;
3290 @@ -3051,6 +3053,7 @@ const struct inode_operations ext4_dir_i
3291  #endif
3292         .get_acl        = ext4_get_acl,
3293         .fiemap         = ext4_fiemap,
3294 +       .sync_flags     = ext4_sync_flags,
3295  };
3296  
3297  const struct inode_operations ext4_special_inode_operations = {
3298 diff -NurpP --minimal linux-3.7.1/fs/ext4/super.c linux-3.7.1-vs2.3.5.5/fs/ext4/super.c
3299 --- linux-3.7.1/fs/ext4/super.c 2012-12-11 03:30:57.000000000 +0000
3300 +++ linux-3.7.1-vs2.3.5.5/fs/ext4/super.c       2012-12-18 15:13:16.000000000 +0000
3301 @@ -1222,7 +1222,7 @@ enum {
3302         Opt_inode_readahead_blks, Opt_journal_ioprio,
3303         Opt_dioread_nolock, Opt_dioread_lock,
3304         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3305 -       Opt_max_dir_size_kb,
3306 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3307  };
3308  
3309  static const match_table_t tokens = {
3310 @@ -1302,6 +1302,9 @@ static const match_table_t tokens = {
3311         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3312         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3313         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3314 +       {Opt_tag, "tag"},
3315 +       {Opt_notag, "notag"},
3316 +       {Opt_tagid, "tagid=%u"},
3317         {Opt_err, NULL},
3318  };
3319  
3320 @@ -1549,6 +1552,20 @@ static int handle_mount_opt(struct super
3321                         return -1;
3322                 *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, arg);
3323                 return 1;
3324 +#ifndef CONFIG_TAGGING_NONE
3325 +       case Opt_tag:
3326 +               set_opt(sb, TAGGED);
3327 +               return 1;
3328 +       case Opt_notag:
3329 +               clear_opt(sb, TAGGED);
3330 +               return 1;
3331 +#endif
3332 +#ifdef CONFIG_PROPAGATE
3333 +       case Opt_tagid:
3334 +               /* use args[0] */
3335 +               set_opt(sb, TAGGED);
3336 +               return 1;
3337 +#endif
3338         }
3339  
3340         for (m = ext4_mount_opts; m->token != Opt_err; m++) {
3341 @@ -3455,6 +3472,9 @@ static int ext4_fill_super(struct super_
3342                 }
3343         }
3344  
3345 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3346 +               sb->s_flags |= MS_TAGGED;
3347 +
3348         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3349                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3350  
3351 @@ -4618,6 +4638,14 @@ static int ext4_remount(struct super_blo
3352         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3353                 ext4_abort(sb, "Abort forced by user");
3354  
3355 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3356 +               !(sb->s_flags & MS_TAGGED)) {
3357 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3358 +                       sb->s_id);
3359 +               err = -EINVAL;
3360 +               goto restore_opts;
3361 +       }
3362 +
3363         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3364                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3365  
3366 diff -NurpP --minimal linux-3.7.1/fs/fcntl.c linux-3.7.1-vs2.3.5.5/fs/fcntl.c
3367 --- linux-3.7.1/fs/fcntl.c      2012-12-11 03:30:57.000000000 +0000
3368 +++ linux-3.7.1-vs2.3.5.5/fs/fcntl.c    2012-12-18 15:13:16.000000000 +0000
3369 @@ -21,6 +21,7 @@
3370  #include <linux/rcupdate.h>
3371  #include <linux/pid_namespace.h>
3372  #include <linux/user_namespace.h>
3373 +#include <linux/vs_limit.h>
3374  
3375  #include <asm/poll.h>
3376  #include <asm/siginfo.h>
3377 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3378  
3379         if (!f.file)
3380                 goto out;
3381 +       if (!vx_files_avail(1))
3382 +               goto out;
3383  
3384         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3385                 if (!check_fcntl_cmd(cmd))
3386 diff -NurpP --minimal linux-3.7.1/fs/file.c linux-3.7.1-vs2.3.5.5/fs/file.c
3387 --- linux-3.7.1/fs/file.c       2012-12-11 03:30:57.000000000 +0000
3388 +++ linux-3.7.1-vs2.3.5.5/fs/file.c     2012-12-18 15:13:16.000000000 +0000
3389 @@ -22,6 +22,7 @@
3390  #include <linux/spinlock.h>
3391  #include <linux/rcupdate.h>
3392  #include <linux/workqueue.h>
3393 +#include <linux/vs_limit.h>
3394  
3395  struct fdtable_defer {
3396         spinlock_t lock;
3397 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3398                 struct file *f = *old_fds++;
3399                 if (f) {
3400                         get_file(f);
3401 +                       /* TODO: sum it first for check and performance */
3402 +                       vx_openfd_inc(open_files - i);
3403                 } else {
3404                         /*
3405                          * The fd may be claimed in the fd bitmap but not yet
3406 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3407                                         filp_close(file, files);
3408                                         cond_resched();
3409                                 }
3410 +                               vx_openfd_dec(i);
3411                         }
3412                         i++;
3413                         set >>= 1;
3414 +                       cond_resched();
3415                 }
3416         }
3417  }
3418 @@ -573,6 +578,7 @@ repeat:
3419         else
3420                 __clear_close_on_exec(fd, fdt);
3421         error = fd;
3422 +       vx_openfd_inc(fd);
3423  #if 1
3424         /* Sanity check */
3425         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3426 @@ -603,6 +609,7 @@ static void __put_unused_fd(struct files
3427         __clear_open_fd(fd, fdt);
3428         if (fd < files->next_fd)
3429                 files->next_fd = fd;
3430 +       vx_openfd_dec(fd);
3431  }
3432  
3433  void put_unused_fd(unsigned int fd)
3434 @@ -882,6 +889,8 @@ static int do_dup2(struct files_struct *
3435  
3436         if (tofree)
3437                 filp_close(tofree, files);
3438 +       else
3439 +               vx_openfd_inc(fd);      /* fd was unused */
3440  
3441         return fd;
3442  
3443 diff -NurpP --minimal linux-3.7.1/fs/file_table.c linux-3.7.1-vs2.3.5.5/fs/file_table.c
3444 --- linux-3.7.1/fs/file_table.c 2012-12-11 03:30:57.000000000 +0000
3445 +++ linux-3.7.1-vs2.3.5.5/fs/file_table.c       2012-12-18 15:13:16.000000000 +0000
3446 @@ -26,6 +26,8 @@
3447  #include <linux/hardirq.h>
3448  #include <linux/task_work.h>
3449  #include <linux/ima.h>
3450 +#include <linux/vs_limit.h>
3451 +#include <linux/vs_context.h>
3452  
3453  #include <linux/atomic.h>
3454  
3455 @@ -136,6 +138,8 @@ struct file *get_empty_filp(void)
3456         spin_lock_init(&f->f_lock);
3457         eventpoll_init_file(f);
3458         /* f->f_version: 0 */
3459 +       f->f_xid = vx_current_xid();
3460 +       vx_files_inc(f);
3461         return f;
3462  
3463  over:
3464 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3465                 i_readcount_dec(inode);
3466         if (file->f_mode & FMODE_WRITE)
3467                 drop_file_write_access(file);
3468 +       vx_files_dec(file);
3469 +       file->f_xid = 0;
3470         file->f_path.dentry = NULL;
3471         file->f_path.mnt = NULL;
3472         file_free(file);
3473 @@ -343,6 +349,8 @@ void put_filp(struct file *file)
3474  {
3475         if (atomic_long_dec_and_test(&file->f_count)) {
3476                 security_file_free(file);
3477 +               vx_files_dec(file);
3478 +               file->f_xid = 0;
3479                 file_sb_list_del(file);
3480                 file_free(file);
3481         }
3482 diff -NurpP --minimal linux-3.7.1/fs/fs_struct.c linux-3.7.1-vs2.3.5.5/fs/fs_struct.c
3483 --- linux-3.7.1/fs/fs_struct.c  2012-12-11 03:30:57.000000000 +0000
3484 +++ linux-3.7.1-vs2.3.5.5/fs/fs_struct.c        2012-12-18 15:13:16.000000000 +0000
3485 @@ -4,6 +4,7 @@
3486  #include <linux/path.h>
3487  #include <linux/slab.h>
3488  #include <linux/fs_struct.h>
3489 +#include <linux/vserver/global.h>
3490  #include "internal.h"
3491  
3492  /*
3493 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3494  {
3495         path_put(&fs->root);
3496         path_put(&fs->pwd);
3497 +       atomic_dec(&vs_global_fs);
3498         kmem_cache_free(fs_cachep, fs);
3499  }
3500  
3501 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3502                 fs->pwd = old->pwd;
3503                 path_get(&fs->pwd);
3504                 spin_unlock(&old->lock);
3505 +               atomic_inc(&vs_global_fs);
3506         }
3507         return fs;
3508  }
3509 diff -NurpP --minimal linux-3.7.1/fs/gfs2/file.c linux-3.7.1-vs2.3.5.5/fs/gfs2/file.c
3510 --- linux-3.7.1/fs/gfs2/file.c  2012-12-11 03:30:57.000000000 +0000
3511 +++ linux-3.7.1-vs2.3.5.5/fs/gfs2/file.c        2012-12-18 15:13:16.000000000 +0000
3512 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3513         [12] = GFS2_DIF_EXHASH,
3514         [14] = GFS2_DIF_INHERIT_JDATA,
3515         [17] = GFS2_DIF_TOPDIR,
3516 +       [27] = GFS2_DIF_IXUNLINK,
3517 +       [26] = GFS2_DIF_BARRIER,
3518 +       [29] = GFS2_DIF_COW,
3519  };
3520  
3521  static const u32 gfs2_to_fsflags[32] = {
3522 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3523         [gfs2fl_ExHash] = FS_INDEX_FL,
3524         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3525         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3526 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3527 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3528 +       [gfs2fl_Cow] = FS_COW_FL,
3529  };
3530  
3531  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3532 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3533  {
3534         struct gfs2_inode *ip = GFS2_I(inode);
3535         unsigned int flags = inode->i_flags;
3536 +       unsigned int vflags = inode->i_vflags;
3537 +
3538 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3539 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3540  
3541 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3542         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3543                 inode->i_flags |= S_NOSEC;
3544         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3545                 flags |= S_IMMUTABLE;
3546 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3547 +               flags |= S_IXUNLINK;
3548 +
3549         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3550                 flags |= S_APPEND;
3551         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3552 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3553         if (ip->i_diskflags & GFS2_DIF_SYNC)
3554                 flags |= S_SYNC;
3555         inode->i_flags = flags;
3556 +
3557 +       vflags &= ~(V_BARRIER | V_COW);
3558 +
3559 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3560 +               vflags |= V_BARRIER;
3561 +       if (ip->i_diskflags & GFS2_DIF_COW)
3562 +               vflags |= V_COW;
3563 +       inode->i_vflags = vflags;
3564 +}
3565 +
3566 +void gfs2_get_inode_flags(struct inode *inode)
3567 +{
3568 +       struct gfs2_inode *ip = GFS2_I(inode);
3569 +       unsigned int flags = inode->i_flags;
3570 +       unsigned int vflags = inode->i_vflags;
3571 +
3572 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3573 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3574 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3575 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3576 +
3577 +       if (flags & S_IMMUTABLE)
3578 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3579 +       if (flags & S_IXUNLINK)
3580 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3581 +
3582 +       if (flags & S_APPEND)
3583 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3584 +       if (flags & S_NOATIME)
3585 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3586 +       if (flags & S_SYNC)
3587 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3588 +
3589 +       if (vflags & V_BARRIER)
3590 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3591 +       if (vflags & V_COW)
3592 +               ip->i_diskflags |= GFS2_DIF_COW;
3593  }
3594  
3595  /* Flags that can be set by user space */
3596 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3597         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3598  }
3599  
3600 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3601 +{
3602 +       struct gfs2_inode *ip = GFS2_I(inode);
3603 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3604 +       struct buffer_head *bh;
3605 +       struct gfs2_holder gh;
3606 +       int error;
3607 +
3608 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3609 +       if (error)
3610 +               return error;
3611 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3612 +       if (error)
3613 +               goto out;
3614 +       error = gfs2_meta_inode_buffer(ip, &bh);
3615 +       if (error)
3616 +               goto out_trans_end;
3617 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3618 +       inode->i_flags = flags;
3619 +       inode->i_vflags = vflags;
3620 +       gfs2_get_inode_flags(inode);
3621 +       gfs2_dinode_out(ip, bh->b_data);
3622 +       brelse(bh);
3623 +       gfs2_set_aops(inode);
3624 +out_trans_end:
3625 +       gfs2_trans_end(sdp);
3626 +out:
3627 +       gfs2_glock_dq_uninit(&gh);
3628 +       return error;
3629 +}
3630 +
3631  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3632  {
3633         switch(cmd) {
3634 diff -NurpP --minimal linux-3.7.1/fs/gfs2/inode.h linux-3.7.1-vs2.3.5.5/fs/gfs2/inode.h
3635 --- linux-3.7.1/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3636 +++ linux-3.7.1-vs2.3.5.5/fs/gfs2/inode.h       2012-12-18 15:13:16.000000000 +0000
3637 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3638  extern const struct file_operations gfs2_dir_fops_nolock;
3639  
3640  extern void gfs2_set_inode_flags(struct inode *inode);
3641 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3642   
3643  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3644  extern const struct file_operations gfs2_file_fops;
3645 diff -NurpP --minimal linux-3.7.1/fs/hostfs/hostfs.h linux-3.7.1-vs2.3.5.5/fs/hostfs/hostfs.h
3646 --- linux-3.7.1/fs/hostfs/hostfs.h      2012-12-11 03:30:57.000000000 +0000
3647 +++ linux-3.7.1-vs2.3.5.5/fs/hostfs/hostfs.h    2012-12-18 15:13:16.000000000 +0000
3648 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3649         unsigned short  ia_mode;
3650         uid_t           ia_uid;
3651         gid_t           ia_gid;
3652 +       tag_t           ia_tag;
3653         loff_t          ia_size;
3654         struct timespec ia_atime;
3655         struct timespec ia_mtime;
3656 diff -NurpP --minimal linux-3.7.1/fs/inode.c linux-3.7.1-vs2.3.5.5/fs/inode.c
3657 --- linux-3.7.1/fs/inode.c      2012-12-11 03:30:57.000000000 +0000
3658 +++ linux-3.7.1-vs2.3.5.5/fs/inode.c    2012-12-18 15:13:16.000000000 +0000
3659 @@ -17,6 +17,7 @@
3660  #include <linux/prefetch.h>
3661  #include <linux/buffer_head.h> /* for inode_has_buffers */
3662  #include <linux/ratelimit.h>
3663 +#include <linux/vs_tag.h>
3664  #include "internal.h"
3665  
3666  /*
3667 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3668         struct address_space *const mapping = &inode->i_data;
3669  
3670         inode->i_sb = sb;
3671 +
3672 +       /* essential because of inode slab reuse */
3673         inode->i_blkbits = sb->s_blocksize_bits;
3674         inode->i_flags = 0;
3675         atomic_set(&inode->i_count, 1);
3676 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3677         inode->i_opflags = 0;
3678         i_uid_write(inode, 0);
3679         i_gid_write(inode, 0);
3680 +       i_tag_write(inode, 0);
3681         atomic_set(&inode->i_writecount, 0);
3682         inode->i_size = 0;
3683         inode->i_blocks = 0;
3684 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3685         inode->i_bdev = NULL;
3686         inode->i_cdev = NULL;
3687         inode->i_rdev = 0;
3688 +       inode->i_mdev = 0;
3689         inode->dirtied_when = 0;
3690  
3691         if (security_inode_alloc(inode))
3692 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3693  }
3694  EXPORT_SYMBOL(__insert_inode_hash);
3695  
3696 +EXPORT_SYMBOL_GPL(__iget);
3697 +
3698  /**
3699   *     __remove_inode_hash - remove an inode from the hash
3700   *     @inode: inode to unhash
3701 @@ -1804,9 +1811,11 @@ void init_special_inode(struct inode *in
3702         if (S_ISCHR(mode)) {
3703                 inode->i_fop = &def_chr_fops;
3704                 inode->i_rdev = rdev;
3705 +               inode->i_mdev = rdev;
3706         } else if (S_ISBLK(mode)) {
3707                 inode->i_fop = &def_blk_fops;
3708                 inode->i_rdev = rdev;
3709 +               inode->i_mdev = rdev;
3710         } else if (S_ISFIFO(mode))
3711                 inode->i_fop = &def_fifo_fops;
3712         else if (S_ISSOCK(mode))
3713 @@ -1835,6 +1844,7 @@ void inode_init_owner(struct inode *inod
3714         } else
3715                 inode->i_gid = current_fsgid();
3716         inode->i_mode = mode;
3717 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3718  }
3719  EXPORT_SYMBOL(inode_init_owner);
3720  
3721 diff -NurpP --minimal linux-3.7.1/fs/ioctl.c linux-3.7.1-vs2.3.5.5/fs/ioctl.c
3722 --- linux-3.7.1/fs/ioctl.c      2012-12-11 03:30:57.000000000 +0000
3723 +++ linux-3.7.1-vs2.3.5.5/fs/ioctl.c    2012-12-18 15:13:16.000000000 +0000
3724 @@ -15,6 +15,9 @@
3725  #include <linux/writeback.h>
3726  #include <linux/buffer_head.h>
3727  #include <linux/falloc.h>
3728 +#include <linux/proc_fs.h>
3729 +#include <linux/vserver/inode.h>
3730 +#include <linux/vs_tag.h>
3731  
3732  #include <asm/ioctls.h>
3733  
3734 diff -NurpP --minimal linux-3.7.1/fs/ioprio.c linux-3.7.1-vs2.3.5.5/fs/ioprio.c
3735 --- linux-3.7.1/fs/ioprio.c     2012-12-11 03:30:57.000000000 +0000
3736 +++ linux-3.7.1-vs2.3.5.5/fs/ioprio.c   2012-12-18 15:13:16.000000000 +0000
3737 @@ -28,6 +28,7 @@
3738  #include <linux/syscalls.h>
3739  #include <linux/security.h>
3740  #include <linux/pid_namespace.h>
3741 +#include <linux/vs_base.h>
3742  
3743  int set_task_ioprio(struct task_struct *task, int ioprio)
3744  {
3745 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3746                         else
3747                                 pgrp = find_vpid(who);
3748                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3749 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3750 +                                       continue;
3751                                 ret = set_task_ioprio(p, ioprio);
3752                                 if (ret)
3753                                         break;
3754 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3755                         else
3756                                 pgrp = find_vpid(who);
3757                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3758 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3759 +                                       continue;
3760                                 tmpio = get_task_ioprio(p);
3761                                 if (tmpio < 0)
3762                                         continue;
3763 diff -NurpP --minimal linux-3.7.1/fs/jfs/file.c linux-3.7.1-vs2.3.5.5/fs/jfs/file.c
3764 --- linux-3.7.1/fs/jfs/file.c   2012-12-11 03:30:57.000000000 +0000
3765 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/file.c 2012-12-18 15:13:16.000000000 +0000
3766 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3767         if (is_quota_modification(inode, iattr))
3768                 dquot_initialize(inode);
3769         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3770 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3771 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3772 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3773                 rc = dquot_transfer(inode, iattr);
3774                 if (rc)
3775                         return rc;
3776 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3777  #ifdef CONFIG_JFS_POSIX_ACL
3778         .get_acl        = jfs_get_acl,
3779  #endif
3780 +       .sync_flags     = jfs_sync_flags,
3781  };
3782  
3783  const struct file_operations jfs_file_operations = {
3784 diff -NurpP --minimal linux-3.7.1/fs/jfs/ioctl.c linux-3.7.1-vs2.3.5.5/fs/jfs/ioctl.c
3785 --- linux-3.7.1/fs/jfs/ioctl.c  2012-12-11 03:30:57.000000000 +0000
3786 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/ioctl.c        2012-12-18 15:13:16.000000000 +0000
3787 @@ -12,6 +12,7 @@
3788  #include <linux/time.h>
3789  #include <linux/sched.h>
3790  #include <linux/blkdev.h>
3791 +#include <linux/mount.h>
3792  #include <asm/current.h>
3793  #include <asm/uaccess.h>
3794  
3795 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3796  }
3797  
3798  
3799 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3800 +{
3801 +       inode->i_flags = flags;
3802 +       inode->i_vflags = vflags;
3803 +       jfs_get_inode_flags(JFS_IP(inode));
3804 +       inode->i_ctime = CURRENT_TIME_SEC;
3805 +       mark_inode_dirty(inode);
3806 +       return 0;
3807 +}
3808 +
3809  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3810  {
3811         struct inode *inode = filp->f_dentry->d_inode;
3812 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3813                 if (!S_ISDIR(inode->i_mode))
3814                         flags &= ~JFS_DIRSYNC_FL;
3815  
3816 +               if (IS_BARRIER(inode)) {
3817 +                       vxwprintk_task(1, "messing with the barrier.");
3818 +                       return -EACCES;
3819 +               }
3820 +
3821                 /* Is it quota file? Do not allow user to mess with it */
3822                 if (IS_NOQUOTA(inode)) {
3823                         err = -EPERM;
3824 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3825                  * the relevant capability.
3826                  */
3827                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3828 -                       ((flags ^ oldflags) &
3829 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3830 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3831 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3832                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3833                                 mutex_unlock(&inode->i_mutex);
3834                                 err = -EPERM;
3835 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3836                         }
3837                 }
3838  
3839 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3840 +               flags &= JFS_FL_USER_MODIFIABLE;
3841                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3842                 jfs_inode->mode2 = flags;
3843  
3844 diff -NurpP --minimal linux-3.7.1/fs/jfs/jfs_dinode.h linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_dinode.h
3845 --- linux-3.7.1/fs/jfs/jfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
3846 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_dinode.h   2012-12-18 15:13:16.000000000 +0000
3847 @@ -161,9 +161,13 @@ struct dinode {
3848  
3849  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3850  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3851 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3852  
3853 -#define JFS_FL_USER_VISIBLE    0x03F80000
3854 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3855 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3856 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3857 +
3858 +#define JFS_FL_USER_VISIBLE    0x07F80000
3859 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3860  #define JFS_FL_INHERIT         0x03C80000
3861  
3862  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3863 diff -NurpP --minimal linux-3.7.1/fs/jfs/jfs_filsys.h linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_filsys.h
3864 --- linux-3.7.1/fs/jfs/jfs_filsys.h     2012-12-11 03:30:57.000000000 +0000
3865 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_filsys.h   2012-12-18 15:13:16.000000000 +0000
3866 @@ -266,6 +266,7 @@
3867  #define JFS_NAME_MAX   255
3868  #define JFS_PATH_MAX   BPSIZE
3869  
3870 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3871  
3872  /*
3873   *     file system state (superblock state)
3874 diff -NurpP --minimal linux-3.7.1/fs/jfs/jfs_imap.c linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_imap.c
3875 --- linux-3.7.1/fs/jfs/jfs_imap.c       2012-12-11 03:30:57.000000000 +0000
3876 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_imap.c     2012-12-18 15:13:16.000000000 +0000
3877 @@ -46,6 +46,7 @@
3878  #include <linux/pagemap.h>
3879  #include <linux/quotaops.h>
3880  #include <linux/slab.h>
3881 +#include <linux/vs_tag.h>
3882  
3883  #include "jfs_incore.h"
3884  #include "jfs_inode.h"
3885 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3886  {
3887         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3888         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3889 +       kuid_t uid;
3890 +       kgid_t gid;
3891  
3892         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3893         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3894 @@ -3078,14 +3081,19 @@ static int copy_from_dinode(struct dinod
3895         }
3896         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3897  
3898 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3899 +       uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3900 +       gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3901 +       ip->i_tag = make_ktag(&init_user_ns,
3902 +               INOTAG_TAG(DX_TAG(ip), uid, gid, 0));
3903 +
3904 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3905         if (!uid_valid(sbi->uid))
3906                 ip->i_uid = jfs_ip->saved_uid;
3907         else {
3908                 ip->i_uid = sbi->uid;
3909         }
3910  
3911 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3912 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3913         if (!gid_valid(sbi->gid))
3914                 ip->i_gid = jfs_ip->saved_gid;
3915         else {
3916 @@ -3150,16 +3158,14 @@ static void copy_to_dinode(struct dinode
3917         dip->di_size = cpu_to_le64(ip->i_size);
3918         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3919         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3920 -       if (!uid_valid(sbi->uid))
3921 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3922 -       else
3923 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3924 -                                                  jfs_ip->saved_uid));
3925 -       if (!gid_valid(sbi->gid))
3926 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3927 -       else
3928 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3929 -                                                   jfs_ip->saved_gid));
3930 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3931 +               TAGINO_UID(DX_TAG(ip),
3932 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3933 +               ip->i_tag)));
3934 +       dip->di_gid = cpu_to_le32(from_kuid(&init_user_ns,
3935 +               TAGINO_GID(DX_TAG(ip),
3936 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3937 +               ip->i_tag)));
3938         jfs_get_inode_flags(jfs_ip);
3939         /*
3940          * mode2 is only needed for storing the higher order bits.
3941 diff -NurpP --minimal linux-3.7.1/fs/jfs/jfs_inode.c linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_inode.c
3942 --- linux-3.7.1/fs/jfs/jfs_inode.c      2012-12-11 03:30:57.000000000 +0000
3943 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_inode.c    2012-12-18 15:13:16.000000000 +0000
3944 @@ -18,6 +18,7 @@
3945  
3946  #include <linux/fs.h>
3947  #include <linux/quotaops.h>
3948 +#include <linux/vs_tag.h>
3949  #include "jfs_incore.h"
3950  #include "jfs_inode.h"
3951  #include "jfs_filsys.h"
3952 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3953  {
3954         unsigned int flags = JFS_IP(inode)->mode2;
3955  
3956 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3957 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3958 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3959 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3960  
3961         if (flags & JFS_IMMUTABLE_FL)
3962                 inode->i_flags |= S_IMMUTABLE;
3963 +       if (flags & JFS_IXUNLINK_FL)
3964 +               inode->i_flags |= S_IXUNLINK;
3965 +
3966 +       if (flags & JFS_SYNC_FL)
3967 +               inode->i_flags |= S_SYNC;
3968         if (flags & JFS_APPEND_FL)
3969                 inode->i_flags |= S_APPEND;
3970         if (flags & JFS_NOATIME_FL)
3971                 inode->i_flags |= S_NOATIME;
3972         if (flags & JFS_DIRSYNC_FL)
3973                 inode->i_flags |= S_DIRSYNC;
3974 -       if (flags & JFS_SYNC_FL)
3975 -               inode->i_flags |= S_SYNC;
3976 +
3977 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3978 +
3979 +       if (flags & JFS_BARRIER_FL)
3980 +               inode->i_vflags |= V_BARRIER;
3981 +       if (flags & JFS_COW_FL)
3982 +               inode->i_vflags |= V_COW;
3983  }
3984  
3985  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3986  {
3987         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3988 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3989 +
3990 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3991 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3992 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3993 +                          JFS_BARRIER_FL | JFS_COW_FL);
3994  
3995 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3996 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3997         if (flags & S_IMMUTABLE)
3998                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3999 +       if (flags & S_IXUNLINK)
4000 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4001 +
4002         if (flags & S_APPEND)
4003                 jfs_ip->mode2 |= JFS_APPEND_FL;
4004         if (flags & S_NOATIME)
4005 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4006                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4007         if (flags & S_SYNC)
4008                 jfs_ip->mode2 |= JFS_SYNC_FL;
4009 +
4010 +       if (vflags & V_BARRIER)
4011 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4012 +       if (vflags & V_COW)
4013 +               jfs_ip->mode2 |= JFS_COW_FL;
4014  }
4015  
4016  /*
4017 diff -NurpP --minimal linux-3.7.1/fs/jfs/jfs_inode.h linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_inode.h
4018 --- linux-3.7.1/fs/jfs/jfs_inode.h      2012-12-11 03:30:57.000000000 +0000
4019 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/jfs_inode.h    2012-12-18 15:13:16.000000000 +0000
4020 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4021  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4022         int fh_len, int fh_type);
4023  extern void jfs_set_inode_flags(struct inode *);
4024 +extern int jfs_sync_flags(struct inode *, int, int);
4025  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4026  extern int jfs_setattr(struct dentry *, struct iattr *);
4027  
4028 diff -NurpP --minimal linux-3.7.1/fs/jfs/namei.c linux-3.7.1-vs2.3.5.5/fs/jfs/namei.c
4029 --- linux-3.7.1/fs/jfs/namei.c  2012-12-11 03:30:57.000000000 +0000
4030 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/namei.c        2012-12-18 15:13:16.000000000 +0000
4031 @@ -22,6 +22,7 @@
4032  #include <linux/ctype.h>
4033  #include <linux/quotaops.h>
4034  #include <linux/exportfs.h>
4035 +#include <linux/vs_tag.h>
4036  #include "jfs_incore.h"
4037  #include "jfs_superblock.h"
4038  #include "jfs_inode.h"
4039 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
4040                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4041         }
4042  
4043 +       dx_propagate_tag(nd, ip);
4044         return d_splice_alias(ip, dentry);
4045  }
4046  
4047 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4048  #ifdef CONFIG_JFS_POSIX_ACL
4049         .get_acl        = jfs_get_acl,
4050  #endif
4051 +       .sync_flags     = jfs_sync_flags,
4052  };
4053  
4054  const struct file_operations jfs_dir_operations = {
4055 diff -NurpP --minimal linux-3.7.1/fs/jfs/super.c linux-3.7.1-vs2.3.5.5/fs/jfs/super.c
4056 --- linux-3.7.1/fs/jfs/super.c  2012-12-11 03:30:57.000000000 +0000
4057 +++ linux-3.7.1-vs2.3.5.5/fs/jfs/super.c        2012-12-18 15:13:16.000000000 +0000
4058 @@ -199,7 +199,8 @@ enum {
4059         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4060         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4061         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4062 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
4063 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4064 +       Opt_tag, Opt_notag, Opt_tagid
4065  };
4066  
4067  static const match_table_t tokens = {
4068 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4069         {Opt_resize, "resize=%u"},
4070         {Opt_resize_nosize, "resize"},
4071         {Opt_errors, "errors=%s"},
4072 +       {Opt_tag, "tag"},
4073 +       {Opt_notag, "notag"},
4074 +       {Opt_tagid, "tagid=%u"},
4075 +       {Opt_tag, "tagxid"},
4076         {Opt_ignore, "noquota"},
4077         {Opt_ignore, "quota"},
4078         {Opt_usrquota, "usrquota"},
4079 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4080                         }
4081                         break;
4082                 }
4083 -
4084 +#ifndef CONFIG_TAGGING_NONE
4085 +               case Opt_tag:
4086 +                       *flag |= JFS_TAGGED;
4087 +                       break;
4088 +               case Opt_notag:
4089 +                       *flag &= JFS_TAGGED;
4090 +                       break;
4091 +#endif
4092 +#ifdef CONFIG_PROPAGATE
4093 +               case Opt_tagid:
4094 +                       /* use args[0] */
4095 +                       *flag |= JFS_TAGGED;
4096 +                       break;
4097 +#endif
4098                 default:
4099                         printk("jfs: Unrecognized mount option \"%s\" "
4100                                         " or missing value\n", p);
4101 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4102                 return -EINVAL;
4103         }
4104  
4105 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4106 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4107 +                       sb->s_id);
4108 +               return -EINVAL;
4109 +       }
4110 +
4111         if (newLVSize) {
4112                 if (sb->s_flags & MS_RDONLY) {
4113                         pr_err("JFS: resize requires volume" \
4114 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4115  #ifdef CONFIG_JFS_POSIX_ACL
4116         sb->s_flags |= MS_POSIXACL;
4117  #endif
4118 +       /* map mount option tagxid */
4119 +       if (sbi->flag & JFS_TAGGED)
4120 +               sb->s_flags |= MS_TAGGED;
4121  
4122         if (newLVSize) {
4123                 pr_err("resize option for remount only\n");
4124 diff -NurpP --minimal linux-3.7.1/fs/libfs.c linux-3.7.1-vs2.3.5.5/fs/libfs.c
4125 --- linux-3.7.1/fs/libfs.c      2012-12-11 03:30:57.000000000 +0000
4126 +++ linux-3.7.1-vs2.3.5.5/fs/libfs.c    2012-12-18 15:13:16.000000000 +0000
4127 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4128   * both impossible due to the lock on directory.
4129   */
4130  
4131 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4132 +static inline int do_dcache_readdir_filter(struct file *filp,
4133 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4134  {
4135         struct dentry *dentry = filp->f_path.dentry;
4136         struct dentry *cursor = filp->private_data;
4137 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4138                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4139                                 struct dentry *next;
4140                                 next = list_entry(p, struct dentry, d_u.d_child);
4141 +                               if (filter && !filter(next))
4142 +                                       continue;
4143                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4144                                 if (!simple_positive(next)) {
4145                                         spin_unlock(&next->d_lock);
4146 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4147         return 0;
4148  }
4149  
4150 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4151 +{
4152 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4153 +}
4154 +
4155 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4156 +       int (*filter)(struct dentry *))
4157 +{
4158 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4159 +}
4160 +
4161  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4162  {
4163         return -EISDIR;
4164 @@ -983,6 +997,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4165  EXPORT_SYMBOL(dcache_dir_lseek);
4166  EXPORT_SYMBOL(dcache_dir_open);
4167  EXPORT_SYMBOL(dcache_readdir);
4168 +EXPORT_SYMBOL(dcache_readdir_filter);
4169  EXPORT_SYMBOL(generic_read_dir);
4170  EXPORT_SYMBOL(mount_pseudo);
4171  EXPORT_SYMBOL(simple_write_begin);
4172 diff -NurpP --minimal linux-3.7.1/fs/locks.c linux-3.7.1-vs2.3.5.5/fs/locks.c
4173 --- linux-3.7.1/fs/locks.c      2012-12-11 03:30:57.000000000 +0000
4174 +++ linux-3.7.1-vs2.3.5.5/fs/locks.c    2012-12-18 15:13:16.000000000 +0000
4175 @@ -126,6 +126,8 @@
4176  #include <linux/time.h>
4177  #include <linux/rcupdate.h>
4178  #include <linux/pid_namespace.h>
4179 +#include <linux/vs_base.h>
4180 +#include <linux/vs_limit.h>
4181  
4182  #include <asm/uaccess.h>
4183  
4184 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4185  /* Allocate an empty lock structure. */
4186  struct file_lock *locks_alloc_lock(void)
4187  {
4188 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4189 +       struct file_lock *fl;
4190  
4191 -       if (fl)
4192 -               locks_init_lock_heads(fl);
4193 +       if (!vx_locks_avail(1))
4194 +               return NULL;
4195  
4196 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4197 +
4198 +       if (fl) {
4199 +               locks_init_lock_heads(fl);
4200 +               fl->fl_xid = -1;
4201 +       }
4202         return fl;
4203  }
4204  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4205 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4206         BUG_ON(!list_empty(&fl->fl_block));
4207         BUG_ON(!list_empty(&fl->fl_link));
4208  
4209 +       vx_locks_dec(fl);
4210         locks_release_private(fl);
4211         kmem_cache_free(filelock_cache, fl);
4212  }
4213 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4214  {
4215         memset(fl, 0, sizeof(struct file_lock));
4216         locks_init_lock_heads(fl);
4217 +       fl->fl_xid = -1;
4218  }
4219  
4220  EXPORT_SYMBOL(locks_init_lock);
4221 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4222         new->fl_file = fl->fl_file;
4223         new->fl_ops = fl->fl_ops;
4224         new->fl_lmops = fl->fl_lmops;
4225 +       new->fl_xid = fl->fl_xid;
4226  
4227         locks_copy_private(new, fl);
4228  }
4229 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4230         fl->fl_flags = FL_FLOCK;
4231         fl->fl_type = type;
4232         fl->fl_end = OFFSET_MAX;
4233 +
4234 +       vxd_assert(filp->f_xid == vx_current_xid(),
4235 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4236 +       fl->fl_xid = filp->f_xid;
4237 +       vx_locks_inc(fl);
4238         
4239         *lock = fl;
4240         return 0;
4241 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4242  
4243         fl->fl_owner = current->files;
4244         fl->fl_pid = current->tgid;
4245 +       fl->fl_xid = vx_current_xid();
4246  
4247         fl->fl_file = filp;
4248         fl->fl_flags = FL_LEASE;
4249 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4250         if (fl == NULL)
4251                 return ERR_PTR(error);
4252  
4253 +       fl->fl_xid = vx_current_xid();
4254 +       if (filp)
4255 +               vxd_assert(filp->f_xid == fl->fl_xid,
4256 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4257 +       vx_locks_inc(fl);
4258         error = lease_init(filp, type, fl);
4259         if (error) {
4260                 locks_free_lock(fl);
4261 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4262                 lock_flocks();
4263         }
4264  
4265 +       new_fl->fl_xid = -1;
4266  find_conflict:
4267         for_each_lock(inode, before) {
4268                 struct file_lock *fl = *before;
4269 @@ -773,6 +796,7 @@ find_conflict:
4270                 goto out;
4271         locks_copy_lock(new_fl, request);
4272         locks_insert_lock(before, new_fl);
4273 +       vx_locks_inc(new_fl);
4274         new_fl = NULL;
4275         error = 0;
4276  
4277 @@ -783,7 +807,8 @@ out:
4278         return error;
4279  }
4280  
4281 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4282 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4283 +       struct file_lock *conflock, xid_t xid)
4284  {
4285         struct file_lock *fl;
4286         struct file_lock *new_fl = NULL;
4287 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4288         struct file_lock **before;
4289         int error, added = 0;
4290  
4291 +       vxd_assert(xid == vx_current_xid(),
4292 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4293         /*
4294          * We may need two file_lock structures for this operation,
4295          * so we get them in advance to avoid races.
4296 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4297             (request->fl_type != F_UNLCK ||
4298              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4299                 new_fl = locks_alloc_lock();
4300 +               new_fl->fl_xid = xid;
4301 +               vx_locks_inc(new_fl);
4302                 new_fl2 = locks_alloc_lock();
4303 +               new_fl2->fl_xid = xid;
4304 +               vx_locks_inc(new_fl2);
4305         }
4306  
4307         lock_flocks();
4308 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4309  int posix_lock_file(struct file *filp, struct file_lock *fl,
4310                         struct file_lock *conflock)
4311  {
4312 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4313 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4314 +               fl, conflock, filp->f_xid);
4315  }
4316  EXPORT_SYMBOL(posix_lock_file);
4317  
4318 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4319         fl.fl_end = offset + count - 1;
4320  
4321         for (;;) {
4322 -               error = __posix_lock_file(inode, &fl, NULL);
4323 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4324                 if (error != FILE_LOCK_DEFERRED)
4325                         break;
4326                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4327 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4328                 goto out;
4329  
4330         locks_insert_lock(before, lease);
4331 +       vx_locks_inc(lease);
4332         return 0;
4333  
4334  out:
4335 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4336         if (file_lock == NULL)
4337                 return -ENOLCK;
4338  
4339 +       vxd_assert(filp->f_xid == vx_current_xid(),
4340 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4341 +       file_lock->fl_xid = filp->f_xid;
4342 +       vx_locks_inc(file_lock);
4343 +
4344         /*
4345          * This might block, so we do it before checking the inode.
4346          */
4347 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4348         if (file_lock == NULL)
4349                 return -ENOLCK;
4350  
4351 +       vxd_assert(filp->f_xid == vx_current_xid(),
4352 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4353 +       file_lock->fl_xid = filp->f_xid;
4354 +       vx_locks_inc(file_lock);
4355 +
4356         /*
4357          * This might block, so we do it before checking the inode.
4358          */
4359 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4360  
4361         lock_get_status(f, fl, *((loff_t *)f->private), "");
4362  
4363 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4364 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4365 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4366 +                       continue;
4367                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4368 +       }
4369  
4370         return 0;
4371  }
4372 diff -NurpP --minimal linux-3.7.1/fs/mount.h linux-3.7.1-vs2.3.5.5/fs/mount.h
4373 --- linux-3.7.1/fs/mount.h      2012-12-11 03:30:57.000000000 +0000
4374 +++ linux-3.7.1-vs2.3.5.5/fs/mount.h    2012-12-18 15:13:16.000000000 +0000
4375 @@ -46,6 +46,7 @@ struct mount {
4376         int mnt_expiry_mark;            /* true if marked for expiry */
4377         int mnt_pinned;
4378         int mnt_ghosts;
4379 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
4380  };
4381  
4382  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4383 diff -NurpP --minimal linux-3.7.1/fs/namei.c linux-3.7.1-vs2.3.5.5/fs/namei.c
4384 --- linux-3.7.1/fs/namei.c      2012-12-11 03:30:57.000000000 +0000
4385 +++ linux-3.7.1-vs2.3.5.5/fs/namei.c    2012-12-18 15:13:16.000000000 +0000
4386 @@ -34,6 +34,14 @@
4387  #include <linux/device_cgroup.h>
4388  #include <linux/fs_struct.h>
4389  #include <linux/posix_acl.h>
4390 +#include <linux/proc_fs.h>
4391 +#include <linux/vserver/inode.h>
4392 +#include <linux/vs_base.h>
4393 +#include <linux/vs_tag.h>
4394 +#include <linux/vs_cowbl.h>
4395 +#include <linux/vs_device.h>
4396 +#include <linux/vs_context.h>
4397 +#include <linux/pid_namespace.h>
4398  #include <asm/uaccess.h>
4399  
4400  #include "internal.h"
4401 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4402         return -EAGAIN;
4403  }
4404  
4405 +static inline int dx_barrier(const struct inode *inode)
4406 +{
4407 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4408 +               vxwprintk_task(1, "did hit the barrier.");
4409 +               return 1;
4410 +       }
4411 +       return 0;
4412 +}
4413 +
4414 +static int __dx_permission(const struct inode *inode, int mask)
4415 +{
4416 +       if (dx_barrier(inode))
4417 +               return -EACCES;
4418 +
4419 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4420 +               /* devpts is xid tagged */
4421 +               if (S_ISDIR(inode->i_mode) ||
4422 +                   vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4423 +                       return 0;
4424 +
4425 +               /* just pretend we didn't find anything */
4426 +               return -ENOENT;
4427 +       }
4428 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4429 +               struct proc_dir_entry *de = PDE(inode);
4430 +
4431 +               if (de && !vx_hide_check(0, de->vx_flags))
4432 +                       goto out;
4433 +
4434 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4435 +                       struct pid *pid;
4436 +                       struct task_struct *tsk;
4437 +
4438 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4439 +                           vx_flags(VXF_STATE_SETUP, 0))
4440 +                               return 0;
4441 +
4442 +                       pid = PROC_I(inode)->pid;
4443 +                       if (!pid)
4444 +                               goto out;
4445 +
4446 +                       rcu_read_lock();
4447 +                       tsk = pid_task(pid, PIDTYPE_PID);
4448 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4449 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4450 +                       if (tsk &&
4451 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4452 +                               rcu_read_unlock();
4453 +                               return 0;
4454 +                       }
4455 +                       rcu_read_unlock();
4456 +               }
4457 +               else {
4458 +                       /* FIXME: Should we block some entries here? */
4459 +                       return 0;
4460 +               }
4461 +       }
4462 +       else {
4463 +               if (dx_notagcheck(inode->i_sb) ||
4464 +                   dx_check((xid_t)i_tag_read(inode),
4465 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4466 +                       return 0;
4467 +       }
4468 +
4469 +out:
4470 +       return -EACCES;
4471 +}
4472 +
4473 +int dx_permission(const struct inode *inode, int mask)
4474 +{
4475 +       int ret = __dx_permission(inode, mask);
4476 +       if (unlikely(ret)) {
4477 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4478 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4479 +#endif
4480 +                   vxwprintk_task(1,
4481 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4482 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4483 +                       inode->i_ino);
4484 +       }
4485 +       return ret;
4486 +}
4487 +
4488  /*
4489   * This does the basic permission checking
4490   */
4491 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4492                 /*
4493                  * Nobody gets write access to an immutable file.
4494                  */
4495 -               if (IS_IMMUTABLE(inode))
4496 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4497                         return -EACCES;
4498         }
4499  
4500 +       retval = dx_permission(inode, mask);
4501 +       if (retval)
4502 +               return retval;
4503 +
4504         retval = do_inode_permission(inode, mask);
4505         if (retval)
4506                 return retval;
4507 @@ -1244,7 +1339,8 @@ static void follow_dotdot(struct nameida
4508  
4509                 if (nd->path.dentry == nd->root.dentry &&
4510                     nd->path.mnt == nd->root.mnt) {
4511 -                       break;
4512 +                       /* for sane '/' avoid follow_mount() */
4513 +                       return;
4514                 }
4515                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4516                         /* rare case of legitimate dget_parent()... */
4517 @@ -1393,6 +1489,9 @@ static int lookup_fast(struct nameidata
4518                                 goto unlazy;
4519                         }
4520                 }
4521 +
4522 +               /* FIXME: check dx permission */
4523 +
4524                 path->mnt = mnt;
4525                 path->dentry = dentry;
4526                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4527 @@ -1428,6 +1527,8 @@ unlazy:
4528                 }
4529         }
4530  
4531 +       /* FIXME: check dx permission */
4532 +
4533         path->mnt = mnt;
4534         path->dentry = dentry;
4535         err = follow_managed(path, nd->flags);
4536 @@ -2258,7 +2359,7 @@ static int may_delete(struct inode *dir,
4537         if (IS_APPEND(dir))
4538                 return -EPERM;
4539         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4540 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4541 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4542                 return -EPERM;
4543         if (isdir) {
4544                 if (!S_ISDIR(victim->d_inode->i_mode))
4545 @@ -2337,19 +2438,25 @@ int vfs_create(struct inode *dir, struct
4546                 bool want_excl)
4547  {
4548         int error = may_create(dir, dentry);
4549 -       if (error)
4550 +       if (error) {
4551 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4552                 return error;
4553 +       }
4554  
4555         if (!dir->i_op->create)
4556                 return -EACCES; /* shouldn't it be ENOSYS? */
4557         mode &= S_IALLUGO;
4558         mode |= S_IFREG;
4559         error = security_inode_create(dir, dentry, mode);
4560 -       if (error)
4561 +       if (error) {
4562 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4563                 return error;
4564 +       }
4565         error = dir->i_op->create(dir, dentry, mode, want_excl);
4566         if (!error)
4567                 fsnotify_create(dir, dentry);
4568 +       else
4569 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4570         return error;
4571  }
4572  
4573 @@ -2384,6 +2491,15 @@ static int may_open(struct path *path, i
4574                 break;
4575         }
4576  
4577 +#ifdef CONFIG_VSERVER_COWBL
4578 +       if (IS_COW(inode) &&
4579 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4580 +               if (IS_COW_LINK(inode))
4581 +                       return -EMLINK;
4582 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4583 +               mark_inode_dirty(inode);
4584 +       }
4585 +#endif
4586         error = inode_permission(inode, acc_mode);
4587         if (error)
4588                 return error;
4589 @@ -2886,6 +3002,16 @@ finish_open:
4590         }
4591  finish_open_created:
4592         error = may_open(&nd->path, acc_mode, open_flag);
4593 +#ifdef CONFIG_VSERVER_COWBL
4594 +       if (error == -EMLINK) {
4595 +               struct dentry *dentry;
4596 +               dentry = cow_break_link(name->name);
4597 +               if (IS_ERR(dentry))
4598 +                       error = PTR_ERR(dentry);
4599 +               else
4600 +                       dput(dentry);
4601 +       }
4602 +#endif
4603         if (error)
4604                 goto out;
4605         file->f_path.mnt = nd->path.mnt;
4606 @@ -2950,6 +3076,7 @@ static struct file *path_openat(int dfd,
4607         int opened = 0;
4608         int error;
4609  
4610 +restart:
4611         file = get_empty_filp();
4612         if (!file)
4613                 return ERR_PTR(-ENFILE);
4614 @@ -2986,6 +3113,16 @@ static struct file *path_openat(int dfd,
4615                 error = do_last(nd, &path, file, op, &opened, pathname);
4616                 put_link(nd, &link, cookie);
4617         }
4618 +
4619 +#ifdef CONFIG_VSERVER_COWBL
4620 +       if (error == -EMLINK) {
4621 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4622 +                       path_put(&nd->root);
4623 +               if (base)
4624 +                       fput(base);
4625 +               goto restart;
4626 +       }
4627 +#endif
4628  out:
4629         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4630                 path_put(&nd->root);
4631 @@ -3090,6 +3227,11 @@ struct dentry *kern_path_create(int dfd,
4632                 goto fail;
4633         }
4634         *path = nd.path;
4635 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4636 +               path->dentry, path->dentry->d_name.len,
4637 +               path->dentry->d_name.name, dentry,
4638 +               dentry->d_name.len, dentry->d_name.name,
4639 +               path->dentry->d_inode);
4640         return dentry;
4641  fail:
4642         dput(dentry);
4643 @@ -3556,7 +3698,7 @@ int vfs_link(struct dentry *old_dentry,
4644         /*
4645          * A link to an append-only or immutable file cannot be created.
4646          */
4647 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4648 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4649                 return -EPERM;
4650         if (!dir->i_op->link)
4651                 return -EPERM;
4652 @@ -3945,6 +4087,275 @@ int vfs_follow_link(struct nameidata *nd
4653         return __vfs_follow_link(nd, link);
4654  }
4655  
4656 +
4657 +#ifdef CONFIG_VSERVER_COWBL
4658 +
4659 +static inline
4660 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4661 +{
4662 +       loff_t ppos = 0;
4663 +
4664 +       return do_splice_direct(in, &ppos, out, len, 0);
4665 +}
4666 +
4667 +struct dentry *cow_break_link(const char *pathname)
4668 +{
4669 +       int ret, mode, pathlen, redo = 0;
4670 +       struct nameidata old_nd, dir_nd;
4671 +       struct path dir_path, *old_path, *new_path;
4672 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4673 +       struct file *old_file;
4674 +       struct file *new_file;
4675 +       char *to, *path, pad='\251';
4676 +       loff_t size;
4677 +
4678 +       vxdprintk(VXD_CBIT(misc, 1),
4679 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4680 +
4681 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4682 +       ret = -ENOMEM;
4683 +       if (!path)
4684 +               goto out;
4685 +
4686 +       /* old_nd.path will have refs to dentry and mnt */
4687 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4688 +       vxdprintk(VXD_CBIT(misc, 2),
4689 +               "do_path_lookup(old): %d", ret);
4690 +       if (ret < 0)
4691 +               goto out_free_path;
4692 +
4693 +       /* dentry/mnt refs handed over to old_path */
4694 +       old_path = &old_nd.path;
4695 +       /* no explicit reference for old_dentry here */
4696 +       old_dentry = old_path->dentry;
4697 +
4698 +       mode = old_dentry->d_inode->i_mode;
4699 +       to = d_path(old_path, path, PATH_MAX-2);
4700 +       pathlen = strlen(to);
4701 +       vxdprintk(VXD_CBIT(misc, 2),
4702 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4703 +               old_dentry,
4704 +               old_dentry->d_name.len, old_dentry->d_name.name,
4705 +               old_dentry->d_name.len);
4706 +
4707 +       to[pathlen + 1] = 0;
4708 +retry:
4709 +       new_dentry = NULL;
4710 +       to[pathlen] = pad--;
4711 +       ret = -ELOOP;
4712 +       if (pad <= '\240')
4713 +               goto out_rel_old;
4714 +
4715 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4716 +
4717 +       /* dir_nd.path will have refs to dentry and mnt */
4718 +       ret = do_path_lookup(AT_FDCWD, to,
4719 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4720 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4721 +       if (ret < 0)
4722 +               goto retry;
4723 +
4724 +       /* this puppy downs the dir inode mutex if successful.
4725 +          dir_path will hold refs to dentry and mnt and
4726 +          we'll have get write access to the mnt */
4727 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4728 +       if (!new_dentry || IS_ERR(new_dentry)) {
4729 +               path_put(&dir_nd.path);
4730 +               vxdprintk(VXD_CBIT(misc, 2),
4731 +                       "kern_path_create(new) failed with %ld",
4732 +                       PTR_ERR(new_dentry));
4733 +               goto retry;
4734 +       }
4735 +       vxdprintk(VXD_CBIT(misc, 2),
4736 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4737 +               new_dentry,
4738 +               new_dentry->d_name.len, new_dentry->d_name.name,
4739 +               new_dentry->d_name.len);
4740 +
4741 +       /* take a reference on new_dentry */
4742 +       dget(new_dentry);
4743 +
4744 +       /* dentry/mnt refs handed over to new_path */
4745 +       new_path = &dir_path;
4746 +
4747 +       /* dentry for old/new dir */
4748 +       dir = dir_nd.path.dentry;
4749 +
4750 +       /* give up reference on dir */
4751 +       dput(new_path->dentry);
4752 +
4753 +       /* new_dentry already has a reference */
4754 +       new_path->dentry = new_dentry;
4755 +
4756 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4757 +       vxdprintk(VXD_CBIT(misc, 2),
4758 +               "vfs_create(new): %d", ret);
4759 +       if (ret == -EEXIST) {
4760 +               mutex_unlock(&dir->d_inode->i_mutex);
4761 +               path_put(&dir_nd.path);
4762 +               mnt_drop_write(new_path->mnt);
4763 +               path_put(new_path);
4764 +               new_dentry = NULL;
4765 +               goto retry;
4766 +       }
4767 +       else if (ret < 0)
4768 +               goto out_unlock_new;
4769 +
4770 +       /* drop out early, ret passes ENOENT */
4771 +       ret = -ENOENT;
4772 +       if ((redo = d_unhashed(old_dentry)))
4773 +               goto out_unlock_new;
4774 +
4775 +       /* doesn't change refs for old_path */
4776 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4777 +       vxdprintk(VXD_CBIT(misc, 2),
4778 +               "dentry_open(old): %p", old_file);
4779 +       if (IS_ERR(old_file)) {
4780 +               ret = PTR_ERR(old_file);
4781 +               goto out_unlock_new;
4782 +       }
4783 +
4784 +       /* doesn't change refs for new_path */
4785 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4786 +       vxdprintk(VXD_CBIT(misc, 2),
4787 +               "dentry_open(new): %p", new_file);
4788 +       if (IS_ERR(new_file)) {
4789 +               ret = PTR_ERR(new_file);
4790 +               goto out_fput_old;
4791 +       }
4792 +
4793 +       size = i_size_read(old_file->f_dentry->d_inode);
4794 +       ret = do_cow_splice(old_file, new_file, size);
4795 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4796 +       if (ret < 0) {
4797 +               goto out_fput_both;
4798 +       } else if (ret < size) {
4799 +               ret = -ENOSPC;
4800 +               goto out_fput_both;
4801 +       } else {
4802 +               struct inode *old_inode = old_dentry->d_inode;
4803 +               struct inode *new_inode = new_dentry->d_inode;
4804 +               struct iattr attr = {
4805 +                       .ia_uid = old_inode->i_uid,
4806 +                       .ia_gid = old_inode->i_gid,
4807 +                       .ia_valid = ATTR_UID | ATTR_GID
4808 +                       };
4809 +
4810 +               setattr_copy(new_inode, &attr);
4811 +               mark_inode_dirty(new_inode);
4812 +       }
4813 +
4814 +       /* lock rename mutex */
4815 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4816 +
4817 +       /* drop out late */
4818 +       ret = -ENOENT;
4819 +       if ((redo = d_unhashed(old_dentry)))
4820 +               goto out_unlock;
4821 +
4822 +       vxdprintk(VXD_CBIT(misc, 2),
4823 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4824 +               new_dentry->d_name.len, new_dentry->d_name.name,
4825 +               new_dentry->d_name.len,
4826 +               old_dentry->d_name.len, old_dentry->d_name.name,
4827 +               old_dentry->d_name.len);
4828 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4829 +               old_dentry->d_parent->d_inode, old_dentry);
4830 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4831 +
4832 +out_unlock:
4833 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4834 +
4835 +out_fput_both:
4836 +       vxdprintk(VXD_CBIT(misc, 3),
4837 +               "fput(new_file=%p[#%ld])", new_file,
4838 +               atomic_long_read(&new_file->f_count));
4839 +       fput(new_file);
4840 +
4841 +out_fput_old:
4842 +       vxdprintk(VXD_CBIT(misc, 3),
4843 +               "fput(old_file=%p[#%ld])", old_file,
4844 +               atomic_long_read(&old_file->f_count));
4845 +       fput(old_file);
4846 +
4847 +out_unlock_new:
4848 +       /* drop references from dir_nd.path */
4849 +       path_put(&dir_nd.path);
4850 +
4851 +       /* drop write access to mnt */
4852 +       mnt_drop_write(new_path->mnt);
4853 +
4854 +       /* unlock the inode mutex from kern_path_create() */
4855 +       mutex_unlock(&dir->d_inode->i_mutex);
4856 +       if (!ret)
4857 +               goto out_redo;
4858 +
4859 +       /* error path cleanup */
4860 +       vfs_unlink(dir->d_inode, new_dentry);
4861 +
4862 +out_redo:
4863 +       if (!redo)
4864 +               goto out_rel_both;
4865 +
4866 +       /* lookup dentry once again
4867 +          old_nd.path will be freed as old_path in out_rel_old */
4868 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4869 +       if (ret)
4870 +               goto out_rel_both;
4871 +
4872 +       /* drop reference on new_dentry */
4873 +       dput(new_dentry);
4874 +       new_dentry = old_path->dentry;
4875 +       dget(new_dentry);
4876 +       vxdprintk(VXD_CBIT(misc, 2),
4877 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4878 +               new_dentry,
4879 +               new_dentry->d_name.len, new_dentry->d_name.name,
4880 +               new_dentry->d_name.len);
4881 +
4882 +out_rel_both:
4883 +       if (new_path)
4884 +               path_put(new_path);
4885 +out_rel_old:
4886 +       path_put(old_path);
4887 +out_free_path:
4888 +       kfree(path);
4889 +out:
4890 +       if (ret) {
4891 +               dput(new_dentry);
4892 +               new_dentry = ERR_PTR(ret);
4893 +       }
4894 +       vxdprintk(VXD_CBIT(misc, 3),
4895 +               "cow_break_link returning with %p", new_dentry);
4896 +       return new_dentry;
4897 +}
4898 +
4899 +#endif
4900 +
4901 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4902 +{
4903 +       struct path path;
4904 +       struct vfsmount *vmnt;
4905 +       char *pstr, *root;
4906 +       int length = 0;
4907 +
4908 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4909 +       if (!pstr)
4910 +               return 0;
4911 +
4912 +       vmnt = &ns->root->mnt;
4913 +       path.mnt = vmnt;
4914 +       path.dentry = vmnt->mnt_root;
4915 +       root = d_path(&path, pstr, PATH_MAX - 2);
4916 +       length = sprintf(buffer + length,
4917 +               "Namespace:\t%p [#%u]\n"
4918 +               "RootPath:\t%s\n",
4919 +               ns, atomic_read(&ns->count),
4920 +               root);
4921 +       kfree(pstr);
4922 +       return length;
4923 +}
4924 +
4925  /* get the link contents into pagecache */
4926  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4927  {
4928 @@ -4068,3 +4479,4 @@ EXPORT_SYMBOL(vfs_symlink);
4929  EXPORT_SYMBOL(vfs_unlink);
4930  EXPORT_SYMBOL(dentry_unhash);
4931  EXPORT_SYMBOL(generic_readlink);
4932 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4933 diff -NurpP --minimal linux-3.7.1/fs/namespace.c linux-3.7.1-vs2.3.5.5/fs/namespace.c
4934 --- linux-3.7.1/fs/namespace.c  2012-12-11 03:30:57.000000000 +0000
4935 +++ linux-3.7.1-vs2.3.5.5/fs/namespace.c        2012-12-18 15:13:16.000000000 +0000
4936 @@ -20,6 +20,11 @@
4937  #include <linux/fs_struct.h>   /* get_fs_root et.al. */
4938  #include <linux/fsnotify.h>    /* fsnotify_vfsmount_delete */
4939  #include <linux/uaccess.h>
4940 +#include <linux/vs_base.h>
4941 +#include <linux/vs_context.h>
4942 +#include <linux/vs_tag.h>
4943 +#include <linux/vserver/space.h>
4944 +#include <linux/vserver/global.h>
4945  #include "pnode.h"
4946  #include "internal.h"
4947  
4948 @@ -749,6 +754,10 @@ vfs_kern_mount(struct file_system_type *
4949         if (!type)
4950                 return ERR_PTR(-ENODEV);
4951  
4952 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4953 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4954 +               return ERR_PTR(-EPERM);
4955 +
4956         mnt = alloc_vfsmnt(name);
4957         if (!mnt)
4958                 return ERR_PTR(-ENOMEM);
4959 @@ -801,6 +810,7 @@ static struct mount *clone_mnt(struct mo
4960         mnt->mnt.mnt_root = dget(root);
4961         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4962         mnt->mnt_parent = mnt;
4963 +               mnt->mnt_tag = old->mnt_tag;
4964         br_write_lock(&vfsmount_lock);
4965         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4966         br_write_unlock(&vfsmount_lock);
4967 @@ -1266,7 +1276,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
4968                 goto dput_and_out;
4969  
4970         retval = -EPERM;
4971 -       if (!capable(CAP_SYS_ADMIN))
4972 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4973                 goto dput_and_out;
4974  
4975         retval = do_umount(mnt, flags);
4976 @@ -1292,7 +1302,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
4977  
4978  static int mount_is_safe(struct path *path)
4979  {
4980 -       if (capable(CAP_SYS_ADMIN))
4981 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
4982                 return 0;
4983         return -EPERM;
4984  #ifdef notyet
4985 @@ -1610,7 +1620,7 @@ static int do_change_type(struct path *p
4986         int type;
4987         int err = 0;
4988  
4989 -       if (!capable(CAP_SYS_ADMIN))
4990 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
4991                 return -EPERM;
4992  
4993         if (path->dentry != path->mnt->mnt_root)
4994 @@ -1626,6 +1636,7 @@ static int do_change_type(struct path *p
4995                 if (err)
4996                         goto out_unlock;
4997         }
4998 +       // mnt->mnt_flags = mnt_flags;
4999  
5000         br_write_lock(&vfsmount_lock);
5001         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5002 @@ -1641,12 +1652,14 @@ static int do_change_type(struct path *p
5003   * do loopback mount.
5004   */
5005  static int do_loopback(struct path *path, const char *old_name,
5006 -                               int recurse)
5007 +       tag_t tag, unsigned long flags, int mnt_flags)
5008  {
5009         LIST_HEAD(umount_list);
5010         struct path old_path;
5011         struct mount *mnt = NULL, *old;
5012         int err = mount_is_safe(path);
5013 +       int recurse = flags & MS_REC;
5014 +
5015         if (err)
5016                 return err;
5017         if (!old_name || !*old_name)
5018 @@ -1715,13 +1728,13 @@ static int change_mount_flags(struct vfs
5019   * on it - tough luck.
5020   */
5021  static int do_remount(struct path *path, int flags, int mnt_flags,
5022 -                     void *data)
5023 +       void *data, xid_t xid)
5024  {
5025         int err;
5026         struct super_block *sb = path->mnt->mnt_sb;
5027         struct mount *mnt = real_mount(path->mnt);
5028  
5029 -       if (!capable(CAP_SYS_ADMIN))
5030 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5031                 return -EPERM;
5032  
5033         if (!check_mnt(mnt))
5034 @@ -1770,7 +1783,7 @@ static int do_move_mount(struct path *pa
5035         struct mount *p;
5036         struct mount *old;
5037         int err = 0;
5038 -       if (!capable(CAP_SYS_ADMIN))
5039 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5040                 return -EPERM;
5041         if (!old_name || !*old_name)
5042                 return -EINVAL;
5043 @@ -1927,7 +1940,7 @@ static int do_new_mount(struct path *pat
5044                 return -EINVAL;
5045  
5046         /* we need capabilities... */
5047 -       if (!capable(CAP_SYS_ADMIN))
5048 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5049                 return -EPERM;
5050  
5051         mnt = do_kern_mount(type, flags, name, data);
5052 @@ -2197,6 +2210,7 @@ long do_mount(const char *dev_name, cons
5053         struct path path;
5054         int retval = 0;
5055         int mnt_flags = 0;
5056 +       tag_t tag = 0;
5057  
5058         /* Discard magic */
5059         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5060 @@ -2224,6 +2238,12 @@ long do_mount(const char *dev_name, cons
5061         if (!(flags & MS_NOATIME))
5062                 mnt_flags |= MNT_RELATIME;
5063  
5064 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5065 +               /* FIXME: bind and re-mounts get the tag flag? */
5066 +               if (flags & (MS_BIND|MS_REMOUNT))
5067 +                       flags |= MS_TAGID;
5068 +       }
5069 +
5070         /* Separate the per-mountpoint flags */
5071         if (flags & MS_NOSUID)
5072                 mnt_flags |= MNT_NOSUID;
5073 @@ -2240,15 +2260,17 @@ long do_mount(const char *dev_name, cons
5074         if (flags & MS_RDONLY)
5075                 mnt_flags |= MNT_READONLY;
5076  
5077 +       if (!capable(CAP_SYS_ADMIN))
5078 +               mnt_flags |= MNT_NODEV;
5079         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5080                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5081                    MS_STRICTATIME);
5082  
5083         if (flags & MS_REMOUNT)
5084                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5085 -                                   data_page);
5086 +                                   data_page, tag);
5087         else if (flags & MS_BIND)
5088 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5089 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5090         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5091                 retval = do_change_type(&path, flags);
5092         else if (flags & MS_MOVE)
5093 @@ -2329,6 +2351,7 @@ static struct mnt_namespace *dup_mnt_ns(
5094                 q = next_mnt(q, new);
5095         }
5096         up_write(&namespace_sem);
5097 +       atomic_inc(&vs_global_mnt_ns);
5098  
5099         if (rootmnt)
5100                 mntput(rootmnt);
5101 @@ -2524,9 +2547,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5102         error = -EINVAL;
5103         new_mnt = real_mount(new.mnt);
5104         root_mnt = real_mount(root.mnt);
5105 -       if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5106 +       if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5107                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5108 -               IS_MNT_SHARED(root_mnt->mnt_parent))
5109 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5110 +               !vx_flags(VXF_STATE_SETUP, 0))
5111                 goto out4;
5112         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5113                 goto out4;
5114 @@ -2647,6 +2671,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5115         br_write_unlock(&vfsmount_lock);
5116         up_write(&namespace_sem);
5117         release_mounts(&umount_list);
5118 +       atomic_dec(&vs_global_mnt_ns);
5119         kfree(ns);
5120  }
5121  
5122 diff -NurpP --minimal linux-3.7.1/fs/nfs/client.c linux-3.7.1-vs2.3.5.5/fs/nfs/client.c
5123 --- linux-3.7.1/fs/nfs/client.c 2012-12-11 03:30:57.000000000 +0000
5124 +++ linux-3.7.1-vs2.3.5.5/fs/nfs/client.c       2012-12-18 15:13:16.000000000 +0000
5125 @@ -684,6 +684,9 @@ int nfs_init_server_rpcclient(struct nfs
5126         if (server->flags & NFS_MOUNT_SOFT)
5127                 server->client->cl_softrtry = 1;
5128  
5129 +       server->client->cl_tag = 0;
5130 +       if (server->flags & NFS_MOUNT_TAGGED)
5131 +               server->client->cl_tag = 1;
5132         return 0;
5133  }
5134  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5135 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
5136                 server->acdirmin = server->acdirmax = 0;
5137         }
5138  
5139 +       /* FIXME: needs fsinfo
5140 +       if (server->flags & NFS_MOUNT_TAGGED)
5141 +               sb->s_flags |= MS_TAGGED;       */
5142 +
5143         server->maxfilesize = fsinfo->maxfilesize;
5144  
5145         server->time_delta = fsinfo->time_delta;
5146 diff -NurpP --minimal linux-3.7.1/fs/nfs/dir.c linux-3.7.1-vs2.3.5.5/fs/nfs/dir.c
5147 --- linux-3.7.1/fs/nfs/dir.c    2012-12-11 03:30:57.000000000 +0000
5148 +++ linux-3.7.1-vs2.3.5.5/fs/nfs/dir.c  2012-12-18 15:13:16.000000000 +0000
5149 @@ -36,6 +36,7 @@
5150  #include <linux/sched.h>
5151  #include <linux/kmemleak.h>
5152  #include <linux/xattr.h>
5153 +#include <linux/vs_tag.h>
5154  
5155  #include "delegation.h"
5156  #include "iostat.h"
5157 @@ -1252,6 +1253,7 @@ struct dentry *nfs_lookup(struct inode *
5158         /* Success: notify readdir to use READDIRPLUS */
5159         nfs_advise_use_readdirplus(dir);
5160  
5161 +       dx_propagate_tag(nd, inode);
5162  no_entry:
5163         res = d_materialise_unique(dentry, inode);
5164         if (res != NULL) {
5165 diff -NurpP --minimal linux-3.7.1/fs/nfs/inode.c linux-3.7.1-vs2.3.5.5/fs/nfs/inode.c
5166 --- linux-3.7.1/fs/nfs/inode.c  2012-12-11 03:30:57.000000000 +0000
5167 +++ linux-3.7.1-vs2.3.5.5/fs/nfs/inode.c        2012-12-18 15:13:16.000000000 +0000
5168 @@ -39,6 +39,7 @@
5169  #include <linux/compat.h>
5170  #include <linux/freezer.h>
5171  #include <linux/crc32.h>
5172 +#include <linux/vs_tag.h>
5173  
5174  #include <asm/uaccess.h>
5175  
5176 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5177         if (inode->i_state & I_NEW) {
5178                 struct nfs_inode *nfsi = NFS_I(inode);
5179                 unsigned long now = jiffies;
5180 +               uid_t uid;
5181 +               gid_t gid;
5182  
5183                 /* We set i_ino for the few things that still rely on it,
5184                  * such as stat(2) */
5185 @@ -323,8 +326,8 @@ nfs_fhget(struct super_block *sb, struct
5186                 inode->i_version = 0;
5187                 inode->i_size = 0;
5188                 clear_nlink(inode);
5189 -               inode->i_uid = -2;
5190 -               inode->i_gid = -2;
5191 +               uid = -2;
5192 +               gid = -2;
5193                 inode->i_blocks = 0;
5194                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5195                 nfsi->write_io = 0;
5196 @@ -358,11 +361,11 @@ nfs_fhget(struct super_block *sb, struct
5197                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5198                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5199                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5200 -                       inode->i_uid = fattr->uid;
5201 +                       uid = fattr->uid;
5202                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5203                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5204                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5205 -                       inode->i_gid = fattr->gid;
5206 +                       gid = fattr->gid;
5207                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5208                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5209                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5210 @@ -373,6 +376,11 @@ nfs_fhget(struct super_block *sb, struct
5211                          */
5212                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5213                 }
5214 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5215 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5216 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5217 +                               /* maybe fattr->xid someday */
5218 +
5219                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5220                 nfsi->attrtimeo_timestamp = now;
5221                 nfsi->access_cache = RB_ROOT;
5222 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5223                         inode->i_uid = attr->ia_uid;
5224                 if ((attr->ia_valid & ATTR_GID) != 0)
5225                         inode->i_gid = attr->ia_gid;
5226 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5227 +                       inode->i_tag = attr->ia_tag;
5228                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5229                 spin_unlock(&inode->i_lock);
5230         }
5231 @@ -968,6 +978,9 @@ static int nfs_check_inode_attributes(st
5232         struct nfs_inode *nfsi = NFS_I(inode);
5233         loff_t cur_size, new_isize;
5234         unsigned long invalid = 0;
5235 +       uid_t uid;
5236 +       gid_t gid;
5237 +       tag_t tag;
5238  
5239  
5240         if (nfs_have_delegated_attributes(inode))
5241 @@ -993,13 +1006,18 @@ static int nfs_check_inode_attributes(st
5242                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5243         }
5244  
5245 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5246 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5247 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5248 +
5249         /* Have any file permissions changed? */
5250         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5251                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5252 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5253 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5254                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5255 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5256 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5257                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5258 +               /* maybe check for tag too? */
5259  
5260         /* Has the link count changed? */
5261         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5262 @@ -1303,6 +1321,9 @@ static int nfs_update_inode(struct inode
5263         unsigned long invalid = 0;
5264         unsigned long now = jiffies;
5265         unsigned long save_cache_validity;
5266 +       uid_t uid;
5267 +       gid_t gid;
5268 +       tag_t tag;
5269  
5270         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5271                         __func__, inode->i_sb->s_id, inode->i_ino,
5272 @@ -1404,6 +1425,9 @@ static int nfs_update_inode(struct inode
5273                                 | NFS_INO_REVAL_PAGECACHE
5274                                 | NFS_INO_REVAL_FORCED);
5275  
5276 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5277 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5278 +       tag = inode->i_tag;
5279  
5280         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5281                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5282 @@ -1425,9 +1449,9 @@ static int nfs_update_inode(struct inode
5283                                 | NFS_INO_REVAL_FORCED);
5284  
5285         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5286 -               if (inode->i_uid != fattr->uid) {
5287 +               if (uid != fattr->uid) {
5288                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5289 -                       inode->i_uid = fattr->uid;
5290 +                       uid = fattr->uid;
5291                 }
5292         } else if (server->caps & NFS_CAP_OWNER)
5293                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5294 @@ -1436,9 +1460,9 @@ static int nfs_update_inode(struct inode
5295                                 | NFS_INO_REVAL_FORCED);
5296  
5297         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5298 -               if (inode->i_gid != fattr->gid) {
5299 +               if (gid != fattr->gid) {
5300                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5301 -                       inode->i_gid = fattr->gid;
5302 +                       gid = fattr->gid;
5303                 }
5304         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5305                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5306 @@ -1446,6 +1470,10 @@ static int nfs_update_inode(struct inode
5307                                 | NFS_INO_INVALID_ACL
5308                                 | NFS_INO_REVAL_FORCED);
5309  
5310 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5311 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5312 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5313 +
5314         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5315                 if (inode->i_nlink != fattr->nlink) {
5316                         invalid |= NFS_INO_INVALID_ATTR;
5317 diff -NurpP --minimal linux-3.7.1/fs/nfs/nfs3xdr.c linux-3.7.1-vs2.3.5.5/fs/nfs/nfs3xdr.c
5318 --- linux-3.7.1/fs/nfs/nfs3xdr.c        2012-12-11 03:30:57.000000000 +0000
5319 +++ linux-3.7.1-vs2.3.5.5/fs/nfs/nfs3xdr.c      2012-12-18 15:13:16.000000000 +0000
5320 @@ -20,6 +20,7 @@
5321  #include <linux/nfs3.h>
5322  #include <linux/nfs_fs.h>
5323  #include <linux/nfsacl.h>
5324 +#include <linux/vs_tag.h>
5325  #include "internal.h"
5326  
5327  #define NFSDBG_FACILITY                NFSDBG_XDR
5328 @@ -560,7 +561,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5329   *             set_mtime       mtime;
5330   *     };
5331   */
5332 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5333 +static void encode_sattr3(struct xdr_stream *xdr,
5334 +       const struct iattr *attr, int tag)
5335  {
5336         u32 nbytes;
5337         __be32 *p;
5338 @@ -592,15 +594,19 @@ static void encode_sattr3(struct xdr_str
5339         } else
5340                 *p++ = xdr_zero;
5341  
5342 -       if (attr->ia_valid & ATTR_UID) {
5343 +       if (attr->ia_valid & ATTR_UID ||
5344 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5345                 *p++ = xdr_one;
5346 -               *p++ = cpu_to_be32(attr->ia_uid);
5347 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5348 +                       attr->ia_uid, attr->ia_tag));
5349         } else
5350                 *p++ = xdr_zero;
5351  
5352 -       if (attr->ia_valid & ATTR_GID) {
5353 +       if (attr->ia_valid & ATTR_GID ||
5354 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5355                 *p++ = xdr_one;
5356 -               *p++ = cpu_to_be32(attr->ia_gid);
5357 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5358 +                       attr->ia_gid, attr->ia_tag));
5359         } else
5360                 *p++ = xdr_zero;
5361  
5362 @@ -879,7 +885,7 @@ static void nfs3_xdr_enc_setattr3args(st
5363                                       const struct nfs3_sattrargs *args)
5364  {
5365         encode_nfs_fh3(xdr, args->fh);
5366 -       encode_sattr3(xdr, args->sattr);
5367 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5368         encode_sattrguard3(xdr, args);
5369  }
5370  
5371 @@ -1029,13 +1035,13 @@ static void nfs3_xdr_enc_write3args(stru
5372   *     };
5373   */
5374  static void encode_createhow3(struct xdr_stream *xdr,
5375 -                             const struct nfs3_createargs *args)
5376 +       const struct nfs3_createargs *args, int tag)
5377  {
5378         encode_uint32(xdr, args->createmode);
5379         switch (args->createmode) {
5380         case NFS3_CREATE_UNCHECKED:
5381         case NFS3_CREATE_GUARDED:
5382 -               encode_sattr3(xdr, args->sattr);
5383 +               encode_sattr3(xdr, args->sattr, tag);
5384                 break;
5385         case NFS3_CREATE_EXCLUSIVE:
5386                 encode_createverf3(xdr, args->verifier);
5387 @@ -1050,7 +1056,7 @@ static void nfs3_xdr_enc_create3args(str
5388                                      const struct nfs3_createargs *args)
5389  {
5390         encode_diropargs3(xdr, args->fh, args->name, args->len);
5391 -       encode_createhow3(xdr, args);
5392 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5393  }
5394  
5395  /*
5396 @@ -1066,7 +1072,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5397                                     const struct nfs3_mkdirargs *args)
5398  {
5399         encode_diropargs3(xdr, args->fh, args->name, args->len);
5400 -       encode_sattr3(xdr, args->sattr);
5401 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5402  }
5403  
5404  /*
5405 @@ -1083,9 +1089,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5406   *     };
5407   */
5408  static void encode_symlinkdata3(struct xdr_stream *xdr,
5409 -                               const struct nfs3_symlinkargs *args)
5410 +       const struct nfs3_symlinkargs *args, int tag)
5411  {
5412 -       encode_sattr3(xdr, args->sattr);
5413 +       encode_sattr3(xdr, args->sattr, tag);
5414         encode_nfspath3(xdr, args->pages, args->pathlen);
5415  }
5416  
5417 @@ -1094,7 +1100,7 @@ static void nfs3_xdr_enc_symlink3args(st
5418                                       const struct nfs3_symlinkargs *args)
5419  {
5420         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5421 -       encode_symlinkdata3(xdr, args);
5422 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5423  }
5424  
5425  /*
5426 @@ -1122,24 +1128,24 @@ static void nfs3_xdr_enc_symlink3args(st
5427   *     };
5428   */
5429  static void encode_devicedata3(struct xdr_stream *xdr,
5430 -                              const struct nfs3_mknodargs *args)
5431 +       const struct nfs3_mknodargs *args, int tag)
5432  {
5433 -       encode_sattr3(xdr, args->sattr);
5434 +       encode_sattr3(xdr, args->sattr, tag);
5435         encode_specdata3(xdr, args->rdev);
5436  }
5437  
5438  static void encode_mknoddata3(struct xdr_stream *xdr,
5439 -                             const struct nfs3_mknodargs *args)
5440 +       const struct nfs3_mknodargs *args, int tag)
5441  {
5442         encode_ftype3(xdr, args->type);
5443         switch (args->type) {
5444         case NF3CHR:
5445         case NF3BLK:
5446 -               encode_devicedata3(xdr, args);
5447 +               encode_devicedata3(xdr, args, tag);
5448                 break;
5449         case NF3SOCK:
5450         case NF3FIFO:
5451 -               encode_sattr3(xdr, args->sattr);
5452 +               encode_sattr3(xdr, args->sattr, tag);
5453                 break;
5454         case NF3REG:
5455         case NF3DIR:
5456 @@ -1154,7 +1160,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5457                                     const struct nfs3_mknodargs *args)
5458  {
5459         encode_diropargs3(xdr, args->fh, args->name, args->len);
5460 -       encode_mknoddata3(xdr, args);
5461 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5462  }
5463  
5464  /*
5465 diff -NurpP --minimal linux-3.7.1/fs/nfs/super.c linux-3.7.1-vs2.3.5.5/fs/nfs/super.c
5466 --- linux-3.7.1/fs/nfs/super.c  2012-12-11 03:30:57.000000000 +0000
5467 +++ linux-3.7.1-vs2.3.5.5/fs/nfs/super.c        2012-12-18 15:13:16.000000000 +0000
5468 @@ -55,6 +55,7 @@
5469  #include <linux/nsproxy.h>
5470  #include <linux/rcupdate.h>
5471  #include <linux/kthread.h>
5472 +#include <linux/vs_tag.h>
5473  
5474  #include <asm/uaccess.h>
5475  
5476 @@ -102,6 +103,7 @@ enum {
5477         Opt_mountport,
5478         Opt_mountvers,
5479         Opt_minorversion,
5480 +       Opt_tagid,
5481  
5482         /* Mount options that take string arguments */
5483         Opt_nfsvers,
5484 @@ -114,6 +116,9 @@ enum {
5485         /* Special mount options */
5486         Opt_userspace, Opt_deprecated, Opt_sloppy,
5487  
5488 +       /* Linux-VServer tagging options */
5489 +       Opt_tag, Opt_notag,
5490 +
5491         Opt_err
5492  };
5493  
5494 @@ -183,6 +188,10 @@ static const match_table_t nfs_mount_opt
5495         { Opt_fscache_uniq, "fsc=%s" },
5496         { Opt_local_lock, "local_lock=%s" },
5497  
5498 +       { Opt_tag, "tag" },
5499 +       { Opt_notag, "notag" },
5500 +       { Opt_tagid, "tagid=%u" },
5501 +
5502         /* The following needs to be listed after all other options */
5503         { Opt_nfsvers, "v%s" },
5504  
5505 @@ -678,6 +687,7 @@ static void nfs_show_mount_options(struc
5506                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5507                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5508                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5509 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5510                 { 0, NULL, NULL }
5511         };
5512         const struct proc_nfs_info *nfs_infop;
5513 @@ -1304,6 +1314,14 @@ static int nfs_parse_mount_options(char
5514                 case Opt_nomigration:
5515                         mnt->options &= NFS_OPTION_MIGRATION;
5516                         break;
5517 +#ifndef CONFIG_TAGGING_NONE
5518 +               case Opt_tag:
5519 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5520 +                       break;
5521 +               case Opt_notag:
5522 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5523 +                       break;
5524 +#endif
5525  
5526                 /*
5527                  * options that take numeric values
5528 @@ -1390,6 +1408,12 @@ static int nfs_parse_mount_options(char
5529                                 goto out_invalid_value;
5530                         mnt->minorversion = option;
5531                         break;
5532 +#ifdef CONFIG_PROPAGATE
5533 +               case Opt_tagid:
5534 +                       /* use args[0] */
5535 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5536 +                       break;
5537 +#endif
5538  
5539                 /*
5540                  * options that take text values
5541 diff -NurpP --minimal linux-3.7.1/fs/nfsd/auth.c linux-3.7.1-vs2.3.5.5/fs/nfsd/auth.c
5542 --- linux-3.7.1/fs/nfsd/auth.c  2012-12-11 03:30:57.000000000 +0000
5543 +++ linux-3.7.1-vs2.3.5.5/fs/nfsd/auth.c        2012-12-18 15:13:16.000000000 +0000
5544 @@ -2,6 +2,7 @@
5545  
5546  #include <linux/sched.h>
5547  #include <linux/user_namespace.h>
5548 +#include <linux/vs_tag.h>
5549  #include "nfsd.h"
5550  #include "auth.h"
5551  
5552 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5553  
5554         new->fsuid = rqstp->rq_cred.cr_uid;
5555         new->fsgid = rqstp->rq_cred.cr_gid;
5556 +       /* FIXME: this desperately needs a tag :)
5557 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5558 +                       */
5559  
5560         rqgi = rqstp->rq_cred.cr_group_info;
5561  
5562 diff -NurpP --minimal linux-3.7.1/fs/nfsd/nfs3xdr.c linux-3.7.1-vs2.3.5.5/fs/nfsd/nfs3xdr.c
5563 --- linux-3.7.1/fs/nfsd/nfs3xdr.c       2012-12-11 03:30:57.000000000 +0000
5564 +++ linux-3.7.1-vs2.3.5.5/fs/nfsd/nfs3xdr.c     2012-12-18 15:13:16.000000000 +0000
5565 @@ -7,6 +7,7 @@
5566   */
5567  
5568  #include <linux/namei.h>
5569 +#include <linux/vs_tag.h>
5570  #include "xdr3.h"
5571  #include "auth.h"
5572  
5573 @@ -95,6 +96,8 @@ static __be32 *
5574  decode_sattr3(__be32 *p, struct iattr *iap)
5575  {
5576         u32     tmp;
5577 +       uid_t   uid = 0;
5578 +       gid_t   gid = 0;
5579  
5580         iap->ia_valid = 0;
5581  
5582 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5583         }
5584         if (*p++) {
5585                 iap->ia_valid |= ATTR_UID;
5586 -               iap->ia_uid = ntohl(*p++);
5587 +               uid = ntohl(*p++);
5588         }
5589         if (*p++) {
5590                 iap->ia_valid |= ATTR_GID;
5591 -               iap->ia_gid = ntohl(*p++);
5592 +               gid = ntohl(*p++);
5593         }
5594 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5595 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5596 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5597         if (*p++) {
5598                 u64     newsize;
5599  
5600 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5601         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5602         *p++ = htonl((u32) stat->mode);
5603         *p++ = htonl((u32) stat->nlink);
5604 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5605 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5606 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5607 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5608 +               stat->uid, stat->tag)));
5609 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5610 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5611 +               stat->gid, stat->tag)));
5612         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5613                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5614         } else {
5615 diff -NurpP --minimal linux-3.7.1/fs/nfsd/nfs4xdr.c linux-3.7.1-vs2.3.5.5/fs/nfsd/nfs4xdr.c
5616 --- linux-3.7.1/fs/nfsd/nfs4xdr.c       2012-12-11 03:30:57.000000000 +0000
5617 +++ linux-3.7.1-vs2.3.5.5/fs/nfsd/nfs4xdr.c     2012-12-18 15:13:16.000000000 +0000
5618 @@ -46,6 +46,7 @@
5619  #include <linux/utsname.h>
5620  #include <linux/pagemap.h>
5621  #include <linux/sunrpc/svcauth_gss.h>
5622 +#include <linux/vs_tag.h>
5623  
5624  #include "idmap.h"
5625  #include "acl.h"
5626 @@ -2351,14 +2352,18 @@ out_acl:
5627                 WRITE32(stat.nlink);
5628         }
5629         if (bmval1 & FATTR4_WORD1_OWNER) {
5630 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5631 +               status = nfsd4_encode_user(rqstp,
5632 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5633 +                       stat.uid, stat.tag), &p, &buflen);
5634                 if (status == nfserr_resource)
5635                         goto out_resource;
5636                 if (status)
5637                         goto out;
5638         }
5639         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5640 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5641 +               status = nfsd4_encode_group(rqstp,
5642 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5643 +                       stat.gid, stat.tag), &p, &buflen);
5644                 if (status == nfserr_resource)
5645                         goto out_resource;
5646                 if (status)
5647 diff -NurpP --minimal linux-3.7.1/fs/nfsd/nfsxdr.c linux-3.7.1-vs2.3.5.5/fs/nfsd/nfsxdr.c
5648 --- linux-3.7.1/fs/nfsd/nfsxdr.c        2012-12-11 03:30:57.000000000 +0000
5649 +++ linux-3.7.1-vs2.3.5.5/fs/nfsd/nfsxdr.c      2012-12-18 15:13:16.000000000 +0000
5650 @@ -6,6 +6,7 @@
5651  
5652  #include "xdr.h"
5653  #include "auth.h"
5654 +#include <linux/vs_tag.h>
5655  
5656  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5657  
5658 @@ -88,6 +89,8 @@ static __be32 *
5659  decode_sattr(__be32 *p, struct iattr *iap)
5660  {
5661         u32     tmp, tmp1;
5662 +       uid_t   uid = 0;
5663 +       gid_t   gid = 0;
5664  
5665         iap->ia_valid = 0;
5666  
5667 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5668         }
5669         if ((tmp = ntohl(*p++)) != (u32)-1) {
5670                 iap->ia_valid |= ATTR_UID;
5671 -               iap->ia_uid = tmp;
5672 +               uid = tmp;
5673         }
5674         if ((tmp = ntohl(*p++)) != (u32)-1) {
5675                 iap->ia_valid |= ATTR_GID;
5676 -               iap->ia_gid = tmp;
5677 +               gid = tmp;
5678         }
5679 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5680 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5681 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5682         if ((tmp = ntohl(*p++)) != (u32)-1) {
5683                 iap->ia_valid |= ATTR_SIZE;
5684                 iap->ia_size = tmp;
5685 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5686         *p++ = htonl(nfs_ftypes[type >> 12]);
5687         *p++ = htonl((u32) stat->mode);
5688         *p++ = htonl((u32) stat->nlink);
5689 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5690 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5691 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5692 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5693 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5694 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5695  
5696         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5697                 *p++ = htonl(NFS_MAXPATHLEN);
5698 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/dlmglue.c linux-3.7.1-vs2.3.5.5/fs/ocfs2/dlmglue.c
5699 --- linux-3.7.1/fs/ocfs2/dlmglue.c      2012-12-11 03:30:57.000000000 +0000
5700 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/dlmglue.c    2012-12-18 15:13:16.000000000 +0000
5701 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5702         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5703         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5704         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5705 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5706         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5707         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5708         lvb->lvb_iatime_packed  =
5709 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5710  
5711         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5712         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5713 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5714         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5715         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5716         ocfs2_unpack_timespec(&inode->i_atime,
5717 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/dlmglue.h linux-3.7.1-vs2.3.5.5/fs/ocfs2/dlmglue.h
5718 --- linux-3.7.1/fs/ocfs2/dlmglue.h      2012-12-11 03:30:57.000000000 +0000
5719 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/dlmglue.h    2012-12-18 15:13:16.000000000 +0000
5720 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5721         __be16       lvb_inlink;
5722         __be32       lvb_iattr;
5723         __be32       lvb_igeneration;
5724 -       __be32       lvb_reserved2;
5725 +       __be16       lvb_itag;
5726 +       __be16       lvb_reserved2;
5727  };
5728  
5729  #define OCFS2_QINFO_LVB_VERSION 1
5730 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/file.c linux-3.7.1-vs2.3.5.5/fs/ocfs2/file.c
5731 --- linux-3.7.1/fs/ocfs2/file.c 2012-12-11 03:30:57.000000000 +0000
5732 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/file.c       2012-12-18 15:13:16.000000000 +0000
5733 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5734                 attr->ia_valid &= ~ATTR_SIZE;
5735  
5736  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5737 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5738 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5739         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5740                 return 0;
5741  
5742 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/inode.c linux-3.7.1-vs2.3.5.5/fs/ocfs2/inode.c
5743 --- linux-3.7.1/fs/ocfs2/inode.c        2012-12-11 03:30:57.000000000 +0000
5744 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/inode.c      2012-12-18 15:13:16.000000000 +0000
5745 @@ -28,6 +28,7 @@
5746  #include <linux/highmem.h>
5747  #include <linux/pagemap.h>
5748  #include <linux/quotaops.h>
5749 +#include <linux/vs_tag.h>
5750  
5751  #include <asm/byteorder.h>
5752  
5753 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5754  {
5755         unsigned int flags = OCFS2_I(inode)->ip_attr;
5756  
5757 -       inode->i_flags &= ~(S_IMMUTABLE |
5758 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5759                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5760  
5761         if (flags & OCFS2_IMMUTABLE_FL)
5762                 inode->i_flags |= S_IMMUTABLE;
5763 +       if (flags & OCFS2_IXUNLINK_FL)
5764 +               inode->i_flags |= S_IXUNLINK;
5765  
5766         if (flags & OCFS2_SYNC_FL)
5767                 inode->i_flags |= S_SYNC;
5768 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5769                 inode->i_flags |= S_NOATIME;
5770         if (flags & OCFS2_DIRSYNC_FL)
5771                 inode->i_flags |= S_DIRSYNC;
5772 +
5773 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5774 +
5775 +       if (flags & OCFS2_BARRIER_FL)
5776 +               inode->i_vflags |= V_BARRIER;
5777 +       if (flags & OCFS2_COW_FL)
5778 +               inode->i_vflags |= V_COW;
5779  }
5780  
5781  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5782  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5783  {
5784         unsigned int flags = oi->vfs_inode.i_flags;
5785 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5786 +
5787 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5788 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5789 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5790 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5791 +
5792 +       if (flags & S_IMMUTABLE)
5793 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5794 +       if (flags & S_IXUNLINK)
5795 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5796  
5797 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5798 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5799         if (flags & S_SYNC)
5800                 oi->ip_attr |= OCFS2_SYNC_FL;
5801         if (flags & S_APPEND)
5802                 oi->ip_attr |= OCFS2_APPEND_FL;
5803 -       if (flags & S_IMMUTABLE)
5804 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5805         if (flags & S_NOATIME)
5806                 oi->ip_attr |= OCFS2_NOATIME_FL;
5807         if (flags & S_DIRSYNC)
5808                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5809 +
5810 +       if (vflags & V_BARRIER)
5811 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5812 +       if (vflags & V_COW)
5813 +               oi->ip_attr |= OCFS2_COW_FL;
5814  }
5815  
5816  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5817 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5818         struct super_block *sb;
5819         struct ocfs2_super *osb;
5820         int use_plocks = 1;
5821 +       uid_t uid;
5822 +       gid_t gid;
5823  
5824         sb = inode->i_sb;
5825         osb = OCFS2_SB(sb);
5826 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5827         inode->i_generation = le32_to_cpu(fe->i_generation);
5828         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5829         inode->i_mode = le16_to_cpu(fe->i_mode);
5830 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5831 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5832 +       uid = le32_to_cpu(fe->i_uid);
5833 +       gid = le32_to_cpu(fe->i_gid);
5834 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5835 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5836 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5837 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5838  
5839         /* Fast symlinks will have i_size but no allocated clusters. */
5840         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5841 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/inode.h linux-3.7.1-vs2.3.5.5/fs/ocfs2/inode.h
5842 --- linux-3.7.1/fs/ocfs2/inode.h        2012-12-11 03:30:57.000000000 +0000
5843 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/inode.h      2012-12-18 15:13:16.000000000 +0000
5844 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5845  
5846  void ocfs2_set_inode_flags(struct inode *inode);
5847  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5848 +int ocfs2_sync_flags(struct inode *inode, int, int);
5849  
5850  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5851  {
5852 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/ioctl.c linux-3.7.1-vs2.3.5.5/fs/ocfs2/ioctl.c
5853 --- linux-3.7.1/fs/ocfs2/ioctl.c        2012-12-11 03:30:57.000000000 +0000
5854 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/ioctl.c      2012-12-18 15:13:16.000000000 +0000
5855 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5856         return status;
5857  }
5858  
5859 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5860 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5861 +{
5862 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5863 +       struct buffer_head *bh = NULL;
5864 +       handle_t *handle = NULL;
5865 +       int status;
5866 +
5867 +       status = ocfs2_inode_lock(inode, &bh, 1);
5868 +       if (status < 0) {
5869 +               mlog_errno(status);
5870 +               return status;
5871 +       }
5872 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5873 +       if (IS_ERR(handle)) {
5874 +               status = PTR_ERR(handle);
5875 +               mlog_errno(status);
5876 +               goto bail_unlock;
5877 +       }
5878 +
5879 +       inode->i_flags = flags;
5880 +       inode->i_vflags = vflags;
5881 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5882 +
5883 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5884 +       if (status < 0)
5885 +               mlog_errno(status);
5886 +
5887 +       ocfs2_commit_trans(osb, handle);
5888 +bail_unlock:
5889 +       ocfs2_inode_unlock(inode, 1);
5890 +       brelse(bh);
5891 +       return status;
5892 +}
5893 +
5894 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5895                                 unsigned mask)
5896  {
5897         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5898 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5899         if (!S_ISDIR(inode->i_mode))
5900                 flags &= ~OCFS2_DIRSYNC_FL;
5901  
5902 +       if (IS_BARRIER(inode)) {
5903 +               vxwprintk_task(1, "messing with the barrier.");
5904 +               goto bail_unlock;
5905 +       }
5906 +
5907         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5908         if (IS_ERR(handle)) {
5909                 status = PTR_ERR(handle);
5910 @@ -879,6 +918,7 @@ bail:
5911         return status;
5912  }
5913  
5914 +
5915  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5916  {
5917         struct inode *inode = filp->f_path.dentry->d_inode;
5918 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/namei.c linux-3.7.1-vs2.3.5.5/fs/ocfs2/namei.c
5919 --- linux-3.7.1/fs/ocfs2/namei.c        2012-12-11 03:30:57.000000000 +0000
5920 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/namei.c      2012-12-18 15:13:16.000000000 +0000
5921 @@ -41,6 +41,7 @@
5922  #include <linux/slab.h>
5923  #include <linux/highmem.h>
5924  #include <linux/quotaops.h>
5925 +#include <linux/vs_tag.h>
5926  
5927  #include <cluster/masklog.h>
5928  
5929 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5930         struct ocfs2_dinode *fe = NULL;
5931         struct ocfs2_extent_list *fel;
5932         u16 feat;
5933 +       tag_t tag;
5934  
5935         *new_fe_bh = NULL;
5936  
5937 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5938         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5939         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5940         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5941 -       fe->i_uid = cpu_to_le32(inode->i_uid);
5942 -       fe->i_gid = cpu_to_le32(inode->i_gid);
5943 +
5944 +       tag = dx_current_fstag(osb->sb);
5945 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
5946 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
5947 +       inode->i_tag = tag;
5948         fe->i_mode = cpu_to_le16(inode->i_mode);
5949         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5950                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5951 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/ocfs2.h linux-3.7.1-vs2.3.5.5/fs/ocfs2/ocfs2.h
5952 --- linux-3.7.1/fs/ocfs2/ocfs2.h        2012-12-11 03:30:57.000000000 +0000
5953 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/ocfs2.h      2012-12-18 15:13:16.000000000 +0000
5954 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5955                                                      writes */
5956         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5957         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5958 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5959  };
5960  
5961  #define OCFS2_OSB_SOFT_RO                      0x0001
5962 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/ocfs2_fs.h linux-3.7.1-vs2.3.5.5/fs/ocfs2/ocfs2_fs.h
5963 --- linux-3.7.1/fs/ocfs2/ocfs2_fs.h     2012-12-11 03:30:57.000000000 +0000
5964 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/ocfs2_fs.h   2012-12-18 15:13:16.000000000 +0000
5965 @@ -266,6 +266,11 @@
5966  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5967  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5968  
5969 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5970 +
5971 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5972 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5973 +
5974  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5975  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5976  
5977 diff -NurpP --minimal linux-3.7.1/fs/ocfs2/super.c linux-3.7.1-vs2.3.5.5/fs/ocfs2/super.c
5978 --- linux-3.7.1/fs/ocfs2/super.c        2012-12-11 03:30:57.000000000 +0000
5979 +++ linux-3.7.1-vs2.3.5.5/fs/ocfs2/super.c      2012-12-18 15:13:16.000000000 +0000
5980 @@ -185,6 +185,7 @@ enum {
5981         Opt_coherency_full,
5982         Opt_resv_level,
5983         Opt_dir_resv_level,
5984 +       Opt_tag, Opt_notag, Opt_tagid,
5985         Opt_err,
5986  };
5987  
5988 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5989         {Opt_coherency_full, "coherency=full"},
5990         {Opt_resv_level, "resv_level=%u"},
5991         {Opt_dir_resv_level, "dir_resv_level=%u"},
5992 +       {Opt_tag, "tag"},
5993 +       {Opt_notag, "notag"},
5994 +       {Opt_tagid, "tagid=%u"},
5995         {Opt_err, NULL}
5996  };
5997  
5998 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5999                 goto out;
6000         }
6001  
6002 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6003 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6004 +               ret = -EINVAL;
6005 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6006 +               goto out;
6007 +       }
6008 +
6009         /* We're going to/from readonly mode. */
6010         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6011                 /* Disable quota accounting before remounting RO */
6012 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6013  
6014         ocfs2_complete_mount_recovery(osb);
6015  
6016 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6017 +               sb->s_flags |= MS_TAGGED;
6018 +
6019         if (ocfs2_mount_local(osb))
6020                 snprintf(nodestr, sizeof(nodestr), "local");
6021         else
6022 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
6023                             option < OCFS2_MAX_RESV_LEVEL)
6024                                 mopt->dir_resv_level = option;
6025                         break;
6026 +#ifndef CONFIG_TAGGING_NONE
6027 +               case Opt_tag:
6028 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6029 +                       break;
6030 +               case Opt_notag:
6031 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6032 +                       break;
6033 +#endif
6034 +#ifdef CONFIG_PROPAGATE
6035 +               case Opt_tagid:
6036 +                       /* use args[0] */
6037 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6038 +                       break;
6039 +#endif
6040                 default:
6041                         mlog(ML_ERROR,
6042                              "Unrecognized mount option \"%s\" "
6043 diff -NurpP --minimal linux-3.7.1/fs/open.c linux-3.7.1-vs2.3.5.5/fs/open.c
6044 --- linux-3.7.1/fs/open.c       2012-12-11 03:30:57.000000000 +0000
6045 +++ linux-3.7.1-vs2.3.5.5/fs/open.c     2012-12-18 15:13:16.000000000 +0000
6046 @@ -30,6 +30,11 @@
6047  #include <linux/fs_struct.h>
6048  #include <linux/ima.h>
6049  #include <linux/dnotify.h>
6050 +#include <linux/vs_base.h>
6051 +#include <linux/vs_limit.h>
6052 +#include <linux/vs_tag.h>
6053 +#include <linux/vs_cowbl.h>
6054 +#include <linux/vserver/dlimit.h>
6055  
6056  #include "internal.h"
6057  
6058 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6059         error = user_path(pathname, &path);
6060         if (error)
6061                 goto out;
6062 +
6063 +#ifdef CONFIG_VSERVER_COWBL
6064 +       error = cow_check_and_break(&path);
6065 +       if (error)
6066 +               goto dput_and_out;
6067 +#endif
6068         inode = path.dentry->d_inode;
6069  
6070         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6071 @@ -492,6 +503,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6072  
6073         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6074         if (!error) {
6075 +#ifdef CONFIG_VSERVER_COWBL
6076 +               error = cow_check_and_break(&path);
6077 +               if (!error)
6078 +#endif
6079                 error = chmod_common(&path, mode);
6080                 path_put(&path);
6081         }
6082 @@ -519,13 +534,13 @@ static int chown_common(struct path *pat
6083                 if (!uid_valid(uid))
6084                         return -EINVAL;
6085                 newattrs.ia_valid |= ATTR_UID;
6086 -               newattrs.ia_uid = uid;
6087 +               newattrs.ia_uid = dx_map_uid(user);
6088         }
6089         if (group != (gid_t) -1) {
6090                 if (!gid_valid(gid))
6091                         return -EINVAL;
6092                 newattrs.ia_valid |= ATTR_GID;
6093 -               newattrs.ia_gid = gid;
6094 +               newattrs.ia_gid = dx_map_gid(group);
6095         }
6096         if (!S_ISDIR(inode->i_mode))
6097                 newattrs.ia_valid |=
6098 @@ -558,6 +573,18 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6099         error = mnt_want_write(path.mnt);
6100         if (error)
6101                 goto out_release;
6102 +#ifdef CONFIG_VSERVER_COWBL
6103 +       error = cow_check_and_break(&path);
6104 +       if (!error)
6105 +#endif
6106 +#ifdef CONFIG_VSERVER_COWBL
6107 +       error = cow_check_and_break(&path);
6108 +       if (!error)
6109 +#endif
6110 +#ifdef CONFIG_VSERVER_COWBL
6111 +       error = cow_check_and_break(&path);
6112 +       if (!error)
6113 +#endif
6114         error = chown_common(&path, user, group);
6115         mnt_drop_write(path.mnt);
6116  out_release:
6117 diff -NurpP --minimal linux-3.7.1/fs/proc/array.c linux-3.7.1-vs2.3.5.5/fs/proc/array.c
6118 --- linux-3.7.1/fs/proc/array.c 2012-12-11 03:30:57.000000000 +0000
6119 +++ linux-3.7.1-vs2.3.5.5/fs/proc/array.c       2012-12-18 15:13:16.000000000 +0000
6120 @@ -82,6 +82,8 @@
6121  #include <linux/ptrace.h>
6122  #include <linux/tracehook.h>
6123  #include <linux/user_namespace.h>
6124 +#include <linux/vs_context.h>
6125 +#include <linux/vs_network.h>
6126  
6127  #include <asm/pgtable.h>
6128  #include <asm/processor.h>
6129 @@ -172,6 +174,9 @@ static inline void task_state(struct seq
6130         rcu_read_lock();
6131         ppid = pid_alive(p) ?
6132                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6133 +       if (unlikely(vx_current_initpid(p->pid)))
6134 +               ppid = 0;
6135 +
6136         tpid = 0;
6137         if (pid_alive(p)) {
6138                 struct task_struct *tracer = ptrace_parent(p);
6139 @@ -296,7 +301,7 @@ static inline void task_sig(struct seq_f
6140  }
6141  
6142  static void render_cap_t(struct seq_file *m, const char *header,
6143 -                       kernel_cap_t *a)
6144 +                       struct vx_info *vxi, kernel_cap_t *a)
6145  {
6146         unsigned __capi;
6147  
6148 @@ -321,10 +326,11 @@ static inline void task_cap(struct seq_f
6149         cap_bset        = cred->cap_bset;
6150         rcu_read_unlock();
6151  
6152 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6153 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6154 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6155 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6156 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6157 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6158 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6159 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6160 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6161  }
6162  
6163  static inline void task_context_switch_counts(struct seq_file *m,
6164 @@ -346,6 +352,42 @@ static void task_cpus_allowed(struct seq
6165         seq_putc(m, '\n');
6166  }
6167  
6168 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6169 +                       struct pid *pid, struct task_struct *task)
6170 +{
6171 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6172 +                       "Count:\t%u\n"
6173 +                       "uts:\t%p(%c)\n"
6174 +                       "ipc:\t%p(%c)\n"
6175 +                       "mnt:\t%p(%c)\n"
6176 +                       "pid:\t%p(%c)\n"
6177 +                       "net:\t%p(%c)\n",
6178 +                       task->nsproxy,
6179 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6180 +                       atomic_read(&task->nsproxy->count),
6181 +                       task->nsproxy->uts_ns,
6182 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6183 +                       task->nsproxy->ipc_ns,
6184 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6185 +                       task->nsproxy->mnt_ns,
6186 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6187 +                       task->nsproxy->pid_ns,
6188 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6189 +                       task->nsproxy->net_ns,
6190 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6191 +       return 0;
6192 +}
6193 +
6194 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6195 +{
6196 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6197 +               return;
6198 +
6199 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6200 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6201 +}
6202 +
6203 +
6204  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6205                         struct pid *pid, struct task_struct *task)
6206  {
6207 @@ -362,6 +404,7 @@ int proc_pid_status(struct seq_file *m,
6208         task_cap(m, task);
6209         task_cpus_allowed(m, task);
6210         cpuset_task_status_allowed(m, task);
6211 +       task_vs_id(m, task);
6212         task_context_switch_counts(m, task);
6213         return 0;
6214  }
6215 @@ -471,6 +514,17 @@ static int do_task_stat(struct seq_file
6216         /* convert nsec -> ticks */
6217         start_time = nsec_to_clock_t(start_time);
6218  
6219 +       /* fixup start time for virt uptime */
6220 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6221 +               unsigned long long bias =
6222 +                       current->vx_info->cvirt.bias_clock;
6223 +
6224 +               if (start_time > bias)
6225 +                       start_time -= bias;
6226 +               else
6227 +                       start_time = 0;
6228 +       }
6229 +
6230         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6231         seq_put_decimal_ll(m, ' ', ppid);
6232         seq_put_decimal_ll(m, ' ', pgid);
6233 diff -NurpP --minimal linux-3.7.1/fs/proc/base.c linux-3.7.1-vs2.3.5.5/fs/proc/base.c
6234 --- linux-3.7.1/fs/proc/base.c  2012-12-11 03:30:57.000000000 +0000
6235 +++ linux-3.7.1-vs2.3.5.5/fs/proc/base.c        2012-12-18 15:13:16.000000000 +0000
6236 @@ -85,6 +85,8 @@
6237  #include <linux/fs_struct.h>
6238  #include <linux/slab.h>
6239  #include <linux/flex_array.h>
6240 +#include <linux/vs_context.h>
6241 +#include <linux/vs_network.h>
6242  #ifdef CONFIG_HARDWALL
6243  #include <asm/hardwall.h>
6244  #endif
6245 @@ -950,11 +952,15 @@ static ssize_t oom_adj_write(struct file
6246                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6247  
6248         if (oom_adj < task->signal->oom_score_adj &&
6249 -           !capable(CAP_SYS_RESOURCE)) {
6250 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6251                 err = -EACCES;
6252                 goto err_sighand;
6253         }
6254  
6255 +       /* prevent guest processes from circumventing the oom killer */
6256 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6257 +               oom_adj = OOM_ADJUST_MIN;
6258 +
6259         /*
6260          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6261          * /proc/pid/oom_score_adj instead.
6262 @@ -1534,6 +1540,8 @@ struct inode *proc_pid_make_inode(struct
6263                 inode->i_gid = cred->egid;
6264                 rcu_read_unlock();
6265         }
6266 +       /* procfs is xid tagged */
6267 +       i_tag_write(inode, (tag_t)vx_task_xid(task));
6268         security_task_to_inode(task, inode);
6269  
6270  out:
6271 @@ -1579,6 +1587,8 @@ int pid_getattr(struct vfsmount *mnt, st
6272  
6273  /* dentry stuff */
6274  
6275 +static unsigned name_to_int(struct dentry *dentry);
6276 +
6277  /*
6278   *     Exceptional case: normally we are not allowed to unhash a busy
6279   * directory. In this case, however, we can do it - no aliasing problems
6280 @@ -1607,6 +1617,12 @@ int pid_revalidate(struct dentry *dentry
6281         task = get_proc_task(inode);
6282  
6283         if (task) {
6284 +               unsigned pid = name_to_int(dentry);
6285 +
6286 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6287 +                       put_task_struct(task);
6288 +                       goto drop;
6289 +               }
6290                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6291                     task_dumpable(task)) {
6292                         rcu_read_lock();
6293 @@ -1623,6 +1639,7 @@ int pid_revalidate(struct dentry *dentry
6294                 put_task_struct(task);
6295                 return 1;
6296         }
6297 +drop:
6298         d_drop(dentry);
6299         return 0;
6300  }
6301 @@ -2065,6 +2082,13 @@ static struct dentry *proc_pident_lookup
6302         if (!task)
6303                 goto out_no_task;
6304  
6305 +       /* TODO: maybe we can come up with a generic approach? */
6306 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6307 +               (dentry->d_name.len == 5) &&
6308 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6309 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6310 +               goto out;
6311 +
6312         /*
6313          * Yes, it does not scale. And it should not. Don't add
6314          * new entries into /proc/<tgid>/ without very good reasons.
6315 @@ -2451,7 +2475,7 @@ out_iput:
6316  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6317  {
6318         struct dentry *error;
6319 -       struct task_struct *task = get_proc_task(dir);
6320 +       struct task_struct *task = get_proc_task_real(dir);
6321         const struct pid_entry *p, *last;
6322  
6323         error = ERR_PTR(-ENOENT);
6324 @@ -2639,6 +2663,9 @@ static int proc_pid_personality(struct s
6325  static const struct file_operations proc_task_operations;
6326  static const struct inode_operations proc_task_inode_operations;
6327  
6328 +extern int proc_pid_vx_info(struct task_struct *, char *);
6329 +extern int proc_pid_nx_info(struct task_struct *, char *);
6330 +
6331  static const struct pid_entry tgid_base_stuff[] = {
6332         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6333         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6334 @@ -2705,6 +2732,8 @@ static const struct pid_entry tgid_base_
6335  #ifdef CONFIG_CGROUPS
6336         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6337  #endif
6338 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6339 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6340         INF("oom_score",  S_IRUGO, proc_oom_score),
6341         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6342         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6343 @@ -2729,6 +2758,7 @@ static const struct pid_entry tgid_base_
6344         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6345         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6346  #endif
6347 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6348  };
6349  
6350  static int proc_tgid_base_readdir(struct file * filp,
6351 @@ -2923,7 +2953,7 @@ retry:
6352         iter.task = NULL;
6353         pid = find_ge_pid(iter.tgid, ns);
6354         if (pid) {
6355 -               iter.tgid = pid_nr_ns(pid, ns);
6356 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6357                 iter.task = pid_task(pid, PIDTYPE_PID);
6358                 /* What we to know is if the pid we have find is the
6359                  * pid of a thread_group_leader.  Testing for task
6360 @@ -2953,7 +2983,7 @@ static int proc_pid_fill_cache(struct fi
6361         struct tgid_iter iter)
6362  {
6363         char name[PROC_NUMBUF];
6364 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6365 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6366         return proc_fill_cache(filp, dirent, filldir, name, len,
6367                                 proc_pid_instantiate, iter.task, NULL);
6368  }
6369 @@ -2977,7 +3007,7 @@ int proc_pid_readdir(struct file * filp,
6370                 goto out_no_task;
6371         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6372  
6373 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6374 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6375         if (!reaper)
6376                 goto out_no_task;
6377  
6378 @@ -2999,6 +3029,8 @@ int proc_pid_readdir(struct file * filp,
6379                         __filldir = fake_filldir;
6380  
6381                 filp->f_pos = iter.tgid + TGID_OFFSET;
6382 +               if (!vx_proc_task_visible(iter.task))
6383 +                       continue;
6384                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6385                         put_task_struct(iter.task);
6386                         goto out;
6387 @@ -3161,6 +3193,8 @@ static struct dentry *proc_task_lookup(s
6388         tid = name_to_int(dentry);
6389         if (tid == ~0U)
6390                 goto out;
6391 +       if (vx_current_initpid(tid))
6392 +               goto out;
6393  
6394         ns = dentry->d_sb->s_fs_info;
6395         rcu_read_lock();
6396 diff -NurpP --minimal linux-3.7.1/fs/proc/generic.c linux-3.7.1-vs2.3.5.5/fs/proc/generic.c
6397 --- linux-3.7.1/fs/proc/generic.c       2012-12-11 03:30:57.000000000 +0000
6398 +++ linux-3.7.1-vs2.3.5.5/fs/proc/generic.c     2012-12-18 15:13:16.000000000 +0000
6399 @@ -22,6 +22,7 @@
6400  #include <linux/bitops.h>
6401  #include <linux/spinlock.h>
6402  #include <linux/completion.h>
6403 +#include <linux/vserver/inode.h>
6404  #include <asm/uaccess.h>
6405  
6406  #include "internal.h"
6407 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6408         for (de = de->subdir; de ; de = de->next) {
6409                 if (de->namelen != dentry->d_name.len)
6410                         continue;
6411 +               if (!vx_hide_check(0, de->vx_flags))
6412 +                       continue;
6413                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6414                         pde_get(de);
6415                         spin_unlock(&proc_subdir_lock);
6416                         error = -ENOMEM;
6417                         inode = proc_get_inode(dir->i_sb, de);
6418 +                       /* generic proc entries belong to the host */
6419 +                       i_tag_write(inode, 0);
6420                         goto out_unlock;
6421                 }
6422         }
6423 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6424  
6425                                 /* filldir passes info to user space */
6426                                 pde_get(de);
6427 +                               if (!vx_hide_check(0, de->vx_flags))
6428 +                                       goto skip;
6429                                 spin_unlock(&proc_subdir_lock);
6430                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6431                                             de->low_ino, de->mode >> 12) < 0) {
6432 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6433                                         goto out;
6434                                 }
6435                                 spin_lock(&proc_subdir_lock);
6436 +                       skip:
6437                                 filp->f_pos++;
6438                                 next = de->next;
6439                                 pde_put(de);
6440 @@ -625,6 +633,7 @@ static struct proc_dir_entry *__proc_cre
6441         ent->namelen = len;
6442         ent->mode = mode;
6443         ent->nlink = nlink;
6444 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6445         atomic_set(&ent->count, 1);
6446         spin_lock_init(&ent->pde_unload_lock);
6447         INIT_LIST_HEAD(&ent->pde_openers);
6448 @@ -648,7 +657,8 @@ struct proc_dir_entry *proc_symlink(cons
6449                                 kfree(ent->data);
6450                                 kfree(ent);
6451                                 ent = NULL;
6452 -                       }
6453 +                       } else
6454 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6455                 } else {
6456                         kfree(ent);
6457                         ent = NULL;
6458 diff -NurpP --minimal linux-3.7.1/fs/proc/inode.c linux-3.7.1-vs2.3.5.5/fs/proc/inode.c
6459 --- linux-3.7.1/fs/proc/inode.c 2012-12-11 03:30:57.000000000 +0000
6460 +++ linux-3.7.1-vs2.3.5.5/fs/proc/inode.c       2012-12-18 15:13:16.000000000 +0000
6461 @@ -457,6 +457,8 @@ struct inode *proc_get_inode(struct supe
6462                         inode->i_uid = de->uid;
6463                         inode->i_gid = de->gid;
6464                 }
6465 +               if (de->vx_flags)
6466 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6467                 if (de->size)
6468                         inode->i_size = de->size;
6469                 if (de->nlink)
6470 diff -NurpP --minimal linux-3.7.1/fs/proc/internal.h linux-3.7.1-vs2.3.5.5/fs/proc/internal.h
6471 --- linux-3.7.1/fs/proc/internal.h      2012-12-11 03:30:57.000000000 +0000
6472 +++ linux-3.7.1-vs2.3.5.5/fs/proc/internal.h    2012-12-18 15:13:16.000000000 +0000
6473 @@ -11,6 +11,8 @@
6474  
6475  #include <linux/sched.h>
6476  #include <linux/proc_fs.h>
6477 +#include <linux/vs_pid.h>
6478 +
6479  struct  ctl_table_header;
6480  struct  mempolicy;
6481  
6482 @@ -54,6 +56,9 @@ extern int proc_pid_status(struct seq_fi
6483                                 struct pid *pid, struct task_struct *task);
6484  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6485                                 struct pid *pid, struct task_struct *task);
6486 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6487 +                               struct pid *pid, struct task_struct *task);
6488 +
6489  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6490  
6491  extern const struct file_operations proc_tid_children_operations;
6492 @@ -87,11 +92,16 @@ static inline struct pid *proc_pid(struc
6493         return PROC_I(inode)->pid;
6494  }
6495  
6496 -static inline struct task_struct *get_proc_task(struct inode *inode)
6497 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6498  {
6499         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6500  }
6501  
6502 +static inline struct task_struct *get_proc_task(struct inode *inode)
6503 +{
6504 +       return vx_get_proc_task(inode, proc_pid(inode));
6505 +}
6506 +
6507  static inline int proc_fd(struct inode *inode)
6508  {
6509         return PROC_I(inode)->fd;
6510 diff -NurpP --minimal linux-3.7.1/fs/proc/loadavg.c linux-3.7.1-vs2.3.5.5/fs/proc/loadavg.c
6511 --- linux-3.7.1/fs/proc/loadavg.c       2012-12-11 03:30:57.000000000 +0000
6512 +++ linux-3.7.1-vs2.3.5.5/fs/proc/loadavg.c     2012-12-18 15:13:16.000000000 +0000
6513 @@ -12,15 +12,27 @@
6514  
6515  static int loadavg_proc_show(struct seq_file *m, void *v)
6516  {
6517 +       unsigned long running;
6518 +       unsigned int threads;
6519         unsigned long avnrun[3];
6520  
6521         get_avenrun(avnrun, FIXED_1/200, 0);
6522  
6523 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6524 +               struct vx_info *vxi = current_vx_info();
6525 +
6526 +               running = atomic_read(&vxi->cvirt.nr_running);
6527 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6528 +       } else {
6529 +               running = nr_running();
6530 +               threads = nr_threads;
6531 +       }
6532 +
6533         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6534                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6535                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6536                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6537 -               nr_running(), nr_threads,
6538 +               running, threads,
6539                 task_active_pid_ns(current)->last_pid);
6540         return 0;
6541  }
6542 diff -NurpP --minimal linux-3.7.1/fs/proc/meminfo.c linux-3.7.1-vs2.3.5.5/fs/proc/meminfo.c
6543 --- linux-3.7.1/fs/proc/meminfo.c       2012-12-11 03:30:57.000000000 +0000
6544 +++ linux-3.7.1-vs2.3.5.5/fs/proc/meminfo.c     2012-12-18 15:13:16.000000000 +0000
6545 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6546         allowed = ((totalram_pages - hugetlb_total_pages())
6547                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6548  
6549 -       cached = global_page_state(NR_FILE_PAGES) -
6550 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6551 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6552                         total_swapcache_pages - i.bufferram;
6553         if (cached < 0)
6554                 cached = 0;
6555 diff -NurpP --minimal linux-3.7.1/fs/proc/root.c linux-3.7.1-vs2.3.5.5/fs/proc/root.c
6556 --- linux-3.7.1/fs/proc/root.c  2012-12-11 03:30:57.000000000 +0000
6557 +++ linux-3.7.1-vs2.3.5.5/fs/proc/root.c        2012-12-18 15:13:16.000000000 +0000
6558 @@ -19,9 +19,14 @@
6559  #include <linux/mount.h>
6560  #include <linux/pid_namespace.h>
6561  #include <linux/parser.h>
6562 +#include <linux/vserver/inode.h>
6563  
6564  #include "internal.h"
6565  
6566 +struct proc_dir_entry *proc_virtual;
6567 +
6568 +extern void proc_vx_init(void);
6569 +
6570  static int proc_test_super(struct super_block *sb, void *data)
6571  {
6572         return sb->s_fs_info == data;
6573 @@ -189,6 +194,7 @@ void __init proc_root_init(void)
6574  #endif
6575         proc_mkdir("bus", NULL);
6576         proc_sys_init();
6577 +       proc_vx_init();
6578  }
6579  
6580  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6581 @@ -255,6 +261,7 @@ struct proc_dir_entry proc_root = {
6582         .proc_iops      = &proc_root_inode_operations, 
6583         .proc_fops      = &proc_root_operations,
6584         .parent         = &proc_root,
6585 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6586         .name           = "/proc",
6587  };
6588  
6589 diff -NurpP --minimal linux-3.7.1/fs/proc/stat.c linux-3.7.1-vs2.3.5.5/fs/proc/stat.c
6590 --- linux-3.7.1/fs/proc/stat.c  2012-12-11 03:30:57.000000000 +0000
6591 +++ linux-3.7.1-vs2.3.5.5/fs/proc/stat.c        2012-12-18 15:13:16.000000000 +0000
6592 @@ -9,8 +9,10 @@
6593  #include <linux/slab.h>
6594  #include <linux/time.h>
6595  #include <linux/irqnr.h>
6596 +#include <linux/vserver/cvirt.h>
6597  #include <asm/cputime.h>
6598  #include <linux/tick.h>
6599 +#include <linux/cpuset.h>
6600  
6601  #ifndef arch_irq_stat_cpu
6602  #define arch_irq_stat_cpu(cpu) 0
6603 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6604         u64 sum_softirq = 0;
6605         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6606         struct timespec boottime;
6607 +       cpumask_var_t cpus_allowed;
6608 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6609  
6610         user = nice = system = idle = iowait =
6611                 irq = softirq = steal = 0;
6612         guest = guest_nice = 0;
6613         getboottime(&boottime);
6614 +
6615 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6616 +               vx_vsi_boottime(&boottime);
6617 +
6618 +       if (virt_cpu)
6619 +               cpuset_cpus_allowed(current, cpus_allowed);
6620 +
6621         jif = boottime.tv_sec;
6622  
6623         for_each_possible_cpu(i) {
6624 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6625 +                       continue;
6626 +
6627                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6628                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6629                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6630 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6631         seq_putc(p, '\n');
6632  
6633         for_each_online_cpu(i) {
6634 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6635 +                       continue;
6636 +
6637                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6638                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6639                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6640 diff -NurpP --minimal linux-3.7.1/fs/proc/uptime.c linux-3.7.1-vs2.3.5.5/fs/proc/uptime.c
6641 --- linux-3.7.1/fs/proc/uptime.c        2012-12-11 03:30:57.000000000 +0000
6642 +++ linux-3.7.1-vs2.3.5.5/fs/proc/uptime.c      2012-12-18 15:13:16.000000000 +0000
6643 @@ -5,6 +5,7 @@
6644  #include <linux/seq_file.h>
6645  #include <linux/time.h>
6646  #include <linux/kernel_stat.h>
6647 +#include <linux/vserver/cvirt.h>
6648  #include <asm/cputime.h>
6649  
6650  static int uptime_proc_show(struct seq_file *m, void *v)
6651 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6652         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6653         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6654         idle.tv_nsec = rem;
6655 +
6656 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6657 +               vx_vsi_uptime(&uptime, &idle);
6658 +
6659         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6660                         (unsigned long) uptime.tv_sec,
6661                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6662 diff -NurpP --minimal linux-3.7.1/fs/proc_namespace.c linux-3.7.1-vs2.3.5.5/fs/proc_namespace.c
6663 --- linux-3.7.1/fs/proc_namespace.c     2012-12-11 03:30:57.000000000 +0000
6664 +++ linux-3.7.1-vs2.3.5.5/fs/proc_namespace.c   2012-12-18 15:13:16.000000000 +0000
6665 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6666                 { MS_SYNCHRONOUS, ",sync" },
6667                 { MS_DIRSYNC, ",dirsync" },
6668                 { MS_MANDLOCK, ",mand" },
6669 +               { MS_TAGGED, ",tag" },
6670 +               { MS_NOTAGCHECK, ",notagcheck" },
6671                 { 0, NULL }
6672         };
6673         const struct proc_fs_info *fs_infop;
6674 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6675         seq_escape(m, s, " \t\n\\");
6676  }
6677  
6678 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6679 +
6680 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6681 +{
6682 +       struct path root;
6683 +       struct dentry *point;
6684 +       struct mount *mnt = real_mount(vfsmnt);
6685 +       struct mount *root_mnt;
6686 +       int ret;
6687 +
6688 +       if (mnt == mnt->mnt_ns->root)
6689 +               return 1;
6690 +
6691 +       br_read_lock(&vfsmount_lock);
6692 +       root = current->fs->root;
6693 +       root_mnt = real_mount(root.mnt);
6694 +       point = root.dentry;
6695 +
6696 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6697 +               point = mnt->mnt_mountpoint;
6698 +               mnt = mnt->mnt_parent;
6699 +       }
6700 +
6701 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6702 +
6703 +       br_read_unlock(&vfsmount_lock);
6704 +
6705 +       return ret;
6706 +}
6707 +
6708 +#else
6709 +#define        mnt_is_reachable(v)     (1)
6710 +#endif
6711 +
6712  static void show_type(struct seq_file *m, struct super_block *sb)
6713  {
6714         mangle(m, sb->s_type->name);
6715 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6716         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6717         struct super_block *sb = mnt_path.dentry->d_sb;
6718  
6719 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6720 +               return SEQ_SKIP;
6721 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6722 +               return SEQ_SKIP;
6723 +
6724 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6725 +               mnt == current->fs->root.mnt) {
6726 +               seq_puts(m, "/dev/root / ");
6727 +               goto type;
6728 +       }
6729 +
6730         if (sb->s_op->show_devname) {
6731                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6732                 if (err)
6733 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6734         seq_putc(m, ' ');
6735         seq_path(m, &mnt_path, " \t\n\\");
6736         seq_putc(m, ' ');
6737 +type:
6738         show_type(m, sb);
6739         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6740         err = show_sb_opts(m, sb);
6741 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6742         struct path root = p->root;
6743         int err = 0;
6744  
6745 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6746 +               return SEQ_SKIP;
6747 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6748 +               return SEQ_SKIP;
6749 +
6750         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6751                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6752         if (sb->s_op->show_path)
6753 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6754         struct super_block *sb = mnt_path.dentry->d_sb;
6755         int err = 0;
6756  
6757 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6758 +               return SEQ_SKIP;
6759 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6760 +               return SEQ_SKIP;
6761 +
6762 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6763 +               mnt == current->fs->root.mnt) {
6764 +               seq_puts(m, "device /dev/root mounted on / ");
6765 +               goto type;
6766 +       }
6767 +
6768         /* device */
6769         if (sb->s_op->show_devname) {
6770                 seq_puts(m, "device ");
6771 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6772         seq_puts(m, " mounted on ");
6773         seq_path(m, &mnt_path, " \t\n\\");
6774         seq_putc(m, ' ');
6775 -
6776 +type:
6777         /* file system type */
6778         seq_puts(m, "with fstype ");
6779         show_type(m, sb);
6780 diff -NurpP --minimal linux-3.7.1/fs/quota/dquot.c linux-3.7.1-vs2.3.5.5/fs/quota/dquot.c
6781 --- linux-3.7.1/fs/quota/dquot.c        2012-12-11 03:30:57.000000000 +0000
6782 +++ linux-3.7.1-vs2.3.5.5/fs/quota/dquot.c      2012-12-18 15:13:16.000000000 +0000
6783 @@ -1582,6 +1582,9 @@ int __dquot_alloc_space(struct inode *in
6784         struct dquot **dquots = inode->i_dquot;
6785         int reserve = flags & DQUOT_SPACE_RESERVE;
6786  
6787 +       if ((ret = dl_alloc_space(inode, number)))
6788 +               return ret;
6789 +
6790         /*
6791          * First test before acquiring mutex - solves deadlocks when we
6792          * re-enter the quota code and are already holding the mutex
6793 @@ -1637,6 +1640,9 @@ int dquot_alloc_inode(const struct inode
6794         struct dquot_warn warn[MAXQUOTAS];
6795         struct dquot * const *dquots = inode->i_dquot;
6796  
6797 +       if ((ret = dl_alloc_inode(inode)))
6798 +               return ret;
6799 +
6800         /* First test before acquiring mutex - solves deadlocks when we
6801           * re-enter the quota code and are already holding the mutex */
6802         if (!dquot_active(inode))
6803 @@ -1708,6 +1714,8 @@ void __dquot_free_space(struct inode *in
6804         struct dquot **dquots = inode->i_dquot;
6805         int reserve = flags & DQUOT_SPACE_RESERVE;
6806  
6807 +       dl_free_space(inode, number);
6808 +
6809         /* First test before acquiring mutex - solves deadlocks when we
6810           * re-enter the quota code and are already holding the mutex */
6811         if (!dquot_active(inode)) {
6812 @@ -1752,6 +1760,8 @@ void dquot_free_inode(const struct inode
6813         struct dquot_warn warn[MAXQUOTAS];
6814         struct dquot * const *dquots = inode->i_dquot;
6815  
6816 +       dl_free_inode(inode);
6817 +
6818         /* First test before acquiring mutex - solves deadlocks when we
6819           * re-enter the quota code and are already holding the mutex */
6820         if (!dquot_active(inode))
6821 diff -NurpP --minimal linux-3.7.1/fs/quota/quota.c linux-3.7.1-vs2.3.5.5/fs/quota/quota.c
6822 --- linux-3.7.1/fs/quota/quota.c        2012-12-11 03:30:57.000000000 +0000
6823 +++ linux-3.7.1-vs2.3.5.5/fs/quota/quota.c      2012-12-18 15:13:16.000000000 +0000
6824 @@ -8,6 +8,7 @@
6825  #include <linux/fs.h>
6826  #include <linux/namei.h>
6827  #include <linux/slab.h>
6828 +#include <linux/vs_context.h>
6829  #include <asm/current.h>
6830  #include <linux/uaccess.h>
6831  #include <linux/kernel.h>
6832 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6833                         break;
6834                 /*FALLTHROUGH*/
6835         default:
6836 -               if (!capable(CAP_SYS_ADMIN))
6837 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6838                         return -EPERM;
6839         }
6840  
6841 @@ -307,6 +308,46 @@ static int do_quotactl(struct super_bloc
6842         }
6843  }
6844  
6845 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6846 +
6847 +#include <linux/vroot.h>
6848 +#include <linux/major.h>
6849 +#include <linux/module.h>
6850 +#include <linux/kallsyms.h>
6851 +#include <linux/vserver/debug.h>
6852 +
6853 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6854 +
6855 +static DEFINE_SPINLOCK(vroot_grb_lock);
6856 +
6857 +int register_vroot_grb(vroot_grb_func *func) {
6858 +       int ret = -EBUSY;
6859 +
6860 +       spin_lock(&vroot_grb_lock);
6861 +       if (!vroot_get_real_bdev) {
6862 +               vroot_get_real_bdev = func;
6863 +               ret = 0;
6864 +       }
6865 +       spin_unlock(&vroot_grb_lock);
6866 +       return ret;
6867 +}
6868 +EXPORT_SYMBOL(register_vroot_grb);
6869 +
6870 +int unregister_vroot_grb(vroot_grb_func *func) {
6871 +       int ret = -EINVAL;
6872 +
6873 +       spin_lock(&vroot_grb_lock);
6874 +       if (vroot_get_real_bdev) {
6875 +               vroot_get_real_bdev = NULL;
6876 +               ret = 0;
6877 +       }
6878 +       spin_unlock(&vroot_grb_lock);
6879 +       return ret;
6880 +}
6881 +EXPORT_SYMBOL(unregister_vroot_grb);
6882 +
6883 +#endif
6884 +
6885  /* Return 1 if 'cmd' will block on frozen filesystem */
6886  static int quotactl_cmd_write(int cmd)
6887  {
6888 @@ -339,6 +380,22 @@ static struct super_block *quotactl_bloc
6889         putname(tmp);
6890         if (IS_ERR(bdev))
6891                 return ERR_CAST(bdev);
6892 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6893 +       if (bdev && bdev->bd_inode &&
6894 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6895 +               struct block_device *bdnew = (void *)-EINVAL;
6896 +
6897 +               if (vroot_get_real_bdev)
6898 +                       bdnew = vroot_get_real_bdev(bdev);
6899 +               else
6900 +                       vxdprintk(VXD_CBIT(misc, 0),
6901 +                                       "vroot_get_real_bdev not set");
6902 +               bdput(bdev);
6903 +               if (IS_ERR(bdnew))
6904 +                       return ERR_PTR(PTR_ERR(bdnew));
6905 +               bdev = bdnew;
6906 +       }
6907 +#endif
6908         if (quotactl_cmd_write(cmd))
6909                 sb = get_super_thawed(bdev);
6910         else
6911 diff -NurpP --minimal linux-3.7.1/fs/stat.c linux-3.7.1-vs2.3.5.5/fs/stat.c
6912 --- linux-3.7.1/fs/stat.c       2012-12-11 03:30:57.000000000 +0000
6913 +++ linux-3.7.1-vs2.3.5.5/fs/stat.c     2012-12-18 15:13:16.000000000 +0000
6914 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6915         stat->nlink = inode->i_nlink;
6916         stat->uid = inode->i_uid;
6917         stat->gid = inode->i_gid;
6918 +       stat->tag = inode->i_tag;
6919         stat->rdev = inode->i_rdev;
6920         stat->size = i_size_read(inode);
6921         stat->atime = inode->i_atime;
6922 diff -NurpP --minimal linux-3.7.1/fs/statfs.c linux-3.7.1-vs2.3.5.5/fs/statfs.c
6923 --- linux-3.7.1/fs/statfs.c     2012-12-11 03:30:57.000000000 +0000
6924 +++ linux-3.7.1-vs2.3.5.5/fs/statfs.c   2012-12-18 15:13:16.000000000 +0000
6925 @@ -7,6 +7,8 @@
6926  #include <linux/statfs.h>
6927  #include <linux/security.h>
6928  #include <linux/uaccess.h>
6929 +#include <linux/vs_base.h>
6930 +#include <linux/vs_dlimit.h>
6931  #include "internal.h"
6932  
6933  static int flags_by_mnt(int mnt_flags)
6934 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6935         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6936         if (retval == 0 && buf->f_frsize == 0)
6937                 buf->f_frsize = buf->f_bsize;
6938 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6939 +               vx_vsi_statfs(dentry->d_sb, buf);
6940         return retval;
6941  }
6942  
6943 diff -NurpP --minimal linux-3.7.1/fs/super.c linux-3.7.1-vs2.3.5.5/fs/super.c
6944 --- linux-3.7.1/fs/super.c      2012-12-11 03:30:57.000000000 +0000
6945 +++ linux-3.7.1-vs2.3.5.5/fs/super.c    2012-12-18 15:13:16.000000000 +0000
6946 @@ -34,6 +34,8 @@
6947  #include <linux/cleancache.h>
6948  #include <linux/fsnotify.h>
6949  #include <linux/lockdep.h>
6950 +#include <linux/magic.h>
6951 +#include <linux/vs_context.h>
6952  #include "internal.h"
6953  
6954  
6955 @@ -1119,6 +1121,13 @@ mount_fs(struct file_system_type *type,
6956         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6957         sb->s_flags |= MS_BORN;
6958  
6959 +       error = -EPERM;
6960 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6961 +               !sb->s_bdev &&
6962 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6963 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6964 +               goto out_sb;
6965 +
6966         error = security_sb_kern_mount(sb, flags, secdata);
6967         if (error)
6968                 goto out_sb;
6969 diff -NurpP --minimal linux-3.7.1/fs/sysfs/mount.c linux-3.7.1-vs2.3.5.5/fs/sysfs/mount.c
6970 --- linux-3.7.1/fs/sysfs/mount.c        2012-12-11 03:30:57.000000000 +0000
6971 +++ linux-3.7.1-vs2.3.5.5/fs/sysfs/mount.c      2012-12-18 15:13:16.000000000 +0000
6972 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
6973  
6974         sb->s_blocksize = PAGE_CACHE_SIZE;
6975         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6976 -       sb->s_magic = SYSFS_MAGIC;
6977 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6978         sb->s_op = &sysfs_ops;
6979         sb->s_time_gran = 1;
6980  
6981 diff -NurpP --minimal linux-3.7.1/fs/utimes.c linux-3.7.1-vs2.3.5.5/fs/utimes.c
6982 --- linux-3.7.1/fs/utimes.c     2012-12-11 03:30:57.000000000 +0000
6983 +++ linux-3.7.1-vs2.3.5.5/fs/utimes.c   2012-12-18 15:13:16.000000000 +0000
6984 @@ -8,6 +8,8 @@
6985  #include <linux/stat.h>
6986  #include <linux/utime.h>
6987  #include <linux/syscalls.h>
6988 +#include <linux/mount.h>
6989 +#include <linux/vs_cowbl.h>
6990  #include <asm/uaccess.h>
6991  #include <asm/unistd.h>
6992  
6993 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6994  {
6995         int error;
6996         struct iattr newattrs;
6997 -       struct inode *inode = path->dentry->d_inode;
6998 +       struct inode *inode;
6999  
7000         error = mnt_want_write(path->mnt);
7001         if (error)
7002                 goto out;
7003  
7004 +       error = cow_check_and_break(path);
7005 +       if (error)
7006 +               goto mnt_drop_write_and_out;
7007 +
7008 +       inode = path->dentry->d_inode;
7009 +
7010         if (times && times[0].tv_nsec == UTIME_NOW &&
7011                      times[1].tv_nsec == UTIME_NOW)
7012                 times = NULL;
7013 diff -NurpP --minimal linux-3.7.1/fs/xattr.c linux-3.7.1-vs2.3.5.5/fs/xattr.c
7014 --- linux-3.7.1/fs/xattr.c      2012-12-11 03:30:57.000000000 +0000
7015 +++ linux-3.7.1-vs2.3.5.5/fs/xattr.c    2012-12-18 15:13:16.000000000 +0000
7016 @@ -21,6 +21,7 @@
7017  #include <linux/audit.h>
7018  #include <linux/vmalloc.h>
7019  #include <linux/posix_acl_xattr.h>
7020 +#include <linux/mount.h>
7021  
7022  #include <asm/uaccess.h>
7023  
7024 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
7025          * The trusted.* namespace can only be accessed by privileged users.
7026          */
7027         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7028 -               if (!capable(CAP_SYS_ADMIN))
7029 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7030                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7031                 return 0;
7032         }
7033 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_dinode.h linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_dinode.h
7034 --- linux-3.7.1/fs/xfs/xfs_dinode.h     2012-12-11 03:30:57.000000000 +0000
7035 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_dinode.h   2012-12-18 15:13:16.000000000 +0000
7036 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7037         __be32          di_nlink;       /* number of links to file */
7038         __be16          di_projid_lo;   /* lower part of owner's project id */
7039         __be16          di_projid_hi;   /* higher part owner's project id */
7040 -       __u8            di_pad[6];      /* unused, zeroed space */
7041 +       __u8            di_pad[2];      /* unused, zeroed space */
7042 +       __be16          di_tag;         /* context tagging */
7043 +       __be16          di_vflags;      /* vserver specific flags */
7044         __be16          di_flushiter;   /* incremented on flush */
7045         xfs_timestamp_t di_atime;       /* time last accessed */
7046         xfs_timestamp_t di_mtime;       /* time last modified */
7047 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7048  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7049  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7050  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7051 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7052 +
7053  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7054  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7055  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7056 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7057  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7058  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7059  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7060 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7061  
7062  #ifdef CONFIG_XFS_RT
7063  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7064 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7065          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7066          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7067          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7068 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7069 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7070 +        XFS_DIFLAG_IXUNLINK)
7071 +
7072 +#define XFS_DIVFLAG_BARRIER    0x01
7073 +#define XFS_DIVFLAG_COW                0x02
7074  
7075  #endif /* __XFS_DINODE_H__ */
7076 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_fs.h linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_fs.h
7077 --- linux-3.7.1/fs/xfs/xfs_fs.h 2012-12-11 03:30:57.000000000 +0000
7078 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_fs.h       2012-12-18 15:13:16.000000000 +0000
7079 @@ -67,6 +67,9 @@ struct fsxattr {
7080  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7081  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7082  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7083 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7084 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7085 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7086  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7087  
7088  /*
7089 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7090  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7091         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7092         __u16           bs_projid_hi;   /* higher part of project id    */
7093 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7094 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7095 +       __u16           bs_tag;         /* context tagging              */
7096         __u32           bs_dmevmask;    /* DMIG event mask              */
7097         __u16           bs_dmstate;     /* DMIG state info              */
7098         __u16           bs_aextents;    /* attribute number of extents  */
7099 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_ialloc.c linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_ialloc.c
7100 --- linux-3.7.1/fs/xfs/xfs_ialloc.c     2012-12-11 03:30:57.000000000 +0000
7101 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_ialloc.c   2012-12-18 15:13:16.000000000 +0000
7102 @@ -37,7 +37,6 @@
7103  #include "xfs_error.h"
7104  #include "xfs_bmap.h"
7105  
7106 -
7107  /*
7108   * Allocation group level functions.
7109   */
7110 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_inode.c linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_inode.c
7111 --- linux-3.7.1/fs/xfs/xfs_inode.c      2012-12-11 03:30:57.000000000 +0000
7112 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_inode.c    2012-12-18 15:13:16.000000000 +0000
7113 @@ -16,6 +16,7 @@
7114   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
7115   */
7116  #include <linux/log2.h>
7117 +#include <linux/vs_tag.h>
7118  
7119  #include "xfs.h"
7120  #include "xfs_fs.h"
7121 @@ -563,15 +564,25 @@ xfs_iformat_btree(
7122  STATIC void
7123  xfs_dinode_from_disk(
7124         xfs_icdinode_t          *to,
7125 -       xfs_dinode_t            *from)
7126 +       xfs_dinode_t            *from,
7127 +       int                     tagged)
7128  {
7129 +       uint32_t uid, gid, tag;
7130 +
7131         to->di_magic = be16_to_cpu(from->di_magic);
7132         to->di_mode = be16_to_cpu(from->di_mode);
7133         to->di_version = from ->di_version;
7134         to->di_format = from->di_format;
7135         to->di_onlink = be16_to_cpu(from->di_onlink);
7136 -       to->di_uid = be32_to_cpu(from->di_uid);
7137 -       to->di_gid = be32_to_cpu(from->di_gid);
7138 +
7139 +       uid = be32_to_cpu(from->di_uid);
7140 +       gid = be32_to_cpu(from->di_gid);
7141 +       tag = be16_to_cpu(from->di_tag);
7142 +
7143 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7144 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7145 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7146 +
7147         to->di_nlink = be32_to_cpu(from->di_nlink);
7148         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7149         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7150 @@ -593,21 +604,26 @@ xfs_dinode_from_disk(
7151         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7152         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7153         to->di_flags    = be16_to_cpu(from->di_flags);
7154 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7155         to->di_gen      = be32_to_cpu(from->di_gen);
7156  }
7157  
7158  void
7159  xfs_dinode_to_disk(
7160         xfs_dinode_t            *to,
7161 -       xfs_icdinode_t          *from)
7162 +       xfs_icdinode_t          *from,
7163 +       int                     tagged)
7164  {
7165         to->di_magic = cpu_to_be16(from->di_magic);
7166         to->di_mode = cpu_to_be16(from->di_mode);
7167         to->di_version = from ->di_version;
7168         to->di_format = from->di_format;
7169         to->di_onlink = cpu_to_be16(from->di_onlink);
7170 -       to->di_uid = cpu_to_be32(from->di_uid);
7171 -       to->di_gid = cpu_to_be32(from->di_gid);
7172 +
7173 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7174 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7175 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7176 +
7177         to->di_nlink = cpu_to_be32(from->di_nlink);
7178         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7179         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7180 @@ -629,12 +645,14 @@ xfs_dinode_to_disk(
7181         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7182         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7183         to->di_flags = cpu_to_be16(from->di_flags);
7184 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7185         to->di_gen = cpu_to_be32(from->di_gen);
7186  }
7187  
7188  STATIC uint
7189  _xfs_dic2xflags(
7190 -       __uint16_t              di_flags)
7191 +       __uint16_t              di_flags,
7192 +       __uint16_t              di_vflags)
7193  {
7194         uint                    flags = 0;
7195  
7196 @@ -645,6 +663,8 @@ _xfs_dic2xflags(
7197                         flags |= XFS_XFLAG_PREALLOC;
7198                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7199                         flags |= XFS_XFLAG_IMMUTABLE;
7200 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7201 +                       flags |= XFS_XFLAG_IXUNLINK;
7202                 if (di_flags & XFS_DIFLAG_APPEND)
7203                         flags |= XFS_XFLAG_APPEND;
7204                 if (di_flags & XFS_DIFLAG_SYNC)
7205 @@ -669,6 +689,10 @@ _xfs_dic2xflags(
7206                         flags |= XFS_XFLAG_FILESTREAM;
7207         }
7208  
7209 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7210 +               flags |= FS_BARRIER_FL;
7211 +       if (di_vflags & XFS_DIVFLAG_COW)
7212 +               flags |= FS_COW_FL;
7213         return flags;
7214  }
7215  
7216 @@ -678,7 +702,7 @@ xfs_ip2xflags(
7217  {
7218         xfs_icdinode_t          *dic = &ip->i_d;
7219  
7220 -       return _xfs_dic2xflags(dic->di_flags) |
7221 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7222                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7223  }
7224  
7225 @@ -686,7 +710,8 @@ uint
7226  xfs_dic2xflags(
7227         xfs_dinode_t            *dip)
7228  {
7229 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7230 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7231 +                               be16_to_cpu(dip->di_vflags)) |
7232                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7233  }
7234  
7235 @@ -740,7 +765,8 @@ xfs_iread(
7236          * Otherwise, just get the truly permanent information.
7237          */
7238         if (dip->di_mode) {
7239 -               xfs_dinode_from_disk(&ip->i_d, dip);
7240 +               xfs_dinode_from_disk(&ip->i_d, dip,
7241 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7242                 error = xfs_iformat(ip, dip);
7243                 if (error)  {
7244  #ifdef DEBUG
7245 @@ -927,6 +953,7 @@ xfs_ialloc(
7246         ASSERT(ip->i_d.di_nlink == nlink);
7247         ip->i_d.di_uid = current_fsuid();
7248         ip->i_d.di_gid = current_fsgid();
7249 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7250         xfs_set_projid(ip, prid);
7251         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7252  
7253 @@ -986,6 +1013,7 @@ xfs_ialloc(
7254         ip->i_d.di_dmevmask = 0;
7255         ip->i_d.di_dmstate = 0;
7256         ip->i_d.di_flags = 0;
7257 +       ip->i_d.di_vflags = 0;
7258         flags = XFS_ILOG_CORE;
7259         switch (mode & S_IFMT) {
7260         case S_IFIFO:
7261 @@ -1668,6 +1696,7 @@ xfs_ifree(
7262         }
7263         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7264         ip->i_d.di_flags = 0;
7265 +       ip->i_d.di_vflags = 0;
7266         ip->i_d.di_dmevmask = 0;
7267         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7268         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7269 @@ -1834,7 +1863,6 @@ xfs_iroot_realloc(
7270         return;
7271  }
7272  
7273 -
7274  /*
7275   * This is called when the amount of space needed for if_data
7276   * is increased or decreased.  The change in size is indicated by
7277 @@ -2522,7 +2550,8 @@ xfs_iflush_int(
7278          * because if the inode is dirty at all the core must
7279          * be.
7280          */
7281 -       xfs_dinode_to_disk(dip, &ip->i_d);
7282 +       xfs_dinode_to_disk(dip, &ip->i_d,
7283 +               mp->m_flags & XFS_MOUNT_TAGGED);
7284  
7285         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7286         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7287 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_inode.h linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_inode.h
7288 --- linux-3.7.1/fs/xfs/xfs_inode.h      2012-12-11 03:30:57.000000000 +0000
7289 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_inode.h    2012-12-18 15:13:16.000000000 +0000
7290 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7291         __uint32_t      di_nlink;       /* number of links to file */
7292         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7293         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7294 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7295 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7296 +       __uint16_t      di_tag;         /* context tagging */
7297 +       __uint16_t      di_vflags;      /* vserver specific flags */
7298         __uint16_t      di_flushiter;   /* incremented on flush */
7299         xfs_ictimestamp_t di_atime;     /* time last accessed */
7300         xfs_ictimestamp_t di_mtime;     /* time last modified */
7301 @@ -561,7 +563,7 @@ int         xfs_imap_to_bp(struct xfs_mount *,
7302  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7303                           struct xfs_inode *, uint);
7304  void           xfs_dinode_to_disk(struct xfs_dinode *,
7305 -                                  struct xfs_icdinode *);
7306 +                                  struct xfs_icdinode *, int);
7307  void           xfs_idestroy_fork(struct xfs_inode *, int);
7308  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7309  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7310 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_ioctl.c linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_ioctl.c
7311 --- linux-3.7.1/fs/xfs/xfs_ioctl.c      2012-12-11 03:30:57.000000000 +0000
7312 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_ioctl.c    2012-12-18 15:13:16.000000000 +0000
7313 @@ -26,7 +26,7 @@
7314  #include "xfs_bmap_btree.h"
7315  #include "xfs_dinode.h"
7316  #include "xfs_inode.h"
7317 -#include "xfs_ioctl.h"
7318 +// #include "xfs_ioctl.h"
7319  #include "xfs_rtalloc.h"
7320  #include "xfs_itable.h"
7321  #include "xfs_error.h"
7322 @@ -762,6 +762,10 @@ xfs_merge_ioc_xflags(
7323                 xflags |= XFS_XFLAG_IMMUTABLE;
7324         else
7325                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7326 +       if (flags & FS_IXUNLINK_FL)
7327 +               xflags |= XFS_XFLAG_IXUNLINK;
7328 +       else
7329 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7330         if (flags & FS_APPEND_FL)
7331                 xflags |= XFS_XFLAG_APPEND;
7332         else
7333 @@ -790,6 +794,8 @@ xfs_di2lxflags(
7334  
7335         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7336                 flags |= FS_IMMUTABLE_FL;
7337 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7338 +               flags |= FS_IXUNLINK_FL;
7339         if (di_flags & XFS_DIFLAG_APPEND)
7340                 flags |= FS_APPEND_FL;
7341         if (di_flags & XFS_DIFLAG_SYNC)
7342 @@ -850,6 +856,8 @@ xfs_set_diflags(
7343         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7344         if (xflags & XFS_XFLAG_IMMUTABLE)
7345                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7346 +       if (xflags & XFS_XFLAG_IXUNLINK)
7347 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7348         if (xflags & XFS_XFLAG_APPEND)
7349                 di_flags |= XFS_DIFLAG_APPEND;
7350         if (xflags & XFS_XFLAG_SYNC)
7351 @@ -892,6 +900,10 @@ xfs_diflags_to_linux(
7352                 inode->i_flags |= S_IMMUTABLE;
7353         else
7354                 inode->i_flags &= ~S_IMMUTABLE;
7355 +       if (xflags & XFS_XFLAG_IXUNLINK)
7356 +               inode->i_flags |= S_IXUNLINK;
7357 +       else
7358 +               inode->i_flags &= ~S_IXUNLINK;
7359         if (xflags & XFS_XFLAG_APPEND)
7360                 inode->i_flags |= S_APPEND;
7361         else
7362 @@ -1396,10 +1408,18 @@ xfs_file_ioctl(
7363         case XFS_IOC_FSGETXATTRA:
7364                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7365         case XFS_IOC_FSSETXATTR:
7366 +               if (IS_BARRIER(inode)) {
7367 +                       vxwprintk_task(1, "messing with the barrier.");
7368 +                       return -XFS_ERROR(EACCES);
7369 +               }
7370                 return xfs_ioc_fssetxattr(ip, filp, arg);
7371         case XFS_IOC_GETXFLAGS:
7372                 return xfs_ioc_getxflags(ip, arg);
7373         case XFS_IOC_SETXFLAGS:
7374 +               if (IS_BARRIER(inode)) {
7375 +                       vxwprintk_task(1, "messing with the barrier.");
7376 +                       return -XFS_ERROR(EACCES);
7377 +               }
7378                 return xfs_ioc_setxflags(ip, filp, arg);
7379  
7380         case XFS_IOC_FSSETDM: {
7381 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_ioctl.h linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_ioctl.h
7382 --- linux-3.7.1/fs/xfs/xfs_ioctl.h      2012-12-11 03:30:57.000000000 +0000
7383 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_ioctl.h    2012-12-18 15:13:16.000000000 +0000
7384 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7385         void __user             *uhandle,
7386         u32                     hlen);
7387  
7388 +extern int
7389 +xfs_sync_flags(
7390 +       struct inode            *inode,
7391 +       int                     flags,
7392 +       int                     vflags);
7393 +
7394  extern long
7395  xfs_file_ioctl(
7396         struct file             *filp,
7397 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_iops.c linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_iops.c
7398 --- linux-3.7.1/fs/xfs/xfs_iops.c       2012-12-11 03:30:57.000000000 +0000
7399 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_iops.c     2012-12-18 15:13:16.000000000 +0000
7400 @@ -28,6 +28,7 @@
7401  #include "xfs_bmap_btree.h"
7402  #include "xfs_dinode.h"
7403  #include "xfs_inode.h"
7404 +#include "xfs_ioctl.h"
7405  #include "xfs_bmap.h"
7406  #include "xfs_rtalloc.h"
7407  #include "xfs_error.h"
7408 @@ -46,6 +47,7 @@
7409  #include <linux/security.h>
7410  #include <linux/fiemap.h>
7411  #include <linux/slab.h>
7412 +#include <linux/vs_tag.h>
7413  
7414  static int
7415  xfs_initxattrs(
7416 @@ -421,6 +423,7 @@ xfs_vn_getattr(
7417         stat->nlink = ip->i_d.di_nlink;
7418         stat->uid = ip->i_d.di_uid;
7419         stat->gid = ip->i_d.di_gid;
7420 +       stat->tag = ip->i_d.di_tag;
7421         stat->ino = ip->i_ino;
7422         stat->atime = inode->i_atime;
7423         stat->mtime = inode->i_mtime;
7424 @@ -1033,6 +1036,7 @@ static const struct inode_operations xfs
7425         .listxattr              = xfs_vn_listxattr,
7426         .fiemap                 = xfs_vn_fiemap,
7427         .update_time            = xfs_vn_update_time,
7428 +       .sync_flags             = xfs_sync_flags,
7429  };
7430  
7431  static const struct inode_operations xfs_dir_inode_operations = {
7432 @@ -1059,6 +1063,7 @@ static const struct inode_operations xfs
7433         .removexattr            = generic_removexattr,
7434         .listxattr              = xfs_vn_listxattr,
7435         .update_time            = xfs_vn_update_time,
7436 +       .sync_flags             = xfs_sync_flags,
7437  };
7438  
7439  static const struct inode_operations xfs_dir_ci_inode_operations = {
7440 @@ -1110,6 +1115,10 @@ xfs_diflags_to_iflags(
7441                 inode->i_flags |= S_IMMUTABLE;
7442         else
7443                 inode->i_flags &= ~S_IMMUTABLE;
7444 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7445 +               inode->i_flags |= S_IXUNLINK;
7446 +       else
7447 +               inode->i_flags &= ~S_IXUNLINK;
7448         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7449                 inode->i_flags |= S_APPEND;
7450         else
7451 @@ -1122,6 +1131,15 @@ xfs_diflags_to_iflags(
7452                 inode->i_flags |= S_NOATIME;
7453         else
7454                 inode->i_flags &= ~S_NOATIME;
7455 +
7456 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7457 +               inode->i_vflags |= V_BARRIER;
7458 +       else
7459 +               inode->i_vflags &= ~V_BARRIER;
7460 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7461 +               inode->i_vflags |= V_COW;
7462 +       else
7463 +               inode->i_vflags &= ~V_COW;
7464  }
7465  
7466  /*
7467 @@ -1153,6 +1171,7 @@ xfs_setup_inode(
7468         set_nlink(inode, ip->i_d.di_nlink);
7469         inode->i_uid    = ip->i_d.di_uid;
7470         inode->i_gid    = ip->i_d.di_gid;
7471 +       inode->i_tag    = ip->i_d.di_tag;
7472  
7473         switch (inode->i_mode & S_IFMT) {
7474         case S_IFBLK:
7475 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_itable.c linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_itable.c
7476 --- linux-3.7.1/fs/xfs/xfs_itable.c     2012-12-11 03:30:57.000000000 +0000
7477 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_itable.c   2012-12-18 15:13:16.000000000 +0000
7478 @@ -96,6 +96,7 @@ xfs_bulkstat_one_int(
7479         buf->bs_mode = dic->di_mode;
7480         buf->bs_uid = dic->di_uid;
7481         buf->bs_gid = dic->di_gid;
7482 +       buf->bs_tag = dic->di_tag;
7483         buf->bs_size = dic->di_size;
7484         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7485         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7486 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_linux.h linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_linux.h
7487 --- linux-3.7.1/fs/xfs/xfs_linux.h      2012-12-11 03:30:57.000000000 +0000
7488 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_linux.h    2012-12-18 15:13:16.000000000 +0000
7489 @@ -121,6 +121,7 @@
7490  
7491  #define current_cpu()          (raw_smp_processor_id())
7492  #define current_pid()          (current->pid)
7493 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7494  #define current_test_flags(f)  (current->flags & (f))
7495  #define current_set_flags_nested(sp, f)                \
7496                 (*(sp) = current->flags, current->flags |= (f))
7497 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_log_recover.c linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_log_recover.c
7498 --- linux-3.7.1/fs/xfs/xfs_log_recover.c        2012-12-11 03:30:57.000000000 +0000
7499 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_log_recover.c      2012-12-18 15:13:16.000000000 +0000
7500 @@ -2359,7 +2359,8 @@ xlog_recover_inode_pass2(
7501         }
7502  
7503         /* The core is in in-core format */
7504 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7505 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7506 +               mp->m_flags & XFS_MOUNT_TAGGED);
7507  
7508         /* the rest is in on-disk format */
7509         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7510 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_mount.h linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_mount.h
7511 --- linux-3.7.1/fs/xfs/xfs_mount.h      2012-12-11 03:30:57.000000000 +0000
7512 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_mount.h    2012-12-18 15:13:16.000000000 +0000
7513 @@ -246,6 +246,7 @@ typedef struct xfs_mount {
7514                                                    allocator */
7515  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7516  
7517 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7518  
7519  /*
7520   * Default minimum read and write sizes.
7521 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_super.c linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_super.c
7522 --- linux-3.7.1/fs/xfs/xfs_super.c      2012-12-11 03:30:57.000000000 +0000
7523 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_super.c    2012-12-18 15:13:16.000000000 +0000
7524 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7525  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7526  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7527  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7528 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7529 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7530 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7531  
7532  /*
7533   * Table driven mount option parser.
7534 @@ -126,6 +129,8 @@ enum {
7535         Opt_nobarrier,
7536         Opt_inode64,
7537         Opt_inode32,
7538 +       Opt_tag,
7539 +       Opt_notag,
7540         Opt_err
7541  };
7542  
7543 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7544         {Opt_nobarrier, "nobarrier"},
7545         {Opt_inode64, "inode64"},
7546         {Opt_inode32, "inode32"},
7547 +       {Opt_tag, "tagxid"},
7548 +       {Opt_tag, "tag"},
7549 +       {Opt_notag, "notag"},
7550         {Opt_err, NULL}
7551  };
7552  
7553 @@ -383,6 +391,19 @@ xfs_parseargs(
7554                 } else if (!strcmp(this_char, "irixsgid")) {
7555                         xfs_warn(mp,
7556         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7557 +#ifndef CONFIG_TAGGING_NONE
7558 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7559 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7560 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7561 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7562 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7563 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7564 +#endif
7565 +#ifdef CONFIG_PROPAGATE
7566 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7567 +                       /* use value */
7568 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7569 +#endif
7570                 } else {
7571                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7572                         return EINVAL;
7573 @@ -1149,6 +1170,16 @@ xfs_fs_remount(
7574                 case Opt_inode32:
7575                         mp->m_maxagi = xfs_set_inode32(mp);
7576                         break;
7577 +               case Opt_tag:
7578 +                       if (!(sb->s_flags & MS_TAGGED)) {
7579 +                               printk(KERN_INFO
7580 +                                       "XFS: %s: tagging not permitted on remount.\n",
7581 +                                       sb->s_id);
7582 +                               return -EINVAL;
7583 +                       }
7584 +                       break;
7585 +               case Opt_notag:
7586 +                       break;
7587                 default:
7588                         /*
7589                          * Logically we would return an error here to prevent
7590 @@ -1368,6 +1399,9 @@ xfs_fs_fill_super(
7591         if (error)
7592                 goto out_free_sb;
7593  
7594 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7595 +               sb->s_flags |= MS_TAGGED;
7596 +
7597         /*
7598          * we must configure the block size in the superblock before we run the
7599          * full mount process as the mount process can lookup and cache inodes.
7600 diff -NurpP --minimal linux-3.7.1/fs/xfs/xfs_vnodeops.c linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_vnodeops.c
7601 --- linux-3.7.1/fs/xfs/xfs_vnodeops.c   2012-12-11 03:30:57.000000000 +0000
7602 +++ linux-3.7.1-vs2.3.5.5/fs/xfs/xfs_vnodeops.c 2012-12-18 15:13:16.000000000 +0000
7603 @@ -103,6 +103,77 @@ xfs_readlink_bmap(
7604         return error;
7605  }
7606  
7607 +
7608 +STATIC void
7609 +xfs_get_inode_flags(
7610 +       xfs_inode_t     *ip)
7611 +{
7612 +       struct inode    *inode = VFS_I(ip);
7613 +       unsigned int    flags = inode->i_flags;
7614 +       unsigned int    vflags = inode->i_vflags;
7615 +
7616 +       if (flags & S_IMMUTABLE)
7617 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7618 +       else
7619 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7620 +       if (flags & S_IXUNLINK)
7621 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7622 +       else
7623 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7624 +
7625 +       if (vflags & V_BARRIER)
7626 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7627 +       else
7628 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7629 +       if (vflags & V_COW)
7630 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7631 +       else
7632 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7633 +}
7634 +
7635 +int
7636 +xfs_sync_flags(
7637 +       struct inode            *inode,
7638 +       int                     flags,
7639 +       int                     vflags)
7640 +{
7641 +       struct xfs_inode        *ip = XFS_I(inode);
7642 +       struct xfs_mount        *mp = ip->i_mount;
7643 +       struct xfs_trans        *tp;
7644 +       unsigned int            lock_flags = 0;
7645 +       int                     code;
7646 +
7647 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7648 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7649 +       if (code)
7650 +               goto error_out;
7651 +
7652 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7653 +       xfs_trans_ijoin(tp, ip, 0);
7654 +
7655 +       inode->i_flags = flags;
7656 +       inode->i_vflags = vflags;
7657 +       xfs_get_inode_flags(ip);
7658 +
7659 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7660 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7661 +
7662 +       XFS_STATS_INC(xs_ig_attrchg);
7663 +
7664 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7665 +               xfs_trans_set_sync(tp);
7666 +       code = xfs_trans_commit(tp, 0);
7667 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7668 +       return code;
7669 +
7670 +error_out:
7671 +       xfs_trans_cancel(tp, 0);
7672 +       if (lock_flags)
7673 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7674 +       return code;
7675 +}
7676 +
7677 +
7678  int
7679  xfs_readlink(
7680         xfs_inode_t     *ip,
7681 diff -NurpP --minimal linux-3.7.1/include/linux/cred.h linux-3.7.1-vs2.3.5.5/include/linux/cred.h
7682 --- linux-3.7.1/include/linux/cred.h    2012-12-11 03:30:57.000000000 +0000
7683 +++ linux-3.7.1-vs2.3.5.5/include/linux/cred.h  2012-12-18 15:13:16.000000000 +0000
7684 @@ -157,6 +157,7 @@ extern void exit_creds(struct task_struc
7685  extern int copy_creds(struct task_struct *, unsigned long);
7686  extern const struct cred *get_task_cred(struct task_struct *);
7687  extern struct cred *cred_alloc_blank(void);
7688 +extern struct cred *__prepare_creds(const struct cred *);
7689  extern struct cred *prepare_creds(void);
7690  extern struct cred *prepare_exec_creds(void);
7691  extern int commit_creds(struct cred *);
7692 @@ -210,6 +211,31 @@ static inline void validate_process_cred
7693  }
7694  #endif
7695  
7696 +static inline void set_cred_subscribers(struct cred *cred, int n)
7697 +{
7698 +#ifdef CONFIG_DEBUG_CREDENTIALS
7699 +       atomic_set(&cred->subscribers, n);
7700 +#endif
7701 +}
7702 +
7703 +static inline int read_cred_subscribers(const struct cred *cred)
7704 +{
7705 +#ifdef CONFIG_DEBUG_CREDENTIALS
7706 +       return atomic_read(&cred->subscribers);
7707 +#else
7708 +       return 0;
7709 +#endif
7710 +}
7711 +
7712 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7713 +{
7714 +#ifdef CONFIG_DEBUG_CREDENTIALS
7715 +       struct cred *cred = (struct cred *) _cred;
7716 +
7717 +       atomic_add(n, &cred->subscribers);
7718 +#endif
7719 +}
7720 +
7721  /**
7722   * get_new_cred - Get a reference on a new set of credentials
7723   * @cred: The new credentials to reference
7724 diff -NurpP --minimal linux-3.7.1/include/linux/devpts_fs.h linux-3.7.1-vs2.3.5.5/include/linux/devpts_fs.h
7725 --- linux-3.7.1/include/linux/devpts_fs.h       2012-12-11 03:30:57.000000000 +0000
7726 +++ linux-3.7.1-vs2.3.5.5/include/linux/devpts_fs.h     2012-12-18 15:13:16.000000000 +0000
7727 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7728  
7729  #endif
7730  
7731 -
7732  #endif /* _LINUX_DEVPTS_FS_H */
7733 diff -NurpP --minimal linux-3.7.1/include/linux/fs.h linux-3.7.1-vs2.3.5.5/include/linux/fs.h
7734 --- linux-3.7.1/include/linux/fs.h      2012-12-11 03:30:57.000000000 +0000
7735 +++ linux-3.7.1-vs2.3.5.5/include/linux/fs.h    2012-12-18 15:13:16.000000000 +0000
7736 @@ -210,6 +210,7 @@ typedef void (dio_iodone_t)(struct kiocb
7737  #define ATTR_KILL_PRIV (1 << 14)
7738  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7739  #define ATTR_TIMES_SET (1 << 16)
7740 +#define ATTR_TAG       (1 << 17)
7741  
7742  /*
7743   * This is the Inode Attributes structure, used for notify_change().  It
7744 @@ -225,6 +226,7 @@ struct iattr {
7745         umode_t         ia_mode;
7746         kuid_t          ia_uid;
7747         kgid_t          ia_gid;
7748 +       ktag_t          ia_tag;
7749         loff_t          ia_size;
7750         struct timespec ia_atime;
7751         struct timespec ia_mtime;
7752 @@ -522,7 +524,9 @@ struct inode {
7753         unsigned short          i_opflags;
7754         kuid_t                  i_uid;
7755         kgid_t                  i_gid;
7756 -       unsigned int            i_flags;
7757 +       ktag_t                  i_tag;
7758 +       unsigned short          i_flags;
7759 +       unsigned short          i_vflags;
7760  
7761  #ifdef CONFIG_FS_POSIX_ACL
7762         struct posix_acl        *i_acl;
7763 @@ -551,6 +555,7 @@ struct inode {
7764                 unsigned int __i_nlink;
7765         };
7766         dev_t                   i_rdev;
7767 +       dev_t                   i_mdev;
7768         loff_t                  i_size;
7769         struct timespec         i_atime;
7770         struct timespec         i_mtime;
7771 @@ -701,6 +706,11 @@ static inline gid_t i_gid_read(const str
7772         return from_kgid(&init_user_ns, inode->i_gid);
7773  }
7774  
7775 +static inline tag_t i_tag_read(const struct inode *inode)
7776 +{
7777 +       return from_ktag(&init_user_ns, inode->i_tag);
7778 +}
7779 +
7780  static inline void i_uid_write(struct inode *inode, uid_t uid)
7781  {
7782         inode->i_uid = make_kuid(&init_user_ns, uid);
7783 @@ -711,14 +721,19 @@ static inline void i_gid_write(struct in
7784         inode->i_gid = make_kgid(&init_user_ns, gid);
7785  }
7786  
7787 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7788 +{
7789 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7790 +}
7791 +
7792  static inline unsigned iminor(const struct inode *inode)
7793  {
7794 -       return MINOR(inode->i_rdev);
7795 +       return MINOR(inode->i_mdev);
7796  }
7797  
7798  static inline unsigned imajor(const struct inode *inode)
7799  {
7800 -       return MAJOR(inode->i_rdev);
7801 +       return MAJOR(inode->i_mdev);
7802  }
7803  
7804  extern struct block_device *I_BDEV(struct inode *inode);
7805 @@ -785,6 +800,7 @@ struct file {
7806         loff_t                  f_pos;
7807         struct fown_struct      f_owner;
7808         const struct cred       *f_cred;
7809 +       xid_t                   f_xid;
7810         struct file_ra_state    f_ra;
7811  
7812         u64                     f_version;
7813 @@ -936,6 +952,7 @@ struct file_lock {
7814         struct file *fl_file;
7815         loff_t fl_start;
7816         loff_t fl_end;
7817 +       xid_t fl_xid;
7818  
7819         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7820         /* for lease breaks: */
7821 @@ -1570,6 +1587,7 @@ struct inode_operations {
7822         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7823         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7824         int (*removexattr) (struct dentry *, const char *);
7825 +       int (*sync_flags) (struct inode *, int, int);
7826         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7827                       u64 len);
7828         int (*update_time)(struct inode *, struct timespec *, int);
7829 @@ -1584,6 +1602,7 @@ ssize_t rw_copy_check_uvector(int type,
7830                               unsigned long nr_segs, unsigned long fast_segs,
7831                               struct iovec *fast_pointer,
7832                               struct iovec **ret_pointer);
7833 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7834  
7835  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7836  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7837 @@ -1637,6 +1656,14 @@ struct super_operations {
7838  #define S_IMA          1024    /* Inode has an associated IMA struct */
7839  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7840  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7841 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7842 +
7843 +/* Linux-VServer related Inode flags */
7844 +
7845 +#define V_VALID                1
7846 +#define V_XATTR                2
7847 +#define V_BARRIER      4       /* Barrier for chroot() */
7848 +#define V_COW          8       /* Copy on Write */
7849  
7850  /*
7851   * Note that nosuid etc flags are inode-specific: setting some file-system
7852 @@ -1661,10 +1688,13 @@ struct super_operations {
7853  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7854  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7855  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7856 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7857  
7858  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7859  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7860  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7861 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7862 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7863  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7864  
7865  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7866 @@ -1675,6 +1705,16 @@ struct super_operations {
7867  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7868  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7869  
7870 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7871 +
7872 +#ifdef CONFIG_VSERVER_COWBL
7873 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7874 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7875 +#else
7876 +#  define IS_COW(inode)                (0)
7877 +#  define IS_COW_LINK(inode)   (0)
7878 +#endif
7879 +
7880  /*
7881   * Inode state bits.  Protected by inode->i_lock
7882   *
7883 @@ -1900,6 +1940,9 @@ extern int rw_verify_area(int, struct fi
7884  extern int locks_mandatory_locked(struct inode *);
7885  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7886  
7887 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7888 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7889 +
7890  /*
7891   * Candidates for mandatory locking have the setgid bit set
7892   * but no group execute bit -  an otherwise meaningless combination.
7893 @@ -2504,6 +2547,7 @@ extern int dcache_dir_open(struct inode
7894  extern int dcache_dir_close(struct inode *, struct file *);
7895  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7896  extern int dcache_readdir(struct file *, void *, filldir_t);
7897 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7898  extern int simple_setattr(struct dentry *, struct iattr *);
7899  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7900  extern int simple_statfs(struct dentry *, struct kstatfs *);
7901 diff -NurpP --minimal linux-3.7.1/include/linux/init_task.h linux-3.7.1-vs2.3.5.5/include/linux/init_task.h
7902 --- linux-3.7.1/include/linux/init_task.h       2012-12-11 03:30:57.000000000 +0000
7903 +++ linux-3.7.1-vs2.3.5.5/include/linux/init_task.h     2012-12-18 15:13:16.000000000 +0000
7904 @@ -210,6 +210,10 @@ extern struct task_group root_task_group
7905         INIT_TRACE_RECURSION                                            \
7906         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7907         INIT_CPUSET_SEQ                                                 \
7908 +       .xid            = 0,                                            \
7909 +       .vx_info        = NULL,                                         \
7910 +       .nid            = 0,                                            \
7911 +       .nx_info        = NULL,                                         \
7912  }
7913  
7914  
7915 diff -NurpP --minimal linux-3.7.1/include/linux/ipc.h linux-3.7.1-vs2.3.5.5/include/linux/ipc.h
7916 --- linux-3.7.1/include/linux/ipc.h     2012-12-11 03:30:57.000000000 +0000
7917 +++ linux-3.7.1-vs2.3.5.5/include/linux/ipc.h   2012-12-18 15:13:16.000000000 +0000
7918 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7919         key_t           key;
7920         kuid_t          uid;
7921         kgid_t          gid;
7922 +       xid_t           xid;
7923         kuid_t          cuid;
7924         kgid_t          cgid;
7925         umode_t         mode; 
7926 diff -NurpP --minimal linux-3.7.1/include/linux/ipc_namespace.h linux-3.7.1-vs2.3.5.5/include/linux/ipc_namespace.h
7927 --- linux-3.7.1/include/linux/ipc_namespace.h   2012-12-11 03:30:57.000000000 +0000
7928 +++ linux-3.7.1-vs2.3.5.5/include/linux/ipc_namespace.h 2012-12-18 15:13:16.000000000 +0000
7929 @@ -133,7 +133,8 @@ static inline int mq_init_ns(struct ipc_
7930  
7931  #if defined(CONFIG_IPC_NS)
7932  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
7933 -                                      struct task_struct *tsk);
7934 +                                      struct ipc_namespace *old_ns,
7935 +                                      struct user_namespace *user_ns);
7936  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
7937  {
7938         if (ns)
7939 @@ -144,12 +145,13 @@ static inline struct ipc_namespace *get_
7940  extern void put_ipc_ns(struct ipc_namespace *ns);
7941  #else
7942  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
7943 -                                             struct task_struct *tsk)
7944 +                                             struct ipc_namespace *old_ns,
7945 +                                             struct user_namespace *user_ns)
7946  {
7947         if (flags & CLONE_NEWIPC)
7948                 return ERR_PTR(-EINVAL);
7949  
7950 -       return tsk->nsproxy->ipc_ns;
7951 +       return old_ns;
7952  }
7953  
7954  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
7955 diff -NurpP --minimal linux-3.7.1/include/linux/loop.h linux-3.7.1-vs2.3.5.5/include/linux/loop.h
7956 --- linux-3.7.1/include/linux/loop.h    2012-12-11 03:30:57.000000000 +0000
7957 +++ linux-3.7.1-vs2.3.5.5/include/linux/loop.h  2012-12-18 15:13:16.000000000 +0000
7958 @@ -41,6 +41,7 @@ struct loop_device {
7959         struct loop_func_table *lo_encryption;
7960         __u32           lo_init[2];
7961         kuid_t          lo_key_owner;   /* Who set the key */
7962 +       xid_t           lo_xid;
7963         int             (*ioctl)(struct loop_device *, int cmd, 
7964                                  unsigned long arg); 
7965  
7966 diff -NurpP --minimal linux-3.7.1/include/linux/memcontrol.h linux-3.7.1-vs2.3.5.5/include/linux/memcontrol.h
7967 --- linux-3.7.1/include/linux/memcontrol.h      2012-12-11 03:30:57.000000000 +0000
7968 +++ linux-3.7.1-vs2.3.5.5/include/linux/memcontrol.h    2012-12-18 15:13:16.000000000 +0000
7969 @@ -83,6 +83,13 @@ extern struct mem_cgroup *try_get_mem_cg
7970  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7971  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7972  
7973 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7974 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7975 +
7976 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7977 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7978 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7979 +
7980  static inline
7981  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7982  {
7983 diff -NurpP --minimal linux-3.7.1/include/linux/mm_types.h linux-3.7.1-vs2.3.5.5/include/linux/mm_types.h
7984 --- linux-3.7.1/include/linux/mm_types.h        2012-12-11 03:30:57.000000000 +0000
7985 +++ linux-3.7.1-vs2.3.5.5/include/linux/mm_types.h      2012-12-18 15:13:16.000000000 +0000
7986 @@ -365,6 +365,7 @@ struct mm_struct {
7987  
7988         /* Architecture-specific MM context */
7989         mm_context_t context;
7990 +       struct vx_info *mm_vx_info;
7991  
7992         unsigned long flags; /* Must use atomic bitops to access the bits */
7993  
7994 diff -NurpP --minimal linux-3.7.1/include/linux/mmzone.h linux-3.7.1-vs2.3.5.5/include/linux/mmzone.h
7995 --- linux-3.7.1/include/linux/mmzone.h  2012-12-11 03:30:57.000000000 +0000
7996 +++ linux-3.7.1-vs2.3.5.5/include/linux/mmzone.h        2012-12-18 15:13:16.000000000 +0000
7997 @@ -735,6 +735,13 @@ typedef struct pglist_data {
7998         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
7999  })
8000  
8001 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8002 +
8003 +#define node_end_pfn(nid) ({\
8004 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8005 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8006 +})
8007 +
8008  #include <linux/memory_hotplug.h>
8009  
8010  extern struct mutex zonelists_mutex;
8011 diff -NurpP --minimal linux-3.7.1/include/linux/mount.h linux-3.7.1-vs2.3.5.5/include/linux/mount.h
8012 --- linux-3.7.1/include/linux/mount.h   2012-12-11 03:30:57.000000000 +0000
8013 +++ linux-3.7.1-vs2.3.5.5/include/linux/mount.h 2012-12-18 15:13:16.000000000 +0000
8014 @@ -47,6 +47,9 @@ struct mnt_namespace;
8015  
8016  #define MNT_INTERNAL   0x4000
8017  
8018 +#define MNT_TAGID      0x10000
8019 +#define MNT_NOTAG      0x20000
8020 +
8021  struct vfsmount {
8022         struct dentry *mnt_root;        /* root of the mounted tree */
8023         struct super_block *mnt_sb;     /* pointer to superblock */
8024 diff -NurpP --minimal linux-3.7.1/include/linux/net.h linux-3.7.1-vs2.3.5.5/include/linux/net.h
8025 --- linux-3.7.1/include/linux/net.h     2012-12-11 03:30:57.000000000 +0000
8026 +++ linux-3.7.1-vs2.3.5.5/include/linux/net.h   2012-12-18 15:13:16.000000000 +0000
8027 @@ -38,6 +38,7 @@ struct net;
8028  #define SOCK_PASSCRED          3
8029  #define SOCK_PASSSEC           4
8030  #define SOCK_EXTERNALLY_ALLOCATED 5
8031 +#define SOCK_USER_SOCKET       6
8032  
8033  #ifndef ARCH_HAS_SOCKET_TYPES
8034  /**
8035 diff -NurpP --minimal linux-3.7.1/include/linux/netdevice.h linux-3.7.1-vs2.3.5.5/include/linux/netdevice.h
8036 --- linux-3.7.1/include/linux/netdevice.h       2012-12-11 03:30:57.000000000 +0000
8037 +++ linux-3.7.1-vs2.3.5.5/include/linux/netdevice.h     2012-12-18 15:13:16.000000000 +0000
8038 @@ -1637,6 +1637,7 @@ extern void               netdev_resync_ops(struct ne
8039  
8040  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8041  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8042 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8043  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8044  extern int             dev_restart(struct net_device *dev);
8045  #ifdef CONFIG_NETPOLL_TRAP
8046 diff -NurpP --minimal linux-3.7.1/include/linux/nsproxy.h linux-3.7.1-vs2.3.5.5/include/linux/nsproxy.h
8047 --- linux-3.7.1/include/linux/nsproxy.h 2012-12-11 03:30:57.000000000 +0000
8048 +++ linux-3.7.1-vs2.3.5.5/include/linux/nsproxy.h       2012-12-18 15:13:16.000000000 +0000
8049 @@ -3,6 +3,7 @@
8050  
8051  #include <linux/spinlock.h>
8052  #include <linux/sched.h>
8053 +#include <linux/vserver/debug.h>
8054  
8055  struct mnt_namespace;
8056  struct uts_namespace;
8057 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8058  }
8059  
8060  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8061 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8062  void exit_task_namespaces(struct task_struct *tsk);
8063  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8064  void free_nsproxy(struct nsproxy *ns);
8065 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
8066         struct fs_struct *);
8067  int __init nsproxy_cache_init(void);
8068  
8069 -static inline void put_nsproxy(struct nsproxy *ns)
8070 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8071 +
8072 +static inline void __get_nsproxy(struct nsproxy *ns,
8073 +       const char *_file, int _line)
8074  {
8075 -       if (atomic_dec_and_test(&ns->count)) {
8076 -               free_nsproxy(ns);
8077 -       }
8078 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8079 +               ns, atomic_read(&ns->count), _file, _line);
8080 +       atomic_inc(&ns->count);
8081  }
8082  
8083 -static inline void get_nsproxy(struct nsproxy *ns)
8084 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8085 +
8086 +static inline void __put_nsproxy(struct nsproxy *ns,
8087 +       const char *_file, int _line)
8088  {
8089 -       atomic_inc(&ns->count);
8090 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8091 +               ns, atomic_read(&ns->count), _file, _line);
8092 +       if (atomic_dec_and_test(&ns->count)) {
8093 +               free_nsproxy(ns);
8094 +       }
8095  }
8096  
8097  #endif
8098 diff -NurpP --minimal linux-3.7.1/include/linux/pid.h linux-3.7.1-vs2.3.5.5/include/linux/pid.h
8099 --- linux-3.7.1/include/linux/pid.h     2012-12-11 03:30:57.000000000 +0000
8100 +++ linux-3.7.1-vs2.3.5.5/include/linux/pid.h   2012-12-18 15:13:16.000000000 +0000
8101 @@ -8,7 +8,8 @@ enum pid_type
8102         PIDTYPE_PID,
8103         PIDTYPE_PGID,
8104         PIDTYPE_SID,
8105 -       PIDTYPE_MAX
8106 +       PIDTYPE_MAX,
8107 +       PIDTYPE_REALPID
8108  };
8109  
8110  /*
8111 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8112  }
8113  
8114  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8115 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8116  pid_t pid_vnr(struct pid *pid);
8117  
8118  #define do_each_pid_task(pid, type, task)                              \
8119 diff -NurpP --minimal linux-3.7.1/include/linux/proc_fs.h linux-3.7.1-vs2.3.5.5/include/linux/proc_fs.h
8120 --- linux-3.7.1/include/linux/proc_fs.h 2012-12-11 03:30:57.000000000 +0000
8121 +++ linux-3.7.1-vs2.3.5.5/include/linux/proc_fs.h       2012-12-18 15:13:16.000000000 +0000
8122 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8123         nlink_t nlink;
8124         kuid_t uid;
8125         kgid_t gid;
8126 +       int vx_flags;
8127         loff_t size;
8128         const struct inode_operations *proc_iops;
8129         /*
8130 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8131  extern const struct proc_ns_operations utsns_operations;
8132  extern const struct proc_ns_operations ipcns_operations;
8133  
8134 +struct vx_info;
8135 +struct nx_info;
8136 +
8137  union proc_op {
8138         int (*proc_get_link)(struct dentry *, struct path *);
8139         int (*proc_read)(struct task_struct *task, char *page);
8140         int (*proc_show)(struct seq_file *m,
8141                 struct pid_namespace *ns, struct pid *pid,
8142                 struct task_struct *task);
8143 +       int (*proc_vs_read)(char *page);
8144 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8145 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8146  };
8147  
8148  struct ctl_table_header;
8149 @@ -265,6 +272,7 @@ struct ctl_table;
8150  
8151  struct proc_inode {
8152         struct pid *pid;
8153 +       int vx_flags;
8154         int fd;
8155         union proc_op op;
8156         struct proc_dir_entry *pde;
8157 diff -NurpP --minimal linux-3.7.1/include/linux/quotaops.h linux-3.7.1-vs2.3.5.5/include/linux/quotaops.h
8158 --- linux-3.7.1/include/linux/quotaops.h        2012-12-11 03:30:57.000000000 +0000
8159 +++ linux-3.7.1-vs2.3.5.5/include/linux/quotaops.h      2012-12-18 15:13:16.000000000 +0000
8160 @@ -8,6 +8,7 @@
8161  #define _LINUX_QUOTAOPS_
8162  
8163  #include <linux/fs.h>
8164 +#include <linux/vs_dlimit.h>
8165  
8166  #define DQUOT_SPACE_WARN       0x1
8167  #define DQUOT_SPACE_RESERVE    0x2
8168 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8169  
8170  static inline int dquot_alloc_inode(const struct inode *inode)
8171  {
8172 -       return 0;
8173 +       return dl_alloc_inode(inode);
8174  }
8175  
8176  static inline void dquot_free_inode(const struct inode *inode)
8177  {
8178 +       dl_free_inode(inode);
8179  }
8180  
8181  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8182 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8183  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8184                 int flags)
8185  {
8186 +       int ret = 0;
8187 +
8188 +       if ((ret = dl_alloc_space(inode, number)))
8189 +               return ret;
8190         if (!(flags & DQUOT_SPACE_RESERVE))
8191                 inode_add_bytes(inode, number);
8192         return 0;
8193 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8194  {
8195         if (!(flags & DQUOT_SPACE_RESERVE))
8196                 inode_sub_bytes(inode, number);
8197 +       dl_free_space(inode, number);
8198  }
8199  
8200  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8201 diff -NurpP --minimal linux-3.7.1/include/linux/sched.h linux-3.7.1-vs2.3.5.5/include/linux/sched.h
8202 --- linux-3.7.1/include/linux/sched.h   2012-12-11 03:30:57.000000000 +0000
8203 +++ linux-3.7.1-vs2.3.5.5/include/linux/sched.h 2012-12-18 15:13:16.000000000 +0000
8204 @@ -1378,6 +1378,14 @@ struct task_struct {
8205  #endif
8206         struct seccomp seccomp;
8207  
8208 +/* vserver context data */
8209 +       struct vx_info *vx_info;
8210 +       struct nx_info *nx_info;
8211 +
8212 +       xid_t xid;
8213 +       nid_t nid;
8214 +       tag_t tag;
8215 +
8216  /* Thread group tracking */
8217         u32 parent_exec_id;
8218         u32 self_exec_id;
8219 @@ -1627,6 +1635,11 @@ struct pid_namespace;
8220  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8221                         struct pid_namespace *ns);
8222  
8223 +#include <linux/vserver/base.h>
8224 +#include <linux/vserver/context.h>
8225 +#include <linux/vserver/debug.h>
8226 +#include <linux/vserver/pid.h>
8227 +
8228  static inline pid_t task_pid_nr(struct task_struct *tsk)
8229  {
8230         return tsk->pid;
8231 @@ -1640,7 +1653,8 @@ static inline pid_t task_pid_nr_ns(struc
8232  
8233  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8234  {
8235 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8236 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8237 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8238  }
8239  
8240  
8241 @@ -1653,7 +1667,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8242  
8243  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8244  {
8245 -       return pid_vnr(task_tgid(tsk));
8246 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8247  }
8248  
8249  
8250 diff -NurpP --minimal linux-3.7.1/include/linux/shmem_fs.h linux-3.7.1-vs2.3.5.5/include/linux/shmem_fs.h
8251 --- linux-3.7.1/include/linux/shmem_fs.h        2012-12-11 03:30:57.000000000 +0000
8252 +++ linux-3.7.1-vs2.3.5.5/include/linux/shmem_fs.h      2012-12-18 15:13:16.000000000 +0000
8253 @@ -9,6 +9,9 @@
8254  
8255  /* inode in-kernel data */
8256  
8257 +#define TMPFS_SUPER_MAGIC      0x01021994
8258 +
8259 +
8260  struct shmem_inode_info {
8261         spinlock_t              lock;
8262         unsigned long           flags;
8263 diff -NurpP --minimal linux-3.7.1/include/linux/stat.h linux-3.7.1-vs2.3.5.5/include/linux/stat.h
8264 --- linux-3.7.1/include/linux/stat.h    2012-12-11 03:30:57.000000000 +0000
8265 +++ linux-3.7.1-vs2.3.5.5/include/linux/stat.h  2012-12-18 15:13:16.000000000 +0000
8266 @@ -25,6 +25,7 @@ struct kstat {
8267         unsigned int    nlink;
8268         kuid_t          uid;
8269         kgid_t          gid;
8270 +       tag_t           tag;
8271         dev_t           rdev;
8272         loff_t          size;
8273         struct timespec  atime;
8274 diff -NurpP --minimal linux-3.7.1/include/linux/sunrpc/auth.h linux-3.7.1-vs2.3.5.5/include/linux/sunrpc/auth.h
8275 --- linux-3.7.1/include/linux/sunrpc/auth.h     2012-12-11 03:30:57.000000000 +0000
8276 +++ linux-3.7.1-vs2.3.5.5/include/linux/sunrpc/auth.h   2012-12-18 15:13:16.000000000 +0000
8277 @@ -25,6 +25,7 @@
8278  struct auth_cred {
8279         uid_t   uid;
8280         gid_t   gid;
8281 +       tag_t   tag;
8282         struct group_info *group_info;
8283         const char *principal;
8284         unsigned char machine_cred : 1;
8285 diff -NurpP --minimal linux-3.7.1/include/linux/sunrpc/clnt.h linux-3.7.1-vs2.3.5.5/include/linux/sunrpc/clnt.h
8286 --- linux-3.7.1/include/linux/sunrpc/clnt.h     2012-12-11 03:30:57.000000000 +0000
8287 +++ linux-3.7.1-vs2.3.5.5/include/linux/sunrpc/clnt.h   2012-12-18 15:13:16.000000000 +0000
8288 @@ -49,7 +49,8 @@ struct rpc_clnt {
8289         unsigned int            cl_softrtry : 1,/* soft timeouts */
8290                                 cl_discrtry : 1,/* disconnect before retry */
8291                                 cl_autobind : 1,/* use getport() */
8292 -                               cl_chatty   : 1;/* be verbose */
8293 +                               cl_chatty   : 1,/* be verbose */
8294 +                               cl_tag      : 1;/* context tagging */
8295  
8296         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8297         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8298 diff -NurpP --minimal linux-3.7.1/include/linux/sysfs.h linux-3.7.1-vs2.3.5.5/include/linux/sysfs.h
8299 --- linux-3.7.1/include/linux/sysfs.h   2012-12-11 03:30:57.000000000 +0000
8300 +++ linux-3.7.1-vs2.3.5.5/include/linux/sysfs.h 2012-12-18 15:13:16.000000000 +0000
8301 @@ -19,6 +19,8 @@
8302  #include <linux/kobject_ns.h>
8303  #include <linux/atomic.h>
8304  
8305 +#define SYSFS_SUPER_MAGIC      0x62656572
8306 +
8307  struct kobject;
8308  struct module;
8309  enum kobj_ns_type;
8310 diff -NurpP --minimal linux-3.7.1/include/linux/types.h linux-3.7.1-vs2.3.5.5/include/linux/types.h
8311 --- linux-3.7.1/include/linux/types.h   2012-12-11 03:30:57.000000000 +0000
8312 +++ linux-3.7.1-vs2.3.5.5/include/linux/types.h 2012-12-18 15:13:16.000000000 +0000
8313 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8314  typedef __kernel_gid32_t       gid_t;
8315  typedef __kernel_uid16_t        uid16_t;
8316  typedef __kernel_gid16_t        gid16_t;
8317 +typedef unsigned int           xid_t;
8318 +typedef unsigned int           nid_t;
8319 +typedef unsigned int           tag_t;
8320  
8321  typedef unsigned long          uintptr_t;
8322  
8323 diff -NurpP --minimal linux-3.7.1/include/linux/uidgid.h linux-3.7.1-vs2.3.5.5/include/linux/uidgid.h
8324 --- linux-3.7.1/include/linux/uidgid.h  2012-12-11 03:30:57.000000000 +0000
8325 +++ linux-3.7.1-vs2.3.5.5/include/linux/uidgid.h        2012-12-18 15:13:16.000000000 +0000
8326 @@ -23,13 +23,17 @@ typedef struct {
8327         uid_t val;
8328  } kuid_t;
8329  
8330 -
8331  typedef struct {
8332         gid_t val;
8333  } kgid_t;
8334  
8335 +typedef struct {
8336 +       tag_t val;
8337 +} ktag_t;
8338 +
8339  #define KUIDT_INIT(value) (kuid_t){ value }
8340  #define KGIDT_INIT(value) (kgid_t){ value }
8341 +#define KTAGT_INIT(value) (ktag_t){ value }
8342  
8343  static inline uid_t __kuid_val(kuid_t uid)
8344  {
8345 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8346         return gid.val;
8347  }
8348  
8349 +static inline tag_t __ktag_val(ktag_t tag)
8350 +{
8351 +       return tag.val;
8352 +}
8353 +
8354  #else
8355  
8356  typedef uid_t kuid_t;
8357  typedef gid_t kgid_t;
8358 +typedef tag_t ktag_t;
8359  
8360  static inline uid_t __kuid_val(kuid_t uid)
8361  {
8362 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8363         return gid;
8364  }
8365  
8366 +static inline tag_t __ktag_val(ktag_t tag)
8367 +{
8368 +       return tag;
8369 +}
8370 +
8371  #define KUIDT_INIT(value) ((kuid_t) value )
8372  #define KGIDT_INIT(value) ((kgid_t) value )
8373 +#define KTAGT_INIT(value) ((ktag_t) value )
8374  
8375  #endif
8376  
8377  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8378  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8379 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8380  
8381  #define INVALID_UID KUIDT_INIT(-1)
8382  #define INVALID_GID KGIDT_INIT(-1)
8383 +#define INVALID_TAG KTAGT_INIT(-1)
8384  
8385  static inline bool uid_eq(kuid_t left, kuid_t right)
8386  {
8387 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8388         return __kgid_val(left) == __kgid_val(right);
8389  }
8390  
8391 +static inline bool tag_eq(ktag_t left, ktag_t right)
8392 +{
8393 +       return __ktag_val(left) == __ktag_val(right);
8394 +}
8395 +
8396  static inline bool uid_gt(kuid_t left, kuid_t right)
8397  {
8398         return __kuid_val(left) > __kuid_val(right);
8399 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8400         return !gid_eq(gid, INVALID_GID);
8401  }
8402  
8403 +static inline bool tag_valid(ktag_t tag)
8404 +{
8405 +       return !tag_eq(tag, INVALID_TAG);
8406 +}
8407 +
8408  #ifdef CONFIG_USER_NS
8409  
8410  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8411  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8412 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8413  
8414  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8415  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8416 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8417 +
8418  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8419  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8420  
8421 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8422         return KGIDT_INIT(gid);
8423  }
8424  
8425 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8426 +{
8427 +       return KTAGT_INIT(tag);
8428 +}
8429 +
8430  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8431  {
8432         return __kuid_val(kuid);
8433 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8434         return __kgid_val(kgid);
8435  }
8436  
8437 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8438 +{
8439 +       return __ktag_val(ktag);
8440 +}
8441 +
8442  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8443  {
8444         uid_t uid = from_kuid(to, kuid);
8445 diff -NurpP --minimal linux-3.7.1/include/linux/utsname.h linux-3.7.1-vs2.3.5.5/include/linux/utsname.h
8446 --- linux-3.7.1/include/linux/utsname.h 2012-12-11 03:30:57.000000000 +0000
8447 +++ linux-3.7.1-vs2.3.5.5/include/linux/utsname.h       2012-12-18 15:13:16.000000000 +0000
8448 @@ -33,7 +33,8 @@ static inline void get_uts_ns(struct uts
8449  }
8450  
8451  extern struct uts_namespace *copy_utsname(unsigned long flags,
8452 -                                         struct task_struct *tsk);
8453 +                                         struct uts_namespace *old_ns,
8454 +                                         struct user_namespace *user_ns);
8455  extern void free_uts_ns(struct kref *kref);
8456  
8457  static inline void put_uts_ns(struct uts_namespace *ns)
8458 @@ -50,12 +51,13 @@ static inline void put_uts_ns(struct uts
8459  }
8460  
8461  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8462 -                                                struct task_struct *tsk)
8463 +                                                struct uts_namespace *old_ns,
8464 +                                                struct user_namespace *user_ns)
8465  {
8466         if (flags & CLONE_NEWUTS)
8467                 return ERR_PTR(-EINVAL);
8468  
8469 -       return tsk->nsproxy->uts_ns;
8470 +       return old_ns;
8471  }
8472  #endif
8473  
8474 diff -NurpP --minimal linux-3.7.1/include/linux/vroot.h linux-3.7.1-vs2.3.5.5/include/linux/vroot.h
8475 --- linux-3.7.1/include/linux/vroot.h   1970-01-01 00:00:00.000000000 +0000
8476 +++ linux-3.7.1-vs2.3.5.5/include/linux/vroot.h 2012-12-18 15:13:16.000000000 +0000
8477 @@ -0,0 +1,51 @@
8478 +
8479 +/*
8480 + * include/linux/vroot.h
8481 + *
8482 + * written by Herbert Pötzl, 9/11/2002
8483 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8484 + *
8485 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8486 + * Redistribution of this file is permitted under the
8487 + * GNU General Public License.
8488 + */
8489 +
8490 +#ifndef _LINUX_VROOT_H
8491 +#define _LINUX_VROOT_H
8492 +
8493 +
8494 +#ifdef __KERNEL__
8495 +
8496 +/* Possible states of device */
8497 +enum {
8498 +       Vr_unbound,
8499 +       Vr_bound,
8500 +};
8501 +
8502 +struct vroot_device {
8503 +       int             vr_number;
8504 +       int             vr_refcnt;
8505 +
8506 +       struct semaphore        vr_ctl_mutex;
8507 +       struct block_device    *vr_device;
8508 +       int                     vr_state;
8509 +};
8510 +
8511 +
8512 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8513 +
8514 +extern int register_vroot_grb(vroot_grb_func *);
8515 +extern int unregister_vroot_grb(vroot_grb_func *);
8516 +
8517 +#endif /* __KERNEL__ */
8518 +
8519 +#define MAX_VROOT_DEFAULT      8
8520 +
8521 +/*
8522 + * IOCTL commands --- we will commandeer 0x56 ('V')
8523 + */
8524 +
8525 +#define VROOT_SET_DEV          0x5600
8526 +#define VROOT_CLR_DEV          0x5601
8527 +
8528 +#endif /* _LINUX_VROOT_H */
8529 diff -NurpP --minimal linux-3.7.1/include/linux/vs_base.h linux-3.7.1-vs2.3.5.5/include/linux/vs_base.h
8530 --- linux-3.7.1/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8531 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_base.h       2012-12-18 15:13:16.000000000 +0000
8532 @@ -0,0 +1,10 @@
8533 +#ifndef _VS_BASE_H
8534 +#define _VS_BASE_H
8535 +
8536 +#include "vserver/base.h"
8537 +#include "vserver/check.h"
8538 +#include "vserver/debug.h"
8539 +
8540 +#else
8541 +#warning duplicate inclusion
8542 +#endif
8543 diff -NurpP --minimal linux-3.7.1/include/linux/vs_context.h linux-3.7.1-vs2.3.5.5/include/linux/vs_context.h
8544 --- linux-3.7.1/include/linux/vs_context.h      1970-01-01 00:00:00.000000000 +0000
8545 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_context.h    2012-12-18 15:13:16.000000000 +0000
8546 @@ -0,0 +1,242 @@
8547 +#ifndef _VS_CONTEXT_H
8548 +#define _VS_CONTEXT_H
8549 +
8550 +#include "vserver/base.h"
8551 +#include "vserver/check.h"
8552 +#include "vserver/context.h"
8553 +#include "vserver/history.h"
8554 +#include "vserver/debug.h"
8555 +
8556 +#include <linux/sched.h>
8557 +
8558 +
8559 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8560 +
8561 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8562 +       const char *_file, int _line, void *_here)
8563 +{
8564 +       if (!vxi)
8565 +               return NULL;
8566 +
8567 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8568 +               vxi, vxi ? vxi->vx_id : 0,
8569 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8570 +               _file, _line);
8571 +       __vxh_get_vx_info(vxi, _here);
8572 +
8573 +       atomic_inc(&vxi->vx_usecnt);
8574 +       return vxi;
8575 +}
8576 +
8577 +
8578 +extern void free_vx_info(struct vx_info *);
8579 +
8580 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8581 +
8582 +static inline void __put_vx_info(struct vx_info *vxi,
8583 +       const char *_file, int _line, void *_here)
8584 +{
8585 +       if (!vxi)
8586 +               return;
8587 +
8588 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8589 +               vxi, vxi ? vxi->vx_id : 0,
8590 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8591 +               _file, _line);
8592 +       __vxh_put_vx_info(vxi, _here);
8593 +
8594 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8595 +               free_vx_info(vxi);
8596 +}
8597 +
8598 +
8599 +#define init_vx_info(p, i) \
8600 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8601 +
8602 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8603 +       const char *_file, int _line, void *_here)
8604 +{
8605 +       if (vxi) {
8606 +               vxlprintk(VXD_CBIT(xid, 3),
8607 +                       "init_vx_info(%p[#%d.%d])",
8608 +                       vxi, vxi ? vxi->vx_id : 0,
8609 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8610 +                       _file, _line);
8611 +               __vxh_init_vx_info(vxi, vxp, _here);
8612 +
8613 +               atomic_inc(&vxi->vx_usecnt);
8614 +       }
8615 +       *vxp = vxi;
8616 +}
8617 +
8618 +
8619 +#define set_vx_info(p, i) \
8620 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8621 +
8622 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8623 +       const char *_file, int _line, void *_here)
8624 +{
8625 +       struct vx_info *vxo;
8626 +
8627 +       if (!vxi)
8628 +               return;
8629 +
8630 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8631 +               vxi, vxi ? vxi->vx_id : 0,
8632 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8633 +               _file, _line);
8634 +       __vxh_set_vx_info(vxi, vxp, _here);
8635 +
8636 +       atomic_inc(&vxi->vx_usecnt);
8637 +       vxo = xchg(vxp, vxi);
8638 +       BUG_ON(vxo);
8639 +}
8640 +
8641 +
8642 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8643 +
8644 +static inline void __clr_vx_info(struct vx_info **vxp,
8645 +       const char *_file, int _line, void *_here)
8646 +{
8647 +       struct vx_info *vxo;
8648 +
8649 +       vxo = xchg(vxp, NULL);
8650 +       if (!vxo)
8651 +               return;
8652 +
8653 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8654 +               vxo, vxo ? vxo->vx_id : 0,
8655 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8656 +               _file, _line);
8657 +       __vxh_clr_vx_info(vxo, vxp, _here);
8658 +
8659 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8660 +               free_vx_info(vxo);
8661 +}
8662 +
8663 +
8664 +#define claim_vx_info(v, p) \
8665 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8666 +
8667 +static inline void __claim_vx_info(struct vx_info *vxi,
8668 +       struct task_struct *task,
8669 +       const char *_file, int _line, void *_here)
8670 +{
8671 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8672 +               vxi, vxi ? vxi->vx_id : 0,
8673 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8674 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8675 +               task, _file, _line);
8676 +       __vxh_claim_vx_info(vxi, task, _here);
8677 +
8678 +       atomic_inc(&vxi->vx_tasks);
8679 +}
8680 +
8681 +
8682 +extern void unhash_vx_info(struct vx_info *);
8683 +
8684 +#define release_vx_info(v, p) \
8685 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8686 +
8687 +static inline void __release_vx_info(struct vx_info *vxi,
8688 +       struct task_struct *task,
8689 +       const char *_file, int _line, void *_here)
8690 +{
8691 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8692 +               vxi, vxi ? vxi->vx_id : 0,
8693 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8694 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8695 +               task, _file, _line);
8696 +       __vxh_release_vx_info(vxi, task, _here);
8697 +
8698 +       might_sleep();
8699 +
8700 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8701 +               unhash_vx_info(vxi);
8702 +}
8703 +
8704 +
8705 +#define task_get_vx_info(p) \
8706 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8707 +
8708 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8709 +       const char *_file, int _line, void *_here)
8710 +{
8711 +       struct vx_info *vxi;
8712 +
8713 +       task_lock(p);
8714 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8715 +               p, _file, _line);
8716 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8717 +       task_unlock(p);
8718 +       return vxi;
8719 +}
8720 +
8721 +
8722 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8723 +{
8724 +       if (waitqueue_active(&vxi->vx_wait))
8725 +               wake_up_interruptible(&vxi->vx_wait);
8726 +}
8727 +
8728 +
8729 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8730 +
8731 +static inline void __enter_vx_info(struct vx_info *vxi,
8732 +       struct vx_info_save *vxis, const char *_file, int _line)
8733 +{
8734 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8735 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8736 +               current->xid, current->vx_info, _file, _line);
8737 +       vxis->vxi = xchg(&current->vx_info, vxi);
8738 +       vxis->xid = current->xid;
8739 +       current->xid = vxi ? vxi->vx_id : 0;
8740 +}
8741 +
8742 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8743 +
8744 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8745 +       const char *_file, int _line)
8746 +{
8747 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8748 +               vxis, vxis->xid, vxis->vxi, current,
8749 +               current->xid, current->vx_info, _file, _line);
8750 +       (void)xchg(&current->vx_info, vxis->vxi);
8751 +       current->xid = vxis->xid;
8752 +}
8753 +
8754 +
8755 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8756 +{
8757 +       vxis->vxi = xchg(&current->vx_info, NULL);
8758 +       vxis->xid = xchg(&current->xid, (xid_t)0);
8759 +}
8760 +
8761 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8762 +{
8763 +       (void)xchg(&current->xid, vxis->xid);
8764 +       (void)xchg(&current->vx_info, vxis->vxi);
8765 +}
8766 +
8767 +#define task_is_init(p) \
8768 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8769 +
8770 +static inline int __task_is_init(struct task_struct *p,
8771 +       const char *_file, int _line, void *_here)
8772 +{
8773 +       int is_init = is_global_init(p);
8774 +
8775 +       task_lock(p);
8776 +       if (p->vx_info)
8777 +               is_init = p->vx_info->vx_initpid == p->pid;
8778 +       task_unlock(p);
8779 +       return is_init;
8780 +}
8781 +
8782 +extern void exit_vx_info(struct task_struct *, int);
8783 +extern void exit_vx_info_early(struct task_struct *, int);
8784 +
8785 +
8786 +#else
8787 +#warning duplicate inclusion
8788 +#endif
8789 diff -NurpP --minimal linux-3.7.1/include/linux/vs_cowbl.h linux-3.7.1-vs2.3.5.5/include/linux/vs_cowbl.h
8790 --- linux-3.7.1/include/linux/vs_cowbl.h        1970-01-01 00:00:00.000000000 +0000
8791 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_cowbl.h      2012-12-18 15:13:16.000000000 +0000
8792 @@ -0,0 +1,48 @@
8793 +#ifndef _VS_COWBL_H
8794 +#define _VS_COWBL_H
8795 +
8796 +#include <linux/fs.h>
8797 +#include <linux/dcache.h>
8798 +#include <linux/namei.h>
8799 +#include <linux/slab.h>
8800 +
8801 +extern struct dentry *cow_break_link(const char *pathname);
8802 +
8803 +static inline int cow_check_and_break(struct path *path)
8804 +{
8805 +       struct inode *inode = path->dentry->d_inode;
8806 +       int error = 0;
8807 +
8808 +       /* do we need this check? */
8809 +       if (IS_RDONLY(inode))
8810 +               return -EROFS;
8811 +
8812 +       if (IS_COW(inode)) {
8813 +               if (IS_COW_LINK(inode)) {
8814 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8815 +                       char *pp, *buf;
8816 +
8817 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8818 +                       if (!buf) {
8819 +                               return -ENOMEM;
8820 +                       }
8821 +                       pp = d_path(path, buf, PATH_MAX);
8822 +                       new_dentry = cow_break_link(pp);
8823 +                       kfree(buf);
8824 +                       if (!IS_ERR(new_dentry)) {
8825 +                               path->dentry = new_dentry;
8826 +                               dput(old_dentry);
8827 +                       } else
8828 +                               error = PTR_ERR(new_dentry);
8829 +               } else {
8830 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8831 +                       inode->i_ctime = CURRENT_TIME;
8832 +                       mark_inode_dirty(inode);
8833 +               }
8834 +       }
8835 +       return error;
8836 +}
8837 +
8838 +#else
8839 +#warning duplicate inclusion
8840 +#endif
8841 diff -NurpP --minimal linux-3.7.1/include/linux/vs_cvirt.h linux-3.7.1-vs2.3.5.5/include/linux/vs_cvirt.h
8842 --- linux-3.7.1/include/linux/vs_cvirt.h        1970-01-01 00:00:00.000000000 +0000
8843 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_cvirt.h      2012-12-18 15:13:16.000000000 +0000
8844 @@ -0,0 +1,50 @@
8845 +#ifndef _VS_CVIRT_H
8846 +#define _VS_CVIRT_H
8847 +
8848 +#include "vserver/cvirt.h"
8849 +#include "vserver/context.h"
8850 +#include "vserver/base.h"
8851 +#include "vserver/check.h"
8852 +#include "vserver/debug.h"
8853 +
8854 +
8855 +static inline void vx_activate_task(struct task_struct *p)
8856 +{
8857 +       struct vx_info *vxi;
8858 +
8859 +       if ((vxi = p->vx_info)) {
8860 +               vx_update_load(vxi);
8861 +               atomic_inc(&vxi->cvirt.nr_running);
8862 +       }
8863 +}
8864 +
8865 +static inline void vx_deactivate_task(struct task_struct *p)
8866 +{
8867 +       struct vx_info *vxi;
8868 +
8869 +       if ((vxi = p->vx_info)) {
8870 +               vx_update_load(vxi);
8871 +               atomic_dec(&vxi->cvirt.nr_running);
8872 +       }
8873 +}
8874 +
8875 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8876 +{
8877 +       struct vx_info *vxi;
8878 +
8879 +       if ((vxi = p->vx_info))
8880 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8881 +}
8882 +
8883 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8884 +{
8885 +       struct vx_info *vxi;
8886 +
8887 +       if ((vxi = p->vx_info))
8888 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8889 +}
8890 +
8891 +
8892 +#else
8893 +#warning duplicate inclusion
8894 +#endif
8895 diff -NurpP --minimal linux-3.7.1/include/linux/vs_device.h linux-3.7.1-vs2.3.5.5/include/linux/vs_device.h
8896 --- linux-3.7.1/include/linux/vs_device.h       1970-01-01 00:00:00.000000000 +0000
8897 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_device.h     2012-12-18 15:13:16.000000000 +0000
8898 @@ -0,0 +1,45 @@
8899 +#ifndef _VS_DEVICE_H
8900 +#define _VS_DEVICE_H
8901 +
8902 +#include "vserver/base.h"
8903 +#include "vserver/device.h"
8904 +#include "vserver/debug.h"
8905 +
8906 +
8907 +#ifdef CONFIG_VSERVER_DEVICE
8908 +
8909 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8910 +
8911 +#define vs_device_perm(v, d, m, p) \
8912 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8913 +
8914 +#else
8915 +
8916 +static inline
8917 +int vs_map_device(struct vx_info *vxi,
8918 +       dev_t device, dev_t *target, umode_t mode)
8919 +{
8920 +       if (target)
8921 +               *target = device;
8922 +       return ~0;
8923 +}
8924 +
8925 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8926 +
8927 +#endif
8928 +
8929 +
8930 +#define vs_map_chrdev(d, t, p) \
8931 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8932 +#define vs_map_blkdev(d, t, p) \
8933 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8934 +
8935 +#define vs_chrdev_perm(d, p) \
8936 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8937 +#define vs_blkdev_perm(d, p) \
8938 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8939 +
8940 +
8941 +#else
8942 +#warning duplicate inclusion
8943 +#endif
8944 diff -NurpP --minimal linux-3.7.1/include/linux/vs_dlimit.h linux-3.7.1-vs2.3.5.5/include/linux/vs_dlimit.h
8945 --- linux-3.7.1/include/linux/vs_dlimit.h       1970-01-01 00:00:00.000000000 +0000
8946 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_dlimit.h     2012-12-18 15:13:16.000000000 +0000
8947 @@ -0,0 +1,215 @@
8948 +#ifndef _VS_DLIMIT_H
8949 +#define _VS_DLIMIT_H
8950 +
8951 +#include <linux/fs.h>
8952 +
8953 +#include "vserver/dlimit.h"
8954 +#include "vserver/base.h"
8955 +#include "vserver/debug.h"
8956 +
8957 +
8958 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8959 +
8960 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8961 +       const char *_file, int _line)
8962 +{
8963 +       if (!dli)
8964 +               return NULL;
8965 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8966 +               dli, dli ? dli->dl_tag : 0,
8967 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8968 +               _file, _line);
8969 +       atomic_inc(&dli->dl_usecnt);
8970 +       return dli;
8971 +}
8972 +
8973 +
8974 +#define free_dl_info(i) \
8975 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8976 +
8977 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8978 +
8979 +static inline void __put_dl_info(struct dl_info *dli,
8980 +       const char *_file, int _line)
8981 +{
8982 +       if (!dli)
8983 +               return;
8984 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8985 +               dli, dli ? dli->dl_tag : 0,
8986 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8987 +               _file, _line);
8988 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8989 +               free_dl_info(dli);
8990 +}
8991 +
8992 +
8993 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8994 +
8995 +static inline int __dl_alloc_space(struct super_block *sb,
8996 +       tag_t tag, dlsize_t nr, const char *file, int line)
8997 +{
8998 +       struct dl_info *dli = NULL;
8999 +       int ret = 0;
9000 +
9001 +       if (nr == 0)
9002 +               goto out;
9003 +       dli = locate_dl_info(sb, tag);
9004 +       if (!dli)
9005 +               goto out;
9006 +
9007 +       spin_lock(&dli->dl_lock);
9008 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9009 +       if (!ret)
9010 +               dli->dl_space_used += nr;
9011 +       spin_unlock(&dli->dl_lock);
9012 +       put_dl_info(dli);
9013 +out:
9014 +       vxlprintk(VXD_CBIT(dlim, 1),
9015 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9016 +               sb, tag, __dlimit_char(dli), (long long)nr,
9017 +               ret, file, line);
9018 +       return ret ? -ENOSPC : 0;
9019 +}
9020 +
9021 +static inline void __dl_free_space(struct super_block *sb,
9022 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9023 +{
9024 +       struct dl_info *dli = NULL;
9025 +
9026 +       if (nr == 0)
9027 +               goto out;
9028 +       dli = locate_dl_info(sb, tag);
9029 +       if (!dli)
9030 +               goto out;
9031 +
9032 +       spin_lock(&dli->dl_lock);
9033 +       if (dli->dl_space_used > nr)
9034 +               dli->dl_space_used -= nr;
9035 +       else
9036 +               dli->dl_space_used = 0;
9037 +       spin_unlock(&dli->dl_lock);
9038 +       put_dl_info(dli);
9039 +out:
9040 +       vxlprintk(VXD_CBIT(dlim, 1),
9041 +               "FREE  (%p,#%d)%c %lld bytes",
9042 +               sb, tag, __dlimit_char(dli), (long long)nr,
9043 +               _file, _line);
9044 +}
9045 +
9046 +static inline int __dl_alloc_inode(struct super_block *sb,
9047 +       tag_t tag, const char *_file, int _line)
9048 +{
9049 +       struct dl_info *dli;
9050 +       int ret = 0;
9051 +
9052 +       dli = locate_dl_info(sb, tag);
9053 +       if (!dli)
9054 +               goto out;
9055 +
9056 +       spin_lock(&dli->dl_lock);
9057 +       dli->dl_inodes_used++;
9058 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9059 +       spin_unlock(&dli->dl_lock);
9060 +       put_dl_info(dli);
9061 +out:
9062 +       vxlprintk(VXD_CBIT(dlim, 0),
9063 +               "ALLOC (%p,#%d)%c inode (%d)",
9064 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9065 +       return ret ? -ENOSPC : 0;
9066 +}
9067 +
9068 +static inline void __dl_free_inode(struct super_block *sb,
9069 +       tag_t tag, const char *_file, int _line)
9070 +{
9071 +       struct dl_info *dli;
9072 +
9073 +       dli = locate_dl_info(sb, tag);
9074 +       if (!dli)
9075 +               goto out;
9076 +
9077 +       spin_lock(&dli->dl_lock);
9078 +       if (dli->dl_inodes_used > 1)
9079 +               dli->dl_inodes_used--;
9080 +       else
9081 +               dli->dl_inodes_used = 0;
9082 +       spin_unlock(&dli->dl_lock);
9083 +       put_dl_info(dli);
9084 +out:
9085 +       vxlprintk(VXD_CBIT(dlim, 0),
9086 +               "FREE  (%p,#%d)%c inode",
9087 +               sb, tag, __dlimit_char(dli), _file, _line);
9088 +}
9089 +
9090 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9091 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9092 +       const char *_file, int _line)
9093 +{
9094 +       struct dl_info *dli;
9095 +       uint64_t broot, bfree;
9096 +
9097 +       dli = locate_dl_info(sb, tag);
9098 +       if (!dli)
9099 +               return;
9100 +
9101 +       spin_lock(&dli->dl_lock);
9102 +       broot = (dli->dl_space_total -
9103 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9104 +               >> sb->s_blocksize_bits;
9105 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9106 +                       >> sb->s_blocksize_bits;
9107 +       spin_unlock(&dli->dl_lock);
9108 +
9109 +       vxlprintk(VXD_CBIT(dlim, 2),
9110 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9111 +               (long long)bfree, (long long)broot,
9112 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9113 +               _file, _line);
9114 +       if (free_blocks) {
9115 +               if (*free_blocks > bfree)
9116 +                       *free_blocks = bfree;
9117 +       }
9118 +       if (root_blocks) {
9119 +               if (*root_blocks > broot)
9120 +                       *root_blocks = broot;
9121 +       }
9122 +       put_dl_info(dli);
9123 +}
9124 +
9125 +#define dl_prealloc_space(in, bytes) \
9126 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9127 +               __FILE__, __LINE__ )
9128 +
9129 +#define dl_alloc_space(in, bytes) \
9130 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9131 +               __FILE__, __LINE__ )
9132 +
9133 +#define dl_reserve_space(in, bytes) \
9134 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9135 +               __FILE__, __LINE__ )
9136 +
9137 +#define dl_claim_space(in, bytes) (0)
9138 +
9139 +#define dl_release_space(in, bytes) \
9140 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9141 +               __FILE__, __LINE__ )
9142 +
9143 +#define dl_free_space(in, bytes) \
9144 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9145 +               __FILE__, __LINE__ )
9146 +
9147 +
9148 +
9149 +#define dl_alloc_inode(in) \
9150 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9151 +
9152 +#define dl_free_inode(in) \
9153 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9154 +
9155 +
9156 +#define dl_adjust_block(sb, tag, fb, rb) \
9157 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9158 +
9159 +
9160 +#else
9161 +#warning duplicate inclusion
9162 +#endif
9163 diff -NurpP --minimal linux-3.7.1/include/linux/vs_inet.h linux-3.7.1-vs2.3.5.5/include/linux/vs_inet.h
9164 --- linux-3.7.1/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
9165 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_inet.h       2013-01-04 23:27:50.000000000 +0000
9166 @@ -0,0 +1,364 @@
9167 +#ifndef _VS_INET_H
9168 +#define _VS_INET_H
9169 +
9170 +#include "vserver/base.h"
9171 +#include "vserver/network.h"
9172 +#include "vserver/debug.h"
9173 +
9174 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9175 +
9176 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9177 +                       NIPQUAD((a)->mask), (a)->type
9178 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9179 +
9180 +#define NIPQUAD(addr) \
9181 +       ((unsigned char *)&addr)[0], \
9182 +       ((unsigned char *)&addr)[1], \
9183 +       ((unsigned char *)&addr)[2], \
9184 +       ((unsigned char *)&addr)[3]
9185 +
9186 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9187 +
9188 +
9189 +static inline
9190 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9191 +{
9192 +       __be32 ip = nxa->ip[0].s_addr;
9193 +       __be32 mask = nxa->mask.s_addr;
9194 +       __be32 bcast = ip | ~mask;
9195 +       int ret = 0;
9196 +
9197 +       switch (nxa->type & tmask) {
9198 +       case NXA_TYPE_MASK:
9199 +               ret = (ip == (addr & mask));
9200 +               break;
9201 +       case NXA_TYPE_ADDR:
9202 +               ret = 3;
9203 +               if (addr == ip)
9204 +                       break;
9205 +               /* fall through to broadcast */
9206 +       case NXA_MOD_BCAST:
9207 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9208 +               break;
9209 +       case NXA_TYPE_RANGE:
9210 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9211 +                       (nxa->ip[1].s_addr > addr));
9212 +               break;
9213 +       case NXA_TYPE_ANY:
9214 +               ret = 2;
9215 +               break;
9216 +       }
9217 +
9218 +       vxdprintk(VXD_CBIT(net, 0),
9219 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9220 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9221 +       return ret;
9222 +}
9223 +
9224 +static inline
9225 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9226 +{
9227 +       struct nx_addr_v4 *nxa;
9228 +       unsigned long irqflags;
9229 +       int ret = 1;
9230 +
9231 +       if (!nxi)
9232 +               goto out;
9233 +
9234 +       ret = 2;
9235 +       /* allow 127.0.0.1 when remapping lback */
9236 +       if ((tmask & NXA_LOOPBACK) &&
9237 +               (addr == IPI_LOOPBACK) &&
9238 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9239 +               goto out;
9240 +       ret = 3;
9241 +       /* check for lback address */
9242 +       if ((tmask & NXA_MOD_LBACK) &&
9243 +               (nxi->v4_lback.s_addr == addr))
9244 +               goto out;
9245 +       ret = 4;
9246 +       /* check for broadcast address */
9247 +       if ((tmask & NXA_MOD_BCAST) &&
9248 +               (nxi->v4_bcast.s_addr == addr))
9249 +               goto out;
9250 +       ret = 5;
9251 +
9252 +       /* check for v4 addresses */
9253 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9254 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9255 +               if (v4_addr_match(nxa, addr, tmask))
9256 +                       goto out_unlock;
9257 +       ret = 0;
9258 +out_unlock:
9259 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9260 +out:
9261 +       vxdprintk(VXD_CBIT(net, 0),
9262 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9263 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9264 +       return ret;
9265 +}
9266 +
9267 +static inline
9268 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9269 +{
9270 +       /* FIXME: needs full range checks */
9271 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9272 +}
9273 +
9274 +static inline
9275 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9276 +{
9277 +       struct nx_addr_v4 *ptr;
9278 +       unsigned long irqflags;
9279 +       int ret = 1;
9280 +
9281 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9282 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9283 +               if (v4_nx_addr_match(ptr, nxa, mask))
9284 +                       goto out_unlock;
9285 +       ret = 0;
9286 +out_unlock:
9287 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9288 +       return ret;
9289 +}
9290 +
9291 +#include <net/inet_sock.h>
9292 +
9293 +/*
9294 + *     Check if a given address matches for a socket
9295 + *
9296 + *     nxi:            the socket's nx_info if any
9297 + *     addr:           to be verified address
9298 + */
9299 +static inline
9300 +int v4_sock_addr_match (
9301 +       struct nx_info *nxi,
9302 +       struct inet_sock *inet,
9303 +       __be32 addr)
9304 +{
9305 +       __be32 saddr = inet->inet_rcv_saddr;
9306 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9307 +
9308 +       if (addr && (saddr == addr || bcast == addr))
9309 +               return 1;
9310 +       if (!saddr)
9311 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9312 +       return 0;
9313 +}
9314 +
9315 +
9316 +/* inet related checks and helpers */
9317 +
9318 +
9319 +struct in_ifaddr;
9320 +struct net_device;
9321 +struct sock;
9322 +
9323 +#ifdef CONFIG_INET
9324 +
9325 +#include <linux/netdevice.h>
9326 +#include <linux/inetdevice.h>
9327 +#include <net/inet_sock.h>
9328 +#include <net/inet_timewait_sock.h>
9329 +
9330 +
9331 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9332 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9333 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9334 +
9335 +
9336 +/*
9337 + *     check if address is covered by socket
9338 + *
9339 + *     sk:     the socket to check against
9340 + *     addr:   the address in question (must be != 0)
9341 + */
9342 +
9343 +static inline
9344 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9345 +{
9346 +       struct nx_info *nxi = sk->sk_nx_info;
9347 +       __be32 saddr = sk_rcv_saddr(sk);
9348 +
9349 +       vxdprintk(VXD_CBIT(net, 5),
9350 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9351 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9352 +               (sk->sk_socket?sk->sk_socket->flags:0));
9353 +
9354 +       if (saddr) {            /* direct address match */
9355 +               return v4_addr_match(nxa, saddr, -1);
9356 +       } else if (nxi) {       /* match against nx_info */
9357 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9358 +       } else {                /* unrestricted any socket */
9359 +               return 1;
9360 +       }
9361 +}
9362 +
9363 +
9364 +
9365 +static inline
9366 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9367 +{
9368 +       vxdprintk(VXD_CBIT(net, 1),
9369 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9370 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9371 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9372 +
9373 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9374 +               return 1;
9375 +       if (dev_in_nx_info(dev, nxi))
9376 +               return 1;
9377 +       return 0;
9378 +}
9379 +
9380 +
9381 +static inline
9382 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9383 +{
9384 +       if (!nxi)
9385 +               return 1;
9386 +       if (!ifa)
9387 +               return 0;
9388 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9389 +}
9390 +
9391 +static inline
9392 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9393 +{
9394 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9395 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9396 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9397 +
9398 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9399 +               return 1;
9400 +       if (v4_ifa_in_nx_info(ifa, nxi))
9401 +               return 1;
9402 +       return 0;
9403 +}
9404 +
9405 +
9406 +struct nx_v4_sock_addr {
9407 +       __be32 saddr;   /* Address used for validation */
9408 +       __be32 baddr;   /* Address used for socket bind */
9409 +};
9410 +
9411 +static inline
9412 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9413 +       struct nx_v4_sock_addr *nsa)
9414 +{
9415 +       struct sock *sk = &inet->sk;
9416 +       struct nx_info *nxi = sk->sk_nx_info;
9417 +       __be32 saddr = addr->sin_addr.s_addr;
9418 +       __be32 baddr = saddr;
9419 +
9420 +       vxdprintk(VXD_CBIT(net, 3),
9421 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9422 +               sk, sk->sk_nx_info, sk->sk_socket,
9423 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9424 +               NIPQUAD(saddr));
9425 +
9426 +       if (nxi) {
9427 +               if (saddr == INADDR_ANY) {
9428 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9429 +                               baddr = nxi->v4.ip[0].s_addr;
9430 +               } else if (saddr == IPI_LOOPBACK) {
9431 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9432 +                               baddr = nxi->v4_lback.s_addr;
9433 +               } else if (!ipv4_is_multicast(saddr) ||
9434 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9435 +                       /* normal address bind */
9436 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9437 +                               return -EADDRNOTAVAIL;
9438 +               }
9439 +       }
9440 +
9441 +       vxdprintk(VXD_CBIT(net, 3),
9442 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9443 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9444 +
9445 +       nsa->saddr = saddr;
9446 +       nsa->baddr = baddr;
9447 +       return 0;
9448 +}
9449 +
9450 +static inline
9451 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9452 +{
9453 +       inet->inet_saddr = nsa->baddr;
9454 +       inet->inet_rcv_saddr = nsa->baddr;
9455 +}
9456 +
9457 +
9458 +/*
9459 + *      helper to simplify inet_lookup_listener
9460 + *
9461 + *      nxi:   the socket's nx_info if any
9462 + *      addr:  to be verified address
9463 + *      saddr: socket address
9464 + */
9465 +static inline int v4_inet_addr_match (
9466 +       struct nx_info *nxi,
9467 +       __be32 addr,
9468 +       __be32 saddr)
9469 +{
9470 +       if (addr && (saddr == addr))
9471 +               return 1;
9472 +       if (!saddr)
9473 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9474 +       return 0;
9475 +}
9476 +
9477 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9478 +{
9479 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9480 +               (addr == nxi->v4_lback.s_addr))
9481 +               return IPI_LOOPBACK;
9482 +       return addr;
9483 +}
9484 +
9485 +static inline
9486 +int nx_info_has_v4(struct nx_info *nxi)
9487 +{
9488 +       if (!nxi)
9489 +               return 1;
9490 +       if (NX_IPV4(nxi))
9491 +               return 1;
9492 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9493 +               return 1;
9494 +       return 0;
9495 +}
9496 +
9497 +#else /* CONFIG_INET */
9498 +
9499 +static inline
9500 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9501 +{
9502 +       return 1;
9503 +}
9504 +
9505 +static inline
9506 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9507 +{
9508 +       return 1;
9509 +}
9510 +
9511 +static inline
9512 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9513 +{
9514 +       return 1;
9515 +}
9516 +
9517 +static inline
9518 +int nx_info_has_v4(struct nx_info *nxi)
9519 +{
9520 +       return 0;
9521 +}
9522 +
9523 +#endif /* CONFIG_INET */
9524 +
9525 +#define current_nx_info_has_v4() \
9526 +       nx_info_has_v4(current_nx_info())
9527 +
9528 +#else
9529 +// #warning duplicate inclusion
9530 +#endif
9531 diff -NurpP --minimal linux-3.7.1/include/linux/vs_inet6.h linux-3.7.1-vs2.3.5.5/include/linux/vs_inet6.h
9532 --- linux-3.7.1/include/linux/vs_inet6.h        1970-01-01 00:00:00.000000000 +0000
9533 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_inet6.h      2013-01-04 23:27:50.000000000 +0000
9534 @@ -0,0 +1,257 @@
9535 +#ifndef _VS_INET6_H
9536 +#define _VS_INET6_H
9537 +
9538 +#include "vserver/base.h"
9539 +#include "vserver/network.h"
9540 +#include "vserver/debug.h"
9541 +
9542 +#include <net/ipv6.h>
9543 +
9544 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9545 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9546 +
9547 +
9548 +#ifdef CONFIG_IPV6
9549 +
9550 +static inline
9551 +int v6_addr_match(struct nx_addr_v6 *nxa,
9552 +       const struct in6_addr *addr, uint16_t mask)
9553 +{
9554 +       int ret = 0;
9555 +
9556 +       switch (nxa->type & mask) {
9557 +       case NXA_TYPE_MASK:
9558 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9559 +               break;
9560 +       case NXA_TYPE_ADDR:
9561 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9562 +               break;
9563 +       case NXA_TYPE_ANY:
9564 +               ret = 1;
9565 +               break;
9566 +       }
9567 +       vxdprintk(VXD_CBIT(net, 0),
9568 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9569 +               nxa, NXAV6(nxa), addr, mask, ret);
9570 +       return ret;
9571 +}
9572 +
9573 +static inline
9574 +int v6_addr_in_nx_info(struct nx_info *nxi,
9575 +       const struct in6_addr *addr, uint16_t mask)
9576 +{
9577 +       struct nx_addr_v6 *nxa;
9578 +       unsigned long irqflags;
9579 +       int ret = 1;
9580 +
9581 +       if (!nxi)
9582 +               goto out;
9583 +
9584 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9585 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9586 +               if (v6_addr_match(nxa, addr, mask))
9587 +                       goto out_unlock;
9588 +       ret = 0;
9589 +out_unlock:
9590 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9591 +out:
9592 +       vxdprintk(VXD_CBIT(net, 0),
9593 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9594 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9595 +       return ret;
9596 +}
9597 +
9598 +static inline
9599 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9600 +{
9601 +       /* FIXME: needs full range checks */
9602 +       return v6_addr_match(nxa, &addr->ip, mask);
9603 +}
9604 +
9605 +static inline
9606 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9607 +{
9608 +       struct nx_addr_v6 *ptr;
9609 +       unsigned long irqflags;
9610 +       int ret = 1;
9611 +
9612 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9613 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9614 +               if (v6_nx_addr_match(ptr, nxa, mask))
9615 +                       goto out_unlock;
9616 +       ret = 0;
9617 +out_unlock:
9618 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9619 +       return ret;
9620 +}
9621 +
9622 +
9623 +/*
9624 + *     Check if a given address matches for a socket
9625 + *
9626 + *     nxi:            the socket's nx_info if any
9627 + *     addr:           to be verified address
9628 + */
9629 +static inline
9630 +int v6_sock_addr_match (
9631 +       struct nx_info *nxi,
9632 +       struct inet_sock *inet,
9633 +       struct in6_addr *addr)
9634 +{
9635 +       struct sock *sk = &inet->sk;
9636 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9637 +
9638 +       if (!ipv6_addr_any(addr) &&
9639 +               ipv6_addr_equal(saddr, addr))
9640 +               return 1;
9641 +       if (ipv6_addr_any(saddr))
9642 +               return v6_addr_in_nx_info(nxi, addr, -1);
9643 +       return 0;
9644 +}
9645 +
9646 +/*
9647 + *     check if address is covered by socket
9648 + *
9649 + *     sk:     the socket to check against
9650 + *     addr:   the address in question (must be != 0)
9651 + */
9652 +
9653 +static inline
9654 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9655 +{
9656 +       struct nx_info *nxi = sk->sk_nx_info;
9657 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9658 +
9659 +       vxdprintk(VXD_CBIT(net, 5),
9660 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9661 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9662 +               (sk->sk_socket?sk->sk_socket->flags:0));
9663 +
9664 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9665 +               return v6_addr_match(nxa, saddr, -1);
9666 +       } else if (nxi) {               /* match against nx_info */
9667 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9668 +       } else {                        /* unrestricted any socket */
9669 +               return 1;
9670 +       }
9671 +}
9672 +
9673 +
9674 +/* inet related checks and helpers */
9675 +
9676 +
9677 +struct in_ifaddr;
9678 +struct net_device;
9679 +struct sock;
9680 +
9681 +
9682 +#include <linux/netdevice.h>
9683 +#include <linux/inetdevice.h>
9684 +#include <net/inet_timewait_sock.h>
9685 +
9686 +
9687 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9688 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9689 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9690 +
9691 +
9692 +
9693 +static inline
9694 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9695 +{
9696 +       if (!nxi)
9697 +               return 1;
9698 +       if (!ifa)
9699 +               return 0;
9700 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9701 +}
9702 +
9703 +static inline
9704 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9705 +{
9706 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9707 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9708 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9709 +
9710 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9711 +               return 1;
9712 +       if (v6_ifa_in_nx_info(ifa, nxi))
9713 +               return 1;
9714 +       return 0;
9715 +}
9716 +
9717 +
9718 +struct nx_v6_sock_addr {
9719 +       struct in6_addr saddr;  /* Address used for validation */
9720 +       struct in6_addr baddr;  /* Address used for socket bind */
9721 +};
9722 +
9723 +static inline
9724 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9725 +       struct nx_v6_sock_addr *nsa)
9726 +{
9727 +       // struct sock *sk = &inet->sk;
9728 +       // struct nx_info *nxi = sk->sk_nx_info;
9729 +       struct in6_addr saddr = addr->sin6_addr;
9730 +       struct in6_addr baddr = saddr;
9731 +
9732 +       nsa->saddr = saddr;
9733 +       nsa->baddr = baddr;
9734 +       return 0;
9735 +}
9736 +
9737 +static inline
9738 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9739 +{
9740 +       // struct sock *sk = &inet->sk;
9741 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9742 +
9743 +       // *saddr = nsa->baddr;
9744 +       // inet->inet_saddr = nsa->baddr;
9745 +}
9746 +
9747 +static inline
9748 +int nx_info_has_v6(struct nx_info *nxi)
9749 +{
9750 +       if (!nxi)
9751 +               return 1;
9752 +       if (NX_IPV6(nxi))
9753 +               return 1;
9754 +       return 0;
9755 +}
9756 +
9757 +#else /* CONFIG_IPV6 */
9758 +
9759 +static inline
9760 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9761 +{
9762 +       return 1;
9763 +}
9764 +
9765 +
9766 +static inline
9767 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9768 +{
9769 +       return 1;
9770 +}
9771 +
9772 +static inline
9773 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9774 +{
9775 +       return 1;
9776 +}
9777 +
9778 +static inline
9779 +int nx_info_has_v6(struct nx_info *nxi)
9780 +{
9781 +       return 0;
9782 +}
9783 +
9784 +#endif /* CONFIG_IPV6 */
9785 +
9786 +#define current_nx_info_has_v6() \
9787 +       nx_info_has_v6(current_nx_info())
9788 +
9789 +#else
9790 +#warning duplicate inclusion
9791 +#endif
9792 diff -NurpP --minimal linux-3.7.1/include/linux/vs_limit.h linux-3.7.1-vs2.3.5.5/include/linux/vs_limit.h
9793 --- linux-3.7.1/include/linux/vs_limit.h        1970-01-01 00:00:00.000000000 +0000
9794 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_limit.h      2012-12-18 15:13:16.000000000 +0000
9795 @@ -0,0 +1,140 @@
9796 +#ifndef _VS_LIMIT_H
9797 +#define _VS_LIMIT_H
9798 +
9799 +#include "vserver/limit.h"
9800 +#include "vserver/base.h"
9801 +#include "vserver/context.h"
9802 +#include "vserver/debug.h"
9803 +#include "vserver/context.h"
9804 +#include "vserver/limit_int.h"
9805 +
9806 +
9807 +#define vx_acc_cres(v, d, p, r) \
9808 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9809 +
9810 +#define vx_acc_cres_cond(x, d, p, r) \
9811 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9812 +       r, d, p, __FILE__, __LINE__)
9813 +
9814 +
9815 +#define vx_add_cres(v, a, p, r) \
9816 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9817 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9818 +
9819 +#define vx_add_cres_cond(x, a, p, r) \
9820 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9821 +       r, a, p, __FILE__, __LINE__)
9822 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9823 +
9824 +
9825 +/* process and file limits */
9826 +
9827 +#define vx_nproc_inc(p) \
9828 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9829 +
9830 +#define vx_nproc_dec(p) \
9831 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9832 +
9833 +#define vx_files_inc(f) \
9834 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9835 +
9836 +#define vx_files_dec(f) \
9837 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9838 +
9839 +#define vx_locks_inc(l) \
9840 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9841 +
9842 +#define vx_locks_dec(l) \
9843 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9844 +
9845 +#define vx_openfd_inc(f) \
9846 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9847 +
9848 +#define vx_openfd_dec(f) \
9849 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9850 +
9851 +
9852 +#define vx_cres_avail(v, n, r) \
9853 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9854 +
9855 +
9856 +#define vx_nproc_avail(n) \
9857 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9858 +
9859 +#define vx_files_avail(n) \
9860 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9861 +
9862 +#define vx_locks_avail(n) \
9863 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9864 +
9865 +#define vx_openfd_avail(n) \
9866 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9867 +
9868 +
9869 +/* dentry limits */
9870 +
9871 +#define vx_dentry_inc(d) do {                                          \
9872 +       if ((d)->d_count == 1)                                          \
9873 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9874 +       } while (0)
9875 +
9876 +#define vx_dentry_dec(d) do {                                          \
9877 +       if ((d)->d_count == 0)                                          \
9878 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9879 +       } while (0)
9880 +
9881 +#define vx_dentry_avail(n) \
9882 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9883 +
9884 +
9885 +/* socket limits */
9886 +
9887 +#define vx_sock_inc(s) \
9888 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9889 +
9890 +#define vx_sock_dec(s) \
9891 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9892 +
9893 +#define vx_sock_avail(n) \
9894 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9895 +
9896 +
9897 +/* ipc resource limits */
9898 +
9899 +#define vx_ipcmsg_add(v, u, a) \
9900 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9901 +
9902 +#define vx_ipcmsg_sub(v, u, a) \
9903 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9904 +
9905 +#define vx_ipcmsg_avail(v, a) \
9906 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9907 +
9908 +
9909 +#define vx_ipcshm_add(v, k, a) \
9910 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9911 +
9912 +#define vx_ipcshm_sub(v, k, a) \
9913 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9914 +
9915 +#define vx_ipcshm_avail(v, a) \
9916 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9917 +
9918 +
9919 +#define vx_semary_inc(a) \
9920 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9921 +
9922 +#define vx_semary_dec(a) \
9923 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9924 +
9925 +
9926 +#define vx_nsems_add(a,n) \
9927 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9928 +
9929 +#define vx_nsems_sub(a,n) \
9930 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9931 +
9932 +
9933 +#else
9934 +#warning duplicate inclusion
9935 +#endif
9936 diff -NurpP --minimal linux-3.7.1/include/linux/vs_network.h linux-3.7.1-vs2.3.5.5/include/linux/vs_network.h
9937 --- linux-3.7.1/include/linux/vs_network.h      1970-01-01 00:00:00.000000000 +0000
9938 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_network.h    2012-12-18 15:13:16.000000000 +0000
9939 @@ -0,0 +1,169 @@
9940 +#ifndef _NX_VS_NETWORK_H
9941 +#define _NX_VS_NETWORK_H
9942 +
9943 +#include "vserver/context.h"
9944 +#include "vserver/network.h"
9945 +#include "vserver/base.h"
9946 +#include "vserver/check.h"
9947 +#include "vserver/debug.h"
9948 +
9949 +#include <linux/sched.h>
9950 +
9951 +
9952 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9953 +
9954 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9955 +       const char *_file, int _line)
9956 +{
9957 +       if (!nxi)
9958 +               return NULL;
9959 +
9960 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9961 +               nxi, nxi ? nxi->nx_id : 0,
9962 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9963 +               _file, _line);
9964 +
9965 +       atomic_inc(&nxi->nx_usecnt);
9966 +       return nxi;
9967 +}
9968 +
9969 +
9970 +extern void free_nx_info(struct nx_info *);
9971 +
9972 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9973 +
9974 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9975 +{
9976 +       if (!nxi)
9977 +               return;
9978 +
9979 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9980 +               nxi, nxi ? nxi->nx_id : 0,
9981 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9982 +               _file, _line);
9983 +
9984 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9985 +               free_nx_info(nxi);
9986 +}
9987 +
9988 +
9989 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9990 +
9991 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9992 +               const char *_file, int _line)
9993 +{
9994 +       if (nxi) {
9995 +               vxlprintk(VXD_CBIT(nid, 3),
9996 +                       "init_nx_info(%p[#%d.%d])",
9997 +                       nxi, nxi ? nxi->nx_id : 0,
9998 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9999 +                       _file, _line);
10000 +
10001 +               atomic_inc(&nxi->nx_usecnt);
10002 +       }
10003 +       *nxp = nxi;
10004 +}
10005 +
10006 +
10007 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10008 +
10009 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10010 +       const char *_file, int _line)
10011 +{
10012 +       struct nx_info *nxo;
10013 +
10014 +       if (!nxi)
10015 +               return;
10016 +
10017 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10018 +               nxi, nxi ? nxi->nx_id : 0,
10019 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10020 +               _file, _line);
10021 +
10022 +       atomic_inc(&nxi->nx_usecnt);
10023 +       nxo = xchg(nxp, nxi);
10024 +       BUG_ON(nxo);
10025 +}
10026 +
10027 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10028 +
10029 +static inline void __clr_nx_info(struct nx_info **nxp,
10030 +       const char *_file, int _line)
10031 +{
10032 +       struct nx_info *nxo;
10033 +
10034 +       nxo = xchg(nxp, NULL);
10035 +       if (!nxo)
10036 +               return;
10037 +
10038 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10039 +               nxo, nxo ? nxo->nx_id : 0,
10040 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10041 +               _file, _line);
10042 +
10043 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10044 +               free_nx_info(nxo);
10045 +}
10046 +
10047 +
10048 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10049 +
10050 +static inline void __claim_nx_info(struct nx_info *nxi,
10051 +       struct task_struct *task, const char *_file, int _line)
10052 +{
10053 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10054 +               nxi, nxi ? nxi->nx_id : 0,
10055 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10056 +               nxi?atomic_read(&nxi->nx_tasks):0,
10057 +               task, _file, _line);
10058 +
10059 +       atomic_inc(&nxi->nx_tasks);
10060 +}
10061 +
10062 +
10063 +extern void unhash_nx_info(struct nx_info *);
10064 +
10065 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10066 +
10067 +static inline void __release_nx_info(struct nx_info *nxi,
10068 +       struct task_struct *task, const char *_file, int _line)
10069 +{
10070 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10071 +               nxi, nxi ? nxi->nx_id : 0,
10072 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10073 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10074 +               task, _file, _line);
10075 +
10076 +       might_sleep();
10077 +
10078 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10079 +               unhash_nx_info(nxi);
10080 +}
10081 +
10082 +
10083 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10084 +
10085 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10086 +       const char *_file, int _line)
10087 +{
10088 +       struct nx_info *nxi;
10089 +
10090 +       task_lock(p);
10091 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10092 +               p, _file, _line);
10093 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10094 +       task_unlock(p);
10095 +       return nxi;
10096 +}
10097 +
10098 +
10099 +static inline void exit_nx_info(struct task_struct *p)
10100 +{
10101 +       if (p->nx_info)
10102 +               release_nx_info(p->nx_info, p);
10103 +}
10104 +
10105 +
10106 +#else
10107 +#warning duplicate inclusion
10108 +#endif
10109 diff -NurpP --minimal linux-3.7.1/include/linux/vs_pid.h linux-3.7.1-vs2.3.5.5/include/linux/vs_pid.h
10110 --- linux-3.7.1/include/linux/vs_pid.h  1970-01-01 00:00:00.000000000 +0000
10111 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_pid.h        2012-12-18 15:13:16.000000000 +0000
10112 @@ -0,0 +1,50 @@
10113 +#ifndef _VS_PID_H
10114 +#define _VS_PID_H
10115 +
10116 +#include "vserver/base.h"
10117 +#include "vserver/check.h"
10118 +#include "vserver/context.h"
10119 +#include "vserver/debug.h"
10120 +#include "vserver/pid.h"
10121 +#include <linux/pid_namespace.h>
10122 +
10123 +
10124 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10125 +
10126 +static inline
10127 +int vx_proc_task_visible(struct task_struct *task)
10128 +{
10129 +       if ((task->pid == 1) &&
10130 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10131 +               /* show a blend through init */
10132 +               goto visible;
10133 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10134 +               goto visible;
10135 +       return 0;
10136 +visible:
10137 +       return 1;
10138 +}
10139 +
10140 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10141 +
10142 +
10143 +static inline
10144 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10145 +{
10146 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10147 +
10148 +       if (task && !vx_proc_task_visible(task)) {
10149 +               vxdprintk(VXD_CBIT(misc, 6),
10150 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10151 +                       task, task->xid, task->pid,
10152 +                       current, current->xid, current->pid);
10153 +               put_task_struct(task);
10154 +               task = NULL;
10155 +       }
10156 +       return task;
10157 +}
10158 +
10159 +
10160 +#else
10161 +#warning duplicate inclusion
10162 +#endif
10163 diff -NurpP --minimal linux-3.7.1/include/linux/vs_sched.h linux-3.7.1-vs2.3.5.5/include/linux/vs_sched.h
10164 --- linux-3.7.1/include/linux/vs_sched.h        1970-01-01 00:00:00.000000000 +0000
10165 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_sched.h      2012-12-18 15:13:16.000000000 +0000
10166 @@ -0,0 +1,40 @@
10167 +#ifndef _VS_SCHED_H
10168 +#define _VS_SCHED_H
10169 +
10170 +#include "vserver/base.h"
10171 +#include "vserver/context.h"
10172 +#include "vserver/sched.h"
10173 +
10174 +
10175 +#define MAX_PRIO_BIAS           20
10176 +#define MIN_PRIO_BIAS          -20
10177 +
10178 +static inline
10179 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10180 +{
10181 +       struct vx_info *vxi = p->vx_info;
10182 +
10183 +       if (vxi)
10184 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10185 +       return prio;
10186 +}
10187 +
10188 +static inline void vx_account_user(struct vx_info *vxi,
10189 +       cputime_t cputime, int nice)
10190 +{
10191 +       if (!vxi)
10192 +               return;
10193 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10194 +}
10195 +
10196 +static inline void vx_account_system(struct vx_info *vxi,
10197 +       cputime_t cputime, int idle)
10198 +{
10199 +       if (!vxi)
10200 +               return;
10201 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10202 +}
10203 +
10204 +#else
10205 +#warning duplicate inclusion
10206 +#endif
10207 diff -NurpP --minimal linux-3.7.1/include/linux/vs_socket.h linux-3.7.1-vs2.3.5.5/include/linux/vs_socket.h
10208 --- linux-3.7.1/include/linux/vs_socket.h       1970-01-01 00:00:00.000000000 +0000
10209 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_socket.h     2012-12-18 15:13:16.000000000 +0000
10210 @@ -0,0 +1,67 @@
10211 +#ifndef _VS_SOCKET_H
10212 +#define _VS_SOCKET_H
10213 +
10214 +#include "vserver/debug.h"
10215 +#include "vserver/base.h"
10216 +#include "vserver/cacct.h"
10217 +#include "vserver/context.h"
10218 +#include "vserver/tag.h"
10219 +
10220 +
10221 +/* socket accounting */
10222 +
10223 +#include <linux/socket.h>
10224 +
10225 +static inline int vx_sock_type(int family)
10226 +{
10227 +       switch (family) {
10228 +       case PF_UNSPEC:
10229 +               return VXA_SOCK_UNSPEC;
10230 +       case PF_UNIX:
10231 +               return VXA_SOCK_UNIX;
10232 +       case PF_INET:
10233 +               return VXA_SOCK_INET;
10234 +       case PF_INET6:
10235 +               return VXA_SOCK_INET6;
10236 +       case PF_PACKET:
10237 +               return VXA_SOCK_PACKET;
10238 +       default:
10239 +               return VXA_SOCK_OTHER;
10240 +       }
10241 +}
10242 +
10243 +#define vx_acc_sock(v, f, p, s) \
10244 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10245 +
10246 +static inline void __vx_acc_sock(struct vx_info *vxi,
10247 +       int family, int pos, int size, char *file, int line)
10248 +{
10249 +       if (vxi) {
10250 +               int type = vx_sock_type(family);
10251 +
10252 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10253 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10254 +       }
10255 +}
10256 +
10257 +#define vx_sock_recv(sk, s) \
10258 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10259 +#define vx_sock_send(sk, s) \
10260 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10261 +#define vx_sock_fail(sk, s) \
10262 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10263 +
10264 +
10265 +#define sock_vx_init(s) do {           \
10266 +       (s)->sk_xid = 0;                \
10267 +       (s)->sk_vx_info = NULL;         \
10268 +       } while (0)
10269 +
10270 +#define sock_nx_init(s) do {           \
10271 +       (s)->sk_nid = 0;                \
10272 +       (s)->sk_nx_info = NULL;         \
10273 +       } while (0)
10274 +
10275 +#else
10276 +#warning duplicate inclusion
10277 +#endif
10278 diff -NurpP --minimal linux-3.7.1/include/linux/vs_tag.h linux-3.7.1-vs2.3.5.5/include/linux/vs_tag.h
10279 --- linux-3.7.1/include/linux/vs_tag.h  1970-01-01 00:00:00.000000000 +0000
10280 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_tag.h        2012-12-18 15:13:16.000000000 +0000
10281 @@ -0,0 +1,47 @@
10282 +#ifndef _VS_TAG_H
10283 +#define _VS_TAG_H
10284 +
10285 +#include <linux/vserver/tag.h>
10286 +
10287 +/* check conditions */
10288 +
10289 +#define DX_ADMIN       0x0001
10290 +#define DX_WATCH       0x0002
10291 +#define DX_HOSTID      0x0008
10292 +
10293 +#define DX_IDENT       0x0010
10294 +
10295 +#define DX_ARG_MASK    0x0010
10296 +
10297 +
10298 +#define dx_task_tag(t) ((t)->tag)
10299 +
10300 +#define dx_current_tag() dx_task_tag(current)
10301 +
10302 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10303 +
10304 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10305 +
10306 +
10307 +/*
10308 + * check current context for ADMIN/WATCH and
10309 + * optionally against supplied argument
10310 + */
10311 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10312 +{
10313 +       if (mode & DX_ARG_MASK) {
10314 +               if ((mode & DX_IDENT) && (id == cid))
10315 +                       return 1;
10316 +       }
10317 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10318 +               ((mode & DX_WATCH) && (cid == 1)) ||
10319 +               ((mode & DX_HOSTID) && (id == 0)));
10320 +}
10321 +
10322 +struct inode;
10323 +int dx_permission(const struct inode *inode, int mask);
10324 +
10325 +
10326 +#else
10327 +#warning duplicate inclusion
10328 +#endif
10329 diff -NurpP --minimal linux-3.7.1/include/linux/vs_time.h linux-3.7.1-vs2.3.5.5/include/linux/vs_time.h
10330 --- linux-3.7.1/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10331 +++ linux-3.7.1-vs2.3.5.5/include/linux/vs_time.h       2012-12-18 15:13:16.000000000 +0000
10332 @@ -0,0 +1,19 @@
10333 +#ifndef _VS_TIME_H
10334 +#define _VS_TIME_H
10335 +
10336 +
10337 +/* time faking stuff */
10338 +
10339 +#ifdef CONFIG_VSERVER_VTIME
10340 +
10341 +extern void vx_adjust_timespec(struct timespec *ts);
10342 +extern int vx_settimeofday(const struct timespec *ts);
10343 +
10344 +#else
10345 +#define        vx_adjust_timespec(t)   do { } while (0)
10346 +#define        vx_settimeofday(t)      do_settimeofday(t)
10347 +#endif
10348 +
10349 +#else
10350 +#warning duplicate inclusion
10351 +#endif
10352 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/base.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/base.h
10353 --- linux-3.7.1/include/linux/vserver/base.h    1970-01-01 00:00:00.000000000 +0000
10354 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/base.h  2012-12-18 15:13:16.000000000 +0000
10355 @@ -0,0 +1,178 @@
10356 +#ifndef _VSERVER_BASE_H
10357 +#define _VSERVER_BASE_H
10358 +
10359 +
10360 +/* context state changes */
10361 +
10362 +enum {
10363 +       VSC_STARTUP = 1,
10364 +       VSC_SHUTDOWN,
10365 +
10366 +       VSC_NETUP,
10367 +       VSC_NETDOWN,
10368 +};
10369 +
10370 +
10371 +
10372 +#define vx_task_xid(t) ((t)->xid)
10373 +
10374 +#define vx_current_xid() vx_task_xid(current)
10375 +
10376 +#define current_vx_info() (current->vx_info)
10377 +
10378 +
10379 +#define nx_task_nid(t) ((t)->nid)
10380 +
10381 +#define nx_current_nid() nx_task_nid(current)
10382 +
10383 +#define current_nx_info() (current->nx_info)
10384 +
10385 +
10386 +/* generic flag merging */
10387 +
10388 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10389 +
10390 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10391 +
10392 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10393 +
10394 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10395 +
10396 +
10397 +/* context flags */
10398 +
10399 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10400 +
10401 +#define vx_current_flags()     __vx_flags(current_vx_info())
10402 +
10403 +#define vx_info_flags(v, m, f) \
10404 +       vs_check_flags(__vx_flags(v), m, f)
10405 +
10406 +#define task_vx_flags(t, m, f) \
10407 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10408 +
10409 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10410 +
10411 +
10412 +/* context caps */
10413 +
10414 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10415 +
10416 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10417 +
10418 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10419 +
10420 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10421 +
10422 +
10423 +
10424 +/* network flags */
10425 +
10426 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10427 +
10428 +#define nx_current_flags()     __nx_flags(current_nx_info())
10429 +
10430 +#define nx_info_flags(n, m, f) \
10431 +       vs_check_flags(__nx_flags(n), m, f)
10432 +
10433 +#define task_nx_flags(t, m, f) \
10434 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10435 +
10436 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10437 +
10438 +
10439 +/* network caps */
10440 +
10441 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10442 +
10443 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10444 +
10445 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10446 +
10447 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10448 +
10449 +
10450 +/* context mask capabilities */
10451 +
10452 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10453 +
10454 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10455 +
10456 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10457 +
10458 +
10459 +/* context bcap mask */
10460 +
10461 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10462 +
10463 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10464 +
10465 +
10466 +/* mask given bcaps */
10467 +
10468 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10469 +
10470 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10471 +
10472 +
10473 +/* masked cap_bset */
10474 +
10475 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10476 +
10477 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10478 +
10479 +#if 0
10480 +#define vx_info_mbcap(v, b) \
10481 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10482 +       vx_info_bcaps(v, b) : (b))
10483 +
10484 +#define task_vx_mbcap(t, b) \
10485 +       vx_info_mbcap((t)->vx_info, (t)->b)
10486 +
10487 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10488 +#endif
10489 +
10490 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10491 +
10492 +#define vx_capable(b, c) (capable(b) || \
10493 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10494 +
10495 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10496 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10497 +
10498 +#define nx_capable(b, c) (capable(b) || \
10499 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10500 +
10501 +#define vx_task_initpid(t, n) \
10502 +       ((t)->vx_info && \
10503 +       ((t)->vx_info->vx_initpid == (n)))
10504 +
10505 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10506 +
10507 +
10508 +/* context unshare mask */
10509 +
10510 +#define __vx_umask(v)          ((v)->vx_umask)
10511 +
10512 +#define vx_current_umask()     __vx_umask(current_vx_info())
10513 +
10514 +#define vx_can_unshare(b, f) (capable(b) || \
10515 +       (cap_raised(current_cap(), b) && \
10516 +       !((f) & ~vx_current_umask())))
10517 +
10518 +
10519 +#define __vx_wmask(v)          ((v)->vx_wmask)
10520 +
10521 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10522 +
10523 +
10524 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10525 +
10526 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10527 +
10528 +
10529 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10530 +
10531 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10532 +
10533 +#endif
10534 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/cacct.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/cacct.h
10535 --- linux-3.7.1/include/linux/vserver/cacct.h   1970-01-01 00:00:00.000000000 +0000
10536 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/cacct.h 2012-12-18 15:13:16.000000000 +0000
10537 @@ -0,0 +1,15 @@
10538 +#ifndef _VSERVER_CACCT_H
10539 +#define _VSERVER_CACCT_H
10540 +
10541 +
10542 +enum sock_acc_field {
10543 +       VXA_SOCK_UNSPEC = 0,
10544 +       VXA_SOCK_UNIX,
10545 +       VXA_SOCK_INET,
10546 +       VXA_SOCK_INET6,
10547 +       VXA_SOCK_PACKET,
10548 +       VXA_SOCK_OTHER,
10549 +       VXA_SOCK_SIZE   /* array size */
10550 +};
10551 +
10552 +#endif /* _VSERVER_CACCT_H */
10553 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/cacct_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/cacct_cmd.h
10554 --- linux-3.7.1/include/linux/vserver/cacct_cmd.h       1970-01-01 00:00:00.000000000 +0000
10555 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/cacct_cmd.h     2012-12-18 15:13:16.000000000 +0000
10556 @@ -0,0 +1,10 @@
10557 +#ifndef _VSERVER_CACCT_CMD_H
10558 +#define _VSERVER_CACCT_CMD_H
10559 +
10560 +
10561 +#include <linux/compiler.h>
10562 +#include <uapi/vserver/cacct_cmd.h>
10563 +
10564 +extern int vc_sock_stat(struct vx_info *, void __user *);
10565 +
10566 +#endif /* _VSERVER_CACCT_CMD_H */
10567 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/cacct_def.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/cacct_def.h
10568 --- linux-3.7.1/include/linux/vserver/cacct_def.h       1970-01-01 00:00:00.000000000 +0000
10569 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/cacct_def.h     2012-12-18 15:13:16.000000000 +0000
10570 @@ -0,0 +1,43 @@
10571 +#ifndef _VSERVER_CACCT_DEF_H
10572 +#define _VSERVER_CACCT_DEF_H
10573 +
10574 +#include <asm/atomic.h>
10575 +#include <linux/vserver/cacct.h>
10576 +
10577 +
10578 +struct _vx_sock_acc {
10579 +       atomic_long_t count;
10580 +       atomic_long_t total;
10581 +};
10582 +
10583 +/* context sub struct */
10584 +
10585 +struct _vx_cacct {
10586 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10587 +       atomic_t slab[8];
10588 +       atomic_t page[6][8];
10589 +};
10590 +
10591 +#ifdef CONFIG_VSERVER_DEBUG
10592 +
10593 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10594 +{
10595 +       int i, j;
10596 +
10597 +       printk("\t_vx_cacct:");
10598 +       for (i = 0; i < 6; i++) {
10599 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10600 +
10601 +               printk("\t [%d] =", i);
10602 +               for (j = 0; j < 3; j++) {
10603 +                       printk(" [%d] = %8lu, %8lu", j,
10604 +                               atomic_long_read(&ptr[j].count),
10605 +                               atomic_long_read(&ptr[j].total));
10606 +               }
10607 +               printk("\n");
10608 +       }
10609 +}
10610 +
10611 +#endif
10612 +
10613 +#endif /* _VSERVER_CACCT_DEF_H */
10614 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/cacct_int.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/cacct_int.h
10615 --- linux-3.7.1/include/linux/vserver/cacct_int.h       1970-01-01 00:00:00.000000000 +0000
10616 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/cacct_int.h     2012-12-18 15:13:16.000000000 +0000
10617 @@ -0,0 +1,17 @@
10618 +#ifndef _VSERVER_CACCT_INT_H
10619 +#define _VSERVER_CACCT_INT_H
10620 +
10621 +static inline
10622 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10623 +{
10624 +       return atomic_long_read(&cacct->sock[type][pos].count);
10625 +}
10626 +
10627 +
10628 +static inline
10629 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10630 +{
10631 +       return atomic_long_read(&cacct->sock[type][pos].total);
10632 +}
10633 +
10634 +#endif /* _VSERVER_CACCT_INT_H */
10635 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/check.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/check.h
10636 --- linux-3.7.1/include/linux/vserver/check.h   1970-01-01 00:00:00.000000000 +0000
10637 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/check.h 2012-12-18 15:13:16.000000000 +0000
10638 @@ -0,0 +1,89 @@
10639 +#ifndef _VSERVER_CHECK_H
10640 +#define _VSERVER_CHECK_H
10641 +
10642 +
10643 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10644 +
10645 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10646 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10647 +#else
10648 +#define MIN_D_CONTEXT  65536
10649 +#endif
10650 +
10651 +/* check conditions */
10652 +
10653 +#define VS_ADMIN       0x0001
10654 +#define VS_WATCH       0x0002
10655 +#define VS_HIDE                0x0004
10656 +#define VS_HOSTID      0x0008
10657 +
10658 +#define VS_IDENT       0x0010
10659 +#define VS_EQUIV       0x0020
10660 +#define VS_PARENT      0x0040
10661 +#define VS_CHILD       0x0080
10662 +
10663 +#define VS_ARG_MASK    0x00F0
10664 +
10665 +#define VS_DYNAMIC     0x0100
10666 +#define VS_STATIC      0x0200
10667 +
10668 +#define VS_ATR_MASK    0x0F00
10669 +
10670 +#ifdef CONFIG_VSERVER_PRIVACY
10671 +#define VS_ADMIN_P     (0)
10672 +#define VS_WATCH_P     (0)
10673 +#else
10674 +#define VS_ADMIN_P     VS_ADMIN
10675 +#define VS_WATCH_P     VS_WATCH
10676 +#endif
10677 +
10678 +#define VS_HARDIRQ     0x1000
10679 +#define VS_SOFTIRQ     0x2000
10680 +#define VS_IRQ         0x4000
10681 +
10682 +#define VS_IRQ_MASK    0xF000
10683 +
10684 +#include <linux/hardirq.h>
10685 +
10686 +/*
10687 + * check current context for ADMIN/WATCH and
10688 + * optionally against supplied argument
10689 + */
10690 +static inline int __vs_check(int cid, int id, unsigned int mode)
10691 +{
10692 +       if (mode & VS_ARG_MASK) {
10693 +               if ((mode & VS_IDENT) && (id == cid))
10694 +                       return 1;
10695 +       }
10696 +       if (mode & VS_ATR_MASK) {
10697 +               if ((mode & VS_DYNAMIC) &&
10698 +                       (id >= MIN_D_CONTEXT) &&
10699 +                       (id <= MAX_S_CONTEXT))
10700 +                       return 1;
10701 +               if ((mode & VS_STATIC) &&
10702 +                       (id > 1) && (id < MIN_D_CONTEXT))
10703 +                       return 1;
10704 +       }
10705 +       if (mode & VS_IRQ_MASK) {
10706 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10707 +                       return 1;
10708 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10709 +                       return 1;
10710 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10711 +                       return 1;
10712 +       }
10713 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10714 +               ((mode & VS_WATCH) && (cid == 1)) ||
10715 +               ((mode & VS_HOSTID) && (id == 0)));
10716 +}
10717 +
10718 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10719 +
10720 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10721 +
10722 +
10723 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10724 +
10725 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10726 +
10727 +#endif
10728 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/context.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/context.h
10729 --- linux-3.7.1/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10730 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/context.h       2012-12-18 15:13:16.000000000 +0000
10731 @@ -0,0 +1,110 @@
10732 +#ifndef _VSERVER_CONTEXT_H
10733 +#define _VSERVER_CONTEXT_H
10734 +
10735 +
10736 +#include <linux/list.h>
10737 +#include <linux/spinlock.h>
10738 +#include <linux/rcupdate.h>
10739 +#include <uapi/vserver/context.h>
10740 +
10741 +#include "limit_def.h"
10742 +#include "sched_def.h"
10743 +#include "cvirt_def.h"
10744 +#include "cacct_def.h"
10745 +#include "device_def.h"
10746 +
10747 +#define VX_SPACES      2
10748 +
10749 +struct _vx_info_pc {
10750 +       struct _vx_sched_pc sched_pc;
10751 +       struct _vx_cvirt_pc cvirt_pc;
10752 +};
10753 +
10754 +struct _vx_space {
10755 +       unsigned long vx_nsmask;                /* assignment mask */
10756 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10757 +       struct fs_struct *vx_fs;                /* private namespace fs */
10758 +       const struct cred *vx_cred;             /* task credentials */
10759 +};
10760 +
10761 +struct vx_info {
10762 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10763 +       xid_t vx_id;                            /* context id */
10764 +       atomic_t vx_usecnt;                     /* usage count */
10765 +       atomic_t vx_tasks;                      /* tasks count */
10766 +       struct vx_info *vx_parent;              /* parent context */
10767 +       int vx_state;                           /* context state */
10768 +
10769 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10770 +
10771 +       uint64_t vx_flags;                      /* context flags */
10772 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10773 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10774 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10775 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10776 +
10777 +       struct task_struct *vx_reaper;          /* guest reaper process */
10778 +       pid_t vx_initpid;                       /* PID of guest init */
10779 +       int64_t vx_badness_bias;                /* OOM points bias */
10780 +
10781 +       struct _vx_limit limit;                 /* vserver limits */
10782 +       struct _vx_sched sched;                 /* vserver scheduler */
10783 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10784 +       struct _vx_cacct cacct;                 /* context accounting */
10785 +
10786 +       struct _vx_device dmap;                 /* default device map targets */
10787 +
10788 +#ifndef CONFIG_SMP
10789 +       struct _vx_info_pc info_pc;             /* per cpu data */
10790 +#else
10791 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10792 +#endif
10793 +
10794 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10795 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10796 +       int exit_code;                          /* last process exit code */
10797 +
10798 +       char vx_name[65];                       /* vserver name */
10799 +};
10800 +
10801 +#ifndef CONFIG_SMP
10802 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10803 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10804 +#else
10805 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10806 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10807 +#endif
10808 +
10809 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10810 +
10811 +
10812 +struct vx_info_save {
10813 +       struct vx_info *vxi;
10814 +       xid_t xid;
10815 +};
10816 +
10817 +
10818 +/* status flags */
10819 +
10820 +#define VXS_HASHED     0x0001
10821 +#define VXS_PAUSED     0x0010
10822 +#define VXS_SHUTDOWN   0x0100
10823 +#define VXS_HELPER     0x1000
10824 +#define VXS_RELEASED   0x8000
10825 +
10826 +
10827 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10828 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10829 +
10830 +extern struct vx_info *lookup_vx_info(int);
10831 +extern struct vx_info *lookup_or_create_vx_info(int);
10832 +
10833 +extern int get_xid_list(int, unsigned int *, int);
10834 +extern int xid_is_hashed(xid_t);
10835 +
10836 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10837 +
10838 +extern long vs_state_change(struct vx_info *, unsigned int);
10839 +
10840 +
10841 +#endif /* _VSERVER_CONTEXT_H */
10842 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/context_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/context_cmd.h
10843 --- linux-3.7.1/include/linux/vserver/context_cmd.h     1970-01-01 00:00:00.000000000 +0000
10844 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/context_cmd.h   2012-12-18 15:13:16.000000000 +0000
10845 @@ -0,0 +1,33 @@
10846 +#ifndef _VSERVER_CONTEXT_CMD_H
10847 +#define _VSERVER_CONTEXT_CMD_H
10848 +
10849 +#include <uapi/vserver/context_cmd.h>
10850 +
10851 +extern int vc_task_xid(uint32_t);
10852 +
10853 +extern int vc_vx_info(struct vx_info *, void __user *);
10854 +
10855 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10856 +
10857 +extern int vc_ctx_create(uint32_t, void __user *);
10858 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10859 +
10860 +extern int vc_get_cflags(struct vx_info *, void __user *);
10861 +extern int vc_set_cflags(struct vx_info *, void __user *);
10862 +
10863 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10864 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10865 +
10866 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10867 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10868 +
10869 +extern int vc_get_umask(struct vx_info *, void __user *);
10870 +extern int vc_set_umask(struct vx_info *, void __user *);
10871 +
10872 +extern int vc_get_wmask(struct vx_info *, void __user *);
10873 +extern int vc_set_wmask(struct vx_info *, void __user *);
10874 +
10875 +extern int vc_get_badness(struct vx_info *, void __user *);
10876 +extern int vc_set_badness(struct vx_info *, void __user *);
10877 +
10878 +#endif /* _VSERVER_CONTEXT_CMD_H */
10879 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/cvirt.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/cvirt.h
10880 --- linux-3.7.1/include/linux/vserver/cvirt.h   1970-01-01 00:00:00.000000000 +0000
10881 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/cvirt.h 2012-12-18 15:13:16.000000000 +0000
10882 @@ -0,0 +1,18 @@
10883 +#ifndef _VSERVER_CVIRT_H
10884 +#define _VSERVER_CVIRT_H
10885 +
10886 +struct timespec;
10887 +
10888 +void vx_vsi_boottime(struct timespec *);
10889 +
10890 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10891 +
10892 +
10893 +struct vx_info;
10894 +
10895 +void vx_update_load(struct vx_info *);
10896 +
10897 +
10898 +int vx_do_syslog(int, char __user *, int);
10899 +
10900 +#endif /* _VSERVER_CVIRT_H */
10901 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/cvirt_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/cvirt_cmd.h
10902 --- linux-3.7.1/include/linux/vserver/cvirt_cmd.h       1970-01-01 00:00:00.000000000 +0000
10903 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/cvirt_cmd.h     2012-12-18 15:13:16.000000000 +0000
10904 @@ -0,0 +1,13 @@
10905 +#ifndef _VSERVER_CVIRT_CMD_H
10906 +#define _VSERVER_CVIRT_CMD_H
10907 +
10908 +
10909 +#include <linux/compiler.h>
10910 +#include <uapi/vserver/cvirt_cmd.h>
10911 +
10912 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10913 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10914 +
10915 +extern int vc_virt_stat(struct vx_info *, void __user *);
10916 +
10917 +#endif /* _VSERVER_CVIRT_CMD_H */
10918 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/cvirt_def.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/cvirt_def.h
10919 --- linux-3.7.1/include/linux/vserver/cvirt_def.h       1970-01-01 00:00:00.000000000 +0000
10920 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/cvirt_def.h     2012-12-18 15:13:16.000000000 +0000
10921 @@ -0,0 +1,80 @@
10922 +#ifndef _VSERVER_CVIRT_DEF_H
10923 +#define _VSERVER_CVIRT_DEF_H
10924 +
10925 +#include <linux/jiffies.h>
10926 +#include <linux/spinlock.h>
10927 +#include <linux/wait.h>
10928 +#include <linux/time.h>
10929 +#include <asm/atomic.h>
10930 +
10931 +
10932 +struct _vx_usage_stat {
10933 +       uint64_t user;
10934 +       uint64_t nice;
10935 +       uint64_t system;
10936 +       uint64_t softirq;
10937 +       uint64_t irq;
10938 +       uint64_t idle;
10939 +       uint64_t iowait;
10940 +};
10941 +
10942 +struct _vx_syslog {
10943 +       wait_queue_head_t log_wait;
10944 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10945 +
10946 +       unsigned long log_start;        /* next char to be read by syslog() */
10947 +       unsigned long con_start;        /* next char to be sent to consoles */
10948 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10949 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10950 +
10951 +       char log_buf[1024];
10952 +};
10953 +
10954 +
10955 +/* context sub struct */
10956 +
10957 +struct _vx_cvirt {
10958 +       atomic_t nr_threads;            /* number of current threads */
10959 +       atomic_t nr_running;            /* number of running threads */
10960 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10961 +
10962 +       atomic_t nr_onhold;             /* processes on hold */
10963 +       uint32_t onhold_last;           /* jiffies when put on hold */
10964 +
10965 +       struct timespec bias_ts;        /* time offset to the host */
10966 +       struct timespec bias_idle;
10967 +       struct timespec bias_uptime;    /* context creation point */
10968 +       uint64_t bias_clock;            /* offset in clock_t */
10969 +
10970 +       spinlock_t load_lock;           /* lock for the load averages */
10971 +       atomic_t load_updates;          /* nr of load updates done so far */
10972 +       uint32_t load_last;             /* last time load was calculated */
10973 +       uint32_t load[3];               /* load averages 1,5,15 */
10974 +
10975 +       atomic_t total_forks;           /* number of forks so far */
10976 +
10977 +       struct _vx_syslog syslog;
10978 +};
10979 +
10980 +struct _vx_cvirt_pc {
10981 +       struct _vx_usage_stat cpustat;
10982 +};
10983 +
10984 +
10985 +#ifdef CONFIG_VSERVER_DEBUG
10986 +
10987 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10988 +{
10989 +       printk("\t_vx_cvirt:\n");
10990 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10991 +               atomic_read(&cvirt->nr_threads),
10992 +               atomic_read(&cvirt->nr_running),
10993 +               atomic_read(&cvirt->nr_uninterruptible),
10994 +               atomic_read(&cvirt->nr_onhold));
10995 +       /* add rest here */
10996 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10997 +}
10998 +
10999 +#endif
11000 +
11001 +#endif /* _VSERVER_CVIRT_DEF_H */
11002 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/debug.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/debug.h
11003 --- linux-3.7.1/include/linux/vserver/debug.h   1970-01-01 00:00:00.000000000 +0000
11004 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/debug.h 2012-12-18 15:13:16.000000000 +0000
11005 @@ -0,0 +1,145 @@
11006 +#ifndef _VSERVER_DEBUG_H
11007 +#define _VSERVER_DEBUG_H
11008 +
11009 +
11010 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11011 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11012 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11013 +
11014 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11015 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11016 +#define VXF_DEV                "%p[%lu,%d:%d]"
11017 +
11018 +#if    defined(CONFIG_QUOTES_UTF8)
11019 +#define        VS_Q_LQM        "\xc2\xbb"
11020 +#define        VS_Q_RQM        "\xc2\xab"
11021 +#elif  defined(CONFIG_QUOTES_ASCII)
11022 +#define        VS_Q_LQM        "\x27"
11023 +#define        VS_Q_RQM        "\x27"
11024 +#else
11025 +#define        VS_Q_LQM        "\xbb"
11026 +#define        VS_Q_RQM        "\xab"
11027 +#endif
11028 +
11029 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11030 +
11031 +
11032 +#define vxd_path(p)                                            \
11033 +       ({ static char _buffer[PATH_MAX];                       \
11034 +          d_path(p, _buffer, sizeof(_buffer)); })
11035 +
11036 +#define vxd_cond_path(n)                                       \
11037 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11038 +
11039 +
11040 +#ifdef CONFIG_VSERVER_DEBUG
11041 +
11042 +extern unsigned int vs_debug_switch;
11043 +extern unsigned int vs_debug_xid;
11044 +extern unsigned int vs_debug_nid;
11045 +extern unsigned int vs_debug_tag;
11046 +extern unsigned int vs_debug_net;
11047 +extern unsigned int vs_debug_limit;
11048 +extern unsigned int vs_debug_cres;
11049 +extern unsigned int vs_debug_dlim;
11050 +extern unsigned int vs_debug_quota;
11051 +extern unsigned int vs_debug_cvirt;
11052 +extern unsigned int vs_debug_space;
11053 +extern unsigned int vs_debug_perm;
11054 +extern unsigned int vs_debug_misc;
11055 +
11056 +
11057 +#define VX_LOGLEVEL    "vxD: "
11058 +#define VX_PROC_FMT    "%p: "
11059 +#define VX_PROCESS     current
11060 +
11061 +#define vxdprintk(c, f, x...)                                  \
11062 +       do {                                                    \
11063 +               if (c)                                          \
11064 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11065 +                               VX_PROCESS , ##x);              \
11066 +       } while (0)
11067 +
11068 +#define vxlprintk(c, f, x...)                                  \
11069 +       do {                                                    \
11070 +               if (c)                                          \
11071 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11072 +       } while (0)
11073 +
11074 +#define vxfprintk(c, f, x...)                                  \
11075 +       do {                                                    \
11076 +               if (c)                                          \
11077 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11078 +       } while (0)
11079 +
11080 +
11081 +struct vx_info;
11082 +
11083 +void dump_vx_info(struct vx_info *, int);
11084 +void dump_vx_info_inactive(int);
11085 +
11086 +#else  /* CONFIG_VSERVER_DEBUG */
11087 +
11088 +#define vs_debug_switch        0
11089 +#define vs_debug_xid   0
11090 +#define vs_debug_nid   0
11091 +#define vs_debug_tag   0
11092 +#define vs_debug_net   0
11093 +#define vs_debug_limit 0
11094 +#define vs_debug_cres  0
11095 +#define vs_debug_dlim  0
11096 +#define vs_debug_quota 0
11097 +#define vs_debug_cvirt 0
11098 +#define vs_debug_space 0
11099 +#define vs_debug_perm  0
11100 +#define vs_debug_misc  0
11101 +
11102 +#define vxdprintk(x...) do { } while (0)
11103 +#define vxlprintk(x...) do { } while (0)
11104 +#define vxfprintk(x...) do { } while (0)
11105 +
11106 +#endif /* CONFIG_VSERVER_DEBUG */
11107 +
11108 +
11109 +#ifdef CONFIG_VSERVER_WARN
11110 +
11111 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11112 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11113 +#define VX_WARN_XID    "[xid #%u] "
11114 +#define VX_WARN_NID    "[nid #%u] "
11115 +#define VX_WARN_TAG    "[tag #%u] "
11116 +
11117 +#define vxwprintk(c, f, x...)                                  \
11118 +       do {                                                    \
11119 +               if (c)                                          \
11120 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11121 +       } while (0)
11122 +
11123 +#else  /* CONFIG_VSERVER_WARN */
11124 +
11125 +#define vxwprintk(x...) do { } while (0)
11126 +
11127 +#endif /* CONFIG_VSERVER_WARN */
11128 +
11129 +#define vxwprintk_task(c, f, x...)                             \
11130 +       vxwprintk(c, VX_WARN_TASK f,                            \
11131 +               current->comm, current->pid,                    \
11132 +               current->xid, current->nid, current->tag, ##x)
11133 +#define vxwprintk_xid(c, f, x...)                              \
11134 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11135 +#define vxwprintk_nid(c, f, x...)                              \
11136 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11137 +#define vxwprintk_tag(c, f, x...)                              \
11138 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11139 +
11140 +#ifdef CONFIG_VSERVER_DEBUG
11141 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11142 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11143 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11144 +#else
11145 +#define vxd_assert_lock(l)     do { } while (0)
11146 +#define vxd_assert(c, f, x...) do { } while (0)
11147 +#endif
11148 +
11149 +
11150 +#endif /* _VSERVER_DEBUG_H */
11151 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/debug_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/debug_cmd.h
11152 --- linux-3.7.1/include/linux/vserver/debug_cmd.h       1970-01-01 00:00:00.000000000 +0000
11153 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/debug_cmd.h     2012-12-18 15:13:16.000000000 +0000
11154 @@ -0,0 +1,37 @@
11155 +#ifndef _VSERVER_DEBUG_CMD_H
11156 +#define _VSERVER_DEBUG_CMD_H
11157 +
11158 +#include <uapi/vserver/debug_cmd.h>
11159 +
11160 +
11161 +#ifdef CONFIG_COMPAT
11162 +
11163 +#include <asm/compat.h>
11164 +
11165 +struct vcmd_read_history_v0_x32 {
11166 +       uint32_t index;
11167 +       uint32_t count;
11168 +       compat_uptr_t data_ptr;
11169 +};
11170 +
11171 +struct vcmd_read_monitor_v0_x32 {
11172 +       uint32_t index;
11173 +       uint32_t count;
11174 +       compat_uptr_t data_ptr;
11175 +};
11176 +
11177 +#endif  /* CONFIG_COMPAT */
11178 +
11179 +extern int vc_dump_history(uint32_t);
11180 +
11181 +extern int vc_read_history(uint32_t, void __user *);
11182 +extern int vc_read_monitor(uint32_t, void __user *);
11183 +
11184 +#ifdef CONFIG_COMPAT
11185 +
11186 +extern int vc_read_history_x32(uint32_t, void __user *);
11187 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11188 +
11189 +#endif  /* CONFIG_COMPAT */
11190 +
11191 +#endif /* _VSERVER_DEBUG_CMD_H */
11192 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/device.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/device.h
11193 --- linux-3.7.1/include/linux/vserver/device.h  1970-01-01 00:00:00.000000000 +0000
11194 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/device.h        2012-12-18 15:13:16.000000000 +0000
11195 @@ -0,0 +1,9 @@
11196 +#ifndef _VSERVER_DEVICE_H
11197 +#define _VSERVER_DEVICE_H
11198 +
11199 +
11200 +#include <uapi/vserver/device.h>
11201 +
11202 +#else  /* _VSERVER_DEVICE_H */
11203 +#warning duplicate inclusion
11204 +#endif /* _VSERVER_DEVICE_H */
11205 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/device_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/device_cmd.h
11206 --- linux-3.7.1/include/linux/vserver/device_cmd.h      1970-01-01 00:00:00.000000000 +0000
11207 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/device_cmd.h    2012-12-18 15:13:16.000000000 +0000
11208 @@ -0,0 +1,31 @@
11209 +#ifndef _VSERVER_DEVICE_CMD_H
11210 +#define _VSERVER_DEVICE_CMD_H
11211 +
11212 +#include <uapi/vserver/device_cmd.h>
11213 +
11214 +
11215 +#ifdef CONFIG_COMPAT
11216 +
11217 +#include <asm/compat.h>
11218 +
11219 +struct vcmd_set_mapping_v0_x32 {
11220 +       compat_uptr_t device_ptr;
11221 +       compat_uptr_t target_ptr;
11222 +       uint32_t flags;
11223 +};
11224 +
11225 +#endif /* CONFIG_COMPAT */
11226 +
11227 +#include <linux/compiler.h>
11228 +
11229 +extern int vc_set_mapping(struct vx_info *, void __user *);
11230 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11231 +
11232 +#ifdef CONFIG_COMPAT
11233 +
11234 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11235 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11236 +
11237 +#endif /* CONFIG_COMPAT */
11238 +
11239 +#endif /* _VSERVER_DEVICE_CMD_H */
11240 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/device_def.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/device_def.h
11241 --- linux-3.7.1/include/linux/vserver/device_def.h      1970-01-01 00:00:00.000000000 +0000
11242 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/device_def.h    2012-12-18 15:13:16.000000000 +0000
11243 @@ -0,0 +1,17 @@
11244 +#ifndef _VSERVER_DEVICE_DEF_H
11245 +#define _VSERVER_DEVICE_DEF_H
11246 +
11247 +#include <linux/types.h>
11248 +
11249 +struct vx_dmap_target {
11250 +       dev_t target;
11251 +       uint32_t flags;
11252 +};
11253 +
11254 +struct _vx_device {
11255 +#ifdef CONFIG_VSERVER_DEVICE
11256 +       struct vx_dmap_target targets[2];
11257 +#endif
11258 +};
11259 +
11260 +#endif /* _VSERVER_DEVICE_DEF_H */
11261 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/dlimit.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/dlimit.h
11262 --- linux-3.7.1/include/linux/vserver/dlimit.h  1970-01-01 00:00:00.000000000 +0000
11263 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/dlimit.h        2012-12-18 15:13:16.000000000 +0000
11264 @@ -0,0 +1,54 @@
11265 +#ifndef _VSERVER_DLIMIT_H
11266 +#define _VSERVER_DLIMIT_H
11267 +
11268 +#include "switch.h"
11269 +
11270 +
11271 +#ifdef __KERNEL__
11272 +
11273 +/*      keep in sync with CDLIM_INFINITY       */
11274 +
11275 +#define DLIM_INFINITY          (~0ULL)
11276 +
11277 +#include <linux/spinlock.h>
11278 +#include <linux/rcupdate.h>
11279 +
11280 +struct super_block;
11281 +
11282 +struct dl_info {
11283 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11284 +       struct rcu_head dl_rcu;                 /* the rcu head */
11285 +       tag_t dl_tag;                           /* context tag */
11286 +       atomic_t dl_usecnt;                     /* usage count */
11287 +       atomic_t dl_refcnt;                     /* reference count */
11288 +
11289 +       struct super_block *dl_sb;              /* associated superblock */
11290 +
11291 +       spinlock_t dl_lock;                     /* protect the values */
11292 +
11293 +       unsigned long long dl_space_used;       /* used space in bytes */
11294 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11295 +       unsigned long dl_inodes_used;           /* used inodes */
11296 +       unsigned long dl_inodes_total;          /* maximum inodes */
11297 +
11298 +       unsigned int dl_nrlmult;                /* non root limit mult */
11299 +};
11300 +
11301 +struct rcu_head;
11302 +
11303 +extern void rcu_free_dl_info(struct rcu_head *);
11304 +extern void unhash_dl_info(struct dl_info *);
11305 +
11306 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11307 +
11308 +
11309 +struct kstatfs;
11310 +
11311 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11312 +
11313 +typedef uint64_t dlsize_t;
11314 +
11315 +#endif /* __KERNEL__ */
11316 +#else  /* _VSERVER_DLIMIT_H */
11317 +#warning duplicate inclusion
11318 +#endif /* _VSERVER_DLIMIT_H */
11319 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/dlimit_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/dlimit_cmd.h
11320 --- linux-3.7.1/include/linux/vserver/dlimit_cmd.h      1970-01-01 00:00:00.000000000 +0000
11321 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/dlimit_cmd.h    2012-12-18 15:13:16.000000000 +0000
11322 @@ -0,0 +1,46 @@
11323 +#ifndef _VSERVER_DLIMIT_CMD_H
11324 +#define _VSERVER_DLIMIT_CMD_H
11325 +
11326 +#include <uapi/vserver/dlimit_cmd.h>
11327 +
11328 +
11329 +#ifdef CONFIG_COMPAT
11330 +
11331 +#include <asm/compat.h>
11332 +
11333 +struct vcmd_ctx_dlimit_base_v0_x32 {
11334 +       compat_uptr_t name_ptr;
11335 +       uint32_t flags;
11336 +};
11337 +
11338 +struct vcmd_ctx_dlimit_v0_x32 {
11339 +       compat_uptr_t name_ptr;
11340 +       uint32_t space_used;                    /* used space in kbytes */
11341 +       uint32_t space_total;                   /* maximum space in kbytes */
11342 +       uint32_t inodes_used;                   /* used inodes */
11343 +       uint32_t inodes_total;                  /* maximum inodes */
11344 +       uint32_t reserved;                      /* reserved for root in % */
11345 +       uint32_t flags;
11346 +};
11347 +
11348 +#endif /* CONFIG_COMPAT */
11349 +
11350 +#include <linux/compiler.h>
11351 +
11352 +extern int vc_add_dlimit(uint32_t, void __user *);
11353 +extern int vc_rem_dlimit(uint32_t, void __user *);
11354 +
11355 +extern int vc_set_dlimit(uint32_t, void __user *);
11356 +extern int vc_get_dlimit(uint32_t, void __user *);
11357 +
11358 +#ifdef CONFIG_COMPAT
11359 +
11360 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11361 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11362 +
11363 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11364 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11365 +
11366 +#endif /* CONFIG_COMPAT */
11367 +
11368 +#endif /* _VSERVER_DLIMIT_CMD_H */
11369 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/global.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/global.h
11370 --- linux-3.7.1/include/linux/vserver/global.h  1970-01-01 00:00:00.000000000 +0000
11371 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/global.h        2012-12-18 15:13:16.000000000 +0000
11372 @@ -0,0 +1,19 @@
11373 +#ifndef _VSERVER_GLOBAL_H
11374 +#define _VSERVER_GLOBAL_H
11375 +
11376 +
11377 +extern atomic_t vx_global_ctotal;
11378 +extern atomic_t vx_global_cactive;
11379 +
11380 +extern atomic_t nx_global_ctotal;
11381 +extern atomic_t nx_global_cactive;
11382 +
11383 +extern atomic_t vs_global_nsproxy;
11384 +extern atomic_t vs_global_fs;
11385 +extern atomic_t vs_global_mnt_ns;
11386 +extern atomic_t vs_global_uts_ns;
11387 +extern atomic_t vs_global_user_ns;
11388 +extern atomic_t vs_global_pid_ns;
11389 +
11390 +
11391 +#endif /* _VSERVER_GLOBAL_H */
11392 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/history.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/history.h
11393 --- linux-3.7.1/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11394 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/history.h       2012-12-18 15:13:16.000000000 +0000
11395 @@ -0,0 +1,197 @@
11396 +#ifndef _VSERVER_HISTORY_H
11397 +#define _VSERVER_HISTORY_H
11398 +
11399 +
11400 +enum {
11401 +       VXH_UNUSED = 0,
11402 +       VXH_THROW_OOPS = 1,
11403 +
11404 +       VXH_GET_VX_INFO,
11405 +       VXH_PUT_VX_INFO,
11406 +       VXH_INIT_VX_INFO,
11407 +       VXH_SET_VX_INFO,
11408 +       VXH_CLR_VX_INFO,
11409 +       VXH_CLAIM_VX_INFO,
11410 +       VXH_RELEASE_VX_INFO,
11411 +       VXH_ALLOC_VX_INFO,
11412 +       VXH_DEALLOC_VX_INFO,
11413 +       VXH_HASH_VX_INFO,
11414 +       VXH_UNHASH_VX_INFO,
11415 +       VXH_LOC_VX_INFO,
11416 +       VXH_LOOKUP_VX_INFO,
11417 +       VXH_CREATE_VX_INFO,
11418 +};
11419 +
11420 +struct _vxhe_vxi {
11421 +       struct vx_info *ptr;
11422 +       unsigned xid;
11423 +       unsigned usecnt;
11424 +       unsigned tasks;
11425 +};
11426 +
11427 +struct _vxhe_set_clr {
11428 +       void *data;
11429 +};
11430 +
11431 +struct _vxhe_loc_lookup {
11432 +       unsigned arg;
11433 +};
11434 +
11435 +struct _vx_hist_entry {
11436 +       void *loc;
11437 +       unsigned short seq;
11438 +       unsigned short type;
11439 +       struct _vxhe_vxi vxi;
11440 +       union {
11441 +               struct _vxhe_set_clr sc;
11442 +               struct _vxhe_loc_lookup ll;
11443 +       };
11444 +};
11445 +
11446 +#ifdef CONFIG_VSERVER_HISTORY
11447 +
11448 +extern unsigned volatile int vxh_active;
11449 +
11450 +struct _vx_hist_entry *vxh_advance(void *loc);
11451 +
11452 +
11453 +static inline
11454 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11455 +{
11456 +       entry->vxi.ptr = vxi;
11457 +       if (vxi) {
11458 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11459 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11460 +               entry->vxi.xid = vxi->vx_id;
11461 +       }
11462 +}
11463 +
11464 +
11465 +#define        __HERE__ current_text_addr()
11466 +
11467 +#define __VXH_BODY(__type, __data, __here)     \
11468 +       struct _vx_hist_entry *entry;           \
11469 +                                               \
11470 +       preempt_disable();                      \
11471 +       entry = vxh_advance(__here);            \
11472 +       __data;                                 \
11473 +       entry->type = __type;                   \
11474 +       preempt_enable();
11475 +
11476 +
11477 +       /* pass vxi only */
11478 +
11479 +#define __VXH_SMPL                             \
11480 +       __vxh_copy_vxi(entry, vxi)
11481 +
11482 +static inline
11483 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11484 +{
11485 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11486 +}
11487 +
11488 +       /* pass vxi and data (void *) */
11489 +
11490 +#define __VXH_DATA                             \
11491 +       __vxh_copy_vxi(entry, vxi);             \
11492 +       entry->sc.data = data
11493 +
11494 +static inline
11495 +void   __vxh_data(struct vx_info *vxi, void *data,
11496 +                       int __type, void *__here)
11497 +{
11498 +       __VXH_BODY(__type, __VXH_DATA, __here)
11499 +}
11500 +
11501 +       /* pass vxi and arg (long) */
11502 +
11503 +#define __VXH_LONG                             \
11504 +       __vxh_copy_vxi(entry, vxi);             \
11505 +       entry->ll.arg = arg
11506 +
11507 +static inline
11508 +void   __vxh_long(struct vx_info *vxi, long arg,
11509 +                       int __type, void *__here)
11510 +{
11511 +       __VXH_BODY(__type, __VXH_LONG, __here)
11512 +}
11513 +
11514 +
11515 +static inline
11516 +void   __vxh_throw_oops(void *__here)
11517 +{
11518 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11519 +       /* prevent further acquisition */
11520 +       vxh_active = 0;
11521 +}
11522 +
11523 +
11524 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11525 +
11526 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11527 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11528 +
11529 +#define __vxh_init_vx_info(v, d, h) \
11530 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11531 +#define __vxh_set_vx_info(v, d, h) \
11532 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11533 +#define __vxh_clr_vx_info(v, d, h) \
11534 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11535 +
11536 +#define __vxh_claim_vx_info(v, d, h) \
11537 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11538 +#define __vxh_release_vx_info(v, d, h) \
11539 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11540 +
11541 +#define vxh_alloc_vx_info(v) \
11542 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11543 +#define vxh_dealloc_vx_info(v) \
11544 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11545 +
11546 +#define vxh_hash_vx_info(v) \
11547 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11548 +#define vxh_unhash_vx_info(v) \
11549 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11550 +
11551 +#define vxh_loc_vx_info(v, l) \
11552 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11553 +#define vxh_lookup_vx_info(v, l) \
11554 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11555 +#define vxh_create_vx_info(v, l) \
11556 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11557 +
11558 +extern void vxh_dump_history(void);
11559 +
11560 +
11561 +#else  /* CONFIG_VSERVER_HISTORY */
11562 +
11563 +#define        __HERE__        0
11564 +
11565 +#define vxh_throw_oops()               do { } while (0)
11566 +
11567 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11568 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11569 +
11570 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11571 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11572 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11573 +
11574 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11575 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11576 +
11577 +#define vxh_alloc_vx_info(v)           do { } while (0)
11578 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11579 +
11580 +#define vxh_hash_vx_info(v)            do { } while (0)
11581 +#define vxh_unhash_vx_info(v)          do { } while (0)
11582 +
11583 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11584 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11585 +#define vxh_create_vx_info(v, l)       do { } while (0)
11586 +
11587 +#define vxh_dump_history()             do { } while (0)
11588 +
11589 +
11590 +#endif /* CONFIG_VSERVER_HISTORY */
11591 +
11592 +#endif /* _VSERVER_HISTORY_H */
11593 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/inode.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/inode.h
11594 --- linux-3.7.1/include/linux/vserver/inode.h   1970-01-01 00:00:00.000000000 +0000
11595 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/inode.h 2012-12-18 15:13:16.000000000 +0000
11596 @@ -0,0 +1,19 @@
11597 +#ifndef _VSERVER_INODE_H
11598 +#define _VSERVER_INODE_H
11599 +
11600 +#include <uapi/vserver/inode.h>
11601 +
11602 +
11603 +#ifdef CONFIG_VSERVER_PROC_SECURE
11604 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11605 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11606 +#else
11607 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11608 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11609 +#endif
11610 +
11611 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11612 +
11613 +#else  /* _VSERVER_INODE_H */
11614 +#warning duplicate inclusion
11615 +#endif /* _VSERVER_INODE_H */
11616 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/inode_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/inode_cmd.h
11617 --- linux-3.7.1/include/linux/vserver/inode_cmd.h       1970-01-01 00:00:00.000000000 +0000
11618 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/inode_cmd.h     2012-12-18 15:13:16.000000000 +0000
11619 @@ -0,0 +1,36 @@
11620 +#ifndef _VSERVER_INODE_CMD_H
11621 +#define _VSERVER_INODE_CMD_H
11622 +
11623 +#include <uapi/vserver/inode_cmd.h>
11624 +
11625 +
11626 +
11627 +#ifdef CONFIG_COMPAT
11628 +
11629 +#include <asm/compat.h>
11630 +
11631 +struct vcmd_ctx_iattr_v1_x32 {
11632 +       compat_uptr_t name_ptr;
11633 +       uint32_t tag;
11634 +       uint32_t flags;
11635 +       uint32_t mask;
11636 +};
11637 +
11638 +#endif /* CONFIG_COMPAT */
11639 +
11640 +#include <linux/compiler.h>
11641 +
11642 +extern int vc_get_iattr(void __user *);
11643 +extern int vc_set_iattr(void __user *);
11644 +
11645 +extern int vc_fget_iattr(uint32_t, void __user *);
11646 +extern int vc_fset_iattr(uint32_t, void __user *);
11647 +
11648 +#ifdef CONFIG_COMPAT
11649 +
11650 +extern int vc_get_iattr_x32(void __user *);
11651 +extern int vc_set_iattr_x32(void __user *);
11652 +
11653 +#endif /* CONFIG_COMPAT */
11654 +
11655 +#endif /* _VSERVER_INODE_CMD_H */
11656 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/limit.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/limit.h
11657 --- linux-3.7.1/include/linux/vserver/limit.h   1970-01-01 00:00:00.000000000 +0000
11658 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/limit.h 2012-12-18 15:13:16.000000000 +0000
11659 @@ -0,0 +1,61 @@
11660 +#ifndef _VSERVER_LIMIT_H
11661 +#define _VSERVER_LIMIT_H
11662 +
11663 +#include <uapi/vserver/limit.h>
11664 +
11665 +
11666 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11667 +
11668 +/*     keep in sync with CRLIM_INFINITY */
11669 +
11670 +#define        VLIM_INFINITY   (~0ULL)
11671 +
11672 +#include <asm/atomic.h>
11673 +#include <asm/resource.h>
11674 +
11675 +#ifndef RLIM_INFINITY
11676 +#warning RLIM_INFINITY is undefined
11677 +#endif
11678 +
11679 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11680 +
11681 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11682 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11683 +
11684 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11685 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11686 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11687 +
11688 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11689 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11690 +
11691 +typedef atomic_long_t rlim_atomic_t;
11692 +typedef unsigned long rlim_t;
11693 +
11694 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11695 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11696 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11697 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11698 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11699 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11700 +
11701 +
11702 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11703 +#define        VX_VLIM(r) ((long long)(long)(r))
11704 +#define        VX_RLIM(v) ((rlim_t)(v))
11705 +#else
11706 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11707 +               ? VLIM_INFINITY : (long long)(r))
11708 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11709 +               ? RLIM_INFINITY : (rlim_t)(v))
11710 +#endif
11711 +
11712 +struct sysinfo;
11713 +
11714 +void vx_vsi_meminfo(struct sysinfo *);
11715 +void vx_vsi_swapinfo(struct sysinfo *);
11716 +long vx_vsi_cached(struct sysinfo *);
11717 +
11718 +#define NUM_LIMITS     24
11719 +
11720 +#endif /* _VSERVER_LIMIT_H */
11721 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/limit_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/limit_cmd.h
11722 --- linux-3.7.1/include/linux/vserver/limit_cmd.h       1970-01-01 00:00:00.000000000 +0000
11723 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/limit_cmd.h     2012-12-18 15:13:16.000000000 +0000
11724 @@ -0,0 +1,35 @@
11725 +#ifndef _VSERVER_LIMIT_CMD_H
11726 +#define _VSERVER_LIMIT_CMD_H
11727 +
11728 +#include <uapi/vserver/limit_cmd.h>
11729 +
11730 +
11731 +#ifdef CONFIG_IA32_EMULATION
11732 +
11733 +struct vcmd_ctx_rlimit_v0_x32 {
11734 +       uint32_t id;
11735 +       uint64_t minimum;
11736 +       uint64_t softlimit;
11737 +       uint64_t maximum;
11738 +} __attribute__ ((packed));
11739 +
11740 +#endif /* CONFIG_IA32_EMULATION */
11741 +
11742 +#include <linux/compiler.h>
11743 +
11744 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11745 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11746 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11747 +extern int vc_reset_hits(struct vx_info *, void __user *);
11748 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11749 +
11750 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11751 +
11752 +#ifdef CONFIG_IA32_EMULATION
11753 +
11754 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11755 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11756 +
11757 +#endif /* CONFIG_IA32_EMULATION */
11758 +
11759 +#endif /* _VSERVER_LIMIT_CMD_H */
11760 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/limit_def.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/limit_def.h
11761 --- linux-3.7.1/include/linux/vserver/limit_def.h       1970-01-01 00:00:00.000000000 +0000
11762 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/limit_def.h     2012-12-18 15:13:16.000000000 +0000
11763 @@ -0,0 +1,47 @@
11764 +#ifndef _VSERVER_LIMIT_DEF_H
11765 +#define _VSERVER_LIMIT_DEF_H
11766 +
11767 +#include <asm/atomic.h>
11768 +#include <asm/resource.h>
11769 +
11770 +#include "limit.h"
11771 +
11772 +
11773 +struct _vx_res_limit {
11774 +       rlim_t soft;            /* Context soft limit */
11775 +       rlim_t hard;            /* Context hard limit */
11776 +
11777 +       rlim_atomic_t rcur;     /* Current value */
11778 +       rlim_t rmin;            /* Context minimum */
11779 +       rlim_t rmax;            /* Context maximum */
11780 +
11781 +       atomic_t lhit;          /* Limit hits */
11782 +};
11783 +
11784 +/* context sub struct */
11785 +
11786 +struct _vx_limit {
11787 +       struct _vx_res_limit res[NUM_LIMITS];
11788 +};
11789 +
11790 +#ifdef CONFIG_VSERVER_DEBUG
11791 +
11792 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11793 +{
11794 +       int i;
11795 +
11796 +       printk("\t_vx_limit:");
11797 +       for (i = 0; i < NUM_LIMITS; i++) {
11798 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11799 +                       i, (unsigned long)__rlim_get(limit, i),
11800 +                       (unsigned long)__rlim_rmin(limit, i),
11801 +                       (unsigned long)__rlim_rmax(limit, i),
11802 +                       (long)__rlim_soft(limit, i),
11803 +                       (long)__rlim_hard(limit, i),
11804 +                       atomic_read(&__rlim_lhit(limit, i)));
11805 +       }
11806 +}
11807 +
11808 +#endif
11809 +
11810 +#endif /* _VSERVER_LIMIT_DEF_H */
11811 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/limit_int.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/limit_int.h
11812 --- linux-3.7.1/include/linux/vserver/limit_int.h       1970-01-01 00:00:00.000000000 +0000
11813 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/limit_int.h     2012-12-18 15:13:16.000000000 +0000
11814 @@ -0,0 +1,193 @@
11815 +#ifndef _VSERVER_LIMIT_INT_H
11816 +#define _VSERVER_LIMIT_INT_H
11817 +
11818 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11819 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11820 +
11821 +extern const char *vlimit_name[NUM_LIMITS];
11822 +
11823 +static inline void __vx_acc_cres(struct vx_info *vxi,
11824 +       int res, int dir, void *_data, char *_file, int _line)
11825 +{
11826 +       if (VXD_RCRES_COND(res))
11827 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11828 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11829 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11830 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11831 +       if (!vxi)
11832 +               return;
11833 +
11834 +       if (dir > 0)
11835 +               __rlim_inc(&vxi->limit, res);
11836 +       else
11837 +               __rlim_dec(&vxi->limit, res);
11838 +}
11839 +
11840 +static inline void __vx_add_cres(struct vx_info *vxi,
11841 +       int res, int amount, void *_data, char *_file, int _line)
11842 +{
11843 +       if (VXD_RCRES_COND(res))
11844 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11845 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11846 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11847 +                       amount, _data, _file, _line);
11848 +       if (amount == 0)
11849 +               return;
11850 +       if (!vxi)
11851 +               return;
11852 +       __rlim_add(&vxi->limit, res, amount);
11853 +}
11854 +
11855 +static inline
11856 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11857 +{
11858 +       int cond = (value > __rlim_rmax(limit, res));
11859 +
11860 +       if (cond)
11861 +               __rlim_rmax(limit, res) = value;
11862 +       return cond;
11863 +}
11864 +
11865 +static inline
11866 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11867 +{
11868 +       int cond = (value < __rlim_rmin(limit, res));
11869 +
11870 +       if (cond)
11871 +               __rlim_rmin(limit, res) = value;
11872 +       return cond;
11873 +}
11874 +
11875 +static inline
11876 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11877 +{
11878 +       if (!__vx_cres_adjust_max(limit, res, value))
11879 +               __vx_cres_adjust_min(limit, res, value);
11880 +}
11881 +
11882 +
11883 +/*     return values:
11884 +        +1 ... no limit hit
11885 +        -1 ... over soft limit
11886 +         0 ... over hard limit         */
11887 +
11888 +static inline int __vx_cres_avail(struct vx_info *vxi,
11889 +       int res, int num, char *_file, int _line)
11890 +{
11891 +       struct _vx_limit *limit;
11892 +       rlim_t value;
11893 +
11894 +       if (VXD_RLIMIT_COND(res))
11895 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11896 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11897 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11898 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11899 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11900 +                       num, _file, _line);
11901 +       if (!vxi)
11902 +               return 1;
11903 +
11904 +       limit = &vxi->limit;
11905 +       value = __rlim_get(limit, res);
11906 +
11907 +       if (!__vx_cres_adjust_max(limit, res, value))
11908 +               __vx_cres_adjust_min(limit, res, value);
11909 +
11910 +       if (num == 0)
11911 +               return 1;
11912 +
11913 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11914 +               return -1;
11915 +       if (value + num <= __rlim_soft(limit, res))
11916 +               return -1;
11917 +
11918 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11919 +               return 1;
11920 +       if (value + num <= __rlim_hard(limit, res))
11921 +               return 1;
11922 +
11923 +       __rlim_hit(limit, res);
11924 +       return 0;
11925 +}
11926 +
11927 +
11928 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11929 +
11930 +static inline
11931 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11932 +{
11933 +       rlim_t value, sum = 0;
11934 +       int res;
11935 +
11936 +       while ((res = *array++)) {
11937 +               value = __rlim_get(limit, res);
11938 +               __vx_cres_fixup(limit, res, value);
11939 +               sum += value;
11940 +       }
11941 +       return sum;
11942 +}
11943 +
11944 +static inline
11945 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11946 +{
11947 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11948 +       int res = *array;
11949 +
11950 +       if (value == __rlim_get(limit, res))
11951 +               return value;
11952 +
11953 +       __rlim_set(limit, res, value);
11954 +       /* now adjust min/max */
11955 +       if (!__vx_cres_adjust_max(limit, res, value))
11956 +               __vx_cres_adjust_min(limit, res, value);
11957 +
11958 +       return value;
11959 +}
11960 +
11961 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11962 +       const int *array, int num, char *_file, int _line)
11963 +{
11964 +       struct _vx_limit *limit;
11965 +       rlim_t value = 0;
11966 +       int res;
11967 +
11968 +       if (num == 0)
11969 +               return 1;
11970 +       if (!vxi)
11971 +               return 1;
11972 +
11973 +       limit = &vxi->limit;
11974 +       res = *array;
11975 +       value = __vx_cres_array_sum(limit, array + 1);
11976 +
11977 +       __rlim_set(limit, res, value);
11978 +       __vx_cres_fixup(limit, res, value);
11979 +
11980 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11981 +}
11982 +
11983 +
11984 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11985 +{
11986 +       rlim_t value;
11987 +       int res;
11988 +
11989 +       /* complex resources first */
11990 +       if ((id < 0) || (id == RLIMIT_RSS))
11991 +               __vx_cres_array_fixup(limit, VLA_RSS);
11992 +
11993 +       for (res = 0; res < NUM_LIMITS; res++) {
11994 +               if ((id > 0) && (res != id))
11995 +                       continue;
11996 +
11997 +               value = __rlim_get(limit, res);
11998 +               __vx_cres_fixup(limit, res, value);
11999 +
12000 +               /* not supposed to happen, maybe warn? */
12001 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12002 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12003 +       }
12004 +}
12005 +
12006 +
12007 +#endif /* _VSERVER_LIMIT_INT_H */
12008 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/monitor.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/monitor.h
12009 --- linux-3.7.1/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
12010 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/monitor.h       2012-12-18 15:13:16.000000000 +0000
12011 @@ -0,0 +1,6 @@
12012 +#ifndef _VSERVER_MONITOR_H
12013 +#define _VSERVER_MONITOR_H
12014 +
12015 +#include <uapi/vserver/monitor.h>
12016 +
12017 +#endif /* _VSERVER_MONITOR_H */
12018 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/network.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/network.h
12019 --- linux-3.7.1/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
12020 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/network.h       2012-12-18 15:13:16.000000000 +0000
12021 @@ -0,0 +1,76 @@
12022 +#ifndef _VSERVER_NETWORK_H
12023 +#define _VSERVER_NETWORK_H
12024 +
12025 +
12026 +#include <linux/list.h>
12027 +#include <linux/spinlock.h>
12028 +#include <linux/rcupdate.h>
12029 +#include <linux/in.h>
12030 +#include <linux/in6.h>
12031 +#include <asm/atomic.h>
12032 +#include <uapi/vserver/network.h>
12033 +
12034 +struct nx_addr_v4 {
12035 +       struct nx_addr_v4 *next;
12036 +       struct in_addr ip[2];
12037 +       struct in_addr mask;
12038 +       uint16_t type;
12039 +       uint16_t flags;
12040 +};
12041 +
12042 +struct nx_addr_v6 {
12043 +       struct nx_addr_v6 *next;
12044 +       struct in6_addr ip;
12045 +       struct in6_addr mask;
12046 +       uint32_t prefix;
12047 +       uint16_t type;
12048 +       uint16_t flags;
12049 +};
12050 +
12051 +struct nx_info {
12052 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12053 +       nid_t nx_id;                    /* vnet id */
12054 +       atomic_t nx_usecnt;             /* usage count */
12055 +       atomic_t nx_tasks;              /* tasks count */
12056 +       int nx_state;                   /* context state */
12057 +
12058 +       uint64_t nx_flags;              /* network flag word */
12059 +       uint64_t nx_ncaps;              /* network capabilities */
12060 +
12061 +       spinlock_t addr_lock;           /* protect address changes */
12062 +       struct in_addr v4_lback;        /* Loopback address */
12063 +       struct in_addr v4_bcast;        /* Broadcast address */
12064 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12065 +#ifdef CONFIG_IPV6
12066 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12067 +#endif
12068 +       char nx_name[65];               /* network context name */
12069 +};
12070 +
12071 +
12072 +/* status flags */
12073 +
12074 +#define NXS_HASHED      0x0001
12075 +#define NXS_SHUTDOWN    0x0100
12076 +#define NXS_RELEASED    0x8000
12077 +
12078 +extern struct nx_info *lookup_nx_info(int);
12079 +
12080 +extern int get_nid_list(int, unsigned int *, int);
12081 +extern int nid_is_hashed(nid_t);
12082 +
12083 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12084 +
12085 +extern long vs_net_change(struct nx_info *, unsigned int);
12086 +
12087 +struct sock;
12088 +
12089 +
12090 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12091 +#ifdef  CONFIG_IPV6
12092 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12093 +#else
12094 +#define NX_IPV6(n)     (0)
12095 +#endif
12096 +
12097 +#endif /* _VSERVER_NETWORK_H */
12098 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/network_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/network_cmd.h
12099 --- linux-3.7.1/include/linux/vserver/network_cmd.h     1970-01-01 00:00:00.000000000 +0000
12100 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/network_cmd.h   2012-12-18 15:13:16.000000000 +0000
12101 @@ -0,0 +1,37 @@
12102 +#ifndef _VSERVER_NETWORK_CMD_H
12103 +#define _VSERVER_NETWORK_CMD_H
12104 +
12105 +#include <uapi/vserver/network_cmd.h>
12106 +
12107 +extern int vc_task_nid(uint32_t);
12108 +
12109 +extern int vc_nx_info(struct nx_info *, void __user *);
12110 +
12111 +extern int vc_net_create(uint32_t, void __user *);
12112 +extern int vc_net_migrate(struct nx_info *, void __user *);
12113 +
12114 +extern int vc_net_add(struct nx_info *, void __user *);
12115 +extern int vc_net_remove(struct nx_info *, void __user *);
12116 +
12117 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
12118 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12119 +
12120 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
12121 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
12122 +
12123 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12124 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12125 +
12126 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12127 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12128 +
12129 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12130 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12131 +
12132 +extern int vc_get_nflags(struct nx_info *, void __user *);
12133 +extern int vc_set_nflags(struct nx_info *, void __user *);
12134 +
12135 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12136 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12137 +
12138 +#endif /* _VSERVER_CONTEXT_CMD_H */
12139 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/percpu.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/percpu.h
12140 --- linux-3.7.1/include/linux/vserver/percpu.h  1970-01-01 00:00:00.000000000 +0000
12141 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/percpu.h        2012-12-18 15:13:16.000000000 +0000
12142 @@ -0,0 +1,14 @@
12143 +#ifndef _VSERVER_PERCPU_H
12144 +#define _VSERVER_PERCPU_H
12145 +
12146 +#include "cvirt_def.h"
12147 +#include "sched_def.h"
12148 +
12149 +struct _vx_percpu {
12150 +       struct _vx_cvirt_pc cvirt;
12151 +       struct _vx_sched_pc sched;
12152 +};
12153 +
12154 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12155 +
12156 +#endif /* _VSERVER_PERCPU_H */
12157 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/pid.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/pid.h
12158 --- linux-3.7.1/include/linux/vserver/pid.h     1970-01-01 00:00:00.000000000 +0000
12159 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/pid.h   2012-12-18 15:13:16.000000000 +0000
12160 @@ -0,0 +1,51 @@
12161 +#ifndef _VSERVER_PID_H
12162 +#define _VSERVER_PID_H
12163 +
12164 +/* pid faking stuff */
12165 +
12166 +#define vx_info_map_pid(v, p) \
12167 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12168 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12169 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12170 +#define vx_map_tgid(p) vx_map_pid(p)
12171 +
12172 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12173 +       const char *func, const char *file, int line)
12174 +{
12175 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12176 +               vxfprintk(VXD_CBIT(cvirt, 2),
12177 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12178 +                       vxi, (long long)vxi->vx_flags, pid,
12179 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12180 +                       func, file, line);
12181 +               if (pid == 0)
12182 +                       return 0;
12183 +               if (pid == vxi->vx_initpid)
12184 +                       return 1;
12185 +       }
12186 +       return pid;
12187 +}
12188 +
12189 +#define vx_info_rmap_pid(v, p) \
12190 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12191 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12192 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12193 +
12194 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12195 +       const char *func, const char *file, int line)
12196 +{
12197 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12198 +               vxfprintk(VXD_CBIT(cvirt, 2),
12199 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12200 +                       vxi, (long long)vxi->vx_flags, pid,
12201 +                       (pid == 1) ? vxi->vx_initpid : pid,
12202 +                       func, file, line);
12203 +               if ((pid == 1) && vxi->vx_initpid)
12204 +                       return vxi->vx_initpid;
12205 +               if (pid == vxi->vx_initpid)
12206 +                       return ~0U;
12207 +       }
12208 +       return pid;
12209 +}
12210 +
12211 +#endif
12212 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/sched.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/sched.h
12213 --- linux-3.7.1/include/linux/vserver/sched.h   1970-01-01 00:00:00.000000000 +0000
12214 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/sched.h 2012-12-18 15:13:16.000000000 +0000
12215 @@ -0,0 +1,23 @@
12216 +#ifndef _VSERVER_SCHED_H
12217 +#define _VSERVER_SCHED_H
12218 +
12219 +
12220 +#ifdef __KERNEL__
12221 +
12222 +struct timespec;
12223 +
12224 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12225 +
12226 +
12227 +struct vx_info;
12228 +
12229 +void vx_update_load(struct vx_info *);
12230 +
12231 +
12232 +void vx_update_sched_param(struct _vx_sched *sched,
12233 +       struct _vx_sched_pc *sched_pc);
12234 +
12235 +#endif /* __KERNEL__ */
12236 +#else  /* _VSERVER_SCHED_H */
12237 +#warning duplicate inclusion
12238 +#endif /* _VSERVER_SCHED_H */
12239 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/sched_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/sched_cmd.h
12240 --- linux-3.7.1/include/linux/vserver/sched_cmd.h       1970-01-01 00:00:00.000000000 +0000
12241 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/sched_cmd.h     2012-12-18 15:13:16.000000000 +0000
12242 @@ -0,0 +1,11 @@
12243 +#ifndef _VSERVER_SCHED_CMD_H
12244 +#define _VSERVER_SCHED_CMD_H
12245 +
12246 +
12247 +#include <linux/compiler.h>
12248 +#include <uapi/vserver/sched_cmd.h>
12249 +
12250 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12251 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12252 +
12253 +#endif /* _VSERVER_SCHED_CMD_H */
12254 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/sched_def.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/sched_def.h
12255 --- linux-3.7.1/include/linux/vserver/sched_def.h       1970-01-01 00:00:00.000000000 +0000
12256 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/sched_def.h     2012-12-18 15:13:16.000000000 +0000
12257 @@ -0,0 +1,38 @@
12258 +#ifndef _VSERVER_SCHED_DEF_H
12259 +#define _VSERVER_SCHED_DEF_H
12260 +
12261 +#include <linux/spinlock.h>
12262 +#include <linux/jiffies.h>
12263 +#include <linux/cpumask.h>
12264 +#include <asm/atomic.h>
12265 +#include <asm/param.h>
12266 +
12267 +
12268 +/* context sub struct */
12269 +
12270 +struct _vx_sched {
12271 +       int prio_bias;                  /* bias offset for priority */
12272 +
12273 +       cpumask_t update;               /* CPUs which should update */
12274 +};
12275 +
12276 +struct _vx_sched_pc {
12277 +       int prio_bias;                  /* bias offset for priority */
12278 +
12279 +       uint64_t user_ticks;            /* token tick events */
12280 +       uint64_t sys_ticks;             /* token tick events */
12281 +       uint64_t hold_ticks;            /* token ticks paused */
12282 +};
12283 +
12284 +
12285 +#ifdef CONFIG_VSERVER_DEBUG
12286 +
12287 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12288 +{
12289 +       printk("\t_vx_sched:\n");
12290 +       printk("\t priority = %4d\n", sched->prio_bias);
12291 +}
12292 +
12293 +#endif
12294 +
12295 +#endif /* _VSERVER_SCHED_DEF_H */
12296 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/signal.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/signal.h
12297 --- linux-3.7.1/include/linux/vserver/signal.h  1970-01-01 00:00:00.000000000 +0000
12298 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/signal.h        2012-12-18 15:13:16.000000000 +0000
12299 @@ -0,0 +1,14 @@
12300 +#ifndef _VSERVER_SIGNAL_H
12301 +#define _VSERVER_SIGNAL_H
12302 +
12303 +
12304 +#ifdef __KERNEL__
12305 +
12306 +struct vx_info;
12307 +
12308 +int vx_info_kill(struct vx_info *, int, int);
12309 +
12310 +#endif /* __KERNEL__ */
12311 +#else  /* _VSERVER_SIGNAL_H */
12312 +#warning duplicate inclusion
12313 +#endif /* _VSERVER_SIGNAL_H */
12314 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/signal_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/signal_cmd.h
12315 --- linux-3.7.1/include/linux/vserver/signal_cmd.h      1970-01-01 00:00:00.000000000 +0000
12316 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/signal_cmd.h    2012-12-18 15:13:16.000000000 +0000
12317 @@ -0,0 +1,14 @@
12318 +#ifndef _VSERVER_SIGNAL_CMD_H
12319 +#define _VSERVER_SIGNAL_CMD_H
12320 +
12321 +#include <uapi/vserver/signal_cmd.h>
12322 +
12323 +
12324 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12325 +extern int vc_wait_exit(struct vx_info *, void __user *);
12326 +
12327 +
12328 +extern int vc_get_pflags(uint32_t pid, void __user *);
12329 +extern int vc_set_pflags(uint32_t pid, void __user *);
12330 +
12331 +#endif /* _VSERVER_SIGNAL_CMD_H */
12332 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/space.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/space.h
12333 --- linux-3.7.1/include/linux/vserver/space.h   1970-01-01 00:00:00.000000000 +0000
12334 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/space.h 2012-12-18 15:13:16.000000000 +0000
12335 @@ -0,0 +1,12 @@
12336 +#ifndef _VSERVER_SPACE_H
12337 +#define _VSERVER_SPACE_H
12338 +
12339 +#include <linux/types.h>
12340 +
12341 +struct vx_info;
12342 +
12343 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12344 +
12345 +#else  /* _VSERVER_SPACE_H */
12346 +#warning duplicate inclusion
12347 +#endif /* _VSERVER_SPACE_H */
12348 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/space_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/space_cmd.h
12349 --- linux-3.7.1/include/linux/vserver/space_cmd.h       1970-01-01 00:00:00.000000000 +0000
12350 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/space_cmd.h     2012-12-18 15:13:16.000000000 +0000
12351 @@ -0,0 +1,13 @@
12352 +#ifndef _VSERVER_SPACE_CMD_H
12353 +#define _VSERVER_SPACE_CMD_H
12354 +
12355 +#include <uapi/vserver/space_cmd.h>
12356 +
12357 +
12358 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12359 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12360 +extern int vc_enter_space(struct vx_info *, void __user *);
12361 +extern int vc_set_space(struct vx_info *, void __user *);
12362 +extern int vc_get_space_mask(void __user *, int);
12363 +
12364 +#endif /* _VSERVER_SPACE_CMD_H */
12365 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/switch.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/switch.h
12366 --- linux-3.7.1/include/linux/vserver/switch.h  1970-01-01 00:00:00.000000000 +0000
12367 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/switch.h        2012-12-18 15:13:16.000000000 +0000
12368 @@ -0,0 +1,8 @@
12369 +#ifndef _VSERVER_SWITCH_H
12370 +#define _VSERVER_SWITCH_H
12371 +
12372 +
12373 +#include <linux/errno.h>
12374 +#include <uapi/vserver/switch.h>
12375 +
12376 +#endif /* _VSERVER_SWITCH_H */
12377 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/tag.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/tag.h
12378 --- linux-3.7.1/include/linux/vserver/tag.h     1970-01-01 00:00:00.000000000 +0000
12379 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/tag.h   2012-12-18 15:13:16.000000000 +0000
12380 @@ -0,0 +1,143 @@
12381 +#ifndef _DX_TAG_H
12382 +#define _DX_TAG_H
12383 +
12384 +#include <linux/types.h>
12385 +
12386 +
12387 +#define DX_TAG(in)     (IS_TAGGED(in))
12388 +
12389 +
12390 +#ifdef CONFIG_TAG_NFSD
12391 +#define DX_TAG_NFSD    1
12392 +#else
12393 +#define DX_TAG_NFSD    0
12394 +#endif
12395 +
12396 +
12397 +#ifdef CONFIG_TAGGING_NONE
12398 +
12399 +#define MAX_UID                0xFFFFFFFF
12400 +#define MAX_GID                0xFFFFFFFF
12401 +
12402 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12403 +
12404 +#define TAGINO_UID(cond, uid, tag)     (uid)
12405 +#define TAGINO_GID(cond, gid, tag)     (gid)
12406 +
12407 +#endif
12408 +
12409 +
12410 +#ifdef CONFIG_TAGGING_GID16
12411 +
12412 +#define MAX_UID                0xFFFFFFFF
12413 +#define MAX_GID                0x0000FFFF
12414 +
12415 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12416 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12417 +
12418 +#define TAGINO_UID(cond, uid, tag)     (uid)
12419 +#define TAGINO_GID(cond, gid, tag)     \
12420 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12421 +
12422 +#endif
12423 +
12424 +
12425 +#ifdef CONFIG_TAGGING_ID24
12426 +
12427 +#define MAX_UID                0x00FFFFFF
12428 +#define MAX_GID                0x00FFFFFF
12429 +
12430 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12431 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12432 +
12433 +#define TAGINO_UID(cond, uid, tag)     \
12434 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12435 +#define TAGINO_GID(cond, gid, tag)     \
12436 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12437 +
12438 +#endif
12439 +
12440 +
12441 +#ifdef CONFIG_TAGGING_UID16
12442 +
12443 +#define MAX_UID                0x0000FFFF
12444 +#define MAX_GID                0xFFFFFFFF
12445 +
12446 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12447 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12448 +
12449 +#define TAGINO_UID(cond, uid, tag)     \
12450 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12451 +#define TAGINO_GID(cond, gid, tag)     (gid)
12452 +
12453 +#endif
12454 +
12455 +
12456 +#ifdef CONFIG_TAGGING_INTERN
12457 +
12458 +#define MAX_UID                0xFFFFFFFF
12459 +#define MAX_GID                0xFFFFFFFF
12460 +
12461 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12462 +       ((cond) ? (tag) : 0)
12463 +
12464 +#define TAGINO_UID(cond, uid, tag)     (uid)
12465 +#define TAGINO_GID(cond, gid, tag)     (gid)
12466 +
12467 +#endif
12468 +
12469 +
12470 +#ifndef CONFIG_TAGGING_NONE
12471 +#define dx_current_fstag(sb)   \
12472 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12473 +#else
12474 +#define dx_current_fstag(sb)   (0)
12475 +#endif
12476 +
12477 +#ifndef CONFIG_TAGGING_INTERN
12478 +#define TAGINO_TAG(cond, tag)  (0)
12479 +#else
12480 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12481 +#endif
12482 +
12483 +#define INOTAG_UID(cond, uid, gid)     \
12484 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12485 +#define INOTAG_GID(cond, uid, gid)     \
12486 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12487 +
12488 +
12489 +static inline uid_t dx_map_uid(uid_t uid)
12490 +{
12491 +       if ((uid > MAX_UID) && (uid != -1))
12492 +               uid = -2;
12493 +       return (uid & MAX_UID);
12494 +}
12495 +
12496 +static inline gid_t dx_map_gid(gid_t gid)
12497 +{
12498 +       if ((gid > MAX_GID) && (gid != -1))
12499 +               gid = -2;
12500 +       return (gid & MAX_GID);
12501 +}
12502 +
12503 +struct peer_tag {
12504 +       int32_t xid;
12505 +       int32_t nid;
12506 +};
12507 +
12508 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12509 +
12510 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12511 +                unsigned long *flags);
12512 +
12513 +#ifdef CONFIG_PROPAGATE
12514 +
12515 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12516 +
12517 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12518 +
12519 +#else
12520 +#define dx_propagate_tag(n, i) do { } while (0)
12521 +#endif
12522 +
12523 +#endif /* _DX_TAG_H */
12524 diff -NurpP --minimal linux-3.7.1/include/linux/vserver/tag_cmd.h linux-3.7.1-vs2.3.5.5/include/linux/vserver/tag_cmd.h
12525 --- linux-3.7.1/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12526 +++ linux-3.7.1-vs2.3.5.5/include/linux/vserver/tag_cmd.h       2012-12-18 15:13:16.000000000 +0000
12527 @@ -0,0 +1,10 @@
12528 +#ifndef _VSERVER_TAG_CMD_H
12529 +#define _VSERVER_TAG_CMD_H
12530 +
12531 +#include <uapi/vserver/tag_cmd.h>
12532 +
12533 +extern int vc_task_tag(uint32_t);
12534 +
12535 +extern int vc_tag_migrate(uint32_t);
12536 +
12537 +#endif /* _VSERVER_TAG_CMD_H */
12538 diff -NurpP --minimal linux-3.7.1/include/net/addrconf.h linux-3.7.1-vs2.3.5.5/include/net/addrconf.h
12539 --- linux-3.7.1/include/net/addrconf.h  2012-12-11 03:30:57.000000000 +0000
12540 +++ linux-3.7.1-vs2.3.5.5/include/net/addrconf.h        2012-12-18 15:13:16.000000000 +0000
12541 @@ -81,7 +81,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12542                                                const struct net_device *dev,
12543                                                const struct in6_addr *daddr,
12544                                                unsigned int srcprefs,
12545 -                                              struct in6_addr *saddr);
12546 +                                              struct in6_addr *saddr,
12547 +                                              struct nx_info *nxi);
12548  extern int                     ipv6_get_lladdr(struct net_device *dev,
12549                                                 struct in6_addr *addr,
12550                                                 unsigned char banned_flags);
12551 diff -NurpP --minimal linux-3.7.1/include/net/af_unix.h linux-3.7.1-vs2.3.5.5/include/net/af_unix.h
12552 --- linux-3.7.1/include/net/af_unix.h   2012-12-11 03:30:57.000000000 +0000
12553 +++ linux-3.7.1-vs2.3.5.5/include/net/af_unix.h 2012-12-18 15:13:16.000000000 +0000
12554 @@ -4,6 +4,7 @@
12555  #include <linux/socket.h>
12556  #include <linux/un.h>
12557  #include <linux/mutex.h>
12558 +#include <linux/vs_base.h>
12559  #include <net/sock.h>
12560  
12561  extern void unix_inflight(struct file *fp);
12562 diff -NurpP --minimal linux-3.7.1/include/net/inet_timewait_sock.h linux-3.7.1-vs2.3.5.5/include/net/inet_timewait_sock.h
12563 --- linux-3.7.1/include/net/inet_timewait_sock.h        2012-12-11 03:30:57.000000000 +0000
12564 +++ linux-3.7.1-vs2.3.5.5/include/net/inet_timewait_sock.h      2012-12-18 15:13:16.000000000 +0000
12565 @@ -112,6 +112,10 @@ struct inet_timewait_sock {
12566  #define tw_net                 __tw_common.skc_net
12567  #define tw_daddr               __tw_common.skc_daddr
12568  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
12569 +#define tw_xid                 __tw_common.skc_xid
12570 +#define tw_vx_info             __tw_common.skc_vx_info
12571 +#define tw_nid                 __tw_common.skc_nid
12572 +#define tw_nx_info             __tw_common.skc_nx_info
12573         int                     tw_timeout;
12574         volatile unsigned char  tw_substate;
12575         unsigned char           tw_rcv_wscale;
12576 diff -NurpP --minimal linux-3.7.1/include/net/ip6_route.h linux-3.7.1-vs2.3.5.5/include/net/ip6_route.h
12577 --- linux-3.7.1/include/net/ip6_route.h 2012-12-11 03:30:57.000000000 +0000
12578 +++ linux-3.7.1-vs2.3.5.5/include/net/ip6_route.h       2012-12-18 15:13:16.000000000 +0000
12579 @@ -97,7 +97,8 @@ extern int                    ip6_route_get_saddr(struct
12580                                                     struct rt6_info *rt,
12581                                                     const struct in6_addr *daddr,
12582                                                     unsigned int prefs,
12583 -                                                   struct in6_addr *saddr);
12584 +                                                   struct in6_addr *saddr,
12585 +                                                   struct nx_info *nxi);
12586  
12587  extern struct rt6_info         *rt6_lookup(struct net *net,
12588                                             const struct in6_addr *daddr,
12589 diff -NurpP --minimal linux-3.7.1/include/net/route.h linux-3.7.1-vs2.3.5.5/include/net/route.h
12590 --- linux-3.7.1/include/net/route.h     2012-12-11 03:30:57.000000000 +0000
12591 +++ linux-3.7.1-vs2.3.5.5/include/net/route.h   2012-12-18 15:13:16.000000000 +0000
12592 @@ -204,6 +204,9 @@ static inline void ip_rt_put(struct rtab
12593                 dst_release(&rt->dst);
12594  }
12595  
12596 +#include <linux/vs_base.h>
12597 +#include <linux/vs_inet.h>
12598 +
12599  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12600  
12601  extern const __u8 ip_tos2prio[16];
12602 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
12603                            protocol, flow_flags, dst, src, dport, sport);
12604  }
12605  
12606 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12607 +       struct flowi4 *);
12608 +
12609  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12610                                               __be32 dst, __be32 src, u32 tos,
12611                                               int oif, u8 protocol,
12612 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
12613  {
12614         struct net *net = sock_net(sk);
12615         struct rtable *rt;
12616 +       struct nx_info *nx_info = current_nx_info();
12617  
12618         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12619                               sport, dport, sk, can_sleep);
12620  
12621 -       if (!dst || !src) {
12622 +       if (sk)
12623 +               nx_info = sk->sk_nx_info;
12624 +
12625 +       vxdprintk(VXD_CBIT(net, 4),
12626 +               "ip_route_connect(%p) %p,%p;%lx",
12627 +               sk, nx_info, sk->sk_socket,
12628 +               (sk->sk_socket?sk->sk_socket->flags:0));
12629 +
12630 +       rt = ip_v4_find_src(net, nx_info, fl4);
12631 +       if (IS_ERR(rt))
12632 +               return rt;
12633 +       ip_rt_put(rt);
12634 +
12635 +       if (!fl4->daddr || !fl4->saddr) {
12636                 rt = __ip_route_output_key(net, fl4);
12637                 if (IS_ERR(rt))
12638                         return rt;
12639 diff -NurpP --minimal linux-3.7.1/include/net/sock.h linux-3.7.1-vs2.3.5.5/include/net/sock.h
12640 --- linux-3.7.1/include/net/sock.h      2012-12-11 03:30:57.000000000 +0000
12641 +++ linux-3.7.1-vs2.3.5.5/include/net/sock.h    2012-12-18 15:13:16.000000000 +0000
12642 @@ -171,6 +171,10 @@ struct sock_common {
12643  #ifdef CONFIG_NET_NS
12644         struct net              *skc_net;
12645  #endif
12646 +       xid_t                   skc_xid;
12647 +       struct vx_info          *skc_vx_info;
12648 +       nid_t                   skc_nid;
12649 +       struct nx_info          *skc_nx_info;
12650         /*
12651          * fields between dontcopy_begin/dontcopy_end
12652          * are not copied in sock_copy()
12653 @@ -283,6 +287,10 @@ struct sock {
12654  #define sk_bind_node           __sk_common.skc_bind_node
12655  #define sk_prot                        __sk_common.skc_prot
12656  #define sk_net                 __sk_common.skc_net
12657 +#define sk_xid                 __sk_common.skc_xid
12658 +#define sk_vx_info             __sk_common.skc_vx_info
12659 +#define sk_nid                 __sk_common.skc_nid
12660 +#define sk_nx_info             __sk_common.skc_nx_info
12661         socket_lock_t           sk_lock;
12662         struct sk_buff_head     sk_receive_queue;
12663         /*
12664 diff -NurpP --minimal linux-3.7.1/include/uapi/Kbuild linux-3.7.1-vs2.3.5.5/include/uapi/Kbuild
12665 --- linux-3.7.1/include/uapi/Kbuild     2012-12-11 03:30:57.000000000 +0000
12666 +++ linux-3.7.1-vs2.3.5.5/include/uapi/Kbuild   2012-12-18 15:13:16.000000000 +0000
12667 @@ -12,3 +12,4 @@ header-y += video/
12668  header-y += drm/
12669  header-y += xen/
12670  header-y += scsi/
12671 +header-y += vserver/
12672 diff -NurpP --minimal linux-3.7.1/include/uapi/linux/capability.h linux-3.7.1-vs2.3.5.5/include/uapi/linux/capability.h
12673 --- linux-3.7.1/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12674 +++ linux-3.7.1-vs2.3.5.5/include/uapi/linux/capability.h       2012-12-18 15:13:16.000000000 +0000
12675 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12676     arbitrary SCSI commands */
12677  /* Allow setting encryption key on loopback filesystem */
12678  /* Allow setting zone reclaim policy */
12679 +/* Allow the selection of a security context */
12680  
12681  #define CAP_SYS_ADMIN        21
12682  
12683 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12684  
12685  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12686  
12687 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12688 +/* Allow context manipulations */
12689 +/* Allow changing context info on files */
12690 +
12691 +#define CAP_CONTEXT         63
12692 +
12693 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12694  
12695  /*
12696   * Bit location of each capability (used by user-space library and kernel)
12697 diff -NurpP --minimal linux-3.7.1/include/uapi/linux/fs.h linux-3.7.1-vs2.3.5.5/include/uapi/linux/fs.h
12698 --- linux-3.7.1/include/uapi/linux/fs.h 2012-12-11 03:30:57.000000000 +0000
12699 +++ linux-3.7.1-vs2.3.5.5/include/uapi/linux/fs.h       2012-12-18 15:13:16.000000000 +0000
12700 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12701  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12702  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12703  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12704 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
12705 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
12706 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
12707  #define MS_NOSEC       (1<<28)
12708  #define MS_BORN                (1<<29)
12709  #define MS_ACTIVE      (1<<30)
12710 @@ -189,11 +192,14 @@ struct inodes_stat_t {
12711  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12712  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12713  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12714 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12715  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12716  
12717 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12718 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12719 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12720 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12721  
12722 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12723 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12724  
12725  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12726  #define SYNC_FILE_RANGE_WRITE          2
12727 diff -NurpP --minimal linux-3.7.1/include/uapi/linux/gfs2_ondisk.h linux-3.7.1-vs2.3.5.5/include/uapi/linux/gfs2_ondisk.h
12728 --- linux-3.7.1/include/uapi/linux/gfs2_ondisk.h        2012-12-11 03:30:57.000000000 +0000
12729 +++ linux-3.7.1-vs2.3.5.5/include/uapi/linux/gfs2_ondisk.h      2012-12-18 15:13:16.000000000 +0000
12730 @@ -225,6 +225,9 @@ enum {
12731         gfs2fl_Sync             = 8,
12732         gfs2fl_System           = 9,
12733         gfs2fl_TopLevel         = 10,
12734 +       gfs2fl_IXUnlink         = 16,
12735 +       gfs2fl_Barrier          = 17,
12736 +       gfs2fl_Cow              = 18,
12737         gfs2fl_TruncInProg      = 29,
12738         gfs2fl_InheritDirectio  = 30,
12739         gfs2fl_InheritJdata     = 31,
12740 @@ -242,6 +245,9 @@ enum {
12741  #define GFS2_DIF_SYNC                  0x00000100
12742  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12743  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12744 +#define GFS2_DIF_IXUNLINK               0x00010000
12745 +#define GFS2_DIF_BARRIER                0x00020000
12746 +#define GFS2_DIF_COW                    0x00040000
12747  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12748  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12749  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12750 diff -NurpP --minimal linux-3.7.1/include/uapi/linux/if_tun.h linux-3.7.1-vs2.3.5.5/include/uapi/linux/if_tun.h
12751 --- linux-3.7.1/include/uapi/linux/if_tun.h     2012-12-11 03:30:57.000000000 +0000
12752 +++ linux-3.7.1-vs2.3.5.5/include/uapi/linux/if_tun.h   2012-12-18 15:13:16.000000000 +0000
12753 @@ -53,6 +53,7 @@
12754  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
12755  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12756  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12757 +#define TUNSETNID     _IOW('T', 217, int)
12758  
12759  /* TUNSETIFF ifr flags */
12760  #define IFF_TUN                0x0001
12761 diff -NurpP --minimal linux-3.7.1/include/uapi/linux/major.h linux-3.7.1-vs2.3.5.5/include/uapi/linux/major.h
12762 --- linux-3.7.1/include/uapi/linux/major.h      2012-12-11 03:30:57.000000000 +0000
12763 +++ linux-3.7.1-vs2.3.5.5/include/uapi/linux/major.h    2012-12-18 15:13:16.000000000 +0000
12764 @@ -15,6 +15,7 @@
12765  #define HD_MAJOR               IDE0_MAJOR
12766  #define PTY_SLAVE_MAJOR                3
12767  #define TTY_MAJOR              4
12768 +#define VROOT_MAJOR            4
12769  #define TTYAUX_MAJOR           5
12770  #define LP_MAJOR               6
12771  #define VCS_MAJOR              7
12772 diff -NurpP --minimal linux-3.7.1/include/uapi/linux/nfs_mount.h linux-3.7.1-vs2.3.5.5/include/uapi/linux/nfs_mount.h
12773 --- linux-3.7.1/include/uapi/linux/nfs_mount.h  2012-12-11 03:30:57.000000000 +0000
12774 +++ linux-3.7.1-vs2.3.5.5/include/uapi/linux/nfs_mount.h        2012-12-18 15:13:16.000000000 +0000
12775 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12776  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12777  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12778  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12779 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12780 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12781 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12782  
12783  /* The following are for internal use only */
12784  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12785 diff -NurpP --minimal linux-3.7.1/include/uapi/linux/reboot.h linux-3.7.1-vs2.3.5.5/include/uapi/linux/reboot.h
12786 --- linux-3.7.1/include/uapi/linux/reboot.h     2012-12-11 03:30:57.000000000 +0000
12787 +++ linux-3.7.1-vs2.3.5.5/include/uapi/linux/reboot.h   2012-12-18 15:13:16.000000000 +0000
12788 @@ -33,7 +33,7 @@
12789  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12790  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12791  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12792 -
12793 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12794  
12795  
12796  #endif /* _UAPI_LINUX_REBOOT_H */
12797 diff -NurpP --minimal linux-3.7.1/include/uapi/linux/sysctl.h linux-3.7.1-vs2.3.5.5/include/uapi/linux/sysctl.h
12798 --- linux-3.7.1/include/uapi/linux/sysctl.h     2012-12-11 03:30:57.000000000 +0000
12799 +++ linux-3.7.1-vs2.3.5.5/include/uapi/linux/sysctl.h   2012-12-18 15:13:16.000000000 +0000
12800 @@ -60,6 +60,7 @@ enum
12801         CTL_ABI=9,              /* Binary emulation */
12802         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12803         CTL_ARLAN=254,          /* arlan wireless driver */
12804 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12805         CTL_S390DBF=5677,       /* s390 debug */
12806         CTL_SUNRPC=7249,        /* sunrpc debug */
12807         CTL_PM=9899,            /* frv power management */
12808 @@ -94,6 +95,7 @@ enum
12809  
12810         KERN_PANIC=15,          /* int: panic timeout */
12811         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12812 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12813  
12814         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12815         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12816 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/Kbuild linux-3.7.1-vs2.3.5.5/include/uapi/vserver/Kbuild
12817 --- linux-3.7.1/include/uapi/vserver/Kbuild     1970-01-01 00:00:00.000000000 +0000
12818 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/Kbuild   2012-12-18 15:13:16.000000000 +0000
12819 @@ -0,0 +1,9 @@
12820 +
12821 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12822 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12823 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12824 +       debug_cmd.h device_cmd.h
12825 +
12826 +header-y += switch.h context.h network.h monitor.h \
12827 +       limit.h inode.h device.h
12828 +
12829 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/cacct_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/cacct_cmd.h
12830 --- linux-3.7.1/include/uapi/vserver/cacct_cmd.h        1970-01-01 00:00:00.000000000 +0000
12831 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/cacct_cmd.h      2012-12-18 15:13:16.000000000 +0000
12832 @@ -0,0 +1,15 @@
12833 +#ifndef _UAPI_VS_CACCT_CMD_H
12834 +#define _UAPI_VS_CACCT_CMD_H
12835 +
12836 +
12837 +/* virtual host info name commands */
12838 +
12839 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12840 +
12841 +struct vcmd_sock_stat_v0 {
12842 +       uint32_t field;
12843 +       uint32_t count[3];
12844 +       uint64_t total[3];
12845 +};
12846 +
12847 +#endif /* _UAPI_VS_CACCT_CMD_H */
12848 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/context.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/context.h
12849 --- linux-3.7.1/include/uapi/vserver/context.h  1970-01-01 00:00:00.000000000 +0000
12850 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/context.h        2012-12-18 15:13:16.000000000 +0000
12851 @@ -0,0 +1,80 @@
12852 +#ifndef _UAPI_VS_CONTEXT_H
12853 +#define _UAPI_VS_CONTEXT_H
12854 +
12855 +#include <linux/types.h>
12856 +#include <linux/capability.h>
12857 +
12858 +
12859 +/* context flags */
12860 +
12861 +#define VXF_INFO_SCHED         0x00000002
12862 +#define VXF_INFO_NPROC         0x00000004
12863 +#define VXF_INFO_PRIVATE       0x00000008
12864 +
12865 +#define VXF_INFO_INIT          0x00000010
12866 +#define VXF_INFO_HIDE          0x00000020
12867 +#define VXF_INFO_ULIMIT                0x00000040
12868 +#define VXF_INFO_NSPACE                0x00000080
12869 +
12870 +#define VXF_SCHED_HARD         0x00000100
12871 +#define VXF_SCHED_PRIO         0x00000200
12872 +#define VXF_SCHED_PAUSE                0x00000400
12873 +
12874 +#define VXF_VIRT_MEM           0x00010000
12875 +#define VXF_VIRT_UPTIME                0x00020000
12876 +#define VXF_VIRT_CPU           0x00040000
12877 +#define VXF_VIRT_LOAD          0x00080000
12878 +#define VXF_VIRT_TIME          0x00100000
12879 +
12880 +#define VXF_HIDE_MOUNT         0x01000000
12881 +/* was VXF_HIDE_NETIF          0x02000000 */
12882 +#define VXF_HIDE_VINFO         0x04000000
12883 +
12884 +#define VXF_STATE_SETUP                (1ULL << 32)
12885 +#define VXF_STATE_INIT         (1ULL << 33)
12886 +#define VXF_STATE_ADMIN                (1ULL << 34)
12887 +
12888 +#define VXF_SC_HELPER          (1ULL << 36)
12889 +#define VXF_REBOOT_KILL                (1ULL << 37)
12890 +#define VXF_PERSISTENT         (1ULL << 38)
12891 +
12892 +#define VXF_FORK_RSS           (1ULL << 48)
12893 +#define VXF_PROLIFIC           (1ULL << 49)
12894 +
12895 +#define VXF_IGNEG_NICE         (1ULL << 52)
12896 +
12897 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12898 +
12899 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12900 +
12901 +
12902 +/* context migration */
12903 +
12904 +#define VXM_SET_INIT           0x00000001
12905 +#define VXM_SET_REAPER         0x00000002
12906 +
12907 +/* context caps */
12908 +
12909 +#define VXC_SET_UTSNAME                0x00000001
12910 +#define VXC_SET_RLIMIT         0x00000002
12911 +#define VXC_FS_SECURITY                0x00000004
12912 +#define VXC_FS_TRUSTED         0x00000008
12913 +#define VXC_TIOCSTI            0x00000010
12914 +
12915 +/* was VXC_RAW_ICMP            0x00000100 */
12916 +#define VXC_SYSLOG             0x00001000
12917 +#define VXC_OOM_ADJUST         0x00002000
12918 +#define VXC_AUDIT_CONTROL      0x00004000
12919 +
12920 +#define VXC_SECURE_MOUNT       0x00010000
12921 +#define VXC_SECURE_REMOUNT     0x00020000
12922 +#define VXC_BINARY_MOUNT       0x00040000
12923 +
12924 +#define VXC_QUOTA_CTL          0x00100000
12925 +#define VXC_ADMIN_MAPPER       0x00200000
12926 +#define VXC_ADMIN_CLOOP                0x00400000
12927 +
12928 +#define VXC_KTHREAD            0x01000000
12929 +#define VXC_NAMESPACE          0x02000000
12930 +
12931 +#endif /* _UAPI_VS_CONTEXT_H */
12932 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/context_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/context_cmd.h
12933 --- linux-3.7.1/include/uapi/vserver/context_cmd.h      1970-01-01 00:00:00.000000000 +0000
12934 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/context_cmd.h    2012-12-18 15:13:16.000000000 +0000
12935 @@ -0,0 +1,115 @@
12936 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12937 +#define _UAPI_VS_CONTEXT_CMD_H
12938 +
12939 +
12940 +/* vinfo commands */
12941 +
12942 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12943 +
12944 +
12945 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12946 +
12947 +struct vcmd_vx_info_v0 {
12948 +       uint32_t xid;
12949 +       uint32_t initpid;
12950 +       /* more to come */
12951 +};
12952 +
12953 +
12954 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12955 +
12956 +struct vcmd_ctx_stat_v0 {
12957 +       uint32_t usecnt;
12958 +       uint32_t tasks;
12959 +       /* more to come */
12960 +};
12961 +
12962 +
12963 +/* context commands */
12964 +
12965 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12966 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12967 +
12968 +struct vcmd_ctx_create {
12969 +       uint64_t flagword;
12970 +};
12971 +
12972 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12973 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12974 +
12975 +struct vcmd_ctx_migrate {
12976 +       uint64_t flagword;
12977 +};
12978 +
12979 +
12980 +
12981 +/* flag commands */
12982 +
12983 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12984 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12985 +
12986 +struct vcmd_ctx_flags_v0 {
12987 +       uint64_t flagword;
12988 +       uint64_t mask;
12989 +};
12990 +
12991 +
12992 +
12993 +/* context caps commands */
12994 +
12995 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12996 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12997 +
12998 +struct vcmd_ctx_caps_v1 {
12999 +       uint64_t ccaps;
13000 +       uint64_t cmask;
13001 +};
13002 +
13003 +
13004 +
13005 +/* bcaps commands */
13006 +
13007 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
13008 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
13009 +
13010 +struct vcmd_bcaps {
13011 +       uint64_t bcaps;
13012 +       uint64_t bmask;
13013 +};
13014 +
13015 +
13016 +
13017 +/* umask commands */
13018 +
13019 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
13020 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
13021 +
13022 +struct vcmd_umask {
13023 +       uint64_t umask;
13024 +       uint64_t mask;
13025 +};
13026 +
13027 +
13028 +
13029 +/* wmask commands */
13030 +
13031 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
13032 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
13033 +
13034 +struct vcmd_wmask {
13035 +       uint64_t wmask;
13036 +       uint64_t mask;
13037 +};
13038 +
13039 +
13040 +
13041 +/* OOM badness */
13042 +
13043 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
13044 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
13045 +
13046 +struct vcmd_badness_v0 {
13047 +       int64_t bias;
13048 +};
13049 +
13050 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
13051 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/cvirt_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/cvirt_cmd.h
13052 --- linux-3.7.1/include/uapi/vserver/cvirt_cmd.h        1970-01-01 00:00:00.000000000 +0000
13053 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/cvirt_cmd.h      2012-12-18 15:13:16.000000000 +0000
13054 @@ -0,0 +1,41 @@
13055 +#ifndef _UAPI_VS_CVIRT_CMD_H
13056 +#define _UAPI_VS_CVIRT_CMD_H
13057 +
13058 +
13059 +/* virtual host info name commands */
13060 +
13061 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
13062 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
13063 +
13064 +struct vcmd_vhi_name_v0 {
13065 +       uint32_t field;
13066 +       char name[65];
13067 +};
13068 +
13069 +
13070 +enum vhi_name_field {
13071 +       VHIN_CONTEXT = 0,
13072 +       VHIN_SYSNAME,
13073 +       VHIN_NODENAME,
13074 +       VHIN_RELEASE,
13075 +       VHIN_VERSION,
13076 +       VHIN_MACHINE,
13077 +       VHIN_DOMAINNAME,
13078 +};
13079 +
13080 +
13081 +
13082 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
13083 +
13084 +struct vcmd_virt_stat_v0 {
13085 +       uint64_t offset;
13086 +       uint64_t uptime;
13087 +       uint32_t nr_threads;
13088 +       uint32_t nr_running;
13089 +       uint32_t nr_uninterruptible;
13090 +       uint32_t nr_onhold;
13091 +       uint32_t nr_forks;
13092 +       uint32_t load[3];
13093 +};
13094 +
13095 +#endif /* _UAPI_VS_CVIRT_CMD_H */
13096 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/debug_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/debug_cmd.h
13097 --- linux-3.7.1/include/uapi/vserver/debug_cmd.h        1970-01-01 00:00:00.000000000 +0000
13098 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/debug_cmd.h      2012-12-18 15:13:16.000000000 +0000
13099 @@ -0,0 +1,24 @@
13100 +#ifndef _UAPI_VS_DEBUG_CMD_H
13101 +#define _UAPI_VS_DEBUG_CMD_H
13102 +
13103 +
13104 +/* debug commands */
13105 +
13106 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
13107 +
13108 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
13109 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
13110 +
13111 +struct  vcmd_read_history_v0 {
13112 +       uint32_t index;
13113 +       uint32_t count;
13114 +       char __user *data;
13115 +};
13116 +
13117 +struct  vcmd_read_monitor_v0 {
13118 +       uint32_t index;
13119 +       uint32_t count;
13120 +       char __user *data;
13121 +};
13122 +
13123 +#endif /* _UAPI_VS_DEBUG_CMD_H */
13124 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/device.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/device.h
13125 --- linux-3.7.1/include/uapi/vserver/device.h   1970-01-01 00:00:00.000000000 +0000
13126 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/device.h 2012-12-18 15:13:16.000000000 +0000
13127 @@ -0,0 +1,12 @@
13128 +#ifndef _UAPI_VS_DEVICE_H
13129 +#define _UAPI_VS_DEVICE_H
13130 +
13131 +
13132 +#define DATTR_CREATE   0x00000001
13133 +#define DATTR_OPEN     0x00000002
13134 +
13135 +#define DATTR_REMAP    0x00000010
13136 +
13137 +#define DATTR_MASK     0x00000013
13138 +
13139 +#endif /* _UAPI_VS_DEVICE_H */
13140 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/device_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/device_cmd.h
13141 --- linux-3.7.1/include/uapi/vserver/device_cmd.h       1970-01-01 00:00:00.000000000 +0000
13142 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/device_cmd.h     2012-12-18 15:13:16.000000000 +0000
13143 @@ -0,0 +1,16 @@
13144 +#ifndef _UAPI_VS_DEVICE_CMD_H
13145 +#define _UAPI_VS_DEVICE_CMD_H
13146 +
13147 +
13148 +/*  device vserver commands */
13149 +
13150 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
13151 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
13152 +
13153 +struct vcmd_set_mapping_v0 {
13154 +       const char __user *device;
13155 +       const char __user *target;
13156 +       uint32_t flags;
13157 +};
13158 +
13159 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13160 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/dlimit_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/dlimit_cmd.h
13161 --- linux-3.7.1/include/uapi/vserver/dlimit_cmd.h       1970-01-01 00:00:00.000000000 +0000
13162 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/dlimit_cmd.h     2012-12-18 15:13:16.000000000 +0000
13163 @@ -0,0 +1,67 @@
13164 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13165 +#define _UAPI_VS_DLIMIT_CMD_H
13166 +
13167 +
13168 +/*  dlimit vserver commands */
13169 +
13170 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
13171 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
13172 +
13173 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
13174 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
13175 +
13176 +struct vcmd_ctx_dlimit_base_v0 {
13177 +       const char __user *name;
13178 +       uint32_t flags;
13179 +};
13180 +
13181 +struct vcmd_ctx_dlimit_v0 {
13182 +       const char __user *name;
13183 +       uint32_t space_used;                    /* used space in kbytes */
13184 +       uint32_t space_total;                   /* maximum space in kbytes */
13185 +       uint32_t inodes_used;                   /* used inodes */
13186 +       uint32_t inodes_total;                  /* maximum inodes */
13187 +       uint32_t reserved;                      /* reserved for root in % */
13188 +       uint32_t flags;
13189 +};
13190 +
13191 +#define CDLIM_UNSET            ((uint32_t)0UL)
13192 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
13193 +#define CDLIM_KEEP             ((uint32_t)~1UL)
13194 +
13195 +#define DLIME_UNIT     0
13196 +#define DLIME_KILO     1
13197 +#define DLIME_MEGA     2
13198 +#define DLIME_GIGA     3
13199 +
13200 +#define DLIMF_SHIFT    0x10
13201 +
13202 +#define DLIMS_USED     0
13203 +#define DLIMS_TOTAL    2
13204 +
13205 +static inline
13206 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13207 +{
13208 +       int exp = (flags & DLIMF_SHIFT) ?
13209 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13210 +       return ((uint64_t)val) << (10 * exp);
13211 +}
13212 +
13213 +static inline
13214 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13215 +{
13216 +       int exp = 0;
13217 +
13218 +       if (*flags & DLIMF_SHIFT) {
13219 +               while (val > (1LL << 32) && (exp < 3)) {
13220 +                       val >>= 10;
13221 +                       exp++;
13222 +               }
13223 +               *flags &= ~(DLIME_GIGA << shift);
13224 +               *flags |= exp << shift;
13225 +       } else
13226 +               val >>= 10;
13227 +       return val;
13228 +}
13229 +
13230 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13231 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/inode.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/inode.h
13232 --- linux-3.7.1/include/uapi/vserver/inode.h    1970-01-01 00:00:00.000000000 +0000
13233 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/inode.h  2012-12-18 15:13:16.000000000 +0000
13234 @@ -0,0 +1,23 @@
13235 +#ifndef _UAPI_VS_INODE_H
13236 +#define _UAPI_VS_INODE_H
13237 +
13238 +
13239 +#define IATTR_TAG      0x01000000
13240 +
13241 +#define IATTR_ADMIN    0x00000001
13242 +#define IATTR_WATCH    0x00000002
13243 +#define IATTR_HIDE     0x00000004
13244 +#define IATTR_FLAGS    0x00000007
13245 +
13246 +#define IATTR_BARRIER  0x00010000
13247 +#define IATTR_IXUNLINK 0x00020000
13248 +#define IATTR_IMMUTABLE 0x00040000
13249 +#define IATTR_COW      0x00080000
13250 +
13251 +
13252 +/* inode ioctls */
13253 +
13254 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13255 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13256 +
13257 +#endif /* _UAPI_VS_INODE_H */
13258 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/inode_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/inode_cmd.h
13259 --- linux-3.7.1/include/uapi/vserver/inode_cmd.h        1970-01-01 00:00:00.000000000 +0000
13260 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/inode_cmd.h      2012-12-18 15:13:16.000000000 +0000
13261 @@ -0,0 +1,26 @@
13262 +#ifndef _UAPI_VS_INODE_CMD_H
13263 +#define _UAPI_VS_INODE_CMD_H
13264 +
13265 +
13266 +/*  inode vserver commands */
13267 +
13268 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13269 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13270 +
13271 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13272 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13273 +
13274 +struct vcmd_ctx_iattr_v1 {
13275 +       const char __user *name;
13276 +       uint32_t tag;
13277 +       uint32_t flags;
13278 +       uint32_t mask;
13279 +};
13280 +
13281 +struct vcmd_ctx_fiattr_v0 {
13282 +       uint32_t tag;
13283 +       uint32_t flags;
13284 +       uint32_t mask;
13285 +};
13286 +
13287 +#endif /* _UAPI_VS_INODE_CMD_H */
13288 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/limit.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/limit.h
13289 --- linux-3.7.1/include/uapi/vserver/limit.h    1970-01-01 00:00:00.000000000 +0000
13290 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/limit.h  2012-12-18 15:13:16.000000000 +0000
13291 @@ -0,0 +1,14 @@
13292 +#ifndef _UAPI_VS_LIMIT_H
13293 +#define _UAPI_VS_LIMIT_H
13294 +
13295 +
13296 +#define VLIMIT_NSOCK   16
13297 +#define VLIMIT_OPENFD  17
13298 +#define VLIMIT_ANON    18
13299 +#define VLIMIT_SHMEM   19
13300 +#define VLIMIT_SEMARY  20
13301 +#define VLIMIT_NSEMS   21
13302 +#define VLIMIT_DENTRY  22
13303 +#define VLIMIT_MAPPED  23
13304 +
13305 +#endif /* _UAPI_VS_LIMIT_H */
13306 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/limit_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/limit_cmd.h
13307 --- linux-3.7.1/include/uapi/vserver/limit_cmd.h        1970-01-01 00:00:00.000000000 +0000
13308 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/limit_cmd.h      2012-12-18 15:13:16.000000000 +0000
13309 @@ -0,0 +1,40 @@
13310 +#ifndef _UAPI_VS_LIMIT_CMD_H
13311 +#define _UAPI_VS_LIMIT_CMD_H
13312 +
13313 +
13314 +/*  rlimit vserver commands */
13315 +
13316 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13317 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13318 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13319 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13320 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13321 +
13322 +struct vcmd_ctx_rlimit_v0 {
13323 +       uint32_t id;
13324 +       uint64_t minimum;
13325 +       uint64_t softlimit;
13326 +       uint64_t maximum;
13327 +};
13328 +
13329 +struct vcmd_ctx_rlimit_mask_v0 {
13330 +       uint32_t minimum;
13331 +       uint32_t softlimit;
13332 +       uint32_t maximum;
13333 +};
13334 +
13335 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13336 +
13337 +struct vcmd_rlimit_stat_v0 {
13338 +       uint32_t id;
13339 +       uint32_t hits;
13340 +       uint64_t value;
13341 +       uint64_t minimum;
13342 +       uint64_t maximum;
13343 +};
13344 +
13345 +#define CRLIM_UNSET            (0ULL)
13346 +#define CRLIM_INFINITY         (~0ULL)
13347 +#define CRLIM_KEEP             (~1ULL)
13348 +
13349 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13350 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/monitor.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/monitor.h
13351 --- linux-3.7.1/include/uapi/vserver/monitor.h  1970-01-01 00:00:00.000000000 +0000
13352 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/monitor.h        2012-12-18 15:13:16.000000000 +0000
13353 @@ -0,0 +1,96 @@
13354 +#ifndef _UAPI_VS_MONITOR_H
13355 +#define _UAPI_VS_MONITOR_H
13356 +
13357 +#include <linux/types.h>
13358 +
13359 +
13360 +enum {
13361 +       VXM_UNUSED = 0,
13362 +
13363 +       VXM_SYNC = 0x10,
13364 +
13365 +       VXM_UPDATE = 0x20,
13366 +       VXM_UPDATE_1,
13367 +       VXM_UPDATE_2,
13368 +
13369 +       VXM_RQINFO_1 = 0x24,
13370 +       VXM_RQINFO_2,
13371 +
13372 +       VXM_ACTIVATE = 0x40,
13373 +       VXM_DEACTIVATE,
13374 +       VXM_IDLE,
13375 +
13376 +       VXM_HOLD = 0x44,
13377 +       VXM_UNHOLD,
13378 +
13379 +       VXM_MIGRATE = 0x48,
13380 +       VXM_RESCHED,
13381 +
13382 +       /* all other bits are flags */
13383 +       VXM_SCHED = 0x80,
13384 +};
13385 +
13386 +struct _vxm_update_1 {
13387 +       uint32_t tokens_max;
13388 +       uint32_t fill_rate;
13389 +       uint32_t interval;
13390 +};
13391 +
13392 +struct _vxm_update_2 {
13393 +       uint32_t tokens_min;
13394 +       uint32_t fill_rate;
13395 +       uint32_t interval;
13396 +};
13397 +
13398 +struct _vxm_rqinfo_1 {
13399 +       uint16_t running;
13400 +       uint16_t onhold;
13401 +       uint16_t iowait;
13402 +       uint16_t uintr;
13403 +       uint32_t idle_tokens;
13404 +};
13405 +
13406 +struct _vxm_rqinfo_2 {
13407 +       uint32_t norm_time;
13408 +       uint32_t idle_time;
13409 +       uint32_t idle_skip;
13410 +};
13411 +
13412 +struct _vxm_sched {
13413 +       uint32_t tokens;
13414 +       uint32_t norm_time;
13415 +       uint32_t idle_time;
13416 +};
13417 +
13418 +struct _vxm_task {
13419 +       uint16_t pid;
13420 +       uint16_t state;
13421 +};
13422 +
13423 +struct _vxm_event {
13424 +       uint32_t jif;
13425 +       union {
13426 +               uint32_t seq;
13427 +               uint32_t sec;
13428 +       };
13429 +       union {
13430 +               uint32_t tokens;
13431 +               uint32_t nsec;
13432 +               struct _vxm_task tsk;
13433 +       };
13434 +};
13435 +
13436 +struct _vx_mon_entry {
13437 +       uint16_t type;
13438 +       uint16_t xid;
13439 +       union {
13440 +               struct _vxm_event ev;
13441 +               struct _vxm_sched sd;
13442 +               struct _vxm_update_1 u1;
13443 +               struct _vxm_update_2 u2;
13444 +               struct _vxm_rqinfo_1 q1;
13445 +               struct _vxm_rqinfo_2 q2;
13446 +       };
13447 +};
13448 +
13449 +#endif /* _UAPI_VS_MONITOR_H */
13450 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/network.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/network.h
13451 --- linux-3.7.1/include/uapi/vserver/network.h  1970-01-01 00:00:00.000000000 +0000
13452 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/network.h        2012-12-18 15:13:16.000000000 +0000
13453 @@ -0,0 +1,76 @@
13454 +#ifndef _UAPI_VS_NETWORK_H
13455 +#define _UAPI_VS_NETWORK_H
13456 +
13457 +#include <linux/types.h>
13458 +
13459 +
13460 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13461 +
13462 +
13463 +/* network flags */
13464 +
13465 +#define NXF_INFO_PRIVATE       0x00000008
13466 +
13467 +#define NXF_SINGLE_IP          0x00000100
13468 +#define NXF_LBACK_REMAP                0x00000200
13469 +#define NXF_LBACK_ALLOW                0x00000400
13470 +
13471 +#define NXF_HIDE_NETIF         0x02000000
13472 +#define NXF_HIDE_LBACK         0x04000000
13473 +
13474 +#define NXF_STATE_SETUP                (1ULL << 32)
13475 +#define NXF_STATE_ADMIN                (1ULL << 34)
13476 +
13477 +#define NXF_SC_HELPER          (1ULL << 36)
13478 +#define NXF_PERSISTENT         (1ULL << 38)
13479 +
13480 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13481 +
13482 +
13483 +#define        NXF_INIT_SET            (__nxf_init_set())
13484 +
13485 +static inline uint64_t __nxf_init_set(void) {
13486 +       return    NXF_STATE_ADMIN
13487 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13488 +               | NXF_LBACK_REMAP
13489 +               | NXF_HIDE_LBACK
13490 +#endif
13491 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13492 +               | NXF_SINGLE_IP
13493 +#endif
13494 +               | NXF_HIDE_NETIF;
13495 +}
13496 +
13497 +
13498 +/* network caps */
13499 +
13500 +#define NXC_TUN_CREATE         0x00000001
13501 +
13502 +#define NXC_RAW_ICMP           0x00000100
13503 +
13504 +#define NXC_MULTICAST          0x00001000
13505 +
13506 +
13507 +/* address types */
13508 +
13509 +#define NXA_TYPE_IPV4          0x0001
13510 +#define NXA_TYPE_IPV6          0x0002
13511 +
13512 +#define NXA_TYPE_NONE          0x0000
13513 +#define NXA_TYPE_ANY           0x00FF
13514 +
13515 +#define NXA_TYPE_ADDR          0x0010
13516 +#define NXA_TYPE_MASK          0x0020
13517 +#define NXA_TYPE_RANGE         0x0040
13518 +
13519 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13520 +
13521 +#define NXA_MOD_BCAST          0x0100
13522 +#define NXA_MOD_LBACK          0x0200
13523 +
13524 +#define NXA_LOOPBACK           0x1000
13525 +
13526 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13527 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13528 +
13529 +#endif /* _UAPI_VS_NETWORK_H */
13530 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/network_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/network_cmd.h
13531 --- linux-3.7.1/include/uapi/vserver/network_cmd.h      1970-01-01 00:00:00.000000000 +0000
13532 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/network_cmd.h    2012-12-18 15:13:16.000000000 +0000
13533 @@ -0,0 +1,123 @@
13534 +#ifndef _UAPI_VS_NETWORK_CMD_H
13535 +#define _UAPI_VS_NETWORK_CMD_H
13536 +
13537 +
13538 +/* vinfo commands */
13539 +
13540 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13541 +
13542 +
13543 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13544 +
13545 +struct vcmd_nx_info_v0 {
13546 +       uint32_t nid;
13547 +       /* more to come */
13548 +};
13549 +
13550 +
13551 +#include <linux/in.h>
13552 +#include <linux/in6.h>
13553 +
13554 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13555 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13556 +
13557 +struct  vcmd_net_create {
13558 +       uint64_t flagword;
13559 +};
13560 +
13561 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13562 +
13563 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13564 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13565 +
13566 +struct vcmd_net_addr_v0 {
13567 +       uint16_t type;
13568 +       uint16_t count;
13569 +       struct in_addr ip[4];
13570 +       struct in_addr mask[4];
13571 +};
13572 +
13573 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13574 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13575 +
13576 +struct vcmd_net_addr_ipv4_v1 {
13577 +       uint16_t type;
13578 +       uint16_t flags;
13579 +       struct in_addr ip;
13580 +       struct in_addr mask;
13581 +};
13582 +
13583 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13584 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13585 +
13586 +struct vcmd_net_addr_ipv4_v2 {
13587 +       uint16_t type;
13588 +       uint16_t flags;
13589 +       struct in_addr ip;
13590 +       struct in_addr ip2;
13591 +       struct in_addr mask;
13592 +};
13593 +
13594 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13595 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13596 +
13597 +struct vcmd_net_addr_ipv6_v1 {
13598 +       uint16_t type;
13599 +       uint16_t flags;
13600 +       uint32_t prefix;
13601 +       struct in6_addr ip;
13602 +       struct in6_addr mask;
13603 +};
13604 +
13605 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13606 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13607 +
13608 +struct vcmd_match_ipv4_v0 {
13609 +       uint16_t type;
13610 +       uint16_t flags;
13611 +       uint16_t parent;
13612 +       uint16_t prefix;
13613 +       struct in_addr ip;
13614 +       struct in_addr ip2;
13615 +       struct in_addr mask;
13616 +};
13617 +
13618 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13619 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13620 +
13621 +struct vcmd_match_ipv6_v0 {
13622 +       uint16_t type;
13623 +       uint16_t flags;
13624 +       uint16_t parent;
13625 +       uint16_t prefix;
13626 +       struct in6_addr ip;
13627 +       struct in6_addr ip2;
13628 +       struct in6_addr mask;
13629 +};
13630 +
13631 +
13632 +
13633 +
13634 +/* flag commands */
13635 +
13636 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13637 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13638 +
13639 +struct vcmd_net_flags_v0 {
13640 +       uint64_t flagword;
13641 +       uint64_t mask;
13642 +};
13643 +
13644 +
13645 +
13646 +/* network caps commands */
13647 +
13648 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13649 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13650 +
13651 +struct vcmd_net_caps_v0 {
13652 +       uint64_t ncaps;
13653 +       uint64_t cmask;
13654 +};
13655 +
13656 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13657 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/sched_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/sched_cmd.h
13658 --- linux-3.7.1/include/uapi/vserver/sched_cmd.h        1970-01-01 00:00:00.000000000 +0000
13659 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/sched_cmd.h      2012-12-18 15:13:16.000000000 +0000
13660 @@ -0,0 +1,13 @@
13661 +#ifndef _UAPI_VS_SCHED_CMD_H
13662 +#define _UAPI_VS_SCHED_CMD_H
13663 +
13664 +
13665 +struct vcmd_prio_bias {
13666 +       int32_t cpu_id;
13667 +       int32_t prio_bias;
13668 +};
13669 +
13670 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13671 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13672 +
13673 +#endif /* _UAPI_VS_SCHED_CMD_H */
13674 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/signal_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/signal_cmd.h
13675 --- linux-3.7.1/include/uapi/vserver/signal_cmd.h       1970-01-01 00:00:00.000000000 +0000
13676 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/signal_cmd.h     2012-12-18 15:13:16.000000000 +0000
13677 @@ -0,0 +1,31 @@
13678 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13679 +#define _UAPI_VS_SIGNAL_CMD_H
13680 +
13681 +
13682 +/*  signalling vserver commands */
13683 +
13684 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13685 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13686 +
13687 +struct vcmd_ctx_kill_v0 {
13688 +       int32_t pid;
13689 +       int32_t sig;
13690 +};
13691 +
13692 +struct vcmd_wait_exit_v0 {
13693 +       int32_t reboot_cmd;
13694 +       int32_t exit_code;
13695 +};
13696 +
13697 +
13698 +/*  process alteration commands */
13699 +
13700 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13701 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13702 +
13703 +struct vcmd_pflags_v0 {
13704 +       uint32_t flagword;
13705 +       uint32_t mask;
13706 +};
13707 +
13708 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13709 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/space_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/space_cmd.h
13710 --- linux-3.7.1/include/uapi/vserver/space_cmd.h        1970-01-01 00:00:00.000000000 +0000
13711 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/space_cmd.h      2012-12-18 15:13:16.000000000 +0000
13712 @@ -0,0 +1,28 @@
13713 +#ifndef _UAPI_VS_SPACE_CMD_H
13714 +#define _UAPI_VS_SPACE_CMD_H
13715 +
13716 +
13717 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13718 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13719 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13720 +
13721 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13722 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13723 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13724 +
13725 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13726 +
13727 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13728 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13729 +
13730 +
13731 +struct vcmd_space_mask_v1 {
13732 +       uint64_t mask;
13733 +};
13734 +
13735 +struct vcmd_space_mask_v2 {
13736 +       uint64_t mask;
13737 +       uint32_t index;
13738 +};
13739 +
13740 +#endif /* _UAPI_VS_SPACE_CMD_H */
13741 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/switch.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/switch.h
13742 --- linux-3.7.1/include/uapi/vserver/switch.h   1970-01-01 00:00:00.000000000 +0000
13743 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/switch.h 2012-12-18 15:13:16.000000000 +0000
13744 @@ -0,0 +1,90 @@
13745 +#ifndef _UAPI_VS_SWITCH_H
13746 +#define _UAPI_VS_SWITCH_H
13747 +
13748 +#include <linux/types.h>
13749 +
13750 +
13751 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13752 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13753 +#define VC_VERSION(c)          ((c) & 0xFFF)
13754 +
13755 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13756 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13757 +
13758 +/*
13759 +
13760 +  Syscall Matrix V2.8
13761 +
13762 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13763 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13764 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13765 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13766 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13767 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13768 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13769 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13770 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13771 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13772 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13773 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13774 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13775 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13776 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13777 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13778 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13779 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13780 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13781 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13782 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13783 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13784 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13785 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13786 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13787 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13788 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13789 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13790 +
13791 +*/
13792 +
13793 +#define VC_CAT_VERSION         0
13794 +
13795 +#define VC_CAT_VSETUP          1
13796 +#define VC_CAT_VHOST           2
13797 +
13798 +#define VC_CAT_DEVICE          6
13799 +
13800 +#define VC_CAT_VPROC           9
13801 +#define VC_CAT_PROCALT         10
13802 +#define VC_CAT_PROCMIG         11
13803 +#define VC_CAT_PROCTRL         12
13804 +
13805 +#define VC_CAT_SCHED           14
13806 +#define VC_CAT_MEMCTRL         20
13807 +
13808 +#define VC_CAT_VNET            25
13809 +#define VC_CAT_NETALT          26
13810 +#define VC_CAT_NETMIG          27
13811 +#define VC_CAT_NETCTRL         28
13812 +
13813 +#define VC_CAT_TAGMIG          35
13814 +#define VC_CAT_DLIMIT          36
13815 +#define VC_CAT_INODE           38
13816 +
13817 +#define VC_CAT_VSTAT           40
13818 +#define VC_CAT_VINFO           46
13819 +#define VC_CAT_EVENT           48
13820 +
13821 +#define VC_CAT_FLAGS           52
13822 +#define VC_CAT_VSPACE          54
13823 +#define VC_CAT_DEBUG           56
13824 +#define VC_CAT_RLIMIT          60
13825 +
13826 +#define VC_CAT_SYSTEST         61
13827 +#define VC_CAT_COMPAT          63
13828 +
13829 +/*  query version */
13830 +
13831 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13832 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13833 +
13834 +#endif /* _UAPI_VS_SWITCH_H */
13835 diff -NurpP --minimal linux-3.7.1/include/uapi/vserver/tag_cmd.h linux-3.7.1-vs2.3.5.5/include/uapi/vserver/tag_cmd.h
13836 --- linux-3.7.1/include/uapi/vserver/tag_cmd.h  1970-01-01 00:00:00.000000000 +0000
13837 +++ linux-3.7.1-vs2.3.5.5/include/uapi/vserver/tag_cmd.h        2012-12-18 15:13:16.000000000 +0000
13838 @@ -0,0 +1,14 @@
13839 +#ifndef _UAPI_VS_TAG_CMD_H
13840 +#define _UAPI_VS_TAG_CMD_H
13841 +
13842 +
13843 +/* vinfo commands */
13844 +
13845 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13846 +
13847 +
13848 +/* context commands */
13849 +
13850 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13851 +
13852 +#endif /* _UAPI_VS_TAG_CMD_H */
13853 diff -NurpP --minimal linux-3.7.1/init/Kconfig linux-3.7.1-vs2.3.5.5/init/Kconfig
13854 --- linux-3.7.1/init/Kconfig    2012-12-11 03:30:57.000000000 +0000
13855 +++ linux-3.7.1-vs2.3.5.5/init/Kconfig  2012-12-18 15:13:16.000000000 +0000
13856 @@ -699,6 +699,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
13857  menuconfig CGROUPS
13858         boolean "Control Group support"
13859         depends on EVENTFD
13860 +       default y
13861         help
13862           This option adds support for grouping sets of processes together, for
13863           use with process control subsystems such as Cpusets, CFS, memory
13864 @@ -964,6 +965,7 @@ config USER_NS
13865         bool "User namespace (EXPERIMENTAL)"
13866         depends on EXPERIMENTAL
13867         depends on UIDGID_CONVERTED
13868 +       depends on VSERVER_DISABLED
13869         select UIDGID_STRICT_TYPE_CHECKS
13870  
13871         default n
13872 diff -NurpP --minimal linux-3.7.1/init/main.c linux-3.7.1-vs2.3.5.5/init/main.c
13873 --- linux-3.7.1/init/main.c     2012-12-11 03:30:57.000000000 +0000
13874 +++ linux-3.7.1-vs2.3.5.5/init/main.c   2012-12-18 15:13:16.000000000 +0000
13875 @@ -70,6 +70,7 @@
13876  #include <linux/perf_event.h>
13877  #include <linux/file.h>
13878  #include <linux/ptrace.h>
13879 +#include <linux/vserver/percpu.h>
13880  
13881  #include <asm/io.h>
13882  #include <asm/bugs.h>
13883 diff -NurpP --minimal linux-3.7.1/ipc/mqueue.c linux-3.7.1-vs2.3.5.5/ipc/mqueue.c
13884 --- linux-3.7.1/ipc/mqueue.c    2012-12-11 03:30:57.000000000 +0000
13885 +++ linux-3.7.1-vs2.3.5.5/ipc/mqueue.c  2012-12-18 15:13:16.000000000 +0000
13886 @@ -35,6 +35,8 @@
13887  #include <linux/ipc_namespace.h>
13888  #include <linux/user_namespace.h>
13889  #include <linux/slab.h>
13890 +#include <linux/vs_context.h>
13891 +#include <linux/vs_limit.h>
13892  
13893  #include <net/sock.h>
13894  #include "util.h"
13895 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13896         struct pid* notify_owner;
13897         struct user_namespace *notify_user_ns;
13898         struct user_struct *user;       /* user who created, for accounting */
13899 +       struct vx_info *vxi;
13900         struct sock *notify_sock;
13901         struct sk_buff *notify_cookie;
13902  
13903 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13904         if (S_ISREG(mode)) {
13905                 struct mqueue_inode_info *info;
13906                 unsigned long mq_bytes, mq_treesize;
13907 +               struct vx_info *vxi = current_vx_info();
13908  
13909                 inode->i_fop = &mqueue_file_operations;
13910                 inode->i_size = FILENT_SIZE;
13911 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13912                 info->notify_user_ns = NULL;
13913                 info->qsize = 0;
13914                 info->user = NULL;      /* set when all is ok */
13915 +               info->vxi = NULL;
13916                 info->msg_tree = RB_ROOT;
13917                 info->node_cache = NULL;
13918                 memset(&info->attr, 0, sizeof(info->attr));
13919 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13920  
13921                 spin_lock(&mq_lock);
13922                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13923 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13924 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13925 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13926                         spin_unlock(&mq_lock);
13927                         /* mqueue_evict_inode() releases info->messages */
13928                         ret = -EMFILE;
13929                         goto out_inode;
13930                 }
13931                 u->mq_bytes += mq_bytes;
13932 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13933                 spin_unlock(&mq_lock);
13934  
13935                 /* all is ok */
13936                 info->user = get_uid(u);
13937 +               info->vxi = get_vx_info(vxi);
13938         } else if (S_ISDIR(mode)) {
13939                 inc_nlink(inode);
13940                 /* Some things misbehave if size == 0 on a directory */
13941 @@ -394,8 +402,11 @@ static void mqueue_evict_inode(struct in
13942  
13943         user = info->user;
13944         if (user) {
13945 +               struct vx_info *vxi = info->vxi;
13946 +
13947                 spin_lock(&mq_lock);
13948                 user->mq_bytes -= mq_bytes;
13949 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13950                 /*
13951                  * get_ns_from_inode() ensures that the
13952                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13953 @@ -405,6 +416,7 @@ static void mqueue_evict_inode(struct in
13954                 if (ipc_ns)
13955                         ipc_ns->mq_queues_count--;
13956                 spin_unlock(&mq_lock);
13957 +               put_vx_info(vxi);
13958                 free_uid(user);
13959         }
13960         if (ipc_ns)
13961 diff -NurpP --minimal linux-3.7.1/ipc/msg.c linux-3.7.1-vs2.3.5.5/ipc/msg.c
13962 --- linux-3.7.1/ipc/msg.c       2012-12-11 03:30:57.000000000 +0000
13963 +++ linux-3.7.1-vs2.3.5.5/ipc/msg.c     2012-12-18 15:13:16.000000000 +0000
13964 @@ -37,6 +37,7 @@
13965  #include <linux/rwsem.h>
13966  #include <linux/nsproxy.h>
13967  #include <linux/ipc_namespace.h>
13968 +#include <linux/vs_base.h>
13969  
13970  #include <asm/current.h>
13971  #include <asm/uaccess.h>
13972 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13973  
13974         msq->q_perm.mode = msgflg & S_IRWXUGO;
13975         msq->q_perm.key = key;
13976 +       msq->q_perm.xid = vx_current_xid();
13977  
13978         msq->q_perm.security = NULL;
13979         retval = security_msg_queue_alloc(msq);
13980 diff -NurpP --minimal linux-3.7.1/ipc/namespace.c linux-3.7.1-vs2.3.5.5/ipc/namespace.c
13981 --- linux-3.7.1/ipc/namespace.c 2012-12-11 03:30:57.000000000 +0000
13982 +++ linux-3.7.1-vs2.3.5.5/ipc/namespace.c       2012-12-18 15:13:16.000000000 +0000
13983 @@ -13,11 +13,12 @@
13984  #include <linux/mount.h>
13985  #include <linux/user_namespace.h>
13986  #include <linux/proc_fs.h>
13987 +#include <linux/vs_base.h>
13988 +#include <linux/vserver/global.h>
13989  
13990  #include "util.h"
13991  
13992 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
13993 -                                          struct ipc_namespace *old_ns)
13994 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
13995  {
13996         struct ipc_namespace *ns;
13997         int err;
13998 @@ -46,19 +47,19 @@ static struct ipc_namespace *create_ipc_
13999         ipcns_notify(IPCNS_CREATED);
14000         register_ipcns_notifier(ns);
14001  
14002 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
14003 +       // ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
14004 +       ns->user_ns = get_user_ns(user_ns);
14005  
14006         return ns;
14007  }
14008  
14009  struct ipc_namespace *copy_ipcs(unsigned long flags,
14010 -                               struct task_struct *tsk)
14011 +                               struct ipc_namespace *old_ns,
14012 +                               struct user_namespace *user_ns)
14013  {
14014 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14015 -
14016         if (!(flags & CLONE_NEWIPC))
14017 -               return get_ipc_ns(ns);
14018 -       return create_ipc_ns(tsk, ns);
14019 +               return get_ipc_ns(old_ns);
14020 +       return create_ipc_ns(user_ns);
14021  }
14022  
14023  /*
14024 diff -NurpP --minimal linux-3.7.1/ipc/sem.c linux-3.7.1-vs2.3.5.5/ipc/sem.c
14025 --- linux-3.7.1/ipc/sem.c       2012-12-11 03:30:57.000000000 +0000
14026 +++ linux-3.7.1-vs2.3.5.5/ipc/sem.c     2012-12-18 15:13:16.000000000 +0000
14027 @@ -86,6 +86,8 @@
14028  #include <linux/rwsem.h>
14029  #include <linux/nsproxy.h>
14030  #include <linux/ipc_namespace.h>
14031 +#include <linux/vs_base.h>
14032 +#include <linux/vs_limit.h>
14033  
14034  #include <asm/uaccess.h>
14035  #include "util.h"
14036 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
14037  
14038         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14039         sma->sem_perm.key = key;
14040 +       sma->sem_perm.xid = vx_current_xid();
14041  
14042         sma->sem_perm.security = NULL;
14043         retval = security_sem_alloc(sma);
14044 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
14045                 return id;
14046         }
14047         ns->used_sems += nsems;
14048 +       /* FIXME: obsoleted? */
14049 +       vx_semary_inc(sma);
14050 +       vx_nsems_add(sma, nsems);
14051  
14052         sma->sem_base = (struct sem *) &sma[1];
14053  
14054 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
14055  
14056         wake_up_sem_queue_do(&tasks);
14057         ns->used_sems -= sma->sem_nsems;
14058 +       /* FIXME: obsoleted? */
14059 +       vx_nsems_sub(sma, sma->sem_nsems);
14060 +       vx_semary_dec(sma);
14061         security_sem_free(sma);
14062         ipc_rcu_putref(sma);
14063  }
14064 diff -NurpP --minimal linux-3.7.1/ipc/shm.c linux-3.7.1-vs2.3.5.5/ipc/shm.c
14065 --- linux-3.7.1/ipc/shm.c       2012-12-11 03:30:57.000000000 +0000
14066 +++ linux-3.7.1-vs2.3.5.5/ipc/shm.c     2012-12-18 15:13:16.000000000 +0000
14067 @@ -39,6 +39,8 @@
14068  #include <linux/nsproxy.h>
14069  #include <linux/mount.h>
14070  #include <linux/ipc_namespace.h>
14071 +#include <linux/vs_context.h>
14072 +#include <linux/vs_limit.h>
14073  
14074  #include <asm/uaccess.h>
14075  
14076 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14077   */
14078  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14079  {
14080 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14081 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14082 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14083 +
14084 +       vx_ipcshm_sub(vxi, shp, numpages);
14085 +       ns->shm_tot -= numpages;
14086 +
14087         shm_rmid(ns, shp);
14088         shm_unlock(shp);
14089         if (!is_file_hugepages(shp->shm_file))
14090 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14091                                                 shp->mlock_user);
14092         fput (shp->shm_file);
14093         security_shm_free(shp);
14094 +       put_vx_info(vxi);
14095         ipc_rcu_putref(shp);
14096  }
14097  
14098 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
14099         if (ns->shm_tot + numpages > ns->shm_ctlall)
14100                 return -ENOSPC;
14101  
14102 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14103 +               return -ENOSPC;
14104 +
14105         shp = ipc_rcu_alloc(sizeof(*shp));
14106         if (!shp)
14107                 return -ENOMEM;
14108  
14109         shp->shm_perm.key = key;
14110 +       shp->shm_perm.xid = vx_current_xid();
14111         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14112         shp->mlock_user = NULL;
14113  
14114 @@ -533,6 +545,7 @@ static int newseg(struct ipc_namespace *
14115         ns->shm_tot += numpages;
14116         error = shp->shm_perm.id;
14117         shm_unlock(shp);
14118 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14119         return error;
14120  
14121  no_id:
14122 diff -NurpP --minimal linux-3.7.1/kernel/Makefile linux-3.7.1-vs2.3.5.5/kernel/Makefile
14123 --- linux-3.7.1/kernel/Makefile 2012-12-11 03:30:57.000000000 +0000
14124 +++ linux-3.7.1-vs2.3.5.5/kernel/Makefile       2012-12-18 15:13:16.000000000 +0000
14125 @@ -24,6 +24,7 @@ endif
14126  
14127  obj-y += sched/
14128  obj-y += power/
14129 +obj-y += vserver/
14130  
14131  ifeq ($(CONFIG_CHECKPOINT_RESTORE),y)
14132  obj-$(CONFIG_X86) += kcmp.o
14133 diff -NurpP --minimal linux-3.7.1/kernel/auditsc.c linux-3.7.1-vs2.3.5.5/kernel/auditsc.c
14134 --- linux-3.7.1/kernel/auditsc.c        2012-12-11 03:30:57.000000000 +0000
14135 +++ linux-3.7.1-vs2.3.5.5/kernel/auditsc.c      2012-12-18 15:13:16.000000000 +0000
14136 @@ -2372,7 +2372,7 @@ int audit_set_loginuid(kuid_t loginuid)
14137         if (uid_valid(task->loginuid))
14138                 return -EPERM;
14139  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14140 -       if (!capable(CAP_AUDIT_CONTROL))
14141 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
14142                 return -EPERM;
14143  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
14144  
14145 diff -NurpP --minimal linux-3.7.1/kernel/capability.c linux-3.7.1-vs2.3.5.5/kernel/capability.c
14146 --- linux-3.7.1/kernel/capability.c     2012-12-11 03:30:57.000000000 +0000
14147 +++ linux-3.7.1-vs2.3.5.5/kernel/capability.c   2012-12-18 15:13:16.000000000 +0000
14148 @@ -15,6 +15,7 @@
14149  #include <linux/syscalls.h>
14150  #include <linux/pid_namespace.h>
14151  #include <linux/user_namespace.h>
14152 +#include <linux/vs_context.h>
14153  #include <asm/uaccess.h>
14154  
14155  /*
14156 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14157         return 0;
14158  }
14159  
14160 +
14161  /*
14162   * The only thing that can change the capabilities of the current
14163   * process is the current process. As such, we can't be in this code
14164 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14165         return (ret == 0);
14166  }
14167  
14168 +#include <linux/vserver/base.h>
14169 +
14170  /**
14171   * has_capability_noaudit - Does a task have a capability (unaudited) in the
14172   * initial user ns
14173 diff -NurpP --minimal linux-3.7.1/kernel/compat.c linux-3.7.1-vs2.3.5.5/kernel/compat.c
14174 --- linux-3.7.1/kernel/compat.c 2012-12-11 03:30:57.000000000 +0000
14175 +++ linux-3.7.1-vs2.3.5.5/kernel/compat.c       2012-12-18 15:13:16.000000000 +0000
14176 @@ -27,6 +27,7 @@
14177  #include <linux/times.h>
14178  #include <linux/ptrace.h>
14179  #include <linux/gfp.h>
14180 +#include <linux/vs_time.h>
14181  
14182  #include <asm/uaccess.h>
14183  
14184 @@ -1054,7 +1055,7 @@ asmlinkage long compat_sys_stime(compat_
14185         if (err)
14186                 return err;
14187  
14188 -       do_settimeofday(&tv);
14189 +       vx_settimeofday(&tv);
14190         return 0;
14191  }
14192  
14193 diff -NurpP --minimal linux-3.7.1/kernel/cred.c linux-3.7.1-vs2.3.5.5/kernel/cred.c
14194 --- linux-3.7.1/kernel/cred.c   2012-12-11 03:30:57.000000000 +0000
14195 +++ linux-3.7.1-vs2.3.5.5/kernel/cred.c 2012-12-18 15:13:16.000000000 +0000
14196 @@ -70,31 +70,6 @@ struct cred init_cred = {
14197  #endif
14198  };
14199  
14200 -static inline void set_cred_subscribers(struct cred *cred, int n)
14201 -{
14202 -#ifdef CONFIG_DEBUG_CREDENTIALS
14203 -       atomic_set(&cred->subscribers, n);
14204 -#endif
14205 -}
14206 -
14207 -static inline int read_cred_subscribers(const struct cred *cred)
14208 -{
14209 -#ifdef CONFIG_DEBUG_CREDENTIALS
14210 -       return atomic_read(&cred->subscribers);
14211 -#else
14212 -       return 0;
14213 -#endif
14214 -}
14215 -
14216 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14217 -{
14218 -#ifdef CONFIG_DEBUG_CREDENTIALS
14219 -       struct cred *cred = (struct cred *) _cred;
14220 -
14221 -       atomic_add(n, &cred->subscribers);
14222 -#endif
14223 -}
14224 -
14225  /*
14226   * Dispose of the shared task group credentials
14227   */
14228 @@ -284,21 +259,16 @@ error:
14229   *
14230   * Call commit_creds() or abort_creds() to clean up.
14231   */
14232 -struct cred *prepare_creds(void)
14233 +struct cred *__prepare_creds(const struct cred *old)
14234  {
14235 -       struct task_struct *task = current;
14236 -       const struct cred *old;
14237         struct cred *new;
14238  
14239 -       validate_process_creds();
14240 -
14241         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14242         if (!new)
14243                 return NULL;
14244  
14245         kdebug("prepare_creds() alloc %p", new);
14246  
14247 -       old = task->cred;
14248         memcpy(new, old, sizeof(struct cred));
14249  
14250         atomic_set(&new->usage, 1);
14251 @@ -326,6 +296,13 @@ error:
14252         abort_creds(new);
14253         return NULL;
14254  }
14255 +
14256 +struct cred *prepare_creds(void)
14257 +{
14258 +       validate_process_creds();
14259 +
14260 +       return __prepare_creds(current->cred);
14261 +}
14262  EXPORT_SYMBOL(prepare_creds);
14263  
14264  /*
14265 diff -NurpP --minimal linux-3.7.1/kernel/exit.c linux-3.7.1-vs2.3.5.5/kernel/exit.c
14266 --- linux-3.7.1/kernel/exit.c   2012-12-11 03:30:57.000000000 +0000
14267 +++ linux-3.7.1-vs2.3.5.5/kernel/exit.c 2012-12-18 15:13:16.000000000 +0000
14268 @@ -48,6 +48,10 @@
14269  #include <linux/fs_struct.h>
14270  #include <linux/init_task.h>
14271  #include <linux/perf_event.h>
14272 +#include <linux/vs_limit.h>
14273 +#include <linux/vs_context.h>
14274 +#include <linux/vs_network.h>
14275 +#include <linux/vs_pid.h>
14276  #include <trace/events/sched.h>
14277  #include <linux/hw_breakpoint.h>
14278  #include <linux/oom.h>
14279 @@ -616,15 +620,25 @@ static struct task_struct *find_new_reap
14280         __acquires(&tasklist_lock)
14281  {
14282         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14283 -       struct task_struct *thread;
14284 +       struct vx_info *vxi = task_get_vx_info(father);
14285 +       struct task_struct *thread = father;
14286 +       struct task_struct *reaper;
14287  
14288 -       thread = father;
14289         while_each_thread(father, thread) {
14290                 if (thread->flags & PF_EXITING)
14291                         continue;
14292                 if (unlikely(pid_ns->child_reaper == father))
14293                         pid_ns->child_reaper = thread;
14294 -               return thread;
14295 +               reaper = thread;
14296 +               goto out_put;
14297 +       }
14298 +
14299 +       reaper = pid_ns->child_reaper;
14300 +       if (vxi) {
14301 +               BUG_ON(!vxi->vx_reaper);
14302 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14303 +                   vxi->vx_reaper != father)
14304 +                       reaper = vxi->vx_reaper;
14305         }
14306  
14307         if (unlikely(pid_ns->child_reaper == father)) {
14308 @@ -662,7 +676,9 @@ static struct task_struct *find_new_reap
14309                 }
14310         }
14311  
14312 -       return pid_ns->child_reaper;
14313 +out_put:
14314 +       put_vx_info(vxi);
14315 +       return reaper;
14316  }
14317  
14318  /*
14319 @@ -713,10 +729,15 @@ static void forget_original_parent(struc
14320         list_for_each_entry_safe(p, n, &father->children, sibling) {
14321                 struct task_struct *t = p;
14322                 do {
14323 -                       t->real_parent = reaper;
14324 +                       struct task_struct *new_parent = reaper;
14325 +
14326 +                       if (unlikely(p == reaper))
14327 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14328 +
14329 +                       t->real_parent = new_parent;
14330                         if (t->parent == father) {
14331                                 BUG_ON(t->ptrace);
14332 -                               t->parent = t->real_parent;
14333 +                               t->parent = new_parent;
14334                         }
14335                         if (t->pdeath_signal)
14336                                 group_send_sig_info(t->pdeath_signal,
14337 @@ -923,6 +944,9 @@ void do_exit(long code)
14338          */
14339         ptrace_put_breakpoints(tsk);
14340  
14341 +       /* needs to stay before exit_notify() */
14342 +       exit_vx_info_early(tsk, code);
14343 +
14344         exit_notify(tsk, group_dead);
14345  #ifdef CONFIG_NUMA
14346         task_lock(tsk);
14347 @@ -976,10 +1000,15 @@ void do_exit(long code)
14348         smp_mb();
14349         raw_spin_unlock_wait(&tsk->pi_lock);
14350  
14351 +       /* needs to stay after exit_notify() */
14352 +       exit_vx_info(tsk, code);
14353 +       exit_nx_info(tsk);
14354 +
14355         /* causes final put_task_struct in finish_task_switch(). */
14356         tsk->state = TASK_DEAD;
14357         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14358         schedule();
14359 +       printk("bad task: %p [%lx]\n", current, current->state);
14360         BUG();
14361         /* Avoid "noreturn function does return".  */
14362         for (;;)
14363 diff -NurpP --minimal linux-3.7.1/kernel/fork.c linux-3.7.1-vs2.3.5.5/kernel/fork.c
14364 --- linux-3.7.1/kernel/fork.c   2012-12-11 03:30:57.000000000 +0000
14365 +++ linux-3.7.1-vs2.3.5.5/kernel/fork.c 2012-12-18 15:13:16.000000000 +0000
14366 @@ -70,6 +70,9 @@
14367  #include <linux/khugepaged.h>
14368  #include <linux/signalfd.h>
14369  #include <linux/uprobes.h>
14370 +#include <linux/vs_context.h>
14371 +#include <linux/vs_network.h>
14372 +#include <linux/vs_limit.h>
14373  
14374  #include <asm/pgtable.h>
14375  #include <asm/pgalloc.h>
14376 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14377         arch_release_thread_info(tsk->stack);
14378         free_thread_info(tsk->stack);
14379         rt_mutex_debug_task_free(tsk);
14380 +       clr_vx_info(&tsk->vx_info);
14381 +       clr_nx_info(&tsk->nx_info);
14382         ftrace_graph_exit_task(tsk);
14383         put_seccomp_filter(tsk);
14384         arch_release_task_struct(tsk);
14385 @@ -545,6 +550,7 @@ static struct mm_struct *mm_init(struct
14386         if (likely(!mm_alloc_pgd(mm))) {
14387                 mm->def_flags = 0;
14388                 mmu_notifier_mm_init(mm);
14389 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14390                 return mm;
14391         }
14392  
14393 @@ -597,6 +603,7 @@ void __mmdrop(struct mm_struct *mm)
14394         destroy_context(mm);
14395         mmu_notifier_mm_destroy(mm);
14396         check_mm(mm);
14397 +       clr_vx_info(&mm->mm_vx_info);
14398         free_mm(mm);
14399  }
14400  EXPORT_SYMBOL_GPL(__mmdrop);
14401 @@ -816,6 +823,7 @@ struct mm_struct *dup_mm(struct task_str
14402                 goto fail_nomem;
14403  
14404         memcpy(mm, oldmm, sizeof(*mm));
14405 +       mm->mm_vx_info = NULL;
14406         mm_init_cpumask(mm);
14407  
14408  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14409 @@ -854,6 +862,7 @@ fail_nocontext:
14410          * If init_new_context() failed, we cannot use mmput() to free the mm
14411          * because it calls destroy_context()
14412          */
14413 +       clr_vx_info(&mm->mm_vx_info);
14414         mm_free_pgd(mm);
14415         free_mm(mm);
14416         return NULL;
14417 @@ -1136,5 +1145,7 @@ static struct task_struct *copy_process(
14418         int retval;
14419         struct task_struct *p;
14420 +       struct vx_info *vxi;
14421 +       struct nx_info *nxi;
14422  
14423         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14424                 return ERR_PTR(-EINVAL);
14425 @@ -1183,7 +1194,12 @@ static struct task_struct *copy_process(
14426         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14427         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14428  #endif
14429 +       init_vx_info(&p->vx_info, current_vx_info());
14430 +       init_nx_info(&p->nx_info, current_nx_info());
14431 +
14432         retval = -EAGAIN;
14433 +       if (!vx_nproc_avail(1))
14434 +               goto bad_fork_free;
14435         if (atomic_read(&p->real_cred->user->processes) >=
14436                         task_rlimit(p, RLIMIT_NPROC)) {
14437                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14438 @@ -1458,6 +1474,18 @@ static struct task_struct *copy_process(
14439  
14440         total_forks++;
14441         spin_unlock(&current->sighand->siglock);
14442 +
14443 +       /* p is copy of current */
14444 +       vxi = p->vx_info;
14445 +       if (vxi) {
14446 +               claim_vx_info(vxi, p);
14447 +               atomic_inc(&vxi->cvirt.nr_threads);
14448 +               atomic_inc(&vxi->cvirt.total_forks);
14449 +               vx_nproc_inc(p);
14450 +       }
14451 +       nxi = p->nx_info;
14452 +       if (nxi)
14453 +               claim_nx_info(nxi, p);
14454         write_unlock_irq(&tasklist_lock);
14455         proc_fork_connector(p);
14456         cgroup_post_fork(p);
14457 diff -NurpP --minimal linux-3.7.1/kernel/kthread.c linux-3.7.1-vs2.3.5.5/kernel/kthread.c
14458 --- linux-3.7.1/kernel/kthread.c        2012-12-11 03:30:57.000000000 +0000
14459 +++ linux-3.7.1-vs2.3.5.5/kernel/kthread.c      2012-12-18 15:13:16.000000000 +0000
14460 @@ -17,6 +17,7 @@
14461  #include <linux/slab.h>
14462  #include <linux/freezer.h>
14463  #include <linux/ptrace.h>
14464 +#include <linux/vs_pid.h>
14465  #include <trace/events/sched.h>
14466  
14467  static DEFINE_SPINLOCK(kthread_create_lock);
14468 diff -NurpP --minimal linux-3.7.1/kernel/nsproxy.c linux-3.7.1-vs2.3.5.5/kernel/nsproxy.c
14469 --- linux-3.7.1/kernel/nsproxy.c        2012-12-11 03:30:57.000000000 +0000
14470 +++ linux-3.7.1-vs2.3.5.5/kernel/nsproxy.c      2012-12-18 15:13:16.000000000 +0000
14471 @@ -20,11 +20,14 @@
14472  #include <linux/mnt_namespace.h>
14473  #include <linux/utsname.h>
14474  #include <linux/pid_namespace.h>
14475 +#include <linux/vserver/global.h>
14476 +#include <linux/vserver/debug.h>
14477  #include <net/net_namespace.h>
14478  #include <linux/ipc_namespace.h>
14479  #include <linux/proc_fs.h>
14480  #include <linux/file.h>
14481  #include <linux/syscalls.h>
14482 +#include "../fs/mount.h"
14483  
14484  static struct kmem_cache *nsproxy_cachep;
14485  
14486 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14487         struct nsproxy *nsproxy;
14488  
14489         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14490 -       if (nsproxy)
14491 +       if (nsproxy) {
14492                 atomic_set(&nsproxy->count, 1);
14493 +               atomic_inc(&vs_global_nsproxy);
14494 +       }
14495 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14496         return nsproxy;
14497  }
14498  
14499 @@ -56,8 +62,11 @@ static inline struct nsproxy *create_nsp
14500   * Return the newly created nsproxy.  Do not attach this to the task,
14501   * leave it to the caller to do proper locking and attach it to task.
14502   */
14503 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14504 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14505 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14506 +                       struct nsproxy *orig,
14507 +                       struct fs_struct *new_fs,
14508 +                       struct user_namespace *new_user,
14509 +                       struct pid_namespace *new_pid)
14510  {
14511         struct nsproxy *new_nsp;
14512         int err;
14513 @@ -66,31 +75,31 @@ static struct nsproxy *create_new_namesp
14514         if (!new_nsp)
14515                 return ERR_PTR(-ENOMEM);
14516  
14517 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14518 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14519         if (IS_ERR(new_nsp->mnt_ns)) {
14520                 err = PTR_ERR(new_nsp->mnt_ns);
14521                 goto out_ns;
14522         }
14523  
14524 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14525 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14526         if (IS_ERR(new_nsp->uts_ns)) {
14527                 err = PTR_ERR(new_nsp->uts_ns);
14528                 goto out_uts;
14529         }
14530  
14531 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14532 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14533         if (IS_ERR(new_nsp->ipc_ns)) {
14534                 err = PTR_ERR(new_nsp->ipc_ns);
14535                 goto out_ipc;
14536         }
14537  
14538 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14539 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14540         if (IS_ERR(new_nsp->pid_ns)) {
14541                 err = PTR_ERR(new_nsp->pid_ns);
14542                 goto out_pid;
14543         }
14544  
14545 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14546 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14547         if (IS_ERR(new_nsp->net_ns)) {
14548                 err = PTR_ERR(new_nsp->net_ns);
14549                 goto out_net;
14550 @@ -115,6 +124,40 @@ out_ns:
14551         return ERR_PTR(err);
14552  }
14553  
14554 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14555 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14556 +{
14557 +       return unshare_namespaces(flags, tsk->nsproxy,
14558 +               new_fs, task_cred_xxx(tsk, user_ns),
14559 +               task_active_pid_ns(tsk));
14560 +}
14561 +
14562 +/*
14563 + * copies the nsproxy, setting refcount to 1, and grabbing a
14564 + * reference to all contained namespaces.
14565 + */
14566 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14567 +{
14568 +       struct nsproxy *ns = create_nsproxy();
14569 +
14570 +       if (ns) {
14571 +               memcpy(ns, orig, sizeof(struct nsproxy));
14572 +               atomic_set(&ns->count, 1);
14573 +
14574 +               if (ns->mnt_ns)
14575 +                       get_mnt_ns(ns->mnt_ns);
14576 +               if (ns->uts_ns)
14577 +                       get_uts_ns(ns->uts_ns);
14578 +               if (ns->ipc_ns)
14579 +                       get_ipc_ns(ns->ipc_ns);
14580 +               if (ns->pid_ns)
14581 +                       get_pid_ns(ns->pid_ns);
14582 +               if (ns->net_ns)
14583 +                       get_net(ns->net_ns);
14584 +       }
14585 +       return ns;
14586 +}
14587 +
14588  /*
14589   * called from clone.  This now handles copy for nsproxy and all
14590   * namespaces therein.
14591 @@ -122,9 +165,12 @@ out_ns:
14592  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14593  {
14594         struct nsproxy *old_ns = tsk->nsproxy;
14595 -       struct nsproxy *new_ns;
14596 +       struct nsproxy *new_ns = NULL;
14597         int err = 0;
14598  
14599 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14600 +               flags, tsk, old_ns);
14601 +
14602         if (!old_ns)
14603                 return 0;
14604  
14605 @@ -134,7 +180,7 @@ int copy_namespaces(unsigned long flags,
14606                                 CLONE_NEWPID | CLONE_NEWNET)))
14607                 return 0;
14608  
14609 -       if (!capable(CAP_SYS_ADMIN)) {
14610 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14611                 err = -EPERM;
14612                 goto out;
14613         }
14614 @@ -161,6 +207,9 @@ int copy_namespaces(unsigned long flags,
14615  
14616  out:
14617         put_nsproxy(old_ns);
14618 +       vxdprintk(VXD_CBIT(space, 3),
14619 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14620 +               flags, tsk, old_ns, err, new_ns);
14621         return err;
14622  }
14623  
14624 @@ -174,7 +223,9 @@ void free_nsproxy(struct nsproxy *ns)
14625                 put_ipc_ns(ns->ipc_ns);
14626         if (ns->pid_ns)
14627                 put_pid_ns(ns->pid_ns);
14628 -       put_net(ns->net_ns);
14629 +       if (ns->net_ns)
14630 +               put_net(ns->net_ns);
14631 +       atomic_dec(&vs_global_nsproxy);
14632         kmem_cache_free(nsproxy_cachep, ns);
14633  }
14634  
14635 @@ -187,11 +238,15 @@ int unshare_nsproxy_namespaces(unsigned
14636  {
14637         int err = 0;
14638  
14639 +       vxdprintk(VXD_CBIT(space, 4),
14640 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14641 +               unshare_flags, current->nsproxy);
14642 +
14643         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14644                                CLONE_NEWNET)))
14645                 return 0;
14646  
14647 -       if (!capable(CAP_SYS_ADMIN))
14648 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14649                 return -EPERM;
14650  
14651         *new_nsp = create_new_namespaces(unshare_flags, current,
14652 diff -NurpP --minimal linux-3.7.1/kernel/pid.c linux-3.7.1-vs2.3.5.5/kernel/pid.c
14653 --- linux-3.7.1/kernel/pid.c    2012-12-11 03:30:57.000000000 +0000
14654 +++ linux-3.7.1-vs2.3.5.5/kernel/pid.c  2012-12-18 15:13:16.000000000 +0000
14655 @@ -36,6 +36,7 @@
14656  #include <linux/pid_namespace.h>
14657  #include <linux/init_task.h>
14658  #include <linux/syscalls.h>
14659 +#include <linux/vs_pid.h>
14660  
14661  #define pid_hashfn(nr, ns)     \
14662         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14663 @@ -344,7 +345,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14664  
14665  struct pid *find_vpid(int nr)
14666  {
14667 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14668 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14669  }
14670  EXPORT_SYMBOL_GPL(find_vpid);
14671  
14672 @@ -404,6 +405,9 @@ void transfer_pid(struct task_struct *ol
14673  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14674  {
14675         struct task_struct *result = NULL;
14676 +
14677 +       if (type == PIDTYPE_REALPID)
14678 +               type = PIDTYPE_PID;
14679         if (pid) {
14680                 struct hlist_node *first;
14681                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14682 @@ -423,7 +427,7 @@ struct task_struct *find_task_by_pid_ns(
14683         rcu_lockdep_assert(rcu_read_lock_held(),
14684                            "find_task_by_pid_ns() needs rcu_read_lock()"
14685                            " protection");
14686 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14687 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14688  }
14689  
14690  struct task_struct *find_task_by_vpid(pid_t vnr)
14691 @@ -467,7 +471,7 @@ struct pid *find_get_pid(pid_t nr)
14692  }
14693  EXPORT_SYMBOL_GPL(find_get_pid);
14694  
14695 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14696 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14697  {
14698         struct upid *upid;
14699         pid_t nr = 0;
14700 @@ -481,6 +485,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14701  }
14702  EXPORT_SYMBOL_GPL(pid_nr_ns);
14703  
14704 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14705 +{
14706 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14707 +}
14708 +
14709  pid_t pid_vnr(struct pid *pid)
14710  {
14711         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14712 diff -NurpP --minimal linux-3.7.1/kernel/pid_namespace.c linux-3.7.1-vs2.3.5.5/kernel/pid_namespace.c
14713 --- linux-3.7.1/kernel/pid_namespace.c  2012-12-11 03:30:57.000000000 +0000
14714 +++ linux-3.7.1-vs2.3.5.5/kernel/pid_namespace.c        2012-12-18 15:13:16.000000000 +0000
14715 @@ -17,6 +17,7 @@
14716  #include <linux/proc_fs.h>
14717  #include <linux/reboot.h>
14718  #include <linux/export.h>
14719 +#include <linux/vserver/global.h>
14720  
14721  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14722  
14723 @@ -100,6 +101,7 @@ static struct pid_namespace *create_pid_
14724                 goto out_free_map;
14725  
14726         kref_init(&ns->kref);
14727 +       atomic_inc(&vs_global_pid_ns);
14728         ns->level = level;
14729         ns->parent = get_pid_ns(parent_pid_ns);
14730  
14731 @@ -131,6 +133,7 @@ static void destroy_pid_namespace(struct
14732  
14733         for (i = 0; i < PIDMAP_ENTRIES; i++)
14734                 kfree(ns->pidmap[i].page);
14735 +       atomic_dec(&vs_global_pid_ns);
14736         kmem_cache_free(pid_ns_cachep, ns);
14737  }
14738  
14739 diff -NurpP --minimal linux-3.7.1/kernel/posix-timers.c linux-3.7.1-vs2.3.5.5/kernel/posix-timers.c
14740 --- linux-3.7.1/kernel/posix-timers.c   2012-12-11 03:30:57.000000000 +0000
14741 +++ linux-3.7.1-vs2.3.5.5/kernel/posix-timers.c 2012-12-18 15:13:16.000000000 +0000
14742 @@ -47,6 +47,7 @@
14743  #include <linux/wait.h>
14744  #include <linux/workqueue.h>
14745  #include <linux/export.h>
14746 +#include <linux/vs_context.h>
14747  
14748  /*
14749   * Management arrays for POSIX timers.  Timers are kept in slab memory
14750 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14751  {
14752         struct task_struct *task;
14753         int shared, ret = -1;
14754 +
14755         /*
14756          * FIXME: if ->sigq is queued we can race with
14757          * dequeue_signal()->do_schedule_next_timer().
14758 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14759         rcu_read_lock();
14760         task = pid_task(timr->it_pid, PIDTYPE_PID);
14761         if (task) {
14762 +               struct vx_info_save vxis;
14763 +               struct vx_info *vxi;
14764 +
14765 +               vxi = get_vx_info(task->vx_info);
14766 +               enter_vx_info(vxi, &vxis);
14767                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14768                 ret = send_sigqueue(timr->sigq, task, shared);
14769 +               leave_vx_info(&vxis);
14770 +               put_vx_info(vxi);
14771         }
14772         rcu_read_unlock();
14773 +
14774         /* If we failed to send the signal the timer stops. */
14775         return ret > 0;
14776  }
14777 diff -NurpP --minimal linux-3.7.1/kernel/printk.c linux-3.7.1-vs2.3.5.5/kernel/printk.c
14778 --- linux-3.7.1/kernel/printk.c 2012-12-11 03:30:57.000000000 +0000
14779 +++ linux-3.7.1-vs2.3.5.5/kernel/printk.c       2012-12-18 15:13:16.000000000 +0000
14780 @@ -42,6 +42,7 @@
14781  #include <linux/notifier.h>
14782  #include <linux/rculist.h>
14783  #include <linux/poll.h>
14784 +#include <linux/vs_cvirt.h>
14785  
14786  #include <asm/uaccess.h>
14787  
14788 @@ -818,7 +819,7 @@ static int check_syslog_permissions(int
14789                 return 0;
14790  
14791         if (syslog_action_restricted(type)) {
14792 -               if (capable(CAP_SYSLOG))
14793 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14794                         return 0;
14795                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14796                 if (capable(CAP_SYS_ADMIN)) {
14797 @@ -1111,12 +1112,9 @@ int do_syslog(int type, char __user *buf
14798         if (error)
14799                 return error;
14800  
14801 -       switch (type) {
14802 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14803 -               break;
14804 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14805 -               break;
14806 -       case SYSLOG_ACTION_READ:        /* Read from log */
14807 +       if ((type == SYSLOG_ACTION_READ) ||
14808 +           (type == SYSLOG_ACTION_READ_ALL) ||
14809 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14810                 error = -EINVAL;
14811                 if (!buf || len < 0)
14812                         goto out;
14813 @@ -1127,6 +1125,16 @@ int do_syslog(int type, char __user *buf
14814                         error = -EFAULT;
14815                         goto out;
14816                 }
14817 +       }
14818 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14819 +               return vx_do_syslog(type, buf, len);
14820 +
14821 +       switch (type) {
14822 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14823 +               break;
14824 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14825 +               break;
14826 +       case SYSLOG_ACTION_READ:        /* Read from log */
14827                 error = wait_event_interruptible(log_wait,
14828                                                  syslog_seq != log_next_seq);
14829                 if (error)
14830 @@ -1139,16 +1147,6 @@ int do_syslog(int type, char __user *buf
14831                 /* FALL THRU */
14832         /* Read last kernel messages */
14833         case SYSLOG_ACTION_READ_ALL:
14834 -               error = -EINVAL;
14835 -               if (!buf || len < 0)
14836 -                       goto out;
14837 -               error = 0;
14838 -               if (!len)
14839 -                       goto out;
14840 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14841 -                       error = -EFAULT;
14842 -                       goto out;
14843 -               }
14844                 error = syslog_print_all(buf, len, clear);
14845                 break;
14846         /* Clear ring buffer */
14847 diff -NurpP --minimal linux-3.7.1/kernel/ptrace.c linux-3.7.1-vs2.3.5.5/kernel/ptrace.c
14848 --- linux-3.7.1/kernel/ptrace.c 2012-12-11 03:30:57.000000000 +0000
14849 +++ linux-3.7.1-vs2.3.5.5/kernel/ptrace.c       2012-12-18 15:13:16.000000000 +0000
14850 @@ -22,6 +22,7 @@
14851  #include <linux/syscalls.h>
14852  #include <linux/uaccess.h>
14853  #include <linux/regset.h>
14854 +#include <linux/vs_context.h>
14855  #include <linux/hw_breakpoint.h>
14856  #include <linux/cn_proc.h>
14857  
14858 @@ -217,6 +218,11 @@ ok:
14859                 dumpable = get_dumpable(task->mm);
14860         if (!dumpable  && !ptrace_has_cap(task_user_ns(task), mode))
14861                 return -EPERM;
14862 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14863 +               return -EPERM;
14864 +       if (!vx_check(task->xid, VS_IDENT) &&
14865 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14866 +               return -EACCES;
14867  
14868         return security_ptrace_access_check(task, mode);
14869  }
14870 diff -NurpP --minimal linux-3.7.1/kernel/sched/core.c linux-3.7.1-vs2.3.5.5/kernel/sched/core.c
14871 --- linux-3.7.1/kernel/sched/core.c     2012-12-11 03:30:57.000000000 +0000
14872 +++ linux-3.7.1-vs2.3.5.5/kernel/sched/core.c   2012-12-18 15:13:16.000000000 +0000
14873 @@ -72,6 +72,8 @@
14874  #include <linux/slab.h>
14875  #include <linux/init_task.h>
14876  #include <linux/binfmts.h>
14877 +#include <linux/vs_sched.h>
14878 +#include <linux/vs_cvirt.h>
14879  
14880  #include <asm/switch_to.h>
14881  #include <asm/tlb.h>
14882 @@ -2030,9 +2032,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14883   */
14884  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14885  {
14886 -       loads[0] = (avenrun[0] + offset) << shift;
14887 -       loads[1] = (avenrun[1] + offset) << shift;
14888 -       loads[2] = (avenrun[2] + offset) << shift;
14889 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14890 +               struct vx_info *vxi = current_vx_info();
14891 +
14892 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14893 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14894 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14895 +       } else {
14896 +               loads[0] = (avenrun[0] + offset) << shift;
14897 +               loads[1] = (avenrun[1] + offset) << shift;
14898 +               loads[2] = (avenrun[2] + offset) << shift;
14899 +       }
14900  }
14901  
14902  static long calc_load_fold_active(struct rq *this_rq)
14903 @@ -3596,7 +3606,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14904                 nice = 19;
14905  
14906         if (increment < 0 && !can_nice(current, nice))
14907 -               return -EPERM;
14908 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14909  
14910         retval = security_task_setnice(current, nice);
14911         if (retval)
14912 diff -NurpP --minimal linux-3.7.1/kernel/sched/cputime.c linux-3.7.1-vs2.3.5.5/kernel/sched/cputime.c
14913 --- linux-3.7.1/kernel/sched/cputime.c  2012-12-11 03:30:57.000000000 +0000
14914 +++ linux-3.7.1-vs2.3.5.5/kernel/sched/cputime.c        2012-12-18 15:13:16.000000000 +0000
14915 @@ -3,6 +3,7 @@
14916  #include <linux/tsacct_kern.h>
14917  #include <linux/kernel_stat.h>
14918  #include <linux/static_key.h>
14919 +#include <linux/vs_sched.h>
14920  #include "sched.h"
14921  
14922  
14923 @@ -150,14 +151,17 @@ static inline void task_group_account_fi
14924  void account_user_time(struct task_struct *p, cputime_t cputime,
14925                        cputime_t cputime_scaled)
14926  {
14927 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14928 +       int nice = (TASK_NICE(p) > 0);
14929         int index;
14930  
14931         /* Add user time to process. */
14932         p->utime += cputime;
14933         p->utimescaled += cputime_scaled;
14934 +       vx_account_user(vxi, cputime, nice);
14935         account_group_user_time(p, cputime);
14936  
14937 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14938 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14939  
14940         /* Add user time to cpustat. */
14941         task_group_account_field(p, index, (__force u64) cputime);
14942 @@ -204,9 +208,12 @@ static inline
14943  void __account_system_time(struct task_struct *p, cputime_t cputime,
14944                         cputime_t cputime_scaled, int index)
14945  {
14946 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14947 +
14948         /* Add system time to process. */
14949         p->stime += cputime;
14950         p->stimescaled += cputime_scaled;
14951 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14952         account_group_system_time(p, cputime);
14953  
14954         /* Add system time to cpustat. */
14955 diff -NurpP --minimal linux-3.7.1/kernel/sched/fair.c linux-3.7.1-vs2.3.5.5/kernel/sched/fair.c
14956 --- linux-3.7.1/kernel/sched/fair.c     2012-12-11 03:30:57.000000000 +0000
14957 +++ linux-3.7.1-vs2.3.5.5/kernel/sched/fair.c   2012-12-18 15:13:16.000000000 +0000
14958 @@ -26,6 +26,7 @@
14959  #include <linux/slab.h>
14960  #include <linux/profile.h>
14961  #include <linux/interrupt.h>
14962 +#include <linux/vs_cvirt.h>
14963  
14964  #include <trace/events/sched.h>
14965  
14966 @@ -1111,6 +1112,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14967                 __enqueue_entity(cfs_rq, se);
14968         se->on_rq = 1;
14969  
14970 +       if (entity_is_task(se))
14971 +               vx_activate_task(task_of(se));
14972         if (cfs_rq->nr_running == 1) {
14973                 list_add_leaf_cfs_rq(cfs_rq);
14974                 check_enqueue_throttle(cfs_rq);
14975 @@ -1191,6 +1194,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14976         if (se != cfs_rq->curr)
14977                 __dequeue_entity(cfs_rq, se);
14978         se->on_rq = 0;
14979 +       if (entity_is_task(se))
14980 +               vx_deactivate_task(task_of(se));
14981         update_cfs_load(cfs_rq, 0);
14982         account_entity_dequeue(cfs_rq, se);
14983  
14984 diff -NurpP --minimal linux-3.7.1/kernel/signal.c linux-3.7.1-vs2.3.5.5/kernel/signal.c
14985 --- linux-3.7.1/kernel/signal.c 2012-12-11 03:30:57.000000000 +0000
14986 +++ linux-3.7.1-vs2.3.5.5/kernel/signal.c       2012-12-18 15:13:16.000000000 +0000
14987 @@ -31,6 +31,8 @@
14988  #include <linux/nsproxy.h>
14989  #include <linux/user_namespace.h>
14990  #include <linux/uprobes.h>
14991 +#include <linux/vs_context.h>
14992 +#include <linux/vs_pid.h>
14993  #define CREATE_TRACE_POINTS
14994  #include <trace/events/signal.h>
14995  
14996 @@ -791,9 +793,18 @@ static int check_kill_permission(int sig
14997         struct pid *sid;
14998         int error;
14999  
15000 +       vxdprintk(VXD_CBIT(misc, 7),
15001 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15002 +               sig, info, t, vx_task_xid(t), t->pid);
15003 +
15004         if (!valid_signal(sig))
15005                 return -EINVAL;
15006  
15007 +/*     FIXME: needed? if so, why?
15008 +       if ((info != SEND_SIG_NOINFO) &&
15009 +               (is_si_special(info) || !si_fromuser(info)))
15010 +               goto skip;      */
15011 +
15012         if (!si_fromuser(info))
15013                 return 0;
15014  
15015 @@ -817,6 +828,20 @@ static int check_kill_permission(int sig
15016                 }
15017         }
15018  
15019 +       error = -EPERM;
15020 +       if (t->pid == 1 && current->xid)
15021 +               return error;
15022 +
15023 +       error = -ESRCH;
15024 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15025 +                 loops, maybe ENOENT or EACCES? */
15026 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15027 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15028 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15029 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15030 +               return error;
15031 +       }
15032 +/* skip: */
15033         return security_task_kill(t, info, sig, 0);
15034  }
15035  
15036 @@ -1352,7 +1377,7 @@ int kill_pid_info(int sig, struct siginf
15037         rcu_read_lock();
15038  retry:
15039         p = pid_task(pid, PIDTYPE_PID);
15040 -       if (p) {
15041 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15042                 error = group_send_sig_info(sig, info, p);
15043                 if (unlikely(error == -ESRCH))
15044                         /*
15045 @@ -1400,7 +1425,7 @@ int kill_pid_info_as_cred(int sig, struc
15046  
15047         rcu_read_lock();
15048         p = pid_task(pid, PIDTYPE_PID);
15049 -       if (!p) {
15050 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15051                 ret = -ESRCH;
15052                 goto out_unlock;
15053         }
15054 @@ -1452,8 +1477,10 @@ static int kill_something_info(int sig,
15055                 struct task_struct * p;
15056  
15057                 for_each_process(p) {
15058 -                       if (task_pid_vnr(p) > 1 &&
15059 -                                       !same_thread_group(p, current)) {
15060 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15061 +                               task_pid_vnr(p) > 1 &&
15062 +                               !same_thread_group(p, current) &&
15063 +                               !vx_current_initpid(p->pid)) {
15064                                 int err = group_send_sig_info(sig, info, p);
15065                                 ++count;
15066                                 if (err != -EPERM)
15067 @@ -2308,6 +2335,11 @@ relock:
15068                                 !sig_kernel_only(signr))
15069                         continue;
15070  
15071 +               /* virtual init is protected against user signals */
15072 +               if ((info->si_code == SI_USER) &&
15073 +                       vx_current_initpid(current->pid))
15074 +                       continue;
15075 +
15076                 if (sig_kernel_stop(signr)) {
15077                         /*
15078                          * The default action is to stop all threads in
15079 diff -NurpP --minimal linux-3.7.1/kernel/softirq.c linux-3.7.1-vs2.3.5.5/kernel/softirq.c
15080 --- linux-3.7.1/kernel/softirq.c        2012-12-11 03:30:57.000000000 +0000
15081 +++ linux-3.7.1-vs2.3.5.5/kernel/softirq.c      2012-12-18 15:13:16.000000000 +0000
15082 @@ -25,6 +25,7 @@
15083  #include <linux/smp.h>
15084  #include <linux/smpboot.h>
15085  #include <linux/tick.h>
15086 +#include <linux/vs_context.h>
15087  
15088  #define CREATE_TRACE_POINTS
15089  #include <trace/events/irq.h>
15090 diff -NurpP --minimal linux-3.7.1/kernel/sys.c linux-3.7.1-vs2.3.5.5/kernel/sys.c
15091 --- linux-3.7.1/kernel/sys.c    2012-12-11 03:30:57.000000000 +0000
15092 +++ linux-3.7.1-vs2.3.5.5/kernel/sys.c  2012-12-18 15:13:16.000000000 +0000
15093 @@ -47,6 +47,7 @@
15094  #include <linux/syscalls.h>
15095  #include <linux/kprobes.h>
15096  #include <linux/user_namespace.h>
15097 +#include <linux/vs_pid.h>
15098  
15099  #include <linux/kmsg_dump.h>
15100  /* Move somewhere else to avoid recompiling? */
15101 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
15102                 goto out;
15103         }
15104         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15105 -               error = -EACCES;
15106 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15107 +                       error = 0;
15108 +               else
15109 +                       error = -EACCES;
15110                 goto out;
15111         }
15112         no_nice = security_task_setnice(p, niceval);
15113 @@ -205,6 +209,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15114                         else
15115                                 pgrp = task_pgrp(current);
15116                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15117 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15118 +                                       continue;
15119                                 error = set_one_prio(p, niceval, error);
15120                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15121                         break;
15122 @@ -270,6 +276,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15123                         else
15124                                 pgrp = task_pgrp(current);
15125                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15126 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15127 +                                       continue;
15128                                 niceval = 20 - task_nice(p);
15129                                 if (niceval > retval)
15130                                         retval = niceval;
15131 @@ -422,6 +430,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15132  
15133  static DEFINE_MUTEX(reboot_mutex);
15134  
15135 +long vs_reboot(unsigned int, void __user *);
15136 +
15137  /*
15138   * Reboot system call: for obvious reasons only root may call it,
15139   * and even root needs to set up some magic numbers in the registers
15140 @@ -463,6 +473,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15141         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15142                 cmd = LINUX_REBOOT_CMD_HALT;
15143  
15144 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15145 +               return vs_reboot(cmd, arg);
15146 +
15147         mutex_lock(&reboot_mutex);
15148         switch (cmd) {
15149         case LINUX_REBOOT_CMD_RESTART:
15150 @@ -1370,7 +1383,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15151         int errno;
15152         char tmp[__NEW_UTS_LEN];
15153  
15154 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15155 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15156 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15157                 return -EPERM;
15158  
15159         if (len < 0 || len > __NEW_UTS_LEN)
15160 @@ -1421,7 +1435,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15161         int errno;
15162         char tmp[__NEW_UTS_LEN];
15163  
15164 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15165 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15166 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15167                 return -EPERM;
15168         if (len < 0 || len > __NEW_UTS_LEN)
15169                 return -EINVAL;
15170 @@ -1540,7 +1555,7 @@ int do_prlimit(struct task_struct *tsk,
15171                 /* Keep the capable check against init_user_ns until
15172                    cgroups can contain all limits */
15173                 if (new_rlim->rlim_max > rlim->rlim_max &&
15174 -                               !capable(CAP_SYS_RESOURCE))
15175 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15176                         retval = -EPERM;
15177                 if (!retval)
15178                         retval = security_task_setrlimit(tsk->group_leader,
15179 @@ -1593,7 +1608,8 @@ static int check_prlimit_permission(stru
15180             gid_eq(cred->gid, tcred->sgid) &&
15181             gid_eq(cred->gid, tcred->gid))
15182                 return 0;
15183 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15184 +       if (vx_ns_capable(tcred->user_ns,
15185 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15186                 return 0;
15187  
15188         return -EPERM;
15189 diff -NurpP --minimal linux-3.7.1/kernel/sysctl.c linux-3.7.1-vs2.3.5.5/kernel/sysctl.c
15190 --- linux-3.7.1/kernel/sysctl.c 2012-12-11 03:30:57.000000000 +0000
15191 +++ linux-3.7.1-vs2.3.5.5/kernel/sysctl.c       2012-12-18 15:13:16.000000000 +0000
15192 @@ -82,6 +82,7 @@
15193  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15194  #include <linux/lockdep.h>
15195  #endif
15196 +extern char vshelper_path[];
15197  #ifdef CONFIG_CHR_DEV_SG
15198  #include <scsi/sg.h>
15199  #endif
15200 @@ -574,6 +575,13 @@ static struct ctl_table kern_table[] = {
15201                 .proc_handler   = proc_dostring,
15202         },
15203  #endif
15204 +       {
15205 +               .procname       = "vshelper",
15206 +               .data           = &vshelper_path,
15207 +               .maxlen         = 256,
15208 +               .mode           = 0644,
15209 +               .proc_handler   = &proc_dostring,
15210 +       },
15211  #ifdef CONFIG_CHR_DEV_SG
15212         {
15213                 .procname       = "sg-big-buff",
15214 diff -NurpP --minimal linux-3.7.1/kernel/sysctl_binary.c linux-3.7.1-vs2.3.5.5/kernel/sysctl_binary.c
15215 --- linux-3.7.1/kernel/sysctl_binary.c  2012-12-11 03:30:57.000000000 +0000
15216 +++ linux-3.7.1-vs2.3.5.5/kernel/sysctl_binary.c        2012-12-18 15:13:16.000000000 +0000
15217 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15218  
15219         { CTL_INT,      KERN_PANIC,                     "panic" },
15220         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15221 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15222  
15223         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15224         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15225 diff -NurpP --minimal linux-3.7.1/kernel/time/timekeeping.c linux-3.7.1-vs2.3.5.5/kernel/time/timekeeping.c
15226 --- linux-3.7.1/kernel/time/timekeeping.c       2012-12-11 03:30:57.000000000 +0000
15227 +++ linux-3.7.1-vs2.3.5.5/kernel/time/timekeeping.c     2012-12-18 15:13:16.000000000 +0000
15228 @@ -21,6 +21,7 @@
15229  #include <linux/time.h>
15230  #include <linux/tick.h>
15231  #include <linux/stop_machine.h>
15232 +#include <linux/vs_time.h>
15233  
15234  
15235  static struct timekeeper timekeeper;
15236 @@ -243,6 +244,7 @@ void getnstimeofday(struct timespec *ts)
15237  
15238         ts->tv_nsec = 0;
15239         timespec_add_ns(ts, nsecs);
15240 +       vx_adjust_timespec(ts);
15241  }
15242  EXPORT_SYMBOL(getnstimeofday);
15243  
15244 diff -NurpP --minimal linux-3.7.1/kernel/time.c linux-3.7.1-vs2.3.5.5/kernel/time.c
15245 --- linux-3.7.1/kernel/time.c   2012-12-11 03:30:57.000000000 +0000
15246 +++ linux-3.7.1-vs2.3.5.5/kernel/time.c 2012-12-18 15:13:16.000000000 +0000
15247 @@ -37,6 +37,7 @@
15248  #include <linux/fs.h>
15249  #include <linux/math64.h>
15250  #include <linux/ptrace.h>
15251 +#include <linux/vs_time.h>
15252  
15253  #include <asm/uaccess.h>
15254  #include <asm/unistd.h>
15255 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15256         if (err)
15257                 return err;
15258  
15259 -       do_settimeofday(&tv);
15260 +       vx_settimeofday(&tv);
15261         return 0;
15262  }
15263  
15264 @@ -172,7 +173,7 @@ int do_sys_settimeofday(const struct tim
15265                 }
15266         }
15267         if (tv)
15268 -               return do_settimeofday(tv);
15269 +               return vx_settimeofday(tv);
15270         return 0;
15271  }
15272  
15273 diff -NurpP --minimal linux-3.7.1/kernel/timer.c linux-3.7.1-vs2.3.5.5/kernel/timer.c
15274 --- linux-3.7.1/kernel/timer.c  2012-12-11 03:30:57.000000000 +0000
15275 +++ linux-3.7.1-vs2.3.5.5/kernel/timer.c        2012-12-18 15:13:16.000000000 +0000
15276 @@ -40,6 +40,10 @@
15277  #include <linux/irq_work.h>
15278  #include <linux/sched.h>
15279  #include <linux/slab.h>
15280 +#include <linux/vs_base.h>
15281 +#include <linux/vs_cvirt.h>
15282 +#include <linux/vs_pid.h>
15283 +#include <linux/vserver/sched.h>
15284  
15285  #include <asm/uaccess.h>
15286  #include <asm/unistd.h>
15287 diff -NurpP --minimal linux-3.7.1/kernel/user_namespace.c linux-3.7.1-vs2.3.5.5/kernel/user_namespace.c
15288 --- linux-3.7.1/kernel/user_namespace.c 2012-12-11 03:30:57.000000000 +0000
15289 +++ linux-3.7.1-vs2.3.5.5/kernel/user_namespace.c       2012-12-18 15:13:16.000000000 +0000
15290 @@ -20,6 +20,7 @@
15291  #include <linux/uaccess.h>
15292  #include <linux/ctype.h>
15293  #include <linux/projid.h>
15294 +#include <linux/vserver/global.h>
15295  
15296  static struct kmem_cache *user_ns_cachep __read_mostly;
15297  
15298 @@ -53,6 +54,7 @@ int create_user_ns(struct cred *new)
15299                 return -ENOMEM;
15300  
15301         kref_init(&ns->kref);
15302 +       atomic_inc(&vs_global_user_ns);
15303         ns->parent = parent_ns;
15304         ns->owner = owner;
15305         ns->group = group;
15306 @@ -85,6 +87,9 @@ void free_user_ns(struct kref *kref)
15307  
15308         parent = ns->parent;
15309         kmem_cache_free(user_ns_cachep, ns);
15310 +
15311 +       /* FIXME: maybe move into destroyer? */
15312 +       atomic_dec(&vs_global_user_ns);
15313         put_user_ns(parent);
15314  }
15315  EXPORT_SYMBOL(free_user_ns);
15316 diff -NurpP --minimal linux-3.7.1/kernel/utsname.c linux-3.7.1-vs2.3.5.5/kernel/utsname.c
15317 --- linux-3.7.1/kernel/utsname.c        2012-12-11 03:30:57.000000000 +0000
15318 +++ linux-3.7.1-vs2.3.5.5/kernel/utsname.c      2012-12-18 15:13:16.000000000 +0000
15319 @@ -16,14 +16,17 @@
15320  #include <linux/slab.h>
15321  #include <linux/user_namespace.h>
15322  #include <linux/proc_fs.h>
15323 +#include <linux/vserver/global.h>
15324  
15325  static struct uts_namespace *create_uts_ns(void)
15326  {
15327         struct uts_namespace *uts_ns;
15328  
15329         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15330 -       if (uts_ns)
15331 +       if (uts_ns) {
15332                 kref_init(&uts_ns->kref);
15333 +               atomic_inc(&vs_global_uts_ns);
15334 +       }
15335         return uts_ns;
15336  }
15337  
15338 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15339   * @old_ns: namespace to clone
15340   * Return NULL on error (failure to kmalloc), new ns otherwise
15341   */
15342 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15343 -                                         struct uts_namespace *old_ns)
15344 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15345 +                                         struct user_namespace *old_user)
15346  {
15347         struct uts_namespace *ns;
15348  
15349 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15350  
15351         down_read(&uts_sem);
15352         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15353 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user_ns));
15354 +       ns->user_ns = get_user_ns(old_user);
15355         up_read(&uts_sem);
15356         return ns;
15357  }
15358 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15359   * versa.
15360   */
15361  struct uts_namespace *copy_utsname(unsigned long flags,
15362 -                                  struct task_struct *tsk)
15363 +                                  struct uts_namespace *old_ns,
15364 +                                  struct user_namespace *user_ns)
15365  {
15366 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15367         struct uts_namespace *new_ns;
15368  
15369         BUG_ON(!old_ns);
15370 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15371         if (!(flags & CLONE_NEWUTS))
15372                 return old_ns;
15373  
15374 -       new_ns = clone_uts_ns(tsk, old_ns);
15375 +       new_ns = clone_uts_ns(old_ns, user_ns);
15376  
15377         put_uts_ns(old_ns);
15378         return new_ns;
15379 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15380  
15381         ns = container_of(kref, struct uts_namespace, kref);
15382         put_user_ns(ns->user_ns);
15383 +       atomic_dec(&vs_global_uts_ns);
15384         kfree(ns);
15385  }
15386  
15387 diff -NurpP --minimal linux-3.7.1/kernel/vserver/Kconfig linux-3.7.1-vs2.3.5.5/kernel/vserver/Kconfig
15388 --- linux-3.7.1/kernel/vserver/Kconfig  1970-01-01 00:00:00.000000000 +0000
15389 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/Kconfig        2012-12-18 15:13:16.000000000 +0000
15390 @@ -0,0 +1,233 @@
15391 +#
15392 +# Linux VServer configuration
15393 +#
15394 +
15395 +menu "Linux VServer"
15396 +
15397 +config VSERVER_AUTO_LBACK
15398 +       bool    "Automatically Assign Loopback IP"
15399 +       default y
15400 +       help
15401 +         Automatically assign a guest specific loopback
15402 +         IP and add it to the kernel network stack on
15403 +         startup.
15404 +
15405 +config VSERVER_AUTO_SINGLE
15406 +       bool    "Automatic Single IP Special Casing"
15407 +       depends on EXPERIMENTAL
15408 +       default y
15409 +       help
15410 +         This allows network contexts with a single IP to
15411 +         automatically remap 0.0.0.0 bindings to that IP,
15412 +         avoiding further network checks and improving
15413 +         performance.
15414 +
15415 +         (note: such guests do not allow to change the ip
15416 +          on the fly and do not show loopback addresses)
15417 +
15418 +config VSERVER_COWBL
15419 +       bool    "Enable COW Immutable Link Breaking"
15420 +       default y
15421 +       help
15422 +         This enables the COW (Copy-On-Write) link break code.
15423 +         It allows you to treat unified files like normal files
15424 +         when writing to them (which will implicitely break the
15425 +         link and create a copy of the unified file)
15426 +
15427 +config VSERVER_VTIME
15428 +       bool    "Enable Virtualized Guest Time"
15429 +       depends on EXPERIMENTAL
15430 +       default n
15431 +       help
15432 +         This enables per guest time offsets to allow for
15433 +         adjusting the system clock individually per guest.
15434 +         this adds some overhead to the time functions and
15435 +         therefore should not be enabled without good reason.
15436 +
15437 +config VSERVER_DEVICE
15438 +       bool    "Enable Guest Device Mapping"
15439 +       depends on EXPERIMENTAL
15440 +       default n
15441 +       help
15442 +         This enables generic device remapping.
15443 +
15444 +config VSERVER_PROC_SECURE
15445 +       bool    "Enable Proc Security"
15446 +       depends on PROC_FS
15447 +       default y
15448 +       help
15449 +         This configures ProcFS security to initially hide
15450 +         non-process entries for all contexts except the main and
15451 +         spectator context (i.e. for all guests), which is a secure
15452 +         default.
15453 +
15454 +         (note: on 1.2x the entries were visible by default)
15455 +
15456 +choice
15457 +       prompt  "Persistent Inode Tagging"
15458 +       default TAGGING_ID24
15459 +       help
15460 +         This adds persistent context information to filesystems
15461 +         mounted with the tagxid option. Tagging is a requirement
15462 +         for per-context disk limits and per-context quota.
15463 +
15464 +
15465 +config TAGGING_NONE
15466 +       bool    "Disabled"
15467 +       help
15468 +         do not store per-context information in inodes.
15469 +
15470 +config TAGGING_UID16
15471 +       bool    "UID16/GID32"
15472 +       help
15473 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15474 +
15475 +config TAGGING_GID16
15476 +       bool    "UID32/GID16"
15477 +       help
15478 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15479 +
15480 +config TAGGING_ID24
15481 +       bool    "UID24/GID24"
15482 +       help
15483 +         uses the upper 8bit from UID and GID for XID tagging
15484 +         which leaves 24bit for UID/GID each, which should be
15485 +         more than sufficient for normal use.
15486 +
15487 +config TAGGING_INTERN
15488 +       bool    "UID32/GID32"
15489 +       help
15490 +         this uses otherwise reserved inode fields in the on
15491 +         disk representation, which limits the use to a few
15492 +         filesystems (currently ext2 and ext3)
15493 +
15494 +endchoice
15495 +
15496 +config TAG_NFSD
15497 +       bool    "Tag NFSD User Auth and Files"
15498 +       default n
15499 +       help
15500 +         Enable this if you do want the in-kernel NFS
15501 +         Server to use the tagging specified above.
15502 +         (will require patched clients too)
15503 +
15504 +config VSERVER_PRIVACY
15505 +       bool    "Honor Privacy Aspects of Guests"
15506 +       default n
15507 +       help
15508 +         When enabled, most context checks will disallow
15509 +         access to structures assigned to a specific context,
15510 +         like ptys or loop devices.
15511 +
15512 +config VSERVER_CONTEXTS
15513 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15514 +       range 1 65533
15515 +       default "768"   if 64BIT
15516 +       default "256"
15517 +       help
15518 +         This setting will optimize certain data structures
15519 +         and memory allocations according to the expected
15520 +         maximum.
15521 +
15522 +         note: this is not a strict upper limit.
15523 +
15524 +config VSERVER_WARN
15525 +       bool    "VServer Warnings"
15526 +       default y
15527 +       help
15528 +         This enables various runtime warnings, which will
15529 +         notify about potential manipulation attempts or
15530 +         resource shortage. It is generally considered to
15531 +         be a good idea to have that enabled.
15532 +
15533 +config VSERVER_WARN_DEVPTS
15534 +       bool    "VServer DevPTS Warnings"
15535 +       depends on VSERVER_WARN
15536 +       default y
15537 +       help
15538 +         This enables DevPTS related warnings, issued when a
15539 +         process inside a context tries to lookup or access
15540 +         a dynamic pts from the host or a different context.
15541 +
15542 +config VSERVER_DEBUG
15543 +       bool    "VServer Debugging Code"
15544 +       default n
15545 +       help
15546 +         Set this to yes if you want to be able to activate
15547 +         debugging output at runtime. It adds a very small
15548 +         overhead to all vserver related functions and
15549 +         increases the kernel size by about 20k.
15550 +
15551 +config VSERVER_HISTORY
15552 +       bool    "VServer History Tracing"
15553 +       depends on VSERVER_DEBUG
15554 +       default n
15555 +       help
15556 +         Set this to yes if you want to record the history of
15557 +         linux-vserver activities, so they can be replayed in
15558 +         the event of a kernel panic or oops.
15559 +
15560 +config VSERVER_HISTORY_SIZE
15561 +       int     "Per-CPU History Size (32-65536)"
15562 +       depends on VSERVER_HISTORY
15563 +       range 32 65536
15564 +       default 64
15565 +       help
15566 +         This allows you to specify the number of entries in
15567 +         the per-CPU history buffer.
15568 +
15569 +config VSERVER_EXTRA_MNT_CHECK
15570 +       bool    "Extra Checks for Reachability"
15571 +       default n
15572 +       help
15573 +         Set this to yes if you want to do extra checks for
15574 +         vfsmount reachability in the proc filesystem code.
15575 +         This shouldn't be required on any setup utilizing
15576 +         mnt namespaces.
15577 +
15578 +choice
15579 +       prompt  "Quotes used in debug and warn messages"
15580 +       default QUOTES_ISO8859
15581 +
15582 +config QUOTES_ISO8859
15583 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15584 +       help
15585 +         This uses the extended ASCII characters \xbb
15586 +         and \xab for quoting file and process names.
15587 +
15588 +config QUOTES_UTF8
15589 +       bool    "UTF-8 angle quotes"
15590 +       help
15591 +         This uses the the UTF-8 sequences for angle
15592 +         quotes to quote file and process names.
15593 +
15594 +config QUOTES_ASCII
15595 +       bool    "ASCII single quotes"
15596 +       help
15597 +         This uses the ASCII single quote character
15598 +         (\x27) to quote file and process names.
15599 +
15600 +endchoice
15601 +
15602 +endmenu
15603 +
15604 +
15605 +config VSERVER
15606 +       bool
15607 +       default y
15608 +       select NAMESPACES
15609 +       select UTS_NS
15610 +       select IPC_NS
15611 +#      select USER_NS
15612 +       select SYSVIPC
15613 +
15614 +config VSERVER_SECURITY
15615 +       bool
15616 +       depends on SECURITY
15617 +       default y
15618 +       select SECURITY_CAPABILITIES
15619 +
15620 +config VSERVER_DISABLED
15621 +       bool
15622 +       default n
15623 +
15624 diff -NurpP --minimal linux-3.7.1/kernel/vserver/Makefile linux-3.7.1-vs2.3.5.5/kernel/vserver/Makefile
15625 --- linux-3.7.1/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15626 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/Makefile       2012-12-18 15:13:16.000000000 +0000
15627 @@ -0,0 +1,18 @@
15628 +#
15629 +# Makefile for the Linux vserver routines.
15630 +#
15631 +
15632 +
15633 +obj-y          += vserver.o
15634 +
15635 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15636 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15637 +                  dlimit.o tag.o
15638 +
15639 +vserver-$(CONFIG_INET) += inet.o
15640 +vserver-$(CONFIG_PROC_FS) += proc.o
15641 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15642 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15643 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15644 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15645 +
15646 diff -NurpP --minimal linux-3.7.1/kernel/vserver/cacct.c linux-3.7.1-vs2.3.5.5/kernel/vserver/cacct.c
15647 --- linux-3.7.1/kernel/vserver/cacct.c  1970-01-01 00:00:00.000000000 +0000
15648 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/cacct.c        2012-12-18 15:13:16.000000000 +0000
15649 @@ -0,0 +1,42 @@
15650 +/*
15651 + *  linux/kernel/vserver/cacct.c
15652 + *
15653 + *  Virtual Server: Context Accounting
15654 + *
15655 + *  Copyright (C) 2006-2007 Herbert Pötzl
15656 + *
15657 + *  V0.01  added accounting stats
15658 + *
15659 + */
15660 +
15661 +#include <linux/types.h>
15662 +#include <linux/vs_context.h>
15663 +#include <linux/vserver/cacct_cmd.h>
15664 +#include <linux/vserver/cacct_int.h>
15665 +
15666 +#include <asm/errno.h>
15667 +#include <asm/uaccess.h>
15668 +
15669 +
15670 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15671 +{
15672 +       struct vcmd_sock_stat_v0 vc_data;
15673 +       int j, field;
15674 +
15675 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15676 +               return -EFAULT;
15677 +
15678 +       field = vc_data.field;
15679 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15680 +               return -EINVAL;
15681 +
15682 +       for (j = 0; j < 3; j++) {
15683 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15684 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15685 +       }
15686 +
15687 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15688 +               return -EFAULT;
15689 +       return 0;
15690 +}
15691 +
15692 diff -NurpP --minimal linux-3.7.1/kernel/vserver/cacct_init.h linux-3.7.1-vs2.3.5.5/kernel/vserver/cacct_init.h
15693 --- linux-3.7.1/kernel/vserver/cacct_init.h     1970-01-01 00:00:00.000000000 +0000
15694 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/cacct_init.h   2012-12-18 15:13:16.000000000 +0000
15695 @@ -0,0 +1,25 @@
15696 +
15697 +
15698 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15699 +{
15700 +       int i, j;
15701 +
15702 +
15703 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15704 +               for (j = 0; j < 3; j++) {
15705 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15706 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15707 +               }
15708 +       }
15709 +       for (i = 0; i < 8; i++)
15710 +               atomic_set(&cacct->slab[i], 0);
15711 +       for (i = 0; i < 5; i++)
15712 +               for (j = 0; j < 4; j++)
15713 +                       atomic_set(&cacct->page[i][j], 0);
15714 +}
15715 +
15716 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15717 +{
15718 +       return;
15719 +}
15720 +
15721 diff -NurpP --minimal linux-3.7.1/kernel/vserver/cacct_proc.h linux-3.7.1-vs2.3.5.5/kernel/vserver/cacct_proc.h
15722 --- linux-3.7.1/kernel/vserver/cacct_proc.h     1970-01-01 00:00:00.000000000 +0000
15723 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/cacct_proc.h   2012-12-18 15:13:16.000000000 +0000
15724 @@ -0,0 +1,53 @@
15725 +#ifndef _VX_CACCT_PROC_H
15726 +#define _VX_CACCT_PROC_H
15727 +
15728 +#include <linux/vserver/cacct_int.h>
15729 +
15730 +
15731 +#define VX_SOCKA_TOP   \
15732 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15733 +
15734 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15735 +{
15736 +       int i, j, length = 0;
15737 +       static char *type[VXA_SOCK_SIZE] = {
15738 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15739 +       };
15740 +
15741 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15742 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15743 +               length += sprintf(buffer + length, "%s:", type[i]);
15744 +               for (j = 0; j < 3; j++) {
15745 +                       length += sprintf(buffer + length,
15746 +                               "\t%10lu/%-10lu",
15747 +                               vx_sock_count(cacct, i, j),
15748 +                               vx_sock_total(cacct, i, j));
15749 +               }
15750 +               buffer[length++] = '\n';
15751 +       }
15752 +
15753 +       length += sprintf(buffer + length, "\n");
15754 +       length += sprintf(buffer + length,
15755 +               "slab:\t %8u %8u %8u %8u\n",
15756 +               atomic_read(&cacct->slab[1]),
15757 +               atomic_read(&cacct->slab[4]),
15758 +               atomic_read(&cacct->slab[0]),
15759 +               atomic_read(&cacct->slab[2]));
15760 +
15761 +       length += sprintf(buffer + length, "\n");
15762 +       for (i = 0; i < 5; i++) {
15763 +               length += sprintf(buffer + length,
15764 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15765 +                       atomic_read(&cacct->page[i][0]),
15766 +                       atomic_read(&cacct->page[i][1]),
15767 +                       atomic_read(&cacct->page[i][2]),
15768 +                       atomic_read(&cacct->page[i][3]),
15769 +                       atomic_read(&cacct->page[i][4]),
15770 +                       atomic_read(&cacct->page[i][5]),
15771 +                       atomic_read(&cacct->page[i][6]),
15772 +                       atomic_read(&cacct->page[i][7]));
15773 +       }
15774 +       return length;
15775 +}
15776 +
15777 +#endif /* _VX_CACCT_PROC_H */
15778 diff -NurpP --minimal linux-3.7.1/kernel/vserver/context.c linux-3.7.1-vs2.3.5.5/kernel/vserver/context.c
15779 --- linux-3.7.1/kernel/vserver/context.c        1970-01-01 00:00:00.000000000 +0000
15780 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/context.c      2012-12-18 15:13:16.000000000 +0000
15781 @@ -0,0 +1,1119 @@
15782 +/*
15783 + *  linux/kernel/vserver/context.c
15784 + *
15785 + *  Virtual Server: Context Support
15786 + *
15787 + *  Copyright (C) 2003-2011  Herbert Pötzl
15788 + *
15789 + *  V0.01  context helper
15790 + *  V0.02  vx_ctx_kill syscall command
15791 + *  V0.03  replaced context_info calls
15792 + *  V0.04  redesign of struct (de)alloc
15793 + *  V0.05  rlimit basic implementation
15794 + *  V0.06  task_xid and info commands
15795 + *  V0.07  context flags and caps
15796 + *  V0.08  switch to RCU based hash
15797 + *  V0.09  revert to non RCU for now
15798 + *  V0.10  and back to working RCU hash
15799 + *  V0.11  and back to locking again
15800 + *  V0.12  referenced context store
15801 + *  V0.13  separate per cpu data
15802 + *  V0.14  changed vcmds to vxi arg
15803 + *  V0.15  added context stat
15804 + *  V0.16  have __create claim() the vxi
15805 + *  V0.17  removed older and legacy stuff
15806 + *  V0.18  added user credentials
15807 + *  V0.19  added warn mask
15808 + *
15809 + */
15810 +
15811 +#include <linux/slab.h>
15812 +#include <linux/types.h>
15813 +#include <linux/security.h>
15814 +#include <linux/pid_namespace.h>
15815 +#include <linux/capability.h>
15816 +
15817 +#include <linux/vserver/context.h>
15818 +#include <linux/vserver/network.h>
15819 +#include <linux/vserver/debug.h>
15820 +#include <linux/vserver/limit.h>
15821 +#include <linux/vserver/limit_int.h>
15822 +#include <linux/vserver/space.h>
15823 +#include <linux/init_task.h>
15824 +#include <linux/fs_struct.h>
15825 +#include <linux/cred.h>
15826 +
15827 +#include <linux/vs_context.h>
15828 +#include <linux/vs_limit.h>
15829 +#include <linux/vs_pid.h>
15830 +#include <linux/vserver/context_cmd.h>
15831 +
15832 +#include "cvirt_init.h"
15833 +#include "cacct_init.h"
15834 +#include "limit_init.h"
15835 +#include "sched_init.h"
15836 +
15837 +
15838 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15839 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15840 +
15841 +
15842 +/*     now inactive context structures */
15843 +
15844 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15845 +
15846 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15847 +
15848 +
15849 +/*     __alloc_vx_info()
15850 +
15851 +       * allocate an initialized vx_info struct
15852 +       * doesn't make it visible (hash)                        */
15853 +
15854 +static struct vx_info *__alloc_vx_info(xid_t xid)
15855 +{
15856 +       struct vx_info *new = NULL;
15857 +       int cpu, index;
15858 +
15859 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15860 +
15861 +       /* would this benefit from a slab cache? */
15862 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15863 +       if (!new)
15864 +               return 0;
15865 +
15866 +       memset(new, 0, sizeof(struct vx_info));
15867 +#ifdef CONFIG_SMP
15868 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15869 +       if (!new->ptr_pc)
15870 +               goto error;
15871 +#endif
15872 +       new->vx_id = xid;
15873 +       INIT_HLIST_NODE(&new->vx_hlist);
15874 +       atomic_set(&new->vx_usecnt, 0);
15875 +       atomic_set(&new->vx_tasks, 0);
15876 +       new->vx_parent = NULL;
15877 +       new->vx_state = 0;
15878 +       init_waitqueue_head(&new->vx_wait);
15879 +
15880 +       /* prepare reaper */
15881 +       get_task_struct(init_pid_ns.child_reaper);
15882 +       new->vx_reaper = init_pid_ns.child_reaper;
15883 +       new->vx_badness_bias = 0;
15884 +
15885 +       /* rest of init goes here */
15886 +       vx_info_init_limit(&new->limit);
15887 +       vx_info_init_sched(&new->sched);
15888 +       vx_info_init_cvirt(&new->cvirt);
15889 +       vx_info_init_cacct(&new->cacct);
15890 +
15891 +       /* per cpu data structures */
15892 +       for_each_possible_cpu(cpu) {
15893 +               vx_info_init_sched_pc(
15894 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15895 +               vx_info_init_cvirt_pc(
15896 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15897 +       }
15898 +
15899 +       new->vx_flags = VXF_INIT_SET;
15900 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15901 +       new->vx_ccaps = 0;
15902 +       new->vx_umask = 0;
15903 +       new->vx_wmask = 0;
15904 +
15905 +       new->reboot_cmd = 0;
15906 +       new->exit_code = 0;
15907 +
15908 +       // preconfig spaces
15909 +       for (index = 0; index < VX_SPACES; index++) {
15910 +               struct _vx_space *space = &new->space[index];
15911 +
15912 +               // filesystem
15913 +               spin_lock(&init_fs.lock);
15914 +               init_fs.users++;
15915 +               spin_unlock(&init_fs.lock);
15916 +               space->vx_fs = &init_fs;
15917 +
15918 +               /* FIXME: do we want defaults? */
15919 +               // space->vx_real_cred = 0;
15920 +               // space->vx_cred = 0;
15921 +       }
15922 +
15923 +
15924 +       vxdprintk(VXD_CBIT(xid, 0),
15925 +               "alloc_vx_info(%d) = %p", xid, new);
15926 +       vxh_alloc_vx_info(new);
15927 +       atomic_inc(&vx_global_ctotal);
15928 +       return new;
15929 +#ifdef CONFIG_SMP
15930 +error:
15931 +       kfree(new);
15932 +       return 0;
15933 +#endif
15934 +}
15935 +
15936 +/*     __dealloc_vx_info()
15937 +
15938 +       * final disposal of vx_info                             */
15939 +
15940 +static void __dealloc_vx_info(struct vx_info *vxi)
15941 +{
15942 +#ifdef CONFIG_VSERVER_WARN
15943 +       struct vx_info_save vxis;
15944 +       int cpu;
15945 +#endif
15946 +       vxdprintk(VXD_CBIT(xid, 0),
15947 +               "dealloc_vx_info(%p)", vxi);
15948 +       vxh_dealloc_vx_info(vxi);
15949 +
15950 +#ifdef CONFIG_VSERVER_WARN
15951 +       enter_vx_info(vxi, &vxis);
15952 +       vx_info_exit_limit(&vxi->limit);
15953 +       vx_info_exit_sched(&vxi->sched);
15954 +       vx_info_exit_cvirt(&vxi->cvirt);
15955 +       vx_info_exit_cacct(&vxi->cacct);
15956 +
15957 +       for_each_possible_cpu(cpu) {
15958 +               vx_info_exit_sched_pc(
15959 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15960 +               vx_info_exit_cvirt_pc(
15961 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15962 +       }
15963 +       leave_vx_info(&vxis);
15964 +#endif
15965 +
15966 +       vxi->vx_id = -1;
15967 +       vxi->vx_state |= VXS_RELEASED;
15968 +
15969 +#ifdef CONFIG_SMP
15970 +       free_percpu(vxi->ptr_pc);
15971 +#endif
15972 +       kfree(vxi);
15973 +       atomic_dec(&vx_global_ctotal);
15974 +}
15975 +
15976 +static void __shutdown_vx_info(struct vx_info *vxi)
15977 +{
15978 +       struct nsproxy *nsproxy;
15979 +       struct fs_struct *fs;
15980 +       struct cred *cred;
15981 +       int index, kill;
15982 +
15983 +       might_sleep();
15984 +
15985 +       vxi->vx_state |= VXS_SHUTDOWN;
15986 +       vs_state_change(vxi, VSC_SHUTDOWN);
15987 +
15988 +       for (index = 0; index < VX_SPACES; index++) {
15989 +               struct _vx_space *space = &vxi->space[index];
15990 +
15991 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15992 +               if (nsproxy)
15993 +                       put_nsproxy(nsproxy);
15994 +
15995 +               fs = xchg(&space->vx_fs, NULL);
15996 +               spin_lock(&fs->lock);
15997 +               kill = !--fs->users;
15998 +               spin_unlock(&fs->lock);
15999 +               if (kill)
16000 +                       free_fs_struct(fs);
16001 +
16002 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16003 +               if (cred)
16004 +                       abort_creds(cred);
16005 +       }
16006 +}
16007 +
16008 +/* exported stuff */
16009 +
16010 +void free_vx_info(struct vx_info *vxi)
16011 +{
16012 +       unsigned long flags;
16013 +       unsigned index;
16014 +
16015 +       /* check for reference counts first */
16016 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16017 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16018 +
16019 +       /* context must not be hashed */
16020 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16021 +
16022 +       /* context shutdown is mandatory */
16023 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16024 +
16025 +       /* spaces check */
16026 +       for (index = 0; index < VX_SPACES; index++) {
16027 +               struct _vx_space *space = &vxi->space[index];
16028 +
16029 +               BUG_ON(space->vx_nsproxy);
16030 +               BUG_ON(space->vx_fs);
16031 +               // BUG_ON(space->vx_real_cred);
16032 +               // BUG_ON(space->vx_cred);
16033 +       }
16034 +
16035 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16036 +       hlist_del(&vxi->vx_hlist);
16037 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16038 +
16039 +       __dealloc_vx_info(vxi);
16040 +}
16041 +
16042 +
16043 +/*     hash table for vx_info hash */
16044 +
16045 +#define VX_HASH_SIZE   13
16046 +
16047 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16048 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16049 +
16050 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16051 +
16052 +
16053 +static inline unsigned int __hashval(xid_t xid)
16054 +{
16055 +       return (xid % VX_HASH_SIZE);
16056 +}
16057 +
16058 +
16059 +
16060 +/*     __hash_vx_info()
16061 +
16062 +       * add the vxi to the global hash table
16063 +       * requires the hash_lock to be held                     */
16064 +
16065 +static inline void __hash_vx_info(struct vx_info *vxi)
16066 +{
16067 +       struct hlist_head *head;
16068 +
16069 +       vxd_assert_lock(&vx_info_hash_lock);
16070 +       vxdprintk(VXD_CBIT(xid, 4),
16071 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16072 +       vxh_hash_vx_info(vxi);
16073 +
16074 +       /* context must not be hashed */
16075 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16076 +
16077 +       vxi->vx_state |= VXS_HASHED;
16078 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16079 +       hlist_add_head(&vxi->vx_hlist, head);
16080 +       atomic_inc(&vx_global_cactive);
16081 +}
16082 +
16083 +/*     __unhash_vx_info()
16084 +
16085 +       * remove the vxi from the global hash table
16086 +       * requires the hash_lock to be held                     */
16087 +
16088 +static inline void __unhash_vx_info(struct vx_info *vxi)
16089 +{
16090 +       unsigned long flags;
16091 +
16092 +       vxd_assert_lock(&vx_info_hash_lock);
16093 +       vxdprintk(VXD_CBIT(xid, 4),
16094 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16095 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16096 +       vxh_unhash_vx_info(vxi);
16097 +
16098 +       /* context must be hashed */
16099 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16100 +       /* but without tasks */
16101 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16102 +
16103 +       vxi->vx_state &= ~VXS_HASHED;
16104 +       hlist_del_init(&vxi->vx_hlist);
16105 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16106 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16107 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16108 +       atomic_dec(&vx_global_cactive);
16109 +}
16110 +
16111 +
16112 +/*     __lookup_vx_info()
16113 +
16114 +       * requires the hash_lock to be held
16115 +       * doesn't increment the vx_refcnt                       */
16116 +
16117 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16118 +{
16119 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16120 +       struct hlist_node *pos;
16121 +       struct vx_info *vxi;
16122 +
16123 +       vxd_assert_lock(&vx_info_hash_lock);
16124 +       hlist_for_each(pos, head) {
16125 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16126 +
16127 +               if (vxi->vx_id == xid)
16128 +                       goto found;
16129 +       }
16130 +       vxi = NULL;
16131 +found:
16132 +       vxdprintk(VXD_CBIT(xid, 0),
16133 +               "__lookup_vx_info(#%u): %p[#%u]",
16134 +               xid, vxi, vxi ? vxi->vx_id : 0);
16135 +       vxh_lookup_vx_info(vxi, xid);
16136 +       return vxi;
16137 +}
16138 +
16139 +
16140 +/*     __create_vx_info()
16141 +
16142 +       * create the requested context
16143 +       * get(), claim() and hash it                            */
16144 +
16145 +static struct vx_info *__create_vx_info(int id)
16146 +{
16147 +       struct vx_info *new, *vxi = NULL;
16148 +
16149 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16150 +
16151 +       if (!(new = __alloc_vx_info(id)))
16152 +               return ERR_PTR(-ENOMEM);
16153 +
16154 +       /* required to make dynamic xids unique */
16155 +       spin_lock(&vx_info_hash_lock);
16156 +
16157 +       /* static context requested */
16158 +       if ((vxi = __lookup_vx_info(id))) {
16159 +               vxdprintk(VXD_CBIT(xid, 0),
16160 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16161 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16162 +                       vxi = ERR_PTR(-EBUSY);
16163 +               else
16164 +                       vxi = ERR_PTR(-EEXIST);
16165 +               goto out_unlock;
16166 +       }
16167 +       /* new context */
16168 +       vxdprintk(VXD_CBIT(xid, 0),
16169 +               "create_vx_info(%d) = %p (new)", id, new);
16170 +       claim_vx_info(new, NULL);
16171 +       __hash_vx_info(get_vx_info(new));
16172 +       vxi = new, new = NULL;
16173 +
16174 +out_unlock:
16175 +       spin_unlock(&vx_info_hash_lock);
16176 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16177 +       if (new)
16178 +               __dealloc_vx_info(new);
16179 +       return vxi;
16180 +}
16181 +
16182 +
16183 +/*     exported stuff                                          */
16184 +
16185 +
16186 +void unhash_vx_info(struct vx_info *vxi)
16187 +{
16188 +       spin_lock(&vx_info_hash_lock);
16189 +       __unhash_vx_info(vxi);
16190 +       spin_unlock(&vx_info_hash_lock);
16191 +       __shutdown_vx_info(vxi);
16192 +       __wakeup_vx_info(vxi);
16193 +}
16194 +
16195 +
16196 +/*     lookup_vx_info()
16197 +
16198 +       * search for a vx_info and get() it
16199 +       * negative id means current                             */
16200 +
16201 +struct vx_info *lookup_vx_info(int id)
16202 +{
16203 +       struct vx_info *vxi = NULL;
16204 +
16205 +       if (id < 0) {
16206 +               vxi = get_vx_info(current_vx_info());
16207 +       } else if (id > 1) {
16208 +               spin_lock(&vx_info_hash_lock);
16209 +               vxi = get_vx_info(__lookup_vx_info(id));
16210 +               spin_unlock(&vx_info_hash_lock);
16211 +       }
16212 +       return vxi;
16213 +}
16214 +
16215 +/*     xid_is_hashed()
16216 +
16217 +       * verify that xid is still hashed                       */
16218 +
16219 +int xid_is_hashed(xid_t xid)
16220 +{
16221 +       int hashed;
16222 +
16223 +       spin_lock(&vx_info_hash_lock);
16224 +       hashed = (__lookup_vx_info(xid) != NULL);
16225 +       spin_unlock(&vx_info_hash_lock);
16226 +       return hashed;
16227 +}
16228 +
16229 +#ifdef CONFIG_PROC_FS
16230 +
16231 +/*     get_xid_list()
16232 +
16233 +       * get a subset of hashed xids for proc
16234 +       * assumes size is at least one                          */
16235 +
16236 +int get_xid_list(int index, unsigned int *xids, int size)
16237 +{
16238 +       int hindex, nr_xids = 0;
16239 +
16240 +       /* only show current and children */
16241 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16242 +               if (index > 0)
16243 +                       return 0;
16244 +               xids[nr_xids] = vx_current_xid();
16245 +               return 1;
16246 +       }
16247 +
16248 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16249 +               struct hlist_head *head = &vx_info_hash[hindex];
16250 +               struct hlist_node *pos;
16251 +
16252 +               spin_lock(&vx_info_hash_lock);
16253 +               hlist_for_each(pos, head) {
16254 +                       struct vx_info *vxi;
16255 +
16256 +                       if (--index > 0)
16257 +                               continue;
16258 +
16259 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16260 +                       xids[nr_xids] = vxi->vx_id;
16261 +                       if (++nr_xids >= size) {
16262 +                               spin_unlock(&vx_info_hash_lock);
16263 +                               goto out;
16264 +                       }
16265 +               }
16266 +               /* keep the lock time short */
16267 +               spin_unlock(&vx_info_hash_lock);
16268 +       }
16269 +out:
16270 +       return nr_xids;
16271 +}
16272 +#endif
16273 +
16274 +#ifdef CONFIG_VSERVER_DEBUG
16275 +
16276 +void   dump_vx_info_inactive(int level)
16277 +{
16278 +       struct hlist_node *entry, *next;
16279 +
16280 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16281 +               struct vx_info *vxi =
16282 +                       list_entry(entry, struct vx_info, vx_hlist);
16283 +
16284 +               dump_vx_info(vxi, level);
16285 +       }
16286 +}
16287 +
16288 +#endif
16289 +
16290 +#if 0
16291 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16292 +{
16293 +       struct user_struct *new_user, *old_user;
16294 +
16295 +       if (!p || !vxi)
16296 +               BUG();
16297 +
16298 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16299 +               return -EACCES;
16300 +
16301 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16302 +       if (!new_user)
16303 +               return -ENOMEM;
16304 +
16305 +       old_user = p->user;
16306 +       if (new_user != old_user) {
16307 +               atomic_inc(&new_user->processes);
16308 +               atomic_dec(&old_user->processes);
16309 +               p->user = new_user;
16310 +       }
16311 +       free_uid(old_user);
16312 +       return 0;
16313 +}
16314 +#endif
16315 +
16316 +#if 0
16317 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16318 +{
16319 +       // p->cap_effective &= vxi->vx_cap_bset;
16320 +       p->cap_effective =
16321 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16322 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16323 +       p->cap_inheritable =
16324 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16325 +       // p->cap_permitted &= vxi->vx_cap_bset;
16326 +       p->cap_permitted =
16327 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16328 +}
16329 +#endif
16330 +
16331 +
16332 +#include <linux/file.h>
16333 +#include <linux/fdtable.h>
16334 +
16335 +static int vx_openfd_task(struct task_struct *tsk)
16336 +{
16337 +       struct files_struct *files = tsk->files;
16338 +       struct fdtable *fdt;
16339 +       const unsigned long *bptr;
16340 +       int count, total;
16341 +
16342 +       /* no rcu_read_lock() because of spin_lock() */
16343 +       spin_lock(&files->file_lock);
16344 +       fdt = files_fdtable(files);
16345 +       bptr = fdt->open_fds;
16346 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16347 +       for (total = 0; count > 0; count--) {
16348 +               if (*bptr)
16349 +                       total += hweight_long(*bptr);
16350 +               bptr++;
16351 +       }
16352 +       spin_unlock(&files->file_lock);
16353 +       return total;
16354 +}
16355 +
16356 +
16357 +/*     for *space compatibility */
16358 +
16359 +asmlinkage long sys_unshare(unsigned long);
16360 +
16361 +/*
16362 + *     migrate task to new context
16363 + *     gets vxi, puts old_vxi on change
16364 + *     optionally unshares namespaces (hack)
16365 + */
16366 +
16367 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16368 +{
16369 +       struct vx_info *old_vxi;
16370 +       int ret = 0;
16371 +
16372 +       if (!p || !vxi)
16373 +               BUG();
16374 +
16375 +       vxdprintk(VXD_CBIT(xid, 5),
16376 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16377 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16378 +
16379 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16380 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16381 +               return -EACCES;
16382 +
16383 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16384 +               return -EFAULT;
16385 +
16386 +       old_vxi = task_get_vx_info(p);
16387 +       if (old_vxi == vxi)
16388 +               goto out;
16389 +
16390 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16391 +       {
16392 +               int openfd;
16393 +
16394 +               task_lock(p);
16395 +               openfd = vx_openfd_task(p);
16396 +
16397 +               if (old_vxi) {
16398 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16399 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16400 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16401 +                       /* FIXME: what about the struct files here? */
16402 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16403 +                       /* account for the executable */
16404 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16405 +               }
16406 +               atomic_inc(&vxi->cvirt.nr_threads);
16407 +               atomic_inc(&vxi->cvirt.nr_running);
16408 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16409 +               /* FIXME: what about the struct files here? */
16410 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16411 +               /* account for the executable */
16412 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16413 +
16414 +               if (old_vxi) {
16415 +                       release_vx_info(old_vxi, p);
16416 +                       clr_vx_info(&p->vx_info);
16417 +               }
16418 +               claim_vx_info(vxi, p);
16419 +               set_vx_info(&p->vx_info, vxi);
16420 +               p->xid = vxi->vx_id;
16421 +
16422 +               vxdprintk(VXD_CBIT(xid, 5),
16423 +                       "moved task %p into vxi:%p[#%d]",
16424 +                       p, vxi, vxi->vx_id);
16425 +
16426 +               // vx_mask_cap_bset(vxi, p);
16427 +               task_unlock(p);
16428 +
16429 +               /* hack for *spaces to provide compatibility */
16430 +               if (unshare) {
16431 +                       struct nsproxy *old_nsp, *new_nsp;
16432 +
16433 +                       ret = unshare_nsproxy_namespaces(
16434 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16435 +                               &new_nsp, NULL);
16436 +                       if (ret)
16437 +                               goto out;
16438 +
16439 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16440 +                       vx_set_space(vxi,
16441 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16442 +                       put_nsproxy(old_nsp);
16443 +               }
16444 +       }
16445 +out:
16446 +       put_vx_info(old_vxi);
16447 +       return ret;
16448 +}
16449 +
16450 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16451 +{
16452 +       struct task_struct *old_reaper;
16453 +       struct vx_info *reaper_vxi;
16454 +
16455 +       if (!vxi)
16456 +               return -EINVAL;
16457 +
16458 +       vxdprintk(VXD_CBIT(xid, 6),
16459 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16460 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16461 +
16462 +       old_reaper = vxi->vx_reaper;
16463 +       if (old_reaper == p)
16464 +               return 0;
16465 +
16466 +       reaper_vxi = task_get_vx_info(p);
16467 +       if (reaper_vxi && reaper_vxi != vxi) {
16468 +               vxwprintk(1,
16469 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16470 +                       "for [xid #%u]",
16471 +                       p->comm, p->pid, p->xid, vx_current_xid());
16472 +               goto out;
16473 +       }
16474 +
16475 +       /* set new child reaper */
16476 +       get_task_struct(p);
16477 +       vxi->vx_reaper = p;
16478 +       put_task_struct(old_reaper);
16479 +out:
16480 +       put_vx_info(reaper_vxi);
16481 +       return 0;
16482 +}
16483 +
16484 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16485 +{
16486 +       if (!vxi)
16487 +               return -EINVAL;
16488 +
16489 +       vxdprintk(VXD_CBIT(xid, 6),
16490 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16491 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16492 +
16493 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16494 +       // vxi->vx_initpid = p->tgid;
16495 +       vxi->vx_initpid = p->pid;
16496 +       return 0;
16497 +}
16498 +
16499 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16500 +{
16501 +       vxdprintk(VXD_CBIT(xid, 6),
16502 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16503 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16504 +
16505 +       vxi->exit_code = code;
16506 +       vxi->vx_initpid = 0;
16507 +}
16508 +
16509 +
16510 +void vx_set_persistent(struct vx_info *vxi)
16511 +{
16512 +       vxdprintk(VXD_CBIT(xid, 6),
16513 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16514 +
16515 +       get_vx_info(vxi);
16516 +       claim_vx_info(vxi, NULL);
16517 +}
16518 +
16519 +void vx_clear_persistent(struct vx_info *vxi)
16520 +{
16521 +       vxdprintk(VXD_CBIT(xid, 6),
16522 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16523 +
16524 +       release_vx_info(vxi, NULL);
16525 +       put_vx_info(vxi);
16526 +}
16527 +
16528 +void vx_update_persistent(struct vx_info *vxi)
16529 +{
16530 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16531 +               vx_set_persistent(vxi);
16532 +       else
16533 +               vx_clear_persistent(vxi);
16534 +}
16535 +
16536 +
16537 +/*     task must be current or locked          */
16538 +
16539 +void   exit_vx_info(struct task_struct *p, int code)
16540 +{
16541 +       struct vx_info *vxi = p->vx_info;
16542 +
16543 +       if (vxi) {
16544 +               atomic_dec(&vxi->cvirt.nr_threads);
16545 +               vx_nproc_dec(p);
16546 +
16547 +               vxi->exit_code = code;
16548 +               release_vx_info(vxi, p);
16549 +       }
16550 +}
16551 +
16552 +void   exit_vx_info_early(struct task_struct *p, int code)
16553 +{
16554 +       struct vx_info *vxi = p->vx_info;
16555 +
16556 +       if (vxi) {
16557 +               if (vxi->vx_initpid == p->pid)
16558 +                       vx_exit_init(vxi, p, code);
16559 +               if (vxi->vx_reaper == p)
16560 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16561 +       }
16562 +}
16563 +
16564 +
16565 +/* vserver syscall commands below here */
16566 +
16567 +/* taks xid and vx_info functions */
16568 +
16569 +#include <asm/uaccess.h>
16570 +
16571 +
16572 +int vc_task_xid(uint32_t id)
16573 +{
16574 +       xid_t xid;
16575 +
16576 +       if (id) {
16577 +               struct task_struct *tsk;
16578 +
16579 +               rcu_read_lock();
16580 +               tsk = find_task_by_real_pid(id);
16581 +               xid = (tsk) ? tsk->xid : -ESRCH;
16582 +               rcu_read_unlock();
16583 +       } else
16584 +               xid = vx_current_xid();
16585 +       return xid;
16586 +}
16587 +
16588 +
16589 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16590 +{
16591 +       struct vcmd_vx_info_v0 vc_data;
16592 +
16593 +       vc_data.xid = vxi->vx_id;
16594 +       vc_data.initpid = vxi->vx_initpid;
16595 +
16596 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16597 +               return -EFAULT;
16598 +       return 0;
16599 +}
16600 +
16601 +
16602 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16603 +{
16604 +       struct vcmd_ctx_stat_v0 vc_data;
16605 +
16606 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16607 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16608 +
16609 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16610 +               return -EFAULT;
16611 +       return 0;
16612 +}
16613 +
16614 +
16615 +/* context functions */
16616 +
16617 +int vc_ctx_create(uint32_t xid, void __user *data)
16618 +{
16619 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16620 +       struct vx_info *new_vxi;
16621 +       int ret;
16622 +
16623 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16624 +               return -EFAULT;
16625 +
16626 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16627 +               return -EINVAL;
16628 +
16629 +       new_vxi = __create_vx_info(xid);
16630 +       if (IS_ERR(new_vxi))
16631 +               return PTR_ERR(new_vxi);
16632 +
16633 +       /* initial flags */
16634 +       new_vxi->vx_flags = vc_data.flagword;
16635 +
16636 +       ret = -ENOEXEC;
16637 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16638 +               goto out;
16639 +
16640 +       ret = vx_migrate_task(current, new_vxi, (!data));
16641 +       if (ret)
16642 +               goto out;
16643 +
16644 +       /* return context id on success */
16645 +       ret = new_vxi->vx_id;
16646 +
16647 +       /* get a reference for persistent contexts */
16648 +       if ((vc_data.flagword & VXF_PERSISTENT))
16649 +               vx_set_persistent(new_vxi);
16650 +out:
16651 +       release_vx_info(new_vxi, NULL);
16652 +       put_vx_info(new_vxi);
16653 +       return ret;
16654 +}
16655 +
16656 +
16657 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16658 +{
16659 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16660 +       int ret;
16661 +
16662 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16663 +               return -EFAULT;
16664 +
16665 +       ret = vx_migrate_task(current, vxi, 0);
16666 +       if (ret)
16667 +               return ret;
16668 +       if (vc_data.flagword & VXM_SET_INIT)
16669 +               ret = vx_set_init(vxi, current);
16670 +       if (ret)
16671 +               return ret;
16672 +       if (vc_data.flagword & VXM_SET_REAPER)
16673 +               ret = vx_set_reaper(vxi, current);
16674 +       return ret;
16675 +}
16676 +
16677 +
16678 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16679 +{
16680 +       struct vcmd_ctx_flags_v0 vc_data;
16681 +
16682 +       vc_data.flagword = vxi->vx_flags;
16683 +
16684 +       /* special STATE flag handling */
16685 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16686 +
16687 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16688 +               return -EFAULT;
16689 +       return 0;
16690 +}
16691 +
16692 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16693 +{
16694 +       struct vcmd_ctx_flags_v0 vc_data;
16695 +       uint64_t mask, trigger;
16696 +
16697 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16698 +               return -EFAULT;
16699 +
16700 +       /* special STATE flag handling */
16701 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16702 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16703 +
16704 +       if (vxi == current_vx_info()) {
16705 +               /* if (trigger & VXF_STATE_SETUP)
16706 +                       vx_mask_cap_bset(vxi, current); */
16707 +               if (trigger & VXF_STATE_INIT) {
16708 +                       int ret;
16709 +
16710 +                       ret = vx_set_init(vxi, current);
16711 +                       if (ret)
16712 +                               return ret;
16713 +                       ret = vx_set_reaper(vxi, current);
16714 +                       if (ret)
16715 +                               return ret;
16716 +               }
16717 +       }
16718 +
16719 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16720 +               vc_data.flagword, mask);
16721 +       if (trigger & VXF_PERSISTENT)
16722 +               vx_update_persistent(vxi);
16723 +
16724 +       return 0;
16725 +}
16726 +
16727 +
16728 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16729 +{
16730 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16731 +
16732 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16733 +       return v;
16734 +}
16735 +
16736 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16737 +{
16738 +       kernel_cap_t c = __cap_empty_set;
16739 +
16740 +       c.cap[0] = v & 0xFFFFFFFF;
16741 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16742 +
16743 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16744 +       return c;
16745 +}
16746 +
16747 +
16748 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16749 +{
16750 +       if (bcaps)
16751 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16752 +       if (ccaps)
16753 +               *ccaps = vxi->vx_ccaps;
16754 +
16755 +       return 0;
16756 +}
16757 +
16758 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16759 +{
16760 +       struct vcmd_ctx_caps_v1 vc_data;
16761 +       int ret;
16762 +
16763 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16764 +       if (ret)
16765 +               return ret;
16766 +       vc_data.cmask = ~0ULL;
16767 +
16768 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16769 +               return -EFAULT;
16770 +       return 0;
16771 +}
16772 +
16773 +static int do_set_caps(struct vx_info *vxi,
16774 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16775 +{
16776 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16777 +
16778 +#if 0
16779 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16780 +               bcaps, bmask, ccaps, cmask);
16781 +#endif
16782 +       vxi->vx_bcaps = cap_t_from_caps(
16783 +               vs_mask_flags(bcold, bcaps, bmask));
16784 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16785 +
16786 +       return 0;
16787 +}
16788 +
16789 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16790 +{
16791 +       struct vcmd_ctx_caps_v1 vc_data;
16792 +
16793 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16794 +               return -EFAULT;
16795 +
16796 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16797 +}
16798 +
16799 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16800 +{
16801 +       struct vcmd_bcaps vc_data;
16802 +       int ret;
16803 +
16804 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16805 +       if (ret)
16806 +               return ret;
16807 +       vc_data.bmask = ~0ULL;
16808 +
16809 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16810 +               return -EFAULT;
16811 +       return 0;
16812 +}
16813 +
16814 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16815 +{
16816 +       struct vcmd_bcaps vc_data;
16817 +
16818 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16819 +               return -EFAULT;
16820 +
16821 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16822 +}
16823 +
16824 +
16825 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16826 +{
16827 +       struct vcmd_umask vc_data;
16828 +
16829 +       vc_data.umask = vxi->vx_umask;
16830 +       vc_data.mask = ~0ULL;
16831 +
16832 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16833 +               return -EFAULT;
16834 +       return 0;
16835 +}
16836 +
16837 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16838 +{
16839 +       struct vcmd_umask vc_data;
16840 +
16841 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16842 +               return -EFAULT;
16843 +
16844 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16845 +               vc_data.umask, vc_data.mask);
16846 +       return 0;
16847 +}
16848 +
16849 +
16850 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16851 +{
16852 +       struct vcmd_wmask vc_data;
16853 +
16854 +       vc_data.wmask = vxi->vx_wmask;
16855 +       vc_data.mask = ~0ULL;
16856 +
16857 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16858 +               return -EFAULT;
16859 +       return 0;
16860 +}
16861 +
16862 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16863 +{
16864 +       struct vcmd_wmask vc_data;
16865 +
16866 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16867 +               return -EFAULT;
16868 +
16869 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16870 +               vc_data.wmask, vc_data.mask);
16871 +       return 0;
16872 +}
16873 +
16874 +
16875 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16876 +{
16877 +       struct vcmd_badness_v0 vc_data;
16878 +
16879 +       vc_data.bias = vxi->vx_badness_bias;
16880 +
16881 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16882 +               return -EFAULT;
16883 +       return 0;
16884 +}
16885 +
16886 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16887 +{
16888 +       struct vcmd_badness_v0 vc_data;
16889 +
16890 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16891 +               return -EFAULT;
16892 +
16893 +       vxi->vx_badness_bias = vc_data.bias;
16894 +       return 0;
16895 +}
16896 +
16897 +#include <linux/module.h>
16898 +
16899 +EXPORT_SYMBOL_GPL(free_vx_info);
16900 +
16901 diff -NurpP --minimal linux-3.7.1/kernel/vserver/cvirt.c linux-3.7.1-vs2.3.5.5/kernel/vserver/cvirt.c
16902 --- linux-3.7.1/kernel/vserver/cvirt.c  1970-01-01 00:00:00.000000000 +0000
16903 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/cvirt.c        2012-12-18 15:13:16.000000000 +0000
16904 @@ -0,0 +1,313 @@
16905 +/*
16906 + *  linux/kernel/vserver/cvirt.c
16907 + *
16908 + *  Virtual Server: Context Virtualization
16909 + *
16910 + *  Copyright (C) 2004-2007  Herbert Pötzl
16911 + *
16912 + *  V0.01  broken out from limit.c
16913 + *  V0.02  added utsname stuff
16914 + *  V0.03  changed vcmds to vxi arg
16915 + *
16916 + */
16917 +
16918 +#include <linux/types.h>
16919 +#include <linux/utsname.h>
16920 +#include <linux/vs_cvirt.h>
16921 +#include <linux/vserver/switch.h>
16922 +#include <linux/vserver/cvirt_cmd.h>
16923 +
16924 +#include <asm/uaccess.h>
16925 +
16926 +
16927 +void vx_vsi_boottime(struct timespec *boottime)
16928 +{
16929 +       struct vx_info *vxi = current_vx_info();
16930 +
16931 +       set_normalized_timespec(boottime,
16932 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16933 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16934 +       return;
16935 +}
16936 +
16937 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16938 +{
16939 +       struct vx_info *vxi = current_vx_info();
16940 +
16941 +       set_normalized_timespec(uptime,
16942 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16943 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16944 +       if (!idle)
16945 +               return;
16946 +       set_normalized_timespec(idle,
16947 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16948 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16949 +       return;
16950 +}
16951 +
16952 +uint64_t vx_idle_jiffies(void)
16953 +{
16954 +       return init_task.utime + init_task.stime;
16955 +}
16956 +
16957 +
16958 +
16959 +static inline uint32_t __update_loadavg(uint32_t load,
16960 +       int wsize, int delta, int n)
16961 +{
16962 +       unsigned long long calc, prev;
16963 +
16964 +       /* just set it to n */
16965 +       if (unlikely(delta >= wsize))
16966 +               return (n << FSHIFT);
16967 +
16968 +       calc = delta * n;
16969 +       calc <<= FSHIFT;
16970 +       prev = (wsize - delta);
16971 +       prev *= load;
16972 +       calc += prev;
16973 +       do_div(calc, wsize);
16974 +       return calc;
16975 +}
16976 +
16977 +
16978 +void vx_update_load(struct vx_info *vxi)
16979 +{
16980 +       uint32_t now, last, delta;
16981 +       unsigned int nr_running, nr_uninterruptible;
16982 +       unsigned int total;
16983 +       unsigned long flags;
16984 +
16985 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16986 +
16987 +       now = jiffies;
16988 +       last = vxi->cvirt.load_last;
16989 +       delta = now - last;
16990 +
16991 +       if (delta < 5*HZ)
16992 +               goto out;
16993 +
16994 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16995 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16996 +       total = nr_running + nr_uninterruptible;
16997 +
16998 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16999 +               60*HZ, delta, total);
17000 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17001 +               5*60*HZ, delta, total);
17002 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17003 +               15*60*HZ, delta, total);
17004 +
17005 +       vxi->cvirt.load_last = now;
17006 +out:
17007 +       atomic_inc(&vxi->cvirt.load_updates);
17008 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17009 +}
17010 +
17011 +
17012 +/*
17013 + * Commands to do_syslog:
17014 + *
17015 + *      0 -- Close the log.  Currently a NOP.
17016 + *      1 -- Open the log. Currently a NOP.
17017 + *      2 -- Read from the log.
17018 + *      3 -- Read all messages remaining in the ring buffer.
17019 + *      4 -- Read and clear all messages remaining in the ring buffer
17020 + *      5 -- Clear ring buffer.
17021 + *      6 -- Disable printk's to console
17022 + *      7 -- Enable printk's to console
17023 + *      8 -- Set level of messages printed to console
17024 + *      9 -- Return number of unread characters in the log buffer
17025 + *     10 -- Return size of the log buffer
17026 + */
17027 +int vx_do_syslog(int type, char __user *buf, int len)
17028 +{
17029 +       int error = 0;
17030 +       int do_clear = 0;
17031 +       struct vx_info *vxi = current_vx_info();
17032 +       struct _vx_syslog *log;
17033 +
17034 +       if (!vxi)
17035 +               return -EINVAL;
17036 +       log = &vxi->cvirt.syslog;
17037 +
17038 +       switch (type) {
17039 +       case 0:         /* Close log */
17040 +       case 1:         /* Open log */
17041 +               break;
17042 +       case 2:         /* Read from log */
17043 +               error = wait_event_interruptible(log->log_wait,
17044 +                       (log->log_start - log->log_end));
17045 +               if (error)
17046 +                       break;
17047 +               spin_lock_irq(&log->logbuf_lock);
17048 +               spin_unlock_irq(&log->logbuf_lock);
17049 +               break;
17050 +       case 4:         /* Read/clear last kernel messages */
17051 +               do_clear = 1;
17052 +               /* fall through */
17053 +       case 3:         /* Read last kernel messages */
17054 +               return 0;
17055 +
17056 +       case 5:         /* Clear ring buffer */
17057 +               return 0;
17058 +
17059 +       case 6:         /* Disable logging to console */
17060 +       case 7:         /* Enable logging to console */
17061 +       case 8:         /* Set level of messages printed to console */
17062 +               break;
17063 +
17064 +       case 9:         /* Number of chars in the log buffer */
17065 +               return 0;
17066 +       case 10:        /* Size of the log buffer */
17067 +               return 0;
17068 +       default:
17069 +               error = -EINVAL;
17070 +               break;
17071 +       }
17072 +       return error;
17073 +}
17074 +
17075 +
17076 +/* virtual host info names */
17077 +
17078 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17079 +{
17080 +       struct nsproxy *nsproxy;
17081 +       struct uts_namespace *uts;
17082 +
17083 +       if (id == VHIN_CONTEXT)
17084 +               return vxi->vx_name;
17085 +
17086 +       nsproxy = vxi->space[0].vx_nsproxy;
17087 +       if (!nsproxy)
17088 +               return NULL;
17089 +
17090 +       uts = nsproxy->uts_ns;
17091 +       if (!uts)
17092 +               return NULL;
17093 +
17094 +       switch (id) {
17095 +       case VHIN_SYSNAME:
17096 +               return uts->name.sysname;
17097 +       case VHIN_NODENAME:
17098 +               return uts->name.nodename;
17099 +       case VHIN_RELEASE:
17100 +               return uts->name.release;
17101 +       case VHIN_VERSION:
17102 +               return uts->name.version;
17103 +       case VHIN_MACHINE:
17104 +               return uts->name.machine;
17105 +       case VHIN_DOMAINNAME:
17106 +               return uts->name.domainname;
17107 +       default:
17108 +               return NULL;
17109 +       }
17110 +       return NULL;
17111 +}
17112 +
17113 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17114 +{
17115 +       struct vcmd_vhi_name_v0 vc_data;
17116 +       char *name;
17117 +
17118 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17119 +               return -EFAULT;
17120 +
17121 +       name = vx_vhi_name(vxi, vc_data.field);
17122 +       if (!name)
17123 +               return -EINVAL;
17124 +
17125 +       memcpy(name, vc_data.name, 65);
17126 +       return 0;
17127 +}
17128 +
17129 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17130 +{
17131 +       struct vcmd_vhi_name_v0 vc_data;
17132 +       char *name;
17133 +
17134 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17135 +               return -EFAULT;
17136 +
17137 +       name = vx_vhi_name(vxi, vc_data.field);
17138 +       if (!name)
17139 +               return -EINVAL;
17140 +
17141 +       memcpy(vc_data.name, name, 65);
17142 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17143 +               return -EFAULT;
17144 +       return 0;
17145 +}
17146 +
17147 +
17148 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17149 +{
17150 +       struct vcmd_virt_stat_v0 vc_data;
17151 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17152 +       struct timespec uptime;
17153 +
17154 +       do_posix_clock_monotonic_gettime(&uptime);
17155 +       set_normalized_timespec(&uptime,
17156 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17157 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17158 +
17159 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17160 +       vc_data.uptime = timespec_to_ns(&uptime);
17161 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17162 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17163 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17164 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17165 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17166 +       vc_data.load[0] = cvirt->load[0];
17167 +       vc_data.load[1] = cvirt->load[1];
17168 +       vc_data.load[2] = cvirt->load[2];
17169 +
17170 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17171 +               return -EFAULT;
17172 +       return 0;
17173 +}
17174 +
17175 +
17176 +#ifdef CONFIG_VSERVER_VTIME
17177 +
17178 +/* virtualized time base */
17179 +
17180 +void vx_adjust_timespec(struct timespec *ts)
17181 +{
17182 +       struct vx_info *vxi;
17183 +
17184 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17185 +               return;
17186 +
17187 +       vxi = current_vx_info();
17188 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17189 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17190 +
17191 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17192 +               ts->tv_sec++;
17193 +               ts->tv_nsec -= NSEC_PER_SEC;
17194 +       } else if (ts->tv_nsec < 0) {
17195 +               ts->tv_sec--;
17196 +               ts->tv_nsec += NSEC_PER_SEC;
17197 +       }
17198 +}
17199 +
17200 +int vx_settimeofday(const struct timespec *ts)
17201 +{
17202 +       struct timespec ats, delta;
17203 +       struct vx_info *vxi;
17204 +
17205 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17206 +               return do_settimeofday(ts);
17207 +
17208 +       getnstimeofday(&ats);
17209 +       delta = timespec_sub(*ts, ats);
17210 +
17211 +       vxi = current_vx_info();
17212 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17213 +       return 0;
17214 +}
17215 +
17216 +#endif
17217 +
17218 diff -NurpP --minimal linux-3.7.1/kernel/vserver/cvirt_init.h linux-3.7.1-vs2.3.5.5/kernel/vserver/cvirt_init.h
17219 --- linux-3.7.1/kernel/vserver/cvirt_init.h     1970-01-01 00:00:00.000000000 +0000
17220 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/cvirt_init.h   2012-12-18 15:13:16.000000000 +0000
17221 @@ -0,0 +1,70 @@
17222 +
17223 +
17224 +extern uint64_t vx_idle_jiffies(void);
17225 +
17226 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17227 +{
17228 +       uint64_t idle_jiffies = vx_idle_jiffies();
17229 +       uint64_t nsuptime;
17230 +
17231 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17232 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17233 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17234 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17235 +       cvirt->bias_ts.tv_sec = 0;
17236 +       cvirt->bias_ts.tv_nsec = 0;
17237 +
17238 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17239 +       atomic_set(&cvirt->nr_threads, 0);
17240 +       atomic_set(&cvirt->nr_running, 0);
17241 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17242 +       atomic_set(&cvirt->nr_onhold, 0);
17243 +
17244 +       spin_lock_init(&cvirt->load_lock);
17245 +       cvirt->load_last = jiffies;
17246 +       atomic_set(&cvirt->load_updates, 0);
17247 +       cvirt->load[0] = 0;
17248 +       cvirt->load[1] = 0;
17249 +       cvirt->load[2] = 0;
17250 +       atomic_set(&cvirt->total_forks, 0);
17251 +
17252 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17253 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17254 +       cvirt->syslog.log_start = 0;
17255 +       cvirt->syslog.log_end = 0;
17256 +       cvirt->syslog.con_start = 0;
17257 +       cvirt->syslog.logged_chars = 0;
17258 +}
17259 +
17260 +static inline
17261 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17262 +{
17263 +       // cvirt_pc->cpustat = { 0 };
17264 +}
17265 +
17266 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17267 +{
17268 +#ifdef CONFIG_VSERVER_WARN
17269 +       int value;
17270 +#endif
17271 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17272 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17273 +               cvirt, value);
17274 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17275 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17276 +               cvirt, value);
17277 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17278 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17279 +               cvirt, value);
17280 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17281 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17282 +               cvirt, value);
17283 +       return;
17284 +}
17285 +
17286 +static inline
17287 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17288 +{
17289 +       return;
17290 +}
17291 +
17292 diff -NurpP --minimal linux-3.7.1/kernel/vserver/cvirt_proc.h linux-3.7.1-vs2.3.5.5/kernel/vserver/cvirt_proc.h
17293 --- linux-3.7.1/kernel/vserver/cvirt_proc.h     1970-01-01 00:00:00.000000000 +0000
17294 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/cvirt_proc.h   2012-12-18 15:13:16.000000000 +0000
17295 @@ -0,0 +1,123 @@
17296 +#ifndef _VX_CVIRT_PROC_H
17297 +#define _VX_CVIRT_PROC_H
17298 +
17299 +#include <linux/nsproxy.h>
17300 +#include <linux/mnt_namespace.h>
17301 +#include <linux/ipc_namespace.h>
17302 +#include <linux/utsname.h>
17303 +#include <linux/ipc.h>
17304 +
17305 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17306 +
17307 +static inline
17308 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17309 +{
17310 +       struct mnt_namespace *ns;
17311 +       struct uts_namespace *uts;
17312 +       struct ipc_namespace *ipc;
17313 +       int length = 0;
17314 +
17315 +       if (!nsproxy)
17316 +               goto out;
17317 +
17318 +       length += sprintf(buffer + length,
17319 +               "NSProxy:\t%p [%p,%p,%p]\n",
17320 +               nsproxy, nsproxy->mnt_ns,
17321 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17322 +
17323 +       ns = nsproxy->mnt_ns;
17324 +       if (!ns)
17325 +               goto skip_ns;
17326 +
17327 +       length += vx_info_mnt_namespace(ns, buffer + length);
17328 +
17329 +skip_ns:
17330 +
17331 +       uts = nsproxy->uts_ns;
17332 +       if (!uts)
17333 +               goto skip_uts;
17334 +
17335 +       length += sprintf(buffer + length,
17336 +               "SysName:\t%.*s\n"
17337 +               "NodeName:\t%.*s\n"
17338 +               "Release:\t%.*s\n"
17339 +               "Version:\t%.*s\n"
17340 +               "Machine:\t%.*s\n"
17341 +               "DomainName:\t%.*s\n",
17342 +               __NEW_UTS_LEN, uts->name.sysname,
17343 +               __NEW_UTS_LEN, uts->name.nodename,
17344 +               __NEW_UTS_LEN, uts->name.release,
17345 +               __NEW_UTS_LEN, uts->name.version,
17346 +               __NEW_UTS_LEN, uts->name.machine,
17347 +               __NEW_UTS_LEN, uts->name.domainname);
17348 +skip_uts:
17349 +
17350 +       ipc = nsproxy->ipc_ns;
17351 +       if (!ipc)
17352 +               goto skip_ipc;
17353 +
17354 +       length += sprintf(buffer + length,
17355 +               "SEMS:\t\t%d %d %d %d  %d\n"
17356 +               "MSG:\t\t%d %d %d\n"
17357 +               "SHM:\t\t%lu %lu  %d %d\n",
17358 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17359 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17360 +               ipc->used_sems,
17361 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17362 +               (unsigned long)ipc->shm_ctlmax,
17363 +               (unsigned long)ipc->shm_ctlall,
17364 +               ipc->shm_ctlmni, ipc->shm_tot);
17365 +skip_ipc:
17366 +out:
17367 +       return length;
17368 +}
17369 +
17370 +
17371 +#include <linux/sched.h>
17372 +
17373 +#define LOAD_INT(x) ((x) >> FSHIFT)
17374 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17375 +
17376 +static inline
17377 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17378 +{
17379 +       int length = 0;
17380 +       int a, b, c;
17381 +
17382 +       length += sprintf(buffer + length,
17383 +               "BiasUptime:\t%lu.%02lu\n",
17384 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17385 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17386 +
17387 +       a = cvirt->load[0] + (FIXED_1 / 200);
17388 +       b = cvirt->load[1] + (FIXED_1 / 200);
17389 +       c = cvirt->load[2] + (FIXED_1 / 200);
17390 +       length += sprintf(buffer + length,
17391 +               "nr_threads:\t%d\n"
17392 +               "nr_running:\t%d\n"
17393 +               "nr_unintr:\t%d\n"
17394 +               "nr_onhold:\t%d\n"
17395 +               "load_updates:\t%d\n"
17396 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17397 +               "total_forks:\t%d\n",
17398 +               atomic_read(&cvirt->nr_threads),
17399 +               atomic_read(&cvirt->nr_running),
17400 +               atomic_read(&cvirt->nr_uninterruptible),
17401 +               atomic_read(&cvirt->nr_onhold),
17402 +               atomic_read(&cvirt->load_updates),
17403 +               LOAD_INT(a), LOAD_FRAC(a),
17404 +               LOAD_INT(b), LOAD_FRAC(b),
17405 +               LOAD_INT(c), LOAD_FRAC(c),
17406 +               atomic_read(&cvirt->total_forks));
17407 +       return length;
17408 +}
17409 +
17410 +static inline
17411 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17412 +       char *buffer, int cpu)
17413 +{
17414 +       int length = 0;
17415 +       return length;
17416 +}
17417 +
17418 +#endif /* _VX_CVIRT_PROC_H */
17419 diff -NurpP --minimal linux-3.7.1/kernel/vserver/debug.c linux-3.7.1-vs2.3.5.5/kernel/vserver/debug.c
17420 --- linux-3.7.1/kernel/vserver/debug.c  1970-01-01 00:00:00.000000000 +0000
17421 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/debug.c        2012-12-18 15:13:16.000000000 +0000
17422 @@ -0,0 +1,32 @@
17423 +/*
17424 + *  kernel/vserver/debug.c
17425 + *
17426 + *  Copyright (C) 2005-2007 Herbert Pötzl
17427 + *
17428 + *  V0.01  vx_info dump support
17429 + *
17430 + */
17431 +
17432 +#include <linux/module.h>
17433 +
17434 +#include <linux/vserver/context.h>
17435 +
17436 +
17437 +void   dump_vx_info(struct vx_info *vxi, int level)
17438 +{
17439 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17440 +               atomic_read(&vxi->vx_usecnt),
17441 +               atomic_read(&vxi->vx_tasks),
17442 +               vxi->vx_state);
17443 +       if (level > 0) {
17444 +               __dump_vx_limit(&vxi->limit);
17445 +               __dump_vx_sched(&vxi->sched);
17446 +               __dump_vx_cvirt(&vxi->cvirt);
17447 +               __dump_vx_cacct(&vxi->cacct);
17448 +       }
17449 +       printk("---\n");
17450 +}
17451 +
17452 +
17453 +EXPORT_SYMBOL_GPL(dump_vx_info);
17454 +
17455 diff -NurpP --minimal linux-3.7.1/kernel/vserver/device.c linux-3.7.1-vs2.3.5.5/kernel/vserver/device.c
17456 --- linux-3.7.1/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17457 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/device.c       2012-12-18 15:13:16.000000000 +0000
17458 @@ -0,0 +1,443 @@
17459 +/*
17460 + *  linux/kernel/vserver/device.c
17461 + *
17462 + *  Linux-VServer: Device Support
17463 + *
17464 + *  Copyright (C) 2006  Herbert Pötzl
17465 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17466 + *
17467 + *  V0.01  device mapping basics
17468 + *  V0.02  added defaults
17469 + *
17470 + */
17471 +
17472 +#include <linux/slab.h>
17473 +#include <linux/rcupdate.h>
17474 +#include <linux/fs.h>
17475 +#include <linux/namei.h>
17476 +#include <linux/hash.h>
17477 +
17478 +#include <asm/errno.h>
17479 +#include <asm/uaccess.h>
17480 +#include <linux/vserver/base.h>
17481 +#include <linux/vserver/debug.h>
17482 +#include <linux/vserver/context.h>
17483 +#include <linux/vserver/device.h>
17484 +#include <linux/vserver/device_cmd.h>
17485 +
17486 +
17487 +#define DMAP_HASH_BITS 4
17488 +
17489 +
17490 +struct vs_mapping {
17491 +       union {
17492 +               struct hlist_node hlist;
17493 +               struct list_head list;
17494 +       } u;
17495 +#define dm_hlist       u.hlist
17496 +#define dm_list                u.list
17497 +       xid_t xid;
17498 +       dev_t device;
17499 +       struct vx_dmap_target target;
17500 +};
17501 +
17502 +
17503 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17504 +
17505 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17506 +
17507 +static struct vx_dmap_target dmap_defaults[2] = {
17508 +       { .flags = DATTR_OPEN },
17509 +       { .flags = DATTR_OPEN },
17510 +};
17511 +
17512 +
17513 +struct kmem_cache *dmap_cachep __read_mostly;
17514 +
17515 +int __init dmap_cache_init(void)
17516 +{
17517 +       dmap_cachep = kmem_cache_create("dmap_cache",
17518 +               sizeof(struct vs_mapping), 0,
17519 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17520 +       return 0;
17521 +}
17522 +
17523 +__initcall(dmap_cache_init);
17524 +
17525 +
17526 +static inline unsigned int __hashval(dev_t dev, int bits)
17527 +{
17528 +       return hash_long((unsigned long)dev, bits);
17529 +}
17530 +
17531 +
17532 +/*     __hash_mapping()
17533 + *     add the mapping to the hash table
17534 + */
17535 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17536 +{
17537 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17538 +       struct hlist_head *head, *hash = dmap_main_hash;
17539 +       int device = vdm->device;
17540 +
17541 +       spin_lock(hash_lock);
17542 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17543 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17544 +
17545 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17546 +       hlist_add_head(&vdm->dm_hlist, head);
17547 +       spin_unlock(hash_lock);
17548 +}
17549 +
17550 +
17551 +static inline int __mode_to_default(umode_t mode)
17552 +{
17553 +       switch (mode) {
17554 +       case S_IFBLK:
17555 +               return 0;
17556 +       case S_IFCHR:
17557 +               return 1;
17558 +       default:
17559 +               BUG();
17560 +       }
17561 +}
17562 +
17563 +
17564 +/*     __set_default()
17565 + *     set a default
17566 + */
17567 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17568 +       struct vx_dmap_target *vdmt)
17569 +{
17570 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17571 +       spin_lock(hash_lock);
17572 +
17573 +       if (vxi)
17574 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17575 +       else
17576 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17577 +
17578 +
17579 +       spin_unlock(hash_lock);
17580 +
17581 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17582 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17583 +}
17584 +
17585 +
17586 +/*     __remove_default()
17587 + *     remove a default
17588 + */
17589 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17590 +{
17591 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17592 +       spin_lock(hash_lock);
17593 +
17594 +       if (vxi)
17595 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17596 +       else    /* remove == reset */
17597 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17598 +
17599 +       spin_unlock(hash_lock);
17600 +       return 0;
17601 +}
17602 +
17603 +
17604 +/*     __find_mapping()
17605 + *     find a mapping in the hash table
17606 + *
17607 + *     caller must hold hash_lock
17608 + */
17609 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17610 +       struct vs_mapping **local, struct vs_mapping **global)
17611 +{
17612 +       struct hlist_head *hash = dmap_main_hash;
17613 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17614 +       struct hlist_node *pos;
17615 +       struct vs_mapping *vdm;
17616 +
17617 +       *local = NULL;
17618 +       if (global)
17619 +               *global = NULL;
17620 +
17621 +       hlist_for_each(pos, head) {
17622 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17623 +
17624 +               if ((vdm->device == device) &&
17625 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17626 +                       if (vdm->xid == xid) {
17627 +                               *local = vdm;
17628 +                               return 1;
17629 +                       } else if (global && vdm->xid == 0)
17630 +                               *global = vdm;
17631 +               }
17632 +       }
17633 +
17634 +       if (global && *global)
17635 +               return 0;
17636 +       else
17637 +               return -ENOENT;
17638 +}
17639 +
17640 +
17641 +/*     __lookup_mapping()
17642 + *     find a mapping and store the result in target and flags
17643 + */
17644 +static inline int __lookup_mapping(struct vx_info *vxi,
17645 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17646 +{
17647 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17648 +       struct vs_mapping *vdm, *global;
17649 +       struct vx_dmap_target *vdmt;
17650 +       int ret = 0;
17651 +       xid_t xid = vxi->vx_id;
17652 +       int index;
17653 +
17654 +       spin_lock(hash_lock);
17655 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17656 +               ret = 1;
17657 +               vdmt = &vdm->target;
17658 +               goto found;
17659 +       }
17660 +
17661 +       index = __mode_to_default(mode);
17662 +       if (vxi && vxi->dmap.targets[index].flags) {
17663 +               ret = 2;
17664 +               vdmt = &vxi->dmap.targets[index];
17665 +       } else if (global) {
17666 +               ret = 3;
17667 +               vdmt = &global->target;
17668 +               goto found;
17669 +       } else {
17670 +               ret = 4;
17671 +               vdmt = &dmap_defaults[index];
17672 +       }
17673 +
17674 +found:
17675 +       if (target && (vdmt->flags & DATTR_REMAP))
17676 +               *target = vdmt->target;
17677 +       else if (target)
17678 +               *target = device;
17679 +       if (flags)
17680 +               *flags = vdmt->flags;
17681 +
17682 +       spin_unlock(hash_lock);
17683 +
17684 +       return ret;
17685 +}
17686 +
17687 +
17688 +/*     __remove_mapping()
17689 + *     remove a mapping from the hash table
17690 + */
17691 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17692 +       umode_t mode)
17693 +{
17694 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17695 +       struct vs_mapping *vdm = NULL;
17696 +       int ret = 0;
17697 +
17698 +       spin_lock(hash_lock);
17699 +
17700 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17701 +               NULL);
17702 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17703 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17704 +       if (ret < 0)
17705 +               goto out;
17706 +       hlist_del(&vdm->dm_hlist);
17707 +
17708 +out:
17709 +       spin_unlock(hash_lock);
17710 +       if (vdm)
17711 +               kmem_cache_free(dmap_cachep, vdm);
17712 +       return ret;
17713 +}
17714 +
17715 +
17716 +
17717 +int vs_map_device(struct vx_info *vxi,
17718 +       dev_t device, dev_t *target, umode_t mode)
17719 +{
17720 +       int ret, flags = DATTR_MASK;
17721 +
17722 +       if (!vxi) {
17723 +               if (target)
17724 +                       *target = device;
17725 +               goto out;
17726 +       }
17727 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17728 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17729 +               device, target ? *target : 0, flags, mode, ret);
17730 +out:
17731 +       return (flags & DATTR_MASK);
17732 +}
17733 +
17734 +
17735 +
17736 +static int do_set_mapping(struct vx_info *vxi,
17737 +       dev_t device, dev_t target, int flags, umode_t mode)
17738 +{
17739 +       if (device) {
17740 +               struct vs_mapping *new;
17741 +
17742 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17743 +               if (!new)
17744 +                       return -ENOMEM;
17745 +
17746 +               INIT_HLIST_NODE(&new->dm_hlist);
17747 +               new->device = device;
17748 +               new->target.target = target;
17749 +               new->target.flags = flags | mode;
17750 +               new->xid = (vxi ? vxi->vx_id : 0);
17751 +
17752 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17753 +               __hash_mapping(vxi, new);
17754 +       } else {
17755 +               struct vx_dmap_target new = {
17756 +                       .target = target,
17757 +                       .flags = flags | mode,
17758 +               };
17759 +               __set_default(vxi, mode, &new);
17760 +       }
17761 +       return 0;
17762 +}
17763 +
17764 +
17765 +static int do_unset_mapping(struct vx_info *vxi,
17766 +       dev_t device, dev_t target, int flags, umode_t mode)
17767 +{
17768 +       int ret = -EINVAL;
17769 +
17770 +       if (device) {
17771 +               ret = __remove_mapping(vxi, device, mode);
17772 +               if (ret < 0)
17773 +                       goto out;
17774 +       } else {
17775 +               ret = __remove_default(vxi, mode);
17776 +               if (ret < 0)
17777 +                       goto out;
17778 +       }
17779 +
17780 +out:
17781 +       return ret;
17782 +}
17783 +
17784 +
17785 +static inline int __user_device(const char __user *name, dev_t *dev,
17786 +       umode_t *mode)
17787 +{
17788 +       struct nameidata nd;
17789 +       int ret;
17790 +
17791 +       if (!name) {
17792 +               *dev = 0;
17793 +               return 0;
17794 +       }
17795 +       ret = user_lpath(name, &nd.path);
17796 +       if (ret)
17797 +               return ret;
17798 +       if (nd.path.dentry->d_inode) {
17799 +               *dev = nd.path.dentry->d_inode->i_rdev;
17800 +               *mode = nd.path.dentry->d_inode->i_mode;
17801 +       }
17802 +       path_put(&nd.path);
17803 +       return 0;
17804 +}
17805 +
17806 +static inline int __mapping_mode(dev_t device, dev_t target,
17807 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17808 +{
17809 +       if (device)
17810 +               *mode = device_mode & S_IFMT;
17811 +       else if (target)
17812 +               *mode = target_mode & S_IFMT;
17813 +       else
17814 +               return -EINVAL;
17815 +
17816 +       /* if both given, device and target mode have to match */
17817 +       if (device && target &&
17818 +               ((device_mode ^ target_mode) & S_IFMT))
17819 +               return -EINVAL;
17820 +       return 0;
17821 +}
17822 +
17823 +
17824 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17825 +       const char __user *target_path, int flags, int set)
17826 +{
17827 +       dev_t device = ~0, target = ~0;
17828 +       umode_t device_mode = 0, target_mode = 0, mode;
17829 +       int ret;
17830 +
17831 +       ret = __user_device(device_path, &device, &device_mode);
17832 +       if (ret)
17833 +               return ret;
17834 +       ret = __user_device(target_path, &target, &target_mode);
17835 +       if (ret)
17836 +               return ret;
17837 +
17838 +       ret = __mapping_mode(device, target,
17839 +               device_mode, target_mode, &mode);
17840 +       if (ret)
17841 +               return ret;
17842 +
17843 +       if (set)
17844 +               return do_set_mapping(vxi, device, target,
17845 +                       flags, mode);
17846 +       else
17847 +               return do_unset_mapping(vxi, device, target,
17848 +                       flags, mode);
17849 +}
17850 +
17851 +
17852 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17853 +{
17854 +       struct vcmd_set_mapping_v0 vc_data;
17855 +
17856 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17857 +               return -EFAULT;
17858 +
17859 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17860 +               vc_data.flags, 1);
17861 +}
17862 +
17863 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17864 +{
17865 +       struct vcmd_set_mapping_v0 vc_data;
17866 +
17867 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17868 +               return -EFAULT;
17869 +
17870 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17871 +               vc_data.flags, 0);
17872 +}
17873 +
17874 +
17875 +#ifdef CONFIG_COMPAT
17876 +
17877 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17878 +{
17879 +       struct vcmd_set_mapping_v0_x32 vc_data;
17880 +
17881 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17882 +               return -EFAULT;
17883 +
17884 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17885 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17886 +}
17887 +
17888 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17889 +{
17890 +       struct vcmd_set_mapping_v0_x32 vc_data;
17891 +
17892 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17893 +               return -EFAULT;
17894 +
17895 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17896 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17897 +}
17898 +
17899 +#endif /* CONFIG_COMPAT */
17900 +
17901 +
17902 diff -NurpP --minimal linux-3.7.1/kernel/vserver/dlimit.c linux-3.7.1-vs2.3.5.5/kernel/vserver/dlimit.c
17903 --- linux-3.7.1/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17904 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/dlimit.c       2012-12-18 15:13:16.000000000 +0000
17905 @@ -0,0 +1,531 @@
17906 +/*
17907 + *  linux/kernel/vserver/dlimit.c
17908 + *
17909 + *  Virtual Server: Context Disk Limits
17910 + *
17911 + *  Copyright (C) 2004-2009  Herbert Pötzl
17912 + *
17913 + *  V0.01  initial version
17914 + *  V0.02  compat32 splitup
17915 + *  V0.03  extended interface
17916 + *
17917 + */
17918 +
17919 +#include <linux/statfs.h>
17920 +#include <linux/sched.h>
17921 +#include <linux/namei.h>
17922 +#include <linux/vs_tag.h>
17923 +#include <linux/vs_dlimit.h>
17924 +#include <linux/vserver/dlimit_cmd.h>
17925 +#include <linux/slab.h>
17926 +// #include <linux/gfp.h>
17927 +
17928 +#include <asm/uaccess.h>
17929 +
17930 +/*     __alloc_dl_info()
17931 +
17932 +       * allocate an initialized dl_info struct
17933 +       * doesn't make it visible (hash)                        */
17934 +
17935 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17936 +{
17937 +       struct dl_info *new = NULL;
17938 +
17939 +       vxdprintk(VXD_CBIT(dlim, 5),
17940 +               "alloc_dl_info(%p,%d)*", sb, tag);
17941 +
17942 +       /* would this benefit from a slab cache? */
17943 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17944 +       if (!new)
17945 +               return 0;
17946 +
17947 +       memset(new, 0, sizeof(struct dl_info));
17948 +       new->dl_tag = tag;
17949 +       new->dl_sb = sb;
17950 +       // INIT_RCU_HEAD(&new->dl_rcu);
17951 +       INIT_HLIST_NODE(&new->dl_hlist);
17952 +       spin_lock_init(&new->dl_lock);
17953 +       atomic_set(&new->dl_refcnt, 0);
17954 +       atomic_set(&new->dl_usecnt, 0);
17955 +
17956 +       /* rest of init goes here */
17957 +
17958 +       vxdprintk(VXD_CBIT(dlim, 4),
17959 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17960 +       return new;
17961 +}
17962 +
17963 +/*     __dealloc_dl_info()
17964 +
17965 +       * final disposal of dl_info                             */
17966 +
17967 +static void __dealloc_dl_info(struct dl_info *dli)
17968 +{
17969 +       vxdprintk(VXD_CBIT(dlim, 4),
17970 +               "dealloc_dl_info(%p)", dli);
17971 +
17972 +       dli->dl_hlist.next = LIST_POISON1;
17973 +       dli->dl_tag = -1;
17974 +       dli->dl_sb = 0;
17975 +
17976 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17977 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17978 +
17979 +       kfree(dli);
17980 +}
17981 +
17982 +
17983 +/*     hash table for dl_info hash */
17984 +
17985 +#define DL_HASH_SIZE   13
17986 +
17987 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17988 +
17989 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17990 +
17991 +
17992 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17993 +{
17994 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17995 +}
17996 +
17997 +
17998 +
17999 +/*     __hash_dl_info()
18000 +
18001 +       * add the dli to the global hash table
18002 +       * requires the hash_lock to be held                     */
18003 +
18004 +static inline void __hash_dl_info(struct dl_info *dli)
18005 +{
18006 +       struct hlist_head *head;
18007 +
18008 +       vxdprintk(VXD_CBIT(dlim, 6),
18009 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18010 +       get_dl_info(dli);
18011 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18012 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18013 +}
18014 +
18015 +/*     __unhash_dl_info()
18016 +
18017 +       * remove the dli from the global hash table
18018 +       * requires the hash_lock to be held                     */
18019 +
18020 +static inline void __unhash_dl_info(struct dl_info *dli)
18021 +{
18022 +       vxdprintk(VXD_CBIT(dlim, 6),
18023 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18024 +       hlist_del_rcu(&dli->dl_hlist);
18025 +       put_dl_info(dli);
18026 +}
18027 +
18028 +
18029 +/*     __lookup_dl_info()
18030 +
18031 +       * requires the rcu_read_lock()
18032 +       * doesn't increment the dl_refcnt                       */
18033 +
18034 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18035 +{
18036 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18037 +       struct hlist_node *pos;
18038 +       struct dl_info *dli;
18039 +
18040 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18041 +
18042 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18043 +                       return dli;
18044 +               }
18045 +       }
18046 +       return NULL;
18047 +}
18048 +
18049 +
18050 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18051 +{
18052 +       struct dl_info *dli;
18053 +
18054 +       rcu_read_lock();
18055 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18056 +       vxdprintk(VXD_CBIT(dlim, 7),
18057 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18058 +       rcu_read_unlock();
18059 +       return dli;
18060 +}
18061 +
18062 +void rcu_free_dl_info(struct rcu_head *head)
18063 +{
18064 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18065 +       int usecnt, refcnt;
18066 +
18067 +       BUG_ON(!dli || !head);
18068 +
18069 +       usecnt = atomic_read(&dli->dl_usecnt);
18070 +       BUG_ON(usecnt < 0);
18071 +
18072 +       refcnt = atomic_read(&dli->dl_refcnt);
18073 +       BUG_ON(refcnt < 0);
18074 +
18075 +       vxdprintk(VXD_CBIT(dlim, 3),
18076 +               "rcu_free_dl_info(%p)", dli);
18077 +       if (!usecnt)
18078 +               __dealloc_dl_info(dli);
18079 +       else
18080 +               printk("!!! rcu didn't free\n");
18081 +}
18082 +
18083 +
18084 +
18085 +
18086 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18087 +       uint32_t flags, int add)
18088 +{
18089 +       struct path path;
18090 +       int ret;
18091 +
18092 +       ret = user_lpath(name, &path);
18093 +       if (!ret) {
18094 +               struct super_block *sb;
18095 +               struct dl_info *dli;
18096 +
18097 +               ret = -EINVAL;
18098 +               if (!path.dentry->d_inode)
18099 +                       goto out_release;
18100 +               if (!(sb = path.dentry->d_inode->i_sb))
18101 +                       goto out_release;
18102 +
18103 +               if (add) {
18104 +                       dli = __alloc_dl_info(sb, id);
18105 +                       spin_lock(&dl_info_hash_lock);
18106 +
18107 +                       ret = -EEXIST;
18108 +                       if (__lookup_dl_info(sb, id))
18109 +                               goto out_unlock;
18110 +                       __hash_dl_info(dli);
18111 +                       dli = NULL;
18112 +               } else {
18113 +                       spin_lock(&dl_info_hash_lock);
18114 +                       dli = __lookup_dl_info(sb, id);
18115 +
18116 +                       ret = -ESRCH;
18117 +                       if (!dli)
18118 +                               goto out_unlock;
18119 +                       __unhash_dl_info(dli);
18120 +               }
18121 +               ret = 0;
18122 +       out_unlock:
18123 +               spin_unlock(&dl_info_hash_lock);
18124 +               if (add && dli)
18125 +                       __dealloc_dl_info(dli);
18126 +       out_release:
18127 +               path_put(&path);
18128 +       }
18129 +       return ret;
18130 +}
18131 +
18132 +int vc_add_dlimit(uint32_t id, void __user *data)
18133 +{
18134 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18135 +
18136 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18137 +               return -EFAULT;
18138 +
18139 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18140 +}
18141 +
18142 +int vc_rem_dlimit(uint32_t id, void __user *data)
18143 +{
18144 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18145 +
18146 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18147 +               return -EFAULT;
18148 +
18149 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18150 +}
18151 +
18152 +#ifdef CONFIG_COMPAT
18153 +
18154 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18155 +{
18156 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18157 +
18158 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18159 +               return -EFAULT;
18160 +
18161 +       return do_addrem_dlimit(id,
18162 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18163 +}
18164 +
18165 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18166 +{
18167 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18168 +
18169 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18170 +               return -EFAULT;
18171 +
18172 +       return do_addrem_dlimit(id,
18173 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18174 +}
18175 +
18176 +#endif /* CONFIG_COMPAT */
18177 +
18178 +
18179 +static inline
18180 +int do_set_dlimit(uint32_t id, const char __user *name,
18181 +       uint32_t space_used, uint32_t space_total,
18182 +       uint32_t inodes_used, uint32_t inodes_total,
18183 +       uint32_t reserved, uint32_t flags)
18184 +{
18185 +       struct path path;
18186 +       int ret;
18187 +
18188 +       ret = user_lpath(name, &path);
18189 +       if (!ret) {
18190 +               struct super_block *sb;
18191 +               struct dl_info *dli;
18192 +
18193 +               ret = -EINVAL;
18194 +               if (!path.dentry->d_inode)
18195 +                       goto out_release;
18196 +               if (!(sb = path.dentry->d_inode->i_sb))
18197 +                       goto out_release;
18198 +
18199 +               /* sanity checks */
18200 +               if ((reserved != CDLIM_KEEP &&
18201 +                       reserved > 100) ||
18202 +                       (inodes_used != CDLIM_KEEP &&
18203 +                       inodes_used > inodes_total) ||
18204 +                       (space_used != CDLIM_KEEP &&
18205 +                       space_used > space_total))
18206 +                       goto out_release;
18207 +
18208 +               ret = -ESRCH;
18209 +               dli = locate_dl_info(sb, id);
18210 +               if (!dli)
18211 +                       goto out_release;
18212 +
18213 +               spin_lock(&dli->dl_lock);
18214 +
18215 +               if (inodes_used != CDLIM_KEEP)
18216 +                       dli->dl_inodes_used = inodes_used;
18217 +               if (inodes_total != CDLIM_KEEP)
18218 +                       dli->dl_inodes_total = inodes_total;
18219 +               if (space_used != CDLIM_KEEP)
18220 +                       dli->dl_space_used = dlimit_space_32to64(
18221 +                               space_used, flags, DLIMS_USED);
18222 +
18223 +               if (space_total == CDLIM_INFINITY)
18224 +                       dli->dl_space_total = DLIM_INFINITY;
18225 +               else if (space_total != CDLIM_KEEP)
18226 +                       dli->dl_space_total = dlimit_space_32to64(
18227 +                               space_total, flags, DLIMS_TOTAL);
18228 +
18229 +               if (reserved != CDLIM_KEEP)
18230 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18231 +
18232 +               spin_unlock(&dli->dl_lock);
18233 +
18234 +               put_dl_info(dli);
18235 +               ret = 0;
18236 +
18237 +       out_release:
18238 +               path_put(&path);
18239 +       }
18240 +       return ret;
18241 +}
18242 +
18243 +int vc_set_dlimit(uint32_t id, void __user *data)
18244 +{
18245 +       struct vcmd_ctx_dlimit_v0 vc_data;
18246 +
18247 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18248 +               return -EFAULT;
18249 +
18250 +       return do_set_dlimit(id, vc_data.name,
18251 +               vc_data.space_used, vc_data.space_total,
18252 +               vc_data.inodes_used, vc_data.inodes_total,
18253 +               vc_data.reserved, vc_data.flags);
18254 +}
18255 +
18256 +#ifdef CONFIG_COMPAT
18257 +
18258 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18259 +{
18260 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18261 +
18262 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18263 +               return -EFAULT;
18264 +
18265 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18266 +               vc_data.space_used, vc_data.space_total,
18267 +               vc_data.inodes_used, vc_data.inodes_total,
18268 +               vc_data.reserved, vc_data.flags);
18269 +}
18270 +
18271 +#endif /* CONFIG_COMPAT */
18272 +
18273 +
18274 +static inline
18275 +int do_get_dlimit(uint32_t id, const char __user *name,
18276 +       uint32_t *space_used, uint32_t *space_total,
18277 +       uint32_t *inodes_used, uint32_t *inodes_total,
18278 +       uint32_t *reserved, uint32_t *flags)
18279 +{
18280 +       struct path path;
18281 +       int ret;
18282 +
18283 +       ret = user_lpath(name, &path);
18284 +       if (!ret) {
18285 +               struct super_block *sb;
18286 +               struct dl_info *dli;
18287 +
18288 +               ret = -EINVAL;
18289 +               if (!path.dentry->d_inode)
18290 +                       goto out_release;
18291 +               if (!(sb = path.dentry->d_inode->i_sb))
18292 +                       goto out_release;
18293 +
18294 +               ret = -ESRCH;
18295 +               dli = locate_dl_info(sb, id);
18296 +               if (!dli)
18297 +                       goto out_release;
18298 +
18299 +               spin_lock(&dli->dl_lock);
18300 +               *inodes_used = dli->dl_inodes_used;
18301 +               *inodes_total = dli->dl_inodes_total;
18302 +
18303 +               *space_used = dlimit_space_64to32(
18304 +                       dli->dl_space_used, flags, DLIMS_USED);
18305 +
18306 +               if (dli->dl_space_total == DLIM_INFINITY)
18307 +                       *space_total = CDLIM_INFINITY;
18308 +               else
18309 +                       *space_total = dlimit_space_64to32(
18310 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18311 +
18312 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18313 +               spin_unlock(&dli->dl_lock);
18314 +
18315 +               put_dl_info(dli);
18316 +               ret = -EFAULT;
18317 +
18318 +               ret = 0;
18319 +       out_release:
18320 +               path_put(&path);
18321 +       }
18322 +       return ret;
18323 +}
18324 +
18325 +
18326 +int vc_get_dlimit(uint32_t id, void __user *data)
18327 +{
18328 +       struct vcmd_ctx_dlimit_v0 vc_data;
18329 +       int ret;
18330 +
18331 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18332 +               return -EFAULT;
18333 +
18334 +       ret = do_get_dlimit(id, vc_data.name,
18335 +               &vc_data.space_used, &vc_data.space_total,
18336 +               &vc_data.inodes_used, &vc_data.inodes_total,
18337 +               &vc_data.reserved, &vc_data.flags);
18338 +       if (ret)
18339 +               return ret;
18340 +
18341 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18342 +               return -EFAULT;
18343 +       return 0;
18344 +}
18345 +
18346 +#ifdef CONFIG_COMPAT
18347 +
18348 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18349 +{
18350 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18351 +       int ret;
18352 +
18353 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18354 +               return -EFAULT;
18355 +
18356 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18357 +               &vc_data.space_used, &vc_data.space_total,
18358 +               &vc_data.inodes_used, &vc_data.inodes_total,
18359 +               &vc_data.reserved, &vc_data.flags);
18360 +       if (ret)
18361 +               return ret;
18362 +
18363 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18364 +               return -EFAULT;
18365 +       return 0;
18366 +}
18367 +
18368 +#endif /* CONFIG_COMPAT */
18369 +
18370 +
18371 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18372 +{
18373 +       struct dl_info *dli;
18374 +       __u64 blimit, bfree, bavail;
18375 +       __u32 ifree;
18376 +
18377 +       dli = locate_dl_info(sb, dx_current_tag());
18378 +       if (!dli)
18379 +               return;
18380 +
18381 +       spin_lock(&dli->dl_lock);
18382 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18383 +               goto no_ilim;
18384 +
18385 +       /* reduce max inodes available to limit */
18386 +       if (buf->f_files > dli->dl_inodes_total)
18387 +               buf->f_files = dli->dl_inodes_total;
18388 +
18389 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18390 +       /* reduce free inodes to min */
18391 +       if (ifree < buf->f_ffree)
18392 +               buf->f_ffree = ifree;
18393 +
18394 +no_ilim:
18395 +       if (dli->dl_space_total == DLIM_INFINITY)
18396 +               goto no_blim;
18397 +
18398 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18399 +
18400 +       if (dli->dl_space_total < dli->dl_space_used)
18401 +               bfree = 0;
18402 +       else
18403 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18404 +                       >> sb->s_blocksize_bits;
18405 +
18406 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18407 +       if (bavail < dli->dl_space_used)
18408 +               bavail = 0;
18409 +       else
18410 +               bavail = (bavail - dli->dl_space_used)
18411 +                       >> sb->s_blocksize_bits;
18412 +
18413 +       /* reduce max space available to limit */
18414 +       if (buf->f_blocks > blimit)
18415 +               buf->f_blocks = blimit;
18416 +
18417 +       /* reduce free space to min */
18418 +       if (bfree < buf->f_bfree)
18419 +               buf->f_bfree = bfree;
18420 +
18421 +       /* reduce avail space to min */
18422 +       if (bavail < buf->f_bavail)
18423 +               buf->f_bavail = bavail;
18424 +
18425 +no_blim:
18426 +       spin_unlock(&dli->dl_lock);
18427 +       put_dl_info(dli);
18428 +
18429 +       return;
18430 +}
18431 +
18432 +#include <linux/module.h>
18433 +
18434 +EXPORT_SYMBOL_GPL(locate_dl_info);
18435 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18436 +
18437 diff -NurpP --minimal linux-3.7.1/kernel/vserver/helper.c linux-3.7.1-vs2.3.5.5/kernel/vserver/helper.c
18438 --- linux-3.7.1/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18439 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/helper.c       2012-12-18 15:13:16.000000000 +0000
18440 @@ -0,0 +1,229 @@
18441 +/*
18442 + *  linux/kernel/vserver/helper.c
18443 + *
18444 + *  Virtual Context Support
18445 + *
18446 + *  Copyright (C) 2004-2007  Herbert Pötzl
18447 + *
18448 + *  V0.01  basic helper
18449 + *
18450 + */
18451 +
18452 +#include <linux/kmod.h>
18453 +#include <linux/reboot.h>
18454 +#include <linux/vs_context.h>
18455 +#include <linux/vs_network.h>
18456 +#include <linux/vserver/signal.h>
18457 +
18458 +
18459 +char vshelper_path[255] = "/sbin/vshelper";
18460 +
18461 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18462 +{
18463 +       current->flags &= ~PF_THREAD_BOUND;
18464 +       return 0;
18465 +}
18466 +
18467 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18468 +{
18469 +       int ret;
18470 +
18471 +       if ((ret = call_usermodehelper_fns(name, argv, envp,
18472 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18473 +               vshelper_init, NULL, NULL))) {
18474 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18475 +                       name, argv[1], argv[2],
18476 +                       sync ? "sync" : "async", ret);
18477 +       }
18478 +       vxdprintk(VXD_CBIT(switch, 4),
18479 +               "%s: (%s %s) returned %s with %d",
18480 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18481 +       return ret;
18482 +}
18483 +
18484 +/*
18485 + *      vshelper path is set via /proc/sys
18486 + *      invoked by vserver sys_reboot(), with
18487 + *      the following arguments
18488 + *
18489 + *      argv [0] = vshelper_path;
18490 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18491 + *      argv [2] = context identifier
18492 + *
18493 + *      envp [*] = type-specific parameters
18494 + */
18495 +
18496 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18497 +{
18498 +       char id_buf[8], cmd_buf[16];
18499 +       char uid_buf[16], pid_buf[16];
18500 +       int ret;
18501 +
18502 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18503 +       char *envp[] = {"HOME=/", "TERM=linux",
18504 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18505 +                       uid_buf, pid_buf, cmd_buf, 0};
18506 +
18507 +       if (vx_info_state(vxi, VXS_HELPER))
18508 +               return -EAGAIN;
18509 +       vxi->vx_state |= VXS_HELPER;
18510 +
18511 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18512 +
18513 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18514 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18515 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18516 +
18517 +       switch (cmd) {
18518 +       case LINUX_REBOOT_CMD_RESTART:
18519 +               argv[1] = "restart";
18520 +               break;
18521 +
18522 +       case LINUX_REBOOT_CMD_HALT:
18523 +               argv[1] = "halt";
18524 +               break;
18525 +
18526 +       case LINUX_REBOOT_CMD_POWER_OFF:
18527 +               argv[1] = "poweroff";
18528 +               break;
18529 +
18530 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18531 +               argv[1] = "swsusp";
18532 +               break;
18533 +
18534 +       case LINUX_REBOOT_CMD_OOM:
18535 +               argv[1] = "oom";
18536 +               break;
18537 +
18538 +       default:
18539 +               vxi->vx_state &= ~VXS_HELPER;
18540 +               return 0;
18541 +       }
18542 +
18543 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18544 +       vxi->vx_state &= ~VXS_HELPER;
18545 +       __wakeup_vx_info(vxi);
18546 +       return (ret) ? -EPERM : 0;
18547 +}
18548 +
18549 +
18550 +long vs_reboot(unsigned int cmd, void __user *arg)
18551 +{
18552 +       struct vx_info *vxi = current_vx_info();
18553 +       long ret = 0;
18554 +
18555 +       vxdprintk(VXD_CBIT(misc, 5),
18556 +               "vs_reboot(%p[#%d],%u)",
18557 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18558 +
18559 +       ret = vs_reboot_helper(vxi, cmd, arg);
18560 +       if (ret)
18561 +               return ret;
18562 +
18563 +       vxi->reboot_cmd = cmd;
18564 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18565 +               switch (cmd) {
18566 +               case LINUX_REBOOT_CMD_RESTART:
18567 +               case LINUX_REBOOT_CMD_HALT:
18568 +               case LINUX_REBOOT_CMD_POWER_OFF:
18569 +                       vx_info_kill(vxi, 0, SIGKILL);
18570 +                       vx_info_kill(vxi, 1, SIGKILL);
18571 +               default:
18572 +                       break;
18573 +               }
18574 +       }
18575 +       return 0;
18576 +}
18577 +
18578 +long vs_oom_action(unsigned int cmd)
18579 +{
18580 +       struct vx_info *vxi = current_vx_info();
18581 +       long ret = 0;
18582 +
18583 +       vxdprintk(VXD_CBIT(misc, 5),
18584 +               "vs_oom_action(%p[#%d],%u)",
18585 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18586 +
18587 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18588 +       if (ret)
18589 +               return ret;
18590 +
18591 +       vxi->reboot_cmd = cmd;
18592 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18593 +               vx_info_kill(vxi, 0, SIGKILL);
18594 +               vx_info_kill(vxi, 1, SIGKILL);
18595 +       }
18596 +       return 0;
18597 +}
18598 +
18599 +/*
18600 + *      argv [0] = vshelper_path;
18601 + *      argv [1] = action: "startup", "shutdown"
18602 + *      argv [2] = context identifier
18603 + *
18604 + *      envp [*] = type-specific parameters
18605 + */
18606 +
18607 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18608 +{
18609 +       char id_buf[8], cmd_buf[16];
18610 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18611 +       char *envp[] = {"HOME=/", "TERM=linux",
18612 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18613 +
18614 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18615 +               return 0;
18616 +
18617 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18618 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18619 +
18620 +       switch (cmd) {
18621 +       case VSC_STARTUP:
18622 +               argv[1] = "startup";
18623 +               break;
18624 +       case VSC_SHUTDOWN:
18625 +               argv[1] = "shutdown";
18626 +               break;
18627 +       default:
18628 +               return 0;
18629 +       }
18630 +
18631 +       return do_vshelper(vshelper_path, argv, envp, 1);
18632 +}
18633 +
18634 +
18635 +/*
18636 + *      argv [0] = vshelper_path;
18637 + *      argv [1] = action: "netup", "netdown"
18638 + *      argv [2] = context identifier
18639 + *
18640 + *      envp [*] = type-specific parameters
18641 + */
18642 +
18643 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18644 +{
18645 +       char id_buf[8], cmd_buf[16];
18646 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18647 +       char *envp[] = {"HOME=/", "TERM=linux",
18648 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18649 +
18650 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18651 +               return 0;
18652 +
18653 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18654 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18655 +
18656 +       switch (cmd) {
18657 +       case VSC_NETUP:
18658 +               argv[1] = "netup";
18659 +               break;
18660 +       case VSC_NETDOWN:
18661 +               argv[1] = "netdown";
18662 +               break;
18663 +       default:
18664 +               return 0;
18665 +       }
18666 +
18667 +       return do_vshelper(vshelper_path, argv, envp, 1);
18668 +}
18669 +
18670 diff -NurpP --minimal linux-3.7.1/kernel/vserver/history.c linux-3.7.1-vs2.3.5.5/kernel/vserver/history.c
18671 --- linux-3.7.1/kernel/vserver/history.c        1970-01-01 00:00:00.000000000 +0000
18672 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/history.c      2012-12-18 15:13:16.000000000 +0000
18673 @@ -0,0 +1,258 @@
18674 +/*
18675 + *  kernel/vserver/history.c
18676 + *
18677 + *  Virtual Context History Backtrace
18678 + *
18679 + *  Copyright (C) 2004-2007  Herbert Pötzl
18680 + *
18681 + *  V0.01  basic structure
18682 + *  V0.02  hash/unhash and trace
18683 + *  V0.03  preemption fixes
18684 + *
18685 + */
18686 +
18687 +#include <linux/module.h>
18688 +#include <asm/uaccess.h>
18689 +
18690 +#include <linux/vserver/context.h>
18691 +#include <linux/vserver/debug.h>
18692 +#include <linux/vserver/debug_cmd.h>
18693 +#include <linux/vserver/history.h>
18694 +
18695 +
18696 +#ifdef CONFIG_VSERVER_HISTORY
18697 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18698 +#else
18699 +#define VXH_SIZE       64
18700 +#endif
18701 +
18702 +struct _vx_history {
18703 +       unsigned int counter;
18704 +
18705 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18706 +};
18707 +
18708 +
18709 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18710 +
18711 +unsigned volatile int vxh_active = 1;
18712 +
18713 +static atomic_t sequence = ATOMIC_INIT(0);
18714 +
18715 +
18716 +/*     vxh_advance()
18717 +
18718 +       * requires disabled preemption                          */
18719 +
18720 +struct _vx_hist_entry *vxh_advance(void *loc)
18721 +{
18722 +       unsigned int cpu = smp_processor_id();
18723 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18724 +       struct _vx_hist_entry *entry;
18725 +       unsigned int index;
18726 +
18727 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18728 +       entry = &hist->entry[index];
18729 +
18730 +       entry->seq = atomic_inc_return(&sequence);
18731 +       entry->loc = loc;
18732 +       return entry;
18733 +}
18734 +
18735 +EXPORT_SYMBOL_GPL(vxh_advance);
18736 +
18737 +
18738 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18739 +
18740 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18741 +
18742 +
18743 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18744 +
18745 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18746 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18747 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18748 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18749 +
18750 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18751 +{
18752 +       switch (e->type) {
18753 +       case VXH_THROW_OOPS:
18754 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18755 +               break;
18756 +
18757 +       case VXH_GET_VX_INFO:
18758 +       case VXH_PUT_VX_INFO:
18759 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18760 +                       VXH_LOC_ARGS(e),
18761 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18762 +                       VXH_VXI_ARGS(e));
18763 +               break;
18764 +
18765 +       case VXH_INIT_VX_INFO:
18766 +       case VXH_SET_VX_INFO:
18767 +       case VXH_CLR_VX_INFO:
18768 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18769 +                       VXH_LOC_ARGS(e),
18770 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18771 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18772 +                       VXH_VXI_ARGS(e), e->sc.data);
18773 +               break;
18774 +
18775 +       case VXH_CLAIM_VX_INFO:
18776 +       case VXH_RELEASE_VX_INFO:
18777 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18778 +                       VXH_LOC_ARGS(e),
18779 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18780 +                       VXH_VXI_ARGS(e), e->sc.data);
18781 +               break;
18782 +
18783 +       case VXH_ALLOC_VX_INFO:
18784 +       case VXH_DEALLOC_VX_INFO:
18785 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18786 +                       VXH_LOC_ARGS(e),
18787 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18788 +                       VXH_VXI_ARGS(e));
18789 +               break;
18790 +
18791 +       case VXH_HASH_VX_INFO:
18792 +       case VXH_UNHASH_VX_INFO:
18793 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18794 +                       VXH_LOC_ARGS(e),
18795 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18796 +                       VXH_VXI_ARGS(e));
18797 +               break;
18798 +
18799 +       case VXH_LOC_VX_INFO:
18800 +       case VXH_LOOKUP_VX_INFO:
18801 +       case VXH_CREATE_VX_INFO:
18802 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18803 +                       VXH_LOC_ARGS(e),
18804 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18805 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18806 +                       e->ll.arg, VXH_VXI_ARGS(e));
18807 +               break;
18808 +       }
18809 +}
18810 +
18811 +static void __vxh_dump_history(void)
18812 +{
18813 +       unsigned int i, cpu;
18814 +
18815 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18816 +               atomic_read(&sequence), NR_CPUS);
18817 +
18818 +       for (i = 0; i < VXH_SIZE; i++) {
18819 +               for_each_online_cpu(cpu) {
18820 +                       struct _vx_history *hist =
18821 +                               &per_cpu(vx_history_buffer, cpu);
18822 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18823 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18824 +
18825 +                       vxh_dump_entry(entry, cpu);
18826 +               }
18827 +       }
18828 +}
18829 +
18830 +void   vxh_dump_history(void)
18831 +{
18832 +       vxh_active = 0;
18833 +#ifdef CONFIG_SMP
18834 +       local_irq_enable();
18835 +       smp_send_stop();
18836 +       local_irq_disable();
18837 +#endif
18838 +       __vxh_dump_history();
18839 +}
18840 +
18841 +
18842 +/* vserver syscall commands below here */
18843 +
18844 +
18845 +int vc_dump_history(uint32_t id)
18846 +{
18847 +       vxh_active = 0;
18848 +       __vxh_dump_history();
18849 +       vxh_active = 1;
18850 +
18851 +       return 0;
18852 +}
18853 +
18854 +
18855 +int do_read_history(struct __user _vx_hist_entry *data,
18856 +       int cpu, uint32_t *index, uint32_t *count)
18857 +{
18858 +       int pos, ret = 0;
18859 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18860 +       int end = hist->counter;
18861 +       int start = end - VXH_SIZE + 2;
18862 +       int idx = *index;
18863 +
18864 +       /* special case: get current pos */
18865 +       if (!*count) {
18866 +               *index = end;
18867 +               return 0;
18868 +       }
18869 +
18870 +       /* have we lost some data? */
18871 +       if (idx < start)
18872 +               idx = start;
18873 +
18874 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18875 +               struct _vx_hist_entry *entry =
18876 +                       &hist->entry[idx % VXH_SIZE];
18877 +
18878 +               /* send entry to userspace */
18879 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18880 +               if (ret)
18881 +                       break;
18882 +       }
18883 +       /* save new index and count */
18884 +       *index = idx;
18885 +       *count = pos;
18886 +       return ret ? ret : (*index < end);
18887 +}
18888 +
18889 +int vc_read_history(uint32_t id, void __user *data)
18890 +{
18891 +       struct vcmd_read_history_v0 vc_data;
18892 +       int ret;
18893 +
18894 +       if (id >= NR_CPUS)
18895 +               return -EINVAL;
18896 +
18897 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18898 +               return -EFAULT;
18899 +
18900 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18901 +               id, &vc_data.index, &vc_data.count);
18902 +
18903 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18904 +               return -EFAULT;
18905 +       return ret;
18906 +}
18907 +
18908 +#ifdef CONFIG_COMPAT
18909 +
18910 +int vc_read_history_x32(uint32_t id, void __user *data)
18911 +{
18912 +       struct vcmd_read_history_v0_x32 vc_data;
18913 +       int ret;
18914 +
18915 +       if (id >= NR_CPUS)
18916 +               return -EINVAL;
18917 +
18918 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18919 +               return -EFAULT;
18920 +
18921 +       ret = do_read_history((struct __user _vx_hist_entry *)
18922 +               compat_ptr(vc_data.data_ptr),
18923 +               id, &vc_data.index, &vc_data.count);
18924 +
18925 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18926 +               return -EFAULT;
18927 +       return ret;
18928 +}
18929 +
18930 +#endif /* CONFIG_COMPAT */
18931 +
18932 diff -NurpP --minimal linux-3.7.1/kernel/vserver/inet.c linux-3.7.1-vs2.3.5.5/kernel/vserver/inet.c
18933 --- linux-3.7.1/kernel/vserver/inet.c   1970-01-01 00:00:00.000000000 +0000
18934 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/inet.c 2013-01-11 13:43:00.000000000 +0000
18935 @@ -0,0 +1,236 @@
18936 +
18937 +#include <linux/in.h>
18938 +#include <linux/inetdevice.h>
18939 +#include <linux/export.h>
18940 +#include <linux/vs_inet.h>
18941 +#include <linux/vs_inet6.h>
18942 +#include <linux/vserver/debug.h>
18943 +#include <net/route.h>
18944 +#include <net/addrconf.h>
18945 +
18946 +
18947 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18948 +{
18949 +       int ret = 0;
18950 +
18951 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18952 +               ret = 1;
18953 +       else {
18954 +               struct nx_addr_v4 *ptr;
18955 +               unsigned long irqflags;
18956 +
18957 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18958 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18959 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18960 +                               ret = 1;
18961 +                               break;
18962 +                       }
18963 +               }
18964 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18965 +       }
18966 +
18967 +       vxdprintk(VXD_CBIT(net, 2),
18968 +               "nx_v4_addr_conflict(%p,%p): %d",
18969 +               nxi1, nxi2, ret);
18970 +
18971 +       return ret;
18972 +}
18973 +
18974 +
18975 +#ifdef CONFIG_IPV6
18976 +
18977 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18978 +{
18979 +       int ret = 0;
18980 +
18981 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18982 +               ret = 1;
18983 +       else {
18984 +               struct nx_addr_v6 *ptr;
18985 +               unsigned long irqflags;
18986 +
18987 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18988 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18989 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18990 +                               ret = 1;
18991 +                               break;
18992 +                       }
18993 +               }
18994 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18995 +       }
18996 +
18997 +       vxdprintk(VXD_CBIT(net, 2),
18998 +               "nx_v6_addr_conflict(%p,%p): %d",
18999 +               nxi1, nxi2, ret);
19000 +
19001 +       return ret;
19002 +}
19003 +
19004 +#endif
19005 +
19006 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19007 +{
19008 +       struct in_device *in_dev;
19009 +       struct in_ifaddr **ifap;
19010 +       struct in_ifaddr *ifa;
19011 +       int ret = 0;
19012 +
19013 +       if (!dev)
19014 +               goto out;
19015 +       in_dev = in_dev_get(dev);
19016 +       if (!in_dev)
19017 +               goto out;
19018 +
19019 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19020 +               ifap = &ifa->ifa_next) {
19021 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19022 +                       ret = 1;
19023 +                       break;
19024 +               }
19025 +       }
19026 +       in_dev_put(in_dev);
19027 +out:
19028 +       return ret;
19029 +}
19030 +
19031 +
19032 +#ifdef CONFIG_IPV6
19033 +
19034 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19035 +{
19036 +       struct inet6_dev *in_dev;
19037 +       struct inet6_ifaddr *ifa;
19038 +       int ret = 0;
19039 +
19040 +       if (!dev)
19041 +               goto out;
19042 +       in_dev = in6_dev_get(dev);
19043 +       if (!in_dev)
19044 +               goto out;
19045 +
19046 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19047 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19048 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19049 +                       ret = 1;
19050 +                       break;
19051 +               }
19052 +       }
19053 +       in6_dev_put(in_dev);
19054 +out:
19055 +       return ret;
19056 +}
19057 +
19058 +#endif
19059 +
19060 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19061 +{
19062 +       int ret = 1;
19063 +
19064 +       if (!nxi)
19065 +               goto out;
19066 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19067 +               goto out;
19068 +#ifdef CONFIG_IPV6
19069 +       ret = 2;
19070 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19071 +               goto out;
19072 +#endif
19073 +       ret = 0;
19074 +out:
19075 +       vxdprintk(VXD_CBIT(net, 3),
19076 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19077 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19078 +       return ret;
19079 +}
19080 +
19081 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19082 +       struct flowi4 *fl4)
19083 +{
19084 +       struct rtable *rt;
19085 +
19086 +       if (!nxi)
19087 +               return NULL;
19088 +
19089 +       /* FIXME: handle lback only case */
19090 +       if (!NX_IPV4(nxi))
19091 +               return ERR_PTR(-EPERM);
19092 +
19093 +       vxdprintk(VXD_CBIT(net, 4),
19094 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19095 +               nxi, nxi ? nxi->nx_id : 0,
19096 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19097 +
19098 +       /* single IP is unconditional */
19099 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19100 +               (fl4->saddr == INADDR_ANY))
19101 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19102 +
19103 +       if (fl4->saddr == INADDR_ANY) {
19104 +               struct nx_addr_v4 *ptr;
19105 +               unsigned long irqflags;
19106 +               __be32 found = 0;
19107 +
19108 +               rt = __ip_route_output_key(net, fl4);
19109 +               if (!IS_ERR(rt)) {
19110 +                       found = fl4->saddr;
19111 +                       ip_rt_put(rt);
19112 +                       vxdprintk(VXD_CBIT(net, 4),
19113 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19114 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19115 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19116 +                               goto found;
19117 +               }
19118 +
19119 +               spin_lock_irqsave(&nxi->addr_lock, irqflags);
19120 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19121 +                       __be32 primary = ptr->ip[0].s_addr;
19122 +                       __be32 mask = ptr->mask.s_addr;
19123 +                       __be32 neta = primary & mask;
19124 +
19125 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19126 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19127 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19128 +                               NIPQUAD(mask), NIPQUAD(neta));
19129 +                       if ((found & mask) != neta)
19130 +                               continue;
19131 +
19132 +                       fl4->saddr = primary;
19133 +                       rt = __ip_route_output_key(net, fl4);
19134 +                       vxdprintk(VXD_CBIT(net, 4),
19135 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19136 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19137 +                       if (!IS_ERR(rt)) {
19138 +                               found = fl4->saddr;
19139 +                               ip_rt_put(rt);
19140 +                               if (found == primary)
19141 +                                       goto found_unlock;
19142 +                       }
19143 +               }
19144 +               /* still no source ip? */
19145 +               found = ipv4_is_loopback(fl4->daddr)
19146 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19147 +       found_unlock:
19148 +               spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19149 +       found:
19150 +               /* assign src ip to flow */
19151 +               fl4->saddr = found;
19152 +
19153 +       } else {
19154 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19155 +                       return ERR_PTR(-EPERM);
19156 +       }
19157 +
19158 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19159 +               if (ipv4_is_loopback(fl4->daddr))
19160 +                       fl4->daddr = nxi->v4_lback.s_addr;
19161 +               if (ipv4_is_loopback(fl4->saddr))
19162 +                       fl4->saddr = nxi->v4_lback.s_addr;
19163 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19164 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19165 +               return ERR_PTR(-EPERM);
19166 +
19167 +       return NULL;
19168 +}
19169 +
19170 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19171 +
19172 diff -NurpP --minimal linux-3.7.1/kernel/vserver/init.c linux-3.7.1-vs2.3.5.5/kernel/vserver/init.c
19173 --- linux-3.7.1/kernel/vserver/init.c   1970-01-01 00:00:00.000000000 +0000
19174 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/init.c 2012-12-18 15:13:16.000000000 +0000
19175 @@ -0,0 +1,45 @@
19176 +/*
19177 + *  linux/kernel/init.c
19178 + *
19179 + *  Virtual Server Init
19180 + *
19181 + *  Copyright (C) 2004-2007  Herbert Pötzl
19182 + *
19183 + *  V0.01  basic structure
19184 + *
19185 + */
19186 +
19187 +#include <linux/init.h>
19188 +
19189 +int    vserver_register_sysctl(void);
19190 +void   vserver_unregister_sysctl(void);
19191 +
19192 +
19193 +static int __init init_vserver(void)
19194 +{
19195 +       int ret = 0;
19196 +
19197 +#ifdef CONFIG_VSERVER_DEBUG
19198 +       vserver_register_sysctl();
19199 +#endif
19200 +       return ret;
19201 +}
19202 +
19203 +
19204 +static void __exit exit_vserver(void)
19205 +{
19206 +
19207 +#ifdef CONFIG_VSERVER_DEBUG
19208 +       vserver_unregister_sysctl();
19209 +#endif
19210 +       return;
19211 +}
19212 +
19213 +/* FIXME: GFP_ZONETYPES gone
19214 +long vx_slab[GFP_ZONETYPES]; */
19215 +long vx_area;
19216 +
19217 +
19218 +module_init(init_vserver);
19219 +module_exit(exit_vserver);
19220 +
19221 diff -NurpP --minimal linux-3.7.1/kernel/vserver/inode.c linux-3.7.1-vs2.3.5.5/kernel/vserver/inode.c
19222 --- linux-3.7.1/kernel/vserver/inode.c  1970-01-01 00:00:00.000000000 +0000
19223 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/inode.c        2012-12-18 15:13:16.000000000 +0000
19224 @@ -0,0 +1,437 @@
19225 +/*
19226 + *  linux/kernel/vserver/inode.c
19227 + *
19228 + *  Virtual Server: File System Support
19229 + *
19230 + *  Copyright (C) 2004-2007  Herbert Pötzl
19231 + *
19232 + *  V0.01  separated from vcontext V0.05
19233 + *  V0.02  moved to tag (instead of xid)
19234 + *
19235 + */
19236 +
19237 +#include <linux/tty.h>
19238 +#include <linux/proc_fs.h>
19239 +#include <linux/devpts_fs.h>
19240 +#include <linux/fs.h>
19241 +#include <linux/file.h>
19242 +#include <linux/mount.h>
19243 +#include <linux/parser.h>
19244 +#include <linux/namei.h>
19245 +#include <linux/vserver/inode.h>
19246 +#include <linux/vserver/inode_cmd.h>
19247 +#include <linux/vs_base.h>
19248 +#include <linux/vs_tag.h>
19249 +
19250 +#include <asm/uaccess.h>
19251 +
19252 +
19253 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19254 +{
19255 +       struct proc_dir_entry *entry;
19256 +
19257 +       if (!in || !in->i_sb)
19258 +               return -ESRCH;
19259 +
19260 +       *flags = IATTR_TAG
19261 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19262 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19263 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19264 +               | (IS_COW(in) ? IATTR_COW : 0);
19265 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19266 +
19267 +       if (S_ISDIR(in->i_mode))
19268 +               *mask |= IATTR_BARRIER;
19269 +
19270 +       if (IS_TAGGED(in)) {
19271 +               *tag = i_tag_read(in);
19272 +               *mask |= IATTR_TAG;
19273 +       }
19274 +
19275 +       switch (in->i_sb->s_magic) {
19276 +       case PROC_SUPER_MAGIC:
19277 +               entry = PROC_I(in)->pde;
19278 +
19279 +               /* check for specific inodes? */
19280 +               if (entry)
19281 +                       *mask |= IATTR_FLAGS;
19282 +               if (entry)
19283 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19284 +               else
19285 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19286 +               break;
19287 +
19288 +       case DEVPTS_SUPER_MAGIC:
19289 +               *tag = i_tag_read(in);
19290 +               *mask |= IATTR_TAG;
19291 +               break;
19292 +
19293 +       default:
19294 +               break;
19295 +       }
19296 +       return 0;
19297 +}
19298 +
19299 +int vc_get_iattr(void __user *data)
19300 +{
19301 +       struct path path;
19302 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19303 +       int ret;
19304 +
19305 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19306 +               return -EFAULT;
19307 +
19308 +       ret = user_lpath(vc_data.name, &path);
19309 +       if (!ret) {
19310 +               ret = __vc_get_iattr(path.dentry->d_inode,
19311 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19312 +               path_put(&path);
19313 +       }
19314 +       if (ret)
19315 +               return ret;
19316 +
19317 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19318 +               ret = -EFAULT;
19319 +       return ret;
19320 +}
19321 +
19322 +#ifdef CONFIG_COMPAT
19323 +
19324 +int vc_get_iattr_x32(void __user *data)
19325 +{
19326 +       struct path path;
19327 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19328 +       int ret;
19329 +
19330 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19331 +               return -EFAULT;
19332 +
19333 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19334 +       if (!ret) {
19335 +               ret = __vc_get_iattr(path.dentry->d_inode,
19336 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19337 +               path_put(&path);
19338 +       }
19339 +       if (ret)
19340 +               return ret;
19341 +
19342 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19343 +               ret = -EFAULT;
19344 +       return ret;
19345 +}
19346 +
19347 +#endif /* CONFIG_COMPAT */
19348 +
19349 +
19350 +int vc_fget_iattr(uint32_t fd, void __user *data)
19351 +{
19352 +       struct file *filp;
19353 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19354 +       int ret;
19355 +
19356 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19357 +               return -EFAULT;
19358 +
19359 +       filp = fget(fd);
19360 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19361 +               return -EBADF;
19362 +
19363 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19364 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19365 +
19366 +       fput(filp);
19367 +
19368 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19369 +               ret = -EFAULT;
19370 +       return ret;
19371 +}
19372 +
19373 +
19374 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19375 +{
19376 +       struct inode *in = de->d_inode;
19377 +       int error = 0, is_proc = 0, has_tag = 0;
19378 +       struct iattr attr = { 0 };
19379 +
19380 +       if (!in || !in->i_sb)
19381 +               return -ESRCH;
19382 +
19383 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19384 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19385 +               return -EINVAL;
19386 +
19387 +       has_tag = IS_TAGGED(in) ||
19388 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19389 +       if ((*mask & IATTR_TAG) && !has_tag)
19390 +               return -EINVAL;
19391 +
19392 +       mutex_lock(&in->i_mutex);
19393 +       if (*mask & IATTR_TAG) {
19394 +               attr.ia_tag = *tag;
19395 +               attr.ia_valid |= ATTR_TAG;
19396 +       }
19397 +
19398 +       if (*mask & IATTR_FLAGS) {
19399 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19400 +               unsigned int iflags = PROC_I(in)->vx_flags;
19401 +
19402 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19403 +                       | (*flags & IATTR_FLAGS);
19404 +               PROC_I(in)->vx_flags = iflags;
19405 +               if (entry)
19406 +                       entry->vx_flags = iflags;
19407 +       }
19408 +
19409 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19410 +               IATTR_BARRIER | IATTR_COW)) {
19411 +               int iflags = in->i_flags;
19412 +               int vflags = in->i_vflags;
19413 +
19414 +               if (*mask & IATTR_IMMUTABLE) {
19415 +                       if (*flags & IATTR_IMMUTABLE)
19416 +                               iflags |= S_IMMUTABLE;
19417 +                       else
19418 +                               iflags &= ~S_IMMUTABLE;
19419 +               }
19420 +               if (*mask & IATTR_IXUNLINK) {
19421 +                       if (*flags & IATTR_IXUNLINK)
19422 +                               iflags |= S_IXUNLINK;
19423 +                       else
19424 +                               iflags &= ~S_IXUNLINK;
19425 +               }
19426 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19427 +                       if (*flags & IATTR_BARRIER)
19428 +                               vflags |= V_BARRIER;
19429 +                       else
19430 +                               vflags &= ~V_BARRIER;
19431 +               }
19432 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19433 +                       if (*flags & IATTR_COW)
19434 +                               vflags |= V_COW;
19435 +                       else
19436 +                               vflags &= ~V_COW;
19437 +               }
19438 +               if (in->i_op && in->i_op->sync_flags) {
19439 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19440 +                       if (error)
19441 +                               goto out;
19442 +               }
19443 +       }
19444 +
19445 +       if (attr.ia_valid) {
19446 +               if (in->i_op && in->i_op->setattr)
19447 +                       error = in->i_op->setattr(de, &attr);
19448 +               else {
19449 +                       error = inode_change_ok(in, &attr);
19450 +                       if (!error) {
19451 +                               setattr_copy(in, &attr);
19452 +                               mark_inode_dirty(in);
19453 +                       }
19454 +               }
19455 +       }
19456 +
19457 +out:
19458 +       mutex_unlock(&in->i_mutex);
19459 +       return error;
19460 +}
19461 +
19462 +int vc_set_iattr(void __user *data)
19463 +{
19464 +       struct path path;
19465 +       struct vcmd_ctx_iattr_v1 vc_data;
19466 +       int ret;
19467 +
19468 +       if (!capable(CAP_LINUX_IMMUTABLE))
19469 +               return -EPERM;
19470 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19471 +               return -EFAULT;
19472 +
19473 +       ret = user_lpath(vc_data.name, &path);
19474 +       if (!ret) {
19475 +               ret = __vc_set_iattr(path.dentry,
19476 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19477 +               path_put(&path);
19478 +       }
19479 +
19480 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19481 +               ret = -EFAULT;
19482 +       return ret;
19483 +}
19484 +
19485 +#ifdef CONFIG_COMPAT
19486 +
19487 +int vc_set_iattr_x32(void __user *data)
19488 +{
19489 +       struct path path;
19490 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19491 +       int ret;
19492 +
19493 +       if (!capable(CAP_LINUX_IMMUTABLE))
19494 +               return -EPERM;
19495 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19496 +               return -EFAULT;
19497 +
19498 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19499 +       if (!ret) {
19500 +               ret = __vc_set_iattr(path.dentry,
19501 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19502 +               path_put(&path);
19503 +       }
19504 +
19505 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19506 +               ret = -EFAULT;
19507 +       return ret;
19508 +}
19509 +
19510 +#endif /* CONFIG_COMPAT */
19511 +
19512 +int vc_fset_iattr(uint32_t fd, void __user *data)
19513 +{
19514 +       struct file *filp;
19515 +       struct vcmd_ctx_fiattr_v0 vc_data;
19516 +       int ret;
19517 +
19518 +       if (!capable(CAP_LINUX_IMMUTABLE))
19519 +               return -EPERM;
19520 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19521 +               return -EFAULT;
19522 +
19523 +       filp = fget(fd);
19524 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19525 +               return -EBADF;
19526 +
19527 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19528 +               &vc_data.flags, &vc_data.mask);
19529 +
19530 +       fput(filp);
19531 +
19532 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19533 +               return -EFAULT;
19534 +       return ret;
19535 +}
19536 +
19537 +
19538 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19539 +
19540 +static match_table_t tokens = {
19541 +       {Opt_notagcheck, "notagcheck"},
19542 +#ifdef CONFIG_PROPAGATE
19543 +       {Opt_notag, "notag"},
19544 +       {Opt_tag, "tag"},
19545 +       {Opt_tagid, "tagid=%u"},
19546 +#endif
19547 +       {Opt_err, NULL}
19548 +};
19549 +
19550 +
19551 +static void __dx_parse_remove(char *string, char *opt)
19552 +{
19553 +       char *p = strstr(string, opt);
19554 +       char *q = p;
19555 +
19556 +       if (p) {
19557 +               while (*q != '\0' && *q != ',')
19558 +                       q++;
19559 +               while (*q)
19560 +                       *p++ = *q++;
19561 +               while (*p)
19562 +                       *p++ = '\0';
19563 +       }
19564 +}
19565 +
19566 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19567 +                unsigned long *flags)
19568 +{
19569 +       int set = 0;
19570 +       substring_t args[MAX_OPT_ARGS];
19571 +       int token;
19572 +       char *s, *p, *opts;
19573 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19574 +       int option = 0;
19575 +#endif
19576 +
19577 +       if (!string)
19578 +               return 0;
19579 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19580 +       if (!s)
19581 +               return 0;
19582 +
19583 +       opts = s;
19584 +       while ((p = strsep(&opts, ",")) != NULL) {
19585 +               token = match_token(p, tokens, args);
19586 +
19587 +               switch (token) {
19588 +#ifdef CONFIG_PROPAGATE
19589 +               case Opt_tag:
19590 +                       if (tag)
19591 +                               *tag = 0;
19592 +                       if (remove)
19593 +                               __dx_parse_remove(s, "tag");
19594 +                       *mnt_flags |= MNT_TAGID;
19595 +                       set |= MNT_TAGID;
19596 +                       break;
19597 +               case Opt_notag:
19598 +                       if (remove)
19599 +                               __dx_parse_remove(s, "notag");
19600 +                       *mnt_flags |= MNT_NOTAG;
19601 +                       set |= MNT_NOTAG;
19602 +                       break;
19603 +               case Opt_tagid:
19604 +                       if (tag && !match_int(args, &option))
19605 +                               *tag = option;
19606 +                       if (remove)
19607 +                               __dx_parse_remove(s, "tagid");
19608 +                       *mnt_flags |= MNT_TAGID;
19609 +                       set |= MNT_TAGID;
19610 +                       break;
19611 +#endif /* CONFIG_PROPAGATE */
19612 +               case Opt_notagcheck:
19613 +                       if (remove)
19614 +                               __dx_parse_remove(s, "notagcheck");
19615 +                       *flags |= MS_NOTAGCHECK;
19616 +                       set |= MS_NOTAGCHECK;
19617 +                       break;
19618 +               }
19619 +               vxdprintk(VXD_CBIT(tag, 7),
19620 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19621 +                       p, token, option);
19622 +       }
19623 +       if (set)
19624 +               strcpy(string, s);
19625 +       kfree(s);
19626 +       return set;
19627 +}
19628 +
19629 +#ifdef CONFIG_PROPAGATE
19630 +
19631 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19632 +{
19633 +       tag_t new_tag = 0;
19634 +       struct vfsmount *mnt;
19635 +       int propagate;
19636 +
19637 +       if (!nd)
19638 +               return;
19639 +       mnt = nd->path.mnt;
19640 +       if (!mnt)
19641 +               return;
19642 +
19643 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19644 +       if (propagate)
19645 +               new_tag = mnt->mnt_tag;
19646 +
19647 +       vxdprintk(VXD_CBIT(tag, 7),
19648 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19649 +               inode, inode->i_ino, inode->i_tag,
19650 +               new_tag, (propagate) ? 1 : 0);
19651 +
19652 +       if (propagate)
19653 +               i_tag_write(inode, new_tag);
19654 +}
19655 +
19656 +#include <linux/module.h>
19657 +
19658 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19659 +
19660 +#endif /* CONFIG_PROPAGATE */
19661 +
19662 diff -NurpP --minimal linux-3.7.1/kernel/vserver/limit.c linux-3.7.1-vs2.3.5.5/kernel/vserver/limit.c
19663 --- linux-3.7.1/kernel/vserver/limit.c  1970-01-01 00:00:00.000000000 +0000
19664 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/limit.c        2012-12-18 15:13:16.000000000 +0000
19665 @@ -0,0 +1,345 @@
19666 +/*
19667 + *  linux/kernel/vserver/limit.c
19668 + *
19669 + *  Virtual Server: Context Limits
19670 + *
19671 + *  Copyright (C) 2004-2010  Herbert Pötzl
19672 + *
19673 + *  V0.01  broken out from vcontext V0.05
19674 + *  V0.02  changed vcmds to vxi arg
19675 + *  V0.03  added memory cgroup support
19676 + *
19677 + */
19678 +
19679 +#include <linux/sched.h>
19680 +#include <linux/module.h>
19681 +#include <linux/memcontrol.h>
19682 +#include <linux/res_counter.h>
19683 +#include <linux/vs_limit.h>
19684 +#include <linux/vserver/limit.h>
19685 +#include <linux/vserver/limit_cmd.h>
19686 +
19687 +#include <asm/uaccess.h>
19688 +
19689 +
19690 +const char *vlimit_name[NUM_LIMITS] = {
19691 +       [RLIMIT_CPU]            = "CPU",
19692 +       [RLIMIT_NPROC]          = "NPROC",
19693 +       [RLIMIT_NOFILE]         = "NOFILE",
19694 +       [RLIMIT_LOCKS]          = "LOCKS",
19695 +       [RLIMIT_SIGPENDING]     = "SIGP",
19696 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19697 +
19698 +       [VLIMIT_NSOCK]          = "NSOCK",
19699 +       [VLIMIT_OPENFD]         = "OPENFD",
19700 +       [VLIMIT_SHMEM]          = "SHMEM",
19701 +       [VLIMIT_DENTRY]         = "DENTRY",
19702 +};
19703 +
19704 +EXPORT_SYMBOL_GPL(vlimit_name);
19705 +
19706 +#define MASK_ENTRY(x)  (1 << (x))
19707 +
19708 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19709 +               /* minimum */
19710 +       0
19711 +       ,       /* softlimit */
19712 +       0
19713 +       ,       /* maximum */
19714 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19715 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19716 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19717 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19718 +
19719 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19720 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19721 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19722 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19723 +       0
19724 +};
19725 +               /* accounting only */
19726 +uint32_t account_mask =
19727 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19728 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19729 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19730 +       0;
19731 +
19732 +
19733 +static int is_valid_vlimit(int id)
19734 +{
19735 +       uint32_t mask = vlimit_mask.minimum |
19736 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19737 +       return mask & (1 << id);
19738 +}
19739 +
19740 +static int is_accounted_vlimit(int id)
19741 +{
19742 +       if (is_valid_vlimit(id))
19743 +               return 1;
19744 +       return account_mask & (1 << id);
19745 +}
19746 +
19747 +
19748 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19749 +{
19750 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19751 +       return VX_VLIM(limit);
19752 +}
19753 +
19754 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19755 +{
19756 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19757 +       return VX_VLIM(limit);
19758 +}
19759 +
19760 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19761 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19762 +{
19763 +       if (!is_valid_vlimit(id))
19764 +               return -EINVAL;
19765 +
19766 +       if (minimum)
19767 +               *minimum = CRLIM_UNSET;
19768 +       if (softlimit)
19769 +               *softlimit = vc_get_soft(vxi, id);
19770 +       if (maximum)
19771 +               *maximum = vc_get_hard(vxi, id);
19772 +       return 0;
19773 +}
19774 +
19775 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19776 +{
19777 +       struct vcmd_ctx_rlimit_v0 vc_data;
19778 +       int ret;
19779 +
19780 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19781 +               return -EFAULT;
19782 +
19783 +       ret = do_get_rlimit(vxi, vc_data.id,
19784 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19785 +       if (ret)
19786 +               return ret;
19787 +
19788 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19789 +               return -EFAULT;
19790 +       return 0;
19791 +}
19792 +
19793 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19794 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19795 +{
19796 +       if (!is_valid_vlimit(id))
19797 +               return -EINVAL;
19798 +
19799 +       if (maximum != CRLIM_KEEP)
19800 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19801 +       if (softlimit != CRLIM_KEEP)
19802 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19803 +
19804 +       /* clamp soft limit */
19805 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19806 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19807 +
19808 +       return 0;
19809 +}
19810 +
19811 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19812 +{
19813 +       struct vcmd_ctx_rlimit_v0 vc_data;
19814 +
19815 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19816 +               return -EFAULT;
19817 +
19818 +       return do_set_rlimit(vxi, vc_data.id,
19819 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19820 +}
19821 +
19822 +#ifdef CONFIG_IA32_EMULATION
19823 +
19824 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19825 +{
19826 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19827 +
19828 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19829 +               return -EFAULT;
19830 +
19831 +       return do_set_rlimit(vxi, vc_data.id,
19832 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19833 +}
19834 +
19835 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19836 +{
19837 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19838 +       int ret;
19839 +
19840 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19841 +               return -EFAULT;
19842 +
19843 +       ret = do_get_rlimit(vxi, vc_data.id,
19844 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19845 +       if (ret)
19846 +               return ret;
19847 +
19848 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19849 +               return -EFAULT;
19850 +       return 0;
19851 +}
19852 +
19853 +#endif /* CONFIG_IA32_EMULATION */
19854 +
19855 +
19856 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19857 +{
19858 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19859 +               return -EFAULT;
19860 +       return 0;
19861 +}
19862 +
19863 +
19864 +static inline void vx_reset_hits(struct _vx_limit *limit)
19865 +{
19866 +       int lim;
19867 +
19868 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19869 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19870 +       }
19871 +}
19872 +
19873 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19874 +{
19875 +       vx_reset_hits(&vxi->limit);
19876 +       return 0;
19877 +}
19878 +
19879 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19880 +{
19881 +       rlim_t value;
19882 +       int lim;
19883 +
19884 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19885 +               value = __rlim_get(limit, lim);
19886 +               __rlim_rmax(limit, lim) = value;
19887 +               __rlim_rmin(limit, lim) = value;
19888 +       }
19889 +}
19890 +
19891 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19892 +{
19893 +       vx_reset_minmax(&vxi->limit);
19894 +       return 0;
19895 +}
19896 +
19897 +
19898 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19899 +{
19900 +       struct vcmd_rlimit_stat_v0 vc_data;
19901 +       struct _vx_limit *limit = &vxi->limit;
19902 +       int id;
19903 +
19904 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19905 +               return -EFAULT;
19906 +
19907 +       id = vc_data.id;
19908 +       if (!is_accounted_vlimit(id))
19909 +               return -EINVAL;
19910 +
19911 +       vx_limit_fixup(limit, id);
19912 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19913 +       vc_data.value = __rlim_get(limit, id);
19914 +       vc_data.minimum = __rlim_rmin(limit, id);
19915 +       vc_data.maximum = __rlim_rmax(limit, id);
19916 +
19917 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19918 +               return -EFAULT;
19919 +       return 0;
19920 +}
19921 +
19922 +
19923 +void vx_vsi_meminfo(struct sysinfo *val)
19924 +{
19925 +#ifdef CONFIG_MEMCG
19926 +       struct mem_cgroup *mcg;
19927 +       u64 res_limit, res_usage;
19928 +
19929 +       rcu_read_lock();
19930 +       mcg = mem_cgroup_from_task(current);
19931 +       rcu_read_unlock();
19932 +       if (!mcg)
19933 +               goto out;
19934 +
19935 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19936 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19937 +
19938 +       if (res_limit != RESOURCE_MAX)
19939 +               val->totalram = (res_limit >> PAGE_SHIFT);
19940 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19941 +       val->bufferram = 0;
19942 +       val->totalhigh = 0;
19943 +       val->freehigh = 0;
19944 +out:
19945 +#endif /* CONFIG_MEMCG */
19946 +       return;
19947 +}
19948 +
19949 +void vx_vsi_swapinfo(struct sysinfo *val)
19950 +{
19951 +#ifdef CONFIG_MEMCG
19952 +#ifdef CONFIG_MEMCG_SWAP
19953 +       struct mem_cgroup *mcg;
19954 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19955 +       s64 swap_limit, swap_usage;
19956 +
19957 +       rcu_read_lock();
19958 +       mcg = mem_cgroup_from_task(current);
19959 +       rcu_read_unlock();
19960 +       if (!mcg)
19961 +               goto out;
19962 +
19963 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19964 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19965 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19966 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19967 +
19968 +       /* memory unlimited */
19969 +       if (res_limit == RESOURCE_MAX)
19970 +               goto out;
19971 +
19972 +       swap_limit = memsw_limit - res_limit;
19973 +       /* we have a swap limit? */
19974 +       if (memsw_limit != RESOURCE_MAX)
19975 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19976 +
19977 +       /* calculate swap part */
19978 +       swap_usage = (memsw_usage > res_usage) ?
19979 +               memsw_usage - res_usage : 0;
19980 +
19981 +       /* total shown minus usage gives free swap */
19982 +       val->freeswap = (swap_usage < swap_limit) ?
19983 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19984 +out:
19985 +#else  /* !CONFIG_MEMCG_SWAP */
19986 +       val->totalswap = 0;
19987 +       val->freeswap = 0;
19988 +#endif /* !CONFIG_MEMCG_SWAP */
19989 +#endif /* CONFIG_MEMCG */
19990 +       return;
19991 +}
19992 +
19993 +long vx_vsi_cached(struct sysinfo *val)
19994 +{
19995 +       long cache = 0;
19996 +#ifdef CONFIG_MEMCG
19997 +       struct mem_cgroup *mcg;
19998 +
19999 +       rcu_read_lock();
20000 +       mcg = mem_cgroup_from_task(current);
20001 +       rcu_read_unlock();
20002 +       if (!mcg)
20003 +               goto out;
20004 +
20005 +       cache = mem_cgroup_stat_read_cache(mcg);
20006 +out:
20007 +#endif
20008 +       return cache;
20009 +}
20010 +
20011 diff -NurpP --minimal linux-3.7.1/kernel/vserver/limit_init.h linux-3.7.1-vs2.3.5.5/kernel/vserver/limit_init.h
20012 --- linux-3.7.1/kernel/vserver/limit_init.h     1970-01-01 00:00:00.000000000 +0000
20013 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/limit_init.h   2012-12-18 15:13:16.000000000 +0000
20014 @@ -0,0 +1,31 @@
20015 +
20016 +
20017 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20018 +{
20019 +       int lim;
20020 +
20021 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20022 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20023 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20024 +               __rlim_set(limit, lim, 0);
20025 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20026 +               __rlim_rmin(limit, lim) = 0;
20027 +               __rlim_rmax(limit, lim) = 0;
20028 +       }
20029 +}
20030 +
20031 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20032 +{
20033 +       rlim_t value;
20034 +       int lim;
20035 +
20036 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20037 +               if ((1 << lim) & VLIM_NOCHECK)
20038 +                       continue;
20039 +               value = __rlim_get(limit, lim);
20040 +               vxwprintk_xid(value,
20041 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20042 +                       limit, vlimit_name[lim], lim, (long)value);
20043 +       }
20044 +}
20045 +
20046 diff -NurpP --minimal linux-3.7.1/kernel/vserver/limit_proc.h linux-3.7.1-vs2.3.5.5/kernel/vserver/limit_proc.h
20047 --- linux-3.7.1/kernel/vserver/limit_proc.h     1970-01-01 00:00:00.000000000 +0000
20048 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/limit_proc.h   2012-12-18 15:13:16.000000000 +0000
20049 @@ -0,0 +1,57 @@
20050 +#ifndef _VX_LIMIT_PROC_H
20051 +#define _VX_LIMIT_PROC_H
20052 +
20053 +#include <linux/vserver/limit_int.h>
20054 +
20055 +
20056 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20057 +#define VX_LIMIT_TOP   \
20058 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20059 +
20060 +#define VX_LIMIT_ARG(r)                                \
20061 +       (unsigned long)__rlim_get(limit, r),    \
20062 +       (unsigned long)__rlim_rmin(limit, r),   \
20063 +       (unsigned long)__rlim_rmax(limit, r),   \
20064 +       VX_VLIM(__rlim_soft(limit, r)),         \
20065 +       VX_VLIM(__rlim_hard(limit, r)),         \
20066 +       atomic_read(&__rlim_lhit(limit, r))
20067 +
20068 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20069 +{
20070 +       vx_limit_fixup(limit, -1);
20071 +       return sprintf(buffer, VX_LIMIT_TOP
20072 +               "PROC"  VX_LIMIT_FMT
20073 +               "VM"    VX_LIMIT_FMT
20074 +               "VML"   VX_LIMIT_FMT
20075 +               "RSS"   VX_LIMIT_FMT
20076 +               "ANON"  VX_LIMIT_FMT
20077 +               "RMAP"  VX_LIMIT_FMT
20078 +               "FILES" VX_LIMIT_FMT
20079 +               "OFD"   VX_LIMIT_FMT
20080 +               "LOCKS" VX_LIMIT_FMT
20081 +               "SOCK"  VX_LIMIT_FMT
20082 +               "MSGQ"  VX_LIMIT_FMT
20083 +               "SHM"   VX_LIMIT_FMT
20084 +               "SEMA"  VX_LIMIT_FMT
20085 +               "SEMS"  VX_LIMIT_FMT
20086 +               "DENT"  VX_LIMIT_FMT,
20087 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20088 +               VX_LIMIT_ARG(RLIMIT_AS),
20089 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20090 +               VX_LIMIT_ARG(RLIMIT_RSS),
20091 +               VX_LIMIT_ARG(VLIMIT_ANON),
20092 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20093 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20094 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20095 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20096 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20097 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20098 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20099 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20100 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20101 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20102 +}
20103 +
20104 +#endif /* _VX_LIMIT_PROC_H */
20105 +
20106 +
20107 diff -NurpP --minimal linux-3.7.1/kernel/vserver/network.c linux-3.7.1-vs2.3.5.5/kernel/vserver/network.c
20108 --- linux-3.7.1/kernel/vserver/network.c        1970-01-01 00:00:00.000000000 +0000
20109 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/network.c      2013-01-04 23:27:50.000000000 +0000
20110 @@ -0,0 +1,1053 @@
20111 +/*
20112 + *  linux/kernel/vserver/network.c
20113 + *
20114 + *  Virtual Server: Network Support
20115 + *
20116 + *  Copyright (C) 2003-2007  Herbert Pötzl
20117 + *
20118 + *  V0.01  broken out from vcontext V0.05
20119 + *  V0.02  cleaned up implementation
20120 + *  V0.03  added equiv nx commands
20121 + *  V0.04  switch to RCU based hash
20122 + *  V0.05  and back to locking again
20123 + *  V0.06  changed vcmds to nxi arg
20124 + *  V0.07  have __create claim() the nxi
20125 + *
20126 + */
20127 +
20128 +#include <linux/err.h>
20129 +#include <linux/slab.h>
20130 +#include <linux/rcupdate.h>
20131 +#include <net/ipv6.h>
20132 +
20133 +#include <linux/vs_network.h>
20134 +#include <linux/vs_pid.h>
20135 +#include <linux/vserver/network_cmd.h>
20136 +
20137 +
20138 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20139 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20140 +
20141 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20142 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20143 +
20144 +
20145 +static int __init init_network(void)
20146 +{
20147 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20148 +               sizeof(struct nx_addr_v4), 0,
20149 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20150 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20151 +               sizeof(struct nx_addr_v6), 0,
20152 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20153 +       return 0;
20154 +}
20155 +
20156 +
20157 +/*     __alloc_nx_addr_v4()                                    */
20158 +
20159 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20160 +{
20161 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20162 +               nx_addr_v4_cachep, GFP_KERNEL);
20163 +
20164 +       if (!IS_ERR(nxa))
20165 +               memset(nxa, 0, sizeof(*nxa));
20166 +       return nxa;
20167 +}
20168 +
20169 +/*     __dealloc_nx_addr_v4()                                  */
20170 +
20171 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20172 +{
20173 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20174 +}
20175 +
20176 +/*     __dealloc_nx_addr_v4_all()                              */
20177 +
20178 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20179 +{
20180 +       while (nxa) {
20181 +               struct nx_addr_v4 *next = nxa->next;
20182 +
20183 +               __dealloc_nx_addr_v4(nxa);
20184 +               nxa = next;
20185 +       }
20186 +}
20187 +
20188 +
20189 +#ifdef CONFIG_IPV6
20190 +
20191 +/*     __alloc_nx_addr_v6()                                    */
20192 +
20193 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20194 +{
20195 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20196 +               nx_addr_v6_cachep, GFP_KERNEL);
20197 +
20198 +       if (!IS_ERR(nxa))
20199 +               memset(nxa, 0, sizeof(*nxa));
20200 +       return nxa;
20201 +}
20202 +
20203 +/*     __dealloc_nx_addr_v6()                                  */
20204 +
20205 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20206 +{
20207 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20208 +}
20209 +
20210 +/*     __dealloc_nx_addr_v6_all()                              */
20211 +
20212 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20213 +{
20214 +       while (nxa) {
20215 +               struct nx_addr_v6 *next = nxa->next;
20216 +
20217 +               __dealloc_nx_addr_v6(nxa);
20218 +               nxa = next;
20219 +       }
20220 +}
20221 +
20222 +#endif /* CONFIG_IPV6 */
20223 +
20224 +/*     __alloc_nx_info()
20225 +
20226 +       * allocate an initialized nx_info struct
20227 +       * doesn't make it visible (hash)                        */
20228 +
20229 +static struct nx_info *__alloc_nx_info(nid_t nid)
20230 +{
20231 +       struct nx_info *new = NULL;
20232 +
20233 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20234 +
20235 +       /* would this benefit from a slab cache? */
20236 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20237 +       if (!new)
20238 +               return 0;
20239 +
20240 +       memset(new, 0, sizeof(struct nx_info));
20241 +       new->nx_id = nid;
20242 +       INIT_HLIST_NODE(&new->nx_hlist);
20243 +       atomic_set(&new->nx_usecnt, 0);
20244 +       atomic_set(&new->nx_tasks, 0);
20245 +       spin_lock_init(&new->addr_lock);
20246 +       new->nx_state = 0;
20247 +
20248 +       new->nx_flags = NXF_INIT_SET;
20249 +
20250 +       /* rest of init goes here */
20251 +
20252 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20253 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20254 +
20255 +       vxdprintk(VXD_CBIT(nid, 0),
20256 +               "alloc_nx_info(%d) = %p", nid, new);
20257 +       atomic_inc(&nx_global_ctotal);
20258 +       return new;
20259 +}
20260 +
20261 +/*     __dealloc_nx_info()
20262 +
20263 +       * final disposal of nx_info                             */
20264 +
20265 +static void __dealloc_nx_info(struct nx_info *nxi)
20266 +{
20267 +       vxdprintk(VXD_CBIT(nid, 0),
20268 +               "dealloc_nx_info(%p)", nxi);
20269 +
20270 +       nxi->nx_hlist.next = LIST_POISON1;
20271 +       nxi->nx_id = -1;
20272 +
20273 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20274 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20275 +
20276 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20277 +#ifdef CONFIG_IPV6
20278 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20279 +#endif
20280 +
20281 +       nxi->nx_state |= NXS_RELEASED;
20282 +       kfree(nxi);
20283 +       atomic_dec(&nx_global_ctotal);
20284 +}
20285 +
20286 +static void __shutdown_nx_info(struct nx_info *nxi)
20287 +{
20288 +       nxi->nx_state |= NXS_SHUTDOWN;
20289 +       vs_net_change(nxi, VSC_NETDOWN);
20290 +}
20291 +
20292 +/*     exported stuff                                          */
20293 +
20294 +void free_nx_info(struct nx_info *nxi)
20295 +{
20296 +       /* context shutdown is mandatory */
20297 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20298 +
20299 +       /* context must not be hashed */
20300 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20301 +
20302 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20303 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20304 +
20305 +       __dealloc_nx_info(nxi);
20306 +}
20307 +
20308 +
20309 +void __nx_set_lback(struct nx_info *nxi)
20310 +{
20311 +       int nid = nxi->nx_id;
20312 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20313 +
20314 +       nxi->v4_lback.s_addr = lback;
20315 +}
20316 +
20317 +extern int __nx_inet_add_lback(__be32 addr);
20318 +extern int __nx_inet_del_lback(__be32 addr);
20319 +
20320 +
20321 +/*     hash table for nx_info hash */
20322 +
20323 +#define NX_HASH_SIZE   13
20324 +
20325 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20326 +
20327 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20328 +
20329 +
20330 +static inline unsigned int __hashval(nid_t nid)
20331 +{
20332 +       return (nid % NX_HASH_SIZE);
20333 +}
20334 +
20335 +
20336 +
20337 +/*     __hash_nx_info()
20338 +
20339 +       * add the nxi to the global hash table
20340 +       * requires the hash_lock to be held                     */
20341 +
20342 +static inline void __hash_nx_info(struct nx_info *nxi)
20343 +{
20344 +       struct hlist_head *head;
20345 +
20346 +       vxd_assert_lock(&nx_info_hash_lock);
20347 +       vxdprintk(VXD_CBIT(nid, 4),
20348 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20349 +
20350 +       /* context must not be hashed */
20351 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20352 +
20353 +       nxi->nx_state |= NXS_HASHED;
20354 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20355 +       hlist_add_head(&nxi->nx_hlist, head);
20356 +       atomic_inc(&nx_global_cactive);
20357 +}
20358 +
20359 +/*     __unhash_nx_info()
20360 +
20361 +       * remove the nxi from the global hash table
20362 +       * requires the hash_lock to be held                     */
20363 +
20364 +static inline void __unhash_nx_info(struct nx_info *nxi)
20365 +{
20366 +       vxd_assert_lock(&nx_info_hash_lock);
20367 +       vxdprintk(VXD_CBIT(nid, 4),
20368 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20369 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20370 +
20371 +       /* context must be hashed */
20372 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20373 +       /* but without tasks */
20374 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20375 +
20376 +       nxi->nx_state &= ~NXS_HASHED;
20377 +       hlist_del(&nxi->nx_hlist);
20378 +       atomic_dec(&nx_global_cactive);
20379 +}
20380 +
20381 +
20382 +/*     __lookup_nx_info()
20383 +
20384 +       * requires the hash_lock to be held
20385 +       * doesn't increment the nx_refcnt                       */
20386 +
20387 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20388 +{
20389 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20390 +       struct hlist_node *pos;
20391 +       struct nx_info *nxi;
20392 +
20393 +       vxd_assert_lock(&nx_info_hash_lock);
20394 +       hlist_for_each(pos, head) {
20395 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20396 +
20397 +               if (nxi->nx_id == nid)
20398 +                       goto found;
20399 +       }
20400 +       nxi = NULL;
20401 +found:
20402 +       vxdprintk(VXD_CBIT(nid, 0),
20403 +               "__lookup_nx_info(#%u): %p[#%u]",
20404 +               nid, nxi, nxi ? nxi->nx_id : 0);
20405 +       return nxi;
20406 +}
20407 +
20408 +
20409 +/*     __create_nx_info()
20410 +
20411 +       * create the requested context
20412 +       * get(), claim() and hash it                            */
20413 +
20414 +static struct nx_info *__create_nx_info(int id)
20415 +{
20416 +       struct nx_info *new, *nxi = NULL;
20417 +
20418 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20419 +
20420 +       if (!(new = __alloc_nx_info(id)))
20421 +               return ERR_PTR(-ENOMEM);
20422 +
20423 +       /* required to make dynamic xids unique */
20424 +       spin_lock(&nx_info_hash_lock);
20425 +
20426 +       /* static context requested */
20427 +       if ((nxi = __lookup_nx_info(id))) {
20428 +               vxdprintk(VXD_CBIT(nid, 0),
20429 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20430 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20431 +                       nxi = ERR_PTR(-EBUSY);
20432 +               else
20433 +                       nxi = ERR_PTR(-EEXIST);
20434 +               goto out_unlock;
20435 +       }
20436 +       /* new context */
20437 +       vxdprintk(VXD_CBIT(nid, 0),
20438 +               "create_nx_info(%d) = %p (new)", id, new);
20439 +       claim_nx_info(new, NULL);
20440 +       __nx_set_lback(new);
20441 +       __hash_nx_info(get_nx_info(new));
20442 +       nxi = new, new = NULL;
20443 +
20444 +out_unlock:
20445 +       spin_unlock(&nx_info_hash_lock);
20446 +       if (new)
20447 +               __dealloc_nx_info(new);
20448 +       return nxi;
20449 +}
20450 +
20451 +
20452 +
20453 +/*     exported stuff                                          */
20454 +
20455 +
20456 +void unhash_nx_info(struct nx_info *nxi)
20457 +{
20458 +       __shutdown_nx_info(nxi);
20459 +       spin_lock(&nx_info_hash_lock);
20460 +       __unhash_nx_info(nxi);
20461 +       spin_unlock(&nx_info_hash_lock);
20462 +}
20463 +
20464 +/*     lookup_nx_info()
20465 +
20466 +       * search for a nx_info and get() it
20467 +       * negative id means current                             */
20468 +
20469 +struct nx_info *lookup_nx_info(int id)
20470 +{
20471 +       struct nx_info *nxi = NULL;
20472 +
20473 +       if (id < 0) {
20474 +               nxi = get_nx_info(current_nx_info());
20475 +       } else if (id > 1) {
20476 +               spin_lock(&nx_info_hash_lock);
20477 +               nxi = get_nx_info(__lookup_nx_info(id));
20478 +               spin_unlock(&nx_info_hash_lock);
20479 +       }
20480 +       return nxi;
20481 +}
20482 +
20483 +/*     nid_is_hashed()
20484 +
20485 +       * verify that nid is still hashed                       */
20486 +
20487 +int nid_is_hashed(nid_t nid)
20488 +{
20489 +       int hashed;
20490 +
20491 +       spin_lock(&nx_info_hash_lock);
20492 +       hashed = (__lookup_nx_info(nid) != NULL);
20493 +       spin_unlock(&nx_info_hash_lock);
20494 +       return hashed;
20495 +}
20496 +
20497 +
20498 +#ifdef CONFIG_PROC_FS
20499 +
20500 +/*     get_nid_list()
20501 +
20502 +       * get a subset of hashed nids for proc
20503 +       * assumes size is at least one                          */
20504 +
20505 +int get_nid_list(int index, unsigned int *nids, int size)
20506 +{
20507 +       int hindex, nr_nids = 0;
20508 +
20509 +       /* only show current and children */
20510 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20511 +               if (index > 0)
20512 +                       return 0;
20513 +               nids[nr_nids] = nx_current_nid();
20514 +               return 1;
20515 +       }
20516 +
20517 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20518 +               struct hlist_head *head = &nx_info_hash[hindex];
20519 +               struct hlist_node *pos;
20520 +
20521 +               spin_lock(&nx_info_hash_lock);
20522 +               hlist_for_each(pos, head) {
20523 +                       struct nx_info *nxi;
20524 +
20525 +                       if (--index > 0)
20526 +                               continue;
20527 +
20528 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20529 +                       nids[nr_nids] = nxi->nx_id;
20530 +                       if (++nr_nids >= size) {
20531 +                               spin_unlock(&nx_info_hash_lock);
20532 +                               goto out;
20533 +                       }
20534 +               }
20535 +               /* keep the lock time short */
20536 +               spin_unlock(&nx_info_hash_lock);
20537 +       }
20538 +out:
20539 +       return nr_nids;
20540 +}
20541 +#endif
20542 +
20543 +
20544 +/*
20545 + *     migrate task to new network
20546 + *     gets nxi, puts old_nxi on change
20547 + */
20548 +
20549 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20550 +{
20551 +       struct nx_info *old_nxi;
20552 +       int ret = 0;
20553 +
20554 +       if (!p || !nxi)
20555 +               BUG();
20556 +
20557 +       vxdprintk(VXD_CBIT(nid, 5),
20558 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20559 +               p, nxi, nxi->nx_id,
20560 +               atomic_read(&nxi->nx_usecnt),
20561 +               atomic_read(&nxi->nx_tasks));
20562 +
20563 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20564 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20565 +               return -EACCES;
20566 +
20567 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20568 +               return -EFAULT;
20569 +
20570 +       /* maybe disallow this completely? */
20571 +       old_nxi = task_get_nx_info(p);
20572 +       if (old_nxi == nxi)
20573 +               goto out;
20574 +
20575 +       task_lock(p);
20576 +       if (old_nxi)
20577 +               clr_nx_info(&p->nx_info);
20578 +       claim_nx_info(nxi, p);
20579 +       set_nx_info(&p->nx_info, nxi);
20580 +       p->nid = nxi->nx_id;
20581 +       task_unlock(p);
20582 +
20583 +       vxdprintk(VXD_CBIT(nid, 5),
20584 +               "moved task %p into nxi:%p[#%d]",
20585 +               p, nxi, nxi->nx_id);
20586 +
20587 +       if (old_nxi)
20588 +               release_nx_info(old_nxi, p);
20589 +       ret = 0;
20590 +out:
20591 +       put_nx_info(old_nxi);
20592 +       return ret;
20593 +}
20594 +
20595 +
20596 +void nx_set_persistent(struct nx_info *nxi)
20597 +{
20598 +       vxdprintk(VXD_CBIT(nid, 6),
20599 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20600 +
20601 +       get_nx_info(nxi);
20602 +       claim_nx_info(nxi, NULL);
20603 +}
20604 +
20605 +void nx_clear_persistent(struct nx_info *nxi)
20606 +{
20607 +       vxdprintk(VXD_CBIT(nid, 6),
20608 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20609 +
20610 +       release_nx_info(nxi, NULL);
20611 +       put_nx_info(nxi);
20612 +}
20613 +
20614 +void nx_update_persistent(struct nx_info *nxi)
20615 +{
20616 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20617 +               nx_set_persistent(nxi);
20618 +       else
20619 +               nx_clear_persistent(nxi);
20620 +}
20621 +
20622 +/* vserver syscall commands below here */
20623 +
20624 +/* taks nid and nx_info functions */
20625 +
20626 +#include <asm/uaccess.h>
20627 +
20628 +
20629 +int vc_task_nid(uint32_t id)
20630 +{
20631 +       nid_t nid;
20632 +
20633 +       if (id) {
20634 +               struct task_struct *tsk;
20635 +
20636 +               rcu_read_lock();
20637 +               tsk = find_task_by_real_pid(id);
20638 +               nid = (tsk) ? tsk->nid : -ESRCH;
20639 +               rcu_read_unlock();
20640 +       } else
20641 +               nid = nx_current_nid();
20642 +       return nid;
20643 +}
20644 +
20645 +
20646 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20647 +{
20648 +       struct vcmd_nx_info_v0 vc_data;
20649 +
20650 +       vc_data.nid = nxi->nx_id;
20651 +
20652 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20653 +               return -EFAULT;
20654 +       return 0;
20655 +}
20656 +
20657 +
20658 +/* network functions */
20659 +
20660 +int vc_net_create(uint32_t nid, void __user *data)
20661 +{
20662 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20663 +       struct nx_info *new_nxi;
20664 +       int ret;
20665 +
20666 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20667 +               return -EFAULT;
20668 +
20669 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20670 +               return -EINVAL;
20671 +
20672 +       new_nxi = __create_nx_info(nid);
20673 +       if (IS_ERR(new_nxi))
20674 +               return PTR_ERR(new_nxi);
20675 +
20676 +       /* initial flags */
20677 +       new_nxi->nx_flags = vc_data.flagword;
20678 +
20679 +       ret = -ENOEXEC;
20680 +       if (vs_net_change(new_nxi, VSC_NETUP))
20681 +               goto out;
20682 +
20683 +       ret = nx_migrate_task(current, new_nxi);
20684 +       if (ret)
20685 +               goto out;
20686 +
20687 +       /* return context id on success */
20688 +       ret = new_nxi->nx_id;
20689 +
20690 +       /* get a reference for persistent contexts */
20691 +       if ((vc_data.flagword & NXF_PERSISTENT))
20692 +               nx_set_persistent(new_nxi);
20693 +out:
20694 +       release_nx_info(new_nxi, NULL);
20695 +       put_nx_info(new_nxi);
20696 +       return ret;
20697 +}
20698 +
20699 +
20700 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20701 +{
20702 +       return nx_migrate_task(current, nxi);
20703 +}
20704 +
20705 +
20706 +static inline
20707 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20708 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20709 +       struct nx_addr_v4 **prev)
20710 +{
20711 +       struct nx_addr_v4 *nxa = &nxi->v4;
20712 +
20713 +       for (; nxa; nxa = nxa->next) {
20714 +               if ((nxa->ip[0].s_addr == ip) &&
20715 +                   (nxa->ip[1].s_addr == ip2) &&
20716 +                   (nxa->mask.s_addr == mask) &&
20717 +                   (nxa->type == type) &&
20718 +                   (nxa->flags == flags))
20719 +                   return nxa;
20720 +
20721 +               /* save previous entry */
20722 +               if (prev)
20723 +                       *prev = nxa;
20724 +       }
20725 +       return NULL;
20726 +}
20727 +
20728 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20729 +       uint16_t type, uint16_t flags)
20730 +{
20731 +       struct nx_addr_v4 *nxa = NULL;
20732 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20733 +       unsigned long irqflags;
20734 +       int ret = -EEXIST;
20735 +
20736 +       if (IS_ERR(new))
20737 +               return PTR_ERR(new);
20738 +
20739 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20740 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20741 +               goto out_unlock;
20742 +
20743 +       if (NX_IPV4(nxi)) {
20744 +               nxa->next = new;
20745 +               nxa = new;
20746 +               new = NULL;
20747 +
20748 +               /* remove single ip for ip list */
20749 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20750 +       }
20751 +
20752 +       nxa->ip[0].s_addr = ip;
20753 +       nxa->ip[1].s_addr = ip2;
20754 +       nxa->mask.s_addr = mask;
20755 +       nxa->type = type;
20756 +       nxa->flags = flags;
20757 +       ret = 0;
20758 +out_unlock:
20759 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20760 +       if (new)
20761 +               __dealloc_nx_addr_v4(new);
20762 +       return ret;
20763 +}
20764 +
20765 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20766 +       uint16_t type, uint16_t flags)
20767 +{
20768 +       struct nx_addr_v4 *nxa = NULL;
20769 +       struct nx_addr_v4 *old = NULL;
20770 +       unsigned long irqflags;
20771 +       int ret = 0;
20772 +
20773 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20774 +       switch (type) {
20775 +       case NXA_TYPE_ADDR:
20776 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20777 +               if (old) {
20778 +                       if (nxa) {
20779 +                               nxa->next = old->next;
20780 +                               old->next = NULL;
20781 +                       } else {
20782 +                               if (old->next) {
20783 +                                       nxa = old;
20784 +                                       old = old->next;
20785 +                                       *nxa = *old;
20786 +                                       old->next = NULL;
20787 +                               } else {
20788 +                                       memset(old, 0, sizeof(*old));
20789 +                                       old = NULL;
20790 +                               }
20791 +                       }
20792 +               } else
20793 +                       ret = -ESRCH;
20794 +               break;
20795 +
20796 +       case NXA_TYPE_ANY:
20797 +               nxa = &nxi->v4;
20798 +               old = nxa->next;
20799 +               memset(nxa, 0, sizeof(*nxa));
20800 +               break;
20801 +
20802 +       default:
20803 +               ret = -EINVAL;
20804 +       }
20805 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20806 +       __dealloc_nx_addr_v4_all(old);
20807 +       return ret;
20808 +}
20809 +
20810 +
20811 +int vc_net_add(struct nx_info *nxi, void __user *data)
20812 +{
20813 +       struct vcmd_net_addr_v0 vc_data;
20814 +       int index, ret = 0;
20815 +
20816 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20817 +               return -EFAULT;
20818 +
20819 +       switch (vc_data.type) {
20820 +       case NXA_TYPE_IPV4:
20821 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20822 +                       return -EINVAL;
20823 +
20824 +               index = 0;
20825 +               while (index < vc_data.count) {
20826 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20827 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20828 +                       if (ret)
20829 +                               return ret;
20830 +                       index++;
20831 +               }
20832 +               ret = index;
20833 +               break;
20834 +
20835 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20836 +               nxi->v4_bcast = vc_data.ip[0];
20837 +               ret = 1;
20838 +               break;
20839 +
20840 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20841 +               nxi->v4_lback = vc_data.ip[0];
20842 +               ret = 1;
20843 +               break;
20844 +
20845 +       default:
20846 +               ret = -EINVAL;
20847 +               break;
20848 +       }
20849 +       return ret;
20850 +}
20851 +
20852 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20853 +{
20854 +       struct vcmd_net_addr_v0 vc_data;
20855 +
20856 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20857 +               return -EFAULT;
20858 +
20859 +       switch (vc_data.type) {
20860 +       case NXA_TYPE_ANY:
20861 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20862 +       default:
20863 +               return -EINVAL;
20864 +       }
20865 +       return 0;
20866 +}
20867 +
20868 +
20869 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20870 +{
20871 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20872 +
20873 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20874 +               return -EFAULT;
20875 +
20876 +       switch (vc_data.type) {
20877 +       case NXA_TYPE_ADDR:
20878 +       case NXA_TYPE_MASK:
20879 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20880 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20881 +
20882 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20883 +               nxi->v4_bcast = vc_data.ip;
20884 +               break;
20885 +
20886 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20887 +               nxi->v4_lback = vc_data.ip;
20888 +               break;
20889 +
20890 +       default:
20891 +               return -EINVAL;
20892 +       }
20893 +       return 0;
20894 +}
20895 +
20896 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20897 +{
20898 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20899 +
20900 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20901 +               return -EFAULT;
20902 +
20903 +       switch (vc_data.type) {
20904 +       case NXA_TYPE_ADDR:
20905 +       case NXA_TYPE_MASK:
20906 +       case NXA_TYPE_RANGE:
20907 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20908 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20909 +
20910 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20911 +               nxi->v4_bcast = vc_data.ip;
20912 +               break;
20913 +
20914 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20915 +               nxi->v4_lback = vc_data.ip;
20916 +               break;
20917 +
20918 +       default:
20919 +               return -EINVAL;
20920 +       }
20921 +       return 0;
20922 +}
20923 +
20924 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20925 +{
20926 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20927 +
20928 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20929 +               return -EFAULT;
20930 +
20931 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20932 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20933 +}
20934 +
20935 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20936 +{
20937 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20938 +
20939 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20940 +               return -EFAULT;
20941 +
20942 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20943 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20944 +}
20945 +
20946 +#ifdef CONFIG_IPV6
20947 +
20948 +static inline
20949 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20950 +       struct in6_addr *ip, struct in6_addr *mask,
20951 +       uint32_t prefix, uint16_t type, uint16_t flags,
20952 +       struct nx_addr_v6 **prev)
20953 +{
20954 +       struct nx_addr_v6 *nxa = &nxi->v6;
20955 +
20956 +       for (; nxa; nxa = nxa->next) {
20957 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20958 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20959 +                   (nxa->prefix == prefix) &&
20960 +                   (nxa->type == type) &&
20961 +                   (nxa->flags == flags))
20962 +                   return nxa;
20963 +
20964 +               /* save previous entry */
20965 +               if (prev)
20966 +                       *prev = nxa;
20967 +       }
20968 +       return NULL;
20969 +}
20970 +
20971 +
20972 +int do_add_v6_addr(struct nx_info *nxi,
20973 +       struct in6_addr *ip, struct in6_addr *mask,
20974 +       uint32_t prefix, uint16_t type, uint16_t flags)
20975 +{
20976 +       struct nx_addr_v6 *nxa = NULL;
20977 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20978 +       unsigned long irqflags;
20979 +       int ret = -EEXIST;
20980 +
20981 +       if (IS_ERR(new))
20982 +               return PTR_ERR(new);
20983 +
20984 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20985 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20986 +               goto out_unlock;
20987 +
20988 +       if (NX_IPV6(nxi)) {
20989 +               nxa->next = new;
20990 +               nxa = new;
20991 +               new = NULL;
20992 +       }
20993 +
20994 +       nxa->ip = *ip;
20995 +       nxa->mask = *mask;
20996 +       nxa->prefix = prefix;
20997 +       nxa->type = type;
20998 +       nxa->flags = flags;
20999 +       ret = 0;
21000 +out_unlock:
21001 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
21002 +       if (new)
21003 +               __dealloc_nx_addr_v6(new);
21004 +       return ret;
21005 +}
21006 +
21007 +int do_remove_v6_addr(struct nx_info *nxi,
21008 +       struct in6_addr *ip, struct in6_addr *mask,
21009 +       uint32_t prefix, uint16_t type, uint16_t flags)
21010 +{
21011 +       struct nx_addr_v6 *nxa = NULL;
21012 +       struct nx_addr_v6 *old = NULL;
21013 +       unsigned long irqflags;
21014 +       int ret = 0;
21015 +
21016 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
21017 +       switch (type) {
21018 +       case NXA_TYPE_ADDR:
21019 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
21020 +               if (old) {
21021 +                       if (nxa) {
21022 +                               nxa->next = old->next;
21023 +                               old->next = NULL;
21024 +                       } else {
21025 +                               if (old->next) {
21026 +                                       nxa = old;
21027 +                                       old = old->next;
21028 +                                       *nxa = *old;
21029 +                                       old->next = NULL;
21030 +                               } else {
21031 +                                       memset(old, 0, sizeof(*old));
21032 +                                       old = NULL;
21033 +                               }
21034 +                       }
21035 +               } else
21036 +                       ret = -ESRCH;
21037 +               break;
21038 +
21039 +       case NXA_TYPE_ANY:
21040 +               nxa = &nxi->v6;
21041 +               old = nxa->next;
21042 +               memset(nxa, 0, sizeof(*nxa));
21043 +               break;
21044 +
21045 +       default:
21046 +               ret = -EINVAL;
21047 +       }
21048 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
21049 +       __dealloc_nx_addr_v6_all(old);
21050 +       return ret;
21051 +}
21052 +
21053 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21054 +{
21055 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21056 +
21057 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21058 +               return -EFAULT;
21059 +
21060 +       switch (vc_data.type) {
21061 +       case NXA_TYPE_ADDR:
21062 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21063 +               /* fallthrough */
21064 +       case NXA_TYPE_MASK:
21065 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21066 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21067 +       default:
21068 +               return -EINVAL;
21069 +       }
21070 +       return 0;
21071 +}
21072 +
21073 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21074 +{
21075 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21076 +
21077 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21078 +               return -EFAULT;
21079 +
21080 +       switch (vc_data.type) {
21081 +       case NXA_TYPE_ADDR:
21082 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21083 +               /* fallthrough */
21084 +       case NXA_TYPE_MASK:
21085 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21086 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21087 +       case NXA_TYPE_ANY:
21088 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
21089 +       default:
21090 +               return -EINVAL;
21091 +       }
21092 +       return 0;
21093 +}
21094 +
21095 +#endif /* CONFIG_IPV6 */
21096 +
21097 +
21098 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21099 +{
21100 +       struct vcmd_net_flags_v0 vc_data;
21101 +
21102 +       vc_data.flagword = nxi->nx_flags;
21103 +
21104 +       /* special STATE flag handling */
21105 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21106 +
21107 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21108 +               return -EFAULT;
21109 +       return 0;
21110 +}
21111 +
21112 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21113 +{
21114 +       struct vcmd_net_flags_v0 vc_data;
21115 +       uint64_t mask, trigger;
21116 +
21117 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21118 +               return -EFAULT;
21119 +
21120 +       /* special STATE flag handling */
21121 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21122 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21123 +
21124 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21125 +               vc_data.flagword, mask);
21126 +       if (trigger & NXF_PERSISTENT)
21127 +               nx_update_persistent(nxi);
21128 +
21129 +       return 0;
21130 +}
21131 +
21132 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21133 +{
21134 +       struct vcmd_net_caps_v0 vc_data;
21135 +
21136 +       vc_data.ncaps = nxi->nx_ncaps;
21137 +       vc_data.cmask = ~0ULL;
21138 +
21139 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21140 +               return -EFAULT;
21141 +       return 0;
21142 +}
21143 +
21144 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21145 +{
21146 +       struct vcmd_net_caps_v0 vc_data;
21147 +
21148 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21149 +               return -EFAULT;
21150 +
21151 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21152 +               vc_data.ncaps, vc_data.cmask);
21153 +       return 0;
21154 +}
21155 +
21156 +
21157 +#include <linux/module.h>
21158 +
21159 +module_init(init_network);
21160 +
21161 +EXPORT_SYMBOL_GPL(free_nx_info);
21162 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21163 +
21164 diff -NurpP --minimal linux-3.7.1/kernel/vserver/proc.c linux-3.7.1-vs2.3.5.5/kernel/vserver/proc.c
21165 --- linux-3.7.1/kernel/vserver/proc.c   1970-01-01 00:00:00.000000000 +0000
21166 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/proc.c 2012-12-18 15:13:16.000000000 +0000
21167 @@ -0,0 +1,1110 @@
21168 +/*
21169 + *  linux/kernel/vserver/proc.c
21170 + *
21171 + *  Virtual Context Support
21172 + *
21173 + *  Copyright (C) 2003-2011  Herbert Pötzl
21174 + *
21175 + *  V0.01  basic structure
21176 + *  V0.02  adaptation vs1.3.0
21177 + *  V0.03  proc permissions
21178 + *  V0.04  locking/generic
21179 + *  V0.05  next generation procfs
21180 + *  V0.06  inode validation
21181 + *  V0.07  generic rewrite vid
21182 + *  V0.08  remove inode type
21183 + *  V0.09  added u/wmask info
21184 + *
21185 + */
21186 +
21187 +#include <linux/proc_fs.h>
21188 +#include <linux/fs_struct.h>
21189 +#include <linux/mount.h>
21190 +#include <linux/namei.h>
21191 +#include <asm/unistd.h>
21192 +
21193 +#include <linux/vs_context.h>
21194 +#include <linux/vs_network.h>
21195 +#include <linux/vs_cvirt.h>
21196 +
21197 +#include <linux/in.h>
21198 +#include <linux/inetdevice.h>
21199 +#include <linux/vs_inet.h>
21200 +#include <linux/vs_inet6.h>
21201 +
21202 +#include <linux/vserver/global.h>
21203 +
21204 +#include "cvirt_proc.h"
21205 +#include "cacct_proc.h"
21206 +#include "limit_proc.h"
21207 +#include "sched_proc.h"
21208 +#include "vci_config.h"
21209 +
21210 +
21211 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21212 +{
21213 +       unsigned __capi;
21214 +
21215 +       CAP_FOR_EACH_U32(__capi) {
21216 +               buffer += sprintf(buffer, "%08x",
21217 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21218 +       }
21219 +       return buffer;
21220 +}
21221 +
21222 +
21223 +static struct proc_dir_entry *proc_virtual;
21224 +
21225 +static struct proc_dir_entry *proc_virtnet;
21226 +
21227 +
21228 +/* first the actual feeds */
21229 +
21230 +
21231 +static int proc_vci(char *buffer)
21232 +{
21233 +       return sprintf(buffer,
21234 +               "VCIVersion:\t%04x:%04x\n"
21235 +               "VCISyscall:\t%d\n"
21236 +               "VCIKernel:\t%08x\n",
21237 +               VCI_VERSION >> 16,
21238 +               VCI_VERSION & 0xFFFF,
21239 +               __NR_vserver,
21240 +               vci_kernel_config());
21241 +}
21242 +
21243 +static int proc_virtual_info(char *buffer)
21244 +{
21245 +       return proc_vci(buffer);
21246 +}
21247 +
21248 +static int proc_virtual_status(char *buffer)
21249 +{
21250 +       return sprintf(buffer,
21251 +               "#CTotal:\t%d\n"
21252 +               "#CActive:\t%d\n"
21253 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21254 +               "#InitTask:\t%d\t%d %d\n",
21255 +               atomic_read(&vx_global_ctotal),
21256 +               atomic_read(&vx_global_cactive),
21257 +               atomic_read(&vs_global_nsproxy),
21258 +               atomic_read(&vs_global_fs),
21259 +               atomic_read(&vs_global_mnt_ns),
21260 +               atomic_read(&vs_global_uts_ns),
21261 +               atomic_read(&nr_ipc_ns),
21262 +               atomic_read(&vs_global_user_ns),
21263 +               atomic_read(&vs_global_pid_ns),
21264 +               atomic_read(&init_task.usage),
21265 +               atomic_read(&init_task.nsproxy->count),
21266 +               init_task.fs->users);
21267 +}
21268 +
21269 +
21270 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21271 +{
21272 +       int length;
21273 +
21274 +       length = sprintf(buffer,
21275 +               "ID:\t%d\n"
21276 +               "Info:\t%p\n"
21277 +               "Init:\t%d\n"
21278 +               "OOM:\t%lld\n",
21279 +               vxi->vx_id,
21280 +               vxi,
21281 +               vxi->vx_initpid,
21282 +               vxi->vx_badness_bias);
21283 +       return length;
21284 +}
21285 +
21286 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21287 +{
21288 +       char *orig = buffer;
21289 +
21290 +       buffer += sprintf(buffer,
21291 +               "UseCnt:\t%d\n"
21292 +               "Tasks:\t%d\n"
21293 +               "Flags:\t%016llx\n",
21294 +               atomic_read(&vxi->vx_usecnt),
21295 +               atomic_read(&vxi->vx_tasks),
21296 +               (unsigned long long)vxi->vx_flags);
21297 +
21298 +       buffer += sprintf(buffer, "BCaps:\t");
21299 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21300 +       buffer += sprintf(buffer, "\n");
21301 +
21302 +       buffer += sprintf(buffer,
21303 +               "CCaps:\t%016llx\n"
21304 +               "Umask:\t%16llx\n"
21305 +               "Wmask:\t%16llx\n"
21306 +               "Spaces:\t%08lx %08lx\n",
21307 +               (unsigned long long)vxi->vx_ccaps,
21308 +               (unsigned long long)vxi->vx_umask,
21309 +               (unsigned long long)vxi->vx_wmask,
21310 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21311 +       return buffer - orig;
21312 +}
21313 +
21314 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21315 +{
21316 +       return vx_info_proc_limit(&vxi->limit, buffer);
21317 +}
21318 +
21319 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21320 +{
21321 +       int cpu, length;
21322 +
21323 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21324 +       for_each_online_cpu(cpu) {
21325 +               length += vx_info_proc_sched_pc(
21326 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21327 +                       buffer + length, cpu);
21328 +       }
21329 +       return length;
21330 +}
21331 +
21332 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21333 +{
21334 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21335 +}
21336 +
21337 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21338 +{
21339 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21340 +}
21341 +
21342 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21343 +{
21344 +       int cpu, length;
21345 +
21346 +       vx_update_load(vxi);
21347 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21348 +       for_each_online_cpu(cpu) {
21349 +               length += vx_info_proc_cvirt_pc(
21350 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21351 +                       buffer + length, cpu);
21352 +       }
21353 +       return length;
21354 +}
21355 +
21356 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21357 +{
21358 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21359 +}
21360 +
21361 +
21362 +static int proc_virtnet_info(char *buffer)
21363 +{
21364 +       return proc_vci(buffer);
21365 +}
21366 +
21367 +static int proc_virtnet_status(char *buffer)
21368 +{
21369 +       return sprintf(buffer,
21370 +               "#CTotal:\t%d\n"
21371 +               "#CActive:\t%d\n",
21372 +               atomic_read(&nx_global_ctotal),
21373 +               atomic_read(&nx_global_cactive));
21374 +}
21375 +
21376 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21377 +{
21378 +       struct nx_addr_v4 *v4a;
21379 +#ifdef CONFIG_IPV6
21380 +       struct nx_addr_v6 *v6a;
21381 +#endif
21382 +       int length, i;
21383 +
21384 +       length = sprintf(buffer,
21385 +               "ID:\t%d\n"
21386 +               "Info:\t%p\n"
21387 +               "Bcast:\t" NIPQUAD_FMT "\n"
21388 +               "Lback:\t" NIPQUAD_FMT "\n",
21389 +               nxi->nx_id,
21390 +               nxi,
21391 +               NIPQUAD(nxi->v4_bcast.s_addr),
21392 +               NIPQUAD(nxi->v4_lback.s_addr));
21393 +
21394 +       if (!NX_IPV4(nxi))
21395 +               goto skip_v4;
21396 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21397 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21398 +                       i, NXAV4(v4a));
21399 +skip_v4:
21400 +#ifdef CONFIG_IPV6
21401 +       if (!NX_IPV6(nxi))
21402 +               goto skip_v6;
21403 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21404 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21405 +                       i, NXAV6(v6a));
21406 +skip_v6:
21407 +#endif
21408 +       return length;
21409 +}
21410 +
21411 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21412 +{
21413 +       int length;
21414 +
21415 +       length = sprintf(buffer,
21416 +               "UseCnt:\t%d\n"
21417 +               "Tasks:\t%d\n"
21418 +               "Flags:\t%016llx\n"
21419 +               "NCaps:\t%016llx\n",
21420 +               atomic_read(&nxi->nx_usecnt),
21421 +               atomic_read(&nxi->nx_tasks),
21422 +               (unsigned long long)nxi->nx_flags,
21423 +               (unsigned long long)nxi->nx_ncaps);
21424 +       return length;
21425 +}
21426 +
21427 +
21428 +
21429 +/* here the inode helpers */
21430 +
21431 +struct vs_entry {
21432 +       int len;
21433 +       char *name;
21434 +       mode_t mode;
21435 +       struct inode_operations *iop;
21436 +       struct file_operations *fop;
21437 +       union proc_op op;
21438 +};
21439 +
21440 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21441 +{
21442 +       struct inode *inode = new_inode(sb);
21443 +
21444 +       if (!inode)
21445 +               goto out;
21446 +
21447 +       inode->i_mode = p->mode;
21448 +       if (p->iop)
21449 +               inode->i_op = p->iop;
21450 +       if (p->fop)
21451 +               inode->i_fop = p->fop;
21452 +
21453 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21454 +       inode->i_flags |= S_IMMUTABLE;
21455 +
21456 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21457 +
21458 +       inode->i_uid = 0;
21459 +       inode->i_gid = 0;
21460 +       inode->i_tag = 0;
21461 +out:
21462 +       return inode;
21463 +}
21464 +
21465 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21466 +       struct dentry *dentry, int id, void *ptr)
21467 +{
21468 +       struct vs_entry *p = ptr;
21469 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21470 +       struct dentry *error = ERR_PTR(-EINVAL);
21471 +
21472 +       if (!inode)
21473 +               goto out;
21474 +
21475 +       PROC_I(inode)->op = p->op;
21476 +       PROC_I(inode)->fd = id;
21477 +       d_add(dentry, inode);
21478 +       error = NULL;
21479 +out:
21480 +       return error;
21481 +}
21482 +
21483 +/* Lookups */
21484 +
21485 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21486 +
21487 +/*
21488 + * Fill a directory entry.
21489 + *
21490 + * If possible create the dcache entry and derive our inode number and
21491 + * file type from dcache entry.
21492 + *
21493 + * Since all of the proc inode numbers are dynamically generated, the inode
21494 + * numbers do not exist until the inode is cache.  This means creating the
21495 + * the dcache entry in readdir is necessary to keep the inode numbers
21496 + * reported by readdir in sync with the inode numbers reported
21497 + * by stat.
21498 + */
21499 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21500 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21501 +{
21502 +       struct dentry *child, *dir = filp->f_dentry;
21503 +       struct inode *inode;
21504 +       struct qstr qname;
21505 +       ino_t ino = 0;
21506 +       unsigned type = DT_UNKNOWN;
21507 +
21508 +       qname.name = name;
21509 +       qname.len  = len;
21510 +       qname.hash = full_name_hash(name, len);
21511 +
21512 +       child = d_lookup(dir, &qname);
21513 +       if (!child) {
21514 +               struct dentry *new;
21515 +               new = d_alloc(dir, &qname);
21516 +               if (new) {
21517 +                       child = instantiate(dir->d_inode, new, id, ptr);
21518 +                       if (child)
21519 +                               dput(new);
21520 +                       else
21521 +                               child = new;
21522 +               }
21523 +       }
21524 +       if (!child || IS_ERR(child) || !child->d_inode)
21525 +               goto end_instantiate;
21526 +       inode = child->d_inode;
21527 +       if (inode) {
21528 +               ino = inode->i_ino;
21529 +               type = inode->i_mode >> 12;
21530 +       }
21531 +       dput(child);
21532 +end_instantiate:
21533 +       if (!ino)
21534 +               ino = find_inode_number(dir, &qname);
21535 +       if (!ino)
21536 +               ino = 1;
21537 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21538 +}
21539 +
21540 +
21541 +
21542 +/* get and revalidate vx_info/xid */
21543 +
21544 +static inline
21545 +struct vx_info *get_proc_vx_info(struct inode *inode)
21546 +{
21547 +       return lookup_vx_info(PROC_I(inode)->fd);
21548 +}
21549 +
21550 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21551 +{
21552 +       struct inode *inode = dentry->d_inode;
21553 +       xid_t xid = PROC_I(inode)->fd;
21554 +
21555 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21556 +               return -ECHILD;
21557 +
21558 +       if (!xid || xid_is_hashed(xid))
21559 +               return 1;
21560 +       d_drop(dentry);
21561 +       return 0;
21562 +}
21563 +
21564 +
21565 +/* get and revalidate nx_info/nid */
21566 +
21567 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21568 +{
21569 +       struct inode *inode = dentry->d_inode;
21570 +       nid_t nid = PROC_I(inode)->fd;
21571 +
21572 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21573 +               return -ECHILD;
21574 +
21575 +       if (!nid || nid_is_hashed(nid))
21576 +               return 1;
21577 +       d_drop(dentry);
21578 +       return 0;
21579 +}
21580 +
21581 +
21582 +
21583 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21584 +
21585 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21586 +                         size_t count, loff_t *ppos)
21587 +{
21588 +       struct inode *inode = file->f_dentry->d_inode;
21589 +       unsigned long page;
21590 +       ssize_t length = 0;
21591 +
21592 +       if (count > PROC_BLOCK_SIZE)
21593 +               count = PROC_BLOCK_SIZE;
21594 +
21595 +       /* fade that out as soon as stable */
21596 +       WARN_ON(PROC_I(inode)->fd);
21597 +
21598 +       if (!(page = __get_free_page(GFP_KERNEL)))
21599 +               return -ENOMEM;
21600 +
21601 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21602 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21603 +
21604 +       if (length >= 0)
21605 +               length = simple_read_from_buffer(buf, count, ppos,
21606 +                       (char *)page, length);
21607 +
21608 +       free_page(page);
21609 +       return length;
21610 +}
21611 +
21612 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21613 +                         size_t count, loff_t *ppos)
21614 +{
21615 +       struct inode *inode = file->f_dentry->d_inode;
21616 +       struct vx_info *vxi = NULL;
21617 +       xid_t xid = PROC_I(inode)->fd;
21618 +       unsigned long page;
21619 +       ssize_t length = 0;
21620 +
21621 +       if (count > PROC_BLOCK_SIZE)
21622 +               count = PROC_BLOCK_SIZE;
21623 +
21624 +       /* fade that out as soon as stable */
21625 +       WARN_ON(!xid);
21626 +       vxi = lookup_vx_info(xid);
21627 +       if (!vxi)
21628 +               goto out;
21629 +
21630 +       length = -ENOMEM;
21631 +       if (!(page = __get_free_page(GFP_KERNEL)))
21632 +               goto out_put;
21633 +
21634 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21635 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21636 +
21637 +       if (length >= 0)
21638 +               length = simple_read_from_buffer(buf, count, ppos,
21639 +                       (char *)page, length);
21640 +
21641 +       free_page(page);
21642 +out_put:
21643 +       put_vx_info(vxi);
21644 +out:
21645 +       return length;
21646 +}
21647 +
21648 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21649 +                         size_t count, loff_t *ppos)
21650 +{
21651 +       struct inode *inode = file->f_dentry->d_inode;
21652 +       struct nx_info *nxi = NULL;
21653 +       nid_t nid = PROC_I(inode)->fd;
21654 +       unsigned long page;
21655 +       ssize_t length = 0;
21656 +
21657 +       if (count > PROC_BLOCK_SIZE)
21658 +               count = PROC_BLOCK_SIZE;
21659 +
21660 +       /* fade that out as soon as stable */
21661 +       WARN_ON(!nid);
21662 +       nxi = lookup_nx_info(nid);
21663 +       if (!nxi)
21664 +               goto out;
21665 +
21666 +       length = -ENOMEM;
21667 +       if (!(page = __get_free_page(GFP_KERNEL)))
21668 +               goto out_put;
21669 +
21670 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21671 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21672 +
21673 +       if (length >= 0)
21674 +               length = simple_read_from_buffer(buf, count, ppos,
21675 +                       (char *)page, length);
21676 +
21677 +       free_page(page);
21678 +out_put:
21679 +       put_nx_info(nxi);
21680 +out:
21681 +       return length;
21682 +}
21683 +
21684 +
21685 +
21686 +/* here comes the lower level */
21687 +
21688 +
21689 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21690 +       .len  = sizeof(NAME) - 1,       \
21691 +       .name = (NAME),                 \
21692 +       .mode = MODE,                   \
21693 +       .iop  = IOP,                    \
21694 +       .fop  = FOP,                    \
21695 +       .op   = OP,                     \
21696 +}
21697 +
21698 +
21699 +#define DIR(NAME, MODE, OTYPE)                         \
21700 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21701 +               &proc_ ## OTYPE ## _inode_operations,   \
21702 +               &proc_ ## OTYPE ## _file_operations, { } )
21703 +
21704 +#define INF(NAME, MODE, OTYPE)                         \
21705 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21706 +               &proc_vs_info_file_operations,          \
21707 +               { .proc_vs_read = &proc_##OTYPE } )
21708 +
21709 +#define VINF(NAME, MODE, OTYPE)                                \
21710 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21711 +               &proc_vx_info_file_operations,          \
21712 +               { .proc_vxi_read = &proc_##OTYPE } )
21713 +
21714 +#define NINF(NAME, MODE, OTYPE)                                \
21715 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21716 +               &proc_nx_info_file_operations,          \
21717 +               { .proc_nxi_read = &proc_##OTYPE } )
21718 +
21719 +
21720 +static struct file_operations proc_vs_info_file_operations = {
21721 +       .read =         proc_vs_info_read,
21722 +};
21723 +
21724 +static struct file_operations proc_vx_info_file_operations = {
21725 +       .read =         proc_vx_info_read,
21726 +};
21727 +
21728 +static struct dentry_operations proc_xid_dentry_operations = {
21729 +       .d_revalidate = proc_xid_revalidate,
21730 +};
21731 +
21732 +static struct vs_entry vx_base_stuff[] = {
21733 +       VINF("info",    S_IRUGO, vxi_info),
21734 +       VINF("status",  S_IRUGO, vxi_status),
21735 +       VINF("limit",   S_IRUGO, vxi_limit),
21736 +       VINF("sched",   S_IRUGO, vxi_sched),
21737 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21738 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21739 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21740 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21741 +       {}
21742 +};
21743 +
21744 +
21745 +
21746 +
21747 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21748 +       struct dentry *dentry, int id, void *ptr)
21749 +{
21750 +       dentry->d_op = &proc_xid_dentry_operations;
21751 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21752 +}
21753 +
21754 +static struct dentry *proc_xid_lookup(struct inode *dir,
21755 +       struct dentry *dentry, unsigned int flags)
21756 +{
21757 +       struct vs_entry *p = vx_base_stuff;
21758 +       struct dentry *error = ERR_PTR(-ENOENT);
21759 +
21760 +       for (; p->name; p++) {
21761 +               if (p->len != dentry->d_name.len)
21762 +                       continue;
21763 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21764 +                       break;
21765 +       }
21766 +       if (!p->name)
21767 +               goto out;
21768 +
21769 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21770 +out:
21771 +       return error;
21772 +}
21773 +
21774 +static int proc_xid_readdir(struct file *filp,
21775 +       void *dirent, filldir_t filldir)
21776 +{
21777 +       struct dentry *dentry = filp->f_dentry;
21778 +       struct inode *inode = dentry->d_inode;
21779 +       struct vs_entry *p = vx_base_stuff;
21780 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21781 +       int pos, index;
21782 +       u64 ino;
21783 +
21784 +       pos = filp->f_pos;
21785 +       switch (pos) {
21786 +       case 0:
21787 +               ino = inode->i_ino;
21788 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21789 +                       goto out;
21790 +               pos++;
21791 +               /* fall through */
21792 +       case 1:
21793 +               ino = parent_ino(dentry);
21794 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21795 +                       goto out;
21796 +               pos++;
21797 +               /* fall through */
21798 +       default:
21799 +               index = pos - 2;
21800 +               if (index >= size)
21801 +                       goto out;
21802 +               for (p += index; p->name; p++) {
21803 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21804 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21805 +                               goto out;
21806 +                       pos++;
21807 +               }
21808 +       }
21809 +out:
21810 +       filp->f_pos = pos;
21811 +       return 1;
21812 +}
21813 +
21814 +
21815 +
21816 +static struct file_operations proc_nx_info_file_operations = {
21817 +       .read =         proc_nx_info_read,
21818 +};
21819 +
21820 +static struct dentry_operations proc_nid_dentry_operations = {
21821 +       .d_revalidate = proc_nid_revalidate,
21822 +};
21823 +
21824 +static struct vs_entry nx_base_stuff[] = {
21825 +       NINF("info",    S_IRUGO, nxi_info),
21826 +       NINF("status",  S_IRUGO, nxi_status),
21827 +       {}
21828 +};
21829 +
21830 +
21831 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21832 +       struct dentry *dentry, int id, void *ptr)
21833 +{
21834 +       dentry->d_op = &proc_nid_dentry_operations;
21835 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21836 +}
21837 +
21838 +static struct dentry *proc_nid_lookup(struct inode *dir,
21839 +       struct dentry *dentry, unsigned int flags)
21840 +{
21841 +       struct vs_entry *p = nx_base_stuff;
21842 +       struct dentry *error = ERR_PTR(-ENOENT);
21843 +
21844 +       for (; p->name; p++) {
21845 +               if (p->len != dentry->d_name.len)
21846 +                       continue;
21847 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21848 +                       break;
21849 +       }
21850 +       if (!p->name)
21851 +               goto out;
21852 +
21853 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21854 +out:
21855 +       return error;
21856 +}
21857 +
21858 +static int proc_nid_readdir(struct file *filp,
21859 +       void *dirent, filldir_t filldir)
21860 +{
21861 +       struct dentry *dentry = filp->f_dentry;
21862 +       struct inode *inode = dentry->d_inode;
21863 +       struct vs_entry *p = nx_base_stuff;
21864 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21865 +       int pos, index;
21866 +       u64 ino;
21867 +
21868 +       pos = filp->f_pos;
21869 +       switch (pos) {
21870 +       case 0:
21871 +               ino = inode->i_ino;
21872 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21873 +                       goto out;
21874 +               pos++;
21875 +               /* fall through */
21876 +       case 1:
21877 +               ino = parent_ino(dentry);
21878 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21879 +                       goto out;
21880 +               pos++;
21881 +               /* fall through */
21882 +       default:
21883 +               index = pos - 2;
21884 +               if (index >= size)
21885 +                       goto out;
21886 +               for (p += index; p->name; p++) {
21887 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21888 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21889 +                               goto out;
21890 +                       pos++;
21891 +               }
21892 +       }
21893 +out:
21894 +       filp->f_pos = pos;
21895 +       return 1;
21896 +}
21897 +
21898 +
21899 +#define MAX_MULBY10    ((~0U - 9) / 10)
21900 +
21901 +static inline int atovid(const char *str, int len)
21902 +{
21903 +       int vid, c;
21904 +
21905 +       vid = 0;
21906 +       while (len-- > 0) {
21907 +               c = *str - '0';
21908 +               str++;
21909 +               if (c > 9)
21910 +                       return -1;
21911 +               if (vid >= MAX_MULBY10)
21912 +                       return -1;
21913 +               vid *= 10;
21914 +               vid += c;
21915 +               if (!vid)
21916 +                       return -1;
21917 +       }
21918 +       return vid;
21919 +}
21920 +
21921 +/* now the upper level (virtual) */
21922 +
21923 +
21924 +static struct file_operations proc_xid_file_operations = {
21925 +       .read =         generic_read_dir,
21926 +       .readdir =      proc_xid_readdir,
21927 +};
21928 +
21929 +static struct inode_operations proc_xid_inode_operations = {
21930 +       .lookup =       proc_xid_lookup,
21931 +};
21932 +
21933 +static struct vs_entry vx_virtual_stuff[] = {
21934 +       INF("info",     S_IRUGO, virtual_info),
21935 +       INF("status",   S_IRUGO, virtual_status),
21936 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21937 +};
21938 +
21939 +
21940 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21941 +       struct dentry *dentry, unsigned int flags)
21942 +{
21943 +       struct vs_entry *p = vx_virtual_stuff;
21944 +       struct dentry *error = ERR_PTR(-ENOENT);
21945 +       int id = 0;
21946 +
21947 +       for (; p->name; p++) {
21948 +               if (p->len != dentry->d_name.len)
21949 +                       continue;
21950 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21951 +                       break;
21952 +       }
21953 +       if (p->name)
21954 +               goto instantiate;
21955 +
21956 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21957 +       if ((id < 0) || !xid_is_hashed(id))
21958 +               goto out;
21959 +
21960 +instantiate:
21961 +       error = proc_xid_instantiate(dir, dentry, id, p);
21962 +out:
21963 +       return error;
21964 +}
21965 +
21966 +static struct file_operations proc_nid_file_operations = {
21967 +       .read =         generic_read_dir,
21968 +       .readdir =      proc_nid_readdir,
21969 +};
21970 +
21971 +static struct inode_operations proc_nid_inode_operations = {
21972 +       .lookup =       proc_nid_lookup,
21973 +};
21974 +
21975 +static struct vs_entry nx_virtnet_stuff[] = {
21976 +       INF("info",     S_IRUGO, virtnet_info),
21977 +       INF("status",   S_IRUGO, virtnet_status),
21978 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21979 +};
21980 +
21981 +
21982 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21983 +       struct dentry *dentry, unsigned int flags)
21984 +{
21985 +       struct vs_entry *p = nx_virtnet_stuff;
21986 +       struct dentry *error = ERR_PTR(-ENOENT);
21987 +       int id = 0;
21988 +
21989 +       for (; p->name; p++) {
21990 +               if (p->len != dentry->d_name.len)
21991 +                       continue;
21992 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21993 +                       break;
21994 +       }
21995 +       if (p->name)
21996 +               goto instantiate;
21997 +
21998 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21999 +       if ((id < 0) || !nid_is_hashed(id))
22000 +               goto out;
22001 +
22002 +instantiate:
22003 +       error = proc_nid_instantiate(dir, dentry, id, p);
22004 +out:
22005 +       return error;
22006 +}
22007 +
22008 +
22009 +#define PROC_MAXVIDS 32
22010 +
22011 +int proc_virtual_readdir(struct file *filp,
22012 +       void *dirent, filldir_t filldir)
22013 +{
22014 +       struct dentry *dentry = filp->f_dentry;
22015 +       struct inode *inode = dentry->d_inode;
22016 +       struct vs_entry *p = vx_virtual_stuff;
22017 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22018 +       int pos, index;
22019 +       unsigned int xid_array[PROC_MAXVIDS];
22020 +       char buf[PROC_NUMBUF];
22021 +       unsigned int nr_xids, i;
22022 +       u64 ino;
22023 +
22024 +       pos = filp->f_pos;
22025 +       switch (pos) {
22026 +       case 0:
22027 +               ino = inode->i_ino;
22028 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22029 +                       goto out;
22030 +               pos++;
22031 +               /* fall through */
22032 +       case 1:
22033 +               ino = parent_ino(dentry);
22034 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22035 +                       goto out;
22036 +               pos++;
22037 +               /* fall through */
22038 +       default:
22039 +               index = pos - 2;
22040 +               if (index >= size)
22041 +                       goto entries;
22042 +               for (p += index; p->name; p++) {
22043 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22044 +                               vs_proc_instantiate, 0, p))
22045 +                               goto out;
22046 +                       pos++;
22047 +               }
22048 +       entries:
22049 +               index = pos - size;
22050 +               p = &vx_virtual_stuff[size - 1];
22051 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22052 +               for (i = 0; i < nr_xids; i++) {
22053 +                       int n, xid = xid_array[i];
22054 +                       unsigned int j = PROC_NUMBUF;
22055 +
22056 +                       n = xid;
22057 +                       do
22058 +                               buf[--j] = '0' + (n % 10);
22059 +                       while (n /= 10);
22060 +
22061 +                       if (proc_fill_cache(filp, dirent, filldir,
22062 +                               buf + j, PROC_NUMBUF - j,
22063 +                               vs_proc_instantiate, xid, p))
22064 +                               goto out;
22065 +                       pos++;
22066 +               }
22067 +       }
22068 +out:
22069 +       filp->f_pos = pos;
22070 +       return 0;
22071 +}
22072 +
22073 +static int proc_virtual_getattr(struct vfsmount *mnt,
22074 +       struct dentry *dentry, struct kstat *stat)
22075 +{
22076 +       struct inode *inode = dentry->d_inode;
22077 +
22078 +       generic_fillattr(inode, stat);
22079 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22080 +       return 0;
22081 +}
22082 +
22083 +static struct file_operations proc_virtual_dir_operations = {
22084 +       .read =         generic_read_dir,
22085 +       .readdir =      proc_virtual_readdir,
22086 +};
22087 +
22088 +static struct inode_operations proc_virtual_dir_inode_operations = {
22089 +       .getattr =      proc_virtual_getattr,
22090 +       .lookup =       proc_virtual_lookup,
22091 +};
22092 +
22093 +
22094 +
22095 +
22096 +
22097 +int proc_virtnet_readdir(struct file *filp,
22098 +       void *dirent, filldir_t filldir)
22099 +{
22100 +       struct dentry *dentry = filp->f_dentry;
22101 +       struct inode *inode = dentry->d_inode;
22102 +       struct vs_entry *p = nx_virtnet_stuff;
22103 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22104 +       int pos, index;
22105 +       unsigned int nid_array[PROC_MAXVIDS];
22106 +       char buf[PROC_NUMBUF];
22107 +       unsigned int nr_nids, i;
22108 +       u64 ino;
22109 +
22110 +       pos = filp->f_pos;
22111 +       switch (pos) {
22112 +       case 0:
22113 +               ino = inode->i_ino;
22114 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22115 +                       goto out;
22116 +               pos++;
22117 +               /* fall through */
22118 +       case 1:
22119 +               ino = parent_ino(dentry);
22120 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22121 +                       goto out;
22122 +               pos++;
22123 +               /* fall through */
22124 +       default:
22125 +               index = pos - 2;
22126 +               if (index >= size)
22127 +                       goto entries;
22128 +               for (p += index; p->name; p++) {
22129 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22130 +                               vs_proc_instantiate, 0, p))
22131 +                               goto out;
22132 +                       pos++;
22133 +               }
22134 +       entries:
22135 +               index = pos - size;
22136 +               p = &nx_virtnet_stuff[size - 1];
22137 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22138 +               for (i = 0; i < nr_nids; i++) {
22139 +                       int n, nid = nid_array[i];
22140 +                       unsigned int j = PROC_NUMBUF;
22141 +
22142 +                       n = nid;
22143 +                       do
22144 +                               buf[--j] = '0' + (n % 10);
22145 +                       while (n /= 10);
22146 +
22147 +                       if (proc_fill_cache(filp, dirent, filldir,
22148 +                               buf + j, PROC_NUMBUF - j,
22149 +                               vs_proc_instantiate, nid, p))
22150 +                               goto out;
22151 +                       pos++;
22152 +               }
22153 +       }
22154 +out:
22155 +       filp->f_pos = pos;
22156 +       return 0;
22157 +}
22158 +
22159 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22160 +       struct dentry *dentry, struct kstat *stat)
22161 +{
22162 +       struct inode *inode = dentry->d_inode;
22163 +
22164 +       generic_fillattr(inode, stat);
22165 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22166 +       return 0;
22167 +}
22168 +
22169 +static struct file_operations proc_virtnet_dir_operations = {
22170 +       .read =         generic_read_dir,
22171 +       .readdir =      proc_virtnet_readdir,
22172 +};
22173 +
22174 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22175 +       .getattr =      proc_virtnet_getattr,
22176 +       .lookup =       proc_virtnet_lookup,
22177 +};
22178 +
22179 +
22180 +
22181 +void proc_vx_init(void)
22182 +{
22183 +       struct proc_dir_entry *ent;
22184 +
22185 +       ent = proc_mkdir("virtual", 0);
22186 +       if (ent) {
22187 +               ent->proc_fops = &proc_virtual_dir_operations;
22188 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22189 +       }
22190 +       proc_virtual = ent;
22191 +
22192 +       ent = proc_mkdir("virtnet", 0);
22193 +       if (ent) {
22194 +               ent->proc_fops = &proc_virtnet_dir_operations;
22195 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22196 +       }
22197 +       proc_virtnet = ent;
22198 +}
22199 +
22200 +
22201 +
22202 +
22203 +/* per pid info */
22204 +
22205 +
22206 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22207 +{
22208 +       struct vx_info *vxi;
22209 +       char *orig = buffer;
22210 +
22211 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22212 +
22213 +       vxi = task_get_vx_info(p);
22214 +       if (!vxi)
22215 +               goto out;
22216 +
22217 +       buffer += sprintf(buffer, "BCaps:\t");
22218 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22219 +       buffer += sprintf(buffer, "\n");
22220 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22221 +               (unsigned long long)vxi->vx_ccaps);
22222 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22223 +               (unsigned long long)vxi->vx_flags);
22224 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22225 +
22226 +       put_vx_info(vxi);
22227 +out:
22228 +       return buffer - orig;
22229 +}
22230 +
22231 +
22232 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22233 +{
22234 +       struct nx_info *nxi;
22235 +       struct nx_addr_v4 *v4a;
22236 +#ifdef CONFIG_IPV6
22237 +       struct nx_addr_v6 *v6a;
22238 +#endif
22239 +       char *orig = buffer;
22240 +       int i;
22241 +
22242 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22243 +
22244 +       nxi = task_get_nx_info(p);
22245 +       if (!nxi)
22246 +               goto out;
22247 +
22248 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22249 +               (unsigned long long)nxi->nx_ncaps);
22250 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22251 +               (unsigned long long)nxi->nx_flags);
22252 +
22253 +       buffer += sprintf(buffer,
22254 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22255 +               NIPQUAD(nxi->v4_bcast.s_addr));
22256 +       buffer += sprintf (buffer,
22257 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22258 +               NIPQUAD(nxi->v4_lback.s_addr));
22259 +       if (!NX_IPV4(nxi))
22260 +               goto skip_v4;
22261 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22262 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22263 +                       i, NXAV4(v4a));
22264 +skip_v4:
22265 +#ifdef CONFIG_IPV6
22266 +       if (!NX_IPV6(nxi))
22267 +               goto skip_v6;
22268 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22269 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22270 +                       i, NXAV6(v6a));
22271 +skip_v6:
22272 +#endif
22273 +       put_nx_info(nxi);
22274 +out:
22275 +       return buffer - orig;
22276 +}
22277 +
22278 diff -NurpP --minimal linux-3.7.1/kernel/vserver/sched.c linux-3.7.1-vs2.3.5.5/kernel/vserver/sched.c
22279 --- linux-3.7.1/kernel/vserver/sched.c  1970-01-01 00:00:00.000000000 +0000
22280 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/sched.c        2012-12-18 15:13:16.000000000 +0000
22281 @@ -0,0 +1,83 @@
22282 +/*
22283 + *  linux/kernel/vserver/sched.c
22284 + *
22285 + *  Virtual Server: Scheduler Support
22286 + *
22287 + *  Copyright (C) 2004-2010  Herbert Pötzl
22288 + *
22289 + *  V0.01  adapted Sam Vilains version to 2.6.3
22290 + *  V0.02  removed legacy interface
22291 + *  V0.03  changed vcmds to vxi arg
22292 + *  V0.04  removed older and legacy interfaces
22293 + *  V0.05  removed scheduler code/commands
22294 + *
22295 + */
22296 +
22297 +#include <linux/vs_context.h>
22298 +#include <linux/vs_sched.h>
22299 +#include <linux/cpumask.h>
22300 +#include <linux/vserver/sched_cmd.h>
22301 +
22302 +#include <asm/uaccess.h>
22303 +
22304 +
22305 +void vx_update_sched_param(struct _vx_sched *sched,
22306 +       struct _vx_sched_pc *sched_pc)
22307 +{
22308 +       sched_pc->prio_bias = sched->prio_bias;
22309 +}
22310 +
22311 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22312 +{
22313 +       int cpu;
22314 +
22315 +       if (data->prio_bias > MAX_PRIO_BIAS)
22316 +               data->prio_bias = MAX_PRIO_BIAS;
22317 +       if (data->prio_bias < MIN_PRIO_BIAS)
22318 +               data->prio_bias = MIN_PRIO_BIAS;
22319 +
22320 +       if (data->cpu_id != ~0) {
22321 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22322 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22323 +                       cpu_online_mask);
22324 +       } else
22325 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22326 +
22327 +       for_each_cpu_mask(cpu, vxi->sched.update)
22328 +               vx_update_sched_param(&vxi->sched,
22329 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22330 +       return 0;
22331 +}
22332 +
22333 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22334 +{
22335 +       struct vcmd_prio_bias vc_data;
22336 +
22337 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22338 +               return -EFAULT;
22339 +
22340 +       return do_set_prio_bias(vxi, &vc_data);
22341 +}
22342 +
22343 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22344 +{
22345 +       struct vcmd_prio_bias vc_data;
22346 +       struct _vx_sched_pc *pcd;
22347 +       int cpu;
22348 +
22349 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22350 +               return -EFAULT;
22351 +
22352 +       cpu = vc_data.cpu_id;
22353 +
22354 +       if (!cpu_possible(cpu))
22355 +               return -EINVAL;
22356 +
22357 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22358 +       vc_data.prio_bias = pcd->prio_bias;
22359 +
22360 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22361 +               return -EFAULT;
22362 +       return 0;
22363 +}
22364 +
22365 diff -NurpP --minimal linux-3.7.1/kernel/vserver/sched_init.h linux-3.7.1-vs2.3.5.5/kernel/vserver/sched_init.h
22366 --- linux-3.7.1/kernel/vserver/sched_init.h     1970-01-01 00:00:00.000000000 +0000
22367 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/sched_init.h   2012-12-18 15:13:16.000000000 +0000
22368 @@ -0,0 +1,27 @@
22369 +
22370 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22371 +{
22372 +       /* scheduling; hard code starting values as constants */
22373 +       sched->prio_bias = 0;
22374 +}
22375 +
22376 +static inline
22377 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22378 +{
22379 +       sched_pc->prio_bias = 0;
22380 +
22381 +       sched_pc->user_ticks = 0;
22382 +       sched_pc->sys_ticks = 0;
22383 +       sched_pc->hold_ticks = 0;
22384 +}
22385 +
22386 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22387 +{
22388 +       return;
22389 +}
22390 +
22391 +static inline
22392 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22393 +{
22394 +       return;
22395 +}
22396 diff -NurpP --minimal linux-3.7.1/kernel/vserver/sched_proc.h linux-3.7.1-vs2.3.5.5/kernel/vserver/sched_proc.h
22397 --- linux-3.7.1/kernel/vserver/sched_proc.h     1970-01-01 00:00:00.000000000 +0000
22398 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/sched_proc.h   2012-12-18 15:13:16.000000000 +0000
22399 @@ -0,0 +1,32 @@
22400 +#ifndef _VX_SCHED_PROC_H
22401 +#define _VX_SCHED_PROC_H
22402 +
22403 +
22404 +static inline
22405 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22406 +{
22407 +       int length = 0;
22408 +
22409 +       length += sprintf(buffer,
22410 +               "PrioBias:\t%8d\n",
22411 +               sched->prio_bias);
22412 +       return length;
22413 +}
22414 +
22415 +static inline
22416 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22417 +       char *buffer, int cpu)
22418 +{
22419 +       int length = 0;
22420 +
22421 +       length += sprintf(buffer + length,
22422 +               "cpu %d: %lld %lld %lld", cpu,
22423 +               (unsigned long long)sched_pc->user_ticks,
22424 +               (unsigned long long)sched_pc->sys_ticks,
22425 +               (unsigned long long)sched_pc->hold_ticks);
22426 +       length += sprintf(buffer + length,
22427 +               " %d\n", sched_pc->prio_bias);
22428 +       return length;
22429 +}
22430 +
22431 +#endif /* _VX_SCHED_PROC_H */
22432 diff -NurpP --minimal linux-3.7.1/kernel/vserver/signal.c linux-3.7.1-vs2.3.5.5/kernel/vserver/signal.c
22433 --- linux-3.7.1/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22434 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/signal.c       2012-12-18 15:13:16.000000000 +0000
22435 @@ -0,0 +1,134 @@
22436 +/*
22437 + *  linux/kernel/vserver/signal.c
22438 + *
22439 + *  Virtual Server: Signal Support
22440 + *
22441 + *  Copyright (C) 2003-2007  Herbert Pötzl
22442 + *
22443 + *  V0.01  broken out from vcontext V0.05
22444 + *  V0.02  changed vcmds to vxi arg
22445 + *  V0.03  adjusted siginfo for kill
22446 + *
22447 + */
22448 +
22449 +#include <asm/uaccess.h>
22450 +
22451 +#include <linux/vs_context.h>
22452 +#include <linux/vs_pid.h>
22453 +#include <linux/vserver/signal_cmd.h>
22454 +
22455 +
22456 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22457 +{
22458 +       int retval, count = 0;
22459 +       struct task_struct *p;
22460 +       struct siginfo *sip = SEND_SIG_PRIV;
22461 +
22462 +       retval = -ESRCH;
22463 +       vxdprintk(VXD_CBIT(misc, 4),
22464 +               "vx_info_kill(%p[#%d],%d,%d)*",
22465 +               vxi, vxi->vx_id, pid, sig);
22466 +       read_lock(&tasklist_lock);
22467 +       switch (pid) {
22468 +       case  0:
22469 +       case -1:
22470 +               for_each_process(p) {
22471 +                       int err = 0;
22472 +
22473 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22474 +                               (pid && vxi->vx_initpid == p->pid))
22475 +                               continue;
22476 +
22477 +                       err = group_send_sig_info(sig, sip, p);
22478 +                       ++count;
22479 +                       if (err != -EPERM)
22480 +                               retval = err;
22481 +               }
22482 +               break;
22483 +
22484 +       case 1:
22485 +               if (vxi->vx_initpid) {
22486 +                       pid = vxi->vx_initpid;
22487 +                       /* for now, only SIGINT to private init ... */
22488 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22489 +                               /* ... as long as there are tasks left */
22490 +                               (atomic_read(&vxi->vx_tasks) > 1))
22491 +                               sig = SIGINT;
22492 +               }
22493 +               /* fallthrough */
22494 +       default:
22495 +               rcu_read_lock();
22496 +               p = find_task_by_real_pid(pid);
22497 +               rcu_read_unlock();
22498 +               if (p) {
22499 +                       if (vx_task_xid(p) == vxi->vx_id)
22500 +                               retval = group_send_sig_info(sig, sip, p);
22501 +               }
22502 +               break;
22503 +       }
22504 +       read_unlock(&tasklist_lock);
22505 +       vxdprintk(VXD_CBIT(misc, 4),
22506 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22507 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22508 +       return retval;
22509 +}
22510 +
22511 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22512 +{
22513 +       struct vcmd_ctx_kill_v0 vc_data;
22514 +
22515 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22516 +               return -EFAULT;
22517 +
22518 +       /* special check to allow guest shutdown */
22519 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22520 +               /* forbid killall pid=0 when init is present */
22521 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22522 +               (vc_data.pid > 1)))
22523 +               return -EACCES;
22524 +
22525 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22526 +}
22527 +
22528 +
22529 +static int __wait_exit(struct vx_info *vxi)
22530 +{
22531 +       DECLARE_WAITQUEUE(wait, current);
22532 +       int ret = 0;
22533 +
22534 +       add_wait_queue(&vxi->vx_wait, &wait);
22535 +       set_current_state(TASK_INTERRUPTIBLE);
22536 +
22537 +wait:
22538 +       if (vx_info_state(vxi,
22539 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22540 +               goto out;
22541 +       if (signal_pending(current)) {
22542 +               ret = -ERESTARTSYS;
22543 +               goto out;
22544 +       }
22545 +       schedule();
22546 +       goto wait;
22547 +
22548 +out:
22549 +       set_current_state(TASK_RUNNING);
22550 +       remove_wait_queue(&vxi->vx_wait, &wait);
22551 +       return ret;
22552 +}
22553 +
22554 +
22555 +
22556 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22557 +{
22558 +       struct vcmd_wait_exit_v0 vc_data;
22559 +       int ret;
22560 +
22561 +       ret = __wait_exit(vxi);
22562 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22563 +       vc_data.exit_code = vxi->exit_code;
22564 +
22565 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22566 +               ret = -EFAULT;
22567 +       return ret;
22568 +}
22569 +
22570 diff -NurpP --minimal linux-3.7.1/kernel/vserver/space.c linux-3.7.1-vs2.3.5.5/kernel/vserver/space.c
22571 --- linux-3.7.1/kernel/vserver/space.c  1970-01-01 00:00:00.000000000 +0000
22572 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/space.c        2012-12-18 15:13:16.000000000 +0000
22573 @@ -0,0 +1,436 @@
22574 +/*
22575 + *  linux/kernel/vserver/space.c
22576 + *
22577 + *  Virtual Server: Context Space Support
22578 + *
22579 + *  Copyright (C) 2003-2010  Herbert Pötzl
22580 + *
22581 + *  V0.01  broken out from context.c 0.07
22582 + *  V0.02  added task locking for namespace
22583 + *  V0.03  broken out vx_enter_namespace
22584 + *  V0.04  added *space support and commands
22585 + *  V0.05  added credential support
22586 + *
22587 + */
22588 +
22589 +#include <linux/utsname.h>
22590 +#include <linux/nsproxy.h>
22591 +#include <linux/err.h>
22592 +#include <linux/fs_struct.h>
22593 +#include <linux/cred.h>
22594 +#include <asm/uaccess.h>
22595 +
22596 +#include <linux/vs_context.h>
22597 +#include <linux/vserver/space.h>
22598 +#include <linux/vserver/space_cmd.h>
22599 +
22600 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22601 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22602 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22603 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22604 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22605 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22606 +
22607 +
22608 +/* namespace functions */
22609 +
22610 +#include <linux/mnt_namespace.h>
22611 +#include <linux/user_namespace.h>
22612 +#include <linux/pid_namespace.h>
22613 +#include <linux/ipc_namespace.h>
22614 +#include <net/net_namespace.h>
22615 +#include "../fs/mount.h"
22616 +
22617 +
22618 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22619 +       .mask = CLONE_FS |
22620 +               CLONE_NEWNS |
22621 +#ifdef CONFIG_UTS_NS
22622 +               CLONE_NEWUTS |
22623 +#endif
22624 +#ifdef CONFIG_IPC_NS
22625 +               CLONE_NEWIPC |
22626 +#endif
22627 +#ifdef CONFIG_USER_NS
22628 +               CLONE_NEWUSER |
22629 +#endif
22630 +               0
22631 +};
22632 +
22633 +static const struct vcmd_space_mask_v1 space_mask = {
22634 +       .mask = CLONE_FS |
22635 +               CLONE_NEWNS |
22636 +#ifdef CONFIG_UTS_NS
22637 +               CLONE_NEWUTS |
22638 +#endif
22639 +#ifdef CONFIG_IPC_NS
22640 +               CLONE_NEWIPC |
22641 +#endif
22642 +#ifdef CONFIG_USER_NS
22643 +               CLONE_NEWUSER |
22644 +#endif
22645 +#ifdef CONFIG_PID_NS
22646 +               CLONE_NEWPID |
22647 +#endif
22648 +#ifdef CONFIG_NET_NS
22649 +               CLONE_NEWNET |
22650 +#endif
22651 +               0
22652 +};
22653 +
22654 +static const struct vcmd_space_mask_v1 default_space_mask = {
22655 +       .mask = CLONE_FS |
22656 +               CLONE_NEWNS |
22657 +#ifdef CONFIG_UTS_NS
22658 +               CLONE_NEWUTS |
22659 +#endif
22660 +#ifdef CONFIG_IPC_NS
22661 +               CLONE_NEWIPC |
22662 +#endif
22663 +#ifdef CONFIG_USER_NS
22664 +               CLONE_NEWUSER |
22665 +#endif
22666 +#ifdef CONFIG_PID_NS
22667 +//             CLONE_NEWPID |
22668 +#endif
22669 +               0
22670 +};
22671 +
22672 +/*
22673 + *     build a new nsproxy mix
22674 + *      assumes that both proxies are 'const'
22675 + *     does not touch nsproxy refcounts
22676 + *     will hold a reference on the result.
22677 + */
22678 +
22679 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22680 +       struct nsproxy *new_nsproxy, unsigned long mask)
22681 +{
22682 +       struct mnt_namespace *old_ns;
22683 +       struct uts_namespace *old_uts;
22684 +       struct ipc_namespace *old_ipc;
22685 +#ifdef CONFIG_PID_NS
22686 +       struct pid_namespace *old_pid;
22687 +#endif
22688 +#ifdef CONFIG_NET_NS
22689 +       struct net *old_net;
22690 +#endif
22691 +       struct nsproxy *nsproxy;
22692 +
22693 +       nsproxy = copy_nsproxy(old_nsproxy);
22694 +       if (!nsproxy)
22695 +               goto out;
22696 +
22697 +       if (mask & CLONE_NEWNS) {
22698 +               old_ns = nsproxy->mnt_ns;
22699 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22700 +               if (nsproxy->mnt_ns)
22701 +                       get_mnt_ns(nsproxy->mnt_ns);
22702 +       } else
22703 +               old_ns = NULL;
22704 +
22705 +       if (mask & CLONE_NEWUTS) {
22706 +               old_uts = nsproxy->uts_ns;
22707 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22708 +               if (nsproxy->uts_ns)
22709 +                       get_uts_ns(nsproxy->uts_ns);
22710 +       } else
22711 +               old_uts = NULL;
22712 +
22713 +       if (mask & CLONE_NEWIPC) {
22714 +               old_ipc = nsproxy->ipc_ns;
22715 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22716 +               if (nsproxy->ipc_ns)
22717 +                       get_ipc_ns(nsproxy->ipc_ns);
22718 +       } else
22719 +               old_ipc = NULL;
22720 +
22721 +#ifdef CONFIG_PID_NS
22722 +       if (mask & CLONE_NEWPID) {
22723 +               old_pid = nsproxy->pid_ns;
22724 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22725 +               if (nsproxy->pid_ns)
22726 +                       get_pid_ns(nsproxy->pid_ns);
22727 +       } else
22728 +               old_pid = NULL;
22729 +#endif
22730 +#ifdef CONFIG_NET_NS
22731 +       if (mask & CLONE_NEWNET) {
22732 +               old_net = nsproxy->net_ns;
22733 +               nsproxy->net_ns = new_nsproxy->net_ns;
22734 +               if (nsproxy->net_ns)
22735 +                       get_net(nsproxy->net_ns);
22736 +       } else
22737 +               old_net = NULL;
22738 +#endif
22739 +       if (old_ns)
22740 +               put_mnt_ns(old_ns);
22741 +       if (old_uts)
22742 +               put_uts_ns(old_uts);
22743 +       if (old_ipc)
22744 +               put_ipc_ns(old_ipc);
22745 +#ifdef CONFIG_PID_NS
22746 +       if (old_pid)
22747 +               put_pid_ns(old_pid);
22748 +#endif
22749 +#ifdef CONFIG_NET_NS
22750 +       if (old_net)
22751 +               put_net(old_net);
22752 +#endif
22753 +out:
22754 +       return nsproxy;
22755 +}
22756 +
22757 +
22758 +/*
22759 + *     merge two nsproxy structs into a new one.
22760 + *     will hold a reference on the result.
22761 + */
22762 +
22763 +static inline
22764 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22765 +       struct nsproxy *proxy, unsigned long mask)
22766 +{
22767 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22768 +
22769 +       if (!proxy)
22770 +               return NULL;
22771 +
22772 +       if (mask) {
22773 +               /* vs_mix_nsproxy returns with reference */
22774 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22775 +                       proxy, mask);
22776 +       }
22777 +       get_nsproxy(proxy);
22778 +       return proxy;
22779 +}
22780 +
22781 +
22782 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22783 +{
22784 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22785 +       struct fs_struct *fs_cur, *fs = NULL;
22786 +       struct _vx_space *space;
22787 +       int ret, kill = 0;
22788 +
22789 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22790 +               vxi, vxi->vx_id, mask, index);
22791 +
22792 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22793 +               return -EACCES;
22794 +
22795 +       if (index >= VX_SPACES)
22796 +               return -EINVAL;
22797 +
22798 +       space = &vxi->space[index];
22799 +
22800 +       if (!mask)
22801 +               mask = space->vx_nsmask;
22802 +
22803 +       if ((mask & space->vx_nsmask) != mask)
22804 +               return -EINVAL;
22805 +
22806 +       if (mask & CLONE_FS) {
22807 +               fs = copy_fs_struct(space->vx_fs);
22808 +               if (!fs)
22809 +                       return -ENOMEM;
22810 +       }
22811 +       proxy = space->vx_nsproxy;
22812 +
22813 +       vxdprintk(VXD_CBIT(space, 9),
22814 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22815 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22816 +
22817 +       task_lock(current);
22818 +       fs_cur = current->fs;
22819 +
22820 +       if (mask & CLONE_FS) {
22821 +               spin_lock(&fs_cur->lock);
22822 +               current->fs = fs;
22823 +               kill = !--fs_cur->users;
22824 +               spin_unlock(&fs_cur->lock);
22825 +       }
22826 +
22827 +       proxy_cur = current->nsproxy;
22828 +       get_nsproxy(proxy_cur);
22829 +       task_unlock(current);
22830 +
22831 +       if (kill)
22832 +               free_fs_struct(fs_cur);
22833 +
22834 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22835 +       if (IS_ERR(proxy_new)) {
22836 +               ret = PTR_ERR(proxy_new);
22837 +               goto out_put;
22838 +       }
22839 +
22840 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22841 +
22842 +       if (mask & CLONE_NEWUSER) {
22843 +               struct cred *cred;
22844 +
22845 +               vxdprintk(VXD_CBIT(space, 10),
22846 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22847 +                       vxi, vxi->vx_id, space->vx_cred,
22848 +                       current->real_cred, current->cred);
22849 +
22850 +               if (space->vx_cred) {
22851 +                       cred = __prepare_creds(space->vx_cred);
22852 +                       if (cred)
22853 +                               commit_creds(cred);
22854 +               }
22855 +       }
22856 +
22857 +       ret = 0;
22858 +
22859 +       if (proxy_new)
22860 +               put_nsproxy(proxy_new);
22861 +out_put:
22862 +       if (proxy_cur)
22863 +               put_nsproxy(proxy_cur);
22864 +       return ret;
22865 +}
22866 +
22867 +
22868 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22869 +{
22870 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22871 +       struct fs_struct *fs_vxi, *fs = NULL;
22872 +       struct _vx_space *space;
22873 +       int ret, kill = 0;
22874 +
22875 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22876 +               vxi, vxi->vx_id, mask, index);
22877 +
22878 +       if ((mask & space_mask.mask) != mask)
22879 +               return -EINVAL;
22880 +
22881 +       if (index >= VX_SPACES)
22882 +               return -EINVAL;
22883 +
22884 +       space = &vxi->space[index];
22885 +
22886 +       proxy_vxi = space->vx_nsproxy;
22887 +       fs_vxi = space->vx_fs;
22888 +
22889 +       if (mask & CLONE_FS) {
22890 +               fs = copy_fs_struct(current->fs);
22891 +               if (!fs)
22892 +                       return -ENOMEM;
22893 +       }
22894 +
22895 +       task_lock(current);
22896 +
22897 +       if (mask & CLONE_FS) {
22898 +               spin_lock(&fs_vxi->lock);
22899 +               space->vx_fs = fs;
22900 +               kill = !--fs_vxi->users;
22901 +               spin_unlock(&fs_vxi->lock);
22902 +       }
22903 +
22904 +       proxy_cur = current->nsproxy;
22905 +       get_nsproxy(proxy_cur);
22906 +       task_unlock(current);
22907 +
22908 +       if (kill)
22909 +               free_fs_struct(fs_vxi);
22910 +
22911 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22912 +       if (IS_ERR(proxy_new)) {
22913 +               ret = PTR_ERR(proxy_new);
22914 +               goto out_put;
22915 +       }
22916 +
22917 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22918 +       space->vx_nsmask |= mask;
22919 +
22920 +       if (mask & CLONE_NEWUSER) {
22921 +               struct cred *cred;
22922 +
22923 +               vxdprintk(VXD_CBIT(space, 10),
22924 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22925 +                       vxi, vxi->vx_id, space->vx_cred,
22926 +                       current->real_cred, current->cred);
22927 +
22928 +               cred = prepare_creds();
22929 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22930 +               if (cred)
22931 +                       abort_creds(cred);
22932 +       }
22933 +
22934 +       ret = 0;
22935 +
22936 +       if (proxy_new)
22937 +               put_nsproxy(proxy_new);
22938 +out_put:
22939 +       if (proxy_cur)
22940 +               put_nsproxy(proxy_cur);
22941 +       return ret;
22942 +}
22943 +
22944 +
22945 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22946 +{
22947 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22948 +
22949 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22950 +               return -EFAULT;
22951 +
22952 +       return vx_enter_space(vxi, vc_data.mask, 0);
22953 +}
22954 +
22955 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22956 +{
22957 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22958 +
22959 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22960 +               return -EFAULT;
22961 +
22962 +       if (vc_data.index >= VX_SPACES)
22963 +               return -EINVAL;
22964 +
22965 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22966 +}
22967 +
22968 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22969 +{
22970 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22971 +
22972 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22973 +               return -EFAULT;
22974 +
22975 +       return vx_set_space(vxi, vc_data.mask, 0);
22976 +}
22977 +
22978 +int vc_set_space(struct vx_info *vxi, void __user *data)
22979 +{
22980 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22981 +
22982 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22983 +               return -EFAULT;
22984 +
22985 +       if (vc_data.index >= VX_SPACES)
22986 +               return -EINVAL;
22987 +
22988 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22989 +}
22990 +
22991 +int vc_get_space_mask(void __user *data, int type)
22992 +{
22993 +       const struct vcmd_space_mask_v1 *mask;
22994 +
22995 +       if (type == 0)
22996 +               mask = &space_mask_v0;
22997 +       else if (type == 1)
22998 +               mask = &space_mask;
22999 +       else
23000 +               mask = &default_space_mask;
23001 +
23002 +       vxdprintk(VXD_CBIT(space, 10),
23003 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23004 +
23005 +       if (copy_to_user(data, mask, sizeof(*mask)))
23006 +               return -EFAULT;
23007 +       return 0;
23008 +}
23009 +
23010 diff -NurpP --minimal linux-3.7.1/kernel/vserver/switch.c linux-3.7.1-vs2.3.5.5/kernel/vserver/switch.c
23011 --- linux-3.7.1/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
23012 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/switch.c       2012-12-18 15:13:16.000000000 +0000
23013 @@ -0,0 +1,556 @@
23014 +/*
23015 + *  linux/kernel/vserver/switch.c
23016 + *
23017 + *  Virtual Server: Syscall Switch
23018 + *
23019 + *  Copyright (C) 2003-2011  Herbert Pötzl
23020 + *
23021 + *  V0.01  syscall switch
23022 + *  V0.02  added signal to context
23023 + *  V0.03  added rlimit functions
23024 + *  V0.04  added iattr, task/xid functions
23025 + *  V0.05  added debug/history stuff
23026 + *  V0.06  added compat32 layer
23027 + *  V0.07  vcmd args and perms
23028 + *  V0.08  added status commands
23029 + *  V0.09  added tag commands
23030 + *  V0.10  added oom bias
23031 + *  V0.11  added device commands
23032 + *  V0.12  added warn mask
23033 + *
23034 + */
23035 +
23036 +#include <linux/vs_context.h>
23037 +#include <linux/vs_network.h>
23038 +#include <linux/vserver/switch.h>
23039 +
23040 +#include "vci_config.h"
23041 +
23042 +
23043 +static inline
23044 +int vc_get_version(uint32_t id)
23045 +{
23046 +       return VCI_VERSION;
23047 +}
23048 +
23049 +static inline
23050 +int vc_get_vci(uint32_t id)
23051 +{
23052 +       return vci_kernel_config();
23053 +}
23054 +
23055 +#include <linux/vserver/context_cmd.h>
23056 +#include <linux/vserver/cvirt_cmd.h>
23057 +#include <linux/vserver/cacct_cmd.h>
23058 +#include <linux/vserver/limit_cmd.h>
23059 +#include <linux/vserver/network_cmd.h>
23060 +#include <linux/vserver/sched_cmd.h>
23061 +#include <linux/vserver/debug_cmd.h>
23062 +#include <linux/vserver/inode_cmd.h>
23063 +#include <linux/vserver/dlimit_cmd.h>
23064 +#include <linux/vserver/signal_cmd.h>
23065 +#include <linux/vserver/space_cmd.h>
23066 +#include <linux/vserver/tag_cmd.h>
23067 +#include <linux/vserver/device_cmd.h>
23068 +
23069 +#include <linux/vserver/inode.h>
23070 +#include <linux/vserver/dlimit.h>
23071 +
23072 +
23073 +#ifdef CONFIG_COMPAT
23074 +#define __COMPAT(name, id, data, compat)       \
23075 +       (compat) ? name ## _x32(id, data) : name(id, data)
23076 +#define __COMPAT_NO_ID(name, data, compat)     \
23077 +       (compat) ? name ## _x32(data) : name(data)
23078 +#else
23079 +#define __COMPAT(name, id, data, compat)       \
23080 +       name(id, data)
23081 +#define __COMPAT_NO_ID(name, data, compat)     \
23082 +       name(data)
23083 +#endif
23084 +
23085 +
23086 +static inline
23087 +long do_vcmd(uint32_t cmd, uint32_t id,
23088 +       struct vx_info *vxi, struct nx_info *nxi,
23089 +       void __user *data, int compat)
23090 +{
23091 +       switch (cmd) {
23092 +
23093 +       case VCMD_get_version:
23094 +               return vc_get_version(id);
23095 +       case VCMD_get_vci:
23096 +               return vc_get_vci(id);
23097 +
23098 +       case VCMD_task_xid:
23099 +               return vc_task_xid(id);
23100 +       case VCMD_vx_info:
23101 +               return vc_vx_info(vxi, data);
23102 +
23103 +       case VCMD_task_nid:
23104 +               return vc_task_nid(id);
23105 +       case VCMD_nx_info:
23106 +               return vc_nx_info(nxi, data);
23107 +
23108 +       case VCMD_task_tag:
23109 +               return vc_task_tag(id);
23110 +
23111 +       case VCMD_set_space_v1:
23112 +               return vc_set_space_v1(vxi, data);
23113 +       /* this is version 2 */
23114 +       case VCMD_set_space:
23115 +               return vc_set_space(vxi, data);
23116 +
23117 +       case VCMD_get_space_mask_v0:
23118 +               return vc_get_space_mask(data, 0);
23119 +       /* this is version 1 */
23120 +       case VCMD_get_space_mask:
23121 +               return vc_get_space_mask(data, 1);
23122 +
23123 +       case VCMD_get_space_default:
23124 +               return vc_get_space_mask(data, -1);
23125 +
23126 +       case VCMD_set_umask:
23127 +               return vc_set_umask(vxi, data);
23128 +
23129 +       case VCMD_get_umask:
23130 +               return vc_get_umask(vxi, data);
23131 +
23132 +       case VCMD_set_wmask:
23133 +               return vc_set_wmask(vxi, data);
23134 +
23135 +       case VCMD_get_wmask:
23136 +               return vc_get_wmask(vxi, data);
23137 +#ifdef CONFIG_IA32_EMULATION
23138 +       case VCMD_get_rlimit:
23139 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23140 +       case VCMD_set_rlimit:
23141 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23142 +#else
23143 +       case VCMD_get_rlimit:
23144 +               return vc_get_rlimit(vxi, data);
23145 +       case VCMD_set_rlimit:
23146 +               return vc_set_rlimit(vxi, data);
23147 +#endif
23148 +       case VCMD_get_rlimit_mask:
23149 +               return vc_get_rlimit_mask(id, data);
23150 +       case VCMD_reset_hits:
23151 +               return vc_reset_hits(vxi, data);
23152 +       case VCMD_reset_minmax:
23153 +               return vc_reset_minmax(vxi, data);
23154 +
23155 +       case VCMD_get_vhi_name:
23156 +               return vc_get_vhi_name(vxi, data);
23157 +       case VCMD_set_vhi_name:
23158 +               return vc_set_vhi_name(vxi, data);
23159 +
23160 +       case VCMD_ctx_stat:
23161 +               return vc_ctx_stat(vxi, data);
23162 +       case VCMD_virt_stat:
23163 +               return vc_virt_stat(vxi, data);
23164 +       case VCMD_sock_stat:
23165 +               return vc_sock_stat(vxi, data);
23166 +       case VCMD_rlimit_stat:
23167 +               return vc_rlimit_stat(vxi, data);
23168 +
23169 +       case VCMD_set_cflags:
23170 +               return vc_set_cflags(vxi, data);
23171 +       case VCMD_get_cflags:
23172 +               return vc_get_cflags(vxi, data);
23173 +
23174 +       /* this is version 1 */
23175 +       case VCMD_set_ccaps:
23176 +               return vc_set_ccaps(vxi, data);
23177 +       /* this is version 1 */
23178 +       case VCMD_get_ccaps:
23179 +               return vc_get_ccaps(vxi, data);
23180 +       case VCMD_set_bcaps:
23181 +               return vc_set_bcaps(vxi, data);
23182 +       case VCMD_get_bcaps:
23183 +               return vc_get_bcaps(vxi, data);
23184 +
23185 +       case VCMD_set_badness:
23186 +               return vc_set_badness(vxi, data);
23187 +       case VCMD_get_badness:
23188 +               return vc_get_badness(vxi, data);
23189 +
23190 +       case VCMD_set_nflags:
23191 +               return vc_set_nflags(nxi, data);
23192 +       case VCMD_get_nflags:
23193 +               return vc_get_nflags(nxi, data);
23194 +
23195 +       case VCMD_set_ncaps:
23196 +               return vc_set_ncaps(nxi, data);
23197 +       case VCMD_get_ncaps:
23198 +               return vc_get_ncaps(nxi, data);
23199 +
23200 +       case VCMD_set_prio_bias:
23201 +               return vc_set_prio_bias(vxi, data);
23202 +       case VCMD_get_prio_bias:
23203 +               return vc_get_prio_bias(vxi, data);
23204 +       case VCMD_add_dlimit:
23205 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23206 +       case VCMD_rem_dlimit:
23207 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23208 +       case VCMD_set_dlimit:
23209 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23210 +       case VCMD_get_dlimit:
23211 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23212 +
23213 +       case VCMD_ctx_kill:
23214 +               return vc_ctx_kill(vxi, data);
23215 +
23216 +       case VCMD_wait_exit:
23217 +               return vc_wait_exit(vxi, data);
23218 +
23219 +       case VCMD_get_iattr:
23220 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23221 +       case VCMD_set_iattr:
23222 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23223 +
23224 +       case VCMD_fget_iattr:
23225 +               return vc_fget_iattr(id, data);
23226 +       case VCMD_fset_iattr:
23227 +               return vc_fset_iattr(id, data);
23228 +
23229 +       case VCMD_enter_space_v0:
23230 +               return vc_enter_space_v1(vxi, NULL);
23231 +       case VCMD_enter_space_v1:
23232 +               return vc_enter_space_v1(vxi, data);
23233 +       /* this is version 2 */
23234 +       case VCMD_enter_space:
23235 +               return vc_enter_space(vxi, data);
23236 +
23237 +       case VCMD_ctx_create_v0:
23238 +               return vc_ctx_create(id, NULL);
23239 +       case VCMD_ctx_create:
23240 +               return vc_ctx_create(id, data);
23241 +       case VCMD_ctx_migrate_v0:
23242 +               return vc_ctx_migrate(vxi, NULL);
23243 +       case VCMD_ctx_migrate:
23244 +               return vc_ctx_migrate(vxi, data);
23245 +
23246 +       case VCMD_net_create_v0:
23247 +               return vc_net_create(id, NULL);
23248 +       case VCMD_net_create:
23249 +               return vc_net_create(id, data);
23250 +       case VCMD_net_migrate:
23251 +               return vc_net_migrate(nxi, data);
23252 +
23253 +       case VCMD_tag_migrate:
23254 +               return vc_tag_migrate(id);
23255 +
23256 +       case VCMD_net_add:
23257 +               return vc_net_add(nxi, data);
23258 +       case VCMD_net_remove:
23259 +               return vc_net_remove(nxi, data);
23260 +
23261 +       case VCMD_net_add_ipv4_v1:
23262 +               return vc_net_add_ipv4_v1(nxi, data);
23263 +       /* this is version 2 */
23264 +       case VCMD_net_add_ipv4:
23265 +               return vc_net_add_ipv4(nxi, data);
23266 +
23267 +       case VCMD_net_rem_ipv4_v1:
23268 +               return vc_net_rem_ipv4_v1(nxi, data);
23269 +       /* this is version 2 */
23270 +       case VCMD_net_rem_ipv4:
23271 +               return vc_net_rem_ipv4(nxi, data);
23272 +#ifdef CONFIG_IPV6
23273 +       case VCMD_net_add_ipv6:
23274 +               return vc_net_add_ipv6(nxi, data);
23275 +       case VCMD_net_remove_ipv6:
23276 +               return vc_net_remove_ipv6(nxi, data);
23277 +#endif
23278 +/*     case VCMD_add_match_ipv4:
23279 +               return vc_add_match_ipv4(nxi, data);
23280 +       case VCMD_get_match_ipv4:
23281 +               return vc_get_match_ipv4(nxi, data);
23282 +#ifdef CONFIG_IPV6
23283 +       case VCMD_add_match_ipv6:
23284 +               return vc_add_match_ipv6(nxi, data);
23285 +       case VCMD_get_match_ipv6:
23286 +               return vc_get_match_ipv6(nxi, data);
23287 +#endif */
23288 +
23289 +#ifdef CONFIG_VSERVER_DEVICE
23290 +       case VCMD_set_mapping:
23291 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23292 +       case VCMD_unset_mapping:
23293 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23294 +#endif
23295 +#ifdef CONFIG_VSERVER_HISTORY
23296 +       case VCMD_dump_history:
23297 +               return vc_dump_history(id);
23298 +       case VCMD_read_history:
23299 +               return __COMPAT(vc_read_history, id, data, compat);
23300 +#endif
23301 +       default:
23302 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23303 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23304 +       }
23305 +       return -ENOSYS;
23306 +}
23307 +
23308 +
23309 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23310 +       case VCMD_ ## vcmd: perm = _perm;               \
23311 +               args = _args; flags = _flags; break
23312 +
23313 +
23314 +#define VCA_NONE       0x00
23315 +#define VCA_VXI                0x01
23316 +#define VCA_NXI                0x02
23317 +
23318 +#define VCF_NONE       0x00
23319 +#define VCF_INFO       0x01
23320 +#define VCF_ADMIN      0x02
23321 +#define VCF_ARES       0x06    /* includes admin */
23322 +#define VCF_SETUP      0x08
23323 +
23324 +#define VCF_ZIDOK      0x10    /* zero id okay */
23325 +
23326 +
23327 +static inline
23328 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23329 +{
23330 +       long ret;
23331 +       int permit = -1, state = 0;
23332 +       int perm = -1, args = 0, flags = 0;
23333 +       struct vx_info *vxi = NULL;
23334 +       struct nx_info *nxi = NULL;
23335 +
23336 +       switch (cmd) {
23337 +       /* unpriviledged commands */
23338 +       __VCMD(get_version,      0, VCA_NONE,   0);
23339 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23340 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23341 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23342 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23343 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23344 +
23345 +       /* info commands */
23346 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23347 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23348 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23349 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23350 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23351 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23352 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23353 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23354 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23355 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23356 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23357 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23358 +
23359 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23360 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23361 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23362 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23363 +
23364 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23365 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23366 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23367 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23368 +
23369 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23370 +
23371 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23372 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23373 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23374 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23375 +
23376 +       /* lower admin commands */
23377 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23378 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23379 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23380 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23381 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23382 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23383 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23384 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23385 +
23386 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23387 +       __VCMD(net_create,       5, VCA_NONE,   0);
23388 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23389 +
23390 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23391 +
23392 +       /* higher admin commands */
23393 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23394 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23395 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23396 +
23397 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23398 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23399 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23400 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23401 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23402 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23403 +
23404 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23405 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23406 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23407 +
23408 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23409 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23410 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23411 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23412 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23413 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23414 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23415 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23416 +#ifdef CONFIG_IPV6
23417 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23418 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23419 +#endif
23420 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23421 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23422 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23423 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23424 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23425 +
23426 +#ifdef CONFIG_VSERVER_DEVICE
23427 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23428 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23429 +#endif
23430 +       /* debug level admin commands */
23431 +#ifdef CONFIG_VSERVER_HISTORY
23432 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23433 +       __VCMD(read_history,     9, VCA_NONE,   0);
23434 +#endif
23435 +
23436 +       default:
23437 +               perm = -1;
23438 +       }
23439 +
23440 +       vxdprintk(VXD_CBIT(switch, 0),
23441 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23442 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23443 +               VC_VERSION(cmd), id, data, compat,
23444 +               perm, args, flags);
23445 +
23446 +       ret = -ENOSYS;
23447 +       if (perm < 0)
23448 +               goto out;
23449 +
23450 +       state = 1;
23451 +       if (!capable(CAP_CONTEXT))
23452 +               goto out;
23453 +
23454 +       state = 2;
23455 +       /* moved here from the individual commands */
23456 +       ret = -EPERM;
23457 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23458 +               goto out;
23459 +
23460 +       state = 3;
23461 +       /* vcmd involves resource management  */
23462 +       ret = -EPERM;
23463 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23464 +               goto out;
23465 +
23466 +       state = 4;
23467 +       /* various legacy exceptions */
23468 +       switch (cmd) {
23469 +       /* will go away when spectator is a cap */
23470 +       case VCMD_ctx_migrate_v0:
23471 +       case VCMD_ctx_migrate:
23472 +               if (id == 1) {
23473 +                       current->xid = 1;
23474 +                       ret = 1;
23475 +                       goto out;
23476 +               }
23477 +               break;
23478 +
23479 +       /* will go away when spectator is a cap */
23480 +       case VCMD_net_migrate:
23481 +               if (id == 1) {
23482 +                       current->nid = 1;
23483 +                       ret = 1;
23484 +                       goto out;
23485 +               }
23486 +               break;
23487 +       }
23488 +
23489 +       /* vcmds are fine by default */
23490 +       permit = 1;
23491 +
23492 +       /* admin type vcmds require admin ... */
23493 +       if (flags & VCF_ADMIN)
23494 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23495 +
23496 +       /* ... but setup type vcmds override that */
23497 +       if (!permit && (flags & VCF_SETUP))
23498 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23499 +
23500 +       state = 5;
23501 +       ret = -EPERM;
23502 +       if (!permit)
23503 +               goto out;
23504 +
23505 +       state = 6;
23506 +       if (!id && (flags & VCF_ZIDOK))
23507 +               goto skip_id;
23508 +
23509 +       ret = -ESRCH;
23510 +       if (args & VCA_VXI) {
23511 +               vxi = lookup_vx_info(id);
23512 +               if (!vxi)
23513 +                       goto out;
23514 +
23515 +               if ((flags & VCF_ADMIN) &&
23516 +                       /* special case kill for shutdown */
23517 +                       (cmd != VCMD_ctx_kill) &&
23518 +                       /* can context be administrated? */
23519 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23520 +                       ret = -EACCES;
23521 +                       goto out_vxi;
23522 +               }
23523 +       }
23524 +       state = 7;
23525 +       if (args & VCA_NXI) {
23526 +               nxi = lookup_nx_info(id);
23527 +               if (!nxi)
23528 +                       goto out_vxi;
23529 +
23530 +               if ((flags & VCF_ADMIN) &&
23531 +                       /* can context be administrated? */
23532 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23533 +                       ret = -EACCES;
23534 +                       goto out_nxi;
23535 +               }
23536 +       }
23537 +skip_id:
23538 +       state = 8;
23539 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23540 +
23541 +out_nxi:
23542 +       if ((args & VCA_NXI) && nxi)
23543 +               put_nx_info(nxi);
23544 +out_vxi:
23545 +       if ((args & VCA_VXI) && vxi)
23546 +               put_vx_info(vxi);
23547 +out:
23548 +       vxdprintk(VXD_CBIT(switch, 1),
23549 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23550 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23551 +               VC_VERSION(cmd), ret, ret, state, permit);
23552 +       return ret;
23553 +}
23554 +
23555 +asmlinkage long
23556 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23557 +{
23558 +       return do_vserver(cmd, id, data, 0);
23559 +}
23560 +
23561 +#ifdef CONFIG_COMPAT
23562 +
23563 +asmlinkage long
23564 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23565 +{
23566 +       return do_vserver(cmd, id, data, 1);
23567 +}
23568 +
23569 +#endif /* CONFIG_COMPAT */
23570 diff -NurpP --minimal linux-3.7.1/kernel/vserver/sysctl.c linux-3.7.1-vs2.3.5.5/kernel/vserver/sysctl.c
23571 --- linux-3.7.1/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23572 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/sysctl.c       2012-12-18 15:13:16.000000000 +0000
23573 @@ -0,0 +1,247 @@
23574 +/*
23575 + *  kernel/vserver/sysctl.c
23576 + *
23577 + *  Virtual Context Support
23578 + *
23579 + *  Copyright (C) 2004-2007  Herbert Pötzl
23580 + *
23581 + *  V0.01  basic structure
23582 + *
23583 + */
23584 +
23585 +#include <linux/module.h>
23586 +#include <linux/ctype.h>
23587 +#include <linux/sysctl.h>
23588 +#include <linux/parser.h>
23589 +#include <asm/uaccess.h>
23590 +
23591 +enum {
23592 +       CTL_DEBUG_ERROR         = 0,
23593 +       CTL_DEBUG_SWITCH        = 1,
23594 +       CTL_DEBUG_XID,
23595 +       CTL_DEBUG_NID,
23596 +       CTL_DEBUG_TAG,
23597 +       CTL_DEBUG_NET,
23598 +       CTL_DEBUG_LIMIT,
23599 +       CTL_DEBUG_CRES,
23600 +       CTL_DEBUG_DLIM,
23601 +       CTL_DEBUG_QUOTA,
23602 +       CTL_DEBUG_CVIRT,
23603 +       CTL_DEBUG_SPACE,
23604 +       CTL_DEBUG_PERM,
23605 +       CTL_DEBUG_MISC,
23606 +};
23607 +
23608 +
23609 +unsigned int vs_debug_switch   = 0;
23610 +unsigned int vs_debug_xid      = 0;
23611 +unsigned int vs_debug_nid      = 0;
23612 +unsigned int vs_debug_tag      = 0;
23613 +unsigned int vs_debug_net      = 0;
23614 +unsigned int vs_debug_limit    = 0;
23615 +unsigned int vs_debug_cres     = 0;
23616 +unsigned int vs_debug_dlim     = 0;
23617 +unsigned int vs_debug_quota    = 0;
23618 +unsigned int vs_debug_cvirt    = 0;
23619 +unsigned int vs_debug_space    = 0;
23620 +unsigned int vs_debug_perm     = 0;
23621 +unsigned int vs_debug_misc     = 0;
23622 +
23623 +
23624 +static struct ctl_table_header *vserver_table_header;
23625 +static ctl_table vserver_root_table[];
23626 +
23627 +
23628 +void vserver_register_sysctl(void)
23629 +{
23630 +       if (!vserver_table_header) {
23631 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23632 +       }
23633 +
23634 +}
23635 +
23636 +void vserver_unregister_sysctl(void)
23637 +{
23638 +       if (vserver_table_header) {
23639 +               unregister_sysctl_table(vserver_table_header);
23640 +               vserver_table_header = NULL;
23641 +       }
23642 +}
23643 +
23644 +
23645 +static int proc_dodebug(ctl_table *table, int write,
23646 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23647 +{
23648 +       char            tmpbuf[20], *p, c;
23649 +       unsigned int    value;
23650 +       size_t          left, len;
23651 +
23652 +       if ((*ppos && !write) || !*lenp) {
23653 +               *lenp = 0;
23654 +               return 0;
23655 +       }
23656 +
23657 +       left = *lenp;
23658 +
23659 +       if (write) {
23660 +               if (!access_ok(VERIFY_READ, buffer, left))
23661 +                       return -EFAULT;
23662 +               p = (char *)buffer;
23663 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23664 +                       left--, p++;
23665 +               if (!left)
23666 +                       goto done;
23667 +
23668 +               if (left > sizeof(tmpbuf) - 1)
23669 +                       return -EINVAL;
23670 +               if (copy_from_user(tmpbuf, p, left))
23671 +                       return -EFAULT;
23672 +               tmpbuf[left] = '\0';
23673 +
23674 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23675 +                       value = 10 * value + (*p - '0');
23676 +               if (*p && !isspace(*p))
23677 +                       return -EINVAL;
23678 +               while (left && isspace(*p))
23679 +                       left--, p++;
23680 +               *(unsigned int *)table->data = value;
23681 +       } else {
23682 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23683 +                       return -EFAULT;
23684 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23685 +               if (len > left)
23686 +                       len = left;
23687 +               if (__copy_to_user(buffer, tmpbuf, len))
23688 +                       return -EFAULT;
23689 +               if ((left -= len) > 0) {
23690 +                       if (put_user('\n', (char *)buffer + len))
23691 +                               return -EFAULT;
23692 +                       left--;
23693 +               }
23694 +       }
23695 +
23696 +done:
23697 +       *lenp -= left;
23698 +       *ppos += *lenp;
23699 +       return 0;
23700 +}
23701 +
23702 +static int zero;
23703 +
23704 +#define        CTL_ENTRY(ctl, name)                            \
23705 +       {                                               \
23706 +               .procname       = #name,                \
23707 +               .data           = &vs_ ## name,         \
23708 +               .maxlen         = sizeof(int),          \
23709 +               .mode           = 0644,                 \
23710 +               .proc_handler   = &proc_dodebug,        \
23711 +               .extra1         = &zero,                \
23712 +               .extra2         = &zero,                \
23713 +       }
23714 +
23715 +static ctl_table vserver_debug_table[] = {
23716 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23717 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23718 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23719 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23720 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23721 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23722 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23723 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23724 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23725 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23726 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23727 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23728 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23729 +       { 0 }
23730 +};
23731 +
23732 +static ctl_table vserver_root_table[] = {
23733 +       {
23734 +               .procname       = "vserver",
23735 +               .mode           = 0555,
23736 +               .child          = vserver_debug_table
23737 +       },
23738 +       { 0 }
23739 +};
23740 +
23741 +
23742 +static match_table_t tokens = {
23743 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23744 +       { CTL_DEBUG_XID,        "xid=%x"        },
23745 +       { CTL_DEBUG_NID,        "nid=%x"        },
23746 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23747 +       { CTL_DEBUG_NET,        "net=%x"        },
23748 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23749 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23750 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23751 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23752 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23753 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23754 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23755 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23756 +       { CTL_DEBUG_ERROR,      NULL            }
23757 +};
23758 +
23759 +#define        HANDLE_CASE(id, name, val)                              \
23760 +       case CTL_DEBUG_ ## id:                                  \
23761 +               vs_debug_ ## name = val;                        \
23762 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23763 +               break
23764 +
23765 +
23766 +static int __init vs_debug_setup(char *str)
23767 +{
23768 +       char *p;
23769 +       int token;
23770 +
23771 +       printk("vs_debug_setup(%s)\n", str);
23772 +       while ((p = strsep(&str, ",")) != NULL) {
23773 +               substring_t args[MAX_OPT_ARGS];
23774 +               unsigned int value;
23775 +
23776 +               if (!*p)
23777 +                       continue;
23778 +
23779 +               token = match_token(p, tokens, args);
23780 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23781 +
23782 +               switch (token) {
23783 +               HANDLE_CASE(SWITCH, switch, value);
23784 +               HANDLE_CASE(XID,    xid,    value);
23785 +               HANDLE_CASE(NID,    nid,    value);
23786 +               HANDLE_CASE(TAG,    tag,    value);
23787 +               HANDLE_CASE(NET,    net,    value);
23788 +               HANDLE_CASE(LIMIT,  limit,  value);
23789 +               HANDLE_CASE(CRES,   cres,   value);
23790 +               HANDLE_CASE(DLIM,   dlim,   value);
23791 +               HANDLE_CASE(QUOTA,  quota,  value);
23792 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23793 +               HANDLE_CASE(SPACE,  space,  value);
23794 +               HANDLE_CASE(PERM,   perm,   value);
23795 +               HANDLE_CASE(MISC,   misc,   value);
23796 +               default:
23797 +                       return -EINVAL;
23798 +                       break;
23799 +               }
23800 +       }
23801 +       return 1;
23802 +}
23803 +
23804 +__setup("vsdebug=", vs_debug_setup);
23805 +
23806 +
23807 +
23808 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23809 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23810 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23811 +EXPORT_SYMBOL_GPL(vs_debug_net);
23812 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23813 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23814 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23815 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23816 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23817 +EXPORT_SYMBOL_GPL(vs_debug_space);
23818 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23819 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23820 +
23821 diff -NurpP --minimal linux-3.7.1/kernel/vserver/tag.c linux-3.7.1-vs2.3.5.5/kernel/vserver/tag.c
23822 --- linux-3.7.1/kernel/vserver/tag.c    1970-01-01 00:00:00.000000000 +0000
23823 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/tag.c  2012-12-18 15:13:16.000000000 +0000
23824 @@ -0,0 +1,63 @@
23825 +/*
23826 + *  linux/kernel/vserver/tag.c
23827 + *
23828 + *  Virtual Server: Shallow Tag Space
23829 + *
23830 + *  Copyright (C) 2007  Herbert Pötzl
23831 + *
23832 + *  V0.01  basic implementation
23833 + *
23834 + */
23835 +
23836 +#include <linux/sched.h>
23837 +#include <linux/vserver/debug.h>
23838 +#include <linux/vs_pid.h>
23839 +#include <linux/vs_tag.h>
23840 +
23841 +#include <linux/vserver/tag_cmd.h>
23842 +
23843 +
23844 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23845 +{
23846 +       if (!p)
23847 +               BUG();
23848 +
23849 +       vxdprintk(VXD_CBIT(tag, 5),
23850 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23851 +
23852 +       task_lock(p);
23853 +       p->tag = tag;
23854 +       task_unlock(p);
23855 +
23856 +       vxdprintk(VXD_CBIT(tag, 5),
23857 +               "moved task %p into [#%d]", p, tag);
23858 +       return 0;
23859 +}
23860 +
23861 +/* vserver syscall commands below here */
23862 +
23863 +/* taks xid and vx_info functions */
23864 +
23865 +
23866 +int vc_task_tag(uint32_t id)
23867 +{
23868 +       tag_t tag;
23869 +
23870 +       if (id) {
23871 +               struct task_struct *tsk;
23872 +               rcu_read_lock();
23873 +               tsk = find_task_by_real_pid(id);
23874 +               tag = (tsk) ? tsk->tag : -ESRCH;
23875 +               rcu_read_unlock();
23876 +       } else
23877 +               tag = dx_current_tag();
23878 +       return tag;
23879 +}
23880 +
23881 +
23882 +int vc_tag_migrate(uint32_t tag)
23883 +{
23884 +       return dx_migrate_task(current, tag & 0xFFFF);
23885 +}
23886 +
23887 +
23888 diff -NurpP --minimal linux-3.7.1/kernel/vserver/vci_config.h linux-3.7.1-vs2.3.5.5/kernel/vserver/vci_config.h
23889 --- linux-3.7.1/kernel/vserver/vci_config.h     1970-01-01 00:00:00.000000000 +0000
23890 +++ linux-3.7.1-vs2.3.5.5/kernel/vserver/vci_config.h   2012-12-18 15:13:16.000000000 +0000
23891 @@ -0,0 +1,80 @@
23892 +
23893 +/*  interface version */
23894 +
23895 +#define VCI_VERSION            0x00020308
23896 +
23897 +
23898 +enum {
23899 +       VCI_KCBIT_NO_DYNAMIC = 0,
23900 +
23901 +       VCI_KCBIT_PROC_SECURE = 4,
23902 +       /* VCI_KCBIT_HARDCPU = 5, */
23903 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23904 +       /* VCI_KCBIT_IDLETIME = 7, */
23905 +
23906 +       VCI_KCBIT_COWBL = 8,
23907 +       VCI_KCBIT_FULLCOWBL = 9,
23908 +       VCI_KCBIT_SPACES = 10,
23909 +       VCI_KCBIT_NETV2 = 11,
23910 +       VCI_KCBIT_MEMCG = 12,
23911 +       VCI_KCBIT_MEMCG_SWAP = 13,
23912 +
23913 +       VCI_KCBIT_DEBUG = 16,
23914 +       VCI_KCBIT_HISTORY = 20,
23915 +       VCI_KCBIT_TAGGED = 24,
23916 +       VCI_KCBIT_PPTAG = 28,
23917 +
23918 +       VCI_KCBIT_MORE = 31,
23919 +};
23920 +
23921 +
23922 +static inline uint32_t vci_kernel_config(void)
23923 +{
23924 +       return
23925 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23926 +
23927 +       /* configured features */
23928 +#ifdef CONFIG_VSERVER_PROC_SECURE
23929 +       (1 << VCI_KCBIT_PROC_SECURE) |
23930 +#endif
23931 +#ifdef CONFIG_VSERVER_COWBL
23932 +       (1 << VCI_KCBIT_COWBL) |
23933 +       (1 << VCI_KCBIT_FULLCOWBL) |
23934 +#endif
23935 +       (1 << VCI_KCBIT_SPACES) |
23936 +       (1 << VCI_KCBIT_NETV2) |
23937 +#ifdef CONFIG_MEMCG
23938 +       (1 << VCI_KCBIT_MEMCG) |
23939 +#endif
23940 +#ifdef CONFIG_MEMCG_SWAP
23941 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23942 +#endif
23943 +
23944 +       /* debug options */
23945 +#ifdef CONFIG_VSERVER_DEBUG
23946 +       (1 << VCI_KCBIT_DEBUG) |
23947 +#endif
23948 +#ifdef CONFIG_VSERVER_HISTORY
23949 +       (1 << VCI_KCBIT_HISTORY) |
23950 +#endif
23951 +
23952 +       /* inode context tagging */
23953 +#if    defined(CONFIG_TAGGING_NONE)
23954 +       (0 << VCI_KCBIT_TAGGED) |
23955 +#elif  defined(CONFIG_TAGGING_UID16)
23956 +       (1 << VCI_KCBIT_TAGGED) |
23957 +#elif  defined(CONFIG_TAGGING_GID16)
23958 +       (2 << VCI_KCBIT_TAGGED) |
23959 +#elif  defined(CONFIG_TAGGING_ID24)
23960 +       (3 << VCI_KCBIT_TAGGED) |
23961 +#elif  defined(CONFIG_TAGGING_INTERN)
23962 +       (4 << VCI_KCBIT_TAGGED) |
23963 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23964 +       (5 << VCI_KCBIT_TAGGED) |
23965 +#else
23966 +       (7 << VCI_KCBIT_TAGGED) |
23967 +#endif
23968 +       (1 << VCI_KCBIT_PPTAG) |
23969 +       0;
23970 +}
23971 +
23972 diff -NurpP --minimal linux-3.7.1/mm/memcontrol.c linux-3.7.1-vs2.3.5.5/mm/memcontrol.c
23973 --- linux-3.7.1/mm/memcontrol.c 2012-12-11 03:30:57.000000000 +0000
23974 +++ linux-3.7.1-vs2.3.5.5/mm/memcontrol.c       2012-12-18 15:13:16.000000000 +0000
23975 @@ -884,6 +884,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23976         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23977  }
23978  
23979 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23980 +{
23981 +       return res_counter_read_u64(&mem->res, member);
23982 +}
23983 +
23984 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23985 +{
23986 +       return res_counter_read_u64(&mem->memsw, member);
23987 +}
23988 +
23989 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23990 +{
23991 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23992 +}
23993 +
23994 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23995 +{
23996 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23997 +}
23998 +
23999 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24000 +{
24001 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24002 +}
24003 +
24004  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24005  {
24006         struct mem_cgroup *memcg = NULL;
24007 diff -NurpP --minimal linux-3.7.1/mm/oom_kill.c linux-3.7.1-vs2.3.5.5/mm/oom_kill.c
24008 --- linux-3.7.1/mm/oom_kill.c   2012-12-11 03:30:57.000000000 +0000
24009 +++ linux-3.7.1-vs2.3.5.5/mm/oom_kill.c 2012-12-18 15:13:16.000000000 +0000
24010 @@ -35,6 +35,8 @@
24011  #include <linux/freezer.h>
24012  #include <linux/ftrace.h>
24013  #include <linux/ratelimit.h>
24014 +#include <linux/reboot.h>
24015 +#include <linux/vs_context.h>
24016  
24017  #define CREATE_TRACE_POINTS
24018  #include <trace/events/oom.h>
24019 @@ -155,11 +157,18 @@ struct task_struct *find_lock_task_mm(st
24020  static bool oom_unkillable_task(struct task_struct *p,
24021                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
24022  {
24023 -       if (is_global_init(p))
24024 +       unsigned xid = vx_current_xid();
24025 +
24026 +       /* skip the init task, global and per guest */
24027 +       if (task_is_init(p))
24028                 return true;
24029         if (p->flags & PF_KTHREAD)
24030                 return true;
24031  
24032 +       /* skip other guest and host processes if oom in guest */
24033 +       if (xid && vx_task_xid(p) != xid)
24034 +               return true;
24035 +
24036         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24037         if (memcg && !task_in_mem_cgroup(p, memcg))
24038                 return true;
24039 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
24040                 dump_header(p, gfp_mask, order, memcg, nodemask);
24041  
24042         task_lock(p);
24043 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24044 -               message, task_pid_nr(p), p->comm, points);
24045 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24046 +               message, task_pid_nr(p), p->xid, p->comm, points);
24047         task_unlock(p);
24048  
24049         /*
24050 @@ -518,8 +527,8 @@ void oom_kill_process(struct task_struct
24051  
24052         /* mm cannot safely be dereferenced after task_unlock(victim) */
24053         mm = victim->mm;
24054 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24055 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
24056 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24057 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
24058                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
24059                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
24060         task_unlock(victim);
24061 @@ -589,6 +598,8 @@ int unregister_oom_notifier(struct notif
24062  }
24063  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24064  
24065 +long vs_oom_action(unsigned int);
24066 +
24067  /*
24068   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24069   * if a parallel OOM killing is already taking place that includes a zone in
24070 @@ -738,7 +749,12 @@ void out_of_memory(struct zonelist *zone
24071         /* Found nothing?!?! Either we hang forever, or we panic. */
24072         if (!p) {
24073                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24074 -               panic("Out of memory and no killable processes...\n");
24075 +
24076 +               /* avoid panic for guest OOM */
24077 +               if (vx_current_xid())
24078 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24079 +               else
24080 +                       panic("Out of memory and no killable processes...\n");
24081         }
24082         if (PTR_ERR(p) != -1UL) {
24083                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24084 diff -NurpP --minimal linux-3.7.1/mm/page_alloc.c linux-3.7.1-vs2.3.5.5/mm/page_alloc.c
24085 --- linux-3.7.1/mm/page_alloc.c 2012-12-11 03:30:57.000000000 +0000
24086 +++ linux-3.7.1-vs2.3.5.5/mm/page_alloc.c       2012-12-18 15:13:16.000000000 +0000
24087 @@ -58,6 +58,8 @@
24088  #include <linux/prefetch.h>
24089  #include <linux/migrate.h>
24090  #include <linux/page-debug-flags.h>
24091 +#include <linux/vs_base.h>
24092 +#include <linux/vs_limit.h>
24093  
24094  #include <asm/tlbflush.h>
24095  #include <asm/div64.h>
24096 @@ -2832,6 +2834,9 @@ void si_meminfo(struct sysinfo *val)
24097         val->totalhigh = totalhigh_pages;
24098         val->freehigh = nr_free_highpages();
24099         val->mem_unit = PAGE_SIZE;
24100 +
24101 +       if (vx_flags(VXF_VIRT_MEM, 0))
24102 +               vx_vsi_meminfo(val);
24103  }
24104  
24105  EXPORT_SYMBOL(si_meminfo);
24106 @@ -2852,6 +2857,9 @@ void si_meminfo_node(struct sysinfo *val
24107         val->freehigh = 0;
24108  #endif
24109         val->mem_unit = PAGE_SIZE;
24110 +
24111 +       if (vx_flags(VXF_VIRT_MEM, 0))
24112 +               vx_vsi_meminfo(val);
24113  }
24114  #endif
24115  
24116 diff -NurpP --minimal linux-3.7.1/mm/pgtable-generic.c linux-3.7.1-vs2.3.5.5/mm/pgtable-generic.c
24117 --- linux-3.7.1/mm/pgtable-generic.c    2012-12-11 03:30:57.000000000 +0000
24118 +++ linux-3.7.1-vs2.3.5.5/mm/pgtable-generic.c  2012-12-18 15:13:16.000000000 +0000
24119 @@ -6,6 +6,8 @@
24120   *  Copyright (C) 2010  Linus Torvalds
24121   */
24122  
24123 +#include <linux/mm.h>
24124 +
24125  #include <linux/pagemap.h>
24126  #include <asm/tlb.h>
24127  #include <asm-generic/pgtable.h>
24128 diff -NurpP --minimal linux-3.7.1/mm/shmem.c linux-3.7.1-vs2.3.5.5/mm/shmem.c
24129 --- linux-3.7.1/mm/shmem.c      2012-12-11 03:30:57.000000000 +0000
24130 +++ linux-3.7.1-vs2.3.5.5/mm/shmem.c    2012-12-18 15:13:16.000000000 +0000
24131 @@ -1820,7 +1820,7 @@ static int shmem_statfs(struct dentry *d
24132  {
24133         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24134  
24135 -       buf->f_type = TMPFS_MAGIC;
24136 +       buf->f_type = TMPFS_SUPER_MAGIC;
24137         buf->f_bsize = PAGE_CACHE_SIZE;
24138         buf->f_namelen = NAME_MAX;
24139         if (sbinfo->max_blocks) {
24140 @@ -2504,7 +2504,7 @@ int shmem_fill_super(struct super_block
24141         sb->s_maxbytes = MAX_LFS_FILESIZE;
24142         sb->s_blocksize = PAGE_CACHE_SIZE;
24143         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24144 -       sb->s_magic = TMPFS_MAGIC;
24145 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24146         sb->s_op = &shmem_ops;
24147         sb->s_time_gran = 1;
24148  #ifdef CONFIG_TMPFS_XATTR
24149 diff -NurpP --minimal linux-3.7.1/mm/slab.c linux-3.7.1-vs2.3.5.5/mm/slab.c
24150 --- linux-3.7.1/mm/slab.c       2012-12-11 03:30:57.000000000 +0000
24151 +++ linux-3.7.1-vs2.3.5.5/mm/slab.c     2012-12-18 15:13:16.000000000 +0000
24152 @@ -445,6 +445,8 @@ static void kmem_list3_init(struct kmem_
24153  #define STATS_INC_FREEMISS(x)  do { } while (0)
24154  #endif
24155  
24156 +#include "slab_vs.h"
24157 +
24158  #if DEBUG
24159  
24160  /*
24161 @@ -3479,6 +3481,7 @@ retry:
24162  
24163         obj = slab_get_obj(cachep, slabp, nodeid);
24164         check_slabp(cachep, slabp);
24165 +       vx_slab_alloc(cachep, flags);
24166         l3->free_objects--;
24167         /* move slabp to correct slabp list: */
24168         list_del(&slabp->list);
24169 @@ -3556,6 +3559,7 @@ slab_alloc_node(struct kmem_cache *cache
24170         /* ___cache_alloc_node can fall back to other nodes */
24171         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24172    out:
24173 +       vx_slab_alloc(cachep, flags);
24174         local_irq_restore(save_flags);
24175         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24176         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
24177 @@ -3746,6 +3750,7 @@ static inline void __cache_free(struct k
24178         check_irq_off();
24179         kmemleak_free_recursive(objp, cachep->flags);
24180         objp = cache_free_debugcheck(cachep, objp, caller);
24181 +       vx_slab_free(cachep);
24182  
24183         kmemcheck_slab_free(cachep, objp, cachep->object_size);
24184  
24185 diff -NurpP --minimal linux-3.7.1/mm/slab_vs.h linux-3.7.1-vs2.3.5.5/mm/slab_vs.h
24186 --- linux-3.7.1/mm/slab_vs.h    1970-01-01 00:00:00.000000000 +0000
24187 +++ linux-3.7.1-vs2.3.5.5/mm/slab_vs.h  2012-12-18 15:13:16.000000000 +0000
24188 @@ -0,0 +1,29 @@
24189 +
24190 +#include <linux/vserver/context.h>
24191 +
24192 +#include <linux/vs_context.h>
24193 +
24194 +static inline
24195 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24196 +{
24197 +       int what = gfp_zone(cachep->allocflags);
24198 +       struct vx_info *vxi = current_vx_info();
24199 +
24200 +       if (!vxi)
24201 +               return;
24202 +
24203 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
24204 +}
24205 +
24206 +static inline
24207 +void vx_slab_free(struct kmem_cache *cachep)
24208 +{
24209 +       int what = gfp_zone(cachep->allocflags);
24210 +       struct vx_info *vxi = current_vx_info();
24211 +
24212 +       if (!vxi)
24213 +               return;
24214 +
24215 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
24216 +}
24217 +
24218 diff -NurpP --minimal linux-3.7.1/mm/swapfile.c linux-3.7.1-vs2.3.5.5/mm/swapfile.c
24219 --- linux-3.7.1/mm/swapfile.c   2012-12-11 03:30:57.000000000 +0000
24220 +++ linux-3.7.1-vs2.3.5.5/mm/swapfile.c 2012-12-18 15:13:16.000000000 +0000
24221 @@ -39,6 +39,7 @@
24222  #include <asm/tlbflush.h>
24223  #include <linux/swapops.h>
24224  #include <linux/page_cgroup.h>
24225 +#include <linux/vs_base.h>
24226  
24227  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24228                                  unsigned char);
24229 @@ -1685,6 +1686,16 @@ static int swap_show(struct seq_file *sw
24230  
24231         if (si == SEQ_START_TOKEN) {
24232                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24233 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24234 +                       struct sysinfo si;
24235 +
24236 +                       vx_vsi_swapinfo(&si);
24237 +                       if (si.totalswap < (1 << 10))
24238 +                               return 0;
24239 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24240 +                               "hdv0", "partition", si.totalswap >> 10,
24241 +                               (si.totalswap - si.freeswap) >> 10, -1);
24242 +               }
24243                 return 0;
24244         }
24245  
24246 @@ -2112,6 +2123,8 @@ void si_swapinfo(struct sysinfo *val)
24247         val->freeswap = nr_swap_pages + nr_to_be_unused;
24248         val->totalswap = total_swap_pages + nr_to_be_unused;
24249         spin_unlock(&swap_lock);
24250 +       if (vx_flags(VXF_VIRT_MEM, 0))
24251 +               vx_vsi_swapinfo(val);
24252  }
24253  
24254  /*
24255 diff -NurpP --minimal linux-3.7.1/net/bridge/br_multicast.c linux-3.7.1-vs2.3.5.5/net/bridge/br_multicast.c
24256 --- linux-3.7.1/net/bridge/br_multicast.c       2012-12-11 03:30:57.000000000 +0000
24257 +++ linux-3.7.1-vs2.3.5.5/net/bridge/br_multicast.c     2012-12-18 15:13:16.000000000 +0000
24258 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24259         ip6h->hop_limit = 1;
24260         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24261         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24262 -                              &ip6h->saddr)) {
24263 +                              &ip6h->saddr, NULL)) {
24264                 kfree_skb(skb);
24265                 return NULL;
24266         }
24267 diff -NurpP --minimal linux-3.7.1/net/core/dev.c linux-3.7.1-vs2.3.5.5/net/core/dev.c
24268 --- linux-3.7.1/net/core/dev.c  2012-12-11 03:30:57.000000000 +0000
24269 +++ linux-3.7.1-vs2.3.5.5/net/core/dev.c        2012-12-18 15:13:16.000000000 +0000
24270 @@ -126,6 +126,7 @@
24271  #include <linux/in.h>
24272  #include <linux/jhash.h>
24273  #include <linux/random.h>
24274 +#include <linux/vs_inet.h>
24275  #include <trace/events/napi.h>
24276  #include <trace/events/net.h>
24277  #include <trace/events/skb.h>
24278 @@ -620,7 +621,8 @@ struct net_device *__dev_get_by_name(str
24279         struct hlist_head *head = dev_name_hash(net, name);
24280  
24281         hlist_for_each_entry(dev, p, head, name_hlist)
24282 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24283 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24284 +                   nx_dev_visible(current_nx_info(), dev))
24285                         return dev;
24286  
24287         return NULL;
24288 @@ -646,7 +648,8 @@ struct net_device *dev_get_by_name_rcu(s
24289         struct hlist_head *head = dev_name_hash(net, name);
24290  
24291         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24292 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24293 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24294 +                   nx_dev_visible(current_nx_info(), dev))
24295                         return dev;
24296  
24297         return NULL;
24298 @@ -697,7 +700,8 @@ struct net_device *__dev_get_by_index(st
24299         struct hlist_head *head = dev_index_hash(net, ifindex);
24300  
24301         hlist_for_each_entry(dev, p, head, index_hlist)
24302 -               if (dev->ifindex == ifindex)
24303 +               if ((dev->ifindex == ifindex) &&
24304 +                   nx_dev_visible(current_nx_info(), dev))
24305                         return dev;
24306  
24307         return NULL;
24308 @@ -715,7 +719,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24309   *     about locking. The caller must hold RCU lock.
24310   */
24311  
24312 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24313 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24314  {
24315         struct hlist_node *p;
24316         struct net_device *dev;
24317 @@ -727,6 +731,16 @@ struct net_device *dev_get_by_index_rcu(
24318  
24319         return NULL;
24320  }
24321 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24322 +
24323 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24324 +{
24325 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24326 +
24327 +       if (nx_dev_visible(current_nx_info(), dev))
24328 +               return dev;
24329 +       return NULL;
24330 +}
24331  EXPORT_SYMBOL(dev_get_by_index_rcu);
24332  
24333  
24334 @@ -775,7 +789,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24335  
24336         for_each_netdev_rcu(net, dev)
24337                 if (dev->type == type &&
24338 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24339 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24340 +                   nx_dev_visible(current_nx_info(), dev))
24341                         return dev;
24342  
24343         return NULL;
24344 @@ -787,9 +802,11 @@ struct net_device *__dev_getfirstbyhwtyp
24345         struct net_device *dev;
24346  
24347         ASSERT_RTNL();
24348 -       for_each_netdev(net, dev)
24349 -               if (dev->type == type)
24350 +       for_each_netdev(net, dev) {
24351 +               if ((dev->type == type) &&
24352 +                   nx_dev_visible(current_nx_info(), dev))
24353                         return dev;
24354 +       }
24355  
24356         return NULL;
24357  }
24358 @@ -907,6 +924,8 @@ static int __dev_alloc_name(struct net *
24359                                 continue;
24360                         if (i < 0 || i >= max_netdevices)
24361                                 continue;
24362 +                       if (!nx_dev_visible(current_nx_info(), d))
24363 +                               continue;
24364  
24365                         /*  avoid cases where sscanf is not exact inverse of printf */
24366                         snprintf(buf, IFNAMSIZ, name, i);
24367 @@ -4129,6 +4148,8 @@ static int dev_ifconf(struct net *net, c
24368  
24369         total = 0;
24370         for_each_netdev(net, dev) {
24371 +               if (!nx_dev_visible(current_nx_info(), dev))
24372 +                       continue;
24373                 for (i = 0; i < NPROTO; i++) {
24374                         if (gifconf_list[i]) {
24375                                 int done;
24376 @@ -4231,6 +4252,10 @@ static void dev_seq_printf_stats(struct
24377         struct rtnl_link_stats64 temp;
24378         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24379  
24380 +       /* device visible inside network context? */
24381 +       if (!nx_dev_visible(current_nx_info(), dev))
24382 +               return;
24383 +
24384         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24385                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24386                    dev->name, stats->rx_bytes, stats->rx_packets,
24387 diff -NurpP --minimal linux-3.7.1/net/core/rtnetlink.c linux-3.7.1-vs2.3.5.5/net/core/rtnetlink.c
24388 --- linux-3.7.1/net/core/rtnetlink.c    2012-12-11 03:30:57.000000000 +0000
24389 +++ linux-3.7.1-vs2.3.5.5/net/core/rtnetlink.c  2012-12-18 15:13:16.000000000 +0000
24390 @@ -1080,6 +1080,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24391                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24392                         if (idx < s_idx)
24393                                 goto cont;
24394 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24395 +                               continue;
24396                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24397                                              NETLINK_CB(cb->skb).portid,
24398                                              cb->nlh->nlmsg_seq, 0,
24399 @@ -1971,6 +1973,9 @@ void rtmsg_ifinfo(int type, struct net_d
24400         int err = -ENOBUFS;
24401         size_t if_info_size;
24402  
24403 +       if (!nx_dev_visible(current_nx_info(), dev))
24404 +               return;
24405 +
24406         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24407         if (skb == NULL)
24408                 goto errout;
24409 diff -NurpP --minimal linux-3.7.1/net/core/sock.c linux-3.7.1-vs2.3.5.5/net/core/sock.c
24410 --- linux-3.7.1/net/core/sock.c 2012-12-11 03:30:57.000000000 +0000
24411 +++ linux-3.7.1-vs2.3.5.5/net/core/sock.c       2012-12-18 15:13:16.000000000 +0000
24412 @@ -132,6 +132,10 @@
24413  #include <net/netprio_cgroup.h>
24414  
24415  #include <linux/filter.h>
24416 +#include <linux/vs_socket.h>
24417 +#include <linux/vs_limit.h>
24418 +#include <linux/vs_context.h>
24419 +#include <linux/vs_network.h>
24420  
24421  #include <trace/events/sock.h>
24422  
24423 @@ -1183,6 +1187,8 @@ static struct sock *sk_prot_alloc(struct
24424                         goto out_free_sec;
24425                 sk_tx_queue_clear(sk);
24426         }
24427 +               sock_vx_init(sk);
24428 +               sock_nx_init(sk);
24429  
24430         return sk;
24431  
24432 @@ -1295,6 +1301,11 @@ static void __sk_free(struct sock *sk)
24433                 put_cred(sk->sk_peer_cred);
24434         put_pid(sk->sk_peer_pid);
24435         put_net(sock_net(sk));
24436 +       vx_sock_dec(sk);
24437 +       clr_vx_info(&sk->sk_vx_info);
24438 +       sk->sk_xid = -1;
24439 +       clr_nx_info(&sk->sk_nx_info);
24440 +       sk->sk_nid = -1;
24441         sk_prot_free(sk->sk_prot_creator, sk);
24442  }
24443  
24444 @@ -1355,6 +1366,8 @@ struct sock *sk_clone_lock(const struct
24445  
24446                 /* SANITY */
24447                 get_net(sock_net(newsk));
24448 +               sock_vx_init(newsk);
24449 +               sock_nx_init(newsk);
24450                 sk_node_init(&newsk->sk_node);
24451                 sock_lock_init(newsk);
24452                 bh_lock_sock(newsk);
24453 @@ -1411,6 +1424,12 @@ struct sock *sk_clone_lock(const struct
24454                 smp_wmb();
24455                 atomic_set(&newsk->sk_refcnt, 2);
24456  
24457 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24458 +               newsk->sk_xid = sk->sk_xid;
24459 +               vx_sock_inc(newsk);
24460 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24461 +               newsk->sk_nid = sk->sk_nid;
24462 +
24463                 /*
24464                  * Increment the counter in the same struct proto as the master
24465                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24466 @@ -2206,6 +2225,12 @@ void sock_init_data(struct socket *sock,
24467  
24468         sk->sk_stamp = ktime_set(-1L, 0);
24469  
24470 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24471 +       sk->sk_xid = vx_current_xid();
24472 +       vx_sock_inc(sk);
24473 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24474 +       sk->sk_nid = nx_current_nid();
24475 +
24476         /*
24477          * Before updating sk_refcnt, we must commit prior changes to memory
24478          * (Documentation/RCU/rculist_nulls.txt for details)
24479 diff -NurpP --minimal linux-3.7.1/net/ipv4/af_inet.c linux-3.7.1-vs2.3.5.5/net/ipv4/af_inet.c
24480 --- linux-3.7.1/net/ipv4/af_inet.c      2012-12-11 03:30:57.000000000 +0000
24481 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/af_inet.c    2012-12-18 15:13:16.000000000 +0000
24482 @@ -118,6 +118,7 @@
24483  #ifdef CONFIG_IP_MROUTE
24484  #include <linux/mroute.h>
24485  #endif
24486 +#include <linux/vs_limit.h>
24487  
24488  
24489  /* The inetsw table contains everything that inet_create needs to
24490 @@ -346,9 +347,13 @@ lookup_protocol:
24491         }
24492  
24493         err = -EPERM;
24494 +       if ((protocol == IPPROTO_ICMP) &&
24495 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24496 +               goto override;
24497 +
24498         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24499                 goto out_rcu_unlock;
24500 -
24501 +override:
24502         err = -EAFNOSUPPORT;
24503         if (!inet_netns_ok(net, protocol))
24504                 goto out_rcu_unlock;
24505 @@ -473,6 +478,7 @@ int inet_bind(struct socket *sock, struc
24506         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24507         struct sock *sk = sock->sk;
24508         struct inet_sock *inet = inet_sk(sk);
24509 +       struct nx_v4_sock_addr nsa;
24510         unsigned short snum;
24511         int chk_addr_ret;
24512         int err;
24513 @@ -496,7 +502,11 @@ int inet_bind(struct socket *sock, struc
24514                         goto out;
24515         }
24516  
24517 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24518 +       err = v4_map_sock_addr(inet, addr, &nsa);
24519 +       if (err)
24520 +               goto out;
24521 +
24522 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24523  
24524         /* Not specified by any standard per-se, however it breaks too
24525          * many applications when removed.  It is unfortunate since
24526 @@ -508,7 +518,7 @@ int inet_bind(struct socket *sock, struc
24527         err = -EADDRNOTAVAIL;
24528         if (!sysctl_ip_nonlocal_bind &&
24529             !(inet->freebind || inet->transparent) &&
24530 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24531 +           nsa.saddr != htonl(INADDR_ANY) &&
24532             chk_addr_ret != RTN_LOCAL &&
24533             chk_addr_ret != RTN_MULTICAST &&
24534             chk_addr_ret != RTN_BROADCAST)
24535 @@ -533,7 +543,7 @@ int inet_bind(struct socket *sock, struc
24536         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24537                 goto out_release_sock;
24538  
24539 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24540 +       v4_set_sock_addr(inet, &nsa);
24541         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24542                 inet->inet_saddr = 0;  /* Use device */
24543  
24544 @@ -752,11 +762,13 @@ int inet_getname(struct socket *sock, st
24545                      peer == 1))
24546                         return -ENOTCONN;
24547                 sin->sin_port = inet->inet_dport;
24548 -               sin->sin_addr.s_addr = inet->inet_daddr;
24549 +               sin->sin_addr.s_addr =
24550 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24551         } else {
24552                 __be32 addr = inet->inet_rcv_saddr;
24553                 if (!addr)
24554                         addr = inet->inet_saddr;
24555 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24556                 sin->sin_port = inet->inet_sport;
24557                 sin->sin_addr.s_addr = addr;
24558         }
24559 diff -NurpP --minimal linux-3.7.1/net/ipv4/arp.c linux-3.7.1-vs2.3.5.5/net/ipv4/arp.c
24560 --- linux-3.7.1/net/ipv4/arp.c  2012-12-11 03:30:57.000000000 +0000
24561 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/arp.c        2012-12-18 15:13:16.000000000 +0000
24562 @@ -1318,6 +1318,7 @@ static void arp_format_neigh_entry(struc
24563         struct net_device *dev = n->dev;
24564         int hatype = dev->type;
24565  
24566 +       /* FIXME: check for network context */
24567         read_lock(&n->lock);
24568         /* Convert hardware address to XX:XX:XX:XX ... form. */
24569  #if IS_ENABLED(CONFIG_AX25)
24570 @@ -1349,6 +1350,7 @@ static void arp_format_pneigh_entry(stru
24571         int hatype = dev ? dev->type : 0;
24572         char tbuf[16];
24573  
24574 +       /* FIXME: check for network context */
24575         sprintf(tbuf, "%pI4", n->key);
24576         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24577                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24578 diff -NurpP --minimal linux-3.7.1/net/ipv4/devinet.c linux-3.7.1-vs2.3.5.5/net/ipv4/devinet.c
24579 --- linux-3.7.1/net/ipv4/devinet.c      2012-12-11 03:30:57.000000000 +0000
24580 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/devinet.c    2012-12-18 15:13:16.000000000 +0000
24581 @@ -513,6 +513,7 @@ struct in_device *inetdev_by_index(struc
24582  }
24583  EXPORT_SYMBOL(inetdev_by_index);
24584  
24585 +
24586  /* Called only from RTNL semaphored context. No locks. */
24587  
24588  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24589 @@ -754,6 +755,8 @@ int devinet_ioctl(struct net *net, unsig
24590  
24591         in_dev = __in_dev_get_rtnl(dev);
24592         if (in_dev) {
24593 +               struct nx_info *nxi = current_nx_info();
24594 +
24595                 if (tryaddrmatch) {
24596                         /* Matthias Andree */
24597                         /* compare label and address (4.4BSD style) */
24598 @@ -762,6 +765,8 @@ int devinet_ioctl(struct net *net, unsig
24599                            This is checked above. */
24600                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24601                              ifap = &ifa->ifa_next) {
24602 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24603 +                                       continue;
24604                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24605                                     sin_orig.sin_addr.s_addr ==
24606                                                         ifa->ifa_local) {
24607 @@ -774,9 +779,12 @@ int devinet_ioctl(struct net *net, unsig
24608                    comparing just the label */
24609                 if (!ifa) {
24610                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24611 -                            ifap = &ifa->ifa_next)
24612 +                            ifap = &ifa->ifa_next) {
24613 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24614 +                                       continue;
24615                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24616                                         break;
24617 +                       }
24618                 }
24619         }
24620  
24621 @@ -929,6 +937,8 @@ static int inet_gifconf(struct net_devic
24622                 goto out;
24623  
24624         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24625 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24626 +                       continue;
24627                 if (!buf) {
24628                         done += sizeof(ifr);
24629                         continue;
24630 @@ -1288,6 +1298,7 @@ static int inet_dump_ifaddr(struct sk_bu
24631         struct net_device *dev;
24632         struct in_device *in_dev;
24633         struct in_ifaddr *ifa;
24634 +       struct sock *sk = skb->sk;
24635         struct hlist_head *head;
24636         struct hlist_node *node;
24637  
24638 @@ -1310,6 +1321,8 @@ static int inet_dump_ifaddr(struct sk_bu
24639  
24640                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24641                              ifa = ifa->ifa_next, ip_idx++) {
24642 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24643 +                               continue;
24644                                 if (ip_idx < s_ip_idx)
24645                                         continue;
24646                                 if (inet_fill_ifaddr(skb, ifa,
24647 diff -NurpP --minimal linux-3.7.1/net/ipv4/fib_trie.c linux-3.7.1-vs2.3.5.5/net/ipv4/fib_trie.c
24648 --- linux-3.7.1/net/ipv4/fib_trie.c     2012-12-11 03:30:57.000000000 +0000
24649 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/fib_trie.c   2012-12-18 15:13:16.000000000 +0000
24650 @@ -2557,6 +2557,7 @@ static int fib_route_seq_show(struct seq
24651                             || fa->fa_type == RTN_MULTICAST)
24652                                 continue;
24653  
24654 +                       /* FIXME: check for network context? */
24655                         if (fi)
24656                                 seq_printf(seq,
24657                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24658 diff -NurpP --minimal linux-3.7.1/net/ipv4/inet_connection_sock.c linux-3.7.1-vs2.3.5.5/net/ipv4/inet_connection_sock.c
24659 --- linux-3.7.1/net/ipv4/inet_connection_sock.c 2012-12-11 03:30:57.000000000 +0000
24660 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/inet_connection_sock.c       2012-12-18 15:13:16.000000000 +0000
24661 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24662  }
24663  EXPORT_SYMBOL(inet_get_local_port_range);
24664  
24665 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24666 +{
24667 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24668 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24669 +
24670 +       if (inet_v6_ipv6only(sk2))
24671 +               return 0;
24672 +
24673 +       if (sk1_rcv_saddr &&
24674 +           sk2_rcv_saddr &&
24675 +           sk1_rcv_saddr == sk2_rcv_saddr)
24676 +               return 1;
24677 +
24678 +       if (sk1_rcv_saddr &&
24679 +           !sk2_rcv_saddr &&
24680 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24681 +               return 1;
24682 +
24683 +       if (sk2_rcv_saddr &&
24684 +           !sk1_rcv_saddr &&
24685 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24686 +               return 1;
24687 +
24688 +       if (!sk1_rcv_saddr &&
24689 +           !sk2_rcv_saddr &&
24690 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24691 +               return 1;
24692 +
24693 +       return 0;
24694 +}
24695 +
24696  int inet_csk_bind_conflict(const struct sock *sk,
24697                            const struct inet_bind_bucket *tb, bool relax)
24698  {
24699 @@ -75,9 +106,7 @@ int inet_csk_bind_conflict(const struct
24700                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24701                         if (!reuse || !sk2->sk_reuse ||
24702                             sk2->sk_state == TCP_LISTEN) {
24703 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24704 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24705 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24706 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24707                                         break;
24708                         }
24709                         if (!relax && reuse && sk2->sk_reuse &&
24710 diff -NurpP --minimal linux-3.7.1/net/ipv4/inet_diag.c linux-3.7.1-vs2.3.5.5/net/ipv4/inet_diag.c
24711 --- linux-3.7.1/net/ipv4/inet_diag.c    2012-12-11 03:30:57.000000000 +0000
24712 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/inet_diag.c  2012-12-18 15:13:16.000000000 +0000
24713 @@ -31,6 +31,8 @@
24714  
24715  #include <linux/inet.h>
24716  #include <linux/stddef.h>
24717 +#include <linux/vs_network.h>
24718 +#include <linux/vs_inet.h>
24719  
24720  #include <linux/inet_diag.h>
24721  #include <linux/sock_diag.h>
24722 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24723  
24724         r->id.idiag_sport = inet->inet_sport;
24725         r->id.idiag_dport = inet->inet_dport;
24726 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24727 -       r->id.idiag_dst[0] = inet->inet_daddr;
24728 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24729 +               inet->inet_rcv_saddr);
24730 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24731 +               inet->inet_daddr);
24732  
24733         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
24734          * hence this needs to be included regardless of socket family.
24735 @@ -239,8 +243,8 @@ static int inet_twsk_diag_fill(struct in
24736         sock_diag_save_cookie(tw, r->id.idiag_cookie);
24737         r->id.idiag_sport     = tw->tw_sport;
24738         r->id.idiag_dport     = tw->tw_dport;
24739 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24740 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24741 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24742 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24743         r->idiag_state        = tw->tw_substate;
24744         r->idiag_timer        = 3;
24745         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24746 @@ -284,12 +288,14 @@ int inet_diag_dump_one_icsk(struct inet_
24747  
24748         err = -EINVAL;
24749         if (req->sdiag_family == AF_INET) {
24750 +               /* TODO: lback */
24751                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24752                                  req->id.idiag_dport, req->id.idiag_src[0],
24753                                  req->id.idiag_sport, req->id.idiag_if);
24754         }
24755  #if IS_ENABLED(CONFIG_IPV6)
24756         else if (req->sdiag_family == AF_INET6) {
24757 +               /* TODO: lback */
24758                 sk = inet6_lookup(net, hashinfo,
24759                                   (struct in6_addr *)req->id.idiag_dst,
24760                                   req->id.idiag_dport,
24761 @@ -491,6 +497,7 @@ int inet_diag_bc_sk(const struct nlattr
24762         } else
24763  #endif
24764         {
24765 +                       /* TODO: lback */
24766                 entry.saddr = &inet->inet_rcv_saddr;
24767                 entry.daddr = &inet->inet_daddr;
24768         }
24769 @@ -649,6 +656,7 @@ static int inet_twsk_diag_dump(struct in
24770                 } else
24771  #endif
24772                 {
24773 +                       /* TODO: lback */
24774                         entry.saddr = &tw->tw_rcv_saddr;
24775                         entry.daddr = &tw->tw_daddr;
24776                 }
24777 @@ -727,8 +735,8 @@ static int inet_diag_fill_req(struct sk_
24778  
24779         r->id.idiag_sport = inet->inet_sport;
24780         r->id.idiag_dport = ireq->rmt_port;
24781 -       r->id.idiag_src[0] = ireq->loc_addr;
24782 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24783 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24784 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24785         r->idiag_expires = jiffies_to_msecs(tmo);
24786         r->idiag_rqueue = 0;
24787         r->idiag_wqueue = 0;
24788 @@ -791,6 +799,7 @@ static int inet_diag_dump_reqs(struct sk
24789                             r->id.idiag_dport)
24790                                 continue;
24791  
24792 +                       /* TODO: lback */
24793                         if (bc) {
24794                                 inet_diag_req_addrs(sk, req, &entry);
24795                                 entry.dport = ntohs(ireq->rmt_port);
24796 @@ -847,6 +856,8 @@ void inet_diag_dump_icsk(struct inet_has
24797                                 if (!net_eq(sock_net(sk), net))
24798                                         continue;
24799  
24800 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24801 +                                       continue;
24802                                 if (num < s_num) {
24803                                         num++;
24804                                         continue;
24805 @@ -919,6 +930,8 @@ skip_listen_ht:
24806  
24807                         if (!net_eq(sock_net(sk), net))
24808                                 continue;
24809 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24810 +                               continue;
24811                         if (num < s_num)
24812                                 goto next_normal;
24813                         if (!(r->idiag_states & (1 << sk->sk_state)))
24814 @@ -947,7 +960,8 @@ next_normal:
24815                                     &head->twchain) {
24816                                 if (!net_eq(twsk_net(tw), net))
24817                                         continue;
24818 -
24819 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24820 +                                       continue;
24821                                 if (num < s_num)
24822                                         goto next_dying;
24823                                 if (r->sdiag_family != AF_UNSPEC &&
24824 diff -NurpP --minimal linux-3.7.1/net/ipv4/inet_hashtables.c linux-3.7.1-vs2.3.5.5/net/ipv4/inet_hashtables.c
24825 --- linux-3.7.1/net/ipv4/inet_hashtables.c      2012-12-11 03:30:57.000000000 +0000
24826 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/inet_hashtables.c    2012-12-18 15:13:16.000000000 +0000
24827 @@ -22,6 +22,7 @@
24828  #include <net/inet_connection_sock.h>
24829  #include <net/inet_hashtables.h>
24830  #include <net/secure_seq.h>
24831 +#include <net/route.h>
24832  #include <net/ip.h>
24833  
24834  /*
24835 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24836                         if (rcv_saddr != daddr)
24837                                 return -1;
24838                         score += 2;
24839 +               } else {
24840 +                       /* block non nx_info ips */
24841 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24842 +                               daddr, NXA_MASK_BIND))
24843 +                               return -1;
24844                 }
24845                 if (sk->sk_bound_dev_if) {
24846                         if (sk->sk_bound_dev_if != dif)
24847 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24848   * wildcarded during the search since they can never be otherwise.
24849   */
24850  
24851 -
24852  struct sock *__inet_lookup_listener(struct net *net,
24853                                     struct inet_hashinfo *hashinfo,
24854                                     const __be32 daddr, const unsigned short hnum,
24855 @@ -196,6 +201,7 @@ begin:
24856                         hiscore = score;
24857                 }
24858         }
24859 +
24860         /*
24861          * if the nulls value we got at the end of this lookup is
24862          * not the expected one, we must restart lookup.
24863 diff -NurpP --minimal linux-3.7.1/net/ipv4/netfilter.c linux-3.7.1-vs2.3.5.5/net/ipv4/netfilter.c
24864 --- linux-3.7.1/net/ipv4/netfilter.c    2012-12-11 03:30:57.000000000 +0000
24865 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/netfilter.c  2012-12-18 15:13:16.000000000 +0000
24866 @@ -6,7 +6,7 @@
24867  #include <linux/skbuff.h>
24868  #include <linux/gfp.h>
24869  #include <linux/export.h>
24870 -#include <net/route.h>
24871 +// #include <net/route.h>
24872  #include <net/xfrm.h>
24873  #include <net/ip.h>
24874  #include <net/netfilter/nf_queue.h>
24875 diff -NurpP --minimal linux-3.7.1/net/ipv4/raw.c linux-3.7.1-vs2.3.5.5/net/ipv4/raw.c
24876 --- linux-3.7.1/net/ipv4/raw.c  2012-12-11 03:30:57.000000000 +0000
24877 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/raw.c        2012-12-18 15:13:16.000000000 +0000
24878 @@ -118,7 +118,7 @@ static struct sock *__raw_v4_lookup(stru
24879  
24880                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24881                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24882 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24883 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24884                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24885                         goto found; /* gotcha */
24886         }
24887 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
24888                 icmp_out_count(net, ((struct icmphdr *)
24889                         skb_transport_header(skb))->type);
24890  
24891 +       err = -EPERM;
24892 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24893 +               sk->sk_nx_info &&
24894 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24895 +               goto error_free;
24896 +
24897         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24898                       rt->dst.dev, dst_output);
24899         if (err > 0)
24900 @@ -582,6 +588,16 @@ static int raw_sendmsg(struct kiocb *ioc
24901                         goto done;
24902         }
24903  
24904 +       if (sk->sk_nx_info) {
24905 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24906 +               if (IS_ERR(rt)) {
24907 +                       err = PTR_ERR(rt);
24908 +                       rt = NULL;
24909 +                       goto done;
24910 +               }
24911 +               ip_rt_put(rt);
24912 +       }
24913 +
24914         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24915         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24916         if (IS_ERR(rt)) {
24917 @@ -658,17 +674,19 @@ static int raw_bind(struct sock *sk, str
24918  {
24919         struct inet_sock *inet = inet_sk(sk);
24920         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24921 +       struct nx_v4_sock_addr nsa = { 0 };
24922         int ret = -EINVAL;
24923         int chk_addr_ret;
24924  
24925         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24926                 goto out;
24927 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24928 +       v4_map_sock_addr(inet, addr, &nsa);
24929 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24930         ret = -EADDRNOTAVAIL;
24931 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24932 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24933             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24934                 goto out;
24935 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24936 +       v4_set_sock_addr(inet, &nsa);
24937         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24938                 inet->inet_saddr = 0;  /* Use device */
24939         sk_dst_reset(sk);
24940 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24941         /* Copy the address. */
24942         if (sin) {
24943                 sin->sin_family = AF_INET;
24944 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24945 +               sin->sin_addr.s_addr =
24946 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24947                 sin->sin_port = 0;
24948                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24949         }
24950 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24951                 struct hlist_node *node;
24952  
24953                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24954 -                       if (sock_net(sk) == seq_file_net(seq))
24955 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24956 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24957                                 goto found;
24958         }
24959         sk = NULL;
24960 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
24961                 sk = sk_next(sk);
24962  try_again:
24963                 ;
24964 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24965 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24966 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24967  
24968         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24969                 sk = sk_head(&state->h->ht[state->bucket]);
24970 diff -NurpP --minimal linux-3.7.1/net/ipv4/route.c linux-3.7.1-vs2.3.5.5/net/ipv4/route.c
24971 --- linux-3.7.1/net/ipv4/route.c        2012-12-11 03:30:57.000000000 +0000
24972 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/route.c      2012-12-18 15:13:16.000000000 +0000
24973 @@ -1952,7 +1952,7 @@ struct rtable *__ip_route_output_key(str
24974  
24975  
24976         if (fl4->flowi4_oif) {
24977 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24978 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24979                 rth = ERR_PTR(-ENODEV);
24980                 if (dev_out == NULL)
24981                         goto out;
24982 diff -NurpP --minimal linux-3.7.1/net/ipv4/tcp.c linux-3.7.1-vs2.3.5.5/net/ipv4/tcp.c
24983 --- linux-3.7.1/net/ipv4/tcp.c  2012-12-11 03:30:57.000000000 +0000
24984 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/tcp.c        2012-12-18 15:13:16.000000000 +0000
24985 @@ -268,6 +268,7 @@
24986  #include <linux/crypto.h>
24987  #include <linux/time.h>
24988  #include <linux/slab.h>
24989 +#include <linux/in.h>
24990  
24991  #include <net/icmp.h>
24992  #include <net/inet_common.h>
24993 diff -NurpP --minimal linux-3.7.1/net/ipv4/tcp_ipv4.c linux-3.7.1-vs2.3.5.5/net/ipv4/tcp_ipv4.c
24994 --- linux-3.7.1/net/ipv4/tcp_ipv4.c     2012-12-11 03:30:57.000000000 +0000
24995 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/tcp_ipv4.c   2012-12-18 15:13:16.000000000 +0000
24996 @@ -2264,6 +2264,12 @@ static void *listening_get_next(struct s
24997                 req = req->dl_next;
24998                 while (1) {
24999                         while (req) {
25000 +                               vxdprintk(VXD_CBIT(net, 6),
25001 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25002 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25003 +                               if (req->sk &&
25004 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25005 +                                       continue;
25006                                 if (req->rsk_ops->family == st->family) {
25007                                         cur = req;
25008                                         goto out;
25009 @@ -2288,6 +2294,10 @@ get_req:
25010         }
25011  get_sk:
25012         sk_nulls_for_each_from(sk, node) {
25013 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25014 +                       sk, sk->sk_nid, nx_current_nid());
25015 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25016 +                       continue;
25017                 if (!net_eq(sock_net(sk), net))
25018                         continue;
25019                 if (sk->sk_family == st->family) {
25020 @@ -2364,6 +2374,11 @@ static void *established_get_first(struc
25021  
25022                 spin_lock_bh(lock);
25023                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25024 +                       vxdprintk(VXD_CBIT(net, 6),
25025 +                               "sk,egf: %p [#%d] (from %d)",
25026 +                               sk, sk->sk_nid, nx_current_nid());
25027 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25028 +                               continue;
25029                         if (sk->sk_family != st->family ||
25030                             !net_eq(sock_net(sk), net)) {
25031                                 continue;
25032 @@ -2374,6 +2389,11 @@ static void *established_get_first(struc
25033                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25034                 inet_twsk_for_each(tw, node,
25035                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25036 +                       vxdprintk(VXD_CBIT(net, 6),
25037 +                               "tw: %p [#%d] (from %d)",
25038 +                               tw, tw->tw_nid, nx_current_nid());
25039 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25040 +                               continue;
25041                         if (tw->tw_family != st->family ||
25042                             !net_eq(twsk_net(tw), net)) {
25043                                 continue;
25044 @@ -2403,7 +2423,9 @@ static void *established_get_next(struct
25045                 tw = cur;
25046                 tw = tw_next(tw);
25047  get_tw:
25048 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25049 +               while (tw && (tw->tw_family != st->family ||
25050 +                       !net_eq(twsk_net(tw), net) ||
25051 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25052                         tw = tw_next(tw);
25053                 }
25054                 if (tw) {
25055 @@ -2427,6 +2449,11 @@ get_tw:
25056                 sk = sk_nulls_next(sk);
25057  
25058         sk_nulls_for_each_from(sk, node) {
25059 +               vxdprintk(VXD_CBIT(net, 6),
25060 +                       "sk,egn: %p [#%d] (from %d)",
25061 +                       sk, sk->sk_nid, nx_current_nid());
25062 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25063 +                       continue;
25064                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25065                         goto found;
25066         }
25067 @@ -2632,9 +2659,9 @@ static void get_openreq4(const struct so
25068         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25069                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
25070                 i,
25071 -               ireq->loc_addr,
25072 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25073                 ntohs(inet_sk(sk)->inet_sport),
25074 -               ireq->rmt_addr,
25075 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25076                 ntohs(ireq->rmt_port),
25077                 TCP_SYN_RECV,
25078                 0, 0, /* could print option size, but that is af dependent. */
25079 @@ -2657,8 +2684,8 @@ static void get_tcp4_sock(struct sock *s
25080         const struct inet_connection_sock *icsk = inet_csk(sk);
25081         const struct inet_sock *inet = inet_sk(sk);
25082         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
25083 -       __be32 dest = inet->inet_daddr;
25084 -       __be32 src = inet->inet_rcv_saddr;
25085 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25086 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25087         __u16 destp = ntohs(inet->inet_dport);
25088         __u16 srcp = ntohs(inet->inet_sport);
25089         int rx_queue;
25090 @@ -2714,8 +2741,8 @@ static void get_timewait4_sock(const str
25091         __u16 destp, srcp;
25092         long delta = tw->tw_ttd - jiffies;
25093  
25094 -       dest  = tw->tw_daddr;
25095 -       src   = tw->tw_rcv_saddr;
25096 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
25097 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
25098         destp = ntohs(tw->tw_dport);
25099         srcp  = ntohs(tw->tw_sport);
25100  
25101 diff -NurpP --minimal linux-3.7.1/net/ipv4/tcp_minisocks.c linux-3.7.1-vs2.3.5.5/net/ipv4/tcp_minisocks.c
25102 --- linux-3.7.1/net/ipv4/tcp_minisocks.c        2012-12-11 03:30:57.000000000 +0000
25103 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/tcp_minisocks.c      2012-12-18 15:13:16.000000000 +0000
25104 @@ -23,6 +23,9 @@
25105  #include <linux/slab.h>
25106  #include <linux/sysctl.h>
25107  #include <linux/workqueue.h>
25108 +#include <linux/vs_limit.h>
25109 +#include <linux/vs_socket.h>
25110 +#include <linux/vs_context.h>
25111  #include <net/tcp.h>
25112  #include <net/inet_common.h>
25113  #include <net/xfrm.h>
25114 @@ -289,6 +292,11 @@ void tcp_time_wait(struct sock *sk, int
25115                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25116                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25117  
25118 +               tw->tw_xid              = sk->sk_xid;
25119 +               tw->tw_vx_info          = NULL;
25120 +               tw->tw_nid              = sk->sk_nid;
25121 +               tw->tw_nx_info          = NULL;
25122 +
25123  #if IS_ENABLED(CONFIG_IPV6)
25124                 if (tw->tw_family == PF_INET6) {
25125                         struct ipv6_pinfo *np = inet6_sk(sk);
25126 diff -NurpP --minimal linux-3.7.1/net/ipv4/udp.c linux-3.7.1-vs2.3.5.5/net/ipv4/udp.c
25127 --- linux-3.7.1/net/ipv4/udp.c  2012-12-11 03:30:57.000000000 +0000
25128 +++ linux-3.7.1-vs2.3.5.5/net/ipv4/udp.c        2012-12-18 15:13:16.000000000 +0000
25129 @@ -300,14 +300,7 @@ fail:
25130  }
25131  EXPORT_SYMBOL(udp_lib_get_port);
25132  
25133 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25134 -{
25135 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25136 -
25137 -       return  (!ipv6_only_sock(sk2)  &&
25138 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25139 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25140 -}
25141 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25142  
25143  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25144                                        unsigned int port)
25145 @@ -342,6 +335,11 @@ static inline int compute_score(struct s
25146                         if (inet->inet_rcv_saddr != daddr)
25147                                 return -1;
25148                         score += 2;
25149 +               } else {
25150 +                       /* block non nx_info ips */
25151 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25152 +                               daddr, NXA_MASK_BIND))
25153 +                               return -1;
25154                 }
25155                 if (inet->inet_daddr) {
25156                         if (inet->inet_daddr != saddr)
25157 @@ -445,6 +443,7 @@ exact_match:
25158         return result;
25159  }
25160  
25161 +
25162  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25163   * harder than this. -DaveM
25164   */
25165 @@ -490,6 +489,11 @@ begin:
25166         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25167                 score = compute_score(sk, net, saddr, hnum, sport,
25168                                       daddr, dport, dif);
25169 +               /* FIXME: disabled?
25170 +               if (score == 9) {
25171 +                       result = sk;
25172 +                       break;
25173 +               } else */
25174                 if (score > badness) {
25175                         result = sk;
25176                         badness = score;
25177 @@ -503,6 +507,7 @@ begin:
25178         if (get_nulls_value(node) != slot)
25179                 goto begin;
25180  
25181 +
25182         if (result) {
25183                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25184                         result = NULL;
25185 @@ -512,6 +517,7 @@ begin:
25186                         goto begin;
25187                 }
25188         }
25189 +
25190         rcu_read_unlock();
25191         return result;
25192  }
25193 @@ -555,8 +561,7 @@ static inline struct sock *udp_v4_mcast_
25194                     udp_sk(s)->udp_port_hash != hnum ||
25195                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25196                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25197 -                   (inet->inet_rcv_saddr &&
25198 -                    inet->inet_rcv_saddr != loc_addr) ||
25199 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25200                     ipv6_only_sock(s) ||
25201                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25202                         continue;
25203 @@ -939,6 +944,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25204                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25205                                    faddr, saddr, dport, inet->inet_sport);
25206  
25207 +               if (sk->sk_nx_info) {
25208 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25209 +                       if (IS_ERR(rt)) {
25210 +                               err = PTR_ERR(rt);
25211 +                               rt = NULL;
25212 +                               goto out;
25213 +                       }
25214 +                       ip_rt_put(rt);
25215 +               }
25216 +
25217                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25218                 rt = ip_route_output_flow(net, fl4, sk);
25219                 if (IS_ERR(rt)) {
25220 @@ -1244,7 +1259,8 @@ try_again:
25221         if (sin) {
25222                 sin->sin_family = AF_INET;
25223                 sin->sin_port = udp_hdr(skb)->source;
25224 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25225 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25226 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25227                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25228         }
25229         if (inet->cmsg_flags)
25230 @@ -1992,6 +2008,8 @@ static struct sock *udp_get_first(struct
25231                 sk_nulls_for_each(sk, node, &hslot->head) {
25232                         if (!net_eq(sock_net(sk), net))
25233                                 continue;
25234 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25235 +                               continue;
25236                         if (sk->sk_family == state->family)
25237                                 goto found;
25238                 }
25239 @@ -2009,7 +2027,9 @@ static struct sock *udp_get_next(struct
25240  
25241         do {
25242                 sk = sk_nulls_next(sk);
25243 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25244 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25245 +               sk->sk_family != state->family ||
25246 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25247  
25248         if (!sk) {
25249                 if (state->bucket <= state->udp_table->mask)
25250 @@ -2105,8 +2125,8 @@ static void udp4_format_sock(struct sock
25251                 int bucket, int *len)
25252  {
25253         struct inet_sock *inet = inet_sk(sp);
25254 -       __be32 dest = inet->inet_daddr;
25255 -       __be32 src  = inet->inet_rcv_saddr;
25256 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25257 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25258         __u16 destp       = ntohs(inet->inet_dport);
25259         __u16 srcp        = ntohs(inet->inet_sport);
25260  
25261 diff -NurpP --minimal linux-3.7.1/net/ipv6/Kconfig linux-3.7.1-vs2.3.5.5/net/ipv6/Kconfig
25262 --- linux-3.7.1/net/ipv6/Kconfig        2012-12-11 03:30:57.000000000 +0000
25263 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/Kconfig      2012-12-18 15:13:16.000000000 +0000
25264 @@ -4,8 +4,8 @@
25265  
25266  #   IPv6 as module will cause a CRASH if you try to unload it
25267  menuconfig IPV6
25268 -       tristate "The IPv6 protocol"
25269 -       default m
25270 +       bool "The IPv6 protocol"
25271 +       default n
25272         ---help---
25273           This is complemental support for the IP version 6.
25274           You will still be able to do traditional IPv4 networking as well.
25275 diff -NurpP --minimal linux-3.7.1/net/ipv6/addrconf.c linux-3.7.1-vs2.3.5.5/net/ipv6/addrconf.c
25276 --- linux-3.7.1/net/ipv6/addrconf.c     2012-12-11 03:30:57.000000000 +0000
25277 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/addrconf.c   2012-12-18 15:13:16.000000000 +0000
25278 @@ -92,6 +92,8 @@
25279  #include <linux/proc_fs.h>
25280  #include <linux/seq_file.h>
25281  #include <linux/export.h>
25282 +#include <linux/vs_network.h>
25283 +#include <linux/vs_inet6.h>
25284  
25285  /* Set to 3 to get tracing... */
25286  #define ACONF_DEBUG 2
25287 @@ -1094,7 +1096,7 @@ out:
25288  
25289  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25290                        const struct in6_addr *daddr, unsigned int prefs,
25291 -                      struct in6_addr *saddr)
25292 +                      struct in6_addr *saddr, struct nx_info *nxi)
25293  {
25294         struct ipv6_saddr_score scores[2],
25295                                 *score = &scores[0], *hiscore = &scores[1];
25296 @@ -1166,6 +1168,8 @@ int ipv6_dev_get_saddr(struct net *net,
25297                                                dev->name);
25298                                 continue;
25299                         }
25300 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25301 +                               continue;
25302  
25303                         score->rule = -1;
25304                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25305 @@ -3135,7 +3139,10 @@ static void if6_seq_stop(struct seq_file
25306  static int if6_seq_show(struct seq_file *seq, void *v)
25307  {
25308         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25309 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25310 +
25311 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25312 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25313 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25314                    &ifp->addr,
25315                    ifp->idev->dev->ifindex,
25316                    ifp->prefix_len,
25317 @@ -3641,6 +3648,11 @@ static int in6_dump_addrs(struct inet6_d
25318         struct ifacaddr6 *ifaca;
25319         int err = 1;
25320         int ip_idx = *p_ip_idx;
25321 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25322 +
25323 +       /* disable ipv6 on non v6 guests */
25324 +       if (nxi && !nx_info_has_v6(nxi))
25325 +               return skb->len;
25326  
25327         read_lock_bh(&idev->lock);
25328         switch (type) {
25329 @@ -3651,6 +3663,8 @@ static int in6_dump_addrs(struct inet6_d
25330                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25331                         if (++ip_idx < s_ip_idx)
25332                                 continue;
25333 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25334 +                                       continue;
25335                         err = inet6_fill_ifaddr(skb, ifa,
25336                                                 NETLINK_CB(cb->skb).portid,
25337                                                 cb->nlh->nlmsg_seq,
25338 @@ -3667,6 +3681,8 @@ static int in6_dump_addrs(struct inet6_d
25339                      ifmca = ifmca->next, ip_idx++) {
25340                         if (ip_idx < s_ip_idx)
25341                                 continue;
25342 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25343 +                                       continue;
25344                         err = inet6_fill_ifmcaddr(skb, ifmca,
25345                                                   NETLINK_CB(cb->skb).portid,
25346                                                   cb->nlh->nlmsg_seq,
25347 @@ -3682,6 +3698,8 @@ static int in6_dump_addrs(struct inet6_d
25348                      ifaca = ifaca->aca_next, ip_idx++) {
25349                         if (ip_idx < s_ip_idx)
25350                                 continue;
25351 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25352 +                                       continue;
25353                         err = inet6_fill_ifacaddr(skb, ifaca,
25354                                                   NETLINK_CB(cb->skb).portid,
25355                                                   cb->nlh->nlmsg_seq,
25356 @@ -4065,6 +4083,11 @@ static int inet6_dump_ifinfo(struct sk_b
25357         struct inet6_dev *idev;
25358         struct hlist_head *head;
25359         struct hlist_node *node;
25360 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25361 +
25362 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25363 +       if (skb->sk && skb->sk->sk_vx_info)
25364 +               return skb->len; */
25365  
25366         s_h = cb->args[0];
25367         s_idx = cb->args[1];
25368 @@ -4076,6 +4099,8 @@ static int inet6_dump_ifinfo(struct sk_b
25369                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25370                         if (idx < s_idx)
25371                                 goto cont;
25372 +                       if (!v6_dev_in_nx_info(dev, nxi))
25373 +                               goto cont;
25374                         idev = __in6_dev_get(dev);
25375                         if (!idev)
25376                                 goto cont;
25377 diff -NurpP --minimal linux-3.7.1/net/ipv6/af_inet6.c linux-3.7.1-vs2.3.5.5/net/ipv6/af_inet6.c
25378 --- linux-3.7.1/net/ipv6/af_inet6.c     2012-12-11 03:30:57.000000000 +0000
25379 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/af_inet6.c   2012-12-18 15:13:16.000000000 +0000
25380 @@ -43,6 +43,8 @@
25381  #include <linux/netdevice.h>
25382  #include <linux/icmpv6.h>
25383  #include <linux/netfilter_ipv6.h>
25384 +#include <linux/vs_inet.h>
25385 +#include <linux/vs_inet6.h>
25386  
25387  #include <net/ip.h>
25388  #include <net/ipv6.h>
25389 @@ -160,9 +162,12 @@ lookup_protocol:
25390         }
25391  
25392         err = -EPERM;
25393 +       if ((protocol == IPPROTO_ICMPV6) &&
25394 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25395 +               goto override;
25396         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25397                 goto out_rcu_unlock;
25398 -
25399 +override:
25400         sock->ops = answer->ops;
25401         answer_prot = answer->prot;
25402         answer_no_check = answer->no_check;
25403 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25404         struct inet_sock *inet = inet_sk(sk);
25405         struct ipv6_pinfo *np = inet6_sk(sk);
25406         struct net *net = sock_net(sk);
25407 +       struct nx_v6_sock_addr nsa;
25408         __be32 v4addr = 0;
25409         unsigned short snum;
25410         int addr_type = 0;
25411 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25412         if (addr->sin6_family != AF_INET6)
25413                 return -EAFNOSUPPORT;
25414  
25415 +       err = v6_map_sock_addr(inet, addr, &nsa);
25416 +       if (err)
25417 +               return err;
25418 +
25419         addr_type = ipv6_addr_type(&addr->sin6_addr);
25420         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25421                 return -EINVAL;
25422 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25423                 /* Reproduce AF_INET checks to make the bindings consistent */
25424                 v4addr = addr->sin6_addr.s6_addr32[3];
25425                 chk_addr_ret = inet_addr_type(net, v4addr);
25426 +
25427                 if (!sysctl_ip_nonlocal_bind &&
25428                     !(inet->freebind || inet->transparent) &&
25429                     v4addr != htonl(INADDR_ANY) &&
25430 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25431                         err = -EADDRNOTAVAIL;
25432                         goto out;
25433                 }
25434 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25435 +                       err = -EADDRNOTAVAIL;
25436 +                       goto out;
25437 +               }
25438         } else {
25439                 if (addr_type != IPV6_ADDR_ANY) {
25440                         struct net_device *dev = NULL;
25441 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25442                                 }
25443                         }
25444  
25445 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25446 +                               err = -EADDRNOTAVAIL;
25447 +                               goto out_unlock;
25448 +                       }
25449 +
25450                         /* ipv4 addr of the socket is invalid.  Only the
25451                          * unspecified and mapped address have a v4 equivalent.
25452                          */
25453 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25454                 }
25455         }
25456  
25457 +       /* what's that for? */
25458 +       v6_set_sock_addr(inet, &nsa);
25459 +
25460         inet->inet_rcv_saddr = v4addr;
25461         inet->inet_saddr = v4addr;
25462  
25463 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25464                         return -ENOTCONN;
25465                 sin->sin6_port = inet->inet_dport;
25466                 sin->sin6_addr = np->daddr;
25467 +               /* FIXME: remap lback? */
25468                 if (np->sndflow)
25469                         sin->sin6_flowinfo = np->flow_label;
25470         } else {
25471 +               /* FIXME: remap lback? */
25472                 if (ipv6_addr_any(&np->rcv_saddr))
25473                         sin->sin6_addr = np->saddr;
25474                 else
25475 diff -NurpP --minimal linux-3.7.1/net/ipv6/datagram.c linux-3.7.1-vs2.3.5.5/net/ipv6/datagram.c
25476 --- linux-3.7.1/net/ipv6/datagram.c     2012-12-11 03:30:57.000000000 +0000
25477 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/datagram.c   2012-12-18 15:13:16.000000000 +0000
25478 @@ -645,7 +645,7 @@ int datagram_send_ctl(struct net *net, s
25479  
25480                         rcu_read_lock();
25481                         if (fl6->flowi6_oif) {
25482 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25483 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25484                                 if (!dev) {
25485                                         rcu_read_unlock();
25486                                         return -ENODEV;
25487 diff -NurpP --minimal linux-3.7.1/net/ipv6/fib6_rules.c linux-3.7.1-vs2.3.5.5/net/ipv6/fib6_rules.c
25488 --- linux-3.7.1/net/ipv6/fib6_rules.c   2012-12-11 03:30:57.000000000 +0000
25489 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/fib6_rules.c 2012-12-18 15:13:16.000000000 +0000
25490 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25491                                                ip6_dst_idev(&rt->dst)->dev,
25492                                                &flp6->daddr,
25493                                                rt6_flags2srcprefs(flags),
25494 -                                              &saddr))
25495 +                                              &saddr, NULL))
25496                                 goto again;
25497                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25498                                                r->src.plen))
25499 diff -NurpP --minimal linux-3.7.1/net/ipv6/inet6_hashtables.c linux-3.7.1-vs2.3.5.5/net/ipv6/inet6_hashtables.c
25500 --- linux-3.7.1/net/ipv6/inet6_hashtables.c     2012-12-11 03:30:57.000000000 +0000
25501 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/inet6_hashtables.c   2012-12-18 15:13:16.000000000 +0000
25502 @@ -16,6 +16,7 @@
25503  
25504  #include <linux/module.h>
25505  #include <linux/random.h>
25506 +#include <linux/vs_inet6.h>
25507  
25508  #include <net/inet_connection_sock.h>
25509  #include <net/inet_hashtables.h>
25510 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25511         unsigned int slot = hash & hashinfo->ehash_mask;
25512         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25513  
25514 -
25515         rcu_read_lock();
25516  begin:
25517         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25518 @@ -95,7 +95,7 @@ begin:
25519                                 sock_put(sk);
25520                                 goto begin;
25521                         }
25522 -               goto out;
25523 +                       goto out;
25524                 }
25525         }
25526         if (get_nulls_value(node) != slot)
25527 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25528                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25529                                 return -1;
25530                         score++;
25531 +               } else {
25532 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25533 +                               return -1;
25534                 }
25535                 if (sk->sk_bound_dev_if) {
25536                         if (sk->sk_bound_dev_if != dif)
25537 diff -NurpP --minimal linux-3.7.1/net/ipv6/ip6_output.c linux-3.7.1-vs2.3.5.5/net/ipv6/ip6_output.c
25538 --- linux-3.7.1/net/ipv6/ip6_output.c   2012-12-11 03:30:57.000000000 +0000
25539 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/ip6_output.c 2012-12-18 15:13:16.000000000 +0000
25540 @@ -964,7 +964,8 @@ static int ip6_dst_lookup_tail(struct so
25541                 struct rt6_info *rt = (struct rt6_info *) *dst;
25542                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25543                                           sk ? inet6_sk(sk)->srcprefs : 0,
25544 -                                         &fl6->saddr);
25545 +                                         &fl6->saddr,
25546 +                                         sk ? sk->sk_nx_info : NULL);
25547                 if (err)
25548                         goto out_err_release;
25549         }
25550 diff -NurpP --minimal linux-3.7.1/net/ipv6/ndisc.c linux-3.7.1-vs2.3.5.5/net/ipv6/ndisc.c
25551 --- linux-3.7.1/net/ipv6/ndisc.c        2012-12-11 03:30:57.000000000 +0000
25552 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/ndisc.c      2012-12-18 15:13:16.000000000 +0000
25553 @@ -517,7 +517,7 @@ static void ndisc_send_na(struct net_dev
25554         } else {
25555                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25556                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25557 -                                      &tmpaddr))
25558 +                                      &tmpaddr, NULL))
25559                         return;
25560                 src_addr = &tmpaddr;
25561         }
25562 diff -NurpP --minimal linux-3.7.1/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.7.1-vs2.3.5.5/net/ipv6/netfilter/ip6t_MASQUERADE.c
25563 --- linux-3.7.1/net/ipv6/netfilter/ip6t_MASQUERADE.c    2012-12-11 03:30:57.000000000 +0000
25564 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/netfilter/ip6t_MASQUERADE.c  2012-12-18 15:13:16.000000000 +0000
25565 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25566                             ctinfo == IP_CT_RELATED_REPLY));
25567  
25568         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25569 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25570 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25571                 return NF_DROP;
25572  
25573         nfct_nat(ct)->masq_index = par->out->ifindex;
25574 diff -NurpP --minimal linux-3.7.1/net/ipv6/raw.c linux-3.7.1-vs2.3.5.5/net/ipv6/raw.c
25575 --- linux-3.7.1/net/ipv6/raw.c  2012-12-11 03:30:57.000000000 +0000
25576 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/raw.c        2012-12-18 15:13:16.000000000 +0000
25577 @@ -30,6 +30,7 @@
25578  #include <linux/icmpv6.h>
25579  #include <linux/netfilter.h>
25580  #include <linux/netfilter_ipv6.h>
25581 +#include <linux/vs_inet6.h>
25582  #include <linux/skbuff.h>
25583  #include <linux/compat.h>
25584  #include <asm/uaccess.h>
25585 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25586                                 goto out_unlock;
25587                 }
25588  
25589 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25590 +                       err = -EADDRNOTAVAIL;
25591 +                       if (dev)
25592 +                               dev_put(dev);
25593 +                       goto out;
25594 +               }
25595 +
25596                 /* ipv4 addr of the socket is invalid.  Only the
25597                  * unspecified and mapped address have a v4 equivalent.
25598                  */
25599 diff -NurpP --minimal linux-3.7.1/net/ipv6/route.c linux-3.7.1-vs2.3.5.5/net/ipv6/route.c
25600 --- linux-3.7.1/net/ipv6/route.c        2012-12-11 03:30:57.000000000 +0000
25601 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/route.c      2012-12-18 15:13:16.000000000 +0000
25602 @@ -57,6 +57,7 @@
25603  #include <net/xfrm.h>
25604  #include <net/netevent.h>
25605  #include <net/netlink.h>
25606 +#include <linux/vs_inet6.h>
25607  
25608  #include <asm/uaccess.h>
25609  
25610 @@ -2116,15 +2117,17 @@ int ip6_route_get_saddr(struct net *net,
25611                         struct rt6_info *rt,
25612                         const struct in6_addr *daddr,
25613                         unsigned int prefs,
25614 -                       struct in6_addr *saddr)
25615 +                       struct in6_addr *saddr,
25616 +                       struct nx_info *nxi)
25617  {
25618         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25619         int err = 0;
25620 -       if (rt->rt6i_prefsrc.plen)
25621 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25622 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25623                 *saddr = rt->rt6i_prefsrc.addr;
25624         else
25625                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25626 -                                        daddr, prefs, saddr);
25627 +                                        daddr, prefs, saddr, nxi);
25628         return err;
25629  }
25630  
25631 @@ -2478,7 +2481,8 @@ static int rt6_fill_node(struct net *net
25632                                 goto nla_put_failure;
25633         } else if (dst) {
25634                 struct in6_addr saddr_buf;
25635 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25636 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25637 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25638                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25639                         goto nla_put_failure;
25640         }
25641 @@ -2692,6 +2696,7 @@ static int rt6_info_route(struct rt6_inf
25642         struct seq_file *m = p_arg;
25643         struct neighbour *n;
25644  
25645 +       /* FIXME: check for network context? */
25646         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25647  
25648  #ifdef CONFIG_IPV6_SUBTREES
25649 diff -NurpP --minimal linux-3.7.1/net/ipv6/tcp_ipv6.c linux-3.7.1-vs2.3.5.5/net/ipv6/tcp_ipv6.c
25650 --- linux-3.7.1/net/ipv6/tcp_ipv6.c     2012-12-11 03:30:57.000000000 +0000
25651 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/tcp_ipv6.c   2012-12-18 15:13:16.000000000 +0000
25652 @@ -71,6 +71,7 @@
25653  
25654  #include <linux/crypto.h>
25655  #include <linux/scatterlist.h>
25656 +#include <linux/vs_inet6.h>
25657  
25658  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25659  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25660 @@ -175,8 +176,15 @@ static int tcp_v6_connect(struct sock *s
25661          *      connect() to INADDR_ANY means loopback (BSD'ism).
25662          */
25663  
25664 -       if(ipv6_addr_any(&usin->sin6_addr))
25665 -               usin->sin6_addr.s6_addr[15] = 0x1;
25666 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25667 +               struct nx_info *nxi =  sk->sk_nx_info;
25668 +
25669 +               if (nxi && nx_info_has_v6(nxi))
25670 +                       /* FIXME: remap lback? */
25671 +                       usin->sin6_addr = nxi->v6.ip;
25672 +               else
25673 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25674 +       }
25675  
25676         addr_type = ipv6_addr_type(&usin->sin6_addr);
25677  
25678 diff -NurpP --minimal linux-3.7.1/net/ipv6/udp.c linux-3.7.1-vs2.3.5.5/net/ipv6/udp.c
25679 --- linux-3.7.1/net/ipv6/udp.c  2012-12-11 03:30:57.000000000 +0000
25680 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/udp.c        2012-12-18 15:13:16.000000000 +0000
25681 @@ -45,42 +45,68 @@
25682  #include <net/tcp_states.h>
25683  #include <net/ip6_checksum.h>
25684  #include <net/xfrm.h>
25685 +#include <linux/vs_inet6.h>
25686  
25687  #include <linux/proc_fs.h>
25688  #include <linux/seq_file.h>
25689  #include <trace/events/skb.h>
25690  #include "udp_impl.h"
25691  
25692 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25693 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25694  {
25695 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25696 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25697         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25698 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25699 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25700         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25701 -       int sk_ipv6only = ipv6_only_sock(sk);
25702 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25703         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25704 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25705 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25706         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25707  
25708         /* if both are mapped, treat as IPv4 */
25709 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25710 -               return (!sk2_ipv6only &&
25711 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25712 +               if (!sk2_ipv6only &&
25713                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25714 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25715 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25716 +                       goto vs_v4;
25717 +               else
25718 +                       return 0;
25719 +       }
25720  
25721         if (addr_type2 == IPV6_ADDR_ANY &&
25722             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25723 -               return 1;
25724 +               goto vs;
25725  
25726         if (addr_type == IPV6_ADDR_ANY &&
25727 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25728 -               return 1;
25729 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25730 +               goto vs;
25731  
25732         if (sk2_rcv_saddr6 &&
25733 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25734 -               return 1;
25735 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25736 +               goto vs;
25737  
25738         return 0;
25739 +
25740 +vs_v4:
25741 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25742 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25743 +       if (!sk2_rcv_saddr)
25744 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25745 +       if (!sk1_rcv_saddr)
25746 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25747 +       return 1;
25748 +vs:
25749 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25750 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25751 +       else if (addr_type2 == IPV6_ADDR_ANY)
25752 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25753 +       else if (addr_type == IPV6_ADDR_ANY) {
25754 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25755 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25756 +               else
25757 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25758 +       }
25759 +       return 1;
25760  }
25761  
25762  static unsigned int udp6_portaddr_hash(struct net *net,
25763 @@ -144,6 +170,10 @@ static inline int compute_score(struct s
25764                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25765                                 return -1;
25766                         score++;
25767 +               } else {
25768 +                       /* block non nx_info ips */
25769 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25770 +                               return -1;
25771                 }
25772                 if (!ipv6_addr_any(&np->daddr)) {
25773                         if (!ipv6_addr_equal(&np->daddr, saddr))
25774 diff -NurpP --minimal linux-3.7.1/net/ipv6/xfrm6_policy.c linux-3.7.1-vs2.3.5.5/net/ipv6/xfrm6_policy.c
25775 --- linux-3.7.1/net/ipv6/xfrm6_policy.c 2012-12-11 03:30:57.000000000 +0000
25776 +++ linux-3.7.1-vs2.3.5.5/net/ipv6/xfrm6_policy.c       2012-12-18 15:13:16.000000000 +0000
25777 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25778         dev = ip6_dst_idev(dst)->dev;
25779         ipv6_dev_get_saddr(dev_net(dev), dev,
25780                            (struct in6_addr *)&daddr->a6, 0,
25781 -                          (struct in6_addr *)&saddr->a6);
25782 +                          (struct in6_addr *)&saddr->a6, NULL);
25783         dst_release(dst);
25784         return 0;
25785  }
25786 diff -NurpP --minimal linux-3.7.1/net/netfilter/ipvs/ip_vs_xmit.c linux-3.7.1-vs2.3.5.5/net/netfilter/ipvs/ip_vs_xmit.c
25787 --- linux-3.7.1/net/netfilter/ipvs/ip_vs_xmit.c 2012-12-11 03:30:57.000000000 +0000
25788 +++ linux-3.7.1-vs2.3.5.5/net/netfilter/ipvs/ip_vs_xmit.c       2012-12-18 15:13:16.000000000 +0000
25789 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25790                 return dst;
25791         if (ipv6_addr_any(&fl6.saddr) &&
25792             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25793 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25794 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25795                 goto out_err;
25796         if (do_xfrm) {
25797                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25798 diff -NurpP --minimal linux-3.7.1/net/netlink/af_netlink.c linux-3.7.1-vs2.3.5.5/net/netlink/af_netlink.c
25799 --- linux-3.7.1/net/netlink/af_netlink.c        2012-12-11 03:30:57.000000000 +0000
25800 +++ linux-3.7.1-vs2.3.5.5/net/netlink/af_netlink.c      2012-12-18 15:13:16.000000000 +0000
25801 @@ -55,6 +55,9 @@
25802  #include <linux/types.h>
25803  #include <linux/audit.h>
25804  #include <linux/mutex.h>
25805 +#include <linux/vs_context.h>
25806 +#include <linux/vs_network.h>
25807 +#include <linux/vs_limit.h>
25808  
25809  #include <net/net_namespace.h>
25810  #include <net/sock.h>
25811 @@ -1981,6 +1984,8 @@ static struct sock *netlink_seq_socket_i
25812                         sk_for_each(s, node, &hash->table[j]) {
25813                                 if (sock_net(s) != seq_file_net(seq))
25814                                         continue;
25815 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25816 +                                       continue;
25817                                 if (off == pos) {
25818                                         iter->link = i;
25819                                         iter->hash_idx = j;
25820 @@ -2015,7 +2020,8 @@ static void *netlink_seq_next(struct seq
25821         s = v;
25822         do {
25823                 s = sk_next(s);
25824 -       } while (s && sock_net(s) != seq_file_net(seq));
25825 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25826 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25827         if (s)
25828                 return s;
25829  
25830 @@ -2027,7 +2033,8 @@ static void *netlink_seq_next(struct seq
25831  
25832                 for (; j <= hash->mask; j++) {
25833                         s = sk_head(&hash->table[j]);
25834 -                       while (s && sock_net(s) != seq_file_net(seq))
25835 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25836 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25837                                 s = sk_next(s);
25838                         if (s) {
25839                                 iter->link = i;
25840 diff -NurpP --minimal linux-3.7.1/net/socket.c linux-3.7.1-vs2.3.5.5/net/socket.c
25841 --- linux-3.7.1/net/socket.c    2012-12-11 03:30:57.000000000 +0000
25842 +++ linux-3.7.1-vs2.3.5.5/net/socket.c  2012-12-18 15:13:16.000000000 +0000
25843 @@ -99,6 +99,10 @@
25844  
25845  #include <net/sock.h>
25846  #include <linux/netfilter.h>
25847 +#include <linux/vs_base.h>
25848 +#include <linux/vs_socket.h>
25849 +#include <linux/vs_inet.h>
25850 +#include <linux/vs_inet6.h>
25851  
25852  #include <linux/if_tun.h>
25853  #include <linux/ipv6_route.h>
25854 @@ -619,6 +623,7 @@ static inline int __sock_sendmsg_nosec(s
25855                                        struct msghdr *msg, size_t size)
25856  {
25857         struct sock_iocb *si = kiocb_to_siocb(iocb);
25858 +       size_t len;
25859  
25860         sock_update_classid(sock->sk);
25861  
25862 @@ -627,7 +632,22 @@ static inline int __sock_sendmsg_nosec(s
25863         si->msg = msg;
25864         si->size = size;
25865  
25866 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25867 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25868 +       if (sock->sk) {
25869 +               if (len == size)
25870 +                       vx_sock_send(sock->sk, size);
25871 +               else
25872 +                       vx_sock_fail(sock->sk, size);
25873 +       }
25874 +       vxdprintk(VXD_CBIT(net, 7),
25875 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25876 +               sock, sock->sk,
25877 +               (sock->sk)?sock->sk->sk_nx_info:0,
25878 +               (sock->sk)?sock->sk->sk_vx_info:0,
25879 +               (sock->sk)?sock->sk->sk_xid:0,
25880 +               (sock->sk)?sock->sk->sk_nid:0,
25881 +               (unsigned int)size, len);
25882 +       return len;
25883  }
25884  
25885  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25886 @@ -783,6 +803,7 @@ static inline int __sock_recvmsg_nosec(s
25887                                        struct msghdr *msg, size_t size, int flags)
25888  {
25889         struct sock_iocb *si = kiocb_to_siocb(iocb);
25890 +       int len;
25891  
25892         sock_update_classid(sock->sk);
25893  
25894 @@ -792,7 +813,18 @@ static inline int __sock_recvmsg_nosec(s
25895         si->size = size;
25896         si->flags = flags;
25897  
25898 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25899 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25900 +       if ((len >= 0) && sock->sk)
25901 +               vx_sock_recv(sock->sk, len);
25902 +       vxdprintk(VXD_CBIT(net, 7),
25903 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25904 +               sock, sock->sk,
25905 +               (sock->sk)?sock->sk->sk_nx_info:0,
25906 +               (sock->sk)?sock->sk->sk_vx_info:0,
25907 +               (sock->sk)?sock->sk->sk_xid:0,
25908 +               (sock->sk)?sock->sk->sk_nid:0,
25909 +               (unsigned int)size, len);
25910 +       return len;
25911  }
25912  
25913  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25914 @@ -1277,6 +1309,13 @@ int __sock_create(struct net *net, int f
25915         if (type < 0 || type >= SOCK_MAX)
25916                 return -EINVAL;
25917  
25918 +       if (!nx_check(0, VS_ADMIN)) {
25919 +               if (family == PF_INET && !current_nx_info_has_v4())
25920 +                       return -EAFNOSUPPORT;
25921 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25922 +                       return -EAFNOSUPPORT;
25923 +       }
25924 +
25925         /* Compatibility.
25926  
25927            This uglymoron is moved from INET layer to here to avoid
25928 @@ -1411,6 +1450,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25929         if (retval < 0)
25930                 goto out;
25931  
25932 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25933         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25934         if (retval < 0)
25935                 goto out_release;
25936 @@ -1452,10 +1492,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25937         err = sock_create(family, type, protocol, &sock1);
25938         if (err < 0)
25939                 goto out;
25940 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25941  
25942         err = sock_create(family, type, protocol, &sock2);
25943         if (err < 0)
25944                 goto out_release_1;
25945 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25946  
25947         err = sock1->ops->socketpair(sock1, sock2);
25948         if (err < 0)
25949 diff -NurpP --minimal linux-3.7.1/net/sunrpc/auth.c linux-3.7.1-vs2.3.5.5/net/sunrpc/auth.c
25950 --- linux-3.7.1/net/sunrpc/auth.c       2012-12-11 03:30:57.000000000 +0000
25951 +++ linux-3.7.1-vs2.3.5.5/net/sunrpc/auth.c     2012-12-18 15:13:16.000000000 +0000
25952 @@ -15,6 +15,7 @@
25953  #include <linux/sunrpc/clnt.h>
25954  #include <linux/sunrpc/gss_api.h>
25955  #include <linux/spinlock.h>
25956 +#include <linux/vs_tag.h>
25957  
25958  #ifdef RPC_DEBUG
25959  # define RPCDBG_FACILITY       RPCDBG_AUTH
25960 @@ -481,6 +482,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25961         memset(&acred, 0, sizeof(acred));
25962         acred.uid = cred->fsuid;
25963         acred.gid = cred->fsgid;
25964 +       acred.tag = dx_current_tag();
25965         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25966  
25967         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25968 @@ -521,6 +523,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25969         struct auth_cred acred = {
25970                 .uid = 0,
25971                 .gid = 0,
25972 +               .tag = dx_current_tag(),
25973         };
25974  
25975         dprintk("RPC: %5u looking up %s cred\n",
25976 diff -NurpP --minimal linux-3.7.1/net/sunrpc/auth_unix.c linux-3.7.1-vs2.3.5.5/net/sunrpc/auth_unix.c
25977 --- linux-3.7.1/net/sunrpc/auth_unix.c  2012-12-11 03:30:57.000000000 +0000
25978 +++ linux-3.7.1-vs2.3.5.5/net/sunrpc/auth_unix.c        2012-12-18 15:13:16.000000000 +0000
25979 @@ -13,11 +13,13 @@
25980  #include <linux/sunrpc/clnt.h>
25981  #include <linux/sunrpc/auth.h>
25982  #include <linux/user_namespace.h>
25983 +#include <linux/vs_tag.h>
25984  
25985  #define NFS_NGROUPS    16
25986  
25987  struct unx_cred {
25988         struct rpc_cred         uc_base;
25989 +       tag_t                   uc_tag;
25990         gid_t                   uc_gid;
25991         gid_t                   uc_gids[NFS_NGROUPS];
25992  };
25993 @@ -79,6 +81,7 @@ unx_create_cred(struct rpc_auth *auth, s
25994                 groups = NFS_NGROUPS;
25995  
25996         cred->uc_gid = acred->gid;
25997 +       cred->uc_tag = acred->tag;
25998         for (i = 0; i < groups; i++) {
25999                 gid_t gid;
26000                 gid = from_kgid(&init_user_ns, GROUP_AT(acred->group_info, i));
26001 @@ -123,7 +126,9 @@ unx_match(struct auth_cred *acred, struc
26002         unsigned int i;
26003  
26004  
26005 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26006 +       if (cred->uc_uid != acred->uid ||
26007 +               cred->uc_gid != acred->gid ||
26008 +               cred->uc_tag != acred->tag)
26009                 return 0;
26010  
26011         if (acred->group_info != NULL)
26012 @@ -152,7 +157,7 @@ unx_marshal(struct rpc_task *task, __be3
26013         struct rpc_clnt *clnt = task->tk_client;
26014         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26015         __be32          *base, *hold;
26016 -       int             i;
26017 +       int             i, tag;
26018  
26019         *p++ = htonl(RPC_AUTH_UNIX);
26020         base = p++;
26021 @@ -162,9 +167,12 @@ unx_marshal(struct rpc_task *task, __be3
26022          * Copy the UTS nodename captured when the client was created.
26023          */
26024         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26025 +       tag = task->tk_client->cl_tag;
26026  
26027 -       *p++ = htonl((u32) cred->uc_uid);
26028 -       *p++ = htonl((u32) cred->uc_gid);
26029 +       *p++ = htonl((u32) TAGINO_UID(tag,
26030 +               cred->uc_uid, cred->uc_tag));
26031 +       *p++ = htonl((u32) TAGINO_GID(tag,
26032 +               cred->uc_gid, cred->uc_tag));
26033         hold = p++;
26034         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26035                 *p++ = htonl((u32) cred->uc_gids[i]);
26036 diff -NurpP --minimal linux-3.7.1/net/sunrpc/clnt.c linux-3.7.1-vs2.3.5.5/net/sunrpc/clnt.c
26037 --- linux-3.7.1/net/sunrpc/clnt.c       2012-12-11 03:30:57.000000000 +0000
26038 +++ linux-3.7.1-vs2.3.5.5/net/sunrpc/clnt.c     2012-12-18 15:13:16.000000000 +0000
26039 @@ -31,6 +31,7 @@
26040  #include <linux/in6.h>
26041  #include <linux/un.h>
26042  #include <linux/rcupdate.h>
26043 +#include <linux/vs_cvirt.h>
26044  
26045  #include <linux/sunrpc/clnt.h>
26046  #include <linux/sunrpc/rpc_pipe_fs.h>
26047 @@ -481,6 +482,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26048         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26049                 clnt->cl_chatty = 1;
26050  
26051 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26052 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26053 +               clnt->cl_tag = 1; */
26054         return clnt;
26055  }
26056  EXPORT_SYMBOL_GPL(rpc_create);
26057 diff -NurpP --minimal linux-3.7.1/net/unix/af_unix.c linux-3.7.1-vs2.3.5.5/net/unix/af_unix.c
26058 --- linux-3.7.1/net/unix/af_unix.c      2012-12-11 03:30:57.000000000 +0000
26059 +++ linux-3.7.1-vs2.3.5.5/net/unix/af_unix.c    2012-12-18 15:13:16.000000000 +0000
26060 @@ -114,6 +114,8 @@
26061  #include <linux/mount.h>
26062  #include <net/checksum.h>
26063  #include <linux/security.h>
26064 +#include <linux/vs_context.h>
26065 +#include <linux/vs_limit.h>
26066  
26067  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
26068  EXPORT_SYMBOL_GPL(unix_socket_table);
26069 @@ -271,6 +273,8 @@ static struct sock *__unix_find_socket_b
26070                 if (!net_eq(sock_net(s), net))
26071                         continue;
26072  
26073 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26074 +                       continue;
26075                 if (u->addr->len == len &&
26076                     !memcmp(u->addr->name, sunname, len))
26077                         goto found;
26078 @@ -2259,6 +2263,8 @@ static struct sock *unix_from_bucket(str
26079         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
26080                 if (sock_net(sk) != seq_file_net(seq))
26081                         continue;
26082 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26083 +                       continue;
26084                 if (++count == offset)
26085                         break;
26086         }
26087 @@ -2276,6 +2282,8 @@ static struct sock *unix_next_socket(str
26088                 sk = sk_next(sk);
26089                 if (!sk)
26090                         goto next_bucket;
26091 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26092 +                       continue;
26093                 if (sock_net(sk) == seq_file_net(seq))
26094                         return sk;
26095         }
26096 diff -NurpP --minimal linux-3.7.1/scripts/checksyscalls.sh linux-3.7.1-vs2.3.5.5/scripts/checksyscalls.sh
26097 --- linux-3.7.1/scripts/checksyscalls.sh        2012-12-11 03:30:57.000000000 +0000
26098 +++ linux-3.7.1-vs2.3.5.5/scripts/checksyscalls.sh      2012-12-18 15:13:16.000000000 +0000
26099 @@ -193,7 +193,6 @@ cat << EOF
26100  #define __IGNORE_afs_syscall
26101  #define __IGNORE_getpmsg
26102  #define __IGNORE_putpmsg
26103 -#define __IGNORE_vserver
26104  EOF
26105  }
26106  
26107 diff -NurpP --minimal linux-3.7.1/security/commoncap.c linux-3.7.1-vs2.3.5.5/security/commoncap.c
26108 --- linux-3.7.1/security/commoncap.c    2012-12-11 03:30:57.000000000 +0000
26109 +++ linux-3.7.1-vs2.3.5.5/security/commoncap.c  2012-12-18 15:13:16.000000000 +0000
26110 @@ -76,14 +76,20 @@ int cap_netlink_send(struct sock *sk, st
26111  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
26112                 int cap, int audit)
26113  {
26114 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
26115 +
26116         for (;;) {
26117                 /* The owner of the user namespace has all caps. */
26118                 if (targ_ns != &init_user_ns && uid_eq(targ_ns->owner, cred->euid))
26119                         return 0;
26120  
26121                 /* Do we have the necessary capabilities? */
26122 -               if (targ_ns == cred->user_ns)
26123 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26124 +               if (targ_ns == cred->user_ns) {
26125 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26126 +                           cap_raised(cred->cap_effective, cap))
26127 +                               return 0;
26128 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26129 +               }
26130  
26131                 /* Have we tried all of the parent namespaces? */
26132                 if (targ_ns == &init_user_ns)
26133 @@ -619,7 +625,7 @@ int cap_inode_setxattr(struct dentry *de
26134  
26135         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26136                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26137 -           !capable(CAP_SYS_ADMIN))
26138 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26139                 return -EPERM;
26140         return 0;
26141  }
26142 @@ -645,7 +651,7 @@ int cap_inode_removexattr(struct dentry
26143  
26144         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26145                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26146 -           !capable(CAP_SYS_ADMIN))
26147 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26148                 return -EPERM;
26149         return 0;
26150  }
26151 diff -NurpP --minimal linux-3.7.1/security/selinux/hooks.c linux-3.7.1-vs2.3.5.5/security/selinux/hooks.c
26152 --- linux-3.7.1/security/selinux/hooks.c        2012-12-11 03:30:57.000000000 +0000
26153 +++ linux-3.7.1-vs2.3.5.5/security/selinux/hooks.c      2012-12-18 15:13:16.000000000 +0000
26154 @@ -66,7 +66,6 @@
26155  #include <linux/dccp.h>
26156  #include <linux/quota.h>
26157  #include <linux/un.h>          /* for Unix socket types */
26158 -#include <net/af_unix.h>       /* for Unix socket types */
26159  #include <linux/parser.h>
26160  #include <linux/nfs_mount.h>
26161  #include <net/ipv6.h>
26162 --- ../linux-3.7.2-vs2.3.5.5//kernel/vserver/inet.c     2013-01-11 13:43:00.000000000 +0000
26163 +++ ./kernel/vserver/inet.c     2013-02-05 01:41:48.000000000 +0000
26164 @@ -167,7 +167,6 @@ struct rtable *ip_v4_find_src(struct net
26165  
26166         if (fl4->saddr == INADDR_ANY) {
26167                 struct nx_addr_v4 *ptr;
26168 -               unsigned long irqflags;
26169                 __be32 found = 0;
26170  
26171                 rt = __ip_route_output_key(net, fl4);
26172 @@ -181,7 +180,8 @@ struct rtable *ip_v4_find_src(struct net
26173                                 goto found;
26174                 }
26175  
26176 -               spin_lock_irqsave(&nxi->addr_lock, irqflags);
26177 +               WARN_ON_ONCE(in_irq());
26178 +               spin_lock(&nxi->addr_lock);
26179                 for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
26180                         __be32 primary = ptr->ip[0].s_addr;
26181                         __be32 mask = ptr->mask.s_addr;
26182 @@ -210,7 +210,7 @@ struct rtable *ip_v4_find_src(struct net
26183                 found = ipv4_is_loopback(fl4->daddr)
26184                         ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
26185         found_unlock:
26186 -               spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
26187 +               spin_unlock(&nxi->addr_lock);
26188         found:
26189                 /* assign src ip to flow */
26190                 fl4->saddr = found;
This page took 2.54848 seconds and 4 git commands to generate.